简体   繁体   中英

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

    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

 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

Lottery.sol: endLottery method? As After copy pasting the test method you have provided it passed successfully.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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