Skip to content

Commit

Permalink
test(BridgeManager): add configs test
Browse files Browse the repository at this point in the history
  • Loading branch information
huyhuynh3103 committed Jan 17, 2024
1 parent 85409af commit cc7177d
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { MockBridge } from "@ronin/contracts/mocks/MockBridge.sol";
import { RoninBridgeManager } from "@ronin/contracts/ronin/gateway/RoninBridgeManager.sol";
import { MainchainBridgeManager } from "@ronin/contracts/mainchain/MainchainBridgeManager.sol";
import { ContractType } from "@ronin/contracts/utils/ContractType.sol";
import { BridgeSlash } from "src/ronin/gateway/BridgeSlash.sol";
import { BridgeTracking } from "src/ronin/gateway/BridgeTracking.sol";
import { BridgeReward } from "src/ronin/gateway/BridgeReward.sol";

import { Base_Test } from "@ronin/test/Base.t.sol";
import { SignerUtils } from "@ronin/test/utils/Signers.sol";
Expand All @@ -26,6 +29,9 @@ contract Bridge_Integration_Test is Base_Test, InitTest, SignerUtils {

MockBridge internal _bridgeContract;
RoninBridgeManager internal _roninBridgeManager;
BridgeTracking internal _bridgeTracking;
BridgeSlash internal _bridgeSlash;
BridgeReward internal _bridgeReward;
MainchainBridgeManager internal _mainchainBridgeManager;

BridgeManagerInterface _bridgeManagerInterface;
Expand All @@ -40,6 +46,10 @@ contract Bridge_Integration_Test is Base_Test, InitTest, SignerUtils {

_bridgeContract = MockBridge(output.bridgeContractAddress);
_roninBridgeManager = RoninBridgeManager(output.roninBridgeManagerAddress);
_bridgeSlash = BridgeSlash(output.bridgeSlashAddress);
_bridgeReward = BridgeReward(output.bridgeRewardAddress);
_bridgeTracking = BridgeTracking(output.bridgeTrackingAddress);

_mainchainBridgeManager = MainchainBridgeManager(output.mainchainBridgeManagerAddress);

vm.roll(1);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import "../BridgeManager_IntegrationTest.t.sol";

contract SetConfig_MainchainManager_Test is Bridge_Integration_Test {
function setUp() public virtual override {
super.setUp();
}

function test_configBridgeContractCorrectly() external {
address bridgeContract = _mainchainBridgeManager.getContract(ContractType.BRIDGE);
assertEq(bridgeContract, address(_bridgeContract));
}

function test_configBridgeOperatorsCorrectly() external {
address[] memory bridgeOperators = _mainchainBridgeManager.getBridgeOperators();

for (uint256 i; i < bridgeOperators.length; i++) {
assertEq(bridgeOperators[i], _operators[i].addr);
}
}

function test_configTargetsCorrectly() external {
GlobalProposal.TargetOption[] memory targets = new GlobalProposal.TargetOption[](5);
targets[0] = GlobalProposal.TargetOption.BridgeManager;
targets[1] = GlobalProposal.TargetOption.GatewayContract;
targets[2] = GlobalProposal.TargetOption.BridgeSlash;
targets[3] = GlobalProposal.TargetOption.BridgeReward;
targets[4] = GlobalProposal.TargetOption.BridgeTracking;

address[] memory results = _mainchainBridgeManager.resolveTargets(targets);

assertEq(results[0], address(_mainchainBridgeManager));
assertEq(results[1], address(_bridgeContract));
assertEq(results[2], address(DEFAULT_ADDRESS));
assertEq(results[3], address(DEFAULT_ADDRESS));
assertEq(results[4], address(DEFAULT_ADDRESS));
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,40 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import "../BridgeManager_IntergrationTest.t.sol";
import "../BridgeManager_IntegrationTest.t.sol";

contract SetConfig_RoninBridgeManager_Test is Bridge_Integration_Test {
function setUp() public virtual override {
super.setUp();
}

function test_setBridgeContract() external {
function test_configBridgeContractCorrectly() external {
address bridgeContract = _roninBridgeManager.getContract(ContractType.BRIDGE);
assertEq(bridgeContract, address(_bridgeContract));
}

function test_setBridgeOperatorsContract() external {
function test_configBridgeOperatorsCorrectly() external {
address[] memory bridgeOperators = _roninBridgeManager.getBridgeOperators();

for (uint256 i; i < bridgeOperators.length; i++) {
assertEq(bridgeOperators[i], _operators[i].addr);
}
}

function test_configTargetsCorrectly() external {
GlobalProposal.TargetOption[] memory targets = new GlobalProposal.TargetOption[](5);
targets[0] = GlobalProposal.TargetOption.BridgeManager;
targets[1] = GlobalProposal.TargetOption.GatewayContract;
targets[2] = GlobalProposal.TargetOption.BridgeSlash;
targets[3] = GlobalProposal.TargetOption.BridgeReward;
targets[4] = GlobalProposal.TargetOption.BridgeTracking;

address[] memory results = _roninBridgeManager.resolveTargets(targets);

assertEq(results[0], address(_roninBridgeManager));
assertEq(results[1], address(_bridgeContract));
assertEq(results[2], address(_bridgeSlash));
assertEq(results[3], address(_bridgeReward));
assertEq(results[4], address(_bridgeTracking));
}
}
2 changes: 2 additions & 0 deletions test/init-test/InitTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { MockBridge } from "@ronin/contracts/mocks/MockBridge.sol";
import { AddressArrayUtils } from "@ronin/contracts/libraries/AddressArrayUtils.sol";

contract InitTest is Base_Test {
address constant DEFAULT_ADDRESS = address(0);

InitTestInput internal _inputArguments;
address internal _deployer;
address internal _proxyAdmin;
Expand Down

0 comments on commit cc7177d

Please sign in to comment.