I'm trying to run a test on mocha following the steps described in some Udemy course about Ethereum blockchain.
This is the package.json file that I currently have:
{
"name": "inbox",
"version": "1.0.0",
"description": "",
"main": "index",
"typings": "index",
"scripts": {
"test": "mocha"
},
"author": "",
"license": "ISC",
"dependencies": {
"ganache-cli": "^6.3.0",
"mocha": "^5.2.0",
"solc": "^0.4.17",
"web3": "^1.0.0-beta.37"
}
}
When I run: npm run test
, I'm having this issue:
Inbox contract
Error: No callback provided to provider's send function. As of web3 1.0, provider.send is no longer synchronous and must be passed a callback as its final argument.
at b.send (C:\Users\bsimperc\Desktop\SCOMP\blockchain-projects\Inbox\node_modules\ganache-cli\build\ganache-core.node.cli.js:25:90931)
at GetAccountsMethod._callee$ (C:\Users\bsimperc\Desktop\SCOMP\blockchain-projects\Inbox\node_modules\web3-core-method\dist\web3-core-method.cjs.js:454:55)
at tryCatch (C:\Users\bsimperc\Desktop\SCOMP\blockchain-projects\Inbox\node_modules\regenerator-runtime\runtime.js:62:40)
at Generator.invoke [as _invoke] (C:\Users\bsimperc\Desktop\SCOMP\blockchain-projects\Inbox\node_modules\regenerator-runtime\runtime.js:288:22)
at Generator.prototype.(anonymous function) [as next] (C:\Users\bsimperc\Desktop\SCOMP\blockchain-projects\Inbox\node_modules\regenerator-runtime\runtime.js:114:21)
at asyncGeneratorStep (C:\Users\bsimperc\Desktop\SCOMP\blockchain-projects\Inbox\node_modules\@babel\runtime\helpers\asyncToGenerator.js:3:24)
at _next (C:\Users\bsimperc\Desktop\SCOMP\blockchain-projects\Inbox\node_modules\@babel\runtime\helpers\asyncToGenerator.js:25:9)
at C:\Users\bsimperc\Desktop\SCOMP\blockchain-projects\Inbox\node_modules\@babel\runtime\helpers\asyncToGenerator.js:32:7
at new Promise (<anonymous>)
at GetAccountsMethod.<anonymous> (C:\Users\bsimperc\Desktop\SCOMP\blockchain-projects\Inbox\node_modules\@babel\runtime\helpers\asyncToGenerator.js:21:12)
at GetAccountsMethod.execute (C:\Users\bsimperc\Desktop\SCOMP\blockchain-projects\Inbox\node_modules\web3-core-method\dist\web3-core-method.cjs.js:477:25)
at Proxy.anonymousFunction (C:\Users\bsimperc\Desktop\SCOMP\blockchain-projects\Inbox\node_modules\web3-core-method\dist\web3-core-method.cjs.js:228:25)
at Context.beforeEach (C:\Users\bsimperc\Desktop\SCOMP\blockchain-projects\Inbox\test\Inbox.test.js:9:14)
at callFn (C:\Users\bsimperc\Desktop\SCOMP\blockchain-projects\Inbox\node_modules\mocha\lib\runnable.js:372:21)
at Hook.Runnable.run (C:\Users\bsimperc\Desktop\SCOMP\blockchain-projects\Inbox\node_modules\mocha\lib\runnable.js:364:7)
at next (C:\Users\bsimperc\Desktop\SCOMP\blockchain-projects\Inbox\node_modules\mocha\lib\runner.js:317:10)
at Immediate.<anonymous> (C:\Users\bsimperc\Desktop\SCOMP\blockchain-projects\Inbox\node_modules\mocha\lib\runner.js:347:5)
at runCallback (timers.js:705:18)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5)
√ deploys a contract
1 passing (27ms)
I was first using web3@1.0.0-beta.26, since that's the version used in the course. However I was getting the error "addProviders is not a function", which was solved by updating to version beta.37
Finally this is my portion of code, as mentioned in the course this library implements promises:
const assert = require("assert");
const ganache = require("ganache-cli");
const Web3 = require("web3");
const web3 = new Web3(ganache.provider()); //Crea una instancia de web3 y le indica que debe conectarse a la red local de pruebba de ganache
beforeEach(() => {
web3.eth.getAccounts()
.then(accounts => {
console.log(accounts);
})
.catch(err => {
console.log(err);
});
// Obtenemos las cuentas que genera ganache
//Usamos una de las cuentas para desplegar el contrato
});
describe("Inbox contract", () => {
it("deploys a contract", () => {
});
})
None of the suggestions or advice from here worked:
I was facing the same problem, I solved it by setting my mocha, ganache-cli, solc and web3 to the following versions
{
"name": "inbox",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha"
},
"author": "",
"license": "ISC",
"dependencies": {
"ganache-cli": "^6.0.3",
"mocha": "^4.0.1",
"solc": "^0.4.19",
"web3": "^1.0.0-beta.37"
}
}