0

I revert a transaction in my smart contract when a specific condition is met. For instance:

function doMoneyLaundering(uint256 millionsOfDollars) public {
   ...
   require(US_IS_THE_BIGGEST_SUPPORTER_OF_HUMAN_RIGHTS, "Are you kidding me?!");// an always wrong assertion, only for the test!
   ...
}

Now I need to get assertion error in my JS code:

await dangerousContractInstance.methods.doMoneyLaundering(aVeryBigDealOfMoney).send({from: accounts[0]}).catch(console.log);

But it just throws a nonsense exception:

Error: VM execution error.
    at Object.callback (/home/dangerousUser/IdeaProjects/dangerousProject/node_modules/truffle-hdwallet-provider/dist/index.js:15:632675)
    at /home/dangerousUser/IdeaProjects/dangerousProject/node_modules/web3-providers-ws/lib/index.js:114:45
    at Array.forEach (<anonymous>)
    at WebsocketProvider._onMessage (/home/dangerousUser/IdeaProjects/dangerousProject/node_modules/web3-providers-ws/lib/index.js:102:69)
    at W3CWebSocket._dispatchEvent [as dispatchEvent] (/home/dangerousUser/IdeaProjects/dangerousProject/node_modules/yaeti/lib/EventTarget.js:115:12)
    at W3CWebSocket.onMessage (/home/dangerousUser/IdeaProjects/dangerousProject/node_modules/websocket/lib/W3CWebSocket.js:234:14)
    at WebSocketConnection.<anonymous> (/home/dangerousUser/IdeaProjects/dangerousProject/node_modules/websocket/lib/W3CWebSocket.js:205:19)
    at WebSocketConnection.emit (events.js:198:13)
    at WebSocketConnection.processFrame (/home/dangerousUser/IdeaProjects/dangerousProject/node_modules/websocket/lib/WebSocketConnection.js:554:26)
    at /home/dangerousUser/IdeaProjects/dangerousProject/node_modules/websocket/lib/WebSocketConnection.js:323:40
    at process._tickCallback (internal/process/next_tick.js:61:11)

Does anybody know how can I get the correct message? By the way, I'm testing on kovan and Infura.

1
  • @RichardHorrocks I've already tested that, but it did not work for me. – Ehsan Khodarahmi Apr 16 at 12:04