VRFCoordinatorV2Mock
Inherits: VRFCoordinatorV2Interface
State Variables
BASE_FEE
uint96 public immutable BASE_FEE;
GAS_PRICE_LINK
uint96 public immutable GAS_PRICE_LINK;
MAX_CONSUMERS
uint16 public immutable MAX_CONSUMERS = 100;
s_currentSubId
uint64 s_currentSubId;
s_nextRequestId
uint256 s_nextRequestId = 1;
s_nextPreSeed
uint256 s_nextPreSeed = 100;
s_subscriptions
mapping(uint64 => Subscription) s_subscriptions;
s_consumers
mapping(uint64 => address[]) s_consumers;
s_requests
mapping(uint256 => Request) s_requests;
Functions
constructor
constructor(uint96 _baseFee, uint96 _gasPriceLink);
consumerIsAdded
function consumerIsAdded(uint64 _subId, address _consumer) public view returns (bool);
onlyValidConsumer
modifier onlyValidConsumer(uint64 _subId, address _consumer);
fulfillRandomWords
fulfillRandomWords fulfills the given request, sending the random words to the supplied
consumer.
This mock uses a simplified formula for calculating payment amount and gas usage, and does
not account for all edge cases handled in the real VRF coordinator. When making requests
against the real coordinator a small amount of additional LINK is required.
function fulfillRandomWords(uint256 _requestId, address _consumer) external;
Parameters
Name | Type | Description |
---|---|---|
_requestId | uint256 | the request to fulfill |
_consumer | address | the VRF randomness consumer to send the result to |
fulfillRandomWordsWithOverride
fulfillRandomWordsWithOverride allows the user to pass in their own random words.
function fulfillRandomWordsWithOverride(uint256 _requestId, address _consumer, uint256[] memory _words) public;
Parameters
Name | Type | Description |
---|---|---|
_requestId | uint256 | the request to fulfill |
_consumer | address | the VRF randomness consumer to send the result to |
_words | uint256[] | user-provided random words |
fundSubscription
fundSubscription allows funding a subscription with an arbitrary amount for testing.
function fundSubscription(uint64 _subId, uint96 _amount) public;
Parameters
Name | Type | Description |
---|---|---|
_subId | uint64 | the subscription to fund |
_amount | uint96 | the amount to fund |
requestRandomWords
function requestRandomWords(
bytes32 _keyHash,
uint64 _subId,
uint16 _minimumRequestConfirmations,
uint32 _callbackGasLimit,
uint32 _numWords
) external override onlyValidConsumer(_subId, msg.sender) returns (uint256);
createSubscription
function createSubscription() external override returns (uint64 _subId);
getSubscription
function getSubscription(uint64 _subId)
external
view
override
returns (uint96 balance, uint64 reqCount, address owner, address[] memory consumers);
cancelSubscription
function cancelSubscription(uint64 _subId, address _to) external override onlySubOwner(_subId);
onlySubOwner
modifier onlySubOwner(uint64 _subId);
getRequestConfig
function getRequestConfig() external pure override returns (uint16, uint32, bytes32[] memory);
addConsumer
function addConsumer(uint64 _subId, address _consumer) external override onlySubOwner(_subId);
removeConsumer
function removeConsumer(uint64 _subId, address _consumer)
external
override
onlySubOwner(_subId)
onlyValidConsumer(_subId, _consumer);
getConfig
function getConfig()
external
view
returns (
uint16 minimumRequestConfirmations,
uint32 maxGasLimit,
uint32 stalenessSeconds,
uint32 gasAfterPaymentCalculation
);
getFeeConfig
function getFeeConfig()
external
view
returns (
uint32 fulfillmentFlatFeeLinkPPMTier1,
uint32 fulfillmentFlatFeeLinkPPMTier2,
uint32 fulfillmentFlatFeeLinkPPMTier3,
uint32 fulfillmentFlatFeeLinkPPMTier4,
uint32 fulfillmentFlatFeeLinkPPMTier5,
uint24 reqsForTier2,
uint24 reqsForTier3,
uint24 reqsForTier4,
uint24 reqsForTier5
);
getFallbackWeiPerUnitLink
function getFallbackWeiPerUnitLink() external view returns (int256);
requestSubscriptionOwnerTransfer
function requestSubscriptionOwnerTransfer(uint64 _subId, address _newOwner) external pure override;
acceptSubscriptionOwnerTransfer
function acceptSubscriptionOwnerTransfer(uint64 _subId) external pure override;
pendingRequestExists
function pendingRequestExists(uint64 subId) public view override returns (bool);
Events
RandomWordsRequested
event RandomWordsRequested(
bytes32 indexed keyHash,
uint256 requestId,
uint256 preSeed,
uint64 indexed subId,
uint16 minimumRequestConfirmations,
uint32 callbackGasLimit,
uint32 numWords,
address indexed sender
);
RandomWordsFulfilled
event RandomWordsFulfilled(uint256 indexed requestId, uint256 outputSeed, uint96 payment, bool success);
SubscriptionCreated
event SubscriptionCreated(uint64 indexed subId, address owner);
SubscriptionFunded
event SubscriptionFunded(uint64 indexed subId, uint256 oldBalance, uint256 newBalance);
SubscriptionCanceled
event SubscriptionCanceled(uint64 indexed subId, address to, uint256 amount);
ConsumerAdded
event ConsumerAdded(uint64 indexed subId, address consumer);
ConsumerRemoved
event ConsumerRemoved(uint64 indexed subId, address consumer);
Errors
InvalidSubscription
error InvalidSubscription();
InsufficientBalance
error InsufficientBalance();
MustBeSubOwner
error MustBeSubOwner(address owner);
TooManyConsumers
error TooManyConsumers();
InvalidConsumer
error InvalidConsumer();
InvalidRandomWords
error InvalidRandomWords();
Structs
Subscription
struct Subscription {
address owner;
uint96 balance;
}
Request
struct Request {
uint64 subId;
uint32 callbackGasLimit;
uint32 numWords;
}