Skip to content

Commit

Permalink
fix: list ledger entries api fails when paginating
Browse files Browse the repository at this point in the history
Signed-off-by: Elias Van Ootegem <[email protected]>
  • Loading branch information
guoguojin authored and EVODelavega committed Nov 10, 2023
1 parent 5f7be8a commit 953e1cb
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions datanode/sqlstore/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import (
)

var aggregateLedgerEntriesOrdering = TableOrdering{
ColumnOrdering{Name: "ledger_entry_time", Sorting: ASC},
ColumnOrdering{Name: "vega_time", Sorting: ASC},
}

const (
Expand Down Expand Up @@ -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
Expand Down
60 changes: 60 additions & 0 deletions datanode/sqlstore/ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 953e1cb

Please sign in to comment.