运行以太坊智能合约测试时终端中的Mocha或异步库错误

时间:2020-05-11 08:59:37

标签: javascript mocha async.js

我在Mocha中运行一些以太坊智能合约测试时遇到问题。我试图使用异步部署合同。我在Mocha论坛上询问了此问题,并得知错误的性质与异步有关。

node.js版本为6.14.5

异步版本为3.2.0

我的Inbox.test.js:

--------------------------------------------------- --------->

const assert = require("assert");
const ganache = require("ganache-cli");
const Web3 = require("web3");
const web3 = new Web3(ganache.provider());
const {interface, bytecode} = require("../compile");

let accounts;
let inbox;

beforeEach(async ()=> {

//get a a list of all accounts

accounts = await  web3.eth.getAccounts();

// Use one of those accounts to deploy the contract

inbox = await new web3.eth.Contract(JSON.parse(interface))
.deploy({ data: bytecode, arguments: ["Hi there!"] })
.send({ from: accounts[0], gas: "1000000" });

});

describe ("Inboxxx", () => {

it("this deploys a contract", () => {

    console.log(inbox);
});
});

我的package.json:

--------------------------------------------------- ----------------------->

{
"name": "inbox",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha"
},
"author": "",
"license": "ISC",
"dependencies": {
"ganache-cli": "^6.0.3",
"async": "^3.2.0",
"async-await": "^0.1.40",
"mocha": "^4.0.1",
"save": "^2.4.0",
"solc": "^0.4.19",
"web3": "^1.0.0-beta.26"
}
}

我的compile.js

-------------------------------------->

const path = require("path");
const fs = require("fs");
const solc = require("solc")


const inboxPath = path.resolve(__dirname, "contracts", "Inbox.sol");
const source = fs.readFileSync(inboxPath, "utf8");


module.exports = solc.compile(source,1).contracts[":Inbox"];

--------------------------------------------------- -------> 运行后:npm运行测试//在我的cmd中,我得到输出

enter image description here

--------------------------------------------------- ------>这是我的debug.log文件

enter image description here

我试图清除我的npm缓存,取消安装/安装其他mocha,npm和solc版本,但是没有运气,错误仍然存​​在。

我正在乌迪米(Udemy)进行这门坚实的以太坊课程,但我没有从他们这方面得到任何答案,所以我真的会在这里提供一些帮助... Tnx

0 个答案:

没有答案