Skip to content

Commit

Permalink
Use additional parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
wcgcyx committed Dec 12, 2023
1 parent a5b0544 commit 2929d67
Show file tree
Hide file tree
Showing 21 changed files with 69 additions and 68 deletions.
4 changes: 2 additions & 2 deletions src/child/ChildAxelarBridgeAdaptor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ contract ChildAxelarBridgeAdaptor is
/// @notice Address of the authorized initializer.
address public immutable initializerAddress;

constructor(address _gateway) AxelarExecutable(_gateway) {
initializerAddress = msg.sender;
constructor(address _gateway, address _initializerAddress) AxelarExecutable(_gateway) {
initializerAddress = _initializerAddress;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/child/ChildERC20Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ contract ChildERC20Bridge is
_;
}

constructor() {
initializerAddress = msg.sender;
constructor(address _initializerAddress) {
initializerAddress = _initializerAddress;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/root/RootAxelarBridgeAdaptor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ contract RootAxelarBridgeAdaptor is
/// @notice Address of the authorized initializer.
address public immutable initializerAddress;

constructor(address _gateway) AxelarExecutable(_gateway) {
initializerAddress = msg.sender;
constructor(address _gateway, address _initializerAddress) AxelarExecutable(_gateway) {
initializerAddress = _initializerAddress;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/root/RootERC20Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ contract RootERC20Bridge is
_;
}

constructor() {
initializerAddress = msg.sender;
constructor(address _initializerAddress) {
initializerAddress = _initializerAddress;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/root/flowrate/RootERC20BridgeFlowRate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ contract RootERC20BridgeFlowRate is
// Map ERC 20 token address to threshold
mapping(address => uint256) public largeTransferThresholds;

constructor() RootERC20Bridge() {}
constructor(address _initializerAddress) RootERC20Bridge(_initializerAddress) {}

function initialize(
InitializationRoles memory newRoles,
Expand Down
4 changes: 2 additions & 2 deletions test/integration/child/ChildAxelarBridge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ contract ChildERC20BridgeIntegrationTest is Test, IChildERC20BridgeEvents, IChil
childERC20 = new ChildERC20();
childERC20.initialize(address(123), "Test", "TST", 18);

childERC20Bridge = new ChildERC20Bridge();
childERC20Bridge = new ChildERC20Bridge(address(this));
mockChildAxelarGateway = new MockChildAxelarGateway();
mockChildAxelarGasService = new MockChildAxelarGasService();
childAxelarBridgeAdaptor = new ChildAxelarBridgeAdaptor(address(mockChildAxelarGateway));
childAxelarBridgeAdaptor = new ChildAxelarBridgeAdaptor(address(mockChildAxelarGateway), address(this));

IChildERC20Bridge.InitializationRoles memory roles = IChildERC20Bridge.InitializationRoles({
defaultAdmin: address(this),
Expand Down
20 changes: 10 additions & 10 deletions test/unit/child/ChildAxelarBridgeAdaptor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ contract ChildAxelarBridgeAdaptorUnitTest is Test, IChildAxelarBridgeAdaptorErro
mockChildERC20Bridge = new MockChildERC20Bridge();
mockChildAxelarGateway = new MockChildAxelarGateway();
mockChildAxelarGasService = new MockChildAxelarGasService();
axelarAdaptor = new ChildAxelarBridgeAdaptor(address(mockChildAxelarGateway));
axelarAdaptor = new ChildAxelarBridgeAdaptor(address(mockChildAxelarGateway), address(this));
axelarAdaptor.initialize(
roles,
address(mockChildERC20Bridge),
Expand Down Expand Up @@ -77,7 +77,7 @@ contract ChildAxelarBridgeAdaptorUnitTest is Test, IChildAxelarBridgeAdaptorErro
}

function test_RevertIf_InitializeWithUnauthorizedInitializer() public {
ChildAxelarBridgeAdaptor newAdaptor = new ChildAxelarBridgeAdaptor(GATEWAY_ADDRESS);
ChildAxelarBridgeAdaptor newAdaptor = new ChildAxelarBridgeAdaptor(GATEWAY_ADDRESS, address(this));
vm.prank(address(0x1234));
vm.expectRevert(UnauthorizedInitializer.selector);
newAdaptor.initialize(
Expand All @@ -90,7 +90,7 @@ contract ChildAxelarBridgeAdaptorUnitTest is Test, IChildAxelarBridgeAdaptorErro
}

function test_RevertIf_InitializeWithZeroAdmin() public {
ChildAxelarBridgeAdaptor newAdaptor = new ChildAxelarBridgeAdaptor(GATEWAY_ADDRESS);
ChildAxelarBridgeAdaptor newAdaptor = new ChildAxelarBridgeAdaptor(GATEWAY_ADDRESS, address(this));
vm.expectRevert(ZeroAddress.selector);
roles.defaultAdmin = address(0);
newAdaptor.initialize(
Expand All @@ -103,7 +103,7 @@ contract ChildAxelarBridgeAdaptorUnitTest is Test, IChildAxelarBridgeAdaptorErro
}

function test_RevertIf_InitializeWithZeroBridgeManager() public {
ChildAxelarBridgeAdaptor newAdaptor = new ChildAxelarBridgeAdaptor(GATEWAY_ADDRESS);
ChildAxelarBridgeAdaptor newAdaptor = new ChildAxelarBridgeAdaptor(GATEWAY_ADDRESS, address(this));
vm.expectRevert(ZeroAddress.selector);
roles.bridgeManager = address(0);
newAdaptor.initialize(
Expand All @@ -116,7 +116,7 @@ contract ChildAxelarBridgeAdaptorUnitTest is Test, IChildAxelarBridgeAdaptorErro
}

function test_RevertIf_InitializeWithZeroGasServiceManager() public {
ChildAxelarBridgeAdaptor newAdaptor = new ChildAxelarBridgeAdaptor(GATEWAY_ADDRESS);
ChildAxelarBridgeAdaptor newAdaptor = new ChildAxelarBridgeAdaptor(GATEWAY_ADDRESS, address(this));
vm.expectRevert(ZeroAddress.selector);
roles.gasServiceManager = address(0);
newAdaptor.initialize(
Expand All @@ -129,7 +129,7 @@ contract ChildAxelarBridgeAdaptorUnitTest is Test, IChildAxelarBridgeAdaptorErro
}

function test_RevertIf_InitializeWithZeroTargetManager() public {
ChildAxelarBridgeAdaptor newAdaptor = new ChildAxelarBridgeAdaptor(GATEWAY_ADDRESS);
ChildAxelarBridgeAdaptor newAdaptor = new ChildAxelarBridgeAdaptor(GATEWAY_ADDRESS, address(this));
vm.expectRevert(ZeroAddress.selector);
roles.targetManager = address(0);
newAdaptor.initialize(
Expand All @@ -142,31 +142,31 @@ contract ChildAxelarBridgeAdaptorUnitTest is Test, IChildAxelarBridgeAdaptorErro
}

function test_RevertIf_InitializeGivenZeroAddress() public {
ChildAxelarBridgeAdaptor newAdaptor = new ChildAxelarBridgeAdaptor(GATEWAY_ADDRESS);
ChildAxelarBridgeAdaptor newAdaptor = new ChildAxelarBridgeAdaptor(GATEWAY_ADDRESS, address(this));
vm.expectRevert(ZeroAddress.selector);
newAdaptor.initialize(
roles, address(0), ROOT_CHAIN_NAME, ROOT_BRIDGE_ADAPTOR, address(mockChildAxelarGasService)
);
}

function test_RevertIf_InitializeGivenEmptyRootChain() public {
ChildAxelarBridgeAdaptor newAdaptor = new ChildAxelarBridgeAdaptor(GATEWAY_ADDRESS);
ChildAxelarBridgeAdaptor newAdaptor = new ChildAxelarBridgeAdaptor(GATEWAY_ADDRESS, address(this));
vm.expectRevert(InvalidRootChain.selector);
newAdaptor.initialize(
roles, address(mockChildERC20Bridge), "", ROOT_BRIDGE_ADAPTOR, address(mockChildAxelarGasService)
);
}

function test_RevertIf_InitializeGivenAnEmptyBridgeAdaptorString() public {
ChildAxelarBridgeAdaptor newAdaptor = new ChildAxelarBridgeAdaptor(GATEWAY_ADDRESS);
ChildAxelarBridgeAdaptor newAdaptor = new ChildAxelarBridgeAdaptor(GATEWAY_ADDRESS, address(this));
vm.expectRevert(InvalidRootBridgeAdaptor.selector);
newAdaptor.initialize(
roles, address(mockChildERC20Bridge), ROOT_CHAIN_NAME, "", address(mockChildAxelarGasService)
);
}

function test_RevertIf_InitializeGivenZeroGasService() public {
ChildAxelarBridgeAdaptor newAdaptor = new ChildAxelarBridgeAdaptor(GATEWAY_ADDRESS);
ChildAxelarBridgeAdaptor newAdaptor = new ChildAxelarBridgeAdaptor(GATEWAY_ADDRESS, address(this));
vm.expectRevert(ZeroAddress.selector);
newAdaptor.initialize(roles, address(mockChildERC20Bridge), ROOT_CHAIN_NAME, ROOT_BRIDGE_ADAPTOR, address(0));
}
Expand Down
20 changes: 10 additions & 10 deletions test/unit/child/ChildERC20Bridge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ contract ChildERC20BridgeUnitTest is Test, IChildERC20BridgeEvents, IChildERC20B
childTokenTemplate = new ChildERC20();
childTokenTemplate.initialize(address(123), "Test", "TST", 18);

childBridge = new ChildERC20Bridge();
childBridge = new ChildERC20Bridge(address(this));

childBridge.initialize(roles, address(this), address(childTokenTemplate), ROOT_IMX_TOKEN, CHILD_WIMX_TOKEN);
}
Expand Down Expand Up @@ -165,7 +165,7 @@ contract ChildERC20BridgeUnitTest is Test, IChildERC20BridgeEvents, IChildERC20B
}

function test_RevertIf_InitializeWithUnauthorizedInitializer() public {
ChildERC20Bridge bridge = new ChildERC20Bridge();
ChildERC20Bridge bridge = new ChildERC20Bridge(address(this));
vm.prank(address(0x1234));
vm.expectRevert(UnauthorizedInitializer.selector);
bridge.initialize(roles, address(1), address(1), address(1), address(1));
Expand All @@ -177,54 +177,54 @@ contract ChildERC20BridgeUnitTest is Test, IChildERC20BridgeEvents, IChildERC20B
}

function test_RevertIf_InitializeWithAZeroAddressDefaultAdmin() public {
ChildERC20Bridge bridge = new ChildERC20Bridge();
ChildERC20Bridge bridge = new ChildERC20Bridge(address(this));
roles.defaultAdmin = address(0);
vm.expectRevert(ZeroAddress.selector);
bridge.initialize(roles, address(1), address(1), address(1), address(1));
}

function test_RevertIf_InitializeWithAZeroAddressPauser() public {
ChildERC20Bridge bridge = new ChildERC20Bridge();
ChildERC20Bridge bridge = new ChildERC20Bridge(address(this));
roles.pauser = address(0);
vm.expectRevert(ZeroAddress.selector);
bridge.initialize(roles, address(1), address(1), address(1), address(1));
}

function test_RevertIf_InitializeWithAZeroAddressUnpauser() public {
ChildERC20Bridge bridge = new ChildERC20Bridge();
ChildERC20Bridge bridge = new ChildERC20Bridge(address(this));
roles.unpauser = address(0);
vm.expectRevert(ZeroAddress.selector);
bridge.initialize(roles, address(1), address(1), address(1), address(1));
}

function test_RevertIf_InitializeWithAZeroAddressAdapter() public {
ChildERC20Bridge bridge = new ChildERC20Bridge();
ChildERC20Bridge bridge = new ChildERC20Bridge(address(this));
roles.adaptorManager = address(0);
vm.expectRevert(ZeroAddress.selector);
bridge.initialize(roles, address(0), address(1), address(1), address(1));
}

function test_RevertIf_InitializeWithAZeroAddressTreasuryManager() public {
ChildERC20Bridge bridge = new ChildERC20Bridge();
ChildERC20Bridge bridge = new ChildERC20Bridge(address(this));
roles.treasuryManager = address(0);
vm.expectRevert(ZeroAddress.selector);
bridge.initialize(roles, address(1), address(1), address(1), address(1));
}

function test_RevertIf_InitializeWithAZeroAddressChildTemplate() public {
ChildERC20Bridge bridge = new ChildERC20Bridge();
ChildERC20Bridge bridge = new ChildERC20Bridge(address(this));
vm.expectRevert(ZeroAddress.selector);
bridge.initialize(roles, address(1), address(0), address(1), address(1));
}

function test_RevertIf_InitializeWithAZeroAddressIMXToken() public {
ChildERC20Bridge bridge = new ChildERC20Bridge();
ChildERC20Bridge bridge = new ChildERC20Bridge(address(this));
vm.expectRevert(ZeroAddress.selector);
bridge.initialize(roles, address(1), address(1), address(0), address(1));
}

function test_RevertIf_InitializeWithAZeroAddressAll() public {
ChildERC20Bridge bridge = new ChildERC20Bridge();
ChildERC20Bridge bridge = new ChildERC20Bridge(address(this));
vm.expectRevert(ZeroAddress.selector);
roles.defaultAdmin = address(0);
roles.pauser = address(0);
Expand Down
2 changes: 1 addition & 1 deletion test/unit/child/withdrawals/ChildERC20BridgeWithdraw.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ contract ChildERC20BridgeWithdrawUnitTest is Test, IChildERC20BridgeEvents, IChi
initialDepositor: address(this),
treasuryManager: address(this)
});
childBridge = new ChildERC20Bridge();
childBridge = new ChildERC20Bridge(address(this));
childBridge.initialize(
roles, address(mockAdaptor), address(childTokenTemplate), ROOT_IMX_TOKEN, WIMX_TOKEN_ADDRESS
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ contract ChildERC20BridgeWithdrawETHUnitTest is Test, IChildERC20BridgeEvents, I

mockAdaptor = new MockAdaptor();

childBridge = new ChildERC20Bridge();
childBridge = new ChildERC20Bridge(address(this));
IChildERC20Bridge.InitializationRoles memory roles = IChildERC20Bridge.InitializationRoles({
defaultAdmin: address(this),
pauser: pauser,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ contract ChildERC20BridgeWithdrawETHToUnitTest is Test, IChildERC20BridgeEvents,

mockAdaptor = new MockAdaptor();

childBridge = new ChildERC20Bridge();
childBridge = new ChildERC20Bridge(address(this));
IChildERC20Bridge.InitializationRoles memory roles = IChildERC20Bridge.InitializationRoles({
defaultAdmin: address(this),
pauser: pauser,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ contract ChildERC20BridgeWithdrawIMXUnitTest is Test, IChildERC20BridgeEvents, I

mockAdaptor = new MockAdaptor();

childBridge = new ChildERC20Bridge();
childBridge = new ChildERC20Bridge(address(this));
IChildERC20Bridge.InitializationRoles memory roles = IChildERC20Bridge.InitializationRoles({
defaultAdmin: address(this),
pauser: pauser,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ contract ChildERC20BridgeWithdrawIMXToUnitTest is Test, IChildERC20BridgeEvents,

mockAdaptor = new MockAdaptor();

childBridge = new ChildERC20Bridge();
childBridge = new ChildERC20Bridge(address(this));
IChildERC20Bridge.InitializationRoles memory roles = IChildERC20Bridge.InitializationRoles({
defaultAdmin: address(this),
pauser: pauser,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ contract ChildERC20BridgeWithdrawToUnitTest is Test, IChildERC20BridgeEvents, IC
initialDepositor: address(this),
treasuryManager: address(this)
});
childBridge = new ChildERC20Bridge();
childBridge = new ChildERC20Bridge(address(this));
childBridge.initialize(
roles, address(mockAdaptor), address(childTokenTemplate), ROOT_IMX_TOKEN, WIMX_TOKEN_ADDRESS
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ contract ChildERC20BridgeWithdrawWIMXUnitTest is Test, IChildERC20BridgeEvents,
wIMXToken = new WIMX();
Address.sendValue(payable(wIMXToken), 100 ether);

childBridge = new ChildERC20Bridge();
childBridge = new ChildERC20Bridge(address(this));
IChildERC20Bridge.InitializationRoles memory roles = IChildERC20Bridge.InitializationRoles({
defaultAdmin: address(this),
pauser: pauser,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ contract ChildERC20BridgeWithdrawWIMXToUnitTest is Test, IChildERC20BridgeEvents
wIMXToken = new WIMX();
Address.sendValue(payable(wIMXToken), 100 ether);

childBridge = new ChildERC20Bridge();
childBridge = new ChildERC20Bridge(address(this));
IChildERC20Bridge.InitializationRoles memory roles = IChildERC20Bridge.InitializationRoles({
defaultAdmin: address(this),
pauser: pauser,
Expand Down
18 changes: 9 additions & 9 deletions test/unit/root/RootAxelarBridgeAdaptor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ contract RootAxelarBridgeAdaptorTest is Test, IRootAxelarBridgeAdaptorEvents, IR
token = new ERC20PresetMinterPauser("Test", "TST");
mockAxelarGateway = new MockAxelarGateway();
axelarGasService = new MockAxelarGasService();
axelarAdaptor = new RootAxelarBridgeAdaptor(address(mockAxelarGateway));
axelarAdaptor = new RootAxelarBridgeAdaptor(address(mockAxelarGateway), address(this));
stubRootBridge = new StubRootBridge();
axelarAdaptor.initialize(
roles, address(stubRootBridge), CHILD_CHAIN_NAME, CHILD_BRIDGE_ADAPTOR_STRING, address(axelarGasService)
Expand Down Expand Up @@ -77,7 +77,7 @@ contract RootAxelarBridgeAdaptorTest is Test, IRootAxelarBridgeAdaptorEvents, IR
}

function test_RevertIf_InitializeWithUnauthorizedInitializer() public {
RootAxelarBridgeAdaptor newAdaptor = new RootAxelarBridgeAdaptor(address(mockAxelarGateway));
RootAxelarBridgeAdaptor newAdaptor = new RootAxelarBridgeAdaptor(address(mockAxelarGateway), address(this));
vm.prank(address(0x1234));
vm.expectRevert(UnauthorizedInitializer.selector);
newAdaptor.initialize(
Expand All @@ -86,7 +86,7 @@ contract RootAxelarBridgeAdaptorTest is Test, IRootAxelarBridgeAdaptorEvents, IR
}

function test_RevertIf_InitializeWithZeroAdmin() public {
RootAxelarBridgeAdaptor newAdaptor = new RootAxelarBridgeAdaptor(address(mockAxelarGateway));
RootAxelarBridgeAdaptor newAdaptor = new RootAxelarBridgeAdaptor(address(mockAxelarGateway), address(this));
vm.expectRevert(ZeroAddresses.selector);
roles.defaultAdmin = address(0);
newAdaptor.initialize(
Expand All @@ -95,7 +95,7 @@ contract RootAxelarBridgeAdaptorTest is Test, IRootAxelarBridgeAdaptorEvents, IR
}

function test_RevertIf_InitializeWithZeroBridgeManager() public {
RootAxelarBridgeAdaptor newAdaptor = new RootAxelarBridgeAdaptor(address(mockAxelarGateway));
RootAxelarBridgeAdaptor newAdaptor = new RootAxelarBridgeAdaptor(address(mockAxelarGateway), address(this));
vm.expectRevert(ZeroAddresses.selector);
roles.bridgeManager = address(0);
newAdaptor.initialize(
Expand All @@ -104,7 +104,7 @@ contract RootAxelarBridgeAdaptorTest is Test, IRootAxelarBridgeAdaptorEvents, IR
}

function test_RevertIf_InitializeWithZeroGasServiceManager() public {
RootAxelarBridgeAdaptor newAdaptor = new RootAxelarBridgeAdaptor(address(mockAxelarGateway));
RootAxelarBridgeAdaptor newAdaptor = new RootAxelarBridgeAdaptor(address(mockAxelarGateway), address(this));
vm.expectRevert(ZeroAddresses.selector);
roles.gasServiceManager = address(0);
newAdaptor.initialize(
Expand All @@ -113,7 +113,7 @@ contract RootAxelarBridgeAdaptorTest is Test, IRootAxelarBridgeAdaptorEvents, IR
}

function test_RevertIf_InitializeWithZeroTargetManager() public {
RootAxelarBridgeAdaptor newAdaptor = new RootAxelarBridgeAdaptor(address(mockAxelarGateway));
RootAxelarBridgeAdaptor newAdaptor = new RootAxelarBridgeAdaptor(address(mockAxelarGateway), address(this));
vm.expectRevert(ZeroAddresses.selector);
roles.targetManager = address(0);
newAdaptor.initialize(
Expand All @@ -122,21 +122,21 @@ contract RootAxelarBridgeAdaptorTest is Test, IRootAxelarBridgeAdaptorEvents, IR
}

function test_RevertIf_InitializeGivenZeroAddress() public {
RootAxelarBridgeAdaptor newAdaptor = new RootAxelarBridgeAdaptor(address(mockAxelarGateway));
RootAxelarBridgeAdaptor newAdaptor = new RootAxelarBridgeAdaptor(address(mockAxelarGateway), address(this));
vm.expectRevert(ZeroAddresses.selector);
newAdaptor.initialize(
roles, address(0), CHILD_CHAIN_NAME, CHILD_BRIDGE_ADAPTOR_STRING, address(axelarGasService)
);
}

function test_RevertIf_InitializeGivenEmptyChildChainName() public {
RootAxelarBridgeAdaptor newAdaptor = new RootAxelarBridgeAdaptor(address(mockAxelarGateway));
RootAxelarBridgeAdaptor newAdaptor = new RootAxelarBridgeAdaptor(address(mockAxelarGateway), address(this));
vm.expectRevert(InvalidChildChain.selector);
newAdaptor.initialize(roles, address(this), "", CHILD_BRIDGE_ADAPTOR_STRING, address(axelarGasService));
}

function test_RevertIf_InitializeGivenEmptyChildAdapter() public {
RootAxelarBridgeAdaptor newAdaptor = new RootAxelarBridgeAdaptor(address(mockAxelarGateway));
RootAxelarBridgeAdaptor newAdaptor = new RootAxelarBridgeAdaptor(address(mockAxelarGateway), address(this));
vm.expectRevert(InvalidChildBridgeAdaptor.selector);
newAdaptor.initialize(roles, address(this), CHILD_CHAIN_NAME, "", address(axelarGasService));
}
Expand Down
Loading

0 comments on commit 2929d67

Please sign in to comment.