From d75ea20dec83e0b3b8b245bb96eb901fc7850d6d Mon Sep 17 00:00:00 2001 From: zorzal Date: Mon, 14 Oct 2024 11:39:47 -0400 Subject: [PATCH] chore: address PR comments - move common logic to internal function - avoid using fuzzing in integration tests - use startPrank, get rid of repeated lines --- .../integration/ContractCallRequest.t.sol | 45 +++++++------------ solidity/test/integration/HttpRequest.t.sol | 23 ++-------- 2 files changed, 19 insertions(+), 49 deletions(-) diff --git a/solidity/test/integration/ContractCallRequest.t.sol b/solidity/test/integration/ContractCallRequest.t.sol index a879d883..86e03566 100644 --- a/solidity/test/integration/ContractCallRequest.t.sol +++ b/solidity/test/integration/ContractCallRequest.t.sol @@ -9,12 +9,16 @@ import {MockCallee} from '../mocks/MockCallee.sol'; import './IntegrationBase.sol'; contract Integration_ContractCallRequest is IntegrationBase { + ContractCallRequestModule public contractCallRequestModule; + address internal _finalizer = makeAddr('finalizer'); string internal _url = 'an-url'; string internal _body = 'a-body'; + bytes4 internal _selector = bytes4(0xBaadF00d); + bytes internal _calldata = bytes('well-formed-calldata'); + MockCallee internal _target; - ContractCallRequestModule internal _contractCallRequestModule; function setUp() public override { super.setUp(); @@ -22,27 +26,25 @@ contract Integration_ContractCallRequest is IntegrationBase { _deposit(_accountingExtension, requester, usdc, _expectedReward); _deposit(_accountingExtension, proposer, usdc, _expectedBondSize); - _contractCallRequestModule = new ContractCallRequestModule(oracle); + contractCallRequestModule = new ContractCallRequestModule(oracle); _target = new MockCallee(); - } - - function test_createRequest_finalizeEmptyResponse(bytes4 _selector, bytes calldata _data) public { - mockRequest.requestModule = address(_contractCallRequestModule); - - vm.prank(requester); - _accountingExtension.approveModule(address(mockRequest.requestModule)); + mockRequest.requestModule = address(contractCallRequestModule); mockRequest.requestModuleData = abi.encode( IContractCallRequestModule.RequestParameters({ target: address(_target), functionSelector: _selector, - data: _data, + data: _calldata, accountingExtension: _accountingExtension, paymentToken: usdc, paymentAmount: _expectedReward }) ); + vm.prank(requester); + _accountingExtension.approveModule(address(mockRequest.requestModule)); + } + function test_createRequest_finalizeEmptyResponse() public { vm.prank(requester); oracle.createRequest(mockRequest, _ipfsHash); @@ -51,37 +53,20 @@ contract Integration_ContractCallRequest is IntegrationBase { IOracle.Response({proposer: makeAddr('not-the-proposer'), requestId: bytes32(0), response: bytes('')}); vm.warp(block.timestamp + 2 days); - vm.prank(_finalizer); oracle.finalize(mockRequest, mockResponse); } - function test_createRequest_finalizeValidResponse(bytes4 _selector, bytes calldata _data) public { - mockRequest.requestModule = address(_contractCallRequestModule); - - vm.prank(requester); - _accountingExtension.approveModule(address(mockRequest.requestModule)); - - mockRequest.requestModuleData = abi.encode( - IContractCallRequestModule.RequestParameters({ - target: address(_target), - functionSelector: _selector, - data: _data, - accountingExtension: _accountingExtension, - paymentToken: usdc, - paymentAmount: _expectedReward - }) - ); - + function test_createRequest_finalizeValidResponse() public { vm.prank(requester); bytes32 _requestId = oracle.createRequest(mockRequest, _ipfsHash); mockResponse = IOracle.Response({proposer: proposer, requestId: _requestId, response: bytes('good-answer')}); - vm.prank(proposer); + vm.startPrank(proposer); _accountingExtension.approveModule(address(_responseModule)); - vm.prank(proposer); oracle.proposeResponse(mockRequest, mockResponse); + vm.stopPrank(); vm.warp(block.timestamp + _expectedDeadline); diff --git a/solidity/test/integration/HttpRequest.t.sol b/solidity/test/integration/HttpRequest.t.sol index e4e4c436..11d807d2 100644 --- a/solidity/test/integration/HttpRequest.t.sol +++ b/solidity/test/integration/HttpRequest.t.sol @@ -16,12 +16,9 @@ contract Integration_HttpRequest is IntegrationBase { _deposit(_accountingExtension, requester, usdc, _expectedReward); _deposit(_accountingExtension, proposer, usdc, _expectedBondSize); - } - function test_createRequest_finalizeEmptyResponse() public { vm.prank(requester); _accountingExtension.approveModule(address(_requestModule)); - mockRequest.requestModuleData = abi.encode( IHttpRequestModule.RequestParameters({ url: _url, @@ -32,7 +29,9 @@ contract Integration_HttpRequest is IntegrationBase { paymentAmount: _expectedReward }) ); + } + function test_createRequest_finalizeEmptyResponse() public { vm.prank(requester); oracle.createRequest(mockRequest, _ipfsHash); @@ -47,29 +46,15 @@ contract Integration_HttpRequest is IntegrationBase { } function test_createRequest_finalizeValidResponse() public { - vm.prank(requester); - _accountingExtension.approveModule(address(_requestModule)); - - mockRequest.requestModuleData = abi.encode( - IHttpRequestModule.RequestParameters({ - url: _url, - method: METHOD, - body: _body, - accountingExtension: _accountingExtension, - paymentToken: usdc, - paymentAmount: _expectedReward - }) - ); - vm.prank(requester); bytes32 _requestId = oracle.createRequest(mockRequest, _ipfsHash); mockResponse = IOracle.Response({proposer: proposer, requestId: _requestId, response: bytes('good-answer')}); - vm.prank(proposer); + vm.startPrank(proposer); _accountingExtension.approveModule(address(_responseModule)); - vm.prank(proposer); oracle.proposeResponse(mockRequest, mockResponse); + vm.stopPrank(); vm.warp(block.timestamp + _expectedDeadline);