mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Add first passing balance calc test
This commit is contained in:
parent
714df393b4
commit
f9a052deed
18
app/scripts/lib/pending-balance-calculator.js
Normal file
18
app/scripts/lib/pending-balance-calculator.js
Normal file
@ -0,0 +1,18 @@
|
||||
const BN = require('ethereumjs-util').BN
|
||||
const EthQuery = require('ethjs-query')
|
||||
|
||||
class PendingBalanceCalculator {
|
||||
|
||||
constructor ({ getBalance, getPendingTransactions }) {
|
||||
this.getPendingTransactions = getPendingTransactions
|
||||
this.getBalance = getBalance
|
||||
}
|
||||
|
||||
async getBalance() {
|
||||
const balance = await this.getBalance
|
||||
return balance
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = PendingBalanceCalculator
|
@ -8,21 +8,22 @@ describe('PendingBalanceCalculator', function () {
|
||||
let nonceTracker
|
||||
|
||||
describe('if you have no pending txs and one ether', function () {
|
||||
const ether = '0x' + (new BN(1e18)).toString(16)
|
||||
const ether = '0x' + (new BN(String(1e18))).toString(16)
|
||||
|
||||
beforeEach(function () {
|
||||
nonceTracker = generateNonceTrackerWith([], ether)
|
||||
nonceTracker = generateBalaneCalcWith([], ether)
|
||||
})
|
||||
|
||||
it('returns the network balance', function () {
|
||||
const result = nonceTracker.getBalance()
|
||||
assert.equal(result, ether, 'returns one 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 = () => transactions
|
||||
const getPendingTransactions = () => Promise.resolve(transactions)
|
||||
const getBalance = () => Promise.resolve(providerStub)
|
||||
providerResultStub.result = providerStub
|
||||
const provider = {
|
||||
sendAsync: (_, cb) => { cb(undefined, providerResultStub) },
|
||||
@ -31,7 +32,7 @@ function generateBalaneCalcWith (transactions, providerStub = '0x0') {
|
||||
},
|
||||
}
|
||||
return new PendingBalanceCalculator({
|
||||
provider,
|
||||
getBalance,
|
||||
getPendingTransactions,
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user