Skip to content

Commit

Permalink
chore: move common setup to an internal fn
Browse files Browse the repository at this point in the history
  • Loading branch information
xorsal committed Oct 14, 2024
1 parent 0436081 commit 927488b
Showing 1 changed file with 27 additions and 33 deletions.
60 changes: 27 additions & 33 deletions solidity/test/integration/CallbackModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,63 +4,57 @@ pragma solidity ^0.8.19;
import './IntegrationBase.sol';

contract Integration_CallbackModule is IntegrationBase {
IProphetCallback internal _callback;
IProphetCallback public callback;

bytes32 internal _requestId;
uint256 internal _correctValue;
bytes internal _expectedData = bytes('a-well-formed-calldata');

function setUp() public override {
super.setUp();

_callback = new MockCallback();
}
callback = new MockCallback();

function test_finalizeExecutesCallback(bytes memory _data) public {
mockRequest.finalityModuleData =
abi.encode(ICallbackModule.RequestParameters({target: address(_callback), data: _data}));
_resetMockIds();
abi.encode(ICallbackModule.RequestParameters({target: address(callback), data: _expectedData}));
}

// create request
_deposit(_accountingExtension, requester, usdc, _expectedReward);
vm.prank(requester);
_accountingExtension.approveModule(address(_requestModule));
vm.prank(requester);
_requestId = oracle.createRequest(mockRequest, _ipfsHash);
function test_finalizeExecutesCallback() public {
_setupRequest();

// propose response
_deposit(_accountingExtension, proposer, usdc, _expectedBondSize);
vm.prank(proposer);
_accountingExtension.approveModule(address(_responseModule));
mockResponse.response = abi.encode(proposer, _requestId, _correctValue);
vm.prank(proposer);
oracle.proposeResponse(mockRequest, mockResponse);
vm.expectCall(address(callback), abi.encodeCall(IProphetCallback.prophetCallback, (_expectedData)));

// advance time past deadline
vm.warp(_expectedDeadline + _baseDisputeWindow);

vm.warp(block.timestamp + _expectedDeadline + _baseDisputeWindow);
oracle.finalize(mockRequest, mockResponse);
}

function test_callbacksNeverRevert(bytes memory _data) public {
function test_callbacksNeverRevert() public {
MockFailCallback _target = new MockFailCallback();
mockRequest.finalityModuleData =
abi.encode(ICallbackModule.RequestParameters({target: address(new MockFailCallback()), data: _data}));
abi.encode(ICallbackModule.RequestParameters({target: address(_target), data: _expectedData}));
_setupRequest();

// expect call to target passing the expected data
vm.expectCall(address(_target), abi.encodeCall(IProphetCallback.prophetCallback, (_expectedData)));

vm.warp(block.timestamp + _expectedDeadline + _baseDisputeWindow);
oracle.finalize(mockRequest, mockResponse);
}

function _setupRequest() internal {
_resetMockIds();

_deposit(_accountingExtension, requester, usdc, _expectedReward);
vm.prank(requester);
vm.startPrank(requester);
_accountingExtension.approveModule(address(_requestModule));
vm.prank(requester);
_requestId = oracle.createRequest(mockRequest, _ipfsHash);
vm.stopPrank();

_deposit(_accountingExtension, proposer, usdc, _expectedBondSize);
vm.prank(proposer);
vm.startPrank(proposer);
_accountingExtension.approveModule(address(_responseModule));
mockResponse.response = abi.encode(proposer, _requestId, _correctValue);
vm.prank(proposer);
mockResponse.response = abi.encode(proposer, _requestId, bytes(''));
oracle.proposeResponse(mockRequest, mockResponse);

vm.warp(_expectedDeadline + _baseDisputeWindow);

oracle.finalize(mockRequest, mockResponse);
vm.stopPrank();
}
}

0 comments on commit 927488b

Please sign in to comment.