I am trying to run a JS test script with truffles but I can not seem to find the right place to store the assertRevert file so that the module can be found by the script when I try to run the test.
const { assertRevert } = require('assertRevert');
Is that the top of my script.
The Error I am getting is Cannot find module 'assertRevert'
Thanks in advance !
require('assertRevert.js'), otherwise, node searches in its own installation path rather than in your local path. – goodvibration Jul 31 '18 at 12:31require('./assertRevert.js'). Of course, if the fileassertRevert.jsis not located in the same path as your script, then use the correct relative path instead of./. – goodvibration Jul 31 '18 at 13:36module.exports = ...somewhere? Also, why exactly do you doconst { assertRevert } = ...with those curly braces? Seems like you're not entirely familiar with how to export JS code properly. There's a lot of information on that, and you probably want to search it on Stack Overflow, because it doesn't have anything to do specifically with Ethereum. – goodvibration Aug 01 '18 at 12:29module.exports = { assertRevert: async (promise) => { try { await promise; } catch (error) { const revertFound = error.message.search('revert') >= 0; assert(revertFound,Expected "revert", got ${error} instead); return; } assert.fail('Expected revert not received'); }, };And I copied the code from the open zeppelin erc20 testing source code.
– conwise17 Aug 01 '18 at 13:45const assertRevert = require('./assertRevert.js').assertRevert;. – goodvibration Aug 01 '18 at 13:48The final piece of code that worked is const assertRevert = require('../helpers/assertRevert.js').assertRevert;
– conwise17 Aug 02 '18 at 09:29