From 38d62c551747d8f39e7a5f92d1d197c359f1a73c Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Tue, 26 Sep 2023 02:46:16 -0300 Subject: [PATCH] fixes suggested by r4bbit --- .gas-report | 61 ++++++++++++++++++------------------------ .gas-snapshot | 52 +++++++++++++++++------------------ test/MiniMeToken.t.sol | 8 ++++-- 3 files changed, 58 insertions(+), 63 deletions(-) diff --git a/.gas-report b/.gas-report index b17c030..d32369f 100644 --- a/.gas-report +++ b/.gas-report @@ -1,38 +1,29 @@ -| contracts/MiniMeToken.sol:MiniMeToken contract | | | | | | -|------------------------------------------------|-----------------|--------|--------|---------|---------| -| Deployment Cost | Deployment Size | | | | | -| 1804309 | 10009 | | | | | -| Function Name | min | avg | median | max | # calls | -| allowance | 0 | 62 | 0 | 808 | 13 | -| approve | 0 | 15018 | 14715 | 31708 | 10 | -| approveAndCall | 0 | 31201 | 0 | 93603 | 3 | -| balanceOf | 0 | 555 | 0 | 2753 | 63 | -| balanceOfAt | 0 | 905 | 0 | 4027 | 78 | -| changeController | 0 | 507 | 0 | 3558 | 10 | -| claimTokens | 9537 | 41281 | 57154 | 57154 | 3 | -| controller | 0 | 0 | 0 | 0 | 9 | -| createCloneToken | 0 | 924533 | 924533 | 1849066 | 2 | -| decimals | 0 | 0 | 0 | 0 | 9 | -| destroyTokens | 2308 | 5206 | 4310 | 9001 | 3 | -| enableTransfers | 0 | 0 | 0 | 0 | 3 | -| generateTokens | 0 | 13996 | 0 | 95808 | 62 | -| name | 0 | 0 | 0 | 0 | 9 | -| parentSnapShotBlock | 0 | 0 | 0 | 0 | 10 | -| parentToken | 0 | 0 | 0 | 0 | 10 | -| receive | 7960 | 7979 | 7979 | 7998 | 2 | -| symbol | 0 | 0 | 0 | 0 | 9 | -| totalSupply | 0 | 286 | 0 | 2480 | 22 | -| totalSupplyAt | 0 | 873 | 0 | 3659 | 17 | -| transfer | 526 | 39282 | 50395 | 93084 | 20 | -| transferFrom | 0 | 16837 | 3495 | 66596 | 7 | - - -| contracts/MiniMeTokenFactory.sol:MiniMeTokenFactory contract | | | | | | -|--------------------------------------------------------------|-----------------|--------|--------|---------|---------| -| Deployment Cost | Deployment Size | | | | | -| 2129265 | 10667 | | | | | -| Function Name | min | avg | median | max | # calls | -| createCloneToken | 0 | 920744 | 920744 | 1841488 | 2 | +| contracts/MiniMeToken.sol:MiniMeToken contract | | | | | | +|------------------------------------------------|-----------------|-------|--------|-------|---------| +| Deployment Cost | Deployment Size | | | | | +| 1651926 | 9241 | | | | | +| Function Name | min | avg | median | max | # calls | +| allowance | 0 | 60 | 0 | 786 | 13 | +| approve | 0 | 15018 | 14715 | 31708 | 10 | +| approveAndCall | 0 | 31204 | 0 | 93613 | 3 | +| balanceOf | 0 | 550 | 0 | 2731 | 63 | +| balanceOfAt | 0 | 905 | 0 | 4027 | 78 | +| changeController | 0 | 593 | 0 | 3558 | 6 | +| claimTokens | 9582 | 41342 | 57222 | 57222 | 3 | +| controller | 0 | 0 | 0 | 0 | 9 | +| decimals | 0 | 0 | 0 | 0 | 9 | +| destroyTokens | 2286 | 5184 | 4288 | 8979 | 3 | +| enableTransfers | 0 | 0 | 0 | 0 | 3 | +| generateTokens | 0 | 14007 | 0 | 95829 | 62 | +| name | 0 | 0 | 0 | 0 | 9 | +| parentSnapShotBlock | 0 | 0 | 0 | 0 | 10 | +| parentToken | 0 | 0 | 0 | 0 | 10 | +| receive | 7960 | 7979 | 7979 | 7998 | 2 | +| symbol | 0 | 0 | 0 | 0 | 9 | +| totalSupply | 0 | 286 | 0 | 2480 | 22 | +| totalSupplyAt | 0 | 866 | 0 | 3637 | 17 | +| transfer | 571 | 39327 | 50440 | 93129 | 20 | +| transferFrom | 0 | 16831 | 3495 | 66552 | 7 | diff --git a/.gas-snapshot b/.gas-snapshot index fa35720..98a222d 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -1,45 +1,45 @@ AllowanceTest:testAllowance() (gas: 42712) AllowanceTest:testAllowanceAlreadySet() (gas: 36809) AllowanceTest:testAllowanceReset() (gas: 45925) -AllowanceTest:testApproveAndCall() (gas: 98522) +AllowanceTest:testApproveAndCall() (gas: 98532) AllowanceTest:testApproveTransferDisabled() (gas: 7968) AllowanceTest:testDeployment() (gas: 26711) AllowanceTest:testNoAllowance() (gas: 9462) AllowanceTest:testRejectedApproval() (gas: 13643) -ClaimTokensTest:testClaimERC20() (gas: 63740) -ClaimTokensTest:testClaimETH() (gas: 13637) -ClaimTokensTest:testClaimSelf() (gas: 61222) +ClaimTokensTest:testClaimERC20() (gas: 63808) +ClaimTokensTest:testClaimETH() (gas: 13682) +ClaimTokensTest:testClaimSelf() (gas: 61290) ClaimTokensTest:testDeployment() (gas: 26595) -CreateCloneTokenTest:testCloneFutureSnapshot() (gas: 101280) -CreateCloneTokenTest:testCreateCloneToken() (gas: 1853914) +CreateCloneTokenTest:testCloneFutureSnapshot() (gas: 101370) +CreateCloneTokenTest:testCreateCloneToken() (gas: 1692517) CreateCloneTokenTest:testDeployment() (gas: 26550) -CreateCloneTokenTest:testGenerateTokens() (gas: 102094) +CreateCloneTokenTest:testGenerateTokens() (gas: 102115) DestroyTokensTest:testDeployment() (gas: 26595) -DestroyTokensTest:testDestroyTokens() (gas: 13501) -DestroyTokensTest:testDestroyTokensNotEnoughBalance() (gas: 9666) -DestroyTokensTest:testDestroyTokensNotEnoughSupply() (gas: 7997) +DestroyTokensTest:testDestroyTokens() (gas: 13479) +DestroyTokensTest:testDestroyTokensNotEnoughBalance() (gas: 9644) +DestroyTokensTest:testDestroyTokensNotEnoughSupply() (gas: 7975) GenerateTokensTest:testDeployment() (gas: 26550) -GenerateTokensTest:testGenerateTokens() (gas: 109518) +GenerateTokensTest:testGenerateTokens() (gas: 109561) GenerateTokensTest:testGenerateTokensSupplyOverflow() (gas: 3126) -GenerateTokensTest:test_RevertWhen_SenderIsNotController() (gas: 14951) +GenerateTokensTest:test_RevertWhen_SenderIsNotController() (gas: 14994) MiniMeTokenTest:testDeployment() (gas: 26535) ReceiveTest:testAcceptingEther() (gas: 18628) ReceiveTest:testDeployment() (gas: 26595) ReceiveTest:testRejectingEther() (gas: 18691) -ReentrancyTest:testAttack() (gas: 229394) +ReentrancyTest:testAttack() (gas: 229327) TestSnapshotReads:testDeployment() (gas: 26550) -TestSnapshotReads:testSnapshotReads() (gas: 755601) +TestSnapshotReads:testSnapshotReads() (gas: 755896) TransferTest:testDeployment() (gas: 26617) -TransferTest:testDoubleTransfer() (gas: 92425) -TransferTest:testDoubleTransfer2() (gas: 70578) -TransferTest:testInvalidDestinationTransfer() (gas: 6402) -TransferTest:testInvalidDestinationTransfer2() (gas: 6399) -TransferTest:testMultipleTransferToSame() (gas: 114655) -TransferTest:testMultipleTransferToSame2() (gas: 92852) -TransferTest:testRejectedTransfer() (gas: 59921) -TransferTest:testTransfer() (gas: 81718) -TransferTest:testTransfer2() (gas: 59894) -TransferTest:testTransferControllerZero() (gas: 59841) -TransferTest:testTransferDisabled() (gas: 7968) +TransferTest:testDoubleTransfer() (gas: 92515) +TransferTest:testDoubleTransfer2() (gas: 70668) +TransferTest:testInvalidDestinationTransfer() (gas: 6447) +TransferTest:testInvalidDestinationTransfer2() (gas: 6444) +TransferTest:testMultipleTransferToSame() (gas: 114745) +TransferTest:testMultipleTransferToSame2() (gas: 92942) +TransferTest:testRejectedTransfer() (gas: 59966) +TransferTest:testTransfer() (gas: 81763) +TransferTest:testTransfer2() (gas: 59939) +TransferTest:testTransferControllerZero() (gas: 59886) +TransferTest:testTransferDisabled() (gas: 8013) TransferTest:testTransferFromDisabled() (gas: 6526) -TransferTest:testTransferNoBalance() (gas: 16927) \ No newline at end of file +TransferTest:testTransferNoBalance() (gas: 16972) \ No newline at end of file diff --git a/test/MiniMeToken.t.sol b/test/MiniMeToken.t.sol index 9a1f49f..8a204d2 100644 --- a/test/MiniMeToken.t.sol +++ b/test/MiniMeToken.t.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.19; -import { Test, console } from "forge-std/Test.sol"; +import { Test } from "forge-std/Test.sol"; import { Deploy } from "../script/Deploy.s.sol"; import { DeploymentConfig } from "../script/DeploymentConfig.s.sol"; @@ -65,7 +65,11 @@ contract MiniMeTokenTest is Test { } contract AcceptingController is TokenController { - receive() external payable { } + event Received(address, uint256); + + receive() external payable { + emit Received(msg.sender, msg.value); + } function proxyPayment(address) public payable override returns (bool) { return true;