mirror of
https://github.com/dap-ps/discover.git
synced 2025-01-31 03:26:13 +00:00
863d9ea8e3
* chore: update to Embark v5 * fix: fix tests for Embark 5 * update Embark version and remove Geth client * change contracts to deploy and add cross-env for Windows support * feat: upgrade to Embark 5.1.nightly2 Fixes the problem of not exiting on build end * update to Embark 5.1 Fixes issue where artifacts are not built
37 lines
1.6 KiB
JavaScript
37 lines
1.6 KiB
JavaScript
/* global assert */
|
|
|
|
function isException(error) {
|
|
let strError = error.toString();
|
|
return strError.includes('VM Exception') || strError.includes('invalid opcode') || strError.includes('invalid JUMP');
|
|
}
|
|
|
|
function ensureException(error) {
|
|
assert(isException(error), error.toString());
|
|
}
|
|
|
|
const PREFIX = "Returned error: VM Exception while processing transaction: ";
|
|
|
|
async function tryCatch(promise, message) {
|
|
try {
|
|
await promise;
|
|
throw null;
|
|
}
|
|
catch (error) {
|
|
assert(error, "Expected an error but did not get one");
|
|
assert(error.message.startsWith(PREFIX + message), "Expected an error starting with '" + PREFIX + message + "' but got '" + error.message + "' instead");
|
|
}
|
|
};
|
|
|
|
module.exports = {
|
|
zeroAddress : '0x0000000000000000000000000000000000000000',
|
|
isException : isException,
|
|
ensureException : ensureException,
|
|
catchRevert : async function(promise) {await tryCatch(promise, "revert" );},
|
|
catchOutOfGas : async function(promise) {await tryCatch(promise, "out of gas" );},
|
|
catchInvalidJump : async function(promise) {await tryCatch(promise, "invalid JUMP" );},
|
|
catchInvalidOpcode : async function(promise) {await tryCatch(promise, "invalid opcode" );},
|
|
catchStackOverflow : async function(promise) {await tryCatch(promise, "stack overflow" );},
|
|
catchStackUnderflow : async function(promise) {await tryCatch(promise, "stack underflow" );},
|
|
catchStaticStateChange : async function(promise) {await tryCatch(promise, "static state change");},
|
|
};
|