smart contract with brownie gives VirtualMachineError
Question:
I encontered a problem when I test my project, any help would be greatly appreciated.
All my code can be found in here: https://github.com/Karlus44/smartcontract-lottery
When I type the command brownie test
my script tests/test_lottery_unit.py is exectuted, and my different tests are submitted.
Here some quotes of my logout:
Brownie v1.18.1 - Python development framework for Ethereum
================================== test session starts ===================================
platform linux — Python 3.8.10, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: /home/karlus/Documents/NFT-Contract/smartcontract-lottery
plugins: eth-brownie-1.18.1, forked-1.4.0, web3-5.27.0, hypothesis-6.27.3, xdist-1.34.0
collected 4 items
Launching ‘ganache-cli –accounts 10 –hardfork istanbul –gasLimit 12000000 –mnemonic br
ownie –port 8545’…
tests/test_lottery_unit.py …F [100%]
======================================== FAILURES ========================================
__________________________________ test_can_end_lottery __________________________________
def test_can_end_lottery():
# 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()})
fund_with_link(lottery)
print(f"endlottery: {lottery.endLottery}")
transaction = lottery.endLottery({"from": account})
E brownie.exceptions.VirtualMachineError: revert
E Trace step -1, program counter 2469:
E File "/home/karlus/.brownie/packages/smartcontractkit/chainlink-brownie-contract
[email protected]/contracts/src/v0.6/VRFConsumerBase.sol", line 161, in VRFConsumerBase.requestRando
mness:
E function requestRandomness(bytes32 _keyHash, uint256 _fee)
E internal returns (bytes32 requestId)
E {
E LINK.transferAndCall(vrfCoordinator, _fee, abi.encode(_keyHash, USER_SEED_PL
ACEHOLDER));
E // This is the seed passed to VRFCoordinator. The oracle will mix this with
E // the hash of the block containing this request to obtain the seed/input
E // which is finally passed to the VRF cryptographic machinery.
tests/test_lottery_unit.py:58: VirtualMachineError
tests/test_lottery_unit.py:58: VirtualMachineError
———————————- Captured stdout call ———————————-
0x66aB6D9362d4F35596279692F0251Db635165871
Deployed lottery!
Fund contract!
endlottery: <ContractTx ‘endLottery()’>
Transaction sent: 0x59a0a2fdf727591891380c80c0fd90329c8a11b527e24c07d33652b26dfd32c7
================================ short test summary info =================================
FAILED tests/test_lottery_unit.py::test_can_end_lottery – brownie.exceptions.VirtualMac…
============================== 1 failed, 3 passed in 7.97s ===============================
Terminating local RPC client…
Linter
Severity Provider Description Line
So as you can see, my 3 first tests are correctly functionning, but my function fulfillRandomness doesn’t seem to be called, and I can’t figure why.
Answers:
If you’re having a virtual machine check with your ganache port and IP in the settings of your Ethereum VM. If you’re running brownie-compile
and the code is working, then that’s the issue.
Check your fund_with_link
function. Check the amount that you have mentioned. It must be amount = 0.1 * 10**18
.
As mentioned here, https://docs.chain.link/docs/vrf-contracts/v1/ , the fee for, say, Rinkeby test network is 0.1 LINK
.
Check whether the fee you have entered in brownie-config.yaml is 0.1 LINK. This should solve the problem.
I encontered a problem when I test my project, any help would be greatly appreciated.
All my code can be found in here: https://github.com/Karlus44/smartcontract-lottery
When I type the command brownie test
my script tests/test_lottery_unit.py is exectuted, and my different tests are submitted.
Here some quotes of my logout:
Brownie v1.18.1 - Python development framework for Ethereum
================================== test session starts ===================================
platform linux — Python 3.8.10, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: /home/karlus/Documents/NFT-Contract/smartcontract-lottery
plugins: eth-brownie-1.18.1, forked-1.4.0, web3-5.27.0, hypothesis-6.27.3, xdist-1.34.0
collected 4 items
Launching ‘ganache-cli –accounts 10 –hardfork istanbul –gasLimit 12000000 –mnemonic br
ownie –port 8545’…
tests/test_lottery_unit.py …F [100%]
======================================== FAILURES ========================================
__________________________________ test_can_end_lottery __________________________________
def test_can_end_lottery():
# 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()})
fund_with_link(lottery)
print(f"endlottery: {lottery.endLottery}")
transaction = lottery.endLottery({"from": account})
E brownie.exceptions.VirtualMachineError: revert
E Trace step -1, program counter 2469:
E File "/home/karlus/.brownie/packages/smartcontractkit/chainlink-brownie-contract
[email protected]/contracts/src/v0.6/VRFConsumerBase.sol", line 161, in VRFConsumerBase.requestRando
mness:
E function requestRandomness(bytes32 _keyHash, uint256 _fee)
E internal returns (bytes32 requestId)
E {
E LINK.transferAndCall(vrfCoordinator, _fee, abi.encode(_keyHash, USER_SEED_PL
ACEHOLDER));
E // This is the seed passed to VRFCoordinator. The oracle will mix this with
E // the hash of the block containing this request to obtain the seed/input
E // which is finally passed to the VRF cryptographic machinery.
tests/test_lottery_unit.py:58: VirtualMachineError
tests/test_lottery_unit.py:58: VirtualMachineError
———————————- Captured stdout call ———————————-
0x66aB6D9362d4F35596279692F0251Db635165871
Deployed lottery!
Fund contract!
endlottery: <ContractTx ‘endLottery()’>
Transaction sent: 0x59a0a2fdf727591891380c80c0fd90329c8a11b527e24c07d33652b26dfd32c7
================================ short test summary info =================================
FAILED tests/test_lottery_unit.py::test_can_end_lottery – brownie.exceptions.VirtualMac…
============================== 1 failed, 3 passed in 7.97s ===============================
Terminating local RPC client…
Linter
Severity Provider Description Line
So as you can see, my 3 first tests are correctly functionning, but my function fulfillRandomness doesn’t seem to be called, and I can’t figure why.
If you’re having a virtual machine check with your ganache port and IP in the settings of your Ethereum VM. If you’re running brownie-compile
and the code is working, then that’s the issue.
Check your fund_with_link
function. Check the amount that you have mentioned. It must be amount = 0.1 * 10**18
.
As mentioned here, https://docs.chain.link/docs/vrf-contracts/v1/ , the fee for, say, Rinkeby test network is 0.1 LINK
.
Check whether the fee you have entered in brownie-config.yaml is 0.1 LINK. This should solve the problem.