我一直在看帕特里克(很棒的小伙子)的布朗尼教程视频。不过,在运行特定功能时,我似乎遇到了错误,但其余功能运行良好。我不知道我哪里错了。
我附上了代码片段和错误消息
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)
starting_balance_of_account = account.balance()
balance_of_lottery = lottery.balance()
transaction = lottery.endLottery({"from": account})
> request_id = transaction.events["RequestedRandomness"]["requestId"]
E brownie.exceptions.EventLookupError: Event 'RequestedRandomness' did not fire.
tests/test_lottery_uint.py:78: EventLookupError
------------------------------------------------------- Captured stdout call --------------------------------------------------------
Deployed lottery!
Fund contract!
====================================================== short test summary info ======================================================
FAILED tests/test_lottery_uint.py::test_can_pick_winner_correctly - brownie.exceptions.EventLookupError: Event 'RequestedRandomnes...
这是错误消息,下面是包含导入和特定函数的代码片段
from scripts.helpful_scripts import (
LOCAL_BLOCKCHAIN_ENVIRONMENTS,
get_account,
fund_with_link,
get_contract,
)
from brownie import Lottery, accounts, config, network, exceptions
from scripts.deploy_lottery import deploy_lottery
from web3 import Web3
import pytest
这些是进口商品,具体功能如下
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)
starting_balance_of_account = account.balance()
balance_of_lottery = lottery.balance()
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
assert lottery.recentWinner() == account
assert lottery.balance() == 0
assert account.balance() == starting_balance_of_account + balance_of_lottery'