From 6020f843e3f1a3efb1f420aba2ea0f115683fa3f Mon Sep 17 00:00:00 2001 From: Anna Carroll Date: Tue, 29 Nov 2022 22:38:19 +0100 Subject: [PATCH] refactor: fork tests can easily be modified to any chain --- .../contracts-ops/contracts/test/Reboot.t.sol | 12 +++-- .../contracts/test/RebootBridgeRouter.t.sol | 40 +++++++++------- .../test/RebootEthereumBridgeRouter.t.sol | 48 ++++++++++++------- .../contracts/test/RebootTokenRegistry.t.sol | 25 +++++----- 4 files changed, 76 insertions(+), 49 deletions(-) diff --git a/packages/contracts-ops/contracts/test/Reboot.t.sol b/packages/contracts-ops/contracts/test/Reboot.t.sol index 85e70e32..5652144b 100644 --- a/packages/contracts-ops/contracts/test/Reboot.t.sol +++ b/packages/contracts-ops/contracts/test/Reboot.t.sol @@ -7,11 +7,12 @@ import {NomadTest} from "@nomad-xyz/contracts-core/contracts/test/utils/NomadTes contract RebootTest is RebootLogic, NomadTest { string remote; - string constant _domain = "ethereum"; + string constant testDomain = "ethereum"; + uint256 constant testDomainBlock = 15_977_624; function setUpReboot(string memory testName) public { // ALL - vm.createSelectFork(vm.envString("RPC_URL"), 15_977_624); + vm.createSelectFork(vm.envString("RPC_URL"), testDomainBlock); // read fresh config from config.json and write it to a test-specific file // so that state from each test don't collide // NOTE: this is super messy.. it would be better if modifications were stored to memory within the test run @@ -25,7 +26,12 @@ contract RebootTest is RebootLogic, NomadTest { vm.writeFile(_path, vm.readFile("./actions/config.json")); __Config_initialize(_configName); // init fresh callbatch - __CallBatch_initialize(_domain, getDomainNumber(_domain), "", true); + __CallBatch_initialize( + testDomain, + getDomainNumber(testDomain), + "", + true + ); // call base setup super.setUp(); // set fake updater for ethereum & 1 remote chain diff --git a/packages/contracts-ops/contracts/test/RebootBridgeRouter.t.sol b/packages/contracts-ops/contracts/test/RebootBridgeRouter.t.sol index 794dd42f..b33ee33c 100644 --- a/packages/contracts-ops/contracts/test/RebootBridgeRouter.t.sol +++ b/packages/contracts-ops/contracts/test/RebootBridgeRouter.t.sol @@ -19,31 +19,31 @@ contract BridgeRouterRebootTest is RebootTest, BridgeRouterTest { address bridgeRouterHarnessImpl; address tokenRegistryHarnessImpl; - string constant ethereum = "ethereum"; - function setUp() public override(BridgeRouterBaseTest, NomadTest) { setUpReboot("bridgeRouter"); // load proxies tokenRegistry = TokenRegistryHarness( - address(getTokenRegistry(ethereum)) + address(getTokenRegistry(localDomainName)) ); vm.label(address(tokenRegistry), "tokenRegistry"); - bridgeRouter = IBridgeRouterHarness(address(getBridgeRouter(ethereum))); + bridgeRouter = IBridgeRouterHarness( + address(getBridgeRouter(localDomainName)) + ); vm.label(address(bridgeRouter), "bridgeRouter"); // upgrade to harness setUp_upgradeTokenRegistryHarness(); setUp_upgradeBridgeRouterHarness(); // load necessary contracts - xAppConnectionManager = getXAppConnectionManager(ethereum); + xAppConnectionManager = getXAppConnectionManager(localDomainName); vm.label(address(xAppConnectionManager), "XAppConnectionManager"); - upgradeBeaconController = getUpgradeBeaconController(ethereum); + upgradeBeaconController = getUpgradeBeaconController(localDomainName); vm.label(address(upgradeBeaconController), "upgradeBeaconController"); tokenBeacon = UpgradeBeacon(payable(tokenRegistry.tokenBeacon())); vm.label(address(tokenBeacon), "tokenBeacon"); bridgeToken = BridgeToken(beaconImplementation(tokenBeacon)); vm.label(address(bridgeToken), "bridgeToken"); // home needed for vm.expectCall - home = address(getHome("ethereum")); + home = address(getHome(localDomainName)); vm.label(home, "home"); BridgeRouterBaseTest.setUp_testFixtures(); } @@ -54,13 +54,16 @@ contract BridgeRouterRebootTest is RebootTest, BridgeRouterTest { vm.writeJson( vm.toString(tokenRegistryHarnessImpl), outputPath, - bridgeAttributePath(ethereum, "tokenRegistry.implementation") + bridgeAttributePath(localDomainName, "tokenRegistry.implementation") ); reloadConfig(); - pushSingleUpgrade(tokenRegistryUpgrade(ethereum), ethereum); + pushSingleUpgrade( + tokenRegistryUpgrade(localDomainName), + localDomainName + ); prankExecuteRecoveryManager( - address(getGovernanceRouter(ethereum)), - getDomainNumber(ethereum) + address(getGovernanceRouter(localDomainName)), + getDomainNumber(localDomainName) ); } @@ -70,13 +73,16 @@ contract BridgeRouterRebootTest is RebootTest, BridgeRouterTest { vm.writeJson( vm.toString(bridgeRouterHarnessImpl), outputPath, - bridgeAttributePath(ethereum, "bridgeRouter.implementation") + bridgeAttributePath(localDomainName, "bridgeRouter.implementation") ); reloadConfig(); - pushSingleUpgrade(bridgeRouterUpgrade(ethereum), ethereum); + pushSingleUpgrade( + bridgeRouterUpgrade(localDomainName), + localDomainName + ); prankExecuteRecoveryManager( - address(getGovernanceRouter(ethereum)), - getDomainNumber(ethereum) + address(getGovernanceRouter(localDomainName)), + getDomainNumber(localDomainName) ); } @@ -84,11 +90,11 @@ contract BridgeRouterRebootTest is RebootTest, BridgeRouterTest { // check that the harnesses have harness methods available assertEq( bridgeRouterHarnessImpl, - bridgeRouterUpgrade(ethereum).implementation + bridgeRouterUpgrade(localDomainName).implementation ); assertEq( tokenRegistryHarnessImpl, - tokenRegistryUpgrade(ethereum).implementation + tokenRegistryUpgrade(localDomainName).implementation ); bridgeRouter.exposed_dust(address(this)); tokenRegistry.exposed_localDomain(); diff --git a/packages/contracts-ops/contracts/test/RebootEthereumBridgeRouter.t.sol b/packages/contracts-ops/contracts/test/RebootEthereumBridgeRouter.t.sol index 1f6d919a..bc03feca 100644 --- a/packages/contracts-ops/contracts/test/RebootEthereumBridgeRouter.t.sol +++ b/packages/contracts-ops/contracts/test/RebootEthereumBridgeRouter.t.sol @@ -19,31 +19,35 @@ contract EthereumBridgeRouterRebootTest is RebootTest, BridgeRouterTest { address bridgeRouterHarnessImpl; address tokenRegistryHarnessImpl; - string constant ethereum = "ethereum"; - function setUp() public override(BridgeRouterBaseTest, NomadTest) { setUpReboot("ethBridgeRouter"); + require( + keccak256(bytes(localDomainName)) == keccak256(bytes("ethereum")), + "not ethereum bridge router" + ); // load proxies tokenRegistry = TokenRegistryHarness( - address(getTokenRegistry(ethereum)) + address(getTokenRegistry(localDomainName)) ); vm.label(address(tokenRegistry), "tokenRegistry"); - bridgeRouter = IBridgeRouterHarness(address(getBridgeRouter(ethereum))); + bridgeRouter = IBridgeRouterHarness( + address(getBridgeRouter(localDomainName)) + ); vm.label(address(bridgeRouter), "bridgeRouter"); // upgrade to harness setUp_upgradeTokenRegistryHarness(); setUp_upgradeBridgeRouterHarness(); // load necessary contracts - xAppConnectionManager = getXAppConnectionManager(ethereum); + xAppConnectionManager = getXAppConnectionManager(localDomainName); vm.label(address(xAppConnectionManager), "XAppConnectionManager"); - upgradeBeaconController = getUpgradeBeaconController(ethereum); + upgradeBeaconController = getUpgradeBeaconController(localDomainName); vm.label(address(upgradeBeaconController), "upgradeBeaconController"); tokenBeacon = UpgradeBeacon(payable(tokenRegistry.tokenBeacon())); vm.label(address(tokenBeacon), "tokenBeacon"); bridgeToken = BridgeToken(beaconImplementation(tokenBeacon)); vm.label(address(bridgeToken), "bridgeToken"); // home needed for vm.expectCall - home = address(getHome("ethereum")); + home = address(getHome(localDomainName)); vm.label(home, "home"); BridgeRouterBaseTest.setUp_testFixtures(); } @@ -54,31 +58,39 @@ contract EthereumBridgeRouterRebootTest is RebootTest, BridgeRouterTest { vm.writeJson( vm.toString(tokenRegistryHarnessImpl), outputPath, - bridgeAttributePath(ethereum, "tokenRegistry.implementation") + bridgeAttributePath(localDomainName, "tokenRegistry.implementation") ); reloadConfig(); - pushSingleUpgrade(tokenRegistryUpgrade(ethereum), ethereum); + pushSingleUpgrade( + tokenRegistryUpgrade(localDomainName), + localDomainName + ); prankExecuteRecoveryManager( - address(getGovernanceRouter(ethereum)), - getDomainNumber(ethereum) + address(getGovernanceRouter(localDomainName)), + getDomainNumber(localDomainName) ); } function setUp_upgradeBridgeRouterHarness() public { bridgeRouterHarnessImpl = address( - new EthereumBridgeRouterHarness(address(getAccountant(ethereum))) + new EthereumBridgeRouterHarness( + address(getAccountant(localDomainName)) + ) ); vm.label(bridgeRouterHarnessImpl, "bridgeRouterHarnessImpl"); vm.writeJson( vm.toString(bridgeRouterHarnessImpl), outputPath, - bridgeAttributePath(ethereum, "bridgeRouter.implementation") + bridgeAttributePath(localDomainName, "bridgeRouter.implementation") ); reloadConfig(); - pushSingleUpgrade(bridgeRouterUpgrade(ethereum), ethereum); + pushSingleUpgrade( + bridgeRouterUpgrade(localDomainName), + localDomainName + ); prankExecuteRecoveryManager( - address(getGovernanceRouter(ethereum)), - getDomainNumber(ethereum) + address(getGovernanceRouter(localDomainName)), + getDomainNumber(localDomainName) ); } @@ -86,11 +98,11 @@ contract EthereumBridgeRouterRebootTest is RebootTest, BridgeRouterTest { // check that the harnesses have harness methods available assertEq( bridgeRouterHarnessImpl, - bridgeRouterUpgrade(ethereum).implementation + bridgeRouterUpgrade(localDomainName).implementation ); assertEq( tokenRegistryHarnessImpl, - tokenRegistryUpgrade(ethereum).implementation + tokenRegistryUpgrade(localDomainName).implementation ); bridgeRouter.exposed_dust(address(this)); tokenRegistry.exposed_localDomain(); diff --git a/packages/contracts-ops/contracts/test/RebootTokenRegistry.t.sol b/packages/contracts-ops/contracts/test/RebootTokenRegistry.t.sol index 5cfcd3d9..d0a99ffe 100644 --- a/packages/contracts-ops/contracts/test/RebootTokenRegistry.t.sol +++ b/packages/contracts-ops/contracts/test/RebootTokenRegistry.t.sol @@ -16,29 +16,29 @@ import {IBridgeRouterHarness} from "@nomad-xyz/contracts-bridge/contracts/test/h contract TokenRegistryRebootTest is RebootTest, TokenRegistryTest { address tokenRegistryHarnessImpl; - string constant ethereum = "ethereum"; - function setUp() public override(NomadTest, BridgeTestFixture) { setUpReboot("tokenRegistry"); tokenRegistry = TokenRegistryHarness( - address(getTokenRegistry(ethereum)) + address(getTokenRegistry(localDomainName)) ); vm.label(address(tokenRegistry), "tokenRegistry"); - bridgeRouter = IBridgeRouterHarness(address(getBridgeRouter(ethereum))); + bridgeRouter = IBridgeRouterHarness( + address(getBridgeRouter(localDomainName)) + ); vm.label(address(bridgeRouter), "bridgeRouter"); // upgrade to harness setUp_upgradeTokenRegistryHarness(); // load necessary contracts - xAppConnectionManager = getXAppConnectionManager(ethereum); + xAppConnectionManager = getXAppConnectionManager(localDomainName); vm.label(address(xAppConnectionManager), "XAppConnectionManager"); - upgradeBeaconController = getUpgradeBeaconController(ethereum); + upgradeBeaconController = getUpgradeBeaconController(localDomainName); vm.label(address(upgradeBeaconController), "upgradeBeaconController"); tokenBeacon = UpgradeBeacon(payable(tokenRegistry.tokenBeacon())); vm.label(address(tokenBeacon), "tokenBeacon"); bridgeToken = BridgeToken(beaconImplementation(tokenBeacon)); vm.label(address(bridgeToken), "bridgeToken"); // home needed for vm.expectCall - home = address(getHome(ethereum)); + home = address(getHome(localDomainName)); vm.label(home, "home"); // BridgeTestFixture.setUp_testFixtures() setUp_testFixtures(); @@ -50,13 +50,16 @@ contract TokenRegistryRebootTest is RebootTest, TokenRegistryTest { vm.writeJson( vm.toString(tokenRegistryHarnessImpl), outputPath, - bridgeAttributePath(ethereum, "tokenRegistry.implementation") + bridgeAttributePath(localDomainName, "tokenRegistry.implementation") ); reloadConfig(); - pushSingleUpgrade(tokenRegistryUpgrade(ethereum), ethereum); + pushSingleUpgrade( + tokenRegistryUpgrade(localDomainName), + localDomainName + ); prankExecuteRecoveryManager( - address(getGovernanceRouter(ethereum)), - getDomainNumber(ethereum) + address(getGovernanceRouter(localDomainName)), + getDomainNumber(localDomainName) ); } }