forked from axieinfinity/ronin-dpos-contracts
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(MainchainGatewayV3): add test submit withdrawal
- Loading branch information
1 parent
381c48f
commit ff16062
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
67 changes: 67 additions & 0 deletions
67
...integration/mainchain-gateway/submit-withdrawal/submitWithdrawal.MainchainGatewayV3.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |