Improve coverage

This commit is contained in:
Ricardo Guilherme Schmidt 2023-10-06 13:34:15 -03:00
parent b0e2f1b61b
commit 74f3fd88a5
3 changed files with 177 additions and 5 deletions

View File

@ -1,7 +1,21 @@
BurnTest:testDeployment() (gas: 56874) BurnTest:testDeployment() (gas: 61274)
BurnTest:test_Burn() (gas: 124436) BurnTest:test_Burn() (gas: 122496)
BurnTest:test_RevertWhen_SenderIsNotBridge() (gas: 10076) BurnTest:test_RevertWhen_SenderIsNotBridge() (gas: 10076)
MintTest:testDeployment() (gas: 56874) ChangeControllerTest:testDeployment() (gas: 43370)
MintTest:test_Mint() (gas: 110237) ChangeControllerTest:test_changeController() (gas: 26089)
ClaimTokensTest:testDeployment() (gas: 43574)
ClaimTokensTest:test_ClaimERC20() (gas: 57947)
ClaimTokensTest:test_ClaimETH() (gas: 11558)
ERC165Test:testDeployment() (gas: 61274)
ERC165Test:test_supportInterface() (gas: 7836)
MintTest:testDeployment() (gas: 61274)
MintTest:test_Mint() (gas: 109895)
MintTest:test_RevertWhen_SenderIsNotBridge() (gas: 10076) MintTest:test_RevertWhen_SenderIsNotBridge() (gas: 10076)
OptmismMintableMiniMeTokenTest:testDeployment() (gas: 56874) OnApproveTest:testDeployment() (gas: 43370)
OnApproveTest:test_onApprove() (gas: 5865)
OnTransferTest:testDeployment() (gas: 43370)
OnTransferTest:test_onTransfer() (gas: 5777)
OptmismMintableMiniMeTokenTest:testDeployment() (gas: 61274)
ProxyPaymentTest:testDeployment() (gas: 43325)
ProxyPaymentTest:test_proxyPayment() (gas: 5666)
SNTOptimismControllerTest:testDeployment() (gas: 43370)

View File

@ -8,6 +8,9 @@ import { DeploymentConfig } from "../script/DeploymentConfig.s.sol";
import { OptimismMintableMiniMeToken } from "../contracts/optimism/OptimismMintableMiniMeToken.sol"; import { OptimismMintableMiniMeToken } from "../contracts/optimism/OptimismMintableMiniMeToken.sol";
import { SNTOptimismController } from "../contracts/SNTOptimismController.sol"; import { SNTOptimismController } from "../contracts/SNTOptimismController.sol";
import { IERC165 } from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import { ILegacyMintableERC20, IOptimismMintableERC20 } from "../contracts/optimism/IOptimismMintableERC20.sol";
contract OptmismMintableMiniMeTokenTest is Test { contract OptmismMintableMiniMeTokenTest is Test {
DeploymentConfig internal deploymentConfig; DeploymentConfig internal deploymentConfig;
SNTOptimismController internal tokenController; SNTOptimismController internal tokenController;
@ -48,6 +51,19 @@ contract OptmismMintableMiniMeTokenTest is Test {
assertEq(bridgeToken.decimals(), _decimals); assertEq(bridgeToken.decimals(), _decimals);
assertEq(bridgeToken.symbol(), _tokenSymbol); assertEq(bridgeToken.symbol(), _tokenSymbol);
assertEq(bridgeToken.transfersEnabled(), _transferEnabled); assertEq(bridgeToken.transfersEnabled(), _transferEnabled);
assertEq(bridgeToken.version(), "1.0.1");
}
}
contract ERC165Test is OptmismMintableMiniMeTokenTest {
function setUp() public override {
OptmismMintableMiniMeTokenTest.setUp();
}
function test_supportInterface() public {
assertEq(bridgeToken.supportsInterface(type(IOptimismMintableERC20).interfaceId), true);
assertEq(bridgeToken.supportsInterface(type(ILegacyMintableERC20).interfaceId), true);
assertEq(bridgeToken.supportsInterface(type(IERC165).interfaceId), true);
} }
} }

View File

@ -0,0 +1,142 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;
import { Test } from "forge-std/Test.sol";
import { DeployBridge } from "../script/DeployBridge.s.sol";
import { DeploymentConfig } from "../script/DeploymentConfig.s.sol";
import { SNTOptimismController } from "../contracts/SNTOptimismController.sol";
import { OptimismMintableMiniMeToken } from "../contracts/optimism/OptimismMintableMiniMeToken.sol";
import { MiniMeToken } from "@vacp2p/minime/contracts/MiniMeToken.sol";
contract SNTOptimismControllerTest is Test {
DeploymentConfig internal deploymentConfig;
SNTOptimismController internal tokenController;
OptimismMintableMiniMeToken internal bridgeToken;
address internal deployer;
address internal bridgeAddress;
function setUp() public virtual {
DeployBridge deployment = new DeployBridge();
(deploymentConfig, bridgeToken, tokenController) = deployment.run();
(deployer, bridgeAddress,,,,,,,) = deploymentConfig.activeNetworkConfig();
}
function testDeployment() public {
(
,
address _bridgeAddress,
address _remoteTokenAddress,
address _parentTokenAddress,
uint256 _parentSnapShotBlock,
string memory _tokenName,
uint8 _decimals,
string memory _tokenSymbol,
bool _transferEnabled
) = deploymentConfig.activeNetworkConfig();
assertEq(bridgeToken.controller(), address(tokenController));
assertEq(address(tokenController.snt()), address(bridgeToken));
}
}
contract ChangeControllerTest is SNTOptimismControllerTest {
function setUp() public virtual override {
SNTOptimismControllerTest.setUp();
}
function test_changeController() public {
address payable newController = payable(address(0x123));
vm.prank(tokenController.owner());
tokenController.changeController(newController);
assertEq(bridgeToken.controller(), newController);
}
}
contract ClaimTokensTest is SNTOptimismControllerTest {
function setUp() public virtual override {
SNTOptimismControllerTest.setUp();
}
function test_ClaimERC20() public {
vm.pauseGasMetering();
vm.startPrank(tokenController.owner());
MiniMeToken claimTest = new MiniMeToken(
MiniMeToken(payable(address(0))),
0,
"TestClaim",
18,
"TST",
true
);
claimTest.generateTokens(address(tokenController), 1234);
assertEq(
claimTest.balanceOf(address(tokenController)), 1234, "claimTest tokenController balance should be correct"
);
assertEq(claimTest.balanceOf(address(deployer)), 0, "claimTest deployer balance should be correct");
vm.resumeGasMetering();
tokenController.claimTokens(claimTest);
vm.pauseGasMetering();
vm.stopPrank();
assertEq(
claimTest.balanceOf(address(tokenController)), 0, "claimTest tokenController balance should be correct"
);
assertEq(claimTest.balanceOf(address(deployer)), 1234, "claimTest deployer balance should be correct");
vm.resumeGasMetering();
}
function test_ClaimETH() public {
vm.pauseGasMetering();
vm.startPrank(tokenController.owner());
vm.deal(address(tokenController), 1234);
assertEq(address(tokenController).balance, 1234, "tokenController balance should be correct");
assertEq(address(deployer).balance, 0, "deployer balance should be correct");
vm.resumeGasMetering();
tokenController.claimTokens(MiniMeToken(payable(address(0))));
vm.pauseGasMetering();
assertEq(address(tokenController).balance, 0, "tokenController balance should be correct");
assertEq(address(deployer).balance, 1234, "deployer balance should be correct");
vm.stopPrank();
vm.resumeGasMetering();
}
}
contract OnTransferTest is SNTOptimismControllerTest {
function setUp() public virtual override {
SNTOptimismControllerTest.setUp();
}
function test_onTransfer() public {
assertEq(tokenController.onTransfer(address(0), address(0), 0), true);
}
}
contract OnApproveTest is SNTOptimismControllerTest {
function setUp() public virtual override {
SNTOptimismControllerTest.setUp();
}
function test_onApprove() public {
assertEq(tokenController.onApprove(address(0), address(0), 0), true);
}
}
contract ProxyPaymentTest is SNTOptimismControllerTest {
function setUp() public virtual override {
SNTOptimismControllerTest.setUp();
}
function test_proxyPayment() public {
assertEq(tokenController.proxyPayment(address(0)), false);
}
}