smartcontractkit / full-blockchain-solidity-course-py

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

SMARTCONTRACT LOTTERY #1662

Closed AlrohfAZ closed 2 years ago

AlrohfAZ commented 2 years ago

I deployed the contract but it keeps returning a keyerror and even when I test the code it returns a keyerror also, I've checked through the config file and can not see the issue. Although I just installed truffle recently, before installing truffle the test passed so I don't know if that has anything to do with it, the deploy_lottery code and the config file are respectively placed below;

from scripts.helpful_scripts import get_account, get_contract
from brownie import lottery, config, network

def deploy_lottery():
    account = get_account()
    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("Deployed Lottery!")

def start_lottery():
    account = get_account()
    Lottery = lottery[-1]
    starting_tx = Lottery.startlottery({"from": account})
    starting_tx.wait(1)
    print("The lottery has begun")

def main():
    deploy_lottery()
    start_lottery()
dependencies:
  - smartcontractkit/chainlink-brownie-contracts@1.1.1
  - OpenZeppelin/openzeppelin-contracts@3.4.0
compiler:
  solc:
    remappings:
      - '@chainlink=smartcontractkit/chainlink-brownie-contracts@1.1.1'
      - '@openzeppelin=OpenZeppelin/openzeppelin-contracts@3.4.0'
networks:
  default: development
  mainnet-fork:
      eth_usd_price_feed: '0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419'
      keyhash: '0x79d3d8832d904592c0bf9818b621522c988bb8b0c05cdc3b15aea1b6e8db0c15'
      fee: 1000000000000000000
  goerli:
    vrf_coordinator: '0x2Ca8E0C643bDe4C2E08ab1fA0da3401AdAD7734D'
    eth_usd_price_feed: '0xD4a33860578De61DBAbDc8BFdb98FD742fA7028e'
    link_token: '0x326C977E6efc84E512bB9C30f76E30c160eD06FB'
    keyhash: '0x79d3d8832d904592c0bf9818b621522c988bb8b0c05cdc3b15aea1b6e8db0c15'
    fee: 1000000000000000000
    verify: True 
wallets:
  from_key: ${PRIVATE_KEY}

The test_lottery code;

#     0.0337789204065159
#     330000000000000000
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.020, "ether")
    assert Lottery.getEntranceFee() < Web3.toWei(0.050, "ether")