fix getEVMexception

This commit is contained in:
Ricardo Guilherme Schmidt 2019-03-23 06:15:19 -03:00
parent cc28b94a30
commit 3d4f590778
No known key found for this signature in database
GPG Key ID: BFB3F5C8ED618A94
1 changed files with 10 additions and 11 deletions

View File

@ -207,36 +207,35 @@ exports.ensureException = function(error) {
assert(isException(error), error.toString());
};
const NO_ERROR = 0;
const FATAL_ERROR = 1;
const OUT_OF_GAS = 2;
const USER_ERROR = 3;
exports.getEVMException = async function(sendFn) {
exports.getEVMException = async function(sendFn, sender=null, gasLimit=8000000) {
var error = null;
try {
await sendFn.estimateGas();
await sendFn.estimateGas({ from: sender, gas: gasLimit});
} catch(e) {
var a = e.toString().split(": ");
if(a[0] != "RuntimeError" || a[1] != "VM Exception while processing transaction") {
throw e;
}
switch (a[3]){
switch (a[2]){
case "out of gas":
case "invalid opcode":
case "invalid JUMP":
case "stack overflow":
case "revert":
error = a[3]
error = a[2]
break;
default:
if(a[3].startsWith("revert ")){
error = a[3].substring(7)
if(a[2].startsWith("revert ")){
error = a[2].substring(7)
} else {
error = a[3];
error = a[2];
}
}
} finally {
return error;
}
}