diff --git a/packages/contracts-core/contracts/test/GovernanceRouter.t.sol b/packages/contracts-core/contracts/test/GovernanceRouter.t.sol index 07d29f13..52eac0e2 100644 --- a/packages/contracts-core/contracts/test/GovernanceRouter.t.sol +++ b/packages/contracts-core/contracts/test/GovernanceRouter.t.sol @@ -853,7 +853,7 @@ contract GovernanceRouterTest is NomadTest { // todo: expectNoCall Home.Dispatch vm.expectEmit(true, true, true, true); emit TransferGovernor( - homeDomain, + governanceRouter.governorDomain(), newDomain, governanceRouter.governor(), newGovernor @@ -889,7 +889,7 @@ contract GovernanceRouterTest is NomadTest { // todo: expectNoCall Home.Dispatch vm.expectEmit(true, true, true, true); emit TransferGovernor( - homeDomain, + governanceRouter.governorDomain(), newDomain, governanceRouter.governor(), newGovernor diff --git a/packages/contracts-core/contracts/test/Home.t.sol b/packages/contracts-core/contracts/test/Home.t.sol index e9c1aefd..2bc666f3 100644 --- a/packages/contracts-core/contracts/test/Home.t.sol +++ b/packages/contracts-core/contracts/test/Home.t.sol @@ -128,6 +128,18 @@ contract HomeTest is NomadTestWithUpdaterManager { assert(!home.queueContains(newRoot)); } + function test_notUpdaterSig() public { + dispatchTestMessage(); + bytes32 newRoot = home.root(); + bytes32 oldRoot = home.committedRoot(); + uint256 randomFakePk = 777; + bytes memory sig = signHomeUpdate(randomFakePk, oldRoot, newRoot); + vm.expectRevert("!updater sig"); + home.update(oldRoot, newRoot, sig); + assertEq(oldRoot, home.committedRoot()); + assert(home.queueContains(newRoot)); + } + function test_udpdateMultipleMessages() public { dispatchTestMessage(); dispatchTestMessage(); diff --git a/packages/contracts-ops/contracts/Config.sol b/packages/contracts-ops/contracts/Config.sol index c2437fbf..bde44417 100644 --- a/packages/contracts-ops/contracts/Config.sol +++ b/packages/contracts-ops/contracts/Config.sol @@ -243,11 +243,11 @@ abstract contract Config is INomadProtocol { ); } - function getGovernorDomain() public view override returns (uint256) { + function getGovernorDomain() public view override returns (uint32) { return abi.decode( vm.parseJson(config, ".protocol.governor.domain"), - (uint256) + (uint32) ); } @@ -424,7 +424,7 @@ abstract contract Config is INomadProtocol { function protocolConfigAttributePath( string memory domain, string memory key - ) private pure returns (string memory) { + ) internal pure returns (string memory) { return string(abi.encodePacked(protocolConfigPath(domain), ".", key)); } @@ -466,6 +466,20 @@ abstract contract Config is INomadProtocol { ); } + function getDomainName(uint32 _domainNumber) + public + view + returns (string memory) + { + string[] memory networks = getNetworks(); + for (uint256 i; i < networks.length; i++) { + if (getDomainNumber(networks[i]) == _domainNumber) { + return networks[i]; + } + } + revert("domain name not found"); + } + function getDomainNumber(string memory domain) public view @@ -583,7 +597,7 @@ abstract contract Config is INomadProtocol { contract TestJson is Test, Config { function setUp() public { // solhint-disable-next-line quotes - config = '{ "networks": ["avalanche", "ethereum"], "protocol": { "networks": { "avalanche": { "bridgeConfiguration": { "accountant": { "owner": "0x0000011111222223333344444555557777799999" }}}}, "governor": {"domain": 6648936, "id": "0x93277b8f5939975b9e6694d5fd2837143afbf68a"}}, "core": {"ethereum": {"deployHeight": 1234, "governanceRouter": {"proxy":"0x569D80f7FC17316B4C83f072b92EF37B72819DE0","implementation":"0x569D80f7FC17316B4C83f072b92EF37B72819DE0","beacon":"0x569D80f7FC17316B4C83f072b92EF37B72819DE0"}, "ethHelper": "0x999d80F7FC17316b4c83f072b92EF37b72718De0"}}}'; + config = '{ "networks": ["avalanche", "ethereum"], "protocol": { "networks": { "avalanche": { "bridgeConfiguration": { "accountant": { "owner": "0x0000011111222223333344444555557777799999" }}, "configuration": { "updater": "0x5067c8a9cBf708f885195aA318F8d7A3f2f5D112"}, "domain": 1635148152}}, "governor": {"domain": 6648936, "id": "0x93277b8f5939975b9e6694d5fd2837143afbf68a"}}, "core": {"ethereum": {"deployHeight": 1234, "governanceRouter": {"proxy":"0x569D80f7FC17316B4C83f072b92EF37B72819DE0","implementation":"0x569D80f7FC17316B4C83f072b92EF37B72819DE0","beacon":"0x569D80f7FC17316B4C83f072b92EF37B72819DE0"}, "ethHelper": "0x999d80F7FC17316b4c83f072b92EF37b72718De0"}}}'; } function test_Json() public { @@ -593,6 +607,11 @@ contract TestJson is Test, Config { ); vm.expectRevert("no ethHelper for randomDomain"); getEthHelper("randomDomain"); + assertEq( + getUpdater("avalanche"), + 0x5067c8a9cBf708f885195aA318F8d7A3f2f5D112 + ); + assertEq(getDomainName(1635148152), "avalanche"); assertEq(getNetworks()[0], "avalanche"); assertEq( getFundsRecipient("avalanche"), diff --git a/packages/contracts-ops/contracts/test/Reboot.t.sol b/packages/contracts-ops/contracts/test/Reboot.t.sol index 85e70e32..a7c60f13 100644 --- a/packages/contracts-ops/contracts/test/Reboot.t.sol +++ b/packages/contracts-ops/contracts/test/Reboot.t.sol @@ -7,7 +7,7 @@ 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"; function setUpReboot(string memory testName) public { // ALL @@ -25,15 +25,37 @@ 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 + // basic vars + string memory governorDomainName = getDomainName(getGovernorDomain()); + if ( + keccak256(bytes(localDomainName)) == + keccak256(bytes(governorDomainName)) + ) { + remote = getConnections(localDomainName)[0]; + } else { + remote = governorDomainName; + } + remoteDomain = getDomainNumber(remote); + homeDomain = getDomainNumber(localDomainName); + // set fake updater for remote chain replica // before updater rotation, so it will be rotated on-chain vm.writeJson( vm.toString(updaterAddr), outputPath, - protocolAttributePath(remote, "updater") + protocolConfigAttributePath(localDomainName, "updater") + ); + vm.writeJson( + vm.toString(updaterAddr), + outputPath, + protocolConfigAttributePath(remote, "updater") ); reloadConfig(); // perform reboot actions @@ -43,9 +65,5 @@ contract RebootTest is RebootLogic, NomadTest { address(getGovernanceRouter(localDomainName)), getDomainNumber(localDomainName) ); - // basic vars - remote = getConnections(localDomainName)[0]; - remoteDomain = getDomainNumber(remote); - homeDomain = getDomainNumber(localDomainName); } } 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) ); } } diff --git a/packages/contracts-ops/contracts/test/utils/INomadProtocol.sol b/packages/contracts-ops/contracts/test/utils/INomadProtocol.sol index d05fbd29..22ae258e 100644 --- a/packages/contracts-ops/contracts/test/utils/INomadProtocol.sol +++ b/packages/contracts-ops/contracts/test/utils/INomadProtocol.sol @@ -31,7 +31,7 @@ interface INomadProtocol { function getGovernor() external returns (address); - function getGovernorDomain() external returns (uint256); + function getGovernorDomain() external returns (uint32); function getUpdater(string memory domain) external returns (address);