Skip to content

Commit

Permalink
add test for getting balances
Browse files Browse the repository at this point in the history
  • Loading branch information
chadlagore committed Aug 12, 2017
1 parent f12ebbc commit 7b02913
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion blockchain/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (w *Wallet) IsPending(txn *Transaction) (bool, int) {
func (w *Wallet) GetEffectiveBalance() uint64 {
r := w.Balance
for _, t := range w.PendingTxns {
r -= t.Outputs[0].Amount
r -= t.GetTotalOutput()
}
return r
}
Expand Down
10 changes: 10 additions & 0 deletions blockchain/wallet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,13 @@ func TestDropAllPending(t *testing.T) {
result, _ = w.IsPending(txn)
assert.False(t, result)
}

func TestGetWalletBalances(t *testing.T) {
w := NewWallet()
txn := NewTestTransaction()
w.SetBalance(txn.GetTotalOutput())
w.SetAllPending([]*Transaction{txn})

assert.Equal(t, w.GetBalance(), txn.GetTotalOutput())
assert.Equal(t, w.GetEffectiveBalance(), uint64(0))
}

0 comments on commit 7b02913

Please sign in to comment.