Skip to content

Commit

Permalink
chore: address PR comments
Browse files Browse the repository at this point in the history
- move common logic to internal function
- avoid using fuzzing in integration tests
- use startPrank, get rid of repeated lines
  • Loading branch information
xorsal committed Oct 14, 2024
1 parent 4af7511 commit d75ea20
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 49 deletions.
45 changes: 15 additions & 30 deletions solidity/test/integration/ContractCallRequest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,42 @@ 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();

_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);

Expand All @@ -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);

Expand Down
23 changes: 4 additions & 19 deletions solidity/test/integration/HttpRequest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -32,7 +29,9 @@ contract Integration_HttpRequest is IntegrationBase {
paymentAmount: _expectedReward
})
);
}

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

Expand All @@ -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);

Expand Down

0 comments on commit d75ea20

Please sign in to comment.