Skip to content

Commit

Permalink
Pass existing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-ogrady committed Oct 23, 2020
1 parent 8921a7f commit b802ca3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
6 changes: 5 additions & 1 deletion storage/balance_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ var _ BlockWorker = (*BalanceStorage)(nil)
const (
// balanceNamespace is prepended to any stored balance.
balanceNamespace = "balance"

// historicalBalanceNamespace is prepended to any stored
// historical balance.
historicalBalanceNamespace = "hbalance"
)

var (
Expand All @@ -54,7 +58,7 @@ func GetBalanceKey(account *types.AccountIdentifier, currency *types.Currency) [
// GetBalanceKeyHistorical returns a deterministic hash of an types.Account + types.Currency + block index.
func GetBalanceKeyHistorical(account *types.AccountIdentifier, currency *types.Currency, blockIndex int64) []byte {
return []byte(
fmt.Sprintf("%s/%s/%s/%020d", balanceNamespace, types.Hash(account), types.Hash(currency), blockIndex),
fmt.Sprintf("%s/%s/%s/%020d", historicalBalanceNamespace, types.Hash(account), types.Hash(currency), blockIndex),
)
}

Expand Down
18 changes: 13 additions & 5 deletions storage/balance_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,9 +588,12 @@ func TestBalance(t *testing.T) {
assert.NoError(t, err)
assert.NoError(t, txn.Commit(ctx))

retrievedAmount, err := storage.GetBalance(ctx, account, currency, newBlock3)
retrievedAmount, err := storage.GetBalance(ctx, account, largeDeduction.Currency, newBlock3)
assert.NoError(t, err)
assert.Equal(t, result, retrievedAmount)
assert.Equal(t, &types.Amount{
Value: "1200",
Currency: largeDeduction.Currency,
}, retrievedAmount)
})
}

Expand Down Expand Up @@ -708,6 +711,11 @@ func TestBootstrapBalances(t *testing.T) {
Hash: "0",
}

newBlock = &types.BlockIdentifier{
Index: 1,
Hash: "1",
}

account = &types.AccountIdentifier{
Address: "hello",
}
Expand Down Expand Up @@ -785,10 +793,10 @@ func TestBootstrapBalances(t *testing.T) {
&parser.BalanceChange{
Account: account,
Currency: amount.Currency,
Block: genesisBlockIdentifier,
Block: newBlock,
Difference: "100",
},
genesisBlockIdentifier,
newBlock,
)
assert.NoError(t, err)
assert.NoError(t, txn.Commit(ctx))
Expand All @@ -797,7 +805,7 @@ func TestBootstrapBalances(t *testing.T) {
ctx,
account,
amount.Currency,
genesisBlockIdentifier,
newBlock,
)

assert.Equal(t, "110", retrievedAmount.Value)
Expand Down

0 comments on commit b802ca3

Please sign in to comment.