[SOLVED] Truffle Test fails to fail :D

Hi guys,

I hope this is not offtopic for the forum.

So I have a contract that I am writing and I wanted to write some truffle tests for. One of the test cases is simply, test that the owner is not allowed to participate. participate is a function in the contract:

modifier notOwner() {
    require(msg.sender != owner, "is owner");
    _;
}

function participate(string memory data) public payable notOwner
{}

The test is simple:

  it("should not allow owner to participate", async function () {
    try {
      await instance.participate("test", {
        from: accounts[0],
        value: 1
      });
      assert(false);
    } catch (error) {
      assert.ok(true);
    }
  });

For the test to pass the method instance.participate() should throw an error, that should be caught by the catch statement. However what is happening is that an error is being thrown during the test, when I run truffle test :

  1) Contract: TestContact
       should not allow owner to participate:
     Uncaught TypeError: Cannot use 'in' operator to search for 'result' in 0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000086973206f776e6572000000000000000000000000000000000000000000000000
      at Object._extract (/home/ahmed/.nvm/versions/node/v16.13.2/lib/node_modules/truffle/build/webpack:/packages/contract/lib/reason.js:31:1)
      at /home/ahmed/.nvm/versions/node/v16.13.2/lib/node_modules/truffle/build/webpack:/packages/contract/lib/reason.js:79:1
      at /home/ahmed/.nvm/versions/node/v16.13.2/lib/node_modules/truffle/build/webpack:/packages/provider/wrapper.js:107:1
      at XMLHttpRequest.request.onreadystatechange (/home/ahmed/.nvm/versions/node/v16.13.2/lib/node_modules/truffle/build/webpack:/node_modules/web3/node_modules/web3-providers-http/lib/index.js:98:1)
      at XMLHttpRequestEventTarget.dispatchEvent (/home/ahmed/.nvm/versions/node/v16.13.2/lib/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:1)
      at XMLHttpRequest.exports.modules.996763.XMLHttpRequest._setReadyState (/home/ahmed/.nvm/versions/node/v16.13.2/lib/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request.js:208:1)
      at XMLHttpRequest.exports.modules.996763.XMLHttpRequest._onHttpResponseEnd (/home/ahmed/.nvm/versions/node/v16.13.2/lib/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request.js:318:1)
      at IncomingMessage.<anonymous> (/home/ahmed/.nvm/versions/node/v16.13.2/lib/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request.js:289:47)
      at IncomingMessage.emit (node:events:402:35)
      at endReadableNT (node:internal/streams/readable:1343:12)
      at processTicksAndRejections (node:internal/process/task_queues:83:21)

any ideas? have you guys seen something like that?

thanks

truffle update solved the issue … I was only one patch behind :sweat_smile: v5.4.30 … now it works on v5.4.31 :tada:

I took me 24 hours of scratching my head!!

3 Likes