Testing

在主網分叉上執行測試時恢復“evm_increaseTime”

  • July 31, 2021

我正在嘗試使用 hardhat-deploy 範例模板在主網分叉上執行測試,特別是for-test分支範例。

https://github.com/wighawag/template-ethereum-contracts/tree/examples/fork-test/

提供.env變數後。我跑了yarn fork:test mainnet

但是我一直在測試中遇到這個特定的錯誤aToken_Dai。我認為 ABI 可能已經過時,並嘗試從主網合約更新它,但仍然無法正常工作。執行時測試不斷恢復evm_increaseTime。我錯過了什麼需要通過測試的東西嗎?

aave.test.ts

  ...
   await network.provider.request({
     method: 'evm_increaseTime',
     params: [3600 * 24 * 365],
   });
  ...
$ node ./_scripts.js fork:test mainnet


 GreetingsRegistry
Nothing to compile
No need to generate any newer typings.
   ✔ setMessage works (7855ms)

 SimpleERC20
   ✔ transfer fails
   ✔ transfer succeed

 aToken_Dai
   1) aToken_Dai works


 3 passing (43s)
 1 failing

 1) aToken_Dai
      aToken_Dai works:
    Error: VM Exception while processing transaction: revert SafeERC20: low-level call failed
   at <UnrecognizedContract>.<unknown> (0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9)
   at <UnrecognizedContract>.<unknown> (0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9)
   at processTicksAndRejections (internal/process/task_queues.js:95:5)
   at HardhatNode._mineBlockWithPendingTxs (node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:1154:23)
   at HardhatNode.mineBlock (node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:377:16)
   at EthModule._sendTransactionAndReturnHash (node_modules/hardhat/src/internal/hardhat-network/provider/modules/eth.ts:1377:18)
   at HardhatNetworkProvider.request (node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:101:18)
   at EthersProviderWrapper.send (node_modules/@nomiclabs/hardhat-ethers/src/internal/ethers-provider-wrapper.ts:13:20)

.env.example項目提供的似乎缺少一些正在使用的環境變數hardhat.config.ts

在您的.env中,確保設置HARDHAT_FORK為主網。此外,請確保設置HARDHAT_FORK_NUMBER為所有依賴合約都已存在於主網上的區塊編號。

引用自:https://ethereum.stackexchange.com/questions/106381