aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit/pending-balance-test.js
blob: dcf1926f01623e1aa53bb776b07b04fd5ee5a5f9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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 = {}

describe('PendingBalanceCalculator', function () {
  let nonceTracker

  describe('if you have no pending txs and one ether', function () {
    const ether = '0x' + (new BN(String(1e18))).toString(16)

    beforeEach(function () {
      nonceTracker = generateBalaneCalcWith([], ether)
    })

    it('returns the network balance', async function () {
      const result = await nonceTracker.getBalance()
      assert.equal(result, ether, `gave ${result} needed ${ether}`)
    })
  })
})

function generateBalaneCalcWith (transactions, providerStub = '0x0') {
  const getPendingTransactions = () => Promise.resolve(transactions)
  const getBalance = () => Promise.resolve(providerStub)
  providerResultStub.result = providerStub
  const provider = {
    sendAsync: (_, cb) => { cb(undefined, providerResultStub) },
    _blockTracker: {
      getCurrentBlock: () => '0x11b568',
    },
  }
  return new PendingBalanceCalculator({
    getBalance,
    getPendingTransactions,
  })
}