PatrickAlphaC / smartcontract-lottery

MIT License
79 stars 113 forks source link

can't end the lottery #62

Closed andreariba closed 2 years ago

andreariba commented 2 years ago

Hi,

I'm following the course Solidity, Blockchain, and Smart Contract Course and I cannot pass the test_can_end_lottery test in the development network, I didn't test the other networks.

It looks like I can successfully fund with LINK the lottery contract but the transaction endLottery reverts. I checked all the amounts and fees twice to be sure they have 17 zeros. I pasted below the error, the config, and the function end_lottery().

Error:

LINK funded to contract
  LinkToken.transfer confirmed   Block: 7   Gas used: 51398 (0.43%)

Transaction sent: 0xe97361a7db515a30e3feac79b1e14d6e16abd3132949b17a82fbb83cd87bc619
  Gas price: 0.0 gwei   Gas limit: 12000000   Nonce: 7
  Lottery.endLottery confirmed (reverted)   Block: 8   Gas used: 11813268 (98.44%)

  File "brownie/_cli/run.py", line 51, in main
    return_value, frame = run(
  File "brownie/project/scripts.py", line 103, in run
    return_value = f_locals[method_name](*args, **kwargs)
  File "./scripts/deploy_lottery.py", line 90, in main
    end_lottery()
  File "./scripts/deploy_lottery.py", line 71, in end_lottery
    tx = lottery.endLottery({"from": account})
  File "brownie/network/contract.py", line 1710, in __call__
    return self.transact(*args)
  File "brownie/network/contract.py", line 1583, in transact
    return tx["from"].transfer(
  File "brownie/network/account.py", line 682, in transfer
    receipt._raise_if_reverted(exc)
  File "brownie/network/transaction.py", line 446, in _raise_if_reverted
    raise exc._with_attr(
VirtualMachineError: revert

the brownie-config file includes:

networks:
  default: 'development'
  development:
    keyhash: '0x2ed0feb3e7fd2022120aa84fab1945545a9f2ffc9076fd6156fa96eaff4c1311'
    fee: 100000000000000000
  rinkeby:
    vrf_coordinator: '0xb3dCcb4Cf7a26f6cf6B120Cf5A73875B7BBc655B'
    eth_usd_price_feed: '0x8A753747A1Fa494EC906cE90E9f37563A8AF630e'
    link_token: '0x01BE23585060835E02B77ef475b0Cc51aA1e0709'
    keyhash: '0x2ed0feb3e7fd2022120aa84fab1945545a9f2ffc9076fd6156fa96eaff4c1311'
    fee: 100000000000000000
    verify: True    
  mainnet-fork:
    eth_usd_price_feed: '0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419'
    keyhash: '0x2ed0feb3e7fd2022120aa84fab1945545a9f2ffc9076fd6156fa96eaff4c1311'
    fee: 100000000000000000

and the function end_lottery()

def end_lottery():
    account = get_account()

    lottery = Lottery[-1]

    # to request randomness i need to fund LINK token to the contract/VRFCoordinator so
    # 1. I need LINK token in the account
    tx = fund_with_link(lottery)
    tx.wait(1)

    # 2. end the lottery
    tx = lottery.endLottery({"from": account})
    tx.wait(1)

    # wait for the chainlink contract to send the random winner
    time.sleep(60)

    print(f"{lottery.recentWinner()} is the new winner")

    return

I am getting very confused, any idea why this may be happening? Thanks a lot

PatrickAlphaC commented 2 years ago

Can you ask on the main repo?

Thanks!

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