owanhunte / ethereum-solidity-course-updated-code

Up-to-date Solidity / web3.js / Node.js / React / Next.js code for the udemy.com course Ethereum and Solidity: The Complete Developer's Guide.
183 stars 82 forks source link

inbox error: i: VM Exception while processing transaction: invalid opcode #39

Closed kurtappelmans closed 2 years ago

kurtappelmans commented 2 years ago

Dear, thank you for the updated code. In my environment I encounter a problem with the message().call() and the setMessage().call() tests. they fail and the error: i: VM Exception while processing transaction: invalid opcode is returned. Thank you very much in advance for your advice.

owanhunte commented 2 years ago

Hi @kurtappelmans, sorry for the late response. I assume you mean setMessage().send() instead of setMessage().call(). Could you share the full contents of your Inbox.test.js test file?

kurtappelmans commented 2 years ago

Dear, thank you for your reply. I'm basically using your code:

const assert = require("assert"); const ganache = require("ganache-cli"); const Web3 = require("web3"); const provider = ganache.provider(); const web3 = new Web3(provider); const { abi, evm } = require("../compile");

const message = "Hi there!"; 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(abi) .deploy({ data: "0x" + evm.bytecode.object, arguments: [message] }) .send({ from: accounts[0], gas: "900000" }); });

describe("Inbox", () => { it("deploys a contract", () => { assert.ok(inbox.options.address); });

it("has a default message", async () => { const msg = await inbox.methods.message().call(); assert.strictEqual(msg, message); });

it("can change the message", async () => { const newMsg = "bye"; await inbox.methods.setMessage(newMsg).send({ from: accounts[0] });

const msg = await inbox.methods.message().call();
assert.strictEqual(msg, newMsg);

}); });

kurtappelmans commented 2 years ago

For some reason it works now. Thank you very much for your help!