Skip to content

Commit

Permalink
test(BridgeManager): add deploy ronin gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
huyhuynh3103 committed Jan 17, 2024
1 parent 7aa03da commit 8c094a3
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/utils/DeprecatedSlots.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pragma solidity ^0.8.0;
* The purpose of these contracts is to preserve the slots for already deployed contracts.
*/
contract HasBridgeDeprecated {
/// @custom:deprecated Previously `_bridgeContract` (non-zero value)
/// @custom:deprecated Previously `_roninGatewayV3Contract` (non-zero value)
address internal ______deprecatedBridge;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { console2 } from "forge-std/console2.sol";
import { StdStyle } from "forge-std/StdStyle.sol";

import { IBridgeManager } from "@ronin/contracts/interfaces/bridge/IBridgeManager.sol";
import { MockBridge } from "@ronin/contracts/mocks/MockBridge.sol";
import { MockRoninGatewayV3Extended } from "@ronin/contracts/mocks/ronin/MockRoninGatewayV3Extended.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";
Expand All @@ -28,7 +28,7 @@ contract Bridge_Integration_Test is Base_Test, InitTest, SignerUtils {
Account[] internal _operators;
Account[] internal _governors;

MockBridge internal _bridgeContract;
MockRoninGatewayV3Extended internal _roninGatewayV3Contract;
MainchainGatewayV3 internal _mainchainGatewayV3;
RoninBridgeManager internal _roninBridgeManager;
BridgeTracking internal _bridgeTracking;
Expand All @@ -46,7 +46,7 @@ contract Bridge_Integration_Test is Base_Test, InitTest, SignerUtils {

InitTestOutput memory output = init();

_bridgeContract = MockBridge(output.bridgeContractAddress);
_roninGatewayV3Contract = MockRoninGatewayV3Extended(output.roninGatewayV3Address);
_roninBridgeManager = RoninBridgeManager(output.roninBridgeManagerAddress);
_bridgeSlash = BridgeSlash(output.bridgeSlashAddress);
_bridgeReward = BridgeReward(output.bridgeRewardAddress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ contract SetConfig_RoninBridgeManager_Test is Bridge_Integration_Test {

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

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

assertEq(results[0], address(_roninBridgeManager));
assertEq(results[1], address(_bridgeContract));
assertEq(results[1], address(_roninGatewayV3Contract));
assertEq(results[2], address(_bridgeSlash));
assertEq(results[3], address(_bridgeReward));
assertEq(results[4], address(_bridgeTracking));
Expand Down
36 changes: 27 additions & 9 deletions test/init-test/InitTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import { BridgeSlash } from "@ronin/contracts/ronin/gateway/BridgeSlash.sol";
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 { RoninGatewayV3 } from "@ronin/contracts/ronin/gateway/RoninGatewayV3.sol";
import { MockRoninGatewayV3Extended } from "@ronin/contracts/mocks/ronin/MockRoninGatewayV3Extended.sol";
import { MainchainGatewayV3 } from "@ronin/contracts/mainchain/MainchainGatewayV3.sol";
import { AddressArrayUtils } from "@ronin/contracts/libraries/AddressArrayUtils.sol";

Expand Down Expand Up @@ -71,7 +72,7 @@ contract InitTest is Base_Test {
_prepareAddressForGeneralConfig();

vm.startPrank(_deployer);
output.bridgeContractAddress = payable(_deployBridgeContract());
output.roninGatewayV3Address = payable(_deployRoninGatewayV3Contract());
output.mainchainGatewayV3Address = payable(_deployMainchainGatewayV3());
output.bridgeTrackingAddress = payable(_deployBridgeTracking());
output.bridgeSlashAddress = payable(_deployBridgeSlash());
Expand Down Expand Up @@ -109,13 +110,30 @@ contract InitTest is Base_Test {
console2.log(" > mainchainBridgeManagerContract", _inputArguments.mainchainGeneralConfig.bridgeContract);
}

function _deployBridgeContract() internal returns (address) {
MockBridge logic = new MockBridge();
TransparentUpgradeableProxyV2 proxy = new TransparentUpgradeableProxyV2(address(logic), _proxyAdmin, abi.encode());
address bridgeContract = address(proxy);
vm.label(bridgeContract, "BridgeContract");
assertEq(bridgeContract, _inputArguments.roninGeneralConfig.bridgeContract);
return bridgeContract;
function _deployRoninGatewayV3Contract() internal returns (address) {
MockRoninGatewayV3Extended logic = new MockRoninGatewayV3Extended();
TransparentUpgradeableProxyV2 proxy = new TransparentUpgradeableProxyV2(
address(logic),
_proxyAdmin,
abi.encodeCall(
RoninGatewayV3.initialize,
(
_inputArguments.roninGatewayV3Arguments.roleSetter,
_inputArguments.roninGatewayV3Arguments.numerator,
_inputArguments.roninGatewayV3Arguments.denominator,
_inputArguments.roninGatewayV3Arguments.trustedNumerator,
_inputArguments.roninGatewayV3Arguments.trustedDenominator,
_inputArguments.roninGatewayV3Arguments.withdrawalMigrators,
_inputArguments.roninGatewayV3Arguments.packedAddresses,
_inputArguments.roninGatewayV3Arguments.packedNumbers,
_inputArguments.roninGatewayV3Arguments.standards
)
)
);
address roninGatewayContract = address(proxy);
vm.label(roninGatewayContract, "RoninGatewayV3");
assertEq(roninGatewayContract, _inputArguments.roninGeneralConfig.bridgeContract);
return roninGatewayContract;
}

function _deployBridgeTracking() internal returns (address) {
Expand Down
15 changes: 14 additions & 1 deletion test/init-test/Structs.sol
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ struct BridgeManagerArguments {
TargetOptionStruct[] targets;
}

struct RoninGatewayV3Arguments {
address roleSetter;
uint256 numerator;
uint256 denominator;
uint256 trustedNumerator;
uint256 trustedDenominator;
address[] withdrawalMigrators;
address[][2] packedAddresses;
uint256[][2] packedNumbers;
Token.Standard[] standards;
}

struct MainchainGatewayV3Arguments {
address roleSetter;
IWETH wrappedToken;
Expand Down Expand Up @@ -175,11 +187,11 @@ struct InitTestInput {
RoninGovernanceAdminArguments governanceAdminArguments;
BridgeManagerArguments bridgeManagerArguments;
BridgeRewardArguments bridgeRewardArguments;
RoninGatewayV3Arguments roninGatewayV3Arguments;
MainchainGatewayV3Arguments mainchainGatewayV3Arguments;
}

struct InitTestOutput {
address payable bridgeContractAddress;
address payable roninGovernanceAdminAddress;
address payable maintenanceContractAddress;
address payable roninTrustedOrganizationAddress;
Expand All @@ -192,6 +204,7 @@ struct InitTestOutput {
address payable bridgeSlashAddress;
address payable bridgeRewardAddress;
address payable roninBridgeManagerAddress;
address payable roninGatewayV3Address;
address payable mainchainBridgeManagerAddress;
address payable mainchainGatewayV3Address;
}

0 comments on commit 8c094a3

Please sign in to comment.