1

My smart contract:

// SPDX-License-Identifier: MIT 
pragma solidity 0.8.19;

contract Inbox {

string public message;

constructor (string memory initiialMessage) {
    message = intialMessage;
}

}

My test:

// compile code will go here
const path = require('path');
const fs = require('fs');
const solc = require('solc');

const inboxPath = path.resolve(__dirname, 'contracts', 'Inbox.sol'); const source = fs.readFileSync(inboxPath, 'utf-8');

console.log(solc.compile(source, 1))

{ "name": "inbox", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "mocha" }, "author": "", "license": "ISC", "dependencies": { "@truffle/hdwallet-provider": "^2.1.12", "ganache": "^7.8.0", "ganache-cli": "^6.12.2", "mocha": "^10.2.0", "solc": "0.8.19", "web3": "^4.1.2" } }

// contract test code will go here const assert = require('assert'); const ganache = require('ganache-cli'); const { Web3 } = require('web3'); const web3 = new Web3(ganache.provider()); const {abi, evm} = require('../compile');

let accounts; let inbox;

beforeEach(async () => { // Get a list of accounts accounts = await web3.eth.getAccounts();

// Use one of the accounts to deploy contract 
inbox = await new web3.eth.Contract(abi)
.deploy({
    data: evm.bytecode.object, 
    arguments: ['Halo']
})
.send({from: accounts[0], gas: '1000000'});

})

describe('Inbox', () => { it('deploy contract', () => { console.log(inbox); }) })

and this is the error:

C:\Users\ASUS ROG\Downloads\inbox>npm run test

> inbox@1.0.0 test > mocha

AssertionError [ERR_ASSERTION]: Invalid callback object specified. at runWithCallbacks (C:\Users\ASUS ROG\Downloads\inbox\node_modules\solc\bindings\compile.js:120:30) at Object.boundFunctionStandard [as compileStandard] (C:\Users\ASUS ROG\Downloads\inbox\node_modules\solc\bindings\compile.js:83:20) at compileStandardWrapper (C:\Users\ASUS ROG\Downloads\inbox\node_modules\solc\wrapper.js:66:24) at Object.<anonymous> (C:\Users\ASUS ROG\Downloads\inbox\compile.js:9:18) at Module._compile (node:internal/modules/cjs/loader:1256:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1310:10) at Module.load (node:internal/modules/cjs/loader:1119:32) at Function.Module._load (node:internal/modules/cjs/loader:960:12) at Module.require (node:internal/modules/cjs/loader:1143:19) at require (node:internal/modules/cjs/helpers:119:18) at Object.<anonymous> (C:\Users\ASUS ROG\Downloads\inbox\test\Inbox.test.js:6:20) at Module._compile (node:internal/modules/cjs/loader:1256:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1310:10) at Module.load (node:internal/modules/cjs/loader:1119:32) at Function.Module._load (node:internal/modules/cjs/loader:960:12) at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29) at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

Rohan Nero
  • 1,562
  • 2
  • 7
  • 27
Jyobala
  • 11
  • 1
  • The way solc package is being used is too old, look at the package documentation. This answer has an example how to use it https://ethereum.stackexchange.com/a/65278. – Ismael Oct 17 '23 at 02:22

0 Answers0