From e28fd3adc28f3142791586e84860416a9b8f1145 Mon Sep 17 00:00:00 2001 From: zorzal Date: Mon, 14 Oct 2024 13:02:12 -0400 Subject: [PATCH] test: add expectCall in request module integration tests --- .../test/integration/ContractCallRequest.t.sol | 18 ++++++++++++++++-- solidity/test/integration/HttpRequest.t.sol | 17 ++++++++++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/solidity/test/integration/ContractCallRequest.t.sol b/solidity/test/integration/ContractCallRequest.t.sol index 86e03566..bbaf8ee5 100644 --- a/solidity/test/integration/ContractCallRequest.t.sol +++ b/solidity/test/integration/ContractCallRequest.t.sol @@ -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); @@ -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); } diff --git a/solidity/test/integration/HttpRequest.t.sol b/solidity/test/integration/HttpRequest.t.sol index 11d807d2..894d3097 100644 --- a/solidity/test/integration/HttpRequest.t.sol +++ b/solidity/test/integration/HttpRequest.t.sol @@ -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); @@ -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);