-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Mariusz Jasuwienas <[email protected]>
- Loading branch information
1 parent
4156c82
commit ce23d50
Showing
5 changed files
with
94 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.0; | ||
|
||
import {Test} from "forge-std/Test.sol"; | ||
import {console} from "forge-std/console.sol"; | ||
import {TestSetup} from "./lib/TestSetup.sol"; | ||
import {HTS_ADDRESS} from "../contracts/HtsSystemContract.sol"; | ||
import {IHederaTokenService} from "../contracts/IHederaTokenService.sol"; | ||
import {HederaResponseCodes} from "../contracts/HederaResponseCodes.sol"; | ||
import {IERC20} from "../contracts/IERC20.sol"; | ||
import {IERC721} from "../contracts/IERC721.sol"; | ||
|
||
contract FreezeTest is Test, TestSetup { | ||
|
||
address private token; | ||
address private owner; | ||
address private to; | ||
uint256 private amount = 4_000000; | ||
|
||
function setUp() external { | ||
setUpMockStorageForNonFork(); | ||
|
||
if (testMode == TestMode.JSON_RPC) vm.skip(true); | ||
|
||
IHederaTokenService.HederaToken memory hederaToken; | ||
hederaToken.name = "Token name"; | ||
hederaToken.symbol = "Token symbol"; | ||
hederaToken.treasury = makeAddr("Token treasury"); | ||
hederaToken.tokenKeys = new IHederaTokenService.TokenKey[](1); | ||
owner = makeAddr("pause"); | ||
|
||
hederaToken.tokenKeys[0].key.contractId = owner; | ||
|
||
hederaToken.tokenKeys[0].keyType = 0x4; | ||
(, token) = IHederaTokenService(HTS_ADDRESS).createFungibleToken{value: 1000}(hederaToken, 1000000, 4); | ||
vm.assertNotEq(token, address(0)); | ||
to = makeAddr("bob"); | ||
} | ||
|
||
function test_HTS_transferToken_success_when_not_frozen() public { | ||
address from = makeAddr("from"); | ||
deal(token, from, amount); | ||
vm.prank(from); | ||
IHederaTokenService(HTS_ADDRESS).transferToken(token, from, to, int64(int256(amount))); | ||
assertEq(IERC20(token).balanceOf(to), amount); | ||
} | ||
|
||
function test_HTS_freezing_success_with_correct_key() public { | ||
address from = makeAddr("bob"); | ||
vm.startPrank(owner); | ||
int64 freezeCode = IHederaTokenService(HTS_ADDRESS).freezeToken(token, from); | ||
assertEq(freezeCode, HederaResponseCodes.SUCCESS); | ||
int64 unfreezeCode = IHederaTokenService(HTS_ADDRESS).unfreezeToken(token, from); | ||
assertEq(unfreezeCode, HederaResponseCodes.SUCCESS); | ||
vm.stopPrank(); | ||
} | ||
|
||
function test_HTS_freezing_failure_with_incorrect_key() public { | ||
vm.expectRevert("freezeToken: only allowed for freezable tokens"); | ||
vm.prank(makeAddr("bob")); | ||
IHederaTokenService(HTS_ADDRESS).freezeToken(token, makeAddr("alice")); | ||
} | ||
|
||
function test_HTS_transferToken_failure_when_paused() public { | ||
address from = makeAddr("bob"); | ||
deal(token, from, amount); | ||
vm.prank(owner); | ||
IHederaTokenService(HTS_ADDRESS).freezeToken(token, from); | ||
vm.expectRevert("notFrozen: token frozen"); | ||
vm.prank(from); | ||
IHederaTokenService(HTS_ADDRESS).transferToken(token, from, to, int64(int256(amount))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters