Comments (4)
@leovafme, how about something like this? (Haven't had time to try it btw, this is just a pseudo-code)
const vrfConsumerBaseV2Mock: MockContract = await waffle.deployMockContract(
deployer,
VRF_CONSUMER_BASE_V2_ABI
);
const randomWords = [BigNumber.from(`777`)];
vrfConsumerBaseV2Mock.mock.rawFulfillRandomWords(requestId, randomWords).returns();
// or
vrfConsumerBaseV2Mock.mock["rawFulfillRandomWords(uint256, uint256[])"].withArgs(requestId, randomWords).returns();
from hardhat-starter-kit.
Hey @leovafme, thanks for raising this issue. This repo use VRFCoordinatorV2Mock from @chainlink/contracts
package. V1 mock expected uint
to be passed to the fulfillment function, while V2 mock calculates it, you can see how from the implementation. You can either calculate those mock random numbers inside the test itself using ethers.js following the implementation from the VRFCoordinatorV2Mock, OR you can always create your own mock contract/function to test a "specific number" scenario. Maybe this repo from the "Testing with Hardhat" workshop at Chainlink Spring 2022 Hackathon can help you with the mocks alongside the hardhat-starter-kit
repo, of course. Let me know if I can close this or if you maybe have additional questions? Thanks.
from hardhat-starter-kit.
Hi @andrejrakic. Thank you very much for quick response.
I tried to do as you say but I can't find a solution to the dilemma. I have searched and I have not seen any place that has implemented this successfully.
Is there a repository or someone who has implemented it? Thanks.
from hardhat-starter-kit.
Hi @andrejrakic thanks for the code snippet. I tests it. the function rawFulfillRandomWords required OnlyCoordinatorCanFulfill(msg.sender, vrfCoordinator). I extended VRFCoordinatorV2Mock
pragma solidity ^0.8.0;
import "@chainlink/contracts/src/v0.8/mocks/VRFCoordinatorV2Mock.sol";
contract VRFCoordinatorV2MockHelper is VRFCoordinatorV2Mock {
constructor(uint96 _baseFee, uint96 _gasPriceLink) VRFCoordinatorV2Mock(_baseFee, _gasPriceLink) {}
receive() external payable {}
}
in test fund ether to VRFCoordinatorV2MockHelper and use hardhat_impersonateAccount for call vrfConsumerBaseV2Mock
deployer.sendTransaction({
to: vrfCoordinatorV2Mock.address,
value: ethers.utils.parseEther("5.0"),
});
await ethers.provider.send("hardhat_impersonateAccount", [vrfCoordinatorV2Mock.address]);
await ethers.provider.send("evm_mine")
const signer = await ethers.getSigner(vrfCoordinatorV2Mock.address);
const randomWords = [777, 778];
await randomNumberConsumerV2.connect(signer).rawFulfillRandomWords(requestId, randomWords);
this works for me, but is it the proper implementation? Thanks.
from hardhat-starter-kit.
Related Issues (20)
- Add example with `VRFV2Wrapper`
- @ledgerheq/hw-transport-node-hid version ^4.3.0 fails on build HOT 2
- Add Ankr's Public RPCs HOT 2
- Upgrade plugins with @nomicfoundation/hardhat-toolbox HOT 1
- Update to goerli HOT 2
- Npm install is catching an error
- error An unexpected error occurred: "Commit hash required" HOT 3
- [SUGGESTION OF FIX] Error running JSON-RPC server: The number NaN cannot be converted to a BigInt because it is not an integer
- [SUGGESTION OF FIX] "TypeError: customChains is not iterable" When verifying contract. HOT 3
- Upgrade to the hardhat toolbox HOT 1
- [Suggestion] Create npx util to generate empty project HOT 1
- Rename "PRIVATE_KEY" variable to "WALLET_PRIVATE_KEY" HOT 4
- [Bug]: Typo in README.md HOT 1
- NomicLabsHardhatPluginError: Failed to send contract verification request. when using this command “npm run deploy --network sepolia” HOT 1
- Can we write a script to deploy Chainlink automation specifically for use by Register new Upkeep?
- Failed to deploy to different networks than default HOT 1
- ethers.getContract is not a function HOT 1
- replace fund-link with transfer-link
- echidna-test command not found
- Switch to Hardhat configuration variables instead of using `.env` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hardhat-starter-kit.