Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 2948927

Browse files
committed
Handle revert reason errors for geth >= 1.9.5
1 parent 076fd46 commit 2948927

File tree

6 files changed

+44
-23
lines changed

6 files changed

+44
-23
lines changed

TESTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ CI job.
4646
The npm script `test:e2e:clients` greps all tests with an `[ @E2E ]` tag
4747
in their mocha test description and runs them against:
4848
+ ganache-cli
49-
+ geth 1.9.13 (POA, single instance, instamining)
50-
+ geth 1.9.13 (POA, single instance, mining at 2s intervals)
49+
+ geth stable (POA, single instance, instamining)
50+
+ geth stable (POA, single instance, mining at 2s intervals)
5151

5252
These tests are grouped in files prefixed by "e2e", ex: `test/e2e.method.call.js`.
5353

packages/web3-core-helpers/src/errors.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@
2626
module.exports = {
2727
ErrorResponse: function (result) {
2828
var message = !!result && !!result.error && !!result.error.message ? result.error.message : JSON.stringify(result);
29-
return new Error('Returned error: ' + message);
29+
var data = (!!result.error && !!result.error.data) ? result.error.data : null;
30+
var err = new Error('Returned error: ' + message);
31+
err.data = data;
32+
return err;
3033
},
3134
InvalidNumberOfParams: function (got, expected, method) {
3235
return new Error('Invalid number of parameters for "'+ method +'". Got '+ got +' expected '+ expected +'!');

packages/web3-core-method/src/index.js

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ Method.prototype._confirmTransaction = function (defer, result, payload) {
550550
const startInterval = () => {
551551
intervalId = setInterval(checkConfirmation.bind(null, existingReceipt, true), 1000);
552552
}
553-
553+
554554
if (!this.requestManager.provider.on) {
555555
startInterval()
556556
} else {
@@ -618,22 +618,34 @@ Method.prototype.buildCall = function () {
618618

619619
// CALLBACK function
620620
var sendTxCallback = function (err, result) {
621-
if (method.handleRevert && !err && isCall && (method.isRevertReasonString(result) && method.abiCoder)) {
622-
var reason = method.abiCoder.decodeParameter('string', '0x' + result.substring(10));
623-
var signature = 'Error(String)';
624-
625-
utils._fireError(
626-
errors.RevertInstructionError(reason, signature),
627-
defer.eventEmitter,
628-
defer.reject,
629-
payload.callback,
630-
{
631-
reason: reason,
632-
signature: signature
633-
}
634-
);
621+
if (method.handleRevert && isCall && method.abiCoder) {
622+
var reasonData;
623+
624+
// Ganache / Geth <= 1.9.13 return the reason data as a successful eth_call response
625+
// Geth >= 1.9.15 attaches the reason data to an error object.
626+
if (!err && method.isRevertReasonString(result)){
627+
reasonData = result.substring(10);
628+
} else if (err && err.data){
629+
reasonData = err.data.substring(10);
630+
}
635631

636-
return;
632+
if (reasonData){
633+
var reason = method.abiCoder.decodeParameter('string', '0x' + reasonData);
634+
var signature = 'Error(String)';
635+
636+
utils._fireError(
637+
errors.RevertInstructionError(reason, signature),
638+
defer.eventEmitter,
639+
defer.reject,
640+
payload.callback,
641+
{
642+
reason: reason,
643+
signature: signature
644+
}
645+
);
646+
647+
return;
648+
}
637649
}
638650

639651
try {

scripts/e2e.geth.automine.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ echo " "
2424
# Launch client w/ two unlocked accounts.
2525
# + accounts[0] default geth unlocked bal = ~infinity
2626
# + accounts[1] unlocked, signing password = 'left-hand-of-darkness'
27-
geth-dev-assistant --period 2 --accounts 1 --tag 'v1.9.13'
27+
geth-dev-assistant --period 2 --accounts 1 --tag 'stable'
2828

2929
# Test
3030
GETH_AUTOMINE=true nyc --no-clean --silent _mocha -- \

scripts/e2e.geth.instamine.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ echo " "
2424
# Launch client w/ two unlocked accounts.
2525
# + accounts[0] default geth unlocked bal = ~infinity
2626
# + accounts[1] unlocked, bal=50 eth, signing password = 'left-hand-of-darkness'
27-
geth-dev-assistant --accounts 1 --tag 'v1.9.13'
27+
geth-dev-assistant --accounts 1 --tag 'stable'
2828

2929
# Test
3030
GETH_INSTAMINE=true nyc --no-clean --silent _mocha -- \

test/e2e.method.call.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,14 @@ describe('method.call [ @E2E ]', function () {
6262
assert.fail();
6363

6464
} catch (err) {
65-
assert(err.message.includes("Returned values aren't valid"));
66-
assert(err.message.includes('the correct ABI'));
65+
// ganache | geth <= 1.9.13
66+
const nullDataResponse = err.message.includes("Returned values aren't valid") &&
67+
err.message.includes('the correct ABI');
68+
69+
// geth >= 1.9.15
70+
const gethErrResponse = err.message.includes("revert");
71+
72+
assert(nullDataResponse || gethErrResponse);
6773
}
6874
})
6975
});

0 commit comments

Comments
 (0)