Solidity

如何在安全帽測試中部署 WETH 合約

  • November 21, 2021

我有一個 WETH 合約,我想在我的安全帽測試網路上部署它。WETH 合約的來源可以在這裡找到。

當我執行以下安全帽測試時:

const { expect } = require("chai");
const { ethers } = require("hardhat");

describe("testing", function () {
 it("Should work", async function () {
   const Weth = ethers.getContractFactory("WETH")
   const weth = await Weth.deploy()
   await weth.deployed()

   expect(true).to.equal(true);
 });
});

我收到以下錯誤:

 testing
   1) Should work


 0 passing (725ms)
 1 failing

 1) testing
      Should work:
    TypeError: Weth.deploy is not a function
     at Context.<anonymous> (test/test.js:22:29)
     at processImmediate (internal/timers.js:439:21)

為什麼說我不能部署合約?是solidity版本這​​麼老的Hardhat不能部署了嗎?

  1. 您需要等待 getContractFactory
  2. .deployed() 是,iirc,僅在 web3js 中(您可以在此處刪除它)
  3. 仔細檢查您的契約名稱(« WETH »,區分大小寫),如果它沒有解決它
const { expect } = require("chai");
const { ethers } = require("hardhat");

describe("testing", function () {
 it("Should work", async function () {
   const Weth = await ethers.getContractFactory("WETH")
   const weth = await Weth.deploy()

   expect(await weth.symbol()).to.equal(“WETH”);
 });
});

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