From 953e1cbbb9a890d21ac65dd2fa16bbc5f60dbb04 Mon Sep 17 00:00:00 2001 From: Tan Quach Date: Fri, 10 Nov 2023 12:40:34 +0000 Subject: [PATCH] fix: list ledger entries api fails when paginating Signed-off-by: Elias Van Ootegem --- CHANGELOG.md | 1 + datanode/sqlstore/ledger.go | 4 +-- datanode/sqlstore/ledger_test.go | 60 ++++++++++++++++++++++++++++++++ go.mod | 3 +- go.sum | 1 - 5 files changed, 64 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c45f743097c..fca2139d35b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### 🐛 Fixes - [10036](https://github.com/vegaprotocol/vega/issues/10036) - Average entry price no longer flickers after a trade. +- [10041](https://github.com/vegaprotocol/vega/issues/10041) List ledger entries `API` errors when using pagination. ## 0.73.3 diff --git a/datanode/sqlstore/ledger.go b/datanode/sqlstore/ledger.go index bdbe7929a2c..e7e4b54ba73 100644 --- a/datanode/sqlstore/ledger.go +++ b/datanode/sqlstore/ledger.go @@ -46,7 +46,7 @@ import ( ) var aggregateLedgerEntriesOrdering = TableOrdering{ - ColumnOrdering{Name: "ledger_entry_time", Sorting: ASC}, + ColumnOrdering{Name: "vega_time", Sorting: ASC}, } const ( @@ -355,7 +355,7 @@ func (*Ledger) prepareQuery(filter *entities.LedgerEntryFilter, dateRange entiti dynamicQuery := createDynamicQuery(filterQueries, filter.CloseOnAccountFilters) whereQuery := fmt.Sprintf(`SELECT - vega_time, quantity, transfer_type, asset_id, + ledger_entry_time as vega_time, quantity, transfer_type, asset_id, account_from_market_id, account_from_party_id, account_from_account_type, account_to_market_id, account_to_party_id, account_to_account_type, account_from_balance, account_to_balance diff --git a/datanode/sqlstore/ledger_test.go b/datanode/sqlstore/ledger_test.go index d6bdf3bdf7c..3d02ed28714 100644 --- a/datanode/sqlstore/ledger_test.go +++ b/datanode/sqlstore/ledger_test.go @@ -438,6 +438,66 @@ func TestLedger(t *testing.T) { assert.Equal(t, 0, len(*entries)) }) + t.Run("by toAccount filter with cursor", func(t *testing.T) { + // Set filters for FromAccount and AcountTo IDs + filter := &entities.LedgerEntryFilter{ + FromAccountFilter: entities.AccountFilter{}, + ToAccountFilter: entities.AccountFilter{ + AssetID: asset2.ID, + PartyIDs: []entities.PartyID{parties[3].ID}, + }, + } + + first := int32(2) + + cursor, err := entities.NewCursorPagination(&first, nil, nil, nil, false) + require.NoError(t, err) + + entries, _, err := ledgerStore.Query(ctx, + filter, + entities.DateRange{Start: &tStart, End: &tEnd}, + cursor, + ) + + assert.NoError(t, err) + // Output entries for accounts positions: + // 6->7, 6->7, 6->7 + assert.NotNil(t, entries) + assert.Equal(t, 2, len(*entries)) + for _, e := range *entries { + assert.Equal(t, *e.FromAccountType, vega.AccountType_ACCOUNT_TYPE_INSURANCE) + assert.Equal(t, *e.ToAccountType, vega.AccountType_ACCOUNT_TYPE_INSURANCE) + if e.Quantity.Abs().String() == strconv.Itoa(80) { + assert.Equal(t, *e.TransferType, entities.LedgerMovementTypeBondSlashing) + assert.Equal(t, strconv.Itoa(2310), e.FromAccountBalance.Abs().String()) + assert.Equal(t, strconv.Itoa(17000), e.ToAccountBalance.Abs().String()) + } + + if e.Quantity.Abs().String() == strconv.Itoa(9) { + assert.Equal(t, *e.TransferType, entities.LedgerMovementTypeRewardPayout) + assert.Equal(t, strconv.Itoa(2301), e.FromAccountBalance.Abs().String()) + assert.Equal(t, strconv.Itoa(17009), e.ToAccountBalance.Abs().String()) + } + + assert.Equal(t, *e.FromAccountMarketID, markets[3].ID) + assert.Equal(t, *e.ToAccountMarketID, markets[4].ID) + } + + filter.ToAccountFilter.AccountTypes = []vega.AccountType{vega.AccountType_ACCOUNT_TYPE_GENERAL, vega.AccountType_ACCOUNT_TYPE_FEES_LIQUIDITY} + + entries, _, err = ledgerStore.Query(ctx, + filter, + entities.DateRange{Start: &tStart, End: &tEnd}, + entities.CursorPagination{}, + ) + + assert.NoError(t, err) + // Output entries for accounts positions: + // None + assert.NotNil(t, entries) + assert.Equal(t, 0, len(*entries)) + }) + t.Run("by fromAccount+toAccount filters", func(t *testing.T) { t.Run("open", func(t *testing.T) { // Set filters for FromAccount and AcountTo IDs diff --git a/go.mod b/go.mod index 269143e00e2..e6a663c5261 100644 --- a/go.mod +++ b/go.mod @@ -64,7 +64,7 @@ require ( github.com/inhies/go-bytesize v0.0.0-20220417184213-4913239db9cf github.com/ipfs/boxo v0.8.1 github.com/ipfs/go-cid v0.4.1 - github.com/ipfs/go-ipfs-files v0.3.0 + github.com/ipfs/go-libipfs v0.7.0 github.com/ipfs/go-log v1.0.5 github.com/ipfs/interface-go-ipfs-core v0.11.0 github.com/ipfs/kubo v0.20.0 @@ -177,7 +177,6 @@ require ( github.com/ipfs/go-ipld-format v0.4.0 // indirect github.com/ipfs/go-ipld-git v0.1.1 // indirect github.com/ipfs/go-ipld-legacy v0.1.1 // indirect - github.com/ipfs/go-libipfs v0.7.0 // indirect github.com/ipfs/go-log/v2 v2.5.1 // indirect github.com/ipfs/go-metrics-interface v0.0.1 // indirect github.com/ipfs/go-path v0.3.1 // indirect diff --git a/go.sum b/go.sum index d1152e8aa65..f08dd1d4a1d 100644 --- a/go.sum +++ b/go.sum @@ -701,7 +701,6 @@ github.com/ipfs/go-ipfs-ds-help v1.1.0/go.mod h1:YR5+6EaebOhfcqVCyqemItCLthrpVNo github.com/ipfs/go-ipfs-exchange-interface v0.2.0 h1:8lMSJmKogZYNo2jjhUs0izT+dck05pqUw4mWNW9Pw6Y= github.com/ipfs/go-ipfs-exchange-offline v0.3.0 h1:c/Dg8GDPzixGd0MC8Jh6mjOwU57uYokgWRFidfvEkuA= github.com/ipfs/go-ipfs-files v0.3.0 h1:fallckyc5PYjuMEitPNrjRfpwl7YFt69heCOUhsbGxQ= -github.com/ipfs/go-ipfs-files v0.3.0/go.mod h1:xAUtYMwB+iu/dtf6+muHNSFQCJG2dSiStR2P6sn9tIM= github.com/ipfs/go-ipfs-posinfo v0.0.1 h1:Esoxj+1JgSjX0+ylc0hUmJCOv6V2vFoZiETLR6OtpRs= github.com/ipfs/go-ipfs-pq v0.0.3 h1:YpoHVJB+jzK15mr/xsWC574tyDLkezVrDNeaalQBsTE= github.com/ipfs/go-ipfs-pq v0.0.3/go.mod h1:btNw5hsHBpRcSSgZtiNm/SLj5gYIZ18AKtv3kERkRb4=