full-blockchain-solidity-course-py icon indicating copy to clipboard operation
full-blockchain-solidity-course-py copied to clipboard

cannot import VRFCoordinator Mock from brownie

Open RevanthGundala opened this issue 2 years ago • 4 comments

Screen Shot 2022-03-09 at 7 13 33 PM Screen Shot 2022-03-09 at 7 14 13 PM Screen Shot 2022-03-09 at 7 14 49 PM

Not sure what the issue could be. I have tried deleting the build folder and compiling and that still did not fix anything. Any help would be appreciated.

RevanthGundala avatar Mar 10 '22 02:03 RevanthGundala

Please share the code of VRFCoordinatorMock

cromewar avatar Mar 20 '22 03:03 cromewar

`// SPDX-License-Identifier: MIT
pragma solidity 0.6.6;

import "@chainlink/contracts/src/v0.6/interfaces/LinkTokenInterface.sol";
import "@chainlink/contracts/src/v0.6/VRFConsumerBase.sol";

contract VRFCoordinatorMock {

    LinkTokenInterface public LINK;

    event RandomnessRequest(address indexed sender, bytes32 indexed keyHash, uint256 indexed seed);

    constructor(address linkAddress) public {
        LINK = LinkTokenInterface(linkAddress);
    }

    function onTokenTransfer(address sender, uint256 fee, bytes memory _data)
        public
        onlyLINK
    {
        (bytes32 keyHash, uint256 seed) = abi.decode(_data, (bytes32, uint256));
        emit RandomnessRequest(sender, keyHash, seed);
    }

    function callBackWithRandomness(
        bytes32 requestId,
        uint256 randomness,
        address consumerContract
    ) public {
        VRFConsumerBase v;
        bytes memory resp = abi.encodeWithSelector(v.rawFulfillRandomness.selector, requestId, randomness);
        uint256 b = 206000;
        require(gasleft() >= b, "not enough gas for consumer");
        (bool success,) = consumerContract.call(resp);
    }

    modifier onlyLINK() {
        require(msg.sender == address(LINK), "Must use LINK token");
        _;
    }
}`

RevanthGundala avatar Mar 20 '22 03:03 RevanthGundala

The code seem to be ok, which is the result on console when you do brownie compile ? also change the name folder from test, to tests.

cromewar avatar Mar 20 '22 03:03 cromewar

Dude check out here for the solution :) https://github.com/spo0ds/Journey-to-become-a-Blockchain-Engineer/blob/main/Day20/Day20.md

spo0ds avatar Apr 26 '22 08:04 spo0ds