Skip to content

Commit

Permalink
[Functions] (test): Add Functions HasUniqueGlobalRequestId foundry te…
Browse files Browse the repository at this point in the history
…st (#11306)

* (test): Add Functions HasUniqueGlobalRequestId foundry test

* Regenerate gas snapshot
  • Loading branch information
justinkaseman authored Nov 16, 2023
1 parent a75f900 commit 2a947cc
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 22 deletions.
35 changes: 18 additions & 17 deletions contracts/gas-snapshots/functions.gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
ChainSpecificUtil__getCurrentTxL1GasFees_Arbitrum:test__getCurrentTxL1GasFees_SuccessWhenArbitrumGoerli() (gas: 14577815)
ChainSpecificUtil__getCurrentTxL1GasFees_Arbitrum:test__getCurrentTxL1GasFees_SuccessWhenArbitrumMainnet() (gas: 14577793)
ChainSpecificUtil__getCurrentTxL1GasFees_Arbitrum:test__getCurrentTxL1GasFees_SuccessWhenArbitrumSepolia() (gas: 14577809)
ChainSpecificUtil__getCurrentTxL1GasFees_Base:test__getCurrentTxL1GasFees_SuccessWhenBaseGoerli() (gas: 14589229)
ChainSpecificUtil__getCurrentTxL1GasFees_Base:test__getCurrentTxL1GasFees_SuccessWhenBaseMainnet() (gas: 14589206)
ChainSpecificUtil__getCurrentTxL1GasFees_Base:test__getCurrentTxL1GasFees_SuccessWhenBaseSepolia() (gas: 14589178)
ChainSpecificUtil__getCurrentTxL1GasFees_Optimism:test__getCurrentTxL1GasFees_SuccessWhenOptimismGoerli() (gas: 14589129)
ChainSpecificUtil__getCurrentTxL1GasFees_Optimism:test__getCurrentTxL1GasFees_SuccessWhenOptimismMainnet() (gas: 14589118)
ChainSpecificUtil__getCurrentTxL1GasFees_Optimism:test__getCurrentTxL1GasFees_SuccessWhenOptimismSepolia() (gas: 14589162)
ChainSpecificUtil__getCurrentTxL1GasFees_Arbitrum:test__getCurrentTxL1GasFees_SuccessWhenArbitrumGoerli() (gas: 14578318)
ChainSpecificUtil__getCurrentTxL1GasFees_Arbitrum:test__getCurrentTxL1GasFees_SuccessWhenArbitrumMainnet() (gas: 14578296)
ChainSpecificUtil__getCurrentTxL1GasFees_Arbitrum:test__getCurrentTxL1GasFees_SuccessWhenArbitrumSepolia() (gas: 14578312)
ChainSpecificUtil__getCurrentTxL1GasFees_Base:test__getCurrentTxL1GasFees_SuccessWhenBaseGoerli() (gas: 14589732)
ChainSpecificUtil__getCurrentTxL1GasFees_Base:test__getCurrentTxL1GasFees_SuccessWhenBaseMainnet() (gas: 14589709)
ChainSpecificUtil__getCurrentTxL1GasFees_Base:test__getCurrentTxL1GasFees_SuccessWhenBaseSepolia() (gas: 14589681)
ChainSpecificUtil__getCurrentTxL1GasFees_Optimism:test__getCurrentTxL1GasFees_SuccessWhenOptimismGoerli() (gas: 14589632)
ChainSpecificUtil__getCurrentTxL1GasFees_Optimism:test__getCurrentTxL1GasFees_SuccessWhenOptimismMainnet() (gas: 14589621)
ChainSpecificUtil__getCurrentTxL1GasFees_Optimism:test__getCurrentTxL1GasFees_SuccessWhenOptimismSepolia() (gas: 14589665)
FunctionsBilling_Constructor:test_Constructor_Success() (gas: 14812)
FunctionsBilling_DeleteCommitment:test_DeleteCommitment_RevertIfNotRouter() (gas: 13282)
FunctionsBilling_DeleteCommitment:test_DeleteCommitment_Success() (gas: 15897)
Expand All @@ -28,6 +28,7 @@ FunctionsBilling_UpdateConfig:test_UpdateConfig_Success() (gas: 38251)
FunctionsBilling__DisperseFeePool:test__DisperseFeePool_RevertIfNotSet() (gas: 8810)
FunctionsBilling__FulfillAndBill:test__FulfillAndBill_RevertIfInvalidCommitment() (gas: 13302)
FunctionsBilling__FulfillAndBill:test__FulfillAndBill_Success() (gas: 180763)
FunctionsBilling__StartBilling:test__FulfillAndBill_HasUniqueGlobalRequestId() (gas: 398312)
FunctionsClient_Constructor:test_Constructor_Success() (gas: 7573)
FunctionsClient_FulfillRequest:test_FulfillRequest_MaximumGas() (gas: 497786)
FunctionsClient_FulfillRequest:test_FulfillRequest_MinimumGas() (gas: 198990)
Expand All @@ -51,17 +52,17 @@ FunctionsRequest_DEFAULT_BUFFER_SIZE:test_DEFAULT_BUFFER_SIZE() (gas: 246)
FunctionsRequest_EncodeCBOR:test_EncodeCBOR_Success() (gas: 223)
FunctionsRequest_REQUEST_DATA_VERSION:test_REQUEST_DATA_VERSION() (gas: 225)
FunctionsRouter_Constructor:test_Constructor_Success() (gas: 12007)
FunctionsRouter_Fulfill:test_Fulfill_RequestNotProcessedCostExceedsCommitment() (gas: 167459)
FunctionsRouter_Fulfill:test_Fulfill_RequestNotProcessedInsufficientGas() (gas: 157790)
FunctionsRouter_Fulfill:test_Fulfill_RequestNotProcessedCostExceedsCommitment() (gas: 167477)
FunctionsRouter_Fulfill:test_Fulfill_RequestNotProcessedInsufficientGas() (gas: 157808)
FunctionsRouter_Fulfill:test_Fulfill_RequestNotProcessedInvalidCommitment() (gas: 38115)
FunctionsRouter_Fulfill:test_Fulfill_RequestNotProcessedInvalidRequestId() (gas: 35238)
FunctionsRouter_Fulfill:test_Fulfill_RequestNotProcessedSubscriptionBalanceInvariant() (gas: 175935)
FunctionsRouter_Fulfill:test_Fulfill_RequestNotProcessedSubscriptionBalanceInvariant() (gas: 175953)
FunctionsRouter_Fulfill:test_Fulfill_RevertIfNotCommittedCoordinator() (gas: 28086)
FunctionsRouter_Fulfill:test_Fulfill_RevertIfPaused() (gas: 151478)
FunctionsRouter_Fulfill:test_Fulfill_SuccessClientNoLongerExists() (gas: 321037)
FunctionsRouter_Fulfill:test_Fulfill_SuccessFulfilled() (gas: 334658)
FunctionsRouter_Fulfill:test_Fulfill_SuccessUserCallbackReverts() (gas: 2509939)
FunctionsRouter_Fulfill:test_Fulfill_SuccessUserCallbackRunsOutOfGas() (gas: 540418)
FunctionsRouter_Fulfill:test_Fulfill_RevertIfPaused() (gas: 151496)
FunctionsRouter_Fulfill:test_Fulfill_SuccessClientNoLongerExists() (gas: 321059)
FunctionsRouter_Fulfill:test_Fulfill_SuccessFulfilled() (gas: 334680)
FunctionsRouter_Fulfill:test_Fulfill_SuccessUserCallbackReverts() (gas: 2509962)
FunctionsRouter_Fulfill:test_Fulfill_SuccessUserCallbackRunsOutOfGas() (gas: 540441)
FunctionsRouter_GetAdminFee:test_GetAdminFee_Success() (gas: 17983)
FunctionsRouter_GetAllowListId:test_GetAllowListId_Success() (gas: 12904)
FunctionsRouter_GetConfig:test_GetConfig_Success() (gas: 37159)
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/v0.8/functions/tests/v1_X/BaseTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ contract BaseTest is Test {
// BaseTest.setUp is often called multiple times from tests' setUp due to inheritance.
if (s_baseTestInitialized) return;
s_baseTestInitialized = true;
// Set msg.sender to OWNER until stopPrank is called
// Set msg.sender and tx.origin to OWNER until stopPrank is called
vm.startPrank(OWNER_ADDRESS, OWNER_ADDRESS);
}
}
40 changes: 37 additions & 3 deletions contracts/src/v0.8/functions/tests/v1_X/FunctionsBilling.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {FunctionsResponse} from "../../dev/v1_X/libraries/FunctionsResponse.sol"
import {FunctionsSubscriptions} from "../../dev/v1_X/FunctionsSubscriptions.sol";
import {Routable} from "../../dev/v1_X/Routable.sol";

import {FunctionsRouterSetup, FunctionsSubscriptionSetup, FunctionsClientRequestSetup, FunctionsMultipleFulfillmentsSetup} from "./Setup.t.sol";
import {FunctionsRouterSetup, FunctionsSubscriptionSetup, FunctionsClientRequestSetup, FunctionsFulfillmentSetup, FunctionsMultipleFulfillmentsSetup} from "./Setup.t.sol";

/// @notice #constructor
contract FunctionsBilling_Constructor is FunctionsSubscriptionSetup {
Expand Down Expand Up @@ -217,8 +217,42 @@ contract FunctionsBilling__CalculateCostEstimate {
}

/// @notice #_startBilling
contract FunctionsBilling__StartBilling {
// TODO: make contract internal function helper
contract FunctionsBilling__StartBilling is FunctionsFulfillmentSetup {
function test__FulfillAndBill_HasUniqueGlobalRequestId() public {
// Variables that go into a requestId:
// - Coordinator address
// - Consumer contract
// - Subscription ID,
// - Consumer initiated requests
// - Request data
// - Request data version
// - Request callback gas limit
// - Estimated total cost in Juels
// - Request timeout timestamp
// - tx.origin

// Request #1 has already been fulfilled by the test setup

// Reset the nonce (initiatedRequests) by removing and re-adding the consumer
s_functionsRouter.removeConsumer(s_subscriptionId, address(s_functionsClient));
assertEq(s_functionsRouter.getSubscription(s_subscriptionId).consumers.length, 0);
s_functionsRouter.addConsumer(s_subscriptionId, address(s_functionsClient));
assertEq(s_functionsRouter.getSubscription(s_subscriptionId).consumers[0], address(s_functionsClient));

// Make Request #2
_sendAndStoreRequest(
2,
s_requests[1].requestData.sourceCode,
s_requests[1].requestData.secrets,
s_requests[1].requestData.args,
s_requests[1].requestData.bytesArgs,
s_requests[1].requestData.callbackGasLimit
);

// Request #1 and #2 should have different request IDs, because the request timeout timestamp has advanced.
// A request cannot be fulfilled in the same block, which prevents removing a consumer in the same block
assertNotEq(s_requests[1].requestId, s_requests[2].requestId);
}
}

/// @notice #_fulfillAndBill
Expand Down
5 changes: 4 additions & 1 deletion contracts/src/v0.8/functions/tests/v1_X/Setup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ contract FunctionsClientRequestSetup is FunctionsSubscriptionSetup {

// Return prank to Owner
vm.stopPrank();
vm.startPrank(OWNER_ADDRESS);
vm.startPrank(OWNER_ADDRESS, OWNER_ADDRESS);
}

/// @notice Provide a response from the DON to fulfill one or more requests and store the updated balances of the DON & Admin
Expand Down Expand Up @@ -604,6 +604,9 @@ contract FunctionsFulfillmentSetup is FunctionsClientRequestSetup {
function setUp() public virtual override {
FunctionsClientRequestSetup.setUp();

// Fast forward time by 30 seconds to simulate the DON executing the computation
vm.warp(block.timestamp + 30);

// Fulfill request 1
uint256[] memory requestNumberKeys = new uint256[](1);
requestNumberKeys[0] = 1;
Expand Down

0 comments on commit 2a947cc

Please sign in to comment.