Good day everyone, I am working on a lottery smart contract. I am currently done with the remix VM tests and proceeded with the unit tests with JavaScript. The test.js file is shown below.
const assert = require('assert'); const ganache = require('ganache-cli'); const Web3 = require('web3'); const web3 = new Web3(ganache.provider()); const { abi, bytecode } = require('../compile') let lottery; let accounts; beforeEach(async() => { accounts = await web3.eth.getAccounts(); lottery = await new web3.eth.Contract(JSON.parse(abi)) .deploy({ data: evm.bytecode.object }) .send({ from: accounts[0], gas: 1000000}); }); describe('Lottery Contract', () => { it('deploys a contract', () => { assert.ok(lottery.options.address); }); });
The test file for now only checks if the contract deploys, pretty simple. However, I have not been able to proceed from here due to a particular error. Details on that will be shown below. I have checked for syntax and spelling errors but everything seems fine to me. Details on the compile.js and the error are provided below
The compile.js file:
const path = require("path"); const fs = require("fs"); const solc = require("solc"); const lotteryPath = path.resolve(__dirname, "contracts", "Lottery.sol"); const source = fs.readFileSync(lotteryPath, "utf8"); const input = { language: 'Solidity', sources: { 'Lottery.sol': { content: source } }, settings: { outputSelection: { '*': { '*': ['*'], } } } }; // console.log(JSON.parse(solc.compile(JSON.stringify(input))).contracts); module.exports = JSON.parse(solc.compile(JSON.stringify(input))).contracts[ 'Lottery.sol' ].Lottery;
The Error message:
I made use of imports in the lottery.sol file.
Advertisement
Answer
I am currently debugging the same error as well for a NFT I am publishing… I imported the local directory into my Remix workspace and it compiled just fine… this leads me to believe the issue is a mismatch between compiler versions… not sure. VS Code was irritating me, so I just published through Remix and called it a day.