Skip to content

Commit

Permalink
test(MainchainGatewayV3): add test submit withdrawal
Browse files Browse the repository at this point in the history
  • Loading branch information
huyhuynh3103 committed Jan 19, 2024
1 parent 381c48f commit ff16062
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test/bridge/integration/BaseIntegration.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,7 @@ contract BaseIntegration_Test is Base_Test {
_param = ISharedArgument(LibSharedAddress.CONFIG).sharedArguments();

_bridgeAdminInterface = new BridgeAdminInterface(_param.test.roninChainId);

_mainchainGatewayV3.initializeV2(address(_mainchainBridgeManager));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { console2 as console } from "forge-std/console2.sol";
import { ContractType } from "@ronin/contracts/utils/ContractType.sol";
import { Transfer } from "@ronin/contracts/libraries/Transfer.sol";
import { Token } from "@ronin/contracts/libraries/Token.sol";
import { SignatureConsumer } from "@ronin/contracts/interfaces/consumers/SignatureConsumer.sol";
import "../../BaseIntegration.t.sol";

contract SubmitWithdrawal_MainchainGatewayV3_Test is BaseIntegration_Test {
using Transfer for Transfer.Receipt;

Transfer.Receipt _withdrawalReceipt;
bytes32 _domainSeparator;

function setUp() public virtual override {
super.setUp();
_domainSeparator = _mainchainGatewayV3.DOMAIN_SEPARATOR();

_withdrawalReceipt.id = 0;
_withdrawalReceipt.kind = Transfer.Kind.Withdrawal;
_withdrawalReceipt.ronin.addr = makeAddr("requester");
_withdrawalReceipt.ronin.tokenAddr = address(_weth);
_withdrawalReceipt.ronin.chainId = _param.test.roninChainId;
_withdrawalReceipt.mainchain.addr = makeAddr("recipient");
_withdrawalReceipt.mainchain.tokenAddr = address(_weth);
_withdrawalReceipt.mainchain.chainId = block.chainid;
_withdrawalReceipt.info.erc = Token.Standard.ERC20;
_withdrawalReceipt.info.id = 0;
_withdrawalReceipt.info.quantity = 0;

vm.deal(address(_mainchainGatewayV3), 10 ether);
vm.prank(address(_mainchainGatewayV3));
_weth.deposit{ value: 10 ether }();
}

function test_submitWithdrawal() public {
_withdrawalReceipt.info.quantity = 10;

SignatureConsumer.Signature[] memory signatures =
_generateSignaturesFor(_withdrawalReceipt, _param.test.operatorPKs);

_mainchainGatewayV3.submitWithdrawal(_withdrawalReceipt, signatures);
}

function _generateSignaturesFor(Transfer.Receipt memory receipt, uint256[] memory signerPKs)
internal
view
returns (SignatureConsumer.Signature[] memory sigs)
{
sigs = new SignatureConsumer.Signature[](signerPKs.length);

for (uint256 i; i < signerPKs.length; i++) {
bytes32 digest = keccak256(abi.encodePacked("\x19\x01", _domainSeparator, receipt.hash()));

sigs[i] = _sign(signerPKs[i], digest);
}
}

function _sign(uint256 pk, bytes32 digest) internal pure returns (SignatureConsumer.Signature memory sig) {
(uint8 v, bytes32 r, bytes32 s) = vm.sign(pk, digest);
sig.v = v;
sig.r = r;
sig.s = s;
}
}

0 comments on commit ff16062

Please sign in to comment.