diff options
author | frankiebee <frankie.diamond@gmail.com> | 2017-09-27 07:24:43 +0800 |
---|---|---|
committer | frankiebee <frankie.diamond@gmail.com> | 2017-09-27 07:24:43 +0800 |
commit | 8ab23c713db1f5d45abb0ba433450591b8759809 (patch) | |
tree | c192fcf5eec3c7b422f3d0a91a4a96037c7f2fa6 /test/unit | |
parent | 77a48fb0b16d7415377b02a3b7d383c9ef86fcb6 (diff) | |
parent | 6ca519e97c4c282023ab6b7788715ff8d7ec8189 (diff) | |
download | tangerine-wallet-browser-8ab23c713db1f5d45abb0ba433450591b8759809.tar tangerine-wallet-browser-8ab23c713db1f5d45abb0ba433450591b8759809.tar.gz tangerine-wallet-browser-8ab23c713db1f5d45abb0ba433450591b8759809.tar.bz2 tangerine-wallet-browser-8ab23c713db1f5d45abb0ba433450591b8759809.tar.lz tangerine-wallet-browser-8ab23c713db1f5d45abb0ba433450591b8759809.tar.xz tangerine-wallet-browser-8ab23c713db1f5d45abb0ba433450591b8759809.tar.zst tangerine-wallet-browser-8ab23c713db1f5d45abb0ba433450591b8759809.zip |
Merge branch 'master' into transactionControllerRefractorPt3
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/components/pending-tx-test.js | 5 | ||||
-rw-r--r-- | test/unit/keyring-controller-test.js | 7 | ||||
-rw-r--r-- | test/unit/nonce-tracker-test.js | 19 | ||||
-rw-r--r-- | test/unit/pending-balance-test.js | 93 | ||||
-rw-r--r-- | test/unit/tx-controller-test.js | 4 |
5 files changed, 121 insertions, 7 deletions
diff --git a/test/unit/components/pending-tx-test.js b/test/unit/components/pending-tx-test.js index 906564558..20feba2a3 100644 --- a/test/unit/components/pending-tx-test.js +++ b/test/unit/components/pending-tx-test.js @@ -35,10 +35,15 @@ describe('PendingTx', function () { const renderer = ReactTestUtils.createRenderer() const newGasPrice = '0x77359400' + const computedBalances = {} + computedBalances[Object.keys(identities)[0]] = { + ethBalance: '0x00000000000000056bc75e2d63100000', + } const props = { identities, accounts: identities, txData, + computedBalances, sendTransaction: (txMeta, event) => { // Assert changes: const result = ethUtil.addHexPrefix(txMeta.txParams.gasPrice) diff --git a/test/unit/keyring-controller-test.js b/test/unit/keyring-controller-test.js index 2d9a53723..135edf365 100644 --- a/test/unit/keyring-controller-test.js +++ b/test/unit/keyring-controller-test.js @@ -24,15 +24,12 @@ describe('KeyringController', function () { getTxList: () => [], getUnapprovedTxList: () => [], }, - ethStore: { + accountTracker: { addAccount (acct) { accounts.push(ethUtil.addHexPrefix(acct)) }, }, + encryptor: mockEncryptor, }) - // Stub out the browser crypto for a mock encryptor. - // Browser crypto is tested in the integration test suite. - keyringController.encryptor = mockEncryptor - keyringController.createNewVaultAndKeychain(password) .then(function (newState) { newState diff --git a/test/unit/nonce-tracker-test.js b/test/unit/nonce-tracker-test.js index 3312a3bd0..8970cf84d 100644 --- a/test/unit/nonce-tracker-test.js +++ b/test/unit/nonce-tracker-test.js @@ -162,6 +162,25 @@ describe('Nonce Tracker', function () { await nonceLock.releaseLock() }) }) + + describe('Faq issue 67', function () { + beforeEach(function () { + const txGen = new MockTxGen() + const confirmedTxs = txGen.generate({ status: 'confirmed' }, { count: 64 }) + const pendingTxs = txGen.generate({ + status: 'submitted', + }, { count: 10 }) + // 0x40 is 64 in hex: + nonceTracker = generateNonceTrackerWith(pendingTxs, [], '0x40') + }) + + it('should return nonce after network nonce', async function () { + this.timeout(15000) + const nonceLock = await nonceTracker.getNonceLock('0x7d3517b0d011698406d6e0aed8453f0be2697926') + assert.equal(nonceLock.nextNonce, '74', `nonce should be 74 got ${nonceLock.nextNonce}`) + await nonceLock.releaseLock() + }) + }) }) }) diff --git a/test/unit/pending-balance-test.js b/test/unit/pending-balance-test.js new file mode 100644 index 000000000..5048d487b --- /dev/null +++ b/test/unit/pending-balance-test.js @@ -0,0 +1,93 @@ +const assert = require('assert') +const PendingBalanceCalculator = require('../../app/scripts/lib/pending-balance-calculator') +const MockTxGen = require('../lib/mock-tx-gen') +const BN = require('ethereumjs-util').BN +let providerResultStub = {} + +const zeroBn = new BN(0) +const etherBn = new BN(String(1e18)) +const ether = '0x' + etherBn.toString(16) + +describe('PendingBalanceCalculator', function () { + let balanceCalculator + + describe('#calculateMaxCost(tx)', function () { + it('returns a BN for a given tx value', function () { + const txGen = new MockTxGen() + pendingTxs = txGen.generate({ + status: 'submitted', + txParams: { + value: ether, + gasPrice: '0x0', + gas: '0x0', + } + }, { count: 1 }) + + const balanceCalculator = generateBalanceCalcWith([], zeroBn) + const result = balanceCalculator.calculateMaxCost(pendingTxs[0]) + assert.equal(result.toString(), etherBn.toString(), 'computes one ether') + }) + + it('calculates gas costs as well', function () { + const txGen = new MockTxGen() + pendingTxs = txGen.generate({ + status: 'submitted', + txParams: { + value: '0x0', + gasPrice: '0x2', + gas: '0x3', + } + }, { count: 1 }) + + const balanceCalculator = generateBalanceCalcWith([], zeroBn) + const result = balanceCalculator.calculateMaxCost(pendingTxs[0]) + assert.equal(result.toString(), '6', 'computes 6 wei of gas') + }) + }) + + describe('if you have no pending txs and one ether', function () { + + beforeEach(function () { + balanceCalculator = generateBalanceCalcWith([], etherBn) + }) + + it('returns the network balance', async function () { + const result = await balanceCalculator.getBalance() + assert.equal(result, ether, `gave ${result} needed ${ether}`) + }) + }) + + describe('if you have a one ether pending tx and one ether', function () { + beforeEach(function () { + const txGen = new MockTxGen() + pendingTxs = txGen.generate({ + status: 'submitted', + txParams: { + value: ether, + gasPrice: '0x0', + gas: '0x0', + } + }, { count: 1 }) + + balanceCalculator = generateBalanceCalcWith(pendingTxs, etherBn) + }) + + it('returns the subtracted result', async function () { + const result = await balanceCalculator.getBalance() + assert.equal(result, '0x0', `gave ${result} needed '0x0'`) + return true + }) + + }) +}) + +function generateBalanceCalcWith (transactions, providerStub = zeroBn) { + const getPendingTransactions = async () => transactions + const getBalance = async () => providerStub + + return new PendingBalanceCalculator({ + getBalance, + getPendingTransactions, + }) +} + diff --git a/test/unit/tx-controller-test.js b/test/unit/tx-controller-test.js index 47bfe66f8..8d45fb9b5 100644 --- a/test/unit/tx-controller-test.js +++ b/test/unit/tx-controller-test.js @@ -27,7 +27,7 @@ describe('Transaction Controller', function () { networkStore: new ObservableStore(currentNetworkId), txHistoryLimit: 10, blockTracker: { getCurrentBlock: noop, on: noop, once: noop }, - ethStore: { getState: noop }, + accountTracker: { getState: noop }, signTransaction: (ethTx) => new Promise((resolve) => { ethTx.sign(privKey) resolve() @@ -286,4 +286,4 @@ describe('Transaction Controller', function () { }).catch(done) }) }) -})
\ No newline at end of file +}) |