Add test for historical balances

This commit is contained in:
Patrick O'Grady 2020-10-27 10:36:38 -07:00
parent a45bfe47c2
commit fa7b34f90d
No known key found for this signature in database
GPG key ID: 8DE11C985C0C8D85

View file

@ -41,7 +41,7 @@ func TestAccountBalance_Offline(t *testing.T) {
mockIndexer.AssertExpectations(t)
}
func TestAccountBalance_Online(t *testing.T) {
func TestAccountBalance_Online_Current(t *testing.T) {
cfg := &configuration.Configuration{
Mode: configuration.Online,
Currency: bitcoin.MainnetCurrency,
@ -104,3 +104,48 @@ func TestAccountBalance_Online(t *testing.T) {
mockIndexer.AssertExpectations(t)
}
func TestAccountBalance_Online_Historical(t *testing.T) {
cfg := &configuration.Configuration{
Mode: configuration.Online,
Currency: bitcoin.MainnetCurrency,
}
mockIndexer := &mocks.Indexer{}
servicer := NewAccountAPIService(cfg, mockIndexer)
ctx := context.Background()
account := &types.AccountIdentifier{
Address: "hello",
}
block := &types.BlockIdentifier{
Index: 1000,
Hash: "block 1000",
}
partialBlock := &types.PartialBlockIdentifier{
Index: &block.Index,
}
amount := &types.Amount{
Value: "25",
Currency: bitcoin.MainnetCurrency,
}
mockIndexer.On(
"GetBalance",
ctx,
account,
bitcoin.MainnetCurrency,
partialBlock,
).Return(amount, block, nil).Once()
bal, err := servicer.AccountBalance(ctx, &types.AccountBalanceRequest{
AccountIdentifier: account,
BlockIdentifier: partialBlock,
})
assert.Nil(t, err)
assert.Equal(t, &types.AccountBalanceResponse{
BlockIdentifier: block,
Balances: []*types.Amount{
amount,
},
}, bal)
mockIndexer.AssertExpectations(t)
}