From fa7b34f90dfe6a1c03ec4e423199b1e93cd5fbec Mon Sep 17 00:00:00 2001 From: Patrick O'Grady Date: Tue, 27 Oct 2020 10:36:38 -0700 Subject: [PATCH] Add test for historical balances --- services/account_service_test.go | 47 +++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/services/account_service_test.go b/services/account_service_test.go index f50076f..ce94fb1 100644 --- a/services/account_service_test.go +++ b/services/account_service_test.go @@ -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) +}