Skip to content

Commit

Permalink
test(RoninGatewayV3): add more test
Browse files Browse the repository at this point in the history
  • Loading branch information
huyhuynh3103 committed Jan 23, 2024
1 parent 763a1ff commit c7170b2
Showing 1 changed file with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ contract DepositVote_RoninGatewayV3_Test is BaseIntegration_Test {
using Transfer for Transfer.Receipt;

Transfer.Receipt[] _depositReceipts;
uint256 _numOperatorsForVoteExecuted;

function setUp() public virtual override {
super.setUp();
Expand All @@ -25,9 +26,7 @@ contract DepositVote_RoninGatewayV3_Test is BaseIntegration_Test {
);

vm.etch(address(_roninGatewayV3), address(new MockRoninGatewayV3Extended()).code);
}

function test_depositVote() public {
Transfer.Receipt memory receipt = Transfer.Receipt({
id: 0,
kind: Transfer.Kind.Deposit,
Expand All @@ -44,7 +43,13 @@ contract DepositVote_RoninGatewayV3_Test is BaseIntegration_Test {
receipt.id = 1;
_depositReceipts.push(receipt);

for (uint256 i; i < _param.roninBridgeManager.num - 1; i++) {
_numOperatorsForVoteExecuted =
_param.roninBridgeManager.bridgeOperators.length * _param.roninBridgeManager.num / _param.roninBridgeManager.denom;
}

// @dev Should be able to bulk deposits using bridge operator accounts
function test_tryBulkDepositFor_NotExecuted() public {
for (uint256 i; i < _numOperatorsForVoteExecuted - 1; i++) {
vm.prank(_param.roninBridgeManager.bridgeOperators[i]);
_roninGatewayV3.tryBulkDepositFor(_depositReceipts);
}
Expand All @@ -58,7 +63,27 @@ contract DepositVote_RoninGatewayV3_Test is BaseIntegration_Test {
uint256 totalWeight = MockRoninGatewayV3Extended(payable(address(_roninGatewayV3))).getDepositVoteWeight(
_depositReceipts[i].mainchain.chainId, i, Transfer.hash(_depositReceipts[i])
);
assertEq(totalWeight, (_param.roninBridgeManager.num - 1) * 100);
assertEq(totalWeight, (_numOperatorsForVoteExecuted - 1) * 100);
}
}

// Should be able to continue to vote on the votes, the later vote is not counted but is tracked
function test_tryBulkDepositFor_Executed() public {
test_tryBulkDepositFor_NotExecuted();

vm.prank(_param.roninBridgeManager.bridgeOperators[_numOperatorsForVoteExecuted - 1]);
_roninGatewayV3.tryBulkDepositFor(_depositReceipts);

for (uint256 i = 0; i < _depositReceipts.length; i++) {
(VoteStatusConsumer.VoteStatus status,,,) =
_roninGatewayV3.depositVote(_depositReceipts[i].mainchain.chainId, _depositReceipts[i].id);

assertEq(uint256(uint8(status)), uint256(uint8(VoteStatusConsumer.VoteStatus.Executed)));

uint256 totalWeight = MockRoninGatewayV3Extended(payable(address(_roninGatewayV3))).getDepositVoteWeight(
_depositReceipts[i].mainchain.chainId, i, Transfer.hash(_depositReceipts[i])
);
assertEq(totalWeight, (_numOperatorsForVoteExecuted) * 100);
}
}
}

0 comments on commit c7170b2

Please sign in to comment.