const assert = require('assert');
const ganache = require('ganache-cli');
const Web3 = require('web3');

const provider = ganache.provider();
const web3 = new Web3(provider);

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

let accounts;
let inbox;

beforeEach(async () => {
  // Get 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('inbox', () => {
  it('deploys a contract', () => {
  it('has a default message', async () => {
    const message = await inbox.methods.message().call();
    assert.equal(message, 'Hi there!');


  • shouldn't beforeEach be inside the describe? – mirg Jun 5 '18 at 9:24
  • No, if we do so we have to provide it inside all the describe (Local,global concept) – 0xSHA1001 Jun 5 '18 at 11:09
  • seems like an issue with your compile file. require('../compile') is apparently returning null or undefined. – AnAllergyToAnalogy Jun 5 '18 at 11:37

Error lies with the require('../compile')for sure as it must be returning a null.

Try referring to the code below for compilation of the solidity code. Check if your compile.js file is working in the similar manner or not.

// Compile the source code
const input = fs.readFileSync('Coin.sol');

const output = solc.compile(input.toString(), 1);

const bytecode = output.contracts[':Coin'].bytecode;

const abi = JSON.parse(output.contracts[':Coin'].interface);

Make sure you got const abi = JSON.parse(output.contracts[':Coin'].bytecode); the 'C' of 'Coin.sol' in capitals in 'compile.js' cause that's just how it's stored in solidity

  • How did you make it work? @shashvat – urjit on rails Jul 13 '18 at 14:38
  • @urjitonrails simply check your compile.js file. Make sure you have got the first letter in caps as shown in the code above. – Apoorv Jain Jul 18 '18 at 22:11

The problem doesn't lie with the code provided. There's something wrong with your "compile" file.

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

is the issue,


is returning undefined or null.

  • Yes, So how should I fix it ? I Bytecode is working. I am not sure about the inferface. Can you please help me out ? – 0xSHA1001 Jun 5 '18 at 13:55
  • Maybe post another question with your compile file if you can't figure it out. The bytecode isn't working either. The whole require('../compile') evaluates to undefined or null. That's all that I can tell from what you've posted. – AnAllergyToAnalogy Jun 5 '18 at 14:30
  • Also note, the error you've posted has nothing to do with Ethereum, it's just a Javascript error. – AnAllergyToAnalogy Jun 5 '18 at 14:31

You need to make sure that you are exporting everything correctly from your compile.js file to your test file. I have spelling error when I was exporting contract, my code bit here module.exports = solc.compile(source, 1).contracts[':Registration']; the registration was :registration instead of :Registration and hence the {interface, bytecode } were not being exported from thecompile.js`.

I hope this helps. It was a typo, js error.


I also got the same error but make sure spelling of your contract name and the name you are using here: module.exports = solc.compile(source, 1).contracts[':Lottery']; and contract Lottery{ This must be identical.


For googlers:

The issue is with this is likely the versioning of the solc compiler. Bumping the version's dependency to one that is more recent may solve your issue.

Try the following:

  1. rm -rf node_modules // remove node_modules
  2. rm -rf package-lock.json // remove package-lock.json
  3. Change the .sol file's import statement to: pragma solidity ^0.4.25
  4. Change the dependency in package.json to "solc": "^0.4.25"
  5. npm install // install new dependencies

Then you can run your tests

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.