Skip to content

Commit

Permalink
fix: gate setupRequest (#52)
Browse files Browse the repository at this point in the history
# 🤖 Linear

Closes OPO-203
  • Loading branch information
0xng authored Jul 27, 2023
2 parents 01ae0ac + cdf52a7 commit 5fda5ad
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion solidity/contracts/Module.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ abstract contract Module is IModule {
_;
}

function setupRequest(bytes32 _requestId, bytes calldata _data) external {
function setupRequest(bytes32 _requestId, bytes calldata _data) external onlyOracle {
requestData[_requestId] = _data;
_afterSetupRequest(_requestId, _data);
}
Expand Down
1 change: 1 addition & 0 deletions solidity/test/unit/ContractCallRequestModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ contract ContractCallRequestModule_UnitTest is Test {
abi.encodeCall(IAccountingExtension.bond, (_requester, _requestId, _paymentToken, _paymentAmount))
);

vm.prank(address(oracle));
contractCallRequestModule.setupRequest(_requestId, _requestData);

// Check: request data was set?
Expand Down
1 change: 1 addition & 0 deletions solidity/test/unit/HttpRequestModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ contract HttpRequestModule_UnitTest is Test {
address(accounting), abi.encodeCall(IAccountingExtension.bond, (_requester, _requestId, TOKEN, _amount))
);

vm.prank(address(oracle));
httpRequestModule.setupRequest(_requestId, _requestData);

// Check: request data was set?
Expand Down
10 changes: 10 additions & 0 deletions solidity/test/unit/Module.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,22 @@ contract Module_UnitTest is Test {
*/
function test_decodeRequestData(bytes32 _requestId, bytes calldata _data) public {
// Set the request data
vm.prank(address(oracle));
module.setupRequest(_requestId, _data);

// Check: decoded values match original values?
assertEq(module.requestData(_requestId), _data);
}

/**
* @notice Test that setupRequestData reverts if the oracle is not the caller
*/
function test_setupRequestRevertsWhenCalledByNonOracle(bytes32 _requestId, bytes calldata _data) public {
vm.expectRevert(abi.encodeWithSelector(IModule.Module_OnlyOracle.selector));
// Set the request data
module.setupRequest(_requestId, _data);
}

/**
* @notice Test if finalizeRequest can only be called by the oracle
*/
Expand Down

0 comments on commit 5fda5ad

Please sign in to comment.