-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.js
34 lines (31 loc) · 981 Bytes
/
helpers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
module.exports.errTypes = {
revert: "revert",
outOfGas: "out of gas",
invalidJump: "invalid JUMP",
invalidOpcode: "invalid opcode",
stackOverflow: "stack overflow",
stackUnderflow: "stack underflow",
staticStateChange: "static state change",
nonPayableFunction: "Cannot send value to non-payable function"
};
module.exports.tryCatch = async function (promise, errType) {
try {
await promise;
throw null;
}
catch (error) {
assert(error, "Expected an error but did not get one");
assert(error.message.startsWith(PREFIX + errType), "Expected an error starting with '" + PREFIX + errType + "' but got '" + error.message + "' instead");
}
};
const PREFIX = "VM Exception while processing transaction: ";
module.exports.tryFullError = async function (promise, errType) {
try {
await promise;
throw null;
}
catch (error) {
assert(error, "Expected an error but did not get one");
assert.equal(error.message, errType);
}
};