mirror of
https://github.com/vacp2p/minime.git
synced 2026-01-08 22:57:57 -05:00
add rejecting controller tests
This commit is contained in:
12
.gas-report
12
.gas-report
@@ -3,26 +3,26 @@
|
|||||||
| Deployment Cost | Deployment Size | | | | |
|
| Deployment Cost | Deployment Size | | | | |
|
||||||
| 1793495 | 9955 | | | | |
|
| 1793495 | 9955 | | | | |
|
||||||
| Function Name | min | avg | median | max | # calls |
|
| Function Name | min | avg | median | max | # calls |
|
||||||
| allowance | 0 | 67 | 0 | 808 | 12 |
|
| allowance | 0 | 62 | 0 | 808 | 13 |
|
||||||
| approve | 0 | 15995 | 23208 | 31708 | 9 |
|
| approve | 0 | 15018 | 14715 | 31708 | 10 |
|
||||||
| approveAndCall | 0 | 31199 | 0 | 93597 | 3 |
|
| approveAndCall | 0 | 31199 | 0 | 93597 | 3 |
|
||||||
| balanceOf | 0 | 323 | 0 | 2753 | 45 |
|
| balanceOf | 0 | 309 | 0 | 2753 | 47 |
|
||||||
| balanceOfAt | 0 | 90 | 0 | 2363 | 26 |
|
| balanceOfAt | 0 | 90 | 0 | 2363 | 26 |
|
||||||
| changeController | 0 | 1014 | 758 | 3558 | 5 |
|
| changeController | 0 | 724 | 0 | 3558 | 7 |
|
||||||
| claimTokens | 9537 | 41277 | 57148 | 57148 | 3 |
|
| claimTokens | 9537 | 41277 | 57148 | 57148 | 3 |
|
||||||
| controller | 0 | 0 | 0 | 0 | 7 |
|
| controller | 0 | 0 | 0 | 0 | 7 |
|
||||||
| createCloneToken | 0 | 919122 | 919122 | 1838245 | 2 |
|
| createCloneToken | 0 | 919122 | 919122 | 1838245 | 2 |
|
||||||
| decimals | 0 | 0 | 0 | 0 | 7 |
|
| decimals | 0 | 0 | 0 | 0 | 7 |
|
||||||
| destroyTokens | 9001 | 9001 | 9001 | 9001 | 1 |
|
| destroyTokens | 9001 | 9001 | 9001 | 9001 | 1 |
|
||||||
| enableTransfers | 0 | 0 | 0 | 0 | 3 |
|
| enableTransfers | 0 | 0 | 0 | 0 | 3 |
|
||||||
| generateTokens | 0 | 8979 | 0 | 95796 | 32 |
|
| generateTokens | 0 | 8450 | 0 | 95796 | 34 |
|
||||||
| 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 |
|
||||||
| symbol | 0 | 0 | 0 | 0 | 7 |
|
| symbol | 0 | 0 | 0 | 0 | 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 | 37564 | 49389 | 75187 | 17 |
|
||||||
| transferFrom | 0 | 16836 | 3495 | 66590 | 7 |
|
| transferFrom | 0 | 16836 | 3495 | 66590 | 7 |
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
AllowanceTest:testAllowance() (gas: 42689)
|
AllowanceTest:testAllowance() (gas: 42712)
|
||||||
AllowanceTest:testAllowanceAlreadySet() (gas: 36809)
|
AllowanceTest:testAllowanceAlreadySet() (gas: 36809)
|
||||||
AllowanceTest:testAllowanceReset() (gas: 45943)
|
AllowanceTest:testAllowanceReset() (gas: 45925)
|
||||||
AllowanceTest:testApproveAndCall() (gas: 98516)
|
AllowanceTest:testApproveAndCall() (gas: 98516)
|
||||||
AllowanceTest:testApproveTransferDisabled() (gas: 7968)
|
AllowanceTest:testApproveTransferDisabled() (gas: 7968)
|
||||||
AllowanceTest:testDeployment() (gas: 26711)
|
AllowanceTest:testDeployment() (gas: 26711)
|
||||||
AllowanceTest:testNoAllowance() (gas: 9462)
|
AllowanceTest:testNoAllowance() (gas: 9462)
|
||||||
|
AllowanceTest:testRejectedApproval() (gas: 13643)
|
||||||
ClaimTokensTest:testClaimERC20() (gas: 63734)
|
ClaimTokensTest:testClaimERC20() (gas: 63734)
|
||||||
ClaimTokensTest:testClaimETH() (gas: 13637)
|
ClaimTokensTest:testClaimETH() (gas: 13637)
|
||||||
ClaimTokensTest:testClaimSelf() (gas: 61216)
|
ClaimTokensTest:testClaimSelf() (gas: 61216)
|
||||||
@@ -22,10 +23,11 @@ ReentrancyTest:testAttack() (gas: 229376)
|
|||||||
TransferTest:testDeployment() (gas: 26617)
|
TransferTest:testDeployment() (gas: 26617)
|
||||||
TransferTest:testDoubleTransfer() (gas: 92391)
|
TransferTest:testDoubleTransfer() (gas: 92391)
|
||||||
TransferTest:testDoubleTransfer2() (gas: 70610)
|
TransferTest:testDoubleTransfer2() (gas: 70610)
|
||||||
TransferTest:testInvalidDestinationTransfer() (gas: 6380)
|
TransferTest:testInvalidDestinationTransfer() (gas: 6402)
|
||||||
TransferTest:testInvalidDestinationTransfer2() (gas: 6399)
|
TransferTest:testInvalidDestinationTransfer2() (gas: 6399)
|
||||||
TransferTest:testMultipleTransferToSame() (gas: 114643)
|
TransferTest:testMultipleTransferToSame() (gas: 114643)
|
||||||
TransferTest:testMultipleTransferToSame2() (gas: 92818)
|
TransferTest:testMultipleTransferToSame2() (gas: 92818)
|
||||||
|
TransferTest:testRejectedTransfer() (gas: 59915)
|
||||||
TransferTest:testTransfer() (gas: 81690)
|
TransferTest:testTransfer() (gas: 81690)
|
||||||
TransferTest:testTransfer2() (gas: 59888)
|
TransferTest:testTransfer2() (gas: 59888)
|
||||||
TransferTest:testTransferDisabled() (gas: 7968)
|
TransferTest:testTransferDisabled() (gas: 7968)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { Test } from "forge-std/Test.sol";
|
|||||||
import { Deploy } from "../script/Deploy.s.sol";
|
import { Deploy } from "../script/Deploy.s.sol";
|
||||||
import { DeploymentConfig } from "../script/DeploymentConfig.s.sol";
|
import { DeploymentConfig } from "../script/DeploymentConfig.s.sol";
|
||||||
|
|
||||||
|
import { TokenController } from "../contracts/TokenController.sol";
|
||||||
import { NotAuthorized } from "../contracts/Controlled.sol";
|
import { NotAuthorized } from "../contracts/Controlled.sol";
|
||||||
import {
|
import {
|
||||||
TransfersDisabled,
|
TransfersDisabled,
|
||||||
@@ -12,6 +13,7 @@ import {
|
|||||||
NotEnoughBalance,
|
NotEnoughBalance,
|
||||||
NotEnoughAllowance,
|
NotEnoughAllowance,
|
||||||
AllowanceAlreadySet,
|
AllowanceAlreadySet,
|
||||||
|
ControllerRejected,
|
||||||
IERC20
|
IERC20
|
||||||
} from "../contracts/MiniMeBase.sol";
|
} from "../contracts/MiniMeBase.sol";
|
||||||
import { MiniMeToken } from "../contracts/MiniMeToken.sol";
|
import { MiniMeToken } from "../contracts/MiniMeToken.sol";
|
||||||
@@ -58,6 +60,20 @@ contract MiniMeTokenTest is Test {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
contract RejectingController is TokenController {
|
||||||
|
function proxyPayment(address) public payable override returns (bool) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onTransfer(address, address, uint256) public pure override returns (bool) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onApprove(address, address, uint256) public pure override returns (bool) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
contract GenerateTokensTest is MiniMeTokenTest {
|
contract GenerateTokensTest is MiniMeTokenTest {
|
||||||
function setUp() public virtual override {
|
function setUp() public virtual override {
|
||||||
MiniMeTokenTest.setUp();
|
MiniMeTokenTest.setUp();
|
||||||
@@ -274,6 +290,22 @@ contract TransferTest is MiniMeTokenTest {
|
|||||||
assertEq(minimeToken.balanceOf(accounts[1]), 0, "balance of receiver shouldn't be increased");
|
assertEq(minimeToken.balanceOf(accounts[1]), 0, "balance of receiver shouldn't be increased");
|
||||||
vm.resumeGasMetering();
|
vm.resumeGasMetering();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testRejectedTransfer() public {
|
||||||
|
vm.pauseGasMetering();
|
||||||
|
address payable rejectingController = payable(address(new RejectingController()));
|
||||||
|
_generateTokens(accounts[0], 10);
|
||||||
|
vm.prank(deployer);
|
||||||
|
minimeToken.changeController(rejectingController);
|
||||||
|
vm.prank(accounts[0]);
|
||||||
|
vm.expectRevert(ControllerRejected.selector);
|
||||||
|
vm.resumeGasMetering();
|
||||||
|
minimeToken.transfer(accounts[1], 2);
|
||||||
|
vm.pauseGasMetering();
|
||||||
|
assertEq(minimeToken.balanceOf(accounts[0]), 10, "balance of sender shouldn't be reduced");
|
||||||
|
assertEq(minimeToken.balanceOf(accounts[1]), 0, "balance of receiver shouldn't be increased");
|
||||||
|
vm.resumeGasMetering();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
contract AllowanceTest is MiniMeTokenTest {
|
contract AllowanceTest is MiniMeTokenTest {
|
||||||
@@ -408,6 +440,21 @@ contract AllowanceTest is MiniMeTokenTest {
|
|||||||
vm.stopPrank();
|
vm.stopPrank();
|
||||||
vm.resumeGasMetering();
|
vm.resumeGasMetering();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testRejectedApproval() public {
|
||||||
|
vm.pauseGasMetering();
|
||||||
|
address payable rejectingController = payable(address(new RejectingController()));
|
||||||
|
_generateTokens(accounts[0], 10);
|
||||||
|
vm.prank(deployer);
|
||||||
|
minimeToken.changeController(rejectingController);
|
||||||
|
vm.prank(accounts[0]);
|
||||||
|
vm.expectRevert(ControllerRejected.selector);
|
||||||
|
vm.resumeGasMetering();
|
||||||
|
minimeToken.approve(accounts[1], 2);
|
||||||
|
vm.pauseGasMetering();
|
||||||
|
assertEq(minimeToken.allowance(accounts[0], accounts[1]), 0, "allowance should be 0");
|
||||||
|
vm.resumeGasMetering();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
contract ApproverAccount is ApproveAndCallFallBack {
|
contract ApproverAccount is ApproveAndCallFallBack {
|
||||||
|
|||||||
Reference in New Issue
Block a user