Giter VIP home page Giter VIP logo

Comments (4)

andrejrakic avatar andrejrakic commented on June 8, 2024 1

@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.

andrejrakic avatar andrejrakic commented on June 8, 2024

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.

leovafme avatar leovafme commented on June 8, 2024

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.

leovafme avatar leovafme commented on June 8, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.