Skip to content

Commit

Permalink
Add simple TestERC20 token transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
forshtat committed Apr 8, 2024
1 parent 0e7c3c5 commit 66ab9b4
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
29 changes: 29 additions & 0 deletions contracts/test/TestERC20.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.12;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract TestERC20 is ERC20 {
uint8 private immutable __decimals;

constructor(uint8 _decimals) ERC20("TestERC20", "T20") {
_mint(msg.sender, 1000000000000000000000000);
__decimals = _decimals;
}

function decimals() public view override returns (uint8) {
return __decimals;
}

function sudoMint(address _to, uint256 _amount) external {
_mint(_to, _amount);
}

function sudoTransfer(address _from, address _to) external {
_transfer(_from, _to, balanceOf(_from));
}

function sudoApprove(address _from, address _to, uint256 _amount) external {
_approve(_from, _to, _amount);
}
}
22 changes: 22 additions & 0 deletions gascalc/6-simple-wallet-token-transfer.gas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { GasCheckCollector } from './GasChecker'
import { createAddress } from '../test/testutils'
import { ethers } from 'hardhat'
import { TestERC20, TestERC20__factory } from '../typechain'

// TODO: NOTE: Must be executed separately as otherwise test will reuse SimpleAccount
context.only('ERC-20 Token related', function () {
let token: TestERC20

before(async function () {
await GasCheckCollector.init()
GasCheckCollector.inst.createJsonResult = true
token = await new TestERC20__factory(ethers.provider.getSigner()).deploy(18)
})

it('simple 1', async function () {
const destEoa = createAddress()
const tx = await token.transfer(destEoa, 100)
const receipt = await ethers.provider.getTransactionReceipt(tx.hash)
console.log(`ERC-20 EOA -> EOA transfer: status = ${receipt.status}; gasUsed = ${receipt.gasUsed.toString()}; txid = ${receipt.transactionHash}`)
})
})

0 comments on commit 66ab9b4

Please sign in to comment.