Skip to content

Commit

Permalink
test: update integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xorsal committed Oct 23, 2024
1 parent 3dc123e commit ed39f02
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 72 deletions.
12 changes: 6 additions & 6 deletions solidity/test/integration/Arbitration.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ contract Integration_Arbitration is IntegrationBase {

// First step: escalating the dispute
vm.prank(disputer);
oracle.escalateDispute(mockRequest, mockResponse, mockDispute);
oracle.escalateDispute(mockRequest, mockResponse, mockDispute, _createAccessControl(disputer));

// Check: is the dispute status active after starting the resolution?
assertEq(uint256(_arbitratorModule.getStatus(_disputeId)), uint256(IArbitratorModule.ArbitrationStatus.Active));

// Second step: resolving the dispute
vm.prank(disputer);
oracle.resolveDispute(mockRequest, mockResponse, mockDispute);
oracle.resolveDispute(mockRequest, mockResponse, mockDispute, _createAccessControl(disputer));

// Check: is the dispute status resolved after calling resolve?
assertEq(uint256(_arbitratorModule.getStatus(_disputeId)), uint256(IArbitratorModule.ArbitrationStatus.Resolved));
Expand All @@ -58,7 +58,7 @@ contract Integration_Arbitration is IntegrationBase {

// First step: escalating the dispute
vm.prank(disputer);
oracle.escalateDispute(mockRequest, mockResponse, mockDispute);
oracle.escalateDispute(mockRequest, mockResponse, mockDispute, _createAccessControl(disputer));

// Check: is the dispute status resolved after calling resolve?
assertEq(uint256(_arbitratorModule.getStatus(_disputeId)), uint256(IArbitratorModule.ArbitrationStatus.Resolved));
Expand All @@ -83,7 +83,7 @@ contract Integration_Arbitration is IntegrationBase {

// First step: escalating the dispute
vm.prank(disputer);
oracle.escalateDispute(mockRequest, mockResponse, mockDispute);
oracle.escalateDispute(mockRequest, mockResponse, mockDispute, _createAccessControl(disputer));

// Check: is the dispute status active after starting the resolution?
assertEq(uint256(_arbitratorModule.getStatus(_disputeId)), uint256(IArbitratorModule.ArbitrationStatus.Active));
Expand All @@ -97,7 +97,7 @@ contract Integration_Arbitration is IntegrationBase {

// Second step: resolving the dispute
vm.prank(disputer);
oracle.resolveDispute(mockRequest, mockResponse, mockDispute);
oracle.resolveDispute(mockRequest, mockResponse, mockDispute, _createAccessControl(disputer));

// Check: is the dispute status resolved after calling resolve?
assertEq(uint256(_arbitratorModule.getStatus(_disputeId)), uint256(IArbitratorModule.ArbitrationStatus.Resolved));
Expand Down Expand Up @@ -130,7 +130,7 @@ contract Integration_Arbitration is IntegrationBase {

// First step: escalating and resolving the dispute
vm.prank(disputer);
oracle.escalateDispute(mockRequest, mockResponse, mockDispute);
oracle.escalateDispute(mockRequest, mockResponse, mockDispute, _createAccessControl(disputer));

// Check: is the dispute status resolved after calling escalate?
assertEq(uint256(_arbitratorModule.getStatus(_disputeId)), uint256(IArbitratorModule.ArbitrationStatus.Resolved));
Expand Down
77 changes: 43 additions & 34 deletions solidity/test/integration/BondEscalation.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -101,29 +101,29 @@ contract Integration_BondEscalation is IntegrationBase {
// Proposer proposes a response
_deposit(_bondEscalationAccounting, proposer, usdc, _expectedBondSize);
vm.prank(proposer);
_responseId = oracle.proposeResponse(mockRequest, mockResponse);
_responseId = oracle.proposeResponse(mockRequest, mockResponse, _createAccessControl(proposer));

// Disputer disputes the response
_deposit(_bondEscalationAccounting, disputer, usdc, _pledgeSize);
vm.prank(disputer);
_disputeId = oracle.disputeResponse(mockRequest, mockResponse, mockDispute);
_disputeId = oracle.disputeResponse(mockRequest, mockResponse, mockDispute, _createAccessControl(disputer));
}

function test_proposerWins() public {
// Step 1: Proposer pledges against the dispute
_deposit(_bondEscalationAccounting, proposer, usdc, _pledgeSize);
vm.prank(proposer);
_bondEscalationModule.pledgeAgainstDispute(mockRequest, mockDispute);
_bondEscalationModule.pledgeAgainstDispute(mockRequest, mockDispute, _createAccessControl(proposer));

// Step 2: Disputer doubles down
_deposit(_bondEscalationAccounting, disputer, usdc, _pledgeSize);
vm.prank(disputer);
_bondEscalationModule.pledgeForDispute(mockRequest, mockDispute);
_bondEscalationModule.pledgeForDispute(mockRequest, mockDispute, _createAccessControl(disputer));

// Step 3: Proposer doubles down
_deposit(_bondEscalationAccounting, proposer, usdc, _pledgeSize);
vm.prank(proposer);
_bondEscalationModule.pledgeAgainstDispute(mockRequest, mockDispute);
_bondEscalationModule.pledgeAgainstDispute(mockRequest, mockDispute, _createAccessControl(proposer));

// Step 4: Disputer runs out of capital
// Step 5: External parties see that Disputer's dispute was wrong so they don't join to escalate
Expand Down Expand Up @@ -173,17 +173,17 @@ contract Integration_BondEscalation is IntegrationBase {
// Step 1: Proposer pledges against the dispute
_deposit(_bondEscalationAccounting, proposer, usdc, _pledgeSize);
vm.prank(proposer);
_bondEscalationModule.pledgeAgainstDispute(mockRequest, mockDispute);
_bondEscalationModule.pledgeAgainstDispute(mockRequest, mockDispute, _createAccessControl(proposer));

// Step 2: Disputer doubles down
_deposit(_bondEscalationAccounting, disputer, usdc, _pledgeSize);
vm.prank(disputer);
_bondEscalationModule.pledgeForDispute(mockRequest, mockDispute);
_bondEscalationModule.pledgeForDispute(mockRequest, mockDispute, _createAccessControl(disputer));

// Step 3: Another party joins the dispute
_deposit(_bondEscalationAccounting, _secondDisputer, usdc, _pledgeSize);
vm.prank(_secondDisputer);
_bondEscalationModule.pledgeForDispute(mockRequest, mockDispute);
_bondEscalationModule.pledgeForDispute(mockRequest, mockDispute, _createAccessControl(_secondDisputer));

// Step 4: Proposer runs out of capital and doesn't pledge anymore
// External parties see that Proposer's proposal was wrong so they don't join to escalate
Expand Down Expand Up @@ -225,27 +225,27 @@ contract Integration_BondEscalation is IntegrationBase {
IOracle.Response({proposer: _secondProposer, requestId: _requestId, response: abi.encode('second response')});
_deposit(_bondEscalationAccounting, _secondProposer, usdc, _pledgeSize);
vm.prank(_secondProposer);
_responseId = oracle.proposeResponse(mockRequest, _secondResponse);
_responseId = oracle.proposeResponse(mockRequest, _secondResponse, _createAccessControl(_secondProposer));

// Step 8: Disputer disputes Another proposer's answer
// _deposit(_bondEscalationAccounting, disputer, usdc, _pledgeSize);
IOracle.Dispute memory _secondDispute =
IOracle.Dispute({disputer: disputer, responseId: _responseId, requestId: _requestId, proposer: _secondProposer});
vm.prank(disputer);
_disputeId = oracle.disputeResponse(mockRequest, _secondResponse, _secondDispute);
_disputeId = oracle.disputeResponse(mockRequest, _secondResponse, _secondDispute, _createAccessControl(disputer));

// Step 9: Shouldn't be able to pledge for or against the dispute due to the bond escalation deadline being over
_deposit(_bondEscalationAccounting, disputer, usdc, _pledgeSize);
vm.expectRevert(IBondEscalationModule.BondEscalationModule_InvalidDispute.selector);
vm.prank(disputer);
_bondEscalationModule.pledgeForDispute(mockRequest, _secondDispute);
_bondEscalationModule.pledgeForDispute(mockRequest, _secondDispute, _createAccessControl(disputer));

// Step 10: Because Another proposer's answer is disputed, a third party can propose a new answer
IOracle.Response memory _thirdResponse =
IOracle.Response({proposer: _thirdProposer, requestId: _requestId, response: abi.encode('third response')});
_deposit(_bondEscalationAccounting, _thirdProposer, usdc, _expectedBondSize);
vm.prank(_thirdProposer);
_responseId = oracle.proposeResponse(mockRequest, _thirdResponse);
_responseId = oracle.proposeResponse(mockRequest, _thirdResponse, _createAccessControl(_thirdProposer));

// Step 11: It goes undisputed for three days, therefore it's deemed correct and final
vm.warp(block.timestamp + _expectedDeadline + 1);
Expand Down Expand Up @@ -285,7 +285,7 @@ contract Integration_BondEscalation is IntegrationBase {
// So Another proposer gets paid Disputer's bond
vm.warp(block.timestamp + _expectedDeadline + 2 days);
_mockArbitrator.setAnswer(IOracle.DisputeStatus.Lost);
oracle.resolveDispute(mockRequest, _secondResponse, _secondDispute);
oracle.resolveDispute(mockRequest, _secondResponse, _secondDispute, mockAccessControl);

// Test: The requester still has nothing
assertEq(_bondEscalationAccounting.balanceOf(requester, usdc), 0, 'Mismatch: Requester balance');
Expand Down Expand Up @@ -326,17 +326,17 @@ contract Integration_BondEscalation is IntegrationBase {
// Step 1: Proposer pledges against the dispute
_deposit(_bondEscalationAccounting, proposer, usdc, _pledgeSize);
vm.prank(proposer);
_bondEscalationModule.pledgeAgainstDispute(mockRequest, mockDispute);
_bondEscalationModule.pledgeAgainstDispute(mockRequest, mockDispute, _createAccessControl(proposer));

// Step 2: Disputer doubles down
_deposit(_bondEscalationAccounting, disputer, usdc, _pledgeSize);
vm.prank(disputer);
_bondEscalationModule.pledgeForDispute(mockRequest, mockDispute);
_bondEscalationModule.pledgeForDispute(mockRequest, mockDispute, _createAccessControl(disputer));

// Step 3: Proposer doubles down
_deposit(_bondEscalationAccounting, proposer, usdc, _pledgeSize);
vm.prank(proposer);
_bondEscalationModule.pledgeAgainstDispute(mockRequest, mockDispute);
_bondEscalationModule.pledgeAgainstDispute(mockRequest, mockDispute, _createAccessControl(proposer));

// Step 4: Disputer runs out of capital
// Step 5: The tying buffer kicks in
Expand All @@ -345,21 +345,24 @@ contract Integration_BondEscalation is IntegrationBase {
// Step 6: An external party sees that Proposer's response is incorrect, so they bond the required WETH
_deposit(_bondEscalationAccounting, _secondDisputer, usdc, _pledgeSize);
vm.prank(_secondDisputer);
_bondEscalationModule.pledgeForDispute(mockRequest, mockDispute);
_bondEscalationModule.pledgeForDispute(mockRequest, mockDispute, _createAccessControl(_secondDisputer));

// Step 7: They go into the dispute resolution module
oracle.escalateDispute(mockRequest, mockResponse, mockDispute);
// review: we could use a global address `_anyone`
address _escalator = makeAddr('escalator');
vm.prank(_escalator);
oracle.escalateDispute(mockRequest, mockResponse, mockDispute, _createAccessControl(_escalator));

// Step 8: At this point, new answers can be proposed
IOracle.Response memory _secondResponse =
IOracle.Response({proposer: _secondProposer, requestId: _requestId, response: abi.encode('second response')});
_deposit(_bondEscalationAccounting, _secondProposer, usdc, _expectedBondSize);
vm.prank(_secondProposer);
_responseId = oracle.proposeResponse(mockRequest, _secondResponse);
_responseId = oracle.proposeResponse(mockRequest, _secondResponse, _createAccessControl(_secondProposer));

// Step 9: After some time, the resolution module deems Disputer's dispute as correct
_mineBlocks(100);
oracle.resolveDispute(mockRequest, mockResponse, mockDispute);
oracle.resolveDispute(mockRequest, mockResponse, mockDispute, mockAccessControl);
IOracle.DisputeStatus _disputeStatus = oracle.disputeStatus(_disputeId);
assertEq(uint256(_disputeStatus), uint256(IOracle.DisputeStatus.Won), 'Mismatch: Dispute status');

Expand Down Expand Up @@ -400,29 +403,35 @@ contract Integration_BondEscalation is IntegrationBase {
// Step 1: Proposer pledges against the dispute
_deposit(_bondEscalationAccounting, proposer, usdc, _pledgeSize);
vm.prank(proposer);
_bondEscalationModule.pledgeAgainstDispute(mockRequest, mockDispute);
_bondEscalationModule.pledgeAgainstDispute(mockRequest, mockDispute, _createAccessControl(proposer));

// Step 2: Disputer doesn't have money
// Step 3: External actor sees that Proposer's answer was incorrect so they pledge in favor of the dispute
_deposit(_bondEscalationAccounting, _secondDisputer, usdc, _pledgeSize);
vm.prank(_secondDisputer);
_bondEscalationModule.pledgeForDispute(mockRequest, mockDispute);
_bondEscalationModule.pledgeForDispute(mockRequest, mockDispute, _createAccessControl(_secondDisputer));

// Step 4: Proposer doubles down
_deposit(_bondEscalationAccounting, proposer, usdc, _pledgeSize);
vm.prank(proposer);
_bondEscalationModule.pledgeAgainstDispute(mockRequest, mockDispute);
_bondEscalationModule.pledgeAgainstDispute(mockRequest, mockDispute, _createAccessControl(proposer));

// Step 5: External actor sees that Proposer's answer was incorrect so they pledge in favor of the dispute, tying the bond escalation
address _thirdDisputer = makeAddr('thirdDisputer');
_deposit(_bondEscalationAccounting, _thirdDisputer, usdc, _pledgeSize);
vm.prank(_thirdDisputer);
_bondEscalationModule.pledgeForDispute(mockRequest, mockDispute);
_bondEscalationModule.pledgeForDispute(mockRequest, mockDispute, _createAccessControl(_thirdDisputer));

// Step 6: Proposer loses in resolution
address _escalator = makeAddr('escalator');
address _resolver = makeAddr('resolver');

vm.warp(block.timestamp + _bondEscalationDeadline + 1);
oracle.escalateDispute(mockRequest, mockResponse, mockDispute);
oracle.resolveDispute(mockRequest, mockResponse, mockDispute);

vm.prank(_escalator);
oracle.escalateDispute(mockRequest, mockResponse, mockDispute, _createAccessControl(_escalator));
vm.prank(_resolver);
oracle.resolveDispute(mockRequest, mockResponse, mockDispute, _createAccessControl(_resolver));

IOracle.DisputeStatus _disputeStatus = oracle.disputeStatus(_disputeId);
assertEq(uint256(_disputeStatus), uint256(IOracle.DisputeStatus.Won), 'Mismatch: Dispute status');
Expand Down Expand Up @@ -456,17 +465,17 @@ contract Integration_BondEscalation is IntegrationBase {
// Step 1: Proposer pledges against the dispute
_deposit(_bondEscalationAccounting, proposer, usdc, _pledgeSize);
vm.prank(proposer);
_bondEscalationModule.pledgeAgainstDispute(mockRequest, mockDispute);
_bondEscalationModule.pledgeAgainstDispute(mockRequest, mockDispute, _createAccessControl(proposer));

// Step 2: Disputer doubles down
_deposit(_bondEscalationAccounting, disputer, usdc, _pledgeSize);
vm.prank(disputer);
_bondEscalationModule.pledgeForDispute(mockRequest, mockDispute);
_bondEscalationModule.pledgeForDispute(mockRequest, mockDispute, _createAccessControl(disputer));

// Step 3: Proposer doubles down
_deposit(_bondEscalationAccounting, proposer, usdc, _pledgeSize);
vm.prank(proposer);
_bondEscalationModule.pledgeAgainstDispute(mockRequest, mockDispute);
_bondEscalationModule.pledgeAgainstDispute(mockRequest, mockDispute, _createAccessControl(proposer));

// Step 4: Disputer runs out of capital
// Step 5: The tying buffer kicks in
Expand All @@ -475,7 +484,7 @@ contract Integration_BondEscalation is IntegrationBase {
// Step 6: An external party sees that Proposer's response is incorrect, so they bond the required WETH
_deposit(_bondEscalationAccounting, _secondDisputer, usdc, _pledgeSize);
vm.prank(_secondDisputer);
_bondEscalationModule.pledgeForDispute(mockRequest, mockDispute);
_bondEscalationModule.pledgeForDispute(mockRequest, mockDispute, _createAccessControl(_secondDisputer));

////////////////// NEW MALICIOUS REQUEST ////////////////////////

Expand Down Expand Up @@ -517,17 +526,17 @@ contract Integration_BondEscalation is IntegrationBase {
// Step 1: Proposer pledges against the dispute
_deposit(_bondEscalationAccounting, proposer, usdc, _pledgeSize);
vm.prank(proposer);
_bondEscalationModule.pledgeAgainstDispute(mockRequest, mockDispute);
_bondEscalationModule.pledgeAgainstDispute(mockRequest, mockDispute, _createAccessControl(proposer));

// Step 2: Disputer doubles down
_deposit(_bondEscalationAccounting, disputer, usdc, _pledgeSize);
vm.prank(disputer);
_bondEscalationModule.pledgeForDispute(mockRequest, mockDispute);
_bondEscalationModule.pledgeForDispute(mockRequest, mockDispute, _createAccessControl(disputer));

// Step 3: Proposer doubles down
_deposit(_bondEscalationAccounting, proposer, usdc, _pledgeSize);
vm.prank(proposer);
_bondEscalationModule.pledgeAgainstDispute(mockRequest, mockDispute);
_bondEscalationModule.pledgeAgainstDispute(mockRequest, mockDispute, _createAccessControl(proposer));

// Step 4: Disputer runs out of capital
// Step 5: The tying buffer kicks in
Expand All @@ -536,7 +545,7 @@ contract Integration_BondEscalation is IntegrationBase {
// Step 6: An external party sees that Proposer's response is incorrect, so they bond the required WETH
_deposit(_bondEscalationAccounting, _secondDisputer, usdc, _pledgeSize);
vm.prank(_secondDisputer);
_bondEscalationModule.pledgeForDispute(mockRequest, mockDispute);
_bondEscalationModule.pledgeForDispute(mockRequest, mockDispute, _createAccessControl(_secondDisputer));

////////////////// NEW MALICIOUS REQUEST ////////////////////////

Expand Down
2 changes: 1 addition & 1 deletion solidity/test/integration/CallbackModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ contract Integration_CallbackModule is IntegrationBase {
vm.startPrank(proposer);
_accountingExtension.approveModule(address(_responseModule));
mockResponse.response = abi.encode(proposer, _requestId, bytes(''));
oracle.proposeResponse(mockRequest, mockResponse);
oracle.proposeResponse(mockRequest, mockResponse, _createAccessControl());
vm.stopPrank();
}
}
2 changes: 1 addition & 1 deletion solidity/test/integration/ContractCallRequest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ contract Integration_ContractCallRequest is IntegrationBase {

vm.startPrank(proposer);
_accountingExtension.approveModule(address(_responseModule));
oracle.proposeResponse(mockRequest, mockResponse);
oracle.proposeResponse(mockRequest, mockResponse, _createAccessControl());
vm.stopPrank();

// expect call to accounting to pay the proposer
Expand Down
Loading

0 comments on commit ed39f02

Please sign in to comment.