aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorDan <danjm.com@gmail.com>2018-05-25 21:37:16 +0800
committerDan <danjm.com@gmail.com>2018-05-31 07:24:32 +0800
commit5a842e440f0ec565eba38aec4c1c953a775557ea (patch)
treeef31345b42b71fadf1c38731a7252e8da07f2366 /ui
parent0f20fce9b761fc0aa16d61b2b739fa7f9b9f6a7d (diff)
downloadtangerine-wallet-browser-5a842e440f0ec565eba38aec4c1c953a775557ea.tar
tangerine-wallet-browser-5a842e440f0ec565eba38aec4c1c953a775557ea.tar.gz
tangerine-wallet-browser-5a842e440f0ec565eba38aec4c1c953a775557ea.tar.bz2
tangerine-wallet-browser-5a842e440f0ec565eba38aec4c1c953a775557ea.tar.lz
tangerine-wallet-browser-5a842e440f0ec565eba38aec4c1c953a775557ea.tar.xz
tangerine-wallet-browser-5a842e440f0ec565eba38aec4c1c953a775557ea.tar.zst
tangerine-wallet-browser-5a842e440f0ec565eba38aec4c1c953a775557ea.zip
Gas estimation uses block gas limit as fallback if query.estimateGas returns an expected error.
Diffstat (limited to 'ui')
-rw-r--r--ui/app/components/send_/send.utils.js15
-rw-r--r--ui/app/components/send_/tests/send-utils.test.js29
2 files changed, 39 insertions, 5 deletions
diff --git a/ui/app/components/send_/send.utils.js b/ui/app/components/send_/send.utils.js
index 750411908..9b8f1d118 100644
--- a/ui/app/components/send_/send.utils.js
+++ b/ui/app/components/send_/send.utils.js
@@ -193,14 +193,21 @@ async function estimateGas ({ selectedAddress, selectedToken, data, blockGasLimi
roundDown: '0',
toNumericBase: 'hex',
}))
-
// run tx
return new Promise((resolve, reject) => {
- estimateGasMethod(paramsForGasEstimate, (err, estimatedGas) => {
+ return estimateGasMethod(paramsForGasEstimate, (err, estimatedGas) => {
if (err) {
- reject(err)
+ const simulationFailed = (
+ err.message.includes('Transaction execution error.') ||
+ err.message.includes('gas required exceeds allowance or always failing transaction')
+ )
+ if (simulationFailed) {
+ return resolve(paramsForGasEstimate.gas)
+ } else {
+ return reject(err)
+ }
}
- resolve(estimatedGas.toString(16))
+ return resolve(estimatedGas.toString(16))
})
})
}
diff --git a/ui/app/components/send_/tests/send-utils.test.js b/ui/app/components/send_/tests/send-utils.test.js
index 3c772ed47..4801d4a09 100644
--- a/ui/app/components/send_/tests/send-utils.test.js
+++ b/ui/app/components/send_/tests/send-utils.test.js
@@ -241,7 +241,10 @@ describe('send utils', () => {
selectedAddress: 'mockAddress',
to: '0xisContract',
estimateGasMethod: sinon.stub().callsFake(
- (data, cb) => cb(null, { toString: (n) => `mockToString:${n}` })
+ (data, cb) => cb(
+ data.to.match(/willFailBecauseOf:/) ? { message: data.to.match(/\:(.+)$/)[1] } : null,
+ { toString: (n) => `mockToString:${n}` }
+ )
),
}
const baseExpectedCall = {
@@ -298,6 +301,30 @@ describe('send utils', () => {
const result = await estimateGas(Object.assign({}, baseMockParams, { to: '0x123' }))
assert.equal(result, SIMPLE_GAS_COST)
})
+
+ it(`should return the adjusted blockGasLimit if it fails with a 'Transaction execution error.'`, async () => {
+ const result = await estimateGas(Object.assign({}, baseMockParams, {
+ to: 'isContract willFailBecauseOf:Transaction execution error.',
+ }))
+ assert.equal(result, '0x64x0.95')
+ })
+
+ it(`should return the adjusted blockGasLimit if it fails with a 'gas required exceeds allowance or always failing transaction.'`, async () => {
+ const result = await estimateGas(Object.assign({}, baseMockParams, {
+ to: 'isContract willFailBecauseOf:gas required exceeds allowance or always failing transaction.',
+ }))
+ assert.equal(result, '0x64x0.95')
+ })
+
+ it(`should reject other errors`, async () => {
+ try {
+ await estimateGas(Object.assign({}, baseMockParams, {
+ to: 'isContract willFailBecauseOf:some other error',
+ }))
+ } catch (err) {
+ assert.deepEqual(err, { message: 'some other error' })
+ }
+ })
})
describe('estimateGasPriceFromRecentBlocks', () => {