Skip to content

Commit

Permalink
test: remove 2 local chains
Browse files Browse the repository at this point in the history
  • Loading branch information
huyhuynh3103 committed Feb 2, 2024
1 parent a6f390a commit 5877a86
Show file tree
Hide file tree
Showing 21 changed files with 79 additions and 165 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 0 additions & 3 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
22 changes: 2 additions & 20 deletions script/GeneralConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)");
}
Expand Down
15 changes: 5 additions & 10 deletions script/Migration.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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!");
}
Expand All @@ -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();
}
}
2 changes: 0 additions & 2 deletions script/interfaces/ISharedArgument.sol
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ interface ISharedArgument is IGeneralConfig {
address proxyAdmin;
uint256 numberOfBlocksInEpoch;
address dposGA;
uint256 mainchainChainId;
uint256 roninChainId;
uint256[] operatorPKs;
uint256[] governorPKs;
}
Expand Down
16 changes: 3 additions & 13 deletions script/utils/Network.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
}
Expand All @@ -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");
}
Expand All @@ -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");
}
Expand All @@ -56,16 +48,14 @@ 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");
}

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");
}
65 changes: 26 additions & 39 deletions test/bridge/integration/BaseIntegration.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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,
Expand All @@ -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));
Expand All @@ -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 {
Expand All @@ -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 { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit 5877a86

Please sign in to comment.