aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit
diff options
context:
space:
mode:
authorkumavis <kumavis@users.noreply.github.com>2017-03-08 14:28:02 +0800
committerGitHub <noreply@github.com>2017-03-08 14:28:02 +0800
commit68b99dfb086c282fa3f2e76fbaf93673e92f097d (patch)
tree19521ed56a512424155514f7a1a929b980c0cf98 /test/unit
parent17b805c76ea3ea160bcb2560d2043581b54c4834 (diff)
downloadtangerine-wallet-browser-68b99dfb086c282fa3f2e76fbaf93673e92f097d.tar
tangerine-wallet-browser-68b99dfb086c282fa3f2e76fbaf93673e92f097d.tar.gz
tangerine-wallet-browser-68b99dfb086c282fa3f2e76fbaf93673e92f097d.tar.bz2
tangerine-wallet-browser-68b99dfb086c282fa3f2e76fbaf93673e92f097d.tar.lz
tangerine-wallet-browser-68b99dfb086c282fa3f2e76fbaf93673e92f097d.tar.xz
tangerine-wallet-browser-68b99dfb086c282fa3f2e76fbaf93673e92f097d.tar.zst
tangerine-wallet-browser-68b99dfb086c282fa3f2e76fbaf93673e92f097d.zip
test - tx-utils
add tests for `addGasBuffer`
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/tx-utils-test.js32
1 files changed, 29 insertions, 3 deletions
diff --git a/test/unit/tx-utils-test.js b/test/unit/tx-utils-test.js
index 65233e1d9..c0ed9addd 100644
--- a/test/unit/tx-utils-test.js
+++ b/test/unit/tx-utils-test.js
@@ -13,14 +13,40 @@ describe('txUtils', function() {
})
describe('addGasBuffer', function() {
- it('multiplies by 1.5', function() {
+ it('multiplies by 1.5, when within block gas limit', function() {
+ // naive estimatedGas: 0x123fad (~1.2 mil)
const input = '0x123fad'
- const output = txUtils.addGasBuffer(input, '0x3d4c52') //0x3d4c52 is 4mil for dummy gas limit
-
+ // dummy gas limit: 0x3d4c52 (4 mil)
+ const blockGasLimit = '0x3d4c52'
+ const output = txUtils.addGasBuffer(input, blockGasLimit)
const inputBn = new BN(ethUtil.stripHexPrefix(input), 'hex')
const outputBn = new BN(ethUtil.stripHexPrefix(output), 'hex')
const expectedBn = inputBn.muln(1.5)
assert(outputBn.eq(expectedBn), 'returns 1.5 the input value')
})
+
+ it('uses original estimatedGas, when above block gas limit', function() {
+ // naive estimatedGas: 0x123fad (~1.2 mil)
+ const input = '0x123fad'
+ // dummy gas limit: 0x0f4240 (1 mil)
+ const blockGasLimit = '0x0f4240'
+ const output = txUtils.addGasBuffer(input, blockGasLimit)
+ const inputBn = new BN(ethUtil.stripHexPrefix(input), 'hex')
+ const outputBn = new BN(ethUtil.stripHexPrefix(output), 'hex')
+ const expectedBn = new BN(ethUtil.stripHexPrefix(input), 'hex')
+ assert(outputBn.eq(expectedBn), 'returns the original estimatedGas value')
+ })
+
+ it('buffers up to block gas limit', function() {
+ // naive estimatedGas: 0x123fad (~1.2 mil)
+ const input = '0x1e8480'
+ // dummy gas limit: 0x1e8480 (2 mil)
+ const blockGasLimit = '0x1e8480'
+ const output = txUtils.addGasBuffer(input, blockGasLimit)
+ const inputBn = new BN(ethUtil.stripHexPrefix(input), 'hex')
+ const outputBn = new BN(ethUtil.stripHexPrefix(output), 'hex')
+ const expectedBn = new BN(ethUtil.stripHexPrefix(blockGasLimit), 'hex')
+ assert(outputBn.eq(expectedBn), 'returns the block gas limit value')
+ })
})
})