Skip to content

Commit

Permalink
test: non payable hbar transfer should not be possible wthout vm chea…
Browse files Browse the repository at this point in the history
…ts (#195)

Signed-off-by: Mariusz Jasuwienas <mariusz.jasuwienas@arianelabs.com>
  • Loading branch information
arianejasuwienas committed Jan 27, 2025
1 parent 98038ed commit 3086342
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions test/HTS.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 3086342

Please sign in to comment.