iamdefinitelyahuman / brownie-token-tester

Helper objects for generating ERC20s while testing a Brownie project.
MIT License
37 stars 13 forks source link

BrownieEnvironmentError: Functionality not available in local environment #23

Open Decentralisedme opened 2 years ago

Decentralisedme commented 2 years ago

Environment information

What was wrong?

Functionality not available: I tired installing brownie-token-tester using pipx, pip and setuptools. I am in anaconda environment and I can see it has been installed.

CurveFiProject is the active project.

Launching 'ganache-cli --accounts 10 --fork https://eth-mainnet.alchemyapi.io/v2/c40U6PVX1zEFdcRfYVjXMC2X1RBpNKpx --mnemonic brownie --port 8545 --hardfork istanbul'...

Running 'scripts/stake.py::main'... 0x66aB6D9362d4F35596279692F0251Db635165871 0x33A4622B82D4c04a53e170c638B944ce27cffce3 File "brownie/_cli/run.py", line 55, in main _include_frame=True, File "brownie/project/scripts.py", line 110, in run return_value = f_locals[method_name](*args, **kwargs) File "./scripts/stake.py", line 19, in main dai = MintableForkToken(dai_addr) File "brownie/network/contract.py", line 884, in init build, sources = _get_deployment(alias=address_or_alias) File "brownie/network/state.py", line 603, in _get_deployment raise BrownieEnvironmentError("Functionality not available in local environment") from None BrownieEnvironmentError: Functionality not available in local environment



### How can it be fixed?

Fill this in if you know how the bug could be fixed.
Ed-Marcavage commented 2 years ago

I added ".from_explorer(address)" to MintableForkToken and Contract objects, this solved the issue. Please see below:

    dai = MintableForkToken.from_explorer(dai_addr) #See here
    dai._mint_for_testing(accounts[0], amount)

    registry = Contract.from_explorer(registry_addr) #See here
    pool_addr = registry.find_pool_for_coins(dai_addr, usdc_addr)
    pool = Contract.from_explorer(pool_addr)

    dai.approve(pool_addr, amount, {"from": accounts[0]})
    pool.add_liquidity([amount, 0, 0], 0, {"from": accounts[0]})

    gauges = registry.get_gauges(pool_addr)
    gauge_addr = gauges[0][0]
    gauge_contract = interface.LiquidityGauge(gauge_addr)

    lp_token = MintableForkToken.from_explorer(gauge_contract.lp_token())
    lp_token.approve(gauge_addr, amount, {"from": accounts[0]})
    gauge_contract.deposit(lp_token.balanceOf(accounts[0]), {"from": accounts[0]})

You need to add your Etherscan API key to your given network:

brownie networks modify mainnet-fork explorer=https://api.etherscan.io/api?apikey=_____________________
Verde888 commented 2 years ago

Thanks a lot! Basically, you need to fetch the source contract from etherscan, which makes sense to me: according to documentation, MintableForkToken class inherits from and may be used interchangeably with the Contract class (it exposes one additional method, _mint_for_testing)