PatrickAlphaC / smartcontract-lottery

MIT License
77 stars 113 forks source link

[ERROR] Fail - Unable to verify while running integration test #8

Closed salvadorpablo closed 2 years ago

salvadorpablo commented 2 years ago

I'm running into this unable to verify error while testing test_can_pick_winner() and I can't quite see what's wrong. Here's the error msg:

============================================================================================= test session starts ============================================================================================= platform linux -- Python 3.8.10, pytest-6.2.5, py-1.10.0, pluggy-1.0.0 -- /usr/bin/python3 cachedir: .pytest_cache hypothesis profile 'brownie-verbose' -> verbosity=2, deadline=None, max_examples=50, stateful_step_count=10, report_multiple_bugs=False, database=DirectoryBasedExampleDatabase(PosixPath('/home/salvadorpablo/.brownie/hypothesis')) rootdir: /home/salvadorpablo/demos/smartcontract-lottery plugins: eth-brownie-1.16.4, forked-1.3.0, web3-5.23.1, hypothesis-6.21.6, xdist-1.34.0 collected 6 items / 4 deselected / 2 selected

tests/integration/test_lottery_integration.py::test_can_pick_winner RUNNING Waiting for https://api-rinkeby.etherscan.io/api to process contract... Verification submitted successfully. Waiting for result... Verification pending... Verification complete. Result: Fail - Unable to verify Deployed lottery! ^C

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! KeyboardInterrupt !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

I interrupted because I get an error after but I think it's probably a consequence of this one

Here is my code:

deploy_lottery.py

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

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("Deployed lottery!") return lottery

def start_lottery(): account = get_account() lottery = Lottery[-1] starting_tx = lottery.startLottery({"from": account}) starting_tx.wait(1) print("The lottery is started!")

def enter_lottery(): account = get_account() lottery = Lottery[-1] value = lottery.getEntranceFee() + 100000000 tx = lottery.enter({"from": account, "value": value}) tx.wait(1) print("You entered the lottery!")

def end_lottery(): account = get_account() lottery = Lottery[-1]

fund the contract

# then end the lottery
tx = fund_with_link(lottery.address)
tx.wait(1)
ending_transaction = lottery.endLottery({"from": account})
ending_transaction.wait(1)
time.sleep(60)
print(f"{lottery.recentWinner()} is the new winner!")

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

brownie-config.yaml

dependencies:

helpful_scripts.py

from brownie import ( accounts, network, config, MockV3Aggregator, Contract, VRFCoordinatorMock, LinkToken, )

FORKED_LOCAL_ENVIROMENTS = ["mainnet-fork", "mainnet-fork-dev"] LOCAL_BLOCKCHAIN_ENVIRONMENTS = ["development", "ganache-local"]

def get_account(index=None, id=None):

accounts[0]

# accounts.add("env")
# accounts.load("id")
if index:
    return accounts[index]
if id:
    return accounts.load(id)
if (
    network.show_active() in LOCAL_BLOCKCHAIN_ENVIRONMENTS
    or network.show_active() in FORKED_LOCAL_ENVIROMENTS
):
    return accounts[0]
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): """This function will grab the contract addresses from the brownie config if defined, otherwise, it will deploy a mock version of that contract and return that mock contract.

    Args:
        contract_name (string): This is the name thta is refered to in the
        brownie config and 'contract_to_mock' variable.

    Returns:
        brownie.network.contract.ProjectContract: The most recently deployed
        version of this contract. This could be either a mock or the 'real'
        contract on a live network.
"""
contract_type = contract_to_mock[contract_name]
if network.show_active() in LOCAL_BLOCKCHAIN_ENVIRONMENTS:
    if len(contract_type) <= 0:
        # MockV3Aggregator.length
        deploy_mocks()
    contract = contract_type[-1]  # MockV3Aggregator[-1]
else:
    contract_address = config["networks"][network.show_active()][contract_name]
    # address
    # ABI
    contract = Contract.from_abi(
        contract_type._name, contract_address, contract_type.abi
    )
return contract

DECIMALS = 8 INITIAL_VALUE = 200000000000

def deploy_mocks(decimals=DECIMALS, initial_value=INITIAL_VALUE): account = get_account() MockV3Aggregator.deploy(decimals, initial_value, {"from": account}) link_token = LinkToken.deploy({"from": account}) VRFCoordinatorMock.deploy(link_token.address, {"from": account}) print("Deployed!")

def fund_with_link( contract_address, account=None, link_token=None, amount=100000000000000000 ): # 0.1 LINK 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})

link_token_contract = interface.LinkTokenInterface(link_token.address)

# tx = link_token_contract.transfer(contract_address, amount, {"from": account})
tx.wait(30)
print("Fund contract!")
return tx

test_lottery_integration

from brownie import network import pytest from scripts.helpful_scripts import ( LOCAL_BLOCKCHAIN_ENVIRONMENTS, get_account, fund_with_link, ) from scripts.deploy_lottery import deploy_lottery import time

def test_can_pick_winner(): if network.show_active() 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": account, "value": lottery.getEntranceFee()}) fund_with_link(lottery) lottery.endLottery({"from": account}) time.sleep(60) assert lottery.recentWinner() == account assert lottery.balance() == 0

Any help would be much appreciated!

PatrickAlphaC commented 2 years ago

Thanks so much for making this issue! So your config has it defined that it’s going to try to verify your application when deploying to rinkeby, but the verification is having some issues right now (there is an issue in to fix).

So for running tests, you can either not deploy to rinkeby, or you can remove the publish_source line in your deploy script.

PatrickAlphaC commented 2 years ago

Closing for now, feel free to follow up

salvadorpablo commented 2 years ago

Thanks!