pythonethereumbrownie

brownie-token-tester: BrownieEnvironmentError: Functionality not available in local environment


My code:

from brownie_tokens import MintableForkToken
...
dai = MintableForkToken(dai_addr) 

In the terminal i run: brownie run scripts/stake.py --network mainnet-fork-dev

The output is:

Brownie v1.19.0 - Python development framework for Ethereum

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'...
Account 0: 0x66aB6D9362d4F35596279692F0251Db635165871
Account 1: 0x33A4622B82D4c04a53e170c638B944ce27cffce3
Dai address: 0x6B175474E89094C44Da98b954EedeAC495271d0F
  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 21, 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

My environment: brownie Version: v1.19.0 brownie-token-tester Version: 0.3.2 ganache-cli Version: v6.12.2 Python Version: 3.8.13

I am in a conda environment, I installed brownie-token-tester using pip.

Is there any way to avoid the error and use MintableForkToken()? Thank you....


Solution

  • 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=_____________________