Solidity
如何在測試網上執行安全帽測試?
我想在 testnet 上執行我的測試,主要是因為我需要測試 chainlink VRF。我怎樣才能做到這一點?
這是我的
hardhat.config.js
:require("@nomiclabs/hardhat-ethers"); require("@nomiclabs/hardhat-waffle"); require('dotenv').config() const INFURA_URL = "https://rinkeby.infura.io/v3/" + process.env.INFURA_API_KEY; const owner = process.env.PK; const alice = process.env.ALICE; const bob = process.env.BOB; module.exports = { networks: { hardhat:{}, rinkeby: { url: INFURA_URL, accounts: [`0x${owner}`, `0x${alice}`, `0x${bob}`] } }, solidity: { version: "0.8.4", settings: { optimizer: { enabled: true, runs: 200 } } }, };
執行後出現此錯誤
npx hardhat test --network rinkeby
:"before each" hook for "Should set the right owner": Error: Timeout of 20000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
這是錯誤所在的程式碼部分:
nft.test.js
beforeEach(async () => { NFT = await ethers.getContractFactory("NFT"); nft = await NFT.deploy( initURI, secretURI, linkToken, vrfCoordinator, keyHash, linkFee ); await nft.deployed(); [owner, alice, bob, _] = await ethers.getSigners(); });
確保您的帳戶有餘額。您可以通過添加以毫秒為單位的超時屬性來配置超時取決於每個網路(https://hardhat.org/config/#json-rpc-based-networks)
例子:
rinkeby: { url: INFURA_URL, accounts: [`0x${owner}`, `0x${alice}`, `0x${bob}`], timeout: 60000 }