Skip to content

Commit

Permalink
CU-86drpncjw - Refactor example_tests/test_htlc.py to use BoaConstructor
Browse files Browse the repository at this point in the history
  • Loading branch information
luc10921 committed Mar 25, 2024
1 parent 80723f4 commit 1b18091
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions boa3_test/tests/examples_tests/test_htlc.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ async def asyncSetupClass(cls) -> None:

await cls.set_up_contract('htlc.py', signing_account=cls.owner)

async def wait_refund_time(self):
await asyncio.sleep(self.REFUND_WAIT_TIME)

def test_htlc_compile(self):
path = self.get_contract_path('htlc.py')
self.assertCompile(path)
Expand Down Expand Up @@ -73,7 +76,7 @@ async def test_htlc_on_nep17_payment_fail_amount(self):
return_type=bool,
target_contract=constants.GAS_SCRIPT)

await asyncio.sleep(self.REFUND_WAIT_TIME)
await self.wait_refund_time()
# will be able to refund, because enough time has passed
invoke_refund_success, notifications = await self.call('refund', [], return_type=bool, signing_accounts=[self.owner])
self.assertEqual(True, invoke_refund_success)
Expand Down Expand Up @@ -126,7 +129,7 @@ async def test_htlc_on_nep17_payment(self):
balance_gas_receiver_after, _ = await self.call('balanceOf', [htlc], return_type=int, target_contract=constants.GAS_SCRIPT)
self.assertEqual(balance_gas_receiver_before + transferred_amount_gas, balance_gas_receiver_after)

await asyncio.sleep(self.REFUND_WAIT_TIME)
await self.wait_refund_time()
result, _ = await self.call('refund', [], return_type=bool, signing_accounts=[self.owner])
self.assertEqual(True, result)

Expand Down Expand Up @@ -226,7 +229,7 @@ async def test_htlc_refund_zero_transfers(self):
invoke_refund_fail, _ = await self.call('refund', [], return_type=bool, signing_accounts=[self.owner])
self.assertEqual(False, invoke_refund_fail)

await asyncio.sleep(self.REFUND_WAIT_TIME)
await self.wait_refund_time()
# will be able to refund, because enough time has passed
invoke_refund_success, _ = await self.call('refund', [], return_type=bool, signing_accounts=[self.owner])
self.assertEqual(True, invoke_refund_success)
Expand Down Expand Up @@ -254,7 +257,7 @@ async def test_htlc_refund_one_transfer(self):
target_contract=constants.NEO_SCRIPT)
self.assertEqual(True, result)

await asyncio.sleep(self.REFUND_WAIT_TIME)
await self.wait_refund_time()
# will be able to refund, because enough time has passed
invoke_refund_success, notifications = await self.call('refund', [], return_type=bool, signing_accounts=[self.owner])
self.assertEqual(True, invoke_refund_success)
Expand Down Expand Up @@ -300,7 +303,7 @@ async def test_htlc_refund_two_transfers(self):
target_contract=constants.GAS_SCRIPT)
self.assertEqual(True, result)

await asyncio.sleep(self.REFUND_WAIT_TIME)
await self.wait_refund_time()
# will be able to refund, because enough time has passed
invoke_refund_success, notifications = await self.call('refund', [], return_type=bool, signing_accounts=[self.owner])
self.assertEqual(True, invoke_refund_success)
Expand All @@ -313,12 +316,13 @@ async def test_htlc_refund_two_transfers(self):
)
filtered_transfer_events = list(filter(lambda x: x.source is not None, transfer_events))
self.assertEqual(2, len(filtered_transfer_events))
refund_a, refund_b = filtered_transfer_events

# HTLC returning the tokens
self.assertEqual(htlc, filtered_transfer_events[0].source)
self.assertEqual(person_a, filtered_transfer_events[0].destination)
self.assertEqual(transferred_amount_neo, filtered_transfer_events[0].amount)
self.assertEqual(htlc, refund_a.source)
self.assertEqual(person_a, refund_a.destination)
self.assertEqual(transferred_amount_neo, refund_a.amount)

self.assertEqual(htlc, filtered_transfer_events[1].source)
self.assertEqual(person_b, filtered_transfer_events[1].destination)
self.assertEqual(transferred_amount_gas, filtered_transfer_events[1].amount)
self.assertEqual(htlc, refund_b.source)
self.assertEqual(person_b, refund_b.destination)
self.assertEqual(transferred_amount_gas, refund_b.amount)

0 comments on commit 1b18091

Please sign in to comment.