full-blockchain-solidity-course-py icon indicating copy to clipboard operation
full-blockchain-solidity-course-py copied to clipboard

Lesson 6 & 7 : Test using mainnet-fork giving error.

Open shashankvivek opened this issue 2 years ago • 5 comments

when I run brownie test --network mainnet-fork-dev . I am getting below error:

image

What is the reason? I am not able to understand the exact issue based on this message. The test works fine if I run brownie test i.e. development env

image

shashankvivek avatar Mar 20 '22 13:03 shashankvivek

@cromewar : Can you please help me through this :( What am I missing?

shashankvivek avatar Mar 20 '22 20:03 shashankvivek

Hello @shashankvivek I'll need more info on this, seems your getEntraceFee is reverting the transaction. So, please share the following information:

  1. What is the output at deploying on development?.
  2. The brownie-config.yaml.
  3. The code of your test script.

cromewar avatar Mar 21 '22 00:03 cromewar

Hi @cromewar ,

My bad about one info brownie run is not working as I never handled eth_use_price_feed. For Lesson 7, I am at the beginning where there is no deploy.py script yet. I have created the contract and then created the mainnet-fork with API key and then run the test. Hence I see:

image

Here is

brownie-config.yaml

dependencies:
  - smartcontractkit/[email protected]
compiler:
  solc:
    remappings:
      - '@chainlink=smartcontractkit/[email protected]'
networks:
  mainnet-fork:
    eth_use_price_feed: '0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419'

test_lottery.py

# 1 USD => 0.017 ETH
# 170000000000000000
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_use_price_feed"],
        {"from": account}
    )
    print(lottery.getEntranceFee())
    assert lottery.getEntranceFee() > 160000000000000000
    assert lottery.getEntranceFee() > Web3.toWei(0.016,"ether")
    assert lottery.getEntranceFee() < Web3.toWei(0.022,"ether")

shashankvivek avatar Mar 24 '22 11:03 shashankvivek

Well the error shows the problem is with:

`eth_use_price_feed: '0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419' So,

  1. on your contract, is the constructor well declared to receive that entrance fee?
  2. The key error also could be due to a bad brownie-config.yaml look for any typo or indentation error on that file.
  3. Also just a good practice, the name should be eth_usd_price_feed.

I hope any of this info might help.

cromewar avatar Mar 24 '22 13:03 cromewar

Well the error shows the problem is with:

`eth_use_price_feed: '0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419' So,

  1. on your contract, is the constructor well declared to receive that entrance fee?
  2. The key error also could be due to a bad brownie-config.yaml look for any typo or indentation error on that file.
  3. Also just a good practice, the name should be eth_usd_price_feed.

I hope any of this info might help.

@cromewar Well, the error happened because I have not handled development network in the my yaml file and hence getting error while accessing it via config["networks"][network.show_active()]["eth_use_price_feed"] . I'll fix the typo to eth_usd_price_feed

shashankvivek avatar Mar 24 '22 15:03 shashankvivek