From 308634297a47f2757fcb93b1d3f34f2483681ec0 Mon Sep 17 00:00:00 2001 From: Mariusz Jasuwienas Date: Mon, 27 Jan 2025 10:51:25 +0100 Subject: [PATCH] test: non payable hbar transfer should not be possible wthout vm cheats (#195) Signed-off-by: Mariusz Jasuwienas --- test/HTS.t.sol | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/test/HTS.t.sol b/test/HTS.t.sol index 51aa1aeb..1c87a264 100644 --- a/test/HTS.t.sol +++ b/test/HTS.t.sol @@ -832,7 +832,6 @@ contract HTSTest is Test, TestSetup { } function test_HTS_cryptoTransfer() external { - vm.skip(testMode == TestMode.JSON_RPC); address owner = 0x4D1c823b5f15bE83FDf5adAF137c2a9e0E78fE15; address bob = makeAddr("bob"); address alice = makeAddr("alice"); @@ -879,35 +878,35 @@ contract HTSTest is Test, TestSetup { function test_HTS_cryptoTransfer_non_payable_hbar_transfer_without_vm_cheats_fail() external { vm.skip(testMode != TestMode.JSON_RPC); address owner = 0x4D1c823b5f15bE83FDf5adAF137c2a9e0E78fE15; - address alice = makeAddr("alice"); - uint256 amountToAlice = 3_000000; - address token = USDC; - IHederaTokenService.AccountAmount memory transfer1 = IHederaTokenService.AccountAmount( + address recipient = makeAddr("recipient1"); + uint256 amount = 1 ether; + IHederaTokenService.AccountAmount memory transferFrom = IHederaTokenService.AccountAmount( owner, - -int64(uint64(amountToAlice)), + -int64(uint64(amount)), false ); - IHederaTokenService.AccountAmount memory transfer2 = IHederaTokenService.AccountAmount( - alice, - int64(uint64(amountToAlice)), + IHederaTokenService.AccountAmount memory transferTo = IHederaTokenService.AccountAmount( + recipient, + int64(uint64(amount)), false ); - IHederaTokenService.TokenTransferList[] memory tokenTransfers = new IHederaTokenService.TokenTransferList[](1); - IHederaTokenService.TransferList memory hbarTransfers; - IHederaTokenService.AccountAmount[] memory transfers = new IHederaTokenService.AccountAmount[](2); - tokenTransfers[0] = IHederaTokenService.TokenTransferList( - token, - transfers, - new IHederaTokenService.NftTransfer[](0) - ); - tokenTransfers[0].transfers[0] = transfer1; - tokenTransfers[0].transfers[1] = transfer2; + IHederaTokenService.TransferList memory transferList; + transferList.transfers = new IHederaTokenService.AccountAmount[](2); + transferList.transfers[0] = transferFrom; + transferList.transfers[1] = transferTo; + vm.deal(owner, amount + 100); + uint256 initialOwnerBalance = address(owner).balance; + uint256 initialRecipient1Balance = address(recipient).balance; vm.prank(owner); vm.expectRevert("_updateHbarBalanceOnAccount: hbar transfer on non-payable method is not supported"); - IHederaTokenService(HTS_ADDRESS).cryptoTransfer(hbarTransfers, tokenTransfers); + IHederaTokenService(HTS_ADDRESS).cryptoTransfer( + transferList, + new IHederaTokenService.TokenTransferList[](0) + ); } function test_HTS_cryptoTransfer_hbar() external { + vm.skip(testMode == TestMode.JSON_RPC); address owner = 0x4D1c823b5f15bE83FDf5adAF137c2a9e0E78fE15; address recipient1 = makeAddr("recipient1"); address recipient2 = makeAddr("recipient2");