diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5e2b4e56..ad49e528 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -42,7 +42,5 @@ jobs: - name: Run Forge tests run: | - anvil --chain-id 2024 --port 8546 --block-time 3 & - anvil --chain-id 2 --port 8547 --block-time 3 & forge test -vvv id: test diff --git a/foundry.toml b/foundry.toml index e20e1029..f72d3fc2 100644 --- a/foundry.toml +++ b/foundry.toml @@ -52,6 +52,3 @@ ethereum = "https://eth.llamarpc.com" goerli = "https://ethereum-goerli.publicnode.com" ronin-mainnet = "https://api-partner.roninchain.com/rpc" ronin-testnet = "https://saigon-archive.roninchain.com/rpc" - -ronin-local = "http://localhost:8546" -ethereum-local = "http://localhost:8547" diff --git a/script/GeneralConfig.sol b/script/GeneralConfig.sol index 57895eb2..0d85a792 100644 --- a/script/GeneralConfig.sol +++ b/script/GeneralConfig.sol @@ -36,24 +36,6 @@ contract GeneralConfig is BaseGeneralConfig, Utils { Network.RoninDevnet.envLabel(), Network.RoninDevnet.explorer() ); - - setNetworkInfo( - Network.RoninLocal.chainId(), - Network.RoninLocal.key(), - Network.RoninLocal.chainAlias(), - Network.RoninLocal.deploymentDir(), - Network.RoninLocal.envLabel(), - Network.RoninLocal.explorer() - ); - - setNetworkInfo( - Network.EthLocal.chainId(), - Network.EthLocal.key(), - Network.EthLocal.chainAlias(), - Network.EthLocal.deploymentDir(), - Network.EthLocal.envLabel(), - Network.EthLocal.explorer() - ); } function _setUpContracts() internal virtual override { @@ -82,8 +64,8 @@ contract GeneralConfig is BaseGeneralConfig, Utils { function getSender() public view virtual override returns (address payable sender) { sender = _option.trezor ? payable(_trezorSender) : payable(_envSender); - bool isLocalNetwork = getCurrentNetwork() == DefaultNetwork.Local.key() - || getCurrentNetwork() == Network.RoninLocal.key() || getCurrentNetwork() == Network.EthLocal.key(); + bool isLocalNetwork = getCurrentNetwork() == DefaultNetwork.Local.key(); + if (sender == address(0x0) && isLocalNetwork) sender = payable(DEFAULT_SENDER); require(sender != address(0x0), "GeneralConfig: Sender is address(0x0)"); } diff --git a/script/Migration.s.sol b/script/Migration.s.sol index 6fd4ff13..c77df0a1 100644 --- a/script/Migration.s.sol +++ b/script/Migration.s.sol @@ -26,13 +26,11 @@ contract Migration is BaseMigrationV2, Utils { // Undefined } else if (network() == DefaultNetwork.RoninTestnet.key()) { // Undefined - } else if (network() == Network.RoninLocal.key() || network() == Network.EthLocal.key()) { + } else if (network() == DefaultNetwork.Local.key()) { // test param.test.numberOfBlocksInEpoch = 200; param.test.proxyAdmin = makeAddr("proxy-admin"); param.test.dposGA = makeAddr("governance-admin"); - param.test.mainchainChainId = Network.EthLocal.chainId(); - param.test.roninChainId = Network.RoninLocal.chainId(); // tokens param.weth.name = "Wrapped WETH"; @@ -95,7 +93,7 @@ contract Migration is BaseMigrationV2, Utils { param.roninBridgeManager.num = 2; param.roninBridgeManager.denom = 4; param.roninBridgeManager.roninChainId = 0; - param.roninBridgeManager.roninChainId = param.test.roninChainId; + param.roninBridgeManager.roninChainId = block.chainid; param.roninBridgeManager.expiryDuration = 60 * 60 * 24 * 14; // 14 days param.roninBridgeManager.bridgeOperators = operatorAddrs; param.roninBridgeManager.governors = governorAddrs; @@ -108,7 +106,7 @@ contract Migration is BaseMigrationV2, Utils { param.mainchainPauseEnforcer.sentries = wrapAddress(makeAddr("pause-enforcer-sentry")); // Mainchain Gateway V3 - param.mainchainGatewayV3.roninChainId = param.test.roninChainId; + param.mainchainGatewayV3.roninChainId = block.chainid; param.mainchainGatewayV3.numerator = 1; param.mainchainGatewayV3.highTierVWNumerator = 10; param.mainchainGatewayV3.denominator = 10; @@ -117,14 +115,12 @@ contract Migration is BaseMigrationV2, Utils { param.mainchainBridgeManager.num = 2; param.mainchainBridgeManager.denom = 4; param.mainchainBridgeManager.roninChainId = 0; - param.mainchainBridgeManager.roninChainId = param.test.roninChainId; + param.mainchainBridgeManager.roninChainId = block.chainid; param.mainchainBridgeManager.bridgeOperators = operatorAddrs; param.mainchainBridgeManager.governors = governorAddrs; param.mainchainBridgeManager.voteWeights = voteWeights; param.mainchainBridgeManager.targetOptions = options; param.mainchainBridgeManager.targets = targets; - } else if (network() == DefaultNetwork.Local.key()) { - // Undefined } else { revert("Migration: Network Unknown Shared Parameters Unimplemented!"); } @@ -133,8 +129,7 @@ contract Migration is BaseMigrationV2, Utils { } function _getProxyAdmin() internal virtual override returns (address payable) { - bool isLocalNetwork = network() == DefaultNetwork.Local.key() || network() == Network.RoninLocal.key() - || network() == Network.EthLocal.key(); + bool isLocalNetwork = network() == DefaultNetwork.Local.key(); return isLocalNetwork ? payable(config.sharedArguments().test.proxyAdmin) : super._getProxyAdmin(); } } diff --git a/script/interfaces/ISharedArgument.sol b/script/interfaces/ISharedArgument.sol index ef5b215c..6ae10e68 100644 --- a/script/interfaces/ISharedArgument.sol +++ b/script/interfaces/ISharedArgument.sol @@ -97,8 +97,6 @@ interface ISharedArgument is IGeneralConfig { address proxyAdmin; uint256 numberOfBlocksInEpoch; address dposGA; - uint256 mainchainChainId; - uint256 roninChainId; uint256[] operatorPKs; uint256[] governorPKs; } diff --git a/script/utils/Network.sol b/script/utils/Network.sol index b98bd445..9eda031a 100644 --- a/script/utils/Network.sol +++ b/script/utils/Network.sol @@ -6,9 +6,7 @@ import { LibString, TNetwork } from "foundry-deployment-kit/types/Types.sol"; enum Network { Goerli, EthMainnet, - RoninDevnet, - RoninLocal, - EthLocal + RoninDevnet } using { key, name, chainId, chainAlias, envLabel, deploymentDir, explorer } for Network global; @@ -17,8 +15,6 @@ function chainId(Network network) pure returns (uint256) { if (network == Network.Goerli) return 5; if (network == Network.EthMainnet) return 1; if (network == Network.RoninDevnet) return 2022; - if (network == Network.RoninLocal) return 2024; - if (network == Network.EthLocal) return 2; revert("Network: Unknown chain id"); } @@ -36,8 +32,6 @@ function name(Network network) pure returns (string memory) { if (network == Network.Goerli) return "Goerli"; if (network == Network.RoninDevnet) return "RoninDevnet"; if (network == Network.EthMainnet) return "EthMainnet"; - if (network == Network.RoninLocal) return "RoninLocal"; - if (network == Network.EthLocal) return "EthLocal"; revert("Network: Unknown network name"); } @@ -46,8 +40,6 @@ function deploymentDir(Network network) pure returns (string memory) { if (network == Network.Goerli) return "goerli/"; if (network == Network.EthMainnet) return "ethereum/"; if (network == Network.RoninDevnet) return "ronin-devnet/"; - if (network == Network.RoninLocal) return ""; - if (network == Network.EthLocal) return ""; revert("Network: Unknown network deployment directory"); } @@ -56,8 +48,7 @@ function envLabel(Network network) pure returns (string memory) { if (network == Network.Goerli) return "TESTNET_PK"; if (network == Network.RoninDevnet) return "DEVNET_PK"; if (network == Network.EthMainnet) return "MAINNET_PK"; - if (network == Network.RoninLocal) return "DEVNET_PK"; - if (network == Network.EthLocal) return "DEVNET_PK"; + revert("Network: Unknown private key env label"); } @@ -65,7 +56,6 @@ function chainAlias(Network network) pure returns (string memory) { if (network == Network.Goerli) return "goerli"; if (network == Network.EthMainnet) return "ethereum"; if (network == Network.RoninDevnet) return "ronin-devnet"; - if (network == Network.RoninLocal) return "ronin-local"; - if (network == Network.EthLocal) return "ethereum-local"; + revert("Network: Unknown network alias"); } diff --git a/test/bridge/integration/BaseIntegration.t.sol b/test/bridge/integration/BaseIntegration.t.sol index 0e6f875e..535bf093 100644 --- a/test/bridge/integration/BaseIntegration.t.sol +++ b/test/bridge/integration/BaseIntegration.t.sol @@ -105,9 +105,6 @@ contract BaseIntegration_Test is Base_Test { } function _deployContractsOnRonin() internal { - _config.createFork(Network.RoninLocal.key()); - _config.switchTo(Network.RoninLocal.key()); - _roninGatewayV3 = new RoninGatewayV3Deploy().run(); _bridgeTracking = new BridgeTrackingDeploy().run(); _bridgeSlash = new BridgeSlashDeploy().run(); @@ -122,16 +119,12 @@ contract BaseIntegration_Test is Base_Test { _roninUsdc = new USDCDeploy().run(); _param = ISharedArgument(LibSharedAddress.CONFIG).sharedArguments(); - _roninProposalUtils = new RoninBridgeAdminUtils( - _param.test.roninChainId, _param.test.governorPKs, _roninBridgeManager, _param.roninBridgeManager.governors[0] - ); + _roninProposalUtils = + new RoninBridgeAdminUtils(_param.test.governorPKs, _roninBridgeManager, _param.roninBridgeManager.governors[0]); _validatorSet = new MockValidatorContract_OnlyTiming_ForHardhatTest(_param.test.numberOfBlocksInEpoch); } function _deployContractsOnMainchain() internal { - _config.createFork(Network.EthLocal.key()); - _config.switchTo(Network.EthLocal.key()); - _mainchainPauseEnforcer = new MainchainPauseEnforcerDeploy().run(); _mainchainGatewayV3 = new MainchainGatewayV3Deploy().run(); _mainchainBridgeManager = new MainchainBridgeManagerDeploy().run(); @@ -144,29 +137,24 @@ contract BaseIntegration_Test is Base_Test { _param = ISharedArgument(LibSharedAddress.CONFIG).sharedArguments(); _mainchainProposalUtils = new MainchainBridgeAdminUtils( - _param.test.roninChainId, - _param.test.governorPKs, - _mainchainBridgeManager, - _param.mainchainBridgeManager.governors[0] + _param.test.governorPKs, _mainchainBridgeManager, _param.mainchainBridgeManager.governors[0] ); } function _initializeRonin() internal { - _config.switchTo(Network.RoninLocal.key()); - - _validatorSet.setCurrentPeriod(block.timestamp / _validatorSet.PERIOD_DURATION() - 2); - + _moveToEndPeriodAndWrapUpEpoch(); + _moveToEndPeriodAndWrapUpEpoch(); _bridgeRewardInitialize(); + _bridgeTrackingInitialize(); _bridgeSlashInitialize(); + _roninPauseEnforcerInitialize(); _roninGatewayV3Initialize(); _constructForRoninBridgeManager(); } function _initializeMainchain() internal { - _config.switchTo(Network.EthLocal.key()); - _mainchainPauseEnforcerInitialize(); _constructForMainchainBridgeManager(); _mainchainGatewayV3Initialize(); @@ -264,7 +252,7 @@ contract BaseIntegration_Test is Base_Test { Token.Standard[] memory standards = new Token.Standard[](tokenNum); for (uint256 i; i < tokenNum; i++) { minimumThreshold[i] = 0; - chainIds[i] = _param.test.mainchainChainId; + chainIds[i] = block.chainid; standards[i] = Token.Standard.ERC20; } @@ -485,7 +473,7 @@ contract BaseIntegration_Test is Base_Test { _mainchainGatewayV3.initialize( param.roleSetter, IWETH(param.wrappedToken), - param.roninChainId, + block.chainid, param.numerator, param.highTierVWNumerator, param.denominator, @@ -506,8 +494,6 @@ contract BaseIntegration_Test is Base_Test { } function _changeAdminOnRonin() internal { - _config.switchTo(Network.RoninLocal.key()); - vm.startPrank(_param.test.proxyAdmin); TransparentUpgradeableProxyV2(payable(address(_roninGatewayV3))).changeAdmin(address(_roninBridgeManager)); TransparentUpgradeableProxyV2(payable(address(_bridgeReward))).changeAdmin(address(_roninBridgeManager)); @@ -517,35 +503,25 @@ contract BaseIntegration_Test is Base_Test { } function _changeAdminOnMainchain() internal { - _config.switchTo(Network.EthLocal.key()); - vm.startPrank(_param.test.proxyAdmin); TransparentUpgradeableProxyV2(payable(address(_mainchainGatewayV3))).changeAdmin(address(_mainchainBridgeManager)); vm.stopPrank(); } function _configEmergencyPauserForRoninGateway() internal { - _config.switchTo(Network.RoninLocal.key()); - bytes memory calldata_ = abi.encodeCall(GatewayV3.setEmergencyPauser, (address(_roninPauseEnforcer))); _roninProposalUtils.functionDelegateCall(address(_roninGatewayV3), calldata_); } function _configEmergencyPauserForMainchainGateway() internal { - _config.switchTo(Network.EthLocal.key()); - bytes memory calldata_ = abi.encodeCall(GatewayV3.setEmergencyPauser, (address(_mainchainPauseEnforcer))); _mainchainProposalUtils.functionDelegateCall(address(_mainchainGatewayV3), calldata_); } function _configBridgeTrackingForRoninGateway() internal { - _config.switchTo(Network.RoninLocal.key()); - bytes memory calldata_ = abi.encodeCall(IHasContracts.setContract, (ContractType.BRIDGE_TRACKING, address(_bridgeTracking))); _roninProposalUtils.functionDelegateCall(address(_roninGatewayV3), calldata_); - - _config.switchTo(Network.EthLocal.key()); } function _deployGeneralConfig() internal { @@ -561,15 +537,26 @@ contract BaseIntegration_Test is Base_Test { vm.roll(block.number + 1); } - function _wrapUpEpoch() internal { - uint256 multiplier = _validatorSet.numberOfBlocksInEpoch(); - vm.roll((block.number / multiplier + 1) * multiplier - 1); + function _moveToEndPeriodAndWrapUpEpoch() internal { + _fastForwardToNextDay(); + _wrapUpEpoch(); + } - vm.prank(block.coinbase); + function _wrapUpEpoch() internal { _validatorSet.wrapUpEpoch(); + vm.roll(block.number + _validatorSet.numberOfBlocksInEpoch()); } - function _setTimestampToPeriodEnding() internal { - vm.warp(((block.timestamp / 1 days) + 1) * 1 days); + function _fastForwardToNextDay() internal { + uint256 numberOfBlocksInEpoch = _validatorSet.numberOfBlocksInEpoch(); + + uint256 epochEndingBlockNumber = block.number + (numberOfBlocksInEpoch - 1) - (block.number % numberOfBlocksInEpoch); + uint256 nextDayTimestamp = block.timestamp + 1 days; + + // fast forward to next day + vm.warp(nextDayTimestamp); + vm.roll(epochEndingBlockNumber); } + + function test_setUpIntegration() public { } } diff --git a/test/bridge/integration/bridge-manager/propose-and-cast-vote/voteBridgeOperator.RoninBridgeManager.t.sol b/test/bridge/integration/bridge-manager/propose-and-cast-vote/voteBridgeOperator.RoninBridgeManager.t.sol index 0b831b4c..63d56e58 100644 --- a/test/bridge/integration/bridge-manager/propose-and-cast-vote/voteBridgeOperator.RoninBridgeManager.t.sol +++ b/test/bridge/integration/bridge-manager/propose-and-cast-vote/voteBridgeOperator.RoninBridgeManager.t.sol @@ -55,8 +55,6 @@ contract VoteBridgeOperator_RoninBridgeManager_Test is BaseIntegration_Test { } function test_voteAddBridgeOperatorsProposal() public { - _config.switchTo(Network.RoninLocal.key()); - _globalProposal = _roninProposalUtils.createGlobalProposal({ expiryTimestamp: block.timestamp + _proposalExpiryDuration, targetOption: GlobalProposal.TargetOption.BridgeManager, @@ -88,8 +86,6 @@ contract VoteBridgeOperator_RoninBridgeManager_Test is BaseIntegration_Test { function test_relayAddBridgeOperator() public { test_voteAddBridgeOperatorsProposal(); - _config.switchTo(Network.EthLocal.key()); - // before relay assertEq(_mainchainBridgeManager.globalProposalRelayed(_globalProposal.nonce), false); assertEq(_mainchainBridgeManager.getBridgeOperators(), _beforeRelayedOperators); @@ -117,8 +113,6 @@ contract VoteBridgeOperator_RoninBridgeManager_Test is BaseIntegration_Test { uint256 numAddingOperators = seed % 10 + 10; _generateAddingOperators(numAddingOperators); - _config.switchTo(Network.RoninLocal.key()); - _globalProposal = _roninProposalUtils.createGlobalProposal({ expiryTimestamp: block.timestamp + _proposalExpiryDuration, targetOption: GlobalProposal.TargetOption.BridgeManager, @@ -150,7 +144,6 @@ contract VoteBridgeOperator_RoninBridgeManager_Test is BaseIntegration_Test { function test_relayExpiredProposal() public { test_voteAddBridgeOperatorsProposal(); - _config.switchTo(Network.EthLocal.key()); vm.warp(block.timestamp + _proposalExpiryDuration + 1); // before relay diff --git a/test/bridge/integration/bridge-manager/set-config/setConfig.MainchainManager.t.sol b/test/bridge/integration/bridge-manager/set-config/setConfig.MainchainManager.t.sol index 311aefff..358c4810 100644 --- a/test/bridge/integration/bridge-manager/set-config/setConfig.MainchainManager.t.sol +++ b/test/bridge/integration/bridge-manager/set-config/setConfig.MainchainManager.t.sol @@ -8,7 +8,6 @@ import "../../BaseIntegration.t.sol"; contract SetConfig_MainchainManager_Test is BaseIntegration_Test { function setUp() public virtual override { super.setUp(); - _config.switchTo(Network.EthLocal.key()); } function test_configBridgeContractCorrectly() external { diff --git a/test/bridge/integration/bridge-manager/set-config/setConfig.RoninBridgeManager.t.sol b/test/bridge/integration/bridge-manager/set-config/setConfig.RoninBridgeManager.t.sol index 887ca08d..d27aa9d4 100644 --- a/test/bridge/integration/bridge-manager/set-config/setConfig.RoninBridgeManager.t.sol +++ b/test/bridge/integration/bridge-manager/set-config/setConfig.RoninBridgeManager.t.sol @@ -8,7 +8,6 @@ import "../../BaseIntegration.t.sol"; contract SetConfig_RoninBridgeManager_Test is BaseIntegration_Test { function setUp() public virtual override { super.setUp(); - _config.switchTo(Network.RoninLocal.key()); } function test_configBridgeContractCorrectly() external { diff --git a/test/bridge/integration/bridge-tracking/EpochE1_VoteIsApprovedInLastEpoch.BridgeTracking.t.sol b/test/bridge/integration/bridge-tracking/EpochE1_VoteIsApprovedInLastEpoch.BridgeTracking.t.sol index 3cdb172f..c4997634 100644 --- a/test/bridge/integration/bridge-tracking/EpochE1_VoteIsApprovedInLastEpoch.BridgeTracking.t.sol +++ b/test/bridge/integration/bridge-tracking/EpochE1_VoteIsApprovedInLastEpoch.BridgeTracking.t.sol @@ -5,6 +5,9 @@ import { IBridgeTracking } from "@ronin/contracts/interfaces/bridge/IBridgeTrack import { MockGatewayForTracking } from "@ronin/contracts/mocks/MockGatewayForTracking.sol"; import "../BaseIntegration.t.sol"; +import { EpochE2_VoteIsNotApprovedInLastEpoch_BridgeTracking_Test } from + "./EpochE2_VoteIsNotApprovedInLastEpoch.BridgeTracking.t.sol"; + // Epoch e-1 test: Vote is approved in the last epoch of period contract EpochE1_VoteIsApprovedInLastEpoch_BridgeTracking_Test is BaseIntegration_Test { MockGatewayForTracking _mockRoninGatewayV3; @@ -16,7 +19,7 @@ contract EpochE1_VoteIsApprovedInLastEpoch_BridgeTracking_Test is BaseIntegratio function setUp() public virtual override { super.setUp(); - _config.switchTo(Network.RoninLocal.key()); + vm.coinbase(makeAddr("coin-base-addr")); _operators.push(_param.roninBridgeManager.bridgeOperators[0]); @@ -33,14 +36,16 @@ contract EpochE1_VoteIsApprovedInLastEpoch_BridgeTracking_Test is BaseIntegratio vm.deal(address(_bridgeReward), 10 ether); - _setTimestampToPeriodEnding(); - _wrapUpEpochAndMine(); - + _moveToEndPeriodAndWrapUpEpoch(); _period = _validatorSet.currentPeriod(); } // Epoch e-1: Vote & Approve & Vote > Should not record when not approved yet. Vote in last epoch (e-1). - function test_epochE1_notRecordVoteAndBallot_receiptWithoutApproval() public { + function test_epochEMinus1_notRecordVoteAndBallot_receiptWithoutApproval() public { + _wrapUpEpoch(); + _wrapUpEpoch(); + _wrapUpEpoch(); + _mockRoninGatewayV3.sendBallot(_receiptKind, _receiptId, _operators); assertEq(_bridgeTracking.totalVote(_period), 0); @@ -50,8 +55,8 @@ contract EpochE1_VoteIsApprovedInLastEpoch_BridgeTracking_Test is BaseIntegratio } // Epoch e-1: Vote & Approve & Vote > Should not record when approve. Approve in last epoch (e-1). - function test_epochE2_notRecordVoteAndBallot_approveInLastEpoch() public { - test_epochE1_notRecordVoteAndBallot_receiptWithoutApproval(); + function test_epochEMinus1_notRecordVoteAndBallot_approveInLastEpoch() public { + test_epochEMinus1_notRecordVoteAndBallot_receiptWithoutApproval(); _mockRoninGatewayV3.sendApprovedVote(_receiptKind, _receiptId); @@ -62,8 +67,8 @@ contract EpochE1_VoteIsApprovedInLastEpoch_BridgeTracking_Test is BaseIntegratio } // Epoch e-1: Vote & Approve & Vote > Should not record even after approved. Vote in last epoch (e-1). - function test_epochE1_notRecordVoteAndBallot_voteInLastEpoch() public { - test_epochE2_notRecordVoteAndBallot_approveInLastEpoch(); + function test_epochEMinus1_notRecordVoteAndBallot_voteInLastEpoch() public { + test_epochEMinus1_notRecordVoteAndBallot_approveInLastEpoch(); _mockRoninGatewayV3.sendBallot(_receiptKind, _receiptId, wrapAddress(_param.roninBridgeManager.bridgeOperators[2])); @@ -76,11 +81,10 @@ contract EpochE1_VoteIsApprovedInLastEpoch_BridgeTracking_Test is BaseIntegratio // Epoch e: vote > Should not record for current period metric when wrapping up period. Query in next epoch (e), for current period (p-1): return 0. function test_epochE_notRecordForCurrentPeriod_WhenWrappingUpPeriod() public { - test_epochE1_notRecordVoteAndBallot_voteInLastEpoch(); + test_epochEMinus1_notRecordVoteAndBallot_voteInLastEpoch(); uint256 lastPeriod = _period; - _setTimestampToPeriodEnding(); - _wrapUpEpochAndMine(); + _moveToEndPeriodAndWrapUpEpoch(); uint256 newPeriod = _validatorSet.currentPeriod(); _period = newPeriod; @@ -130,7 +134,7 @@ contract EpochE1_VoteIsApprovedInLastEpoch_BridgeTracking_Test is BaseIntegratio } // Epoch 2e-1: vote > Should record new ballot for the buffer metric - function test_epoch2E_1_recordNewBallotForBufferMetric() public { + function test_epoch2EMinus1_recordNewBallotForBufferMetric() public { test_epochE_recordNewBallotForBufferMetric(); _mockRoninGatewayV3.sendBallot(_receiptKind, _receiptId, wrapAddress(_param.roninBridgeManager.bridgeOperators[4])); @@ -144,8 +148,7 @@ contract EpochE1_VoteIsApprovedInLastEpoch_BridgeTracking_Test is BaseIntegratio assertEq(_bridgeTracking.totalBallotOf(_period, _param.roninBridgeManager.bridgeOperators[3]), expectedTotalVotes); assertEq(_bridgeTracking.totalBallotOf(_period, _param.roninBridgeManager.bridgeOperators[4]), expectedTotalVotes); - _setTimestampToPeriodEnding(); - _wrapUpEpochAndMine(); + _moveToEndPeriodAndWrapUpEpoch(); assertEq(_bridgeTracking.totalVote(_period), expectedTotalVotes); assertEq(_bridgeTracking.totalBallot(_period), expectedTotalVotes * 5); @@ -157,8 +160,8 @@ contract EpochE1_VoteIsApprovedInLastEpoch_BridgeTracking_Test is BaseIntegratio } // Epoch 3e: vote > Should not record new ballot. And the period metric is finalized as in epoch 2e-1. - function test_epoch3E_notRecordNewBallot_periodMetricIsFinalizedAsInEpoch2E_1() public { - test_epoch2E_1_recordNewBallotForBufferMetric(); + function test_epoch3E_notRecordNewBallot_periodMetricIsFinalizedAsInepoch2EMinus1() public { + test_epoch2EMinus1_recordNewBallotForBufferMetric(); _mockRoninGatewayV3.sendBallot(_receiptKind, _receiptId, wrapAddress(_param.roninBridgeManager.bridgeOperators[5])); @@ -175,10 +178,9 @@ contract EpochE1_VoteIsApprovedInLastEpoch_BridgeTracking_Test is BaseIntegratio // Epoch 3e: vote > Should the metric of the new period get reset. function test_epoch3E_metricOfNewPeriodGetReset() public { - test_epoch3E_notRecordNewBallot_periodMetricIsFinalizedAsInEpoch2E_1(); + test_epoch3E_notRecordNewBallot_periodMetricIsFinalizedAsInepoch2EMinus1(); - _setTimestampToPeriodEnding(); - _wrapUpEpochAndMine(); + _moveToEndPeriodAndWrapUpEpoch(); uint256 lastPeriod = _period; uint256 newPeriod = _validatorSet.currentPeriod(); diff --git a/test/bridge/integration/bridge-tracking/EpochE2_VoteIsNotApprovedInLastEpoch.BridgeTracking.t.sol b/test/bridge/integration/bridge-tracking/EpochE2_VoteIsNotApprovedInLastEpoch.BridgeTracking.t.sol index 1f3f2c03..5f487d0d 100644 --- a/test/bridge/integration/bridge-tracking/EpochE2_VoteIsNotApprovedInLastEpoch.BridgeTracking.t.sol +++ b/test/bridge/integration/bridge-tracking/EpochE2_VoteIsNotApprovedInLastEpoch.BridgeTracking.t.sol @@ -16,7 +16,7 @@ contract EpochE2_VoteIsNotApprovedInLastEpoch_BridgeTracking_Test is BaseIntegra function setUp() public virtual override { super.setUp(); - _config.switchTo(Network.RoninLocal.key()); + vm.coinbase(makeAddr("coin-base-addr")); // upgrade ronin gateway v3 @@ -28,8 +28,7 @@ contract EpochE2_VoteIsNotApprovedInLastEpoch_BridgeTracking_Test is BaseIntegra vm.deal(address(_bridgeReward), 10 ether); - _setTimestampToPeriodEnding(); - _wrapUpEpochAndMine(); + // _moveToEndPeriodAndWrapUpEpoch(); _period = _validatorSet.currentPeriod(); _receiptId = 0; @@ -49,7 +48,7 @@ contract EpochE2_VoteIsNotApprovedInLastEpoch_BridgeTracking_Test is BaseIntegra assertEq(_bridgeTracking.totalBallotOf(_period, _param.roninBridgeManager.bridgeOperators[1]), 0); } - // Epoch e-2: Vote & Approve & Vote. > Should be able to approve the receipts and not record the approved receipts once the epoch is not yet wrapped up + // Epoch e-2: Vote & Approve & Vote. > Should be able to approve the receipts and Should not record the approved receipts once the epoch is not yet wrapped up function test_epochE2_recordVoteAndBallot_receiptIsApproved() public { test_epochE2_notRecordVoteAndBallot_receiptWithoutApproval(); @@ -60,7 +59,7 @@ contract EpochE2_VoteIsNotApprovedInLastEpoch_BridgeTracking_Test is BaseIntegra assertEq(_bridgeTracking.totalBallotOf(_period, _param.roninBridgeManager.bridgeOperators[1]), 0); } - // Epoch e-1: Continue voting for the vote of e-2 > Should be able to record the approved votes/ballots when the epoch is wrapped up + // Epoch e-1: Continue voting for the vote of e-2 > Should be able to record the approved votes/ballots when the epoch is wrapped up (value from buffer metric) function test_epochE1_continueVotingForVoteOfE2() public { test_epochE2_recordVoteAndBallot_receiptIsApproved(); @@ -92,8 +91,7 @@ contract EpochE2_VoteIsNotApprovedInLastEpoch_BridgeTracking_Test is BaseIntegra function test_epochE_continueVotingForVoteInE2_notRecordInNextPeriod() public { test_epochE1_recordForWhoVoteLately_onceRequestIsApproved(); - _setTimestampToPeriodEnding(); - _wrapUpEpochAndMine(); + _moveToEndPeriodAndWrapUpEpoch(); uint256 lastPeriod = _period; uint256 newPeriod = _validatorSet.currentPeriod(); diff --git a/test/bridge/integration/mainchain-gateway/submit-withdrawal/submitWithdrawal.MainchainGatewayV3.t.sol b/test/bridge/integration/mainchain-gateway/submit-withdrawal/submitWithdrawal.MainchainGatewayV3.t.sol index ea51c8b9..eb60743e 100644 --- a/test/bridge/integration/mainchain-gateway/submit-withdrawal/submitWithdrawal.MainchainGatewayV3.t.sol +++ b/test/bridge/integration/mainchain-gateway/submit-withdrawal/submitWithdrawal.MainchainGatewayV3.t.sol @@ -16,7 +16,6 @@ contract SubmitWithdrawal_MainchainGatewayV3_Test is BaseIntegration_Test { function setUp() public virtual override { super.setUp(); - _config.switchTo(Network.EthLocal.key()); _domainSeparator = _mainchainGatewayV3.DOMAIN_SEPARATOR(); @@ -24,10 +23,10 @@ contract SubmitWithdrawal_MainchainGatewayV3_Test is BaseIntegration_Test { _withdrawalReceipt.kind = Transfer.Kind.Withdrawal; _withdrawalReceipt.ronin.addr = makeAddr("requester"); _withdrawalReceipt.ronin.tokenAddr = address(_roninWeth); - _withdrawalReceipt.ronin.chainId = _param.test.roninChainId; + _withdrawalReceipt.ronin.chainId = block.chainid; _withdrawalReceipt.mainchain.addr = makeAddr("recipient"); _withdrawalReceipt.mainchain.tokenAddr = address(_mainchainWeth); - _withdrawalReceipt.mainchain.chainId = _param.test.mainchainChainId; + _withdrawalReceipt.mainchain.chainId = block.chainid; _withdrawalReceipt.info.erc = Token.Standard.ERC20; _withdrawalReceipt.info.id = 0; _withdrawalReceipt.info.quantity = 0; diff --git a/test/bridge/integration/pause-enforcer/set-config/accessControl.PauseEnforcer.t.sol b/test/bridge/integration/pause-enforcer/set-config/accessControl.PauseEnforcer.t.sol index 250529ba..a4b950cd 100644 --- a/test/bridge/integration/pause-enforcer/set-config/accessControl.PauseEnforcer.t.sol +++ b/test/bridge/integration/pause-enforcer/set-config/accessControl.PauseEnforcer.t.sol @@ -6,7 +6,6 @@ import "../../BaseIntegration.t.sol"; contract AccessControl_PauseEnforcer_Test is BaseIntegration_Test { function setUp() public virtual override { super.setUp(); - _config.switchTo(Network.RoninLocal.key()); } function test_changeAdmin_OfPauseEnforcer() public { diff --git a/test/bridge/integration/pause-enforcer/set-config/emergencyAction.PauseEnforcer.t.sol b/test/bridge/integration/pause-enforcer/set-config/emergencyAction.PauseEnforcer.t.sol index 04126e76..d078ce95 100644 --- a/test/bridge/integration/pause-enforcer/set-config/emergencyAction.PauseEnforcer.t.sol +++ b/test/bridge/integration/pause-enforcer/set-config/emergencyAction.PauseEnforcer.t.sol @@ -14,7 +14,6 @@ contract EmergencyAction_PauseEnforcer_Test is BaseIntegration_Test { // Should be able to emergency pause function test_EmergencyPause_RoninGatewayV3() public { - _config.switchTo(Network.RoninLocal.key()); vm.prank(_param.roninPauseEnforcer.sentries[0]); _roninPauseEnforcer.triggerPause(); @@ -28,12 +27,8 @@ contract EmergencyAction_PauseEnforcer_Test is BaseIntegration_Test { Transfer.Receipt memory receipt = Transfer.Receipt({ id: 0, kind: Transfer.Kind.Deposit, - ronin: Token.Owner({ addr: makeAddr("recipient"), tokenAddr: address(_roninWeth), chainId: _param.test.roninChainId }), - mainchain: Token.Owner({ - addr: makeAddr("requester"), - tokenAddr: address(_mainchainWeth), - chainId: _param.test.mainchainChainId - }), + ronin: Token.Owner({ addr: makeAddr("recipient"), tokenAddr: address(_roninWeth), chainId: block.chainid }), + mainchain: Token.Owner({ addr: makeAddr("requester"), tokenAddr: address(_mainchainWeth), chainId: block.chainid }), info: Token.Info({ erc: Token.Standard.ERC20, id: 0, quantity: 100 }) }); @@ -69,12 +64,8 @@ contract EmergencyAction_PauseEnforcer_Test is BaseIntegration_Test { Transfer.Receipt memory receipt = Transfer.Receipt({ id: 0, kind: Transfer.Kind.Deposit, - ronin: Token.Owner({ addr: makeAddr("recipient"), tokenAddr: address(_roninWeth), chainId: _param.test.roninChainId }), - mainchain: Token.Owner({ - addr: makeAddr("requester"), - tokenAddr: address(_mainchainWeth), - chainId: _param.test.mainchainChainId - }), + ronin: Token.Owner({ addr: makeAddr("recipient"), tokenAddr: address(_roninWeth), chainId: block.chainid }), + mainchain: Token.Owner({ addr: makeAddr("requester"), tokenAddr: address(_mainchainWeth), chainId: block.chainid }), info: Token.Info({ erc: Token.Standard.ERC20, id: 0, quantity: 100 }) }); diff --git a/test/bridge/integration/pause-enforcer/set-config/normalPause.GatewayV3.t.sol b/test/bridge/integration/pause-enforcer/set-config/normalPause.GatewayV3.t.sol index 77a3cb9a..cd9c1b1b 100644 --- a/test/bridge/integration/pause-enforcer/set-config/normalPause.GatewayV3.t.sol +++ b/test/bridge/integration/pause-enforcer/set-config/normalPause.GatewayV3.t.sol @@ -11,7 +11,6 @@ contract NormalPause_GatewayV3_Test is BaseIntegration_Test { function setUp() public virtual override { super.setUp(); - _config.switchTo(Network.RoninLocal.key()); } // Should gateway admin can pause the gateway through voting diff --git a/test/bridge/integration/pause-enforcer/set-config/setConfig.PauseEnforcer.t.sol b/test/bridge/integration/pause-enforcer/set-config/setConfig.PauseEnforcer.t.sol index e9bde218..60e7dd9c 100644 --- a/test/bridge/integration/pause-enforcer/set-config/setConfig.PauseEnforcer.t.sol +++ b/test/bridge/integration/pause-enforcer/set-config/setConfig.PauseEnforcer.t.sol @@ -8,7 +8,6 @@ import "../../BaseIntegration.t.sol"; contract SetConfig_PauseEnforcer_Test is BaseIntegration_Test { function setUp() public virtual override { super.setUp(); - _config.switchTo(Network.RoninLocal.key()); } function test_configPauseEnforcerContract() public { diff --git a/test/bridge/integration/ronin-gateway/depositVote.RoninGatewayV3.t.sol b/test/bridge/integration/ronin-gateway/depositVote.RoninGatewayV3.t.sol index f0e13164..055a1050 100644 --- a/test/bridge/integration/ronin-gateway/depositVote.RoninGatewayV3.t.sol +++ b/test/bridge/integration/ronin-gateway/depositVote.RoninGatewayV3.t.sol @@ -18,19 +18,14 @@ contract DepositVote_RoninGatewayV3_Test is BaseIntegration_Test { function setUp() public virtual override { super.setUp(); - _config.switchTo(Network.RoninLocal.key()); vm.etch(address(_roninGatewayV3), address(new MockRoninGatewayV3Extended()).code); Transfer.Receipt memory receipt = Transfer.Receipt({ id: 0, kind: Transfer.Kind.Deposit, - ronin: Token.Owner({ addr: makeAddr("recipient"), tokenAddr: address(_roninWeth), chainId: _param.test.roninChainId }), - mainchain: Token.Owner({ - addr: makeAddr("requester"), - tokenAddr: address(_mainchainWeth), - chainId: _param.test.mainchainChainId - }), + ronin: Token.Owner({ addr: makeAddr("recipient"), tokenAddr: address(_roninWeth), chainId: block.chainid }), + mainchain: Token.Owner({ addr: makeAddr("requester"), tokenAddr: address(_mainchainWeth), chainId: block.chainid }), info: Token.Info({ erc: Token.Standard.ERC20, id: 0, quantity: 100 }) }); diff --git a/test/helpers/MainchainBridgeAdminUtils.t.sol b/test/helpers/MainchainBridgeAdminUtils.t.sol index 1d02105a..55c534d0 100644 --- a/test/helpers/MainchainBridgeAdminUtils.t.sol +++ b/test/helpers/MainchainBridgeAdminUtils.t.sol @@ -8,9 +8,7 @@ contract MainchainBridgeAdminUtils is ProposalUtils { MainchainBridgeManager _contract; address _sender; - constructor(uint256 roninChainId, uint256[] memory signerPKs, MainchainBridgeManager contract_, address sender) - ProposalUtils(roninChainId, signerPKs) - { + constructor(uint256[] memory signerPKs, MainchainBridgeManager contract_, address sender) ProposalUtils(signerPKs) { _contract = contract_; _sender = sender; } @@ -26,7 +24,7 @@ contract MainchainBridgeAdminUtils is ProposalUtils { value: 0, calldata_: abi.encodeWithSignature("functionDelegateCall(bytes)", data), gasAmount: 2_000_000, - nonce: _contract.round(_roninChainId) + 1 + nonce: _contract.round(block.chainid) + 1 }); SignatureConsumer.Signature[] memory signatures = this.generateSignatures(proposal); diff --git a/test/helpers/ProposalUtils.t.sol b/test/helpers/ProposalUtils.t.sol index ef504c8b..4e06b0b5 100644 --- a/test/helpers/ProposalUtils.t.sol +++ b/test/helpers/ProposalUtils.t.sol @@ -15,13 +15,11 @@ contract ProposalUtils is Utils, Test { using GlobalProposal for GlobalProposal.GlobalProposalDetail; using Proposal for Proposal.ProposalDetail; - uint256 _roninChainId; uint256[] _signerPKs; bytes32 _domain; - constructor(uint256 roninChainId, uint256[] memory signerPKs) { - _roninChainId = roninChainId; - _domain = getBridgeManagerDomain(roninChainId); + constructor(uint256[] memory signerPKs) { + _domain = getBridgeManagerDomain(); for (uint256 i; i < signerPKs.length; i++) { _signerPKs.push(signerPKs[i]); @@ -118,13 +116,13 @@ contract ProposalUtils is Utils, Test { return generateSignaturesGlobal(proposal, _signerPKs, Ballot.VoteType.For); } - function getBridgeManagerDomain(uint256 roninChainId) public pure returns (bytes32) { + function getBridgeManagerDomain() public view returns (bytes32) { return keccak256( abi.encode( keccak256("EIP712Domain(string name,string version,bytes32 salt)"), keccak256("BridgeAdmin"), // name hash keccak256("2"), // version hash - keccak256(abi.encode("BRIDGE_ADMIN", roninChainId)) // salt + keccak256(abi.encode("BRIDGE_ADMIN", block.chainid)) // salt ) ); } diff --git a/test/helpers/RoninBridgeAdminUtils.t.sol b/test/helpers/RoninBridgeAdminUtils.t.sol index 180d88fe..1b65257d 100644 --- a/test/helpers/RoninBridgeAdminUtils.t.sol +++ b/test/helpers/RoninBridgeAdminUtils.t.sol @@ -8,9 +8,7 @@ contract RoninBridgeAdminUtils is ProposalUtils { RoninBridgeManager _contract; address _sender; - constructor(uint256 roninChainId, uint256[] memory signerPKs, RoninBridgeManager contract_, address sender) - ProposalUtils(roninChainId, signerPKs) - { + constructor(uint256[] memory signerPKs, RoninBridgeManager contract_, address sender) ProposalUtils(signerPKs) { _contract = contract_; _sender = sender; } @@ -26,7 +24,7 @@ contract RoninBridgeAdminUtils is ProposalUtils { value: 0, calldata_: abi.encodeWithSignature("functionDelegateCall(bytes)", data), gasAmount: 2_000_000, - nonce: _contract.round(_roninChainId) + 1 + nonce: _contract.round(block.chainid) + 1 }); SignatureConsumer.Signature[] memory signatures = this.generateSignatures(proposal);