fix gas metering

This commit is contained in:
Ricardo Guilherme Schmidt 2023-09-26 02:41:52 -03:00
parent 64fdb4f4e8
commit c105703c8a
3 changed files with 44 additions and 43 deletions

View File

@ -1,34 +1,34 @@
| contracts/MiniMeToken.sol:MiniMeToken contract | | | | | | | contracts/MiniMeToken.sol:MiniMeToken contract | | | | | |
|------------------------------------------------|-----------------|---------|---------|---------|---------| |------------------------------------------------|-----------------|--------|--------|---------|---------|
| Deployment Cost | Deployment Size | | | | | | Deployment Cost | Deployment Size | | | | |
| 1804309 | 10009 | | | | | | 1788057 | 9919 | | | | |
| Function Name | min | avg | median | max | # calls | | Function Name | min | avg | median | max | # calls |
| allowance | 808 | 808 | 808 | 808 | 3 | | allowance | 0 | 269 | 0 | 808 | 3 |
| approve | 30781 | 31244 | 31244 | 31708 | 2 | | approve | 30781 | 31244 | 31244 | 31708 | 2 |
| balanceOf | 2361 | 3138 | 2361 | 5601 | 13 | | balanceOf | 0 | 655 | 0 | 2753 | 15 |
| balanceOfAt | 1142 | 2585 | 2363 | 3603 | 26 | | balanceOfAt | 0 | 90 | 0 | 2363 | 26 |
| changeController | 758 | 1318 | 758 | 3558 | 5 | | changeController | 0 | 1014 | 758 | 3558 | 5 |
| controller | 2447 | 2447 | 2447 | 2447 | 6 | | controller | 0 | 0 | 0 | 0 | 6 |
| createCloneToken | 1849066 | 1849066 | 1849066 | 1849066 | 2 | | createCloneToken | 0 | 916398 | 916398 | 1832796 | 2 |
| decimals | 294 | 294 | 294 | 294 | 6 | | decimals | 0 | 0 | 0 | 0 | 6 |
| destroyTokens | 9001 | 9001 | 9001 | 9001 | 1 | | destroyTokens | 8956 | 8956 | 8956 | 8956 | 1 |
| generateTokens | 2541 | 82088 | 94510 | 95808 | 11 | | generateTokens | 0 | 23933 | 0 | 95751 | 12 |
| name | 3253 | 3253 | 3253 | 3253 | 6 | | name | 0 | 0 | 0 | 0 | 6 |
| parentSnapShotBlock | 284 | 284 | 284 | 284 | 7 | | parentSnapShotBlock | 0 | 0 | 0 | 0 | 7 |
| parentToken | 305 | 305 | 305 | 305 | 7 | | parentToken | 0 | 0 | 0 | 0 | 7 |
| symbol | 3274 | 3274 | 3274 | 3274 | 6 | | symbol | 0 | 0 | 0 | 0 | 6 |
| totalSupply | 1911 | 2917 | 1911 | 4930 | 6 | | totalSupply | 0 | 273 | 0 | 1911 | 7 |
| totalSupplyAt | 1995 | 3028 | 3003 | 4603 | 7 | | totalSupplyAt | 0 | 285 | 0 | 1995 | 7 |
| transfer | 75193 | 75193 | 75193 | 75193 | 1 | | transfer | 9785 | 53386 | 75187 | 75187 | 3 |
| transferFrom | 3495 | 48097 | 66596 | 74200 | 3 | | transferFrom | 0 | 23361 | 3495 | 66590 | 3 |
| contracts/MiniMeTokenFactory.sol:MiniMeTokenFactory contract | | | | | | | contracts/MiniMeTokenFactory.sol:MiniMeTokenFactory contract | | | | | |
|--------------------------------------------------------------|-----------------|---------|---------|---------|---------| |--------------------------------------------------------------|-----------------|--------|--------|---------|---------|
| Deployment Cost | Deployment Size | | | | | | Deployment Cost | Deployment Size | | | | |
| 2129265 | 10667 | | | | | | 2111243 | 10577 | | | | |
| Function Name | min | avg | median | max | # calls | | Function Name | min | avg | median | max | # calls |
| createCloneToken | 1841488 | 1841488 | 1841488 | 1841488 | 2 | | createCloneToken | 0 | 912609 | 912609 | 1825218 | 2 |

View File

@ -1,15 +1,15 @@
AllowanceTest:testAllowance() (gas: 244303) AllowanceTest:testAllowance() (gas: 42674)
AllowanceTest:testDeployment() (gas: 45814) AllowanceTest:testDeployment() (gas: 26595)
CreateCloneTokenTest:testCreateCloneToken() (gas: 2182389) CreateCloneTokenTest:testCreateCloneToken() (gas: 1837160)
CreateCloneTokenTest:testDeployment() (gas: 45769) CreateCloneTokenTest:testDeployment() (gas: 26550)
CreateCloneTokenTest:testGenerateTokens() (gas: 2061699) CreateCloneTokenTest:testGenerateTokens() (gas: 102022)
DestroyTokensTest:testDeployment() (gas: 45598) DestroyTokensTest:testDeployment() (gas: 26595)
DestroyTokensTest:testDestroyTokens() (gas: 124942) DestroyTokensTest:testDestroyTokens() (gas: 13456)
GenerateTokensTest:testDeployment() (gas: 45553) GenerateTokensTest:testDeployment() (gas: 26550)
GenerateTokensTest:testGenerateTokens() (gas: 114621) GenerateTokensTest:testGenerateTokens() (gas: 109461)
GenerateTokensTest:test_RevertWhen_SenderIsNotController() (gas: 14930) GenerateTokensTest:test_RevertWhen_SenderIsNotController() (gas: 14966)
MiniMeTokenTest:testDeployment() (gas: 45598) MiniMeTokenTest:testDeployment() (gas: 26535)
ReentrancyTest:testAttack() (gas: 229394) ReentrancyTest:testAttack() (gas: 229331)
TransferTest:testDeployment() (gas: 45814) TransferTest:testDeployment() (gas: 26595)
TransferTest:testDoubleTransfer() (gas: 92339) TransferTest:testDoubleTransfer() (gas: 92339)
TransferTest:testTransfer() (gas: 81675) TransferTest:testTransfer() (gas: 81675)

View File

@ -32,12 +32,14 @@ contract MiniMeTokenTest is Test {
function testDeployment() public { function testDeployment() public {
(, address parentToken, uint256 parentSnapShotBlock, string memory name, uint8 decimals, string memory symbol,) (, address parentToken, uint256 parentSnapShotBlock, string memory name, uint8 decimals, string memory symbol,)
= deploymentConfig.activeNetworkConfig(); = deploymentConfig.activeNetworkConfig();
vm.pauseGasMetering();
assertEq(minimeToken.name(), name, "name should be correct"); assertEq(minimeToken.name(), name, "name should be correct");
assertEq(minimeToken.symbol(), symbol, "symbol should be correct"); assertEq(minimeToken.symbol(), symbol, "symbol should be correct");
assertEq(minimeToken.decimals(), decimals, "decimals should be correct"); assertEq(minimeToken.decimals(), decimals, "decimals should be correct");
assertEq(minimeToken.controller(), deployer, "controller should be correct"); assertEq(minimeToken.controller(), deployer, "controller should be correct");
assertEq(address(minimeToken.parentToken()), parentToken, "parent token should be correct"); assertEq(address(minimeToken.parentToken()), parentToken, "parent token should be correct");
assertEq(minimeToken.parentSnapShotBlock(), parentSnapShotBlock, "parent snapshot block should be correct"); assertEq(minimeToken.parentSnapShotBlock(), parentSnapShotBlock, "parent snapshot block should be correct");
vm.resumeGasMetering();
} }
function _generateTokens(address to, uint256 amount) internal { function _generateTokens(address to, uint256 amount) internal {
@ -57,7 +59,6 @@ contract GenerateTokensTest is MiniMeTokenTest {
} }
function testGenerateTokens() public { function testGenerateTokens() public {
vm.resumeGasMetering();
_generateTokens(accounts[0], 10); _generateTokens(accounts[0], 10);
vm.pauseGasMetering(); vm.pauseGasMetering();
assertEq(minimeToken.totalSupply(), 10, "total supply should be correct"); assertEq(minimeToken.totalSupply(), 10, "total supply should be correct");