0

我正在尝试学习如何使用 Moralis 配置安全帽,我编写了一个智能合约,现在我想测试它。我成功地分叉了一个 Moralis Kovan 网络和一个本地网络,我让它在我的计算机上运行。现在我想在 Moralis 的分叉 kovan 或本地网络上运行一些测试,但它们似乎都不起作用。

运行 npx hardhat test --network local 或 npx hardhat test --network kovan 时出现以下错误:HardhatError: HH110: Invalid JSON-RPC response received: {"error":"unauthorized"}

这是我的 hardhat.config.js

require("@nomiclabs/hardhat-waffle");
require("@nomiclabs/hardhat-etherscan");

const ethers = require('ethers');

task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
  const accounts = await hre.ethers.getSigners();

  for (const account of accounts) {
    console.log(account.address);
  }
});

// You need to export an object to set up your config
// Go to https://hardhat.org/config/ to learn more

/**
 * @type import('hardhat/config').HardhatUserConfig
 */
module.exports = {
  solidity: "0.8.4",
  networks: {
    kovan: {
      url: "https://vqvzzpqhdvnc.usemoralis.com:2053/server",
      accounts: ["03c1bd1681bf0baf5f32c0e182a23d676d8e645df90ae97613f66b7a6d97a8a3"]
    },
    local: {
      url: "https://7oqyifz8onne.usemoralis.com:2053/server",
      accounts: ["03c1bd1681bf0baf5f32c0e182a23d676d8e645df90ae97613f66b7a6d97a8a3"]
    }
  },
  etherscan: {
    apiKey: "9E45864SC7JZPH4F9U3MX9QXHE9EGXM2ZN"
  }
};

const { expect, assert } = require("chai");
const { ethers } = require("hardhat");
const hre = require('hardhat');
const Moralis = require('moralis/node');

const NODE_URL = "https://speedy-nodes-nyc.moralis.io/6ee15640b2e5107f0e110d0e/eth/kovan";
const provider = new ethers.providers.JsonRpcProvider(NODE_URL);

const signer = provider.getSigner();

const serverUrl = "https://vqvzzpqhdvnc.usemoralis.com:2053/server";
const appId = "WApLAvxmeBmgniXlx50T6SvKMk4FomQHhvXKHQZj";
Moralis.start({ serverUrl, appId });

describe("Greeter", function () {
  it("Should return the new greeting once it's changed", async function () {
    const Greeter = await ethers.getContractFactory("Greeter");
    const greeter = await Greeter.deploy("Hello, world!");
    await greeter.deployed();

    expect(await greeter.greet()).to.equal("Hello, world!");

    const setGreetingTx = await greeter.setGreeting("Hola, mundo!");

    // wait until the transaction is mined
    await setGreetingTx.wait();

    expect(await greeter.greet()).to.equal("Hola, mundo!");
  });
});

describe("UniSwap3", () => {
  let uniSwap3;

  beforeEach(async () => {
    const contractName = "UniSwap3";
    await hre.run("compile");
    const smartContract = await ethers.getContractFactory(contractName);
    uniSwap3 = await smartContract.deploy();
    await uniSwap3.deployed();
    console.log(`${contractName} deployed to: ${uniSwap3.address}`);
  })

  it("should return version 1", async () => {
    const version = await uniSwap3.version();
    assert.equal(version, 1);
  });

  it("should return zero DAI balance", async () => {
    const daiBalance = uniSwap3.getDaiBalance();
    assert.equal(daiBalance, 0);
  })
})

4

1 回答 1

1

尝试在 hardhat.config.js 中使用Speedy Nodes

于 2021-12-02T17:00:46.280 回答