diff options
author | Dan Finlay <dan@danfinlay.com> | 2016-11-08 03:25:23 +0800 |
---|---|---|
committer | Dan Finlay <dan@danfinlay.com> | 2016-11-08 03:25:23 +0800 |
commit | fff5a6765ecc586bd855aa263c0fdfc3f957e8d7 (patch) | |
tree | 306faeaa3200d0f93feceb726b640a0c14bd59fc | |
parent | 30ff9b5e10f12588a213496921e84514c2018641 (diff) | |
download | tangerine-wallet-browser-fff5a6765ecc586bd855aa263c0fdfc3f957e8d7.tar tangerine-wallet-browser-fff5a6765ecc586bd855aa263c0fdfc3f957e8d7.tar.gz tangerine-wallet-browser-fff5a6765ecc586bd855aa263c0fdfc3f957e8d7.tar.bz2 tangerine-wallet-browser-fff5a6765ecc586bd855aa263c0fdfc3f957e8d7.tar.lz tangerine-wallet-browser-fff5a6765ecc586bd855aa263c0fdfc3f957e8d7.tar.xz tangerine-wallet-browser-fff5a6765ecc586bd855aa263c0fdfc3f957e8d7.tar.zst tangerine-wallet-browser-fff5a6765ecc586bd855aa263c0fdfc3f957e8d7.zip |
Added failing test for #787
-rw-r--r-- | test/unit/idStore-test.js | 52 |
1 files changed, 41 insertions, 11 deletions
diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index da465f511..34b0c992e 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -142,20 +142,49 @@ describe('IdentityStore', function() { }) describe('#addGasBuffer', function() { - const idStore = new IdentityStore({ - configManager: configManagerGen(), - ethStore: { - addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) }, - }, + it('formats the result correctly', function() { + const idStore = new IdentityStore({ + configManager: configManagerGen(), + ethStore: { + addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) }, + }, + }) + + const gas = '0x01' + const bnGas = new BN(gas, 16) + const result = idStore.addGasBuffer(gas) + const bnResult = new BN(result, 16) + + assert.ok(bnResult.gt(gas), 'added more gas as buffer.') + assert.equal(result.indexOf('0x'), 0, 'include hex prefix') }) - const gas = '0x01' - const bnGas = new BN(gas, 16) - const result = idStore.addGasBuffer(gas) - const bnResult = new BN(result, 16) + it('buffers reasonably', function() { + const idStore = new IdentityStore({ + configManager: configManagerGen(), + ethStore: { + addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) }, + }, + }) - assert.ok(bnResult.gt(gas), 'added more gas as buffer.') - assert.equal(result.indexOf('0x'), 0, 'include hex prefix') + const gas = '0x04ee59' // Actual estimated gas example + const tooBigOutput = '0x80674f9' // Actual bad output + const bnGas = new BN(gas, 16) + const correctBuffer = new BN('100000', 10) + const correct = bnGas.add(correctBuffer) + + const tooBig = new BN(tooBigOutput, 16) + console.log(`Pure estimate is ${bnGas.toString(10)}`) + console.log(`Too big is ${tooBig.toString(10)}`) + console.log(`Buffer should be ${correctBuffer.toString(10)}`) + console.log(`correct should be ${correct.toString(10)}`) + const result = idStore.addGasBuffer(gas) + const bnResult = new BN(result, 16) + + console.log(`Result was ${bnResult.toString(10)}`) + assert.equal(result, correct.toString(16), 'add the right amount') + assert.notEqual(result, tooBigOutput, 'not that bad estimate') + }) }) describe('#checkForDelegateCall', function() { @@ -169,4 +198,5 @@ describe('IdentityStore', function() { var result = idStore.checkForDelegateCall(delegateCallCode) assert.equal(result, true, 'no delegate call in provided code') }) + }) |