Skip to content

Commit

Permalink
test other functions
Browse files Browse the repository at this point in the history
  • Loading branch information
kumaryash90 committed Oct 21, 2023
1 parent 84ca94a commit f6ddaf4
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 0 deletions.
107 changes: 107 additions & 0 deletions src/test/tokenerc20-BTT/other-functions/other.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

import "../../utils/BaseTest.sol";
import { IStaking20 } from "contracts/extension/interface/IStaking20.sol";

import "@openzeppelin/contracts-upgradeable/access/IAccessControlEnumerableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/IAccessControlUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/introspection/IERC165Upgradeable.sol";

import { TWProxy } from "contracts/infra/TWProxy.sol";

contract MyTokenERC20 is TokenERC20 {
function beforeTokenTransfer(
address from,
address to,
uint256 amount
) external {
_beforeTokenTransfer(from, to, amount);
}

function mint(address account, uint256 amount) external {
_mint(account, amount);
}

function burn(address account, uint256 amount) external {
_burn(account, amount);
}
}

contract TokenERC20Test_OtherFunctions is BaseTest {
address public implementation;
address public proxy;

MyTokenERC20 public tokenContract;
address internal caller;

function setUp() public override {
super.setUp();

// Deploy implementation.
implementation = address(new MyTokenERC20());
caller = getActor(3);

// Deploy proxy pointing to implementaion.
vm.prank(deployer);
proxy = address(
new TWProxy(
implementation,
abi.encodeCall(
TokenERC20.initialize,
(
deployer,
NAME,
SYMBOL,
CONTRACT_URI,
forwarders(),
saleRecipient,
platformFeeRecipient,
platformFeeBps
)
)
)
);

tokenContract = MyTokenERC20(proxy);
}

function test_contractType() public {
assertEq(tokenContract.contractType(), bytes32("TokenERC20"));
}

function test_contractVersion() public {
assertEq(tokenContract.contractVersion(), uint8(1));
}

function test_beforeTokenTransfer_restricted_notTransferRole() public {
vm.prank(deployer);
tokenContract.revokeRole(keccak256("TRANSFER_ROLE"), address(0));
vm.expectRevert("transfers restricted.");
tokenContract.beforeTokenTransfer(caller, address(0x123), 100);
}

modifier whenTransferRole() {
vm.prank(deployer);
tokenContract.grantRole(keccak256("TRANSFER_ROLE"), caller);
_;
}

function test_beforeTokenTransfer_restricted() public whenTransferRole {
tokenContract.beforeTokenTransfer(caller, address(0x123), 100);
}

function test_mint() public {
tokenContract.mint(caller, 100);
assertEq(tokenContract.balanceOf(caller), 100);
}

function test_burn() public {
tokenContract.mint(caller, 100);
assertEq(tokenContract.balanceOf(caller), 100);

tokenContract.burn(caller, 60);
assertEq(tokenContract.balanceOf(caller), 40);
}
}
20 changes: 20 additions & 0 deletions src/test/tokenerc20-BTT/other-functions/other.tree
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
contractType()
├── it should return bytes32("TokenERC20") ✅

contractVersion()
├── it should return uint8(1) ✅

_beforeTokenTransfers(
address from,
address to,
uint256 amount
)
├── when transfers are restricted (i.e. address(0) doesn't have transfer role, or from-to addresses are not address(0)
└── when from and to don't have transfer role
│ └── it should revert ✅

_mint(address account, uint256 amount)
├── it should mint amount to account ✅

_burn(address account, uint256 amount)
├── it should mint amount from account ✅

0 comments on commit f6ddaf4

Please sign in to comment.