From 74f3fd88a5e384cbfb2093dd12e367f73f68a4d7 Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Fri, 6 Oct 2023 13:34:15 -0300 Subject: [PATCH] Improve coverage --- .gas-snapshot | 24 ++++- test/OptimismMintableMiniMeToken.t.sol | 16 +++ test/SNTOptimismController.t.sol | 142 +++++++++++++++++++++++++ 3 files changed, 177 insertions(+), 5 deletions(-) create mode 100644 test/SNTOptimismController.t.sol diff --git a/.gas-snapshot b/.gas-snapshot index 3365c7f..9d98453 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -1,7 +1,21 @@ -BurnTest:testDeployment() (gas: 56874) -BurnTest:test_Burn() (gas: 124436) +BurnTest:testDeployment() (gas: 61274) +BurnTest:test_Burn() (gas: 122496) BurnTest:test_RevertWhen_SenderIsNotBridge() (gas: 10076) -MintTest:testDeployment() (gas: 56874) -MintTest:test_Mint() (gas: 110237) +ChangeControllerTest:testDeployment() (gas: 43370) +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) -OptmismMintableMiniMeTokenTest:testDeployment() (gas: 56874) \ No newline at end of file +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) \ No newline at end of file diff --git a/test/OptimismMintableMiniMeToken.t.sol b/test/OptimismMintableMiniMeToken.t.sol index c593e6e..e0d9500 100644 --- a/test/OptimismMintableMiniMeToken.t.sol +++ b/test/OptimismMintableMiniMeToken.t.sol @@ -8,6 +8,9 @@ import { DeploymentConfig } from "../script/DeploymentConfig.s.sol"; import { OptimismMintableMiniMeToken } from "../contracts/optimism/OptimismMintableMiniMeToken.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 { DeploymentConfig internal deploymentConfig; SNTOptimismController internal tokenController; @@ -48,6 +51,19 @@ contract OptmismMintableMiniMeTokenTest is Test { assertEq(bridgeToken.decimals(), _decimals); assertEq(bridgeToken.symbol(), _tokenSymbol); 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); } } diff --git a/test/SNTOptimismController.t.sol b/test/SNTOptimismController.t.sol new file mode 100644 index 0000000..d892113 --- /dev/null +++ b/test/SNTOptimismController.t.sol @@ -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); + } +}