Skip to content

Commit

Permalink
test: add expectCall in request module integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xorsal committed Oct 14, 2024
1 parent d75ea20 commit e28fd3a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
18 changes: 16 additions & 2 deletions solidity/test/integration/ContractCallRequest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,18 @@ contract Integration_ContractCallRequest is IntegrationBase {

function test_createRequest_finalizeEmptyResponse() public {
vm.prank(requester);
oracle.createRequest(mockRequest, _ipfsHash);
bytes32 _requestId = oracle.createRequest(mockRequest, _ipfsHash);

// mock an empty response
mockResponse =
IOracle.Response({proposer: makeAddr('not-the-proposer'), requestId: bytes32(0), response: bytes('')});

// expect call to accounting to release requester's funds
vm.expectCall(
address(_accountingExtension),
abi.encodeCall(IAccountingExtension.release, (mockRequest.requester, _requestId, usdc, _expectedReward))
);

vm.warp(block.timestamp + 2 days);
vm.prank(_finalizer);
oracle.finalize(mockRequest, mockResponse);
Expand All @@ -68,8 +74,16 @@ contract Integration_ContractCallRequest is IntegrationBase {
oracle.proposeResponse(mockRequest, mockResponse);
vm.stopPrank();

vm.warp(block.timestamp + _expectedDeadline);
// expect call to accounting to pay the proposer
vm.expectCall(
address(_accountingExtension),
abi.encodeCall(
IAccountingExtension.pay,
(mockResponse.requestId, mockRequest.requester, mockResponse.proposer, usdc, _expectedReward)
)
);

vm.warp(block.timestamp + _expectedDeadline);
vm.prank(_finalizer);
oracle.finalize(mockRequest, mockResponse);
}
Expand Down
17 changes: 16 additions & 1 deletion solidity/test/integration/HttpRequest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,18 @@ contract Integration_HttpRequest is IntegrationBase {

function test_createRequest_finalizeEmptyResponse() public {
vm.prank(requester);
oracle.createRequest(mockRequest, _ipfsHash);
bytes32 _requestId = oracle.createRequest(mockRequest, _ipfsHash);

// mock an empty response
mockResponse =
IOracle.Response({proposer: makeAddr('not-the-proposer'), requestId: bytes32(0), response: bytes('')});

// expect call to accounting to release requester's funds
vm.expectCall(
address(_accountingExtension),
abi.encodeCall(IAccountingExtension.release, (mockRequest.requester, _requestId, usdc, _expectedReward))
);

vm.warp(block.timestamp + _expectedDeadline);

vm.prank(_finalizer);
Expand All @@ -56,6 +62,15 @@ contract Integration_HttpRequest is IntegrationBase {
oracle.proposeResponse(mockRequest, mockResponse);
vm.stopPrank();

// expect call to accounting to pay the proposer
vm.expectCall(
address(_accountingExtension),
abi.encodeCall(
IAccountingExtension.pay,
(mockResponse.requestId, mockRequest.requester, mockResponse.proposer, usdc, _expectedReward)
)
);

vm.warp(block.timestamp + _expectedDeadline);

vm.prank(_finalizer);
Expand Down

0 comments on commit e28fd3a

Please sign in to comment.