简体   繁体   English

brownie - 我如何处理异常?

[英]brownie - How do I handle exceptions?

I've been watching a brownie tutorial video by Patrick (fantastic lad).我一直在看帕特里克(很棒的小伙子)的布朗尼教程视频。 Still, I seem to be getting an error when running a particular function, but the rest of the functions run perfectly.不过,在运行特定的 function 时,我似乎遇到了错误,但功能的 rest 运行完美。 I don't know where I went wrong.我不知道我哪里错了。

I've attached the code snippet and the error message我附上了代码片段和错误消息

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...

This the error message, and below is the code snippet that includes the imports and the particular function这是错误消息,下面是包含导入和特定 function 的代码片段

    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

These are the imports and the particular function is below这些是进口的,下面是特定的 function

 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'

Are you sure that you are emitting that event from Share the code from您确定要从 Share the code from 发出该事件吗

Lottery.sol: endLottery method? Lottery.sol:endLottery 方法? As After copy pasting the test method you have provided it passed successfully.在复制粘贴您提供的测试方法后,它成功通过。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM