diff options
author | Dan Finlay <dan@danfinlay.com> | 2016-11-08 07:38:25 +0800 |
---|---|---|
committer | Dan Finlay <dan@danfinlay.com> | 2016-11-08 07:38:25 +0800 |
commit | 161ff62fdcf6f76f7243a1e865dd0cccbc89121f (patch) | |
tree | 68a593b7cf57f2d42a859b09439362b5b4697355 /test | |
parent | 93c0a6826aa70fa14874579b1009bee7248a7c51 (diff) | |
parent | 62a15fc59e4e79a162867ae95e619d1ad22911ec (diff) | |
download | tangerine-wallet-browser-161ff62fdcf6f76f7243a1e865dd0cccbc89121f.tar tangerine-wallet-browser-161ff62fdcf6f76f7243a1e865dd0cccbc89121f.tar.gz tangerine-wallet-browser-161ff62fdcf6f76f7243a1e865dd0cccbc89121f.tar.bz2 tangerine-wallet-browser-161ff62fdcf6f76f7243a1e865dd0cccbc89121f.tar.lz tangerine-wallet-browser-161ff62fdcf6f76f7243a1e865dd0cccbc89121f.tar.xz tangerine-wallet-browser-161ff62fdcf6f76f7243a1e865dd0cccbc89121f.tar.zst tangerine-wallet-browser-161ff62fdcf6f76f7243a1e865dd0cccbc89121f.zip |
Merge branch 'master' into i328-MultiVault
Diffstat (limited to 'test')
-rw-r--r-- | test/unit/idStore-test.js | 50 |
1 files changed, 39 insertions, 11 deletions
diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index da465f511..46b3d4809 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -142,20 +142,47 @@ 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(ethUtil.stripHexPrefix(gas), 16) + const correctBuffer = new BN('100000', 10) + const correct = bnGas.add(correctBuffer) + + const tooBig = new BN(tooBigOutput, 16) + const result = idStore.addGasBuffer(gas) + const bnResult = new BN(ethUtil.stripHexPrefix(result), 16) + + assert.equal(result.indexOf('0x'), 0, 'included hex prefix') + assert(bnResult.gt(bnGas), 'Estimate increased in value.') + assert.equal(bnResult.sub(bnGas).toString(10), '100000', 'added 100k gas') + assert.equal(result, '0x' + correct.toString(16), 'Added the right amount') + assert.notEqual(result, tooBigOutput, 'not that bad estimate') + }) }) describe('#checkForDelegateCall', function() { @@ -169,4 +196,5 @@ describe('IdentityStore', function() { var result = idStore.checkForDelegateCall(delegateCallCode) assert.equal(result, true, 'no delegate call in provided code') }) + }) |