首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >运行npx hardhat test时出现未经授权的错误--network local或npx hardhat test --network kovan on Moralis forked testnet

运行npx hardhat test时出现未经授权的错误--network local或npx hardhat test --network kovan on Moralis forked testnet
EN

Stack Overflow用户
提问于 2021-11-27 16:28:48
回答 1查看 257关注 0票数 0

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

运行npx hardhat test时出现以下错误--network local or npx hardhat test --network kovan: HardhatError: HH110: Invalid JSON-RPC response received:{“错误”:“未授权”}

这是我的hardhat.config.js

代码语言:javascript
复制
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"
  }
};

代码语言:javascript
复制
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);
  })
})

EN

回答 1

Stack Overflow用户

发布于 2021-12-02 17:00:46

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70136668

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档