-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: non reverting callback modules (#65)
* feat: replace external contract call with low level call * feat: add MockFailCallback contract a mock callback that always reverts * test: add callback and multiplecallback module integration test * feat: add missing `s` in module's variable name * test: add missing unit test to complete coverage * test: add unit test for reverting callback * fix: apply linter suggestion * test: actually mock the callback to revert * chore: move common setup to an internal fn * test: update multiple callbacks tests
- Loading branch information
Showing
8 changed files
with
247 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.19; | ||
|
||
import './IntegrationBase.sol'; | ||
|
||
contract Integration_CallbackModule is IntegrationBase { | ||
IProphetCallback public callback; | ||
|
||
bytes32 internal _requestId; | ||
bytes internal _expectedData = bytes('a-well-formed-calldata'); | ||
|
||
function setUp() public override { | ||
super.setUp(); | ||
|
||
callback = new MockCallback(); | ||
|
||
mockRequest.finalityModuleData = | ||
abi.encode(ICallbackModule.RequestParameters({target: address(callback), data: _expectedData})); | ||
} | ||
|
||
function test_finalizeExecutesCallback() public { | ||
_setupRequest(); | ||
|
||
vm.expectCall(address(callback), abi.encodeCall(IProphetCallback.prophetCallback, (_expectedData))); | ||
|
||
// advance time past deadline | ||
vm.warp(block.timestamp + _expectedDeadline + _baseDisputeWindow); | ||
oracle.finalize(mockRequest, mockResponse); | ||
} | ||
|
||
function test_callbacksNeverRevert() public { | ||
MockFailCallback _target = new MockFailCallback(); | ||
mockRequest.finalityModuleData = | ||
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.startPrank(requester); | ||
_accountingExtension.approveModule(address(_requestModule)); | ||
_requestId = oracle.createRequest(mockRequest, _ipfsHash); | ||
vm.stopPrank(); | ||
|
||
_deposit(_accountingExtension, proposer, usdc, _expectedBondSize); | ||
vm.startPrank(proposer); | ||
_accountingExtension.approveModule(address(_responseModule)); | ||
mockResponse.response = abi.encode(proposer, _requestId, bytes('')); | ||
oracle.proposeResponse(mockRequest, mockResponse); | ||
vm.stopPrank(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.19; | ||
|
||
import './IntegrationBase.sol'; | ||
|
||
contract Integration_MultipleCallbackModule is IntegrationBase { | ||
uint256 public constant CALLBACKS_AMOUNT = 255; | ||
IProphetCallback public callback; | ||
MultipleCallbacksModule public multipleCallbacksModule; | ||
|
||
bytes32 internal _requestId; | ||
|
||
function setUp() public override { | ||
super.setUp(); | ||
|
||
multipleCallbacksModule = new MultipleCallbacksModule(oracle); | ||
mockRequest.finalityModule = address(multipleCallbacksModule); | ||
|
||
callback = new MockCallback(); | ||
} | ||
|
||
function test_finalizeExecutesCallback() public { | ||
(address[] memory _targets, bytes[] memory _datas) = _createCallbacksData(address(callback), CALLBACKS_AMOUNT); | ||
mockRequest.finalityModuleData = | ||
abi.encode(IMultipleCallbacksModule.RequestParameters({targets: _targets, data: _datas})); | ||
|
||
_setupRequest(); | ||
|
||
for (uint256 _i; _i < _datas.length; _i++) { | ||
vm.expectCall(address(_targets[_i]), abi.encodeCall(IProphetCallback.prophetCallback, (_datas[_i]))); | ||
} | ||
|
||
vm.warp(block.timestamp + _expectedDeadline + _baseDisputeWindow); | ||
oracle.finalize(mockRequest, mockResponse); | ||
} | ||
|
||
function test_callbacksNeverRevert() public { | ||
callback = new MockFailCallback(); | ||
|
||
(address[] memory _targets, bytes[] memory _datas) = _createCallbacksData(address(callback), CALLBACKS_AMOUNT); | ||
|
||
mockRequest.finalityModuleData = | ||
abi.encode(IMultipleCallbacksModule.RequestParameters({targets: _targets, data: _datas})); | ||
|
||
_setupRequest(); | ||
|
||
// expect call to every target with the expected data | ||
for (uint256 _i; _i < _datas.length; _i++) { | ||
vm.expectCall(address(_targets[_i]), abi.encodeCall(IProphetCallback.prophetCallback, (_datas[_i]))); | ||
} | ||
|
||
vm.warp(block.timestamp + _expectedDeadline + _baseDisputeWindow); | ||
oracle.finalize(mockRequest, mockResponse); | ||
} | ||
|
||
function _setupRequest() internal { | ||
_resetMockIds(); | ||
|
||
_deposit(_accountingExtension, requester, usdc, _expectedReward); | ||
vm.startPrank(requester); | ||
_accountingExtension.approveModule(address(_requestModule)); | ||
_requestId = oracle.createRequest(mockRequest, _ipfsHash); | ||
vm.stopPrank(); | ||
|
||
_deposit(_accountingExtension, proposer, usdc, _expectedBondSize); | ||
vm.startPrank(proposer); | ||
_accountingExtension.approveModule(address(_responseModule)); | ||
mockResponse.response = abi.encode(proposer, _requestId, bytes('')); | ||
oracle.proposeResponse(mockRequest, mockResponse); | ||
vm.stopPrank(); | ||
} | ||
|
||
function _createCallbacksData( | ||
address _target, | ||
uint256 _length | ||
) internal returns (address[] memory _targets, bytes[] memory _datas) { | ||
_targets = new address[](_length); | ||
_datas = new bytes[](_length); | ||
for (uint256 _i; _i < _length; _i++) { | ||
_targets[_i] = _target; | ||
_datas[_i] = abi.encode(keccak256(abi.encode(_i))); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters