PatrickAlphaC / smartcontract-lottery

MIT License
79 stars 113 forks source link

contract_address = config["networks"][network.show_active( E KeyError: None #40

Closed allsoldev closed 2 years ago

allsoldev commented 2 years ago

Hi @PatrickAlphaC Thank you for the great course. I am currently finishing lesson 7. Upon running the integration test I am running into the Key Error. I have checked both the functions and brownie-config but still getting the error. Can you please have a look? My complete error __________________________________________________________ ERROR collecting tests/test_lottery_integration.py ___________________________________________________________ tests\test_lottery_integration.py:14: in <module> lottery = deploy_lottery() scripts\deploy_lottery.py:9: in deploy_lottery lottery = Lottery.deploy(get_contract( scripts\helpful_scripts.py:35: in get_contract contract_address = config["networks"][network.show_active( E KeyError: None ======================================================================== short test summary info ======================================================================== FAILED tests/test_lottery_integration.py - KeyError: None !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!

helpful_scripts.py `from brownie import accounts, network, config, MockV3Aggregator, Contract, VRFCoordinatorMock, LinkToken DECIMLS = 8 StartValue = 200000000 FORKED_MAINNET_ENVIRNOMENT = ["mainnet-fork"] LOCAL_BLOCKCHAIN_NETWORKS = ["development", "ganache-local"]

def get_account(index=None, id=None): if index: return accounts[index]

elif id:
    accounts.load(id)
elif network.show_active() in LOCAL_BLOCKCHAIN_NETWORKS or network.show_active() in FORKED_MAINNET_ENVIRNOMENT:
    return accounts[0]

else:
    return accounts.add(config["wallets"]["from_key"])

contract_to_mock = { "eth_usd_price_feed": MockV3Aggregator, "vrf_coordinator": VRFCoordinatorMock, "link_token": LinkToken, }

def get_contract(contract_name): contract_type = contract_to_mock[contract_name] if network.show_active() in LOCAL_BLOCKCHAIN_NETWORKS: if len(contract_type) <= 0: deploy_mock() contract = contract_type[-1] else: contract_address = config["networks"][network.show_active( )][contract_name] contract = Contract.from_abi( contract_type._name, contract_address, contract_type.abi) return contract

def fund_with_link(contract_address, account=None, link_token=None, amount=5000000000000000000): account = account if account else get_account() link_token = link_token if link_token else get_contract("link_token") tx = link_token.transfer(contract_address, amount, {"from": account}) tx.wait(1) print("Contract Funded") return tx

def deploy_mock(decimals=DECIMLS, initial_value=StartValue): account = get_account() MockV3Aggregator.deploy( decimals, initial_value, {"from": account}) link_token = LinkToken.deploy({"from": account}) VRFCoordinatorMock.deploy(link_token.address, {"from": account})

print("Mocks Deployed!")

deploy_lottery.py import time from scripts.helpful_scripts import get_account, get_contract, fund_with_link from brownie import Lottery, accounts, config, network

def deploy_lottery(): account = get_account() lottery = Lottery.deploy(get_contract( "eth_usd_price_feed").address, get_contract("vrf_coordinator").address, get_contract("link_token").address, config["networks"][network.show_active()]["fee"], config["networks"][network.show_active()]["keyhash"], {"from": account}, publish_source=config["networks"][network.show_active()].get("verify", False)) print("Lottery Deployed") return lottery

def start_lottery(): account = get_account() lottery = Lottery[-1] start_tx = lottery.startLottery({"from": account}) start_tx.wait(1) print("Lottery Started")

def enter_lottery(): account = get_account() lottery = Lottery[-1] enter_value = lottery.getEntraceFee()+100000000 enter_tx = lottery.enter({"from": account, "value": enter_value}) enter_tx.wait(1) print("Entered in the Lottery")

def end_lottery(): account = get_account() lottery = Lottery[-1] tx = fund_with_link(lottery.address) tx.wait(1) end_tx = lottery.EndLottery({"from": account}) end_tx.wait(1) print("Awaiting Response") time.sleep(60) print(f"{lottery.winner} is the new winner!")

def main(): deploy_lottery() start_lottery() enter_lottery() end_lottery() `

brownie-config.yaml

`dependencies:

- organization/repo>@<version

Your efforts towards the community are really appreciated

PatrickAlphaC commented 2 years ago

Could you please make this issue in the larger repo? Thanks!

https://github.com/smartcontractkit/full-blockchain-solidity-course-py