smartcontractkit / full-blockchain-solidity-course-py

Ultimate Solidity, Blockchain, and Smart Contract - Beginner to Expert Full Course | Python Edition
MIT License
10.81k stars 2.91k forks source link

Attribute Error 'NoneType' object has no attribute 'poll' #602

Open JMiddey opened 2 years ago

JMiddey commented 2 years ago

I am getting the following error when trying to test my lottery (from video part @06:28:00) brownie test --network mainnet-fork Brownie v1.16.4 - Python development framework for Ethereum

======================================================================================== test session starts ======================================================================================== platform darwin -- Python 3.10.1, pytest-6.2.5, py-1.10.0, pluggy-1.0.0 rootdir: /Users/joe/demos/smartcontract-lottery plugins: eth-brownie-1.16.4, hypothesis-6.21.6, xdist-1.34.0, web3-5.23.1, forked-1.3.0 collected 1 item

Launching 'ganache-cli --accounts 10 --fork https://eth-mainnet.alchemyapi.io/v2/NrlINoZBBBd2iLXJVLulIPdGk6UEczAF --mnemonic brownie --port 7545 --hardfork istanbul'... Terminating local RPC client... INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/_pytest/main.py", line 269, in wrap_session INTERNALERROR> session.exitstatus = doit(config, session) or 0 INTERNALERROR> File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/_pytest/main.py", line 322, in _main INTERNALERROR> config.hook.pytest_collection(session=session) INTERNALERROR> File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in call INTERNALERROR> return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult) INTERNALERROR> File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult) INTERNALERROR> File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pluggy/_callers.py", line 60, in _multicall INTERNALERROR> return outcome.get_result() INTERNALERROR> File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result INTERNALERROR> raise ex[1].with_traceback(ex[2]) INTERNALERROR> File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/_pytest/main.py", line 333, in pytest_collection INTERNALERROR> session.perform_collect() INTERNALERROR> File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/_pytest/main.py", line 641, in perform_collect INTERNALERROR> hook.pytest_collection_finish(session=self) INTERNALERROR> File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in call INTERNALERROR> return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult) INTERNALERROR> File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult) INTERNALERROR> File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pluggy/_callers.py", line 55, in _multicall INTERNALERROR> gen.send(outcome) INTERNALERROR> File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/brownie/test/managers/runner.py", line 258, in pytest_collection_finish INTERNALERROR> brownie.network.connect(CONFIG.argv["network"]) INTERNALERROR> File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/brownie/network/main.py", line 50, in connect INTERNALERROR> rpc.launch(active["cmd"], **active["cmd_settings"]) INTERNALERROR> File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/brownie/network/rpc/init.py", line 95, in launch INTERNALERROR> raise RPCConnectionError(cmd, self.process, uri) INTERNALERROR> File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/brownie/exceptions.py", line 41, in init INTERNALERROR> f"\n\nCommand: {cmd}\nURI: {uri}\nExit Code: {proc.poll()}" INTERNALERROR> AttributeError: 'NoneType' object has no attribute 'poll'

====================================================================================== no tests ran in 12.06s =======================================================================================

Lottery.sol file = //SPDX-License-Identifier: MIT pragma solidity ^0.6.6;

import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";

contract Lottery { address payable[] public players; uint256 public usdEntryFee; AggregatorV3Interface internal ethUsdPriceFeed;

constructor(address _priceFeedAddress) public {
    usdEntryFee = 50 * (10**18);
    ethUsdPriceFeed = AggregatorV3Interface(_priceFeedAddress);
}

function enter() public payable {
    //minimum USD
    players.push(msg.sender);
}

function getEntranceFee() public view returns (uint256) {
    (, int256 price, , , ) = ethUsdPriceFeed.latestRoundData();
    uint256 adjustedPrice = uint256(price) * 10**10;
    uint256 costToEnter = (usdEntryFee * 10**18) / adjustedPrice;
    return costToEnter;
}

function startLottery() public {}

function endLottery() public {}

}

Test_lottery.py = from brownie import Lottery, accounts, network, config from web3 import Web3

def test_get_entrance_fee(): account = accounts[0] lottery = Lottery.deploy( config["networks"][network.show_active()]["eth_usd_price_feed"], {"from": account}, ) assert lottery.getEntranceFee() > Web3.toWei(0.018, "ether") assert lottery.getEntranceFee() < Web3.toWei(0.022, "ether")

config = dependencies:

networks: mainnet-fork: eth_usd_price_feed: '0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419'

cromewar commented 2 years ago

I would pretty much suggest you to use python version 3.8, the latest ones have been reported as not fully compatible with web3 libraries.

JMiddey commented 2 years ago

I have switched my python version to 3.8, but in the code it still says Python 3.10.1, why is that? I have closed and opened a new terminal so don't think thats the reason joe@Joes-MacBook-Pro smartcontract-lottery % python3 --version Python 3.8.0 joe@Joes-MacBook-Pro smartcontract-lottery % python --version Python 2.7.18 joe@Joes-MacBook-Pro smartcontract-lottery % brownie test Brownie v1.16.4 - Python development framework for Ethereum

======================================================================================== test session starts ======================================================================================== platform darwin -- Python 3.10.1, pytest-6.2.5, py-1.10.0, pluggy-1.0.0 rootdir: /Users/joe/demos/smartcontract-lottery plugins: eth-brownie-1.16.4, hypothesis-6.21.6, xdist-1.34.0, web3-5.23.1, forked-1.3.0 collected 1 item

Launching 'ganache-cli --accounts 10 --hardfork istanbul --gasLimit 12000000 --mnemonic brownie --port 8545'...

tests/test_lottery.py F [100%]

============================================================================================= FAILURES ============================================================================================== ___ test_get_entrance_fee ___

def test_get_entrance_fee():
    account = accounts[0]
    lottery = Lottery.deploy(
      config["networks"][network.show_active()]["eth_usd_price_feed"],

{"from": account}, ) E KeyError: 'eth_usd_price_feed'

tests/test_lottery.py:8: KeyError ====================================================================================== short test summary info ====================================================================================== FAILED tests/test_lottery.py::test_get_entrance_fee - KeyError: 'eth_usd_price_feed' ========================================================================================= 1 failed in 1.31s ========================================================================================= Terminating local RPC client... joe@Joes-MacBook-Pro smartcontract-lottery %

cromewar commented 2 years ago

Do no forget to change the pyhton interpreter on vscode (bottom left corner) before opening it's terminal. If you are using the mac terminal you can refer to this: https://ahmadawais.com/how-to-set-python-default-version-to-3-on-macos/

JMiddey commented 2 years ago

This says I need homebrew but I've found it clashes with node, can i do without? (Thanks btw)

cromewar commented 2 years ago

Well you can uninstall node, and install it through brew, which is actually a good way no manage node packages as same as yarn.