Skip to content

Commit

Permalink
test: fix a part of the e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gas1cent committed Nov 27, 2023
1 parent 7b3fc11 commit 70d0c1e
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 299 deletions.
49 changes: 49 additions & 0 deletions solidity/test/integration/IntegrationBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,55 @@ contract IntegrationBase is DSTestPlus, TestConstants, Helpers {
_finalityModule = new MockFinalityModule(oracle);

vm.stopPrank();

// Configure the mock request
mockRequest.requestModuleData = abi.encode(
IMockRequestModule.RequestParameters({
url: _expectedUrl,
body: _expectedBody,
accountingExtension: _accountingExtension,
paymentToken: usdc,
paymentAmount: _expectedReward
})
);

mockRequest.responseModuleData = abi.encode(
IMockResponseModule.RequestParameters({
accountingExtension: _accountingExtension,
bondToken: usdc,
bondAmount: _expectedBondAmount,
deadline: _expectedDeadline,
disputeWindow: _baseDisputeWindow
})
);

mockRequest.disputeModuleData = abi.encode(
IMockDisputeModule.RequestParameters({
accountingExtension: _accountingExtension,
bondToken: usdc,
bondAmount: _expectedBondAmount
})
);

mockRequest.resolutionModuleData = abi.encode();

mockRequest.finalityModuleData = abi.encode(
IMockFinalityModule.RequestParameters({target: address(_mockCallback), data: abi.encode(_expectedCallbackValue)})
);

mockRequest.requestModule = address(_requestModule);
mockRequest.responseModule = address(_responseModule);
mockRequest.disputeModule = address(_disputeModule);
mockRequest.resolutionModule = address(_resolutionModule);
mockRequest.finalityModule = address(_finalityModule);
mockRequest.requester = requester;

// Configure the mock response
mockResponse.requestId = _getId(mockRequest);

// Configure the mock dispute
mockDispute.requestId = _getId(mockRequest);
mockDispute.responseId = _getId(mockResponse);
}

function _mineBlock() internal {
Expand Down
202 changes: 16 additions & 186 deletions solidity/test/integration/ResponseDispute.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,202 +19,32 @@ contract Integration_ResponseDispute is IntegrationBase {
_expectedDeadline = block.timestamp + BLOCK_TIME * 600;
_responseData = abi.encode('response');

_requestModuleData = abi.encode(
IMockRequestModule.RequestParameters({
url: _expectedUrl,
body: _expectedBody,
accountingExtension: _accountingExtension,
paymentToken: usdc,
paymentAmount: _expectedReward
})
);

_responseModuleData = abi.encode(
IMockResponseModule.RequestParameters({
accountingExtension: _accountingExtension,
bondToken: usdc,
bondAmount: _expectedBondAmount,
deadline: _expectedDeadline,
disputeWindow: _baseDisputeWindow
})
);

_disputeModuleData = abi.encode(
IMockDisputeModule.RequestParameters({
accountingExtension: _accountingExtension,
bondToken: usdc,
bondAmount: _expectedBondAmount
})
);

_resolutionModuleData = abi.encode();
_finalityModuleData = abi.encode(
IMockFinalityModule.RequestParameters({target: address(_mockCallback), data: abi.encode(_expectedCallbackValue)})
);

IOracle.Request memory _request = IOracle.Request({
requestModuleData: abi.encode(
IMockRequestModule.RequestParameters({
url: _expectedUrl,
body: _expectedBody,
accountingExtension: _accountingExtension,
paymentToken: usdc,
paymentAmount: _expectedReward
})
),
responseModuleData: abi.encode(
IMockResponseModule.RequestParameters({
accountingExtension: _accountingExtension,
bondToken: usdc,
bondAmount: _expectedBondAmount,
deadline: _expectedDeadline,
disputeWindow: _baseDisputeWindow
})
),
disputeModuleData: abi.encode(
IMockDisputeModule.RequestParameters({
accountingExtension: _accountingExtension,
bondToken: usdc,
bondAmount: _expectedBondAmount
})
),
resolutionModuleData: abi.encode(),
finalityModuleData: abi.encode(
IMockFinalityModule.RequestParameters({target: address(_mockCallback), data: abi.encode(_expectedCallbackValue)})
),
requestModule: address(_requestModule),
responseModule: address(_responseModule),
disputeModule: address(_disputeModule),
resolutionModule: address(_resolutionModule),
finalityModule: address(_finalityModule),
requester: requester,
nonce: 0
});
mockRequest.nonce = uint96(oracle.totalRequestCount());

vm.prank(requester);
_requestId = oracle.createRequest(_request, _ipfsHash);
_requestId = oracle.createRequest(mockRequest, _ipfsHash);

IOracle.Response memory _response =
IOracle.Response({requestId: _requestId, response: abi.encode('testResponse'), proposer: proposer});
mockResponse.requestId = _requestId;

vm.prank(proposer);
_responseId = oracle.proposeResponse(_request, _response);
_responseId = oracle.proposeResponse(mockRequest, mockResponse);
}

// check that the dispute id is stored in the response struct
function test_disputeResponse_disputeIdStoredInResponse() public {
IOracle.Request memory _request = IOracle.Request({
requestModuleData: abi.encode(
IMockRequestModule.RequestParameters({
url: _expectedUrl,
body: _expectedBody,
accountingExtension: _accountingExtension,
paymentToken: usdc,
paymentAmount: _expectedReward
})
),
responseModuleData: abi.encode(
IMockResponseModule.RequestParameters({
accountingExtension: _accountingExtension,
bondToken: usdc,
bondAmount: _expectedBondAmount,
deadline: _expectedDeadline,
disputeWindow: _baseDisputeWindow
})
),
disputeModuleData: abi.encode(
IMockDisputeModule.RequestParameters({
accountingExtension: _accountingExtension,
bondToken: usdc,
bondAmount: _expectedBondAmount
})
),
resolutionModuleData: abi.encode(),
finalityModuleData: abi.encode(
IMockFinalityModule.RequestParameters({target: address(_mockCallback), data: abi.encode(_expectedCallbackValue)})
),
requestModule: address(_requestModule),
responseModule: address(_responseModule),
disputeModule: address(_disputeModule),
resolutionModule: address(_resolutionModule),
finalityModule: address(_finalityModule),
requester: requester,
nonce: 0
});

IOracle.Response memory _response =
IOracle.Response({requestId: _requestId, response: abi.encode('testResponse'), proposer: proposer});

IOracle.Dispute memory _dispute =
IOracle.Dispute({disputer: disputer, proposer: proposer, responseId: _responseId, requestId: _requestId});
function test_disputeResponse_alreadyFinalized() public {
vm.warp(_expectedDeadline + _baseDisputeWindow);
oracle.finalize(mockRequest, mockResponse);

vm.prank(disputer);
bytes32 _disputeId = oracle.disputeResponse(_request, _response, _dispute);

assertEq(oracle.disputeOf(_responseId), _disputeId);
vm.expectRevert(abi.encodeWithSelector(IOracle.Oracle_AlreadyFinalized.selector, _requestId));
oracle.disputeResponse(mockRequest, mockResponse, mockDispute);
}

// // dispute a non-existent response
// function test_disputeResponse_nonExistentResponse(bytes32 _nonExistentResponseId) public {
// vm.assume(_nonExistentResponseId != _responseId);
// vm.prank(disputer);

// vm.expectRevert(abi.encodeWithSelector(IOracle.Oracle_InvalidResponseId.selector, _nonExistentResponseId));
// oracle.disputeResponse(_requestId, _nonExistentResponseId, _disputeModuleData);
// }

// function test_disputeResponse_requestAndResponseMismatch() public {
// IOracle.Request memory _request = IOracle.Request({
// requestModuleData: abi.encode(
// IMockRequestModule.RequestParameters({
// url: _expectedUrl,
// body: _expectedBody,
// accountingExtension: _accountingExtension,
// paymentToken: usdc,
// paymentAmount: _expectedReward
// })
// ),
// responseModuleData: abi.encode(
// _accountingExtension, USDC_ADDRESS, _expectedBondAmount, _expectedDeadline, _baseDisputeWindow
// ),
// disputeModuleData: abi.encode(_accountingExtension, USDC_ADDRESS, _expectedBondAmount, _expectedDeadline),
// resolutionModuleData: abi.encode(),
// finalityModuleData: abi.encode(
// IMockFinalityModule.RequestParameters({target: address(_mockCallback), data: abi.encode(_expectedCallbackValue)})
// ),
// requestModule: _requestModule,
// responseModule: _responseModule,
// disputeModule: _disputeModule,
// resolutionModule: _resolutionModule,
// finalityModule: _finalityModule,
// ipfsHash: _ipfsHash
// });
// vm.prank(requester);
// bytes32 _secondRequest = oracle.createRequest(_request, _ipfsHash);

// vm.prank(proposer);
// bytes32 _secondResponseId = oracle.proposeResponse(_secondRequest, _responseData, _responseModuleData);

// vm.prank(disputer);
// vm.expectRevert(abi.encodeWithSelector(IOracle.Oracle_InvalidResponseId.selector, _secondResponseId));
// oracle.disputeResponse(_requestId, _secondResponseId, _disputeModuleData);
// }

// function test_disputeResponse_alreadyFinalized() public {
// vm.warp(_expectedDeadline + _baseDisputeWindow);
// oracle.finalize(_requestId, _responseId);

// vm.prank(disputer);
// vm.expectRevert(abi.encodeWithSelector(IOracle.Oracle_AlreadyFinalized.selector, _requestId));
// oracle.disputeResponse(_requestId, _responseId, _disputeModuleData);
// }

// function test_disputeResponse_alreadyDisputed() public {
// vm.prank(disputer);
// oracle.disputeResponse(_requestId, _responseId, _disputeModuleData);
function test_disputeResponse_alreadyDisputed() public {
vm.prank(disputer);
oracle.disputeResponse(mockRequest, mockResponse, mockDispute);

// vm.prank(disputer);
// vm.expectRevert(abi.encodeWithSelector(IOracle.Oracle_ResponseAlreadyDisputed.selector, _responseId));
// oracle.disputeResponse(_requestId, _responseId, _disputeModuleData);
// }
vm.prank(disputer);
vm.expectRevert(abi.encodeWithSelector(IOracle.Oracle_ResponseAlreadyDisputed.selector, _responseId));
oracle.disputeResponse(mockRequest, mockResponse, mockDispute);
}
}
Loading

0 comments on commit 70d0c1e

Please sign in to comment.