1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-23 03:36:18 +02:00
metamask-extension/test/unit/pending-balance-test.js

39 lines
1.2 KiB
JavaScript
Raw Normal View History

2017-09-06 23:27:21 +02:00
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 () {
2017-09-06 23:36:15 +02:00
const ether = '0x' + (new BN(String(1e18))).toString(16)
2017-09-06 23:27:21 +02:00
beforeEach(function () {
2017-09-06 23:36:15 +02:00
nonceTracker = generateBalaneCalcWith([], ether)
2017-09-06 23:27:21 +02:00
})
2017-09-06 23:36:15 +02:00
it('returns the network balance', async function () {
const result = await nonceTracker.getBalance()
assert.equal(result, ether, `gave ${result} needed ${ether}`)
2017-09-06 23:27:21 +02:00
})
})
})
function generateBalaneCalcWith (transactions, providerStub = '0x0') {
2017-09-06 23:36:15 +02:00
const getPendingTransactions = () => Promise.resolve(transactions)
const getBalance = () => Promise.resolve(providerStub)
2017-09-06 23:27:21 +02:00
providerResultStub.result = providerStub
const provider = {
sendAsync: (_, cb) => { cb(undefined, providerResultStub) },
_blockTracker: {
getCurrentBlock: () => '0x11b568',
},
}
return new PendingBalanceCalculator({
2017-09-06 23:36:15 +02:00
getBalance,
2017-09-06 23:27:21 +02:00
getPendingTransactions,
})
}