使用甘那许的布朗尼本地测试失败

brownie local testing with ganache fails

按照训练营第 2 天视频中关于使用 brownie 测试 solidity 合约的步骤,我在本地测试 chainlink-mix 脚本时偶然发现了一个错误。

以下是引入错误的步骤:

  1. 执行布朗尼编译
  2. 在单独的终端中执行 genache-cli
  3. 执行布朗尼 运行 scripts/price_feed_scripts/01_deploy_price_consumer_v3.py
  4. 布朗尼 运行 scripts/price_feed_scripts/02_read_price_feed.py

ganache 被选为默认网络,服务器正在侦听 ip/port 127.0.0.1:8545。

brownie run scripts/price_feed_scripts/02_read_price_feed.py
Brownie v1.18.1 - Python development framework for Ethereum

ChainlinkMixProject is the active project.
/usr/local/lib/python3.9/site-packages/brownie/network/main.py:44: BrownieEnvironmentWarning: Development network has a block height of 14
  warnings.warn(
Attached to local RPC client listening at '127.0.0.1:8545'...

Running 'scripts/price_feed_scripts/02_read_price_feed.py::main'...
<brownie.network.contract.ContractContainer object at 0x10e410dc0>
  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/price_feed_scripts/02_read_price_feed.py", line 7, in main
    price_feed_contract = PriceFeedConsumer[-1]
  File "brownie/network/contract.py", line 175, in __getitem__
    return self._contracts[i]
IndexError: list index out of range

ganache 被设置为 brownie 中的默认网络-config.yaml

默认情况下,Brownie 不会将已部署合约的位置保存到本地 运行 链中,因为它们经常被删除并且会占用大量 space,所以你必须告诉布朗尼记住部署到甘纳许的东西。

在你的brownie-config.yaml中添加

dev_deployment_artifacts: true

然后重新运行脚本