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

fix: eth reboot tests #565

Open
wants to merge 4 commits into
base: anna/fork-multi
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity 0.7.6;

import {TypeCasts} from "@nomad-xyz/contracts-core/contracts/libs/TypeCasts.sol";
import {BridgeRouterBaseTest} from "./BridgeRouterBase.t.sol";
import {EventAccountant} from "../accountants/EventAccountant.sol";

contract EthereumBridgeRouterTest is BridgeRouterBaseTest {
using TypeCasts for bytes32;
Expand Down Expand Up @@ -35,21 +36,26 @@ contract EthereumBridgeRouterTest is BridgeRouterBaseTest {
vm.expectEmit(true, true, false, true, address(localToken));
emit Transfer(address(bridgeRouter), recipient, amount);
bridgeRouter.exposed_giveLocal(address(localToken), amount, recipient);
}

function test_giveLocalAffected() public {
uint256 amount = 1000;
address recipient = address(33);
// test with each affected tokens
// This checks for events on the mock accountant
// Accountant logic is tested separately
address payable[14] memory affected = accountant.affectedAssets();
for (uint256 i = 0; i < affected.length; i++) {
address a = affected[i];
vm.expectEmit(
true,
true,
false,
true,
address(bridgeRouter.accountant())
vm.expectCall(
address(accountant),
abi.encodeWithSelector(
EventAccountant.record.selector,
a,
recipient,
amount
)
);
emit MockAcctCalled(a, recipient, amount);
bridgeRouter.exposed_giveLocal(a, amount, recipient);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,9 @@ contract BridgeTestFixture is NomadTest {
mockUpdaterPK = 420;
mockUpdater = vm.addr(mockUpdaterPK);
remoteBridgeRouter = vm.addr(99123).addressToBytes32();
accountant = NFTRecoveryAccountantHarness(
address(new MockAccountant())
);
mockHome = new MockHome(homeDomain);
home = address(mockHome);
mockReplica = address(0xBEEFEFEEFEF);

// Create implementations
tokenRegistry = new TokenRegistryHarness();
xAppConnectionManager = new XAppConnectionManager();
Expand All @@ -122,6 +118,11 @@ contract BridgeTestFixture is NomadTest {
);
// Tests that concern the EThereumBridgeRouter, they will already have called
// setUpEthereumBridgeRouter(), which means that the address will not be address(0)
if (address(accountant) == address(0)) {
accountant = NFTRecoveryAccountantHarness(
address(new MockAccountant())
);
}
if (address(bridgeRouter) == address(0)) {
setUpBridgeRouter();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts-ops/contracts/test/Reboot.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {NomadTest} from "@nomad-xyz/contracts-core/contracts/test/utils/NomadTes
contract RebootTest is RebootLogic, NomadTest {
string remote;
string constant testDomain = "ethereum";
uint256 constant testDomainBlock = 15_977_624;
uint256 constant testDomainBlock = 16_083_970;

function setUpReboot(string memory testName) public {
// ALL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,23 @@ import {UpgradeBeacon} from "@nomad-xyz/contracts-core/contracts/upgrade/Upgrade
import {NomadTest} from "@nomad-xyz/contracts-core/contracts/test/utils/NomadTest.sol";
import {BridgeTestFixture} from "@nomad-xyz/contracts-bridge/contracts/test/utils/BridgeTest.sol";
import {BridgeRouterBaseTest} from "@nomad-xyz/contracts-bridge/contracts/test/BridgeRouterBase.t.sol";
import {BridgeRouterTest} from "@nomad-xyz/contracts-bridge/contracts/test/BridgeRouter.t.sol";
import {EthereumBridgeRouterTest} from "@nomad-xyz/contracts-bridge/contracts/test/EthereumBridgeRouter.t.sol";
import {NFTRecoveryAccountantHarness} from "@nomad-xyz/contracts-bridge/contracts/test/harness/NFTAccountantHarness.sol";
import {EthereumBridgeRouterHarness} from "@nomad-xyz/contracts-bridge/contracts/test/harness/BridgeRouterHarness.sol";
import {TokenRegistryHarness} from "@nomad-xyz/contracts-bridge/contracts/test/harness/TokenRegistryHarness.sol";
import {IBridgeRouterHarness} from "@nomad-xyz/contracts-bridge/contracts/test/harness/IBridgeRouterHarness.sol";
import {BridgeToken} from "@nomad-xyz/contracts-bridge/contracts/BridgeToken.sol";
import {TokenRegistry} from "@nomad-xyz/contracts-bridge/contracts/TokenRegistry.sol";

contract EthereumBridgeRouterRebootTest is RebootTest, BridgeRouterTest {
contract EthereumBridgeRouterRebootTest is
RebootTest,
EthereumBridgeRouterTest
{
address bridgeRouterHarnessImpl;
address accountantHarnessImpl;
address tokenRegistryHarnessImpl;

function setUp() public override(BridgeRouterBaseTest, NomadTest) {
function setUp() public override(EthereumBridgeRouterTest, NomadTest) {
setUpReboot("ethBridgeRouter");
require(
keccak256(bytes(localDomainName)) == keccak256(bytes("ethereum")),
Expand All @@ -34,9 +39,14 @@ contract EthereumBridgeRouterRebootTest is RebootTest, BridgeRouterTest {
address(getBridgeRouter(localDomainName))
);
vm.label(address(bridgeRouter), "bridgeRouter");
accountant = NFTRecoveryAccountantHarness(
address(getAccountant(localDomainName))
);
vm.label(address(accountant), "accountant");
// upgrade to harness
setUp_upgradeTokenRegistryHarness();
setUp_upgradeBridgeRouterHarness();
setUp_upgradeAccountantHarness();
// load necessary contracts
xAppConnectionManager = getXAppConnectionManager(localDomainName);
vm.label(address(xAppConnectionManager), "XAppConnectionManager");
Expand Down Expand Up @@ -94,8 +104,36 @@ contract EthereumBridgeRouterRebootTest is RebootTest, BridgeRouterTest {
);
}

function setUp_upgradeAccountantHarness() public {
accountantHarnessImpl = address(
new NFTRecoveryAccountantHarness(
address(getBridgeRouter(localDomainName)),
address(getFundsRecipient(localDomainName))
)
);
vm.label(accountantHarnessImpl, "accountantHarnessImpl");
vm.writeJson(
vm.toString(accountantHarnessImpl),
outputPath,
bridgeAttributePath(localDomainName, "accountant.implementation")
);
reloadConfig();
pushSingleUpgrade(accountantUpgrade(localDomainName), localDomainName);
prankExecuteRecoveryManager(
address(getGovernanceRouter(localDomainName)),
getDomainNumber(localDomainName)
);
}

function test_setUp_rebootBridgeRouter() public {
// check that the harnesses have harness methods available
assertEq(
address(accountant),
address(
EthereumBridgeRouterHarness(address(getBridgeRouter(localDomainName)))
.accountant()
)
);
assertEq(
bridgeRouterHarnessImpl,
bridgeRouterUpgrade(localDomainName).implementation
Expand All @@ -104,6 +142,10 @@ contract EthereumBridgeRouterRebootTest is RebootTest, BridgeRouterTest {
tokenRegistryHarnessImpl,
tokenRegistryUpgrade(localDomainName).implementation
);
assertEq(
accountantHarnessImpl,
accountantUpgrade(localDomainName).implementation
);
bridgeRouter.exposed_dust(address(this));
tokenRegistry.exposed_localDomain();
}
Expand Down