From e78e642eef21c0219eb025f859edea5817363b3f Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 7 Mar 2017 11:34:11 -0800 Subject: Add gas buffer test --- test/unit/tx-utils-test.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 test/unit/tx-utils-test.js (limited to 'test/unit') diff --git a/test/unit/tx-utils-test.js b/test/unit/tx-utils-test.js new file mode 100644 index 000000000..6131ed73f --- /dev/null +++ b/test/unit/tx-utils-test.js @@ -0,0 +1,38 @@ +const assert = require('assert') +const ethUtil = require('ethereumjs-util') +const BN = ethUtil.BN + +const TxUtils = require('../../app/scripts/lib/tx-utils') + + +describe('txUtils', function() { + let txUtils + + before(function() { + txUtils = new TxUtils() + }) + + describe('addGasBuffer', function() { + describe('adds a flat value', function() { + it('over an empty value', function() { + const input = '0x0' + const output = txUtils.addGasBuffer(input) + assert.notEqual(output, input, 'changed the value') + + const inputBn = new BN(input, 'hex') + const outputBn = new BN(output, 'hex') + assert(outputBn.gt(inputBn), 'returns a greater value') + }) + + it('over an value', function() { + const input = '0x123fad' + const output = txUtils.addGasBuffer(input) + assert.notEqual(output, input, 'changed the value') + + const inputBn = new BN(input, 'hex') + const outputBn = new BN(output, 'hex') + assert(outputBn.gt(inputBn), 'returns a greater value') + }) + }) + }) +}) \ No newline at end of file -- cgit v1.2.3 From de44cd9ba46e562471d64e6cfc56cf8518f45113 Mon Sep 17 00:00:00 2001 From: Jared Pereira Date: Tue, 7 Mar 2017 20:49:40 -0500 Subject: add gas buffer multiply test --- test/unit/tx-utils-test.js | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'test/unit') diff --git a/test/unit/tx-utils-test.js b/test/unit/tx-utils-test.js index 6131ed73f..a7f2094c4 100644 --- a/test/unit/tx-utils-test.js +++ b/test/unit/tx-utils-test.js @@ -13,26 +13,16 @@ describe('txUtils', function() { }) describe('addGasBuffer', function() { - describe('adds a flat value', function() { - it('over an empty value', function() { - const input = '0x0' - const output = txUtils.addGasBuffer(input) - assert.notEqual(output, input, 'changed the value') - - const inputBn = new BN(input, 'hex') - const outputBn = new BN(output, 'hex') - assert(outputBn.gt(inputBn), 'returns a greater value') - }) - - it('over an value', function() { + describe('multiplies by 1.5', function() { + it('over a value', function() { const input = '0x123fad' - const output = txUtils.addGasBuffer(input) - assert.notEqual(output, input, 'changed the value') + const output = txUtils.addGasBuffer(input, '0x3d4c52') //0x3d4c52 is 4mil for dummy gas limit const inputBn = new BN(input, 'hex') const outputBn = new BN(output, 'hex') - assert(outputBn.gt(inputBn), 'returns a greater value') + const expectedBn = inputBn.mul(1.5) + assert(outputBn.eq(expectedBn), 'returns 1.5 the input value') }) }) }) -}) \ No newline at end of file +}) -- cgit v1.2.3 From 4916331c530896bbcef13a71a8f6dc0164b43c01 Mon Sep 17 00:00:00 2001 From: Jared Pereira Date: Tue, 7 Mar 2017 22:42:16 -0500 Subject: change BN.mul to BN.muln --- test/unit/tx-utils-test.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'test/unit') diff --git a/test/unit/tx-utils-test.js b/test/unit/tx-utils-test.js index a7f2094c4..65233e1d9 100644 --- a/test/unit/tx-utils-test.js +++ b/test/unit/tx-utils-test.js @@ -13,16 +13,14 @@ describe('txUtils', function() { }) describe('addGasBuffer', function() { - describe('multiplies by 1.5', function() { - it('over a value', function() { - const input = '0x123fad' - const output = txUtils.addGasBuffer(input, '0x3d4c52') //0x3d4c52 is 4mil for dummy gas limit + 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(input, 'hex') - const outputBn = new BN(output, 'hex') - const expectedBn = inputBn.mul(1.5) - assert(outputBn.eq(expectedBn), 'returns 1.5 the input value') - }) + 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') }) }) }) -- cgit v1.2.3