Invalid asm.js: Invalid member of stdlib
(node:7894) V8: /var/www/html/testeth/node_modules/solc/soljson.js:3 Invalid asm.js: Invalid member of stdlib
i am making the test deploy on ganache-cli simple contract but it is showing that warning. Please help to resolve that problem.
Below the code of the "index.sol"
pragma solidity ^0.4.17;
contract testalk{
string public message;
function testalk(string initialMsg) public {
message = initialMsg;
}
function setMessage(string nwMsg) public {
message = nwMsg;
}
}
and i am testing it using "mocha" and ganache-cli provider as code below :-
const assert = require('assert');
const ganache = require('ganache-cli');
const Web3 = require('web3');
const web3 = new Web3(ganache.provider());
const { interface, bytecode} = require('../compile');
require('events').EventEmitter.defaultMaxListeners = 15;
let accounts;
let testeth;
beforeEach( async ()=>{
accounts = await web3.eth.getAccounts();
testeth = await new web3.eth.Contract(JSON.parse(interface))
.deploy({data: bytecode, arguments: ['Hi Alok!']})
.send({gas: '1000000',from: accounts['0']});
});
describe("testalk",() => {
it('deploy a contract', () =>{
assert.ok(testeth.options.address);
});
it('get the message', async () => {
const message = await testeth.methods.message().call();
assert.equal('Hi Alok!', message);
//console.log(message);
})
it('get the message', async () => {
await testeth.methods.setMessage("Bye Alok!").send({from: accounts[0], gas: '1000000'});
const message = await testeth.methods.message().call();
console.log(message);
});
});
I am using Ubuntu and nodejs.
I recommend you to select a newer version of the solc compiler (e.g. check Remix to see which version works with your code). Check that the version in the pragma
sentence of your Solidity code is the same as the solc version you have installed with node. Check the sample usages in the solc releases and copy the JS code. I used 0.7.4 https://libraries.io/npm/solc/0.7.4
After that, you need to adapt the compile script to return the ABI and bytecode to your tests. The names must match exactly. Here I'm returning the values in JSON format so I don't have to use JSON.parse(interface)
in my test file. Note that the bytecode is only the HEX value, therefore I'm returning the contract.evm.bytecode.object
. Change Lottery by the name of your contract (if you have multiple contracts you want to check the docs or try a for loop).
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')
var input = {
language: 'Solidity',
sources: {
'test.sol': {
content: source
}
},
settings: {
outputSelection: {
'*': {
'*': ['*']
}
}
}
};
var output = JSON.parse(solc.compile(JSON.stringify(input)));
var contract = output.contracts['test.sol'].Lottery;
var bytecode = contract.evm.bytecode.object;
var interface = contract.abi;
module.exports = {interface, bytecode};
My test file didn't change much, but here it is:
const assert = require('assert');
const ganache = require('ganache-cli');
const Web3 = require('web3');
const web3 = new Web3(ganache.provider());
const { interface, bytecode } = require('../compile');
let lottery;
let accounts;
beforeEach(async () => {
accounts = await web3.eth.getAccounts();
lottery = await new web3.eth.Contract(interface)
.deploy({ data: bytecode })
.send({ from: accounts[0], gas: '6000000' });
});
describe('Lottery Contract', () => {
it('deploys a contract', () => {
assert.ok(lottery.options.address);
});
});