add allowance tests

This commit is contained in:
Ricardo Guilherme Schmidt 2023-09-26 02:41:52 -03:00
parent e69486197c
commit 16d3feb5d9
3 changed files with 81 additions and 8 deletions

View File

@ -3,8 +3,8 @@
| Deployment Cost | Deployment Size | | | | | | Deployment Cost | Deployment Size | | | | |
| 1788057 | 9919 | | | | | | 1788057 | 9919 | | | | |
| Function Name | min | avg | median | max | # calls | | Function Name | min | avg | median | max | # calls |
| allowance | 0 | 269 | 0 | 808 | 3 | | allowance | 0 | 80 | 0 | 808 | 10 |
| approve | 0 | 20829 | 30781 | 31708 | 3 | | approve | 0 | 15995 | 23208 | 31708 | 9 |
| balanceOf | 0 | 355 | 0 | 2753 | 41 | | balanceOf | 0 | 355 | 0 | 2753 | 41 |
| balanceOfAt | 0 | 90 | 0 | 2363 | 26 | | balanceOfAt | 0 | 90 | 0 | 2363 | 26 |
| changeController | 0 | 1014 | 758 | 3558 | 5 | | changeController | 0 | 1014 | 758 | 3558 | 5 |
@ -13,8 +13,8 @@
| createCloneToken | 0 | 916398 | 916398 | 1832796 | 2 | | createCloneToken | 0 | 916398 | 916398 | 1832796 | 2 |
| decimals | 0 | 0 | 0 | 0 | 7 | | decimals | 0 | 0 | 0 | 0 | 7 |
| destroyTokens | 8956 | 8956 | 8956 | 8956 | 1 | | destroyTokens | 8956 | 8956 | 8956 | 8956 | 1 |
| enableTransfers | 0 | 0 | 0 | 0 | 2 | | enableTransfers | 0 | 0 | 0 | 0 | 3 |
| generateTokens | 0 | 10636 | 0 | 95751 | 27 | | generateTokens | 0 | 9264 | 0 | 95751 | 31 |
| name | 0 | 0 | 0 | 0 | 7 | | name | 0 | 0 | 0 | 0 | 7 |
| parentSnapShotBlock | 0 | 0 | 0 | 0 | 8 | | parentSnapShotBlock | 0 | 0 | 0 | 0 | 8 |
| parentToken | 0 | 0 | 0 | 0 | 8 | | parentToken | 0 | 0 | 0 | 0 | 8 |
@ -22,7 +22,7 @@
| totalSupply | 0 | 273 | 0 | 1911 | 7 | | totalSupply | 0 | 273 | 0 | 1911 | 7 |
| totalSupplyAt | 0 | 285 | 0 | 1995 | 7 | | totalSupplyAt | 0 | 285 | 0 | 1995 | 7 |
| transfer | 526 | 36631 | 40486 | 75187 | 16 | | transfer | 526 | 36631 | 40486 | 75187 | 16 |
| transferFrom | 0 | 17717 | 2139 | 66590 | 4 | | transferFrom | 0 | 15187 | 3495 | 66590 | 5 |
| contracts/MiniMeTokenFactory.sol:MiniMeTokenFactory contract | | | | | | | contracts/MiniMeTokenFactory.sol:MiniMeTokenFactory contract | | | | | |

View File

@ -1,5 +1,9 @@
AllowanceTest:testAllowance() (gas: 42674) AllowanceTest:testAllowance() (gas: 42696)
AllowanceTest:testDeployment() (gas: 26595) AllowanceTest:testAllowanceAlreadySet() (gas: 36779)
AllowanceTest:testAllowanceReset() (gas: 45888)
AllowanceTest:testApproveTransferDisabled() (gas: 7975)
AllowanceTest:testDeployment() (gas: 26617)
AllowanceTest:testNoAllowance() (gas: 9469)
ClaimTokensTest:testClaimERC20() (gas: 63734) ClaimTokensTest:testClaimERC20() (gas: 63734)
ClaimTokensTest:testClaimETH() (gas: 13637) ClaimTokensTest:testClaimETH() (gas: 13637)
ClaimTokensTest:testClaimSelf() (gas: 61216) ClaimTokensTest:testClaimSelf() (gas: 61216)

View File

@ -6,7 +6,14 @@ import { Deploy } from "../script/Deploy.s.sol";
import { DeploymentConfig } from "../script/DeploymentConfig.s.sol"; import { DeploymentConfig } from "../script/DeploymentConfig.s.sol";
import { NotAuthorized } from "../contracts/Controlled.sol"; import { NotAuthorized } from "../contracts/Controlled.sol";
import { MiniMeToken, TransfersDisabled, InvalidDestination, NotEnoughBalance } from "../contracts/MiniMeToken.sol"; import {
MiniMeToken,
TransfersDisabled,
InvalidDestination,
NotEnoughBalance,
NotEnoughAllowance,
AllowanceAlreadySet
} from "../contracts/MiniMeToken.sol";
import { MiniMeTokenFactory } from "../contracts/MiniMeTokenFactory.sol"; import { MiniMeTokenFactory } from "../contracts/MiniMeTokenFactory.sol";
contract MiniMeTokenTest is Test { contract MiniMeTokenTest is Test {
@ -306,6 +313,68 @@ contract AllowanceTest is MiniMeTokenTest {
assertEq(minimeToken.balanceOfAt(accounts[2], nextBlock), 1, "balance at next block should be correct"); assertEq(minimeToken.balanceOfAt(accounts[2], nextBlock), 1, "balance at next block should be correct");
vm.resumeGasMetering(); vm.resumeGasMetering();
} }
function testNoAllowance() public {
vm.pauseGasMetering();
_generateTokens(accounts[0], 10);
vm.prank(accounts[1]);
uint256 allowed = minimeToken.allowance(accounts[0], accounts[1]);
assertEq(allowed, 0, "allowance should be correct");
vm.expectRevert(NotEnoughAllowance.selector);
vm.resumeGasMetering();
minimeToken.transferFrom(accounts[0], accounts[1], 1);
}
function testApproveTransferDisabled() public {
vm.pauseGasMetering();
_generateTokens(accounts[0], 10);
vm.prank(deployer);
minimeToken.enableTransfers(false);
vm.prank(accounts[0]);
vm.expectRevert(TransfersDisabled.selector);
vm.resumeGasMetering();
minimeToken.approve(accounts[1], 2);
vm.pauseGasMetering();
assertEq(minimeToken.allowance(accounts[0], accounts[1]), 0, "allowance should be 0");
vm.resumeGasMetering();
}
function testAllowanceAlreadySet() public {
vm.pauseGasMetering();
_generateTokens(accounts[0], 10);
vm.startPrank(accounts[0]);
vm.resumeGasMetering();
minimeToken.approve(accounts[1], 2);
vm.pauseGasMetering();
assertEq(minimeToken.allowance(accounts[0], accounts[1]), 2, "allowance should be 2");
vm.expectRevert(AllowanceAlreadySet.selector);
vm.resumeGasMetering();
minimeToken.approve(accounts[1], 3);
vm.pauseGasMetering();
vm.stopPrank();
assertEq(minimeToken.allowance(accounts[0], accounts[1]), 2, "allowance should stay 2");
vm.resumeGasMetering();
}
function testAllowanceReset() public {
vm.pauseGasMetering();
_generateTokens(accounts[0], 10);
vm.startPrank(accounts[0]);
vm.resumeGasMetering();
minimeToken.approve(accounts[1], 2);
vm.pauseGasMetering();
assertEq(minimeToken.allowance(accounts[0], accounts[1]), 2, "allowance should be 2");
vm.resumeGasMetering();
minimeToken.approve(accounts[1], 0);
vm.pauseGasMetering();
assertEq(minimeToken.allowance(accounts[0], accounts[1]), 0, "allowance should be 0");
vm.resumeGasMetering();
minimeToken.approve(accounts[1], 3);
vm.pauseGasMetering();
vm.stopPrank();
assertEq(minimeToken.allowance(accounts[0], accounts[1]), 3, "allowance should be 3");
vm.resumeGasMetering();
}
} }
contract DestroyTokensTest is MiniMeTokenTest { contract DestroyTokensTest is MiniMeTokenTest {