Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:defi-wonderland/prophet-core into fe…
Browse files Browse the repository at this point in the history
…at/validate-proposer
  • Loading branch information
ashitakah committed Jul 12, 2024
2 parents 1752678 + 1e39da6 commit 1b9a059
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
8 changes: 6 additions & 2 deletions solidity/contracts/Oracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,14 @@ contract Oracle is IOracle {
* @param _ipfsHash The hashed IPFS CID of the metadata json
* @return _requestId The id of the created request
*/
function _createRequest(Request calldata _request, bytes32 _ipfsHash) internal returns (bytes32 _requestId) {
function _createRequest(Request memory _request, bytes32 _ipfsHash) internal returns (bytes32 _requestId) {
uint256 _requestNonce = totalRequestCount++;

if (_requestNonce != _request.nonce || msg.sender != _request.requester) revert Oracle_InvalidRequestBody();
if (_request.nonce == 0) _request.nonce = uint96(_requestNonce);

if (msg.sender != _request.requester || _requestNonce != _request.nonce) {
revert Oracle_InvalidRequestBody();
}

_requestId = keccak256(abi.encode(_request));
nonceToRequestId[_requestNonce] = _requestId;
Expand Down
2 changes: 1 addition & 1 deletion solidity/test/integration/IntegrationBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {IWETH9} from '../utils/external/IWETH9.sol';
// solhint-enable no-unused-import

contract IntegrationBase is TestConstants, Helpers {
uint256 public constant FORK_BLOCK = 117_320_618;
uint256 public constant FORK_BLOCK = 122_612_760;

uint256 internal _initialBalance = 100_000 ether;

Expand Down
37 changes: 37 additions & 0 deletions solidity/test/unit/Oracle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,43 @@ contract Oracle_Unit_CreateRequests is BaseTest {
uint256 _newNonce = oracle.totalRequestCount();
assertEq(_newNonce, _initialNonce + _requestsAmount);
}

/**
* @notice Test creation of requests in batch mode with nonce 0.
*/
function test_createRequestsWithNonceZero(
bytes calldata _requestData,
bytes calldata _responseData,
bytes calldata _disputeData
) public {
uint256 _initialNonce = oracle.totalRequestCount();
uint256 _requestsAmount = 5;
IOracle.Request[] memory _requests = new IOracle.Request[](_requestsAmount);
bytes32[] memory _precalculatedIds = new bytes32[](_requestsAmount);
bytes32[] memory _ipfsHashes = new bytes32[](_requestsAmount);

mockRequest.requestModuleData = _requestData;
mockRequest.responseModuleData = _responseData;
mockRequest.disputeModuleData = _disputeData;
mockRequest.requester = requester;
mockRequest.nonce = uint96(0);

bytes32 _theoreticalRequestId = _getId(mockRequest);
bytes32 _ipfsHash = keccak256(abi.encode(_theoreticalRequestId, uint96(0)));

// Generate requests batch
for (uint256 _i = 0; _i < _requestsAmount; _i++) {
_requests[_i] = mockRequest;
_precalculatedIds[_i] = _theoreticalRequestId;
_ipfsHashes[_i] = _ipfsHash;
}

vm.prank(requester);
oracle.createRequests(_requests, _ipfsHashes);

uint256 _newNonce = oracle.totalRequestCount();
assertEq(_newNonce, _initialNonce + _requestsAmount);
}
}

contract Oracle_Unit_ListRequestIds is BaseTest {
Expand Down

0 comments on commit 1b9a059

Please sign in to comment.