Skip to content

Commit

Permalink
test: additional checks for the request creation
Browse files Browse the repository at this point in the history
  • Loading branch information
gas1cent committed Dec 13, 2023
1 parent a681d28 commit e16c13b
Showing 1 changed file with 64 additions and 19 deletions.
83 changes: 64 additions & 19 deletions solidity/test/integration/RequestCreation.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ contract Integration_RequestCreation is IntegrationBase {
_deposit(_accountingExtension, requester, usdc, _expectedReward);
}

/**
* @notice Test that the request is created correctly with only 3 modules
*/
function test_createRequest_withoutResolutionAndFinalityModules() public {
// Request without resolution and finality modules.
mockRequest.resolutionModule = address(0);
Expand All @@ -27,78 +30,117 @@ contract Integration_RequestCreation is IntegrationBase {

// Check: saved the correct id?
assertEq(_requestId, _getId(mockRequest));

// Check: saved the correct nonce?
assertEq(oracle.nonceToRequestId(mockRequest.nonce), _requestId);

// Check: saved the correct creation block?
assertEq(oracle.createdAt(_requestId), block.number);

// Check: saved the allowed modules?
assertTrue(oracle.allowedModule(_requestId, mockRequest.requestModule));
assertTrue(oracle.allowedModule(_requestId, mockRequest.responseModule));
assertTrue(oracle.allowedModule(_requestId, mockRequest.disputeModule));

// Check: saved the participants?
assertTrue(oracle.isParticipant(_requestId, requester));
}

/**
* @notice Test that the request is created correctly with all modules
*/
function test_createRequest_withAllModules() public {
// Create the request
vm.prank(requester);
bytes32 _requestId = oracle.createRequest(mockRequest, _ipfsHash);

// Check: saved the correct id?
assertEq(_requestId, _getId(mockRequest));
}

function test_createRequest_withReward_UserHasBonded() public {
// Check: should not revert as user has bonded.
vm.prank(requester);
oracle.createRequest(mockRequest, _ipfsHash);
// Check: saved the correct nonce?
assertEq(oracle.nonceToRequestId(mockRequest.nonce), _requestId);

// Check: saved the correct creation block?
assertEq(oracle.createdAt(_requestId), block.number);

// Check: saved the allowed modules?
assertTrue(oracle.allowedModule(_requestId, mockRequest.requestModule));
assertTrue(oracle.allowedModule(_requestId, mockRequest.responseModule));
assertTrue(oracle.allowedModule(_requestId, mockRequest.disputeModule));
assertTrue(oracle.allowedModule(_requestId, mockRequest.resolutionModule));
assertTrue(oracle.allowedModule(_requestId, mockRequest.finalityModule));

// Check: saved the participants?
assertTrue(oracle.isParticipant(_requestId, requester));
}

function test_createRequest_withReward_UserHasNotBonded() public {
// Using WETH as the payment token and not depositing into the accounting extension
/**
* @notice Creating a request without a reward after depositing the bond
*/
function test_createRequest_withoutReward_UserHasBonded() public {
// Request without rewards
mockRequest.requestModuleData = abi.encode(
IHttpRequestModule.RequestParameters({
url: _expectedUrl,
method: _expectedMethod,
body: _expectedBody,
accountingExtension: _accountingExtension,
paymentToken: weth,
paymentAmount: _expectedReward
paymentToken: usdc,
paymentAmount: 0
})
);

// Check: should revert with `InsufficientFunds` as user has not deposited?
vm.expectRevert(IAccountingExtension.AccountingExtension_InsufficientFunds.selector);
// Check: should not revert as user has set no rewards and bonded?
vm.prank(requester);
oracle.createRequest(mockRequest, _ipfsHash);
}

function test_createRequest_withoutReward_UserHasBonded() public {
/**
* @notice Creating a request without a reward and not depositing a bond should not revert
*/
function test_createRequest_withoutReward_UserHasNotBonded() public {
// Request without rewards
mockRequest.requestModuleData = abi.encode(
IHttpRequestModule.RequestParameters({
url: _expectedUrl,
method: _expectedMethod,
body: _expectedBody,
accountingExtension: _accountingExtension,
paymentToken: usdc,
paymentToken: weth,
paymentAmount: 0
})
);

// Check: should not revert as user has set no rewards and bonded?
// Check: doesn't revert if the reward is 0 and the user has not bonded?
vm.prank(requester);
oracle.createRequest(mockRequest, _ipfsHash);
}

function test_createRequest_withoutReward_UserHasNotBonded() public {
// Request without rewards
/**
* @notice Creating a request without any funds deposited to the accounting extension
*/
function test_createRequest_withReward_UserHasNotBonded() public {
// Using WETH as the payment token and not depositing into the accounting extension
mockRequest.requestModuleData = abi.encode(
IHttpRequestModule.RequestParameters({
url: _expectedUrl,
method: _expectedMethod,
body: _expectedBody,
accountingExtension: _accountingExtension,
paymentToken: usdc,
paymentAmount: 0
paymentToken: weth,
paymentAmount: _expectedReward
})
);

// Check: doesn't revert if the reward is 0 and the user has not bonded?
// Check: should revert with `InsufficientFunds` as user has not deposited?
vm.expectRevert(IAccountingExtension.AccountingExtension_InsufficientFunds.selector);
vm.prank(requester);
oracle.createRequest(mockRequest, _ipfsHash);
}

/**
* @notice Creating 2 request with the same parameters
*/
function test_createRequest_duplicate() public {
// Double token amount as each request is a unique bond.
_deposit(_accountingExtension, requester, usdc, _expectedReward * 2);
Expand Down Expand Up @@ -135,6 +177,9 @@ contract Integration_RequestCreation is IntegrationBase {
oracle.createRequest(mockRequest, _ipfsHash);
}

/**
* @notice Reverts if the request module cannot be called
*/
function test_createRequest_withDisallowedModule() public {
mockRequest.requestModule = address(_responseModule);
mockRequest.responseModule = address(_requestModule);
Expand Down

0 comments on commit e16c13b

Please sign in to comment.