0

I wanted to test my code functionality with the Mocha Framework, but every time it responded me with an error, not an assertion. The specific error was:

Error:cannot find module "ganache-cli" require stack:...

This is my contract.test.js:

const assert = require("assert");
const ganache = require("ganache-cli");
const Web3 = require("web3");
const web3 = new Web3(provider());

const { interface, bytecode } = require("../compile");

let lottery;
let accounts;

beforeEach(async () => {
  accounts = await web3.eth.getAccounts();

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

describe("Lottery contract", () => {
  it("deploys a contrcat", () => {
    assert.ok(lottery.options.address);
  })
})
0

You are trying to import from ganache-cli, so you have to install it as a dependency. If you're using npm, you can install it like:

npm install --save-dev ganache-cli

or with yarn:

yarn add -D ganache-cli
3
  • should i take my terminal destination to the intended folder or not ? Nov 10 '20 at 23:41
  • thank u so much for ur respond by the way Nov 10 '20 at 23:42
  • You should run this in the folder with your package.json file.
    – Morten
    Nov 11 '20 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.