aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit/tx-utils-test.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit/tx-utils-test.js')
-rw-r--r--test/unit/tx-utils-test.js44
1 files changed, 38 insertions, 6 deletions
diff --git a/test/unit/tx-utils-test.js b/test/unit/tx-utils-test.js
index 65233e1d9..e57b25e83 100644
--- a/test/unit/tx-utils-test.js
+++ b/test/unit/tx-utils-test.js
@@ -13,14 +13,46 @@ describe('txUtils', function() {
})
describe('addGasBuffer', function() {
- it('multiplies by 1.5', function() {
- const input = '0x123fad'
- const output = txUtils.addGasBuffer(input, '0x3d4c52') //0x3d4c52 is 4mil for dummy gas limit
-
- const inputBn = new BN(ethUtil.stripHexPrefix(input), 'hex')
- const outputBn = new BN(ethUtil.stripHexPrefix(output), 'hex')
+ it('multiplies by 1.5, when within block gas limit', function() {
+ // naive estimatedGas: 0x123fad (~1.2 mil)
+ const inputHex = '0x123fad'
+ // dummy gas limit: 0x3d4c52 (4 mil)
+ const blockGasLimitHex = '0x3d4c52'
+ const output = txUtils.addGasBuffer(inputHex, blockGasLimitHex)
+ const inputBn = hexToBn(inputHex)
+ const outputBn = hexToBn(output)
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 inputHex = '0x123fad'
+ // dummy gas limit: 0x0f4240 (1 mil)
+ const blockGasLimitHex = '0x0f4240'
+ const output = txUtils.addGasBuffer(inputHex, blockGasLimitHex)
+ const inputBn = hexToBn(inputHex)
+ const outputBn = hexToBn(output)
+ const expectedBn = hexToBn(inputHex)
+ assert(outputBn.eq(expectedBn), 'returns the original estimatedGas value')
+ })
+
+ it('buffers up to block gas limit', function() {
+ // naive estimatedGas: 0x123fad (~1.2 mil)
+ const inputHex = '0x1e8480'
+ // dummy gas limit: 0x1e8480 (2 mil)
+ const blockGasLimitHex = '0x1e8480'
+ const output = txUtils.addGasBuffer(inputHex, blockGasLimitHex)
+ const inputBn = hexToBn(inputHex)
+ const outputBn = hexToBn(output)
+ const expectedBn = hexToBn(blockGasLimitHex)
+ assert(outputBn.eq(expectedBn), 'returns the block gas limit value')
+ })
})
})
+
+// util
+
+function hexToBn(inputHex) {
+ return new BN(ethUtil.stripHexPrefix(inputHex), 16)
+} \ No newline at end of file