Lesson 7: FAILED tests/test_lottery_unit.py::test_can_pick_winner_correctly - AttributeError: Contract 'VRFCoordinatorMock' object has no attribute 'callbackWithRandomness' #1408
-
Hello everyone, I'm having an error when running the test_can_pick_winner correctly, which I've pasted in the title: AttributeError: Contract 'VRFCoordinatorMock' object has no attribute 'callbackWithRandomness' It's very weird, because the VRFCoordinatorMock file looks ok on my end, and has the callbackWithRandomness function, which is public -I'm therefore at a bit of a loss, and any help would be greatly appreciated! thanks a lot in advance! Cheers, pascal Here is the code for the test: def test_can_pick_winner_correctly():
# Arrange
if network.show_active not in LOCAL_BLOCKCHAIN_ENVIRONMENTS:
pytest.skip
lottery = deploy_lottery()
account = get_account()
lottery.startLottery({"from": account})
lottery.enter({"from": account, "value": lottery.getEntranceFee()})
lottery.enter({"from": get_account(index=1), "value": lottery.getEntranceFee()})
lottery.enter({"from": get_account(index=2), "value": lottery.getEntranceFee()})
fund_with_link(lottery)
transaction = lottery.endLottery({"from": account})
request_id = transaction.events["RequestedRandomness"]["requestId"]
STATIC_RNG = 777
get_contract("vrf_coordinator").callbackWithRandomness(
request_id, STATIC_RNG, lottery.address, {"from": account}
)
# 777 % 3 = 0
starting_balance_of_account = account.balance()
balance_of_lottery = lottery.balance()
assert lottery.recentWinner() == account
assert lottery.balance() == 0
assert account.balance() == starting_balance_of_account + balance_of_lottery And here is the error trail:
brownie-config.yaml: dependencies:
# - organisation/repo@version
- smartcontractkit/chainlink-brownie-contracts@1.1.1
- OpenZeppelin/openzeppelin-contracts@3.4.0
compiler:
solc:
remappings:
- "@chainlink=smartcontractkit/chainlink-brownie-contracts@1.1.1"
- "@openzeppelin=OpenZeppelin/openzeppelin-contracts@3.4.0"
dotenv: .env
networks:
default: development
development:
keyhash: "0x2ed0feb3e7fd2022120aa84fab1945545a9f2ffc9076fd6156fa96eaff4c1311"
fee: 100000000000000000
rinkeby:
vrf_coordinator: "0xb3dCcb4Cf7a26f6cf6B120Cf5A73875B7BBc655B"
eth_usd_price_feed: "0x8A753747A1Fa494EC906cE90E9f37563A8AF630e"
keyhash: "0x2ed0feb3e7fd2022120aa84fab1945545a9f2ffc9076fd6156fa96eaff4c1311"
link_token: "0x01BE23585060835E02B77ef475b0Cc51aA1e0709"
fee: 100000000000000000
verify: True
mainnet-fork:
eth_usd_price_feed: "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419"
wallets:
from_key: ${PRIVATE_KEY} And, finally, the code for get_contract(): def get_contract(contract_name):
"""This function will grab the contract addresses from the brownie config
if defined, otherwise it will deploy a mock version of that contract, and return that
mock contract.
Args:
contract_name (string)
Returns:
brownie.network.contract.ProjectContract: the most recently deployed version of this contract.
"""
contract_type = contract_to_mock[contract_name]
if network.show_active() in LOCAL_BLOCKCHAIN_ENVIRONMENTS:
if len(contract_type) <= 0:
# MockV3Aggregator.lenth
deploy_mocks()
contract = contract_type[-1]
# MockV3Aggregator[-1]
else:
contract_address = config["networks"][network.show_active()][contract_name]
contract = Contract.from_abi(
contract_type._name, contract_address, contract_type.abi
)
# MockV3Aggregator.abi
return contract Here is the VRFCoordinatorMock.sol file: // 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");
_;
}
}
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
Hello @pbelouin-mpiwg that's a strange error, so we will need more info on this: The complete error log and the code of the test. Please give it a check to #980 in order to know how to make more complete questions so we could provide you better assistance. |
Beta Was this translation helpful? Give feedback.
-
I figured it out, it was a typo in the function's name: callback vs callBack!!!! Thank you again for your help, I'll keep forging ahead! |
Beta Was this translation helpful? Give feedback.
I figured it out, it was a typo in the function's name:
callback vs callBack!!!!
Thank you again for your help, I'll keep forging ahead!