Reputation: 1
I'm working on a smart contract test using Ganache
and Web3.js
. My contract deploys without errors, but when I try to call a function, I encounter an error.
Here’s my code:
const assert = require('assert');
const ganache = require('ganache');
const Web3 = require('web3');
const web3 = new Web3(ganache.provider());
const {interface, bytecode} = require('../compile');
let accounts;
let inbox;
beforeEach(async () => {
accounts = await web3.eth.getAccounts();
inbox = await new web3.eth.Contract(JSON.parse(interface))
.deploy({ data: '0x0' + bytecode, arguments: ['hello!'] }) // 0x0
.send({ from: accounts[0], gas: "1000000"})
.catch(err => {
console.error('Deployment Error:', err); // Log the error if deployment fails
});
if (inbox) {
console.log('Contract deployed at:', inbox.options.address); // Log the deployed address
} else {
console.error('Contract deployment failed.');
}
});
describe('Inbox', () => {
it('deploys a contract1', async () => {
assert.ok(inbox.options.address); // test for deployment
});
it('deploys a contract2', () => {
console.log(inbox.options.jsonInterface);
});
it('deploys a contract3', async () => {
console.log(inbox);
const message = await inbox.methods.message().call();
console.log(message);
});
});
When I run the test suite, I get this error:
2 passing (146ms)
1 failing
- Inbox deploys a contract3: Error: Returned values aren't valid, did it run Out of Gas? You might also see this error if you are not using the correct ABI for the contract you are retrieving data from, requesting data from a block number that does not exist, or querying a node which is not fully synced.
The contract deployment appears successful, and I'm using a high gas limit (1,000,000). The error occurs when calling message()
, a function that should just return a string.
I've also checked the ABI and bytecode and they seem correct.
Is there something I am missing?
Upvotes: 0
Views: 38