Я настраиваю новую локальную тестовую сеть (Ganache), пишу UNI TEST в MOCHA и web3.Мы настроили библиотеку для подключения ABI к тестовой сети с именем Web3.Где мне нужно установить кодировку / кодировки? »
[HELLO.TEST.JS]
//import web3 from 'web3';
const assert= require('assert');
const ganache = require('ganache-cli');
const Web3 = require('web3');
console.log(Web3);return;
const provider = ganache.provider();
console.log(provider);return;
const web3 = new web3(provider);
console.log(web3);return;
const { interface, bytecode } = require('../compile');
let accounts;
let hello;
const INITIAL_THINGS = 'Hi there!';
beforeEach(async () => {
// get a list of all accounts
accounts = await web3.eth.getAccounts();
console.log(JSON.parse(interface));return;
hello = await new web3.eth.Contract(JSON.parse(interface))
.deploy({ data: bytecode, arguments: [INITIAL_THINGS] })
.send({ from: accounts[0], gas: '1000000' })
hello.setProvider(provider);
})
describe('Hello', () => {
it('deploys a contract', () => {
assert.ok(hello.options.address);
});
it ('has a default message', async () => {
const message = await hello.methods.getMessage().call();
assert.equal(message, INITIAL_THINGS);
});
it('can change the message' , async()=>{
await hello.methods.setMessage('bye').send({from: accounts[0]});
const message = await hello.methods.getMessage().call();
assert.equal(message, 'bye');
});
})
и файл PACKAGE.JSON имеет код:
[PACKAGE.JSON]
{
"name": "newpackage",
"version": "1.0.0",
"description": "",
"main": "compile.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "mocha"
},
"author": "",
"license": "ISC",
"dependencies": {
"ganache-cli": "^6.4.4",
"mocha": "^6.1.4",
"solc": "^0.4.25",
"web3": "^1.0.0-beta.26"
}
}
И при запуске он выдает ошибку сейчас, который работал нормально раньше, ошибка показана ниже:
C:\Users\Windon\Desktop\LV\1\node_modules\web3\src\index.js:76
core.addProviders(Web3);
^
TypeError: core.addProviders is not a function
at Object.<anonymous> (C:\Users\Windon\Desktop\LV\1\node_modules\web3\src\index.js:76:6)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:690:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (C:\Users\Windon\Desktop\LV\1\test\hello.test.js:5:14)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:690:17)
at require (internal/modules/cjs/helpers.js:25:18)
at C:\Users\Windon\Desktop\LV\1\node_modules\mocha\lib\mocha.js:330:36
at Array.forEach (<anonymous>)
at Mocha.loadFiles (C:\Users\Windon\Desktop\LV\1\node_modules\mocha\lib\mocha.js:327:14)
at Mocha.run (C:\Users\Windon\Desktop\LV\1\node_modules\mocha\lib\mocha.js:804:10)
at Object.exports.singleRun (C:\Users\Windon\Desktop\LV\1\node_modules\mocha\lib\cli\run-helpers.js:207:16)
at exports.runMocha (C:\Users\Windon\Desktop\LV\1\node_modules\mocha\lib\cli\run-helpers.js:300:13)
at Object.exports.handler.argv [as handler] (C:\Users\Windon\Desktop\LV\1\node_modules\mocha\lib\cli\run.js:296:3)
at Object.runCommand (C:\Users\Windon\Desktop\LV\1\node_modules\mocha\node_modules\yargs\lib\command.js:242:26)
at Object.parseArgs [as _parseArgs] (C:\Users\Windon\Desktop\LV\1\node_modules\mocha\node_modules\yargs\yargs.js:1104:24)
at Object.parse (C:\Users\Windon\Desktop\LV\1\node_modules\mocha\node_modules\yargs\yargs.js:566:25)
at Object.exports.main (C:\Users\Windon\Desktop\LV\1\node_modules\mocha\lib\cli\cli.js:63:6)
at Object.<anonymous> (C:\Users\Windon\Desktop\LV\1\node_modules\mocha\bin\_mocha:10:23)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! newpackage@1.0.0 test: `mocha`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the newpackage@1.0.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Windon\AppData\Roaming\npm-cache\_logs\2019-07-05T18_41_29_582Z-debug.log