Skip to content

fix: inconsistent volumes on accounts list #855

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions internal/storage/ledger/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ func TestAccountsList(t *testing.T) {
},
}))

err = store.CommitTransaction(ctx, pointer.For(ledger.NewTransaction().
WithPostings(ledger.NewPosting("world", "account:1", "USD", big.NewInt(100))).
WithTimestamp(now).
WithInsertedAt(now)), nil)
require.NoError(t, err)

err = store.CommitTransaction(ctx, pointer.For(ledger.NewTransaction().
WithPostings(ledger.NewPosting("world", "account:1", "USD", big.NewInt(100))).
WithTimestamp(now.Add(4*time.Minute)).
Expand Down Expand Up @@ -112,7 +118,7 @@ func TestAccountsList(t *testing.T) {
require.NoError(t, err)
require.Len(t, accounts.Data, 1)
require.Equal(t, ledger.VolumesByAssets{
"USD": ledger.NewVolumesInt64(200, 50),
"USD": ledger.NewVolumesInt64(300, 50),
}, accounts.Data[0].Volumes)
})

Expand All @@ -129,7 +135,7 @@ func TestAccountsList(t *testing.T) {
require.NoError(t, err)
require.Len(t, accounts.Data, 1)
require.Equal(t, ledger.VolumesByAssets{
"USD": ledger.NewVolumesInt64(100, 0),
"USD": ledger.NewVolumesInt64(200, 0),
}, accounts.Data[0].Volumes)
})

Expand All @@ -145,7 +151,7 @@ func TestAccountsList(t *testing.T) {
require.NoError(t, err)
require.Len(t, accounts.Data, 1)
require.Equal(t, ledger.VolumesByAssets{
"USD": ledger.NewVolumesInt64(200, 50),
"USD": ledger.NewVolumesInt64(300, 50),
}, accounts.Data[0].EffectiveVolumes)
})

Expand All @@ -161,7 +167,7 @@ func TestAccountsList(t *testing.T) {
require.NoError(t, err)
require.Len(t, accounts.Data, 1)
require.Equal(t, ledger.VolumesByAssets{
"USD": ledger.NewVolumesInt64(100, 0),
"USD": ledger.NewVolumesInt64(200, 0),
}, accounts.Data[0].EffectiveVolumes)
})

Expand Down
2 changes: 1 addition & 1 deletion internal/storage/ledger/resource_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (h accountsResourceHandler) expand(store *Store, opts ledgercontroller.Reso
Where("insertion_date <= ?", opts.PIT)
} else {
selectRowsQuery = selectRowsQuery.
ColumnExpr("first_value(post_commit_volumes) over (partition by (accounts_address, asset) order by effective_date desc) as volumes").
ColumnExpr("first_value(post_commit_volumes) over (partition by (accounts_address, asset) order by effective_date desc, seq desc) as volumes").
Where("effective_date <= ?", opts.PIT)
}
} else {
Expand Down
Loading