Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(migrate-hardhat-test): implement write-integration-test #27

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion logs/contract-code-sizes.log
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
| ERC1967Proxy | 0.177 | 24.399 |
| ERC20 | 2.173 | 22.403 |
| ERC20PresetMinterPauser | 6.368 | 18.208 |
| ERC721 | 4.363 | 20.213 |
| EnumerableSet | 0.086 | 24.49 |
| ErrorHandler | 0.086 | 24.49 |
| GeneralConfig | 20.136 | 4.44 |
Expand All @@ -39,7 +40,7 @@
| MockBridgeSlash | 1.388 | 23.188 |
| MockBridgeTracking | 1.897 | 22.679 |
| MockERC20 | 2.442 | 22.134 |
| MockERC721 | 3.827 | 20.749 |
| MockERC721 | 4.741 | 19.835 |
| MockGatewayForTracking | 1.616 | 22.96 |
| MockRoninBridgeManager | 24.601 | -0.025 |
| MockRoninGatewayV3Extended | 20.048 | 4.528 |
Expand Down
6 changes: 6 additions & 0 deletions logs/storage/ERC721.sol:ERC721.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
lib/openzeppelin-contracts/contracts/token/ERC721/ERC721.sol:ERC721:_name (storage_slot: 0) (offset: 0) (type: string) (numberOfBytes: 32)
lib/openzeppelin-contracts/contracts/token/ERC721/ERC721.sol:ERC721:_symbol (storage_slot: 1) (offset: 0) (type: string) (numberOfBytes: 32)
lib/openzeppelin-contracts/contracts/token/ERC721/ERC721.sol:ERC721:_owners (storage_slot: 2) (offset: 0) (type: mapping(uint256 => address)) (numberOfBytes: 32)
lib/openzeppelin-contracts/contracts/token/ERC721/ERC721.sol:ERC721:_balances (storage_slot: 3) (offset: 0) (type: mapping(address => uint256)) (numberOfBytes: 32)
lib/openzeppelin-contracts/contracts/token/ERC721/ERC721.sol:ERC721:_tokenApprovals (storage_slot: 4) (offset: 0) (type: mapping(uint256 => address)) (numberOfBytes: 32)
lib/openzeppelin-contracts/contracts/token/ERC721/ERC721.sol:ERC721:_operatorApprovals (storage_slot: 5) (offset: 0) (type: mapping(address => mapping(address => bool))) (numberOfBytes: 32)
13 changes: 6 additions & 7 deletions logs/storage/MockERC721.sol:MockERC721.log
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
lib/foundry-deployment-kit/lib/forge-std/src/mocks/MockERC721.sol:MockERC721:name (storage_slot: 0) (offset: 0) (type: string) (numberOfBytes: 32)
lib/foundry-deployment-kit/lib/forge-std/src/mocks/MockERC721.sol:MockERC721:symbol (storage_slot: 1) (offset: 0) (type: string) (numberOfBytes: 32)
lib/foundry-deployment-kit/lib/forge-std/src/mocks/MockERC721.sol:MockERC721:_ownerOf (storage_slot: 2) (offset: 0) (type: mapping(uint256 => address)) (numberOfBytes: 32)
lib/foundry-deployment-kit/lib/forge-std/src/mocks/MockERC721.sol:MockERC721:_balanceOf (storage_slot: 3) (offset: 0) (type: mapping(address => uint256)) (numberOfBytes: 32)
lib/foundry-deployment-kit/lib/forge-std/src/mocks/MockERC721.sol:MockERC721:getApproved (storage_slot: 4) (offset: 0) (type: mapping(uint256 => address)) (numberOfBytes: 32)
lib/foundry-deployment-kit/lib/forge-std/src/mocks/MockERC721.sol:MockERC721:isApprovedForAll (storage_slot: 5) (offset: 0) (type: mapping(address => mapping(address => bool))) (numberOfBytes: 32)
lib/foundry-deployment-kit/lib/forge-std/src/mocks/MockERC721.sol:MockERC721:initialized (storage_slot: 6) (offset: 0) (type: bool) (numberOfBytes: 1)
src/mocks/token/MockERC721.sol:MockERC721:_name (storage_slot: 0) (offset: 0) (type: string) (numberOfBytes: 32)
src/mocks/token/MockERC721.sol:MockERC721:_symbol (storage_slot: 1) (offset: 0) (type: string) (numberOfBytes: 32)
src/mocks/token/MockERC721.sol:MockERC721:_owners (storage_slot: 2) (offset: 0) (type: mapping(uint256 => address)) (numberOfBytes: 32)
src/mocks/token/MockERC721.sol:MockERC721:_balances (storage_slot: 3) (offset: 0) (type: mapping(address => uint256)) (numberOfBytes: 32)
src/mocks/token/MockERC721.sol:MockERC721:_tokenApprovals (storage_slot: 4) (offset: 0) (type: mapping(uint256 => address)) (numberOfBytes: 32)
src/mocks/token/MockERC721.sol:MockERC721:_operatorApprovals (storage_slot: 5) (offset: 0) (type: mapping(address => mapping(address => bool))) (numberOfBytes: 32)
1 change: 1 addition & 0 deletions script/GeneralConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ contract GeneralConfig is BaseGeneralConfig, Utils {
_mapContractName(Contract.RoninBridgeManager);
_mapContractName(Contract.MainchainGatewayV3);
_mapContractName(Contract.MainchainBridgeManager);
_mapContractName(Contract.MockERC721);

_contractNameMap[Contract.WETH.key()] = "MockWrappedToken";
_contractNameMap[Contract.WRON.key()] = "MockWrappedToken";
Expand Down
2 changes: 2 additions & 0 deletions script/Migration.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ contract Migration is BaseMigrationV2, Utils {
param.slp.symbol = "SLP";
param.usdc.name = "USD Coin";
param.usdc.symbol = "USDC";
param.mockErc721.name = "Mock ERC721";
param.mockErc721.symbol = "M_ERC721";

uint256 num = 6;
address[] memory operatorAddrs = new address[](num);
Expand Down
19 changes: 19 additions & 0 deletions script/contracts/token/MockERC721Deploy.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { MockERC721 } from "@ronin/contracts/mocks/token/MockERC721.sol";
import { Contract } from "../../utils/Contract.sol";
import { ISharedArgument } from "../../interfaces/ISharedArgument.sol";
import { Migration } from "../../Migration.s.sol";

contract MockERC721Deploy is Migration {
function _defaultArguments() internal virtual override returns (bytes memory args) {
ISharedArgument.MockERC721Param memory param = config.sharedArguments().mockErc721;

args = abi.encode(param.name, param.symbol);
}

function run() public virtual returns (MockERC721) {
return MockERC721(_deployImmutable(Contract.MockERC721.key()));
}
}
6 changes: 6 additions & 0 deletions script/interfaces/ISharedArgument.sol
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ interface ISharedArgument is IGeneralConfig {
string symbol;
}

struct MockERC721Param {
string name;
string symbol;
}

struct UnitTestParam {
address proxyAdmin;
uint256 numberOfBlocksInEpoch;
Expand All @@ -119,6 +124,7 @@ interface ISharedArgument is IGeneralConfig {
MockERC20Param axs;
MockERC20Param slp;
MockERC20Param usdc;
MockERC721Param mockErc721;
UnitTestParam test;
}

Expand Down
2 changes: 2 additions & 0 deletions script/utils/Contract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ enum Contract {
AXS,
SLP,
USDC,
MockERC721,
BridgeTracking,
BridgeSlash,
BridgeReward,
Expand All @@ -32,6 +33,7 @@ function name(Contract contractEnum) pure returns (string memory) {
if (contractEnum == Contract.AXS) return "AXS";
if (contractEnum == Contract.SLP) return "SLP";
if (contractEnum == Contract.USDC) return "USDC";
if (contractEnum == Contract.MockERC721) return "MockERC721";

if (contractEnum == Contract.BridgeTracking) return "BridgeTracking";
if (contractEnum == Contract.BridgeSlash) return "BridgeSlash";
Expand Down
12 changes: 12 additions & 0 deletions src/mocks/token/MockERC721.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import { ERC721 } from "@openzeppelin/contracts/token/ERC721/ERC721.sol";

contract MockERC721 is ERC721 {
constructor(string memory name, string memory symbol) ERC721(name, symbol) { }

function mint(address to, uint256 id) external {
_mint(to, id);
}
}
83 changes: 45 additions & 38 deletions test/bridge/integration/BaseIntegration.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { BridgeReward } from "@ronin/contracts/ronin/gateway/BridgeReward.sol";
import { MainchainGatewayV3 } from "@ronin/contracts/mainchain/MainchainGatewayV3.sol";
import { MainchainBridgeManager } from "@ronin/contracts/mainchain/MainchainBridgeManager.sol";
import { MockERC20 } from "@ronin/contracts/mocks/token/MockERC20.sol";
import { MockERC721 } from "@ronin/contracts/mocks/token/MockERC721.sol";

import { MockWrappedToken } from "@ronin/contracts/mocks/token/MockWrappedToken.sol";
import { GlobalProposal } from "@ronin/contracts/libraries/GlobalProposal.sol";
import { Proposal } from "@ronin/contracts/libraries/Proposal.sol";
Expand Down Expand Up @@ -50,6 +52,7 @@ import { WRONDeploy } from "@ronin/script/contracts/token/WRONDeploy.s.sol";
import { AXSDeploy } from "@ronin/script/contracts/token/AXSDeploy.s.sol";
import { SLPDeploy } from "@ronin/script/contracts/token/SLPDeploy.s.sol";
import { USDCDeploy } from "@ronin/script/contracts/token/USDCDeploy.s.sol";
import { MockERC721Deploy } from "@ronin/script/contracts/token/MockERC721Deploy.s.sol";

import { RoninBridgeAdminUtils } from "test/helpers/RoninBridgeAdminUtils.t.sol";
import { MainchainBridgeAdminUtils } from "test/helpers/MainchainBridgeAdminUtils.t.sol";
Expand All @@ -74,12 +77,13 @@ contract BaseIntegration_Test is Base_Test {
MockERC20 _roninAxs;
MockERC20 _roninSlp;
MockERC20 _roninUsdc;
MockERC721 _roninMockERC721;

MockWrappedToken _mainchainWeth;
MockWrappedToken _mainchainWron;
MockERC20 _mainchainAxs;
MockERC20 _mainchainSlp;
MockERC20 _mainchainUsdc;
MockERC721 _mainchainMockERC721;

MockValidatorContract_OnlyTiming_ForHardhatTest _validatorSet;

Expand Down Expand Up @@ -117,6 +121,7 @@ contract BaseIntegration_Test is Base_Test {
_roninAxs = new AXSDeploy().run();
_roninSlp = new SLPDeploy().run();
_roninUsdc = new USDCDeploy().run();
_roninMockERC721 = new MockERC721Deploy().run();

_param = ISharedArgument(LibSharedAddress.CONFIG).sharedArguments();
_roninProposalUtils =
Expand All @@ -130,10 +135,10 @@ contract BaseIntegration_Test is Base_Test {
_mainchainBridgeManager = new MainchainBridgeManagerDeploy().run();

_mainchainWeth = new WETHDeploy().run();
_mainchainWron = new WRONDeploy().run();
_mainchainAxs = new AXSDeploy().run();
_mainchainSlp = new SLPDeploy().run();
_mainchainUsdc = new USDCDeploy().run();
_mainchainMockERC721 = new MockERC721Deploy().run();

_param = ISharedArgument(LibSharedAddress.CONFIG).sharedArguments();
_mainchainProposalUtils = new MainchainBridgeAdminUtils(
Expand All @@ -160,28 +165,6 @@ contract BaseIntegration_Test is Base_Test {
_mainchainGatewayV3Initialize();
}

function _getMainchainAndRoninTokens()
internal
view
returns (address[] memory mainchainTokens, address[] memory roninTokens)
{
uint256 tokenNum = 6;
mainchainTokens = new address[](tokenNum);
roninTokens = new address[](tokenNum);

mainchainTokens[0] = address(_mainchainWeth);
mainchainTokens[1] = address(_mainchainWron);
mainchainTokens[2] = address(_mainchainAxs);
mainchainTokens[3] = address(_mainchainSlp);
mainchainTokens[4] = address(_mainchainUsdc);

roninTokens[0] = address(_roninWeth);
roninTokens[1] = address(_roninWron);
roninTokens[2] = address(_roninAxs);
roninTokens[3] = address(_roninSlp);
roninTokens[4] = address(_roninUsdc);
}

function _bridgeRewardInitialize() internal {
// Bridge rewards
_param.bridgeReward.validatorSetContract = address(_validatorSet);
Expand Down Expand Up @@ -246,14 +229,16 @@ contract BaseIntegration_Test is Base_Test {

function _roninGatewayV3Initialize() internal {
(address[] memory mainchainTokens, address[] memory roninTokens) = _getMainchainAndRoninTokens();
uint256 tokenNum = mainchainTokens.length;
uint256 tokenNum = mainchainTokens.length; // reserve slot for ERC721Tokens
uint256[] memory minimumThreshold = new uint256[](tokenNum);
uint256[] memory chainIds = new uint256[](tokenNum);
Token.Standard[] memory standards = new Token.Standard[](tokenNum);
for (uint256 i; i < tokenNum; i++) {
minimumThreshold[i] = 0;
bool isERC721 = i == mainchainTokens.length - 1; // last item is ERC721

minimumThreshold[i] = 20;
chainIds[i] = block.chainid;
standards[i] = Token.Standard.ERC20;
standards[i] = isERC721 ? Token.Standard.ERC721 : Token.Standard.ERC20;
}

// Ronin Gateway V3
Expand Down Expand Up @@ -447,20 +432,22 @@ contract BaseIntegration_Test is Base_Test {
uint256[] memory lockedThreshold = new uint256[](tokenNum);
uint256[] memory unlockFeePercentages = new uint256[](tokenNum);
uint256[] memory dailyWithdrawalLimits = new uint256[](tokenNum);

highTierThreshold[0] = 10;
lockedThreshold[0] = 20;
unlockFeePercentages[0] = 100_000;
dailyWithdrawalLimits[0] = 12;

Token.Standard[] memory standards = new Token.Standard[](tokenNum);

for (uint256 i; i < tokenNum; i++) {
standards[i] = Token.Standard.ERC20;
bool isERC721 = i == mainchainTokens.length - 1; // last item is ERC721

highTierThreshold[i] = 10;
lockedThreshold[i] = 20;
unlockFeePercentages[i] = 100_000;
dailyWithdrawalLimits[i] = 12;
standards[i] = isERC721 ? Token.Standard.ERC721 : Token.Standard.ERC20;
}

// Mainchain Gateway V3
_param.mainchainGatewayV3.addresses[0] = mainchainTokens;
_param.mainchainGatewayV3.addresses[1] = roninTokens;
_param.mainchainGatewayV3.wrappedToken = address(_mainchainWeth);
_param.mainchainGatewayV3.addresses[0] = mainchainTokens; // (ERC20 + ERC721)
_param.mainchainGatewayV3.addresses[1] = roninTokens; // (ERC20 + ERC721)
_param.mainchainGatewayV3.addresses[2] = getEmptyAddressArray();
_param.mainchainGatewayV3.thresholds[0] = highTierThreshold;
_param.mainchainGatewayV3.thresholds[1] = lockedThreshold;
Expand Down Expand Up @@ -493,6 +480,28 @@ contract BaseIntegration_Test is Base_Test {
_mainchainPauseEnforcer.initialize(IPauseTarget(param.target), param.admin, param.sentries);
}

function _getMainchainAndRoninTokens()
internal
view
returns (address[] memory mainchainTokens, address[] memory roninTokens)
{
uint256 tokenNum = 5;
mainchainTokens = new address[](tokenNum);
roninTokens = new address[](tokenNum);

mainchainTokens[0] = address(_mainchainWeth);
mainchainTokens[1] = address(_mainchainAxs);
mainchainTokens[2] = address(_mainchainSlp);
mainchainTokens[3] = address(_mainchainUsdc);
mainchainTokens[4] = address(_mainchainMockERC721);

roninTokens[0] = address(_roninWeth);
roninTokens[1] = address(_roninAxs);
roninTokens[2] = address(_roninSlp);
roninTokens[3] = address(_roninUsdc);
roninTokens[4] = address(_roninMockERC721);
}

function _changeAdminOnRonin() internal {
vm.startPrank(_param.test.proxyAdmin);
TransparentUpgradeableProxyV2(payable(address(_roninGatewayV3))).changeAdmin(address(_roninBridgeManager));
Expand Down Expand Up @@ -557,6 +566,4 @@ contract BaseIntegration_Test is Base_Test {
vm.warp(nextDayTimestamp);
vm.roll(epochEndingBlockNumber);
}

function test_setUpIntegration() public { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ contract VoteBridgeOperator_RoninBridgeManager_Test is BaseIntegration_Test {
_generateAddingOperators(_addingOperatorNum);
}

// Should be able to vote bridge operators
function test_voteAddBridgeOperatorsProposal() public {
_globalProposal = _roninProposalUtils.createGlobalProposal({
expiryTimestamp: block.timestamp + _proposalExpiryDuration,
Expand Down Expand Up @@ -83,6 +84,7 @@ contract VoteBridgeOperator_RoninBridgeManager_Test is BaseIntegration_Test {
assertEq(_roninBridgeManager.getBridgeOperators(), _afterRelayedOperators);
}

// Should be able relay the vote of bridge operators
function test_relayAddBridgeOperator() public {
test_voteAddBridgeOperatorsProposal();

Expand All @@ -98,6 +100,7 @@ contract VoteBridgeOperator_RoninBridgeManager_Test is BaseIntegration_Test {
assertEq(_mainchainBridgeManager.getBridgeOperators(), _afterRelayedOperators);
}

// Should not able to relay again
function test_RevertWhen_RelayAgain() public {
test_relayAddBridgeOperator();

Expand All @@ -109,6 +112,7 @@ contract VoteBridgeOperator_RoninBridgeManager_Test is BaseIntegration_Test {
_mainchainBridgeManager.relayGlobalProposal(_globalProposal, _supports, _signatures);
}

// Should be able to vote for a larger number of bridge operators
function test_voteForLargeNumberOfOperators(uint256 seed) public {
uint256 numAddingOperators = seed % 10 + 10;
_generateAddingOperators(numAddingOperators);
Expand Down Expand Up @@ -141,6 +145,7 @@ contract VoteBridgeOperator_RoninBridgeManager_Test is BaseIntegration_Test {
assertEq(_roninBridgeManager.getBridgeOperators(), _afterRelayedOperators);
}

// Should the approved proposal can be relayed on mainchain (even when the time of expiry is passed)
function test_relayExpiredProposal() public {
test_voteAddBridgeOperatorsProposal();

Expand Down
Loading
Loading