Skip to content

Commit

Permalink
test(BridgeManager): deploy mainchain gateway V3
Browse files Browse the repository at this point in the history
  • Loading branch information
huyhuynh3103 committed Jan 17, 2024
1 parent cc7177d commit 27785d1
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/foundry-deployment-kit
Submodule foundry-deployment-kit added at e17e26
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { IBridgeManager } from "@ronin/contracts/interfaces/bridge/IBridgeManage
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 { MainchainGatewayV3 } from "@ronin/contracts/mainchain/MainchainGatewayV3.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";
Expand All @@ -28,6 +29,7 @@ contract Bridge_Integration_Test is Base_Test, InitTest, SignerUtils {
Account[] internal _governors;

MockBridge internal _bridgeContract;
MainchainGatewayV3 internal _mainchainGatewayV3;
RoninBridgeManager internal _roninBridgeManager;
BridgeTracking internal _bridgeTracking;
BridgeSlash internal _bridgeSlash;
Expand All @@ -50,6 +52,7 @@ contract Bridge_Integration_Test is Base_Test, InitTest, SignerUtils {
_bridgeReward = BridgeReward(output.bridgeRewardAddress);
_bridgeTracking = BridgeTracking(output.bridgeTrackingAddress);

_mainchainGatewayV3 = MainchainGatewayV3(output.mainchainGatewayV3Address);
_mainchainBridgeManager = MainchainBridgeManager(output.mainchainBridgeManagerAddress);

vm.roll(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ contract SetConfig_MainchainManager_Test is Bridge_Integration_Test {

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

function test_configBridgeOperatorsCorrectly() external {
Expand All @@ -32,7 +32,7 @@ contract SetConfig_MainchainManager_Test is Bridge_Integration_Test {
address[] memory results = _mainchainBridgeManager.resolveTargets(targets);

assertEq(results[0], address(_mainchainBridgeManager));
assertEq(results[1], address(_bridgeContract));
assertEq(results[1], address(_mainchainGatewayV3));
assertEq(results[2], address(DEFAULT_ADDRESS));
assertEq(results[3], address(DEFAULT_ADDRESS));
assertEq(results[4], address(DEFAULT_ADDRESS));
Expand Down
34 changes: 32 additions & 2 deletions test/init-test/InitTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { BridgeReward } from "@ronin/contracts/ronin/gateway/BridgeReward.sol";
import { RoninBridgeManager } from "@ronin/contracts/ronin/gateway/RoninBridgeManager.sol";
import { MainchainBridgeManager } from "@ronin/contracts/mainchain/MainchainBridgeManager.sol";
import { MockBridge } from "@ronin/contracts/mocks/MockBridge.sol";
import { MainchainGatewayV3 } from "@ronin/contracts/mainchain/MainchainGatewayV3.sol";
import { AddressArrayUtils } from "@ronin/contracts/libraries/AddressArrayUtils.sol";

contract InitTest is Base_Test {
Expand Down Expand Up @@ -71,6 +72,7 @@ contract InitTest is Base_Test {

vm.startPrank(_deployer);
output.bridgeContractAddress = payable(_deployBridgeContract());
output.mainchainGatewayV3Address = payable(_deployMainchainGatewayV3());
output.bridgeTrackingAddress = payable(_deployBridgeTracking());
output.bridgeSlashAddress = payable(_deployBridgeSlash());
output.bridgeRewardAddress = payable(_deployBridgeReward());
Expand All @@ -82,7 +84,8 @@ contract InitTest is Base_Test {
function _prepareAddressForGeneralConfig() internal {
uint256 nonce = 1;
_inputArguments.roninGeneralConfig.bridgeContract = _calculateAddress(_deployer, nonce).addr;
_inputArguments.mainchainGeneralConfig.bridgeContract = _inputArguments.roninGeneralConfig.bridgeContract;
nonce += 2;
_inputArguments.mainchainGeneralConfig.bridgeContract = _calculateAddress(_deployer, nonce).addr;

nonce += 2;
_inputArguments.roninGeneralConfig.bridgeTrackingContract = _calculateAddress(_deployer, nonce);
Expand All @@ -97,7 +100,8 @@ contract InitTest is Base_Test {
_inputArguments.mainchainGeneralConfig.bridgeManagerContract = _calculateAddress(_deployer, nonce);

console2.log("Deployer", _deployer);
console2.log(" > bridgeContract", _inputArguments.roninGeneralConfig.bridgeContract);
console2.log(" > roninGateway", _inputArguments.roninGeneralConfig.bridgeContract);
console2.log(" > mainchainGateway", _inputArguments.mainchainGeneralConfig.bridgeContract);
console2.log(" > bridgeTrackingContract", _inputArguments.roninGeneralConfig.bridgeTrackingContract.addr);
console2.log(" > bridgeSlashContract", _inputArguments.roninGeneralConfig.bridgeSlashContract.addr);
console2.log(" > bridgeRewardContract", _inputArguments.roninGeneralConfig.bridgeRewardContract.addr);
Expand Down Expand Up @@ -260,6 +264,32 @@ contract InitTest is Base_Test {
return address(bridgeManager);
}

function _deployMainchainGatewayV3() internal returns (address) {
MainchainGatewayV3 logic = new MainchainGatewayV3();
TransparentUpgradeableProxyV2 proxy = new TransparentUpgradeableProxyV2(
address(logic),
_proxyAdmin,
abi.encodeCall(
MainchainGatewayV3.initialize,
(
_inputArguments.mainchainGatewayV3Arguments.roleSetter,
_inputArguments.mainchainGatewayV3Arguments.wrappedToken,
_inputArguments.mainchainGatewayV3Arguments.roninChainId,
_inputArguments.mainchainGatewayV3Arguments.numerator,
_inputArguments.mainchainGatewayV3Arguments.highTierVWNumerator,
_inputArguments.mainchainGatewayV3Arguments.denominator,
_inputArguments.mainchainGatewayV3Arguments.addresses,
_inputArguments.mainchainGatewayV3Arguments.thresholds,
_inputArguments.mainchainGatewayV3Arguments.standards
)
)
);
address mainchainGatewayContract = address(proxy);
vm.label(mainchainGatewayContract, "MainchainGatewayV3");
assertEq(mainchainGatewayContract, _inputArguments.mainchainGeneralConfig.bridgeContract);
return mainchainGatewayContract;
}

function _calculateAddress(address deployer, uint256 nonce) internal pure returns (AddressExtended memory rs) {
rs.nonce = nonce;
rs.addr = computeCreateAddress(deployer, nonce);
Expand Down
23 changes: 23 additions & 0 deletions test/init-test/Structs.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
pragma solidity ^0.8.19;

import "@ronin/contracts/libraries/GlobalProposal.sol";
import "@ronin/contracts/interfaces/IWETH.sol";
import "@ronin/contracts/libraries/Token.sol";

struct MaintenanceArguments {
uint256 minMaintenanceDurationInBlock;
Expand Down Expand Up @@ -114,6 +116,25 @@ struct BridgeManagerArguments {
TargetOptionStruct[] targets;
}

struct MainchainGatewayV3Arguments {
address roleSetter;
IWETH wrappedToken;
uint256 roninChainId;
uint256 numerator;
uint256 highTierVWNumerator;
uint256 denominator;
// addresses[0]: mainchainTokens
// addresses[1]: roninTokens
// addresses[2]: withdrawalUnlockers
address[][3] addresses;
// thresholds[0]: highTierThreshold
// thresholds[1]: lockedThreshold
// thresholds[2]: unlockFeePercentages
// thresholds[3]: dailyWithdrawalLimit
uint256[][4] thresholds;
Token.Standard[] standards;
}

struct BridgeRewardArguments {
uint256 rewardPerPeriod;
uint256 topupAmount;
Expand Down Expand Up @@ -154,6 +175,7 @@ struct InitTestInput {
RoninGovernanceAdminArguments governanceAdminArguments;
BridgeManagerArguments bridgeManagerArguments;
BridgeRewardArguments bridgeRewardArguments;
MainchainGatewayV3Arguments mainchainGatewayV3Arguments;
}

struct InitTestOutput {
Expand All @@ -171,4 +193,5 @@ struct InitTestOutput {
address payable bridgeRewardAddress;
address payable roninBridgeManagerAddress;
address payable mainchainBridgeManagerAddress;
address payable mainchainGatewayV3Address;
}

0 comments on commit 27785d1

Please sign in to comment.