【发布时间】:2021-12-14 17:58:27
【问题描述】:
我一直在观看 Patrick(了不起的小伙子)制作的巧克力蛋糕教程视频。不过,在运行特定功能时,我似乎遇到了错误,但其余功能运行良好。我不知道我哪里出错了。
我已附上代码 sn-p 和错误消息
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...
这是错误消息,下面是包含导入和特定函数的代码 sn-p
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'
【问题讨论】:
-
请提供足够的代码,以便其他人更好地理解或重现问题。
标签: python blockchain solidity brownie