0

Does anyone know why console.log in Truffle Javascript promises causes errors given below?

I have the following code, where as soon as I remove the console.log statements, the errors given below go away. How can I dump some text, or data to the console then?

Alternatively, can someone provide some resource where I can dump text or data to a storage somewhere for later review? The console.log statements are there to help me debug the code.

Thank you.

  it("Owner should be creator", async function() {
    TestOwnership.new({from: account_main}).then(async function(instance) {
      let currentOwner = await instance.getOwner.call();
      console.log("Hello world1");
      return currentOwner;
    }).then(function(owner) {
      console.log("Hello world2");
      assert.equal(owner, account_main);
    })
  });


  it("Owner can't be changed by outsider", async function() {
    let prevOwner;
    let newOwner = 0x0;
    TestOwnership.new({from: account_main}).then(async function(instance) {
      prevOwner = await instance.getOwner.call();
      await instance.changeOwner.call(account_outsider, {from: account_outsider});
      console.log("Hello world3");
      return instance;
    }).then(async function(instance) {
      console.log("Hello world4");
      newOwner = await instance.getOwner.call();
      assert.notEqual(newOwner, prevOwner); 
    }).catch(function(err) {
      console.log("Hello worls5");
    });
  });

Errors as mentioned earlier:

Error: Error: VM Exception while executing eth_call: invalid opcode
    at C:\Users\Administrator\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:59368:17
    at C:\Users\Administrator\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:69306:5
    at C:\Users\Administrator\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:11335:9
    at C:\Users\Administrator\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:7895:16
    at replenish (C:\Users\Administrator\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:8415:25)
    at iterateeCallback (C:\Users\Administrator\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:8405:17)
    at C:\Users\Administrator\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:8380:16
    at C:\Users\Administrator\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:11332:13
    at C:\Users\Administrator\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:69302:9
    at C:\Users\Administrator\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:63982:7
    at Object.InvalidResponse (C:\Users\Administrator\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:37312:16)
    at C:\Users\Administrator\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:220420:36
    at C:\Users\Administrator\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:204149:9
    at XMLHttpRequest.request.onreadystatechange (C:\Users\Administrator\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:2055
    at XMLHttpRequestEventTarget.dispatchEvent (C:\Users\Administrator\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:73069:
    at XMLHttpRequest._setReadyState (C:\Users\Administrator\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:73359:12)
    at XMLHttpRequest._onHttpResponseEnd (C:\Users\Administrator\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:73514:12)
    at IncomingMessage.<anonymous> (C:\Users\Administrator\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:73474:24)
    at emitNone (events.js:110:20)
    at IncomingMessage.emit (events.js:207:7)
  • Invalid opcode means some of your call/transaction has reached an invalid condition, ie it throws an exception, an assert or require fails its condition, try to use an invalid position in an array, etc. ethereum.stackexchange.com/questions/25364/… – Ismael Oct 5 '17 at 16:18
  • Removing all comsole.log statements removes the exception. Did you miss that? – chuacw Oct 5 '17 at 16:32
  • You are mixing async/await with promises, console.log may causes a timing issue and the promises are executed in an unexpected order. You should be able to await a Promise. – Ismael Oct 5 '17 at 16:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.