From 8c676b5e1beaacb4987e3f670e3fb4c94aea8671 Mon Sep 17 00:00:00 2001 From: tamirms Date: Wed, 25 Sep 2024 12:48:10 +0100 Subject: [PATCH] add tests --- .../internal/db2/history/trade_test.go | 9 +- .../internal/db2/history/transaction_test.go | 404 ++++++++++++++---- 2 files changed, 323 insertions(+), 90 deletions(-) diff --git a/services/horizon/internal/db2/history/trade_test.go b/services/horizon/internal/db2/history/trade_test.go index 0fd15647a5..157142e296 100644 --- a/services/horizon/internal/db2/history/trade_test.go +++ b/services/horizon/internal/db2/history/trade_test.go @@ -3,6 +3,7 @@ package history import ( "testing" + "github.com/stellar/go/toid" "github.com/stellar/go/xdr" "github.com/stellar/go/services/horizon/internal/db2" @@ -46,6 +47,8 @@ func TestSelectTrades(t *testing.T) { test.ResetHorizonDB(t, tt.HorizonDB) q := &Q{tt.HorizonSession()} fixtures := TradeScenario(tt, q) + afterTradesSeq := toid.Parse(fixtures.Trades[0].HistoryOperationID).LedgerSequence + 1 + beforeTradesSeq := afterTradesSeq - 2 for _, account := range append([]string{allAccounts}, fixtures.Addresses...) { for _, tradeType := range []string{AllTrades, OrderbookTrades, LiquidityPoolTrades} { @@ -55,7 +58,7 @@ func TestSelectTrades(t *testing.T) { assertTradesAreEqual(tt, expected, rows) - rows, err = q.GetTrades(tt.Ctx, descPQ, 0, account, tradeType) + rows, err = q.GetTrades(tt.Ctx, descPQ, beforeTradesSeq, account, tradeType) tt.Assert.NoError(err) start, end := 0, len(rows)-1 for start < end { @@ -65,6 +68,10 @@ func TestSelectTrades(t *testing.T) { } assertTradesAreEqual(tt, expected, rows) + + rows, err = q.GetTrades(tt.Ctx, descPQ, afterTradesSeq, account, tradeType) + tt.Assert.NoError(err) + tt.Assert.Empty(rows) } } } diff --git a/services/horizon/internal/db2/history/transaction_test.go b/services/horizon/internal/db2/history/transaction_test.go index 2dacccd7c8..1a6497f41a 100644 --- a/services/horizon/internal/db2/history/transaction_test.go +++ b/services/horizon/internal/db2/history/transaction_test.go @@ -957,93 +957,319 @@ func TestTransactionQueryBuilder(t *testing.T) { tt.Assert.NoError(q.Commit()) - txQ := q.Transactions().ForAccount(tt.Ctx, address).Page(db2.PageQuery{Cursor: "8589938689", Order: "asc", Limit: 10}, 0) - tt.Assert.NoError(txQ.Err) - got, _, err := txQ.sql.ToSql() - tt.Assert.NoError(err) - // Transactions for account queries will use - // history_transaction_participants.history_transaction_id in their predicates. - want := "SELECT " + - "ht.id, ht.transaction_hash, ht.ledger_sequence, ht.application_order, " + - "ht.account, ht.account_muxed, ht.account_sequence, ht.max_fee, " + - "COALESCE(ht.fee_charged, ht.max_fee) as fee_charged, ht.operation_count, " + - "ht.tx_envelope, ht.tx_result, ht.tx_meta, ht.tx_fee_meta, ht.created_at, " + - "ht.updated_at, COALESCE(ht.successful, true) as successful, ht.signatures, " + - "ht.memo_type, ht.memo, ht.time_bounds, ht.ledger_bounds, ht.min_account_sequence, " + - "ht.min_account_sequence_age, ht.min_account_sequence_ledger_gap, ht.extra_signers, " + - "hl.closed_at AS ledger_close_time, ht.inner_transaction_hash, ht.fee_account, " + - "ht.fee_account_muxed, ht.new_max_fee, ht.inner_signatures " + - "FROM history_transactions ht " + - "LEFT JOIN history_ledgers hl ON ht.ledger_sequence = hl.sequence " + - "JOIN history_transaction_participants htp ON htp.history_transaction_id = ht.id " + - "WHERE htp.history_account_id = ? AND htp.history_transaction_id > ? " + - "ORDER BY htp.history_transaction_id asc LIMIT 10" - tt.Assert.EqualValues(want, got) - - txQ = q.Transactions().ForClaimableBalance(tt.Ctx, cbID).Page(db2.PageQuery{Cursor: "8589938689", Order: "asc", Limit: 10}, 0) - tt.Assert.NoError(txQ.Err) - got, _, err = txQ.sql.ToSql() - tt.Assert.NoError(err) - // Transactions for claimable balance queries will use - // history_transaction_claimable_balances.history_transaction_id in their predicates. - want = "SELECT " + - "ht.id, ht.transaction_hash, ht.ledger_sequence, ht.application_order, " + - "ht.account, ht.account_muxed, ht.account_sequence, ht.max_fee, " + - "COALESCE(ht.fee_charged, ht.max_fee) as fee_charged, ht.operation_count, " + - "ht.tx_envelope, ht.tx_result, ht.tx_meta, ht.tx_fee_meta, ht.created_at, " + - "ht.updated_at, COALESCE(ht.successful, true) as successful, ht.signatures, " + - "ht.memo_type, ht.memo, ht.time_bounds, ht.ledger_bounds, ht.min_account_sequence, " + - "ht.min_account_sequence_age, ht.min_account_sequence_ledger_gap, ht.extra_signers, " + - "hl.closed_at AS ledger_close_time, ht.inner_transaction_hash, ht.fee_account, " + - "ht.fee_account_muxed, ht.new_max_fee, ht.inner_signatures " + - "FROM history_transactions ht " + - "LEFT JOIN history_ledgers hl ON ht.ledger_sequence = hl.sequence " + - "JOIN history_transaction_claimable_balances htcb ON htcb.history_transaction_id = ht.id " + - "WHERE htcb.history_claimable_balance_id = ? AND htcb.history_transaction_id > ? " + - "ORDER BY htcb.history_transaction_id asc LIMIT 10" - tt.Assert.EqualValues(want, got) - - txQ = q.Transactions().ForLiquidityPool(tt.Ctx, lpID).Page(db2.PageQuery{Cursor: "8589938689", Order: "asc", Limit: 10}, 0) - tt.Assert.NoError(txQ.Err) - got, _, err = txQ.sql.ToSql() - tt.Assert.NoError(err) - // Transactions for liquidity pool queries will use - // history_transaction_liquidity_pools.history_transaction_id in their predicates. - want = "SELECT " + - "ht.id, ht.transaction_hash, ht.ledger_sequence, ht.application_order, " + - "ht.account, ht.account_muxed, ht.account_sequence, ht.max_fee, " + - "COALESCE(ht.fee_charged, ht.max_fee) as fee_charged, ht.operation_count, " + - "ht.tx_envelope, ht.tx_result, ht.tx_meta, ht.tx_fee_meta, ht.created_at, " + - "ht.updated_at, COALESCE(ht.successful, true) as successful, ht.signatures, " + - "ht.memo_type, ht.memo, ht.time_bounds, ht.ledger_bounds, ht.min_account_sequence, " + - "ht.min_account_sequence_age, ht.min_account_sequence_ledger_gap, ht.extra_signers, " + - "hl.closed_at AS ledger_close_time, ht.inner_transaction_hash, ht.fee_account, " + - "ht.fee_account_muxed, ht.new_max_fee, ht.inner_signatures " + - "FROM history_transactions ht " + - "LEFT JOIN history_ledgers hl ON ht.ledger_sequence = hl.sequence " + - "JOIN history_transaction_liquidity_pools htlp ON htlp.history_transaction_id = ht.id " + - "WHERE htlp.history_liquidity_pool_id = ? AND htlp.history_transaction_id > ? " + - "ORDER BY htlp.history_transaction_id asc LIMIT 10" - tt.Assert.EqualValues(want, got) - - txQ = q.Transactions().Page(db2.PageQuery{Cursor: "8589938689", Order: "asc", Limit: 10}, 0) - tt.Assert.NoError(txQ.Err) - got, _, err = txQ.sql.ToSql() - tt.Assert.NoError(err) - // Other Transaction queries will use history_transactions.id in their predicates. - want = "SELECT " + - "ht.id, ht.transaction_hash, ht.ledger_sequence, ht.application_order, " + - "ht.account, ht.account_muxed, ht.account_sequence, ht.max_fee, " + - "COALESCE(ht.fee_charged, ht.max_fee) as fee_charged, ht.operation_count, " + - "ht.tx_envelope, ht.tx_result, ht.tx_meta, ht.tx_fee_meta, ht.created_at, " + - "ht.updated_at, COALESCE(ht.successful, true) as successful, ht.signatures, " + - "ht.memo_type, ht.memo, ht.time_bounds, ht.ledger_bounds, ht.min_account_sequence, " + - "ht.min_account_sequence_age, ht.min_account_sequence_ledger_gap, ht.extra_signers, " + - "hl.closed_at AS ledger_close_time, ht.inner_transaction_hash, ht.fee_account, " + - "ht.fee_account_muxed, ht.new_max_fee, ht.inner_signatures " + - "FROM history_transactions ht " + - "LEFT JOIN history_ledgers hl ON ht.ledger_sequence = hl.sequence " + - "WHERE ht.id > ? " + - "ORDER BY ht.id asc LIMIT 10" - tt.Assert.EqualValues(want, got) + for _, testCase := range []struct { + q *TransactionsQ + expectedSQL string + expectedArgs []interface{} + }{ + { + q.Transactions().ForAccount(tt.Ctx, address).Page(db2.PageQuery{Cursor: "8589938689", Order: "asc", Limit: 10}, 0), + "SELECT " + + "ht.id, ht.transaction_hash, ht.ledger_sequence, ht.application_order, " + + "ht.account, ht.account_muxed, ht.account_sequence, ht.max_fee, " + + "COALESCE(ht.fee_charged, ht.max_fee) as fee_charged, ht.operation_count, " + + "ht.tx_envelope, ht.tx_result, ht.tx_meta, ht.tx_fee_meta, ht.created_at, " + + "ht.updated_at, COALESCE(ht.successful, true) as successful, ht.signatures, " + + "ht.memo_type, ht.memo, ht.time_bounds, ht.ledger_bounds, ht.min_account_sequence, " + + "ht.min_account_sequence_age, ht.min_account_sequence_ledger_gap, ht.extra_signers, " + + "hl.closed_at AS ledger_close_time, ht.inner_transaction_hash, ht.fee_account, " + + "ht.fee_account_muxed, ht.new_max_fee, ht.inner_signatures " + + "FROM history_transactions ht " + + "LEFT JOIN history_ledgers hl ON ht.ledger_sequence = hl.sequence " + + "JOIN history_transaction_participants htp ON htp.history_transaction_id = ht.id " + + "WHERE htp.history_account_id = ? AND htp.history_transaction_id > ? " + + "ORDER BY htp.history_transaction_id asc LIMIT 10", + []interface{}{int64(1), int64(8589938689)}, + }, + { + q.Transactions().ForClaimableBalance(tt.Ctx, cbID).Page(db2.PageQuery{Cursor: "8589938689", Order: "asc", Limit: 10}, 0), + "SELECT " + + "ht.id, ht.transaction_hash, ht.ledger_sequence, ht.application_order, " + + "ht.account, ht.account_muxed, ht.account_sequence, ht.max_fee, " + + "COALESCE(ht.fee_charged, ht.max_fee) as fee_charged, ht.operation_count, " + + "ht.tx_envelope, ht.tx_result, ht.tx_meta, ht.tx_fee_meta, ht.created_at, " + + "ht.updated_at, COALESCE(ht.successful, true) as successful, ht.signatures, " + + "ht.memo_type, ht.memo, ht.time_bounds, ht.ledger_bounds, ht.min_account_sequence, " + + "ht.min_account_sequence_age, ht.min_account_sequence_ledger_gap, ht.extra_signers, " + + "hl.closed_at AS ledger_close_time, ht.inner_transaction_hash, ht.fee_account, " + + "ht.fee_account_muxed, ht.new_max_fee, ht.inner_signatures " + + "FROM history_transactions ht " + + "LEFT JOIN history_ledgers hl ON ht.ledger_sequence = hl.sequence " + + "JOIN history_transaction_claimable_balances htcb ON htcb.history_transaction_id = ht.id " + + "WHERE htcb.history_claimable_balance_id = ? AND htcb.history_transaction_id > ? " + + "ORDER BY htcb.history_transaction_id asc LIMIT 10", + []interface{}{int64(1), int64(8589938689)}, + }, + { + q.Transactions().ForLiquidityPool(tt.Ctx, lpID).Page(db2.PageQuery{Cursor: "8589938689", Order: "asc", Limit: 10}, 0), + "SELECT " + + "ht.id, ht.transaction_hash, ht.ledger_sequence, ht.application_order, " + + "ht.account, ht.account_muxed, ht.account_sequence, ht.max_fee, " + + "COALESCE(ht.fee_charged, ht.max_fee) as fee_charged, ht.operation_count, " + + "ht.tx_envelope, ht.tx_result, ht.tx_meta, ht.tx_fee_meta, ht.created_at, " + + "ht.updated_at, COALESCE(ht.successful, true) as successful, ht.signatures, " + + "ht.memo_type, ht.memo, ht.time_bounds, ht.ledger_bounds, ht.min_account_sequence, " + + "ht.min_account_sequence_age, ht.min_account_sequence_ledger_gap, ht.extra_signers, " + + "hl.closed_at AS ledger_close_time, ht.inner_transaction_hash, ht.fee_account, " + + "ht.fee_account_muxed, ht.new_max_fee, ht.inner_signatures " + + "FROM history_transactions ht " + + "LEFT JOIN history_ledgers hl ON ht.ledger_sequence = hl.sequence " + + "JOIN history_transaction_liquidity_pools htlp ON htlp.history_transaction_id = ht.id " + + "WHERE htlp.history_liquidity_pool_id = ? AND htlp.history_transaction_id > ? " + + "ORDER BY htlp.history_transaction_id asc LIMIT 10", + []interface{}{int64(1), int64(8589938689)}, + }, + { + q.Transactions().Page(db2.PageQuery{Cursor: "8589938689", Order: "asc", Limit: 10}, 0), + "SELECT " + + "ht.id, ht.transaction_hash, ht.ledger_sequence, ht.application_order, " + + "ht.account, ht.account_muxed, ht.account_sequence, ht.max_fee, " + + "COALESCE(ht.fee_charged, ht.max_fee) as fee_charged, ht.operation_count, " + + "ht.tx_envelope, ht.tx_result, ht.tx_meta, ht.tx_fee_meta, ht.created_at, " + + "ht.updated_at, COALESCE(ht.successful, true) as successful, ht.signatures, " + + "ht.memo_type, ht.memo, ht.time_bounds, ht.ledger_bounds, ht.min_account_sequence, " + + "ht.min_account_sequence_age, ht.min_account_sequence_ledger_gap, ht.extra_signers, " + + "hl.closed_at AS ledger_close_time, ht.inner_transaction_hash, ht.fee_account, " + + "ht.fee_account_muxed, ht.new_max_fee, ht.inner_signatures " + + "FROM history_transactions ht " + + "LEFT JOIN history_ledgers hl ON ht.ledger_sequence = hl.sequence " + + "WHERE ht.id > ? " + + "ORDER BY ht.id asc LIMIT 10", + []interface{}{int64(8589938689)}, + }, + { + q.Transactions().ForAccount(tt.Ctx, address).Page(db2.PageQuery{Cursor: "8589938689", Order: "asc", Limit: 10}, 100), + "SELECT " + + "ht.id, ht.transaction_hash, ht.ledger_sequence, ht.application_order, " + + "ht.account, ht.account_muxed, ht.account_sequence, ht.max_fee, " + + "COALESCE(ht.fee_charged, ht.max_fee) as fee_charged, ht.operation_count, " + + "ht.tx_envelope, ht.tx_result, ht.tx_meta, ht.tx_fee_meta, ht.created_at, " + + "ht.updated_at, COALESCE(ht.successful, true) as successful, ht.signatures, " + + "ht.memo_type, ht.memo, ht.time_bounds, ht.ledger_bounds, ht.min_account_sequence, " + + "ht.min_account_sequence_age, ht.min_account_sequence_ledger_gap, ht.extra_signers, " + + "hl.closed_at AS ledger_close_time, ht.inner_transaction_hash, ht.fee_account, " + + "ht.fee_account_muxed, ht.new_max_fee, ht.inner_signatures " + + "FROM history_transactions ht " + + "LEFT JOIN history_ledgers hl ON ht.ledger_sequence = hl.sequence " + + "JOIN history_transaction_participants htp ON htp.history_transaction_id = ht.id " + + "WHERE htp.history_account_id = ? AND htp.history_transaction_id > ? " + + "ORDER BY htp.history_transaction_id asc LIMIT 10", + []interface{}{int64(1), int64(8589938689)}, + }, + { + q.Transactions().ForClaimableBalance(tt.Ctx, cbID).Page(db2.PageQuery{Cursor: "8589938689", Order: "asc", Limit: 10}, 100), + "SELECT " + + "ht.id, ht.transaction_hash, ht.ledger_sequence, ht.application_order, " + + "ht.account, ht.account_muxed, ht.account_sequence, ht.max_fee, " + + "COALESCE(ht.fee_charged, ht.max_fee) as fee_charged, ht.operation_count, " + + "ht.tx_envelope, ht.tx_result, ht.tx_meta, ht.tx_fee_meta, ht.created_at, " + + "ht.updated_at, COALESCE(ht.successful, true) as successful, ht.signatures, " + + "ht.memo_type, ht.memo, ht.time_bounds, ht.ledger_bounds, ht.min_account_sequence, " + + "ht.min_account_sequence_age, ht.min_account_sequence_ledger_gap, ht.extra_signers, " + + "hl.closed_at AS ledger_close_time, ht.inner_transaction_hash, ht.fee_account, " + + "ht.fee_account_muxed, ht.new_max_fee, ht.inner_signatures " + + "FROM history_transactions ht " + + "LEFT JOIN history_ledgers hl ON ht.ledger_sequence = hl.sequence " + + "JOIN history_transaction_claimable_balances htcb ON htcb.history_transaction_id = ht.id " + + "WHERE htcb.history_claimable_balance_id = ? AND htcb.history_transaction_id > ? " + + "ORDER BY htcb.history_transaction_id asc LIMIT 10", + []interface{}{int64(1), int64(8589938689)}, + }, + { + q.Transactions().ForLiquidityPool(tt.Ctx, lpID).Page(db2.PageQuery{Cursor: "8589938689", Order: "asc", Limit: 10}, 100), + "SELECT " + + "ht.id, ht.transaction_hash, ht.ledger_sequence, ht.application_order, " + + "ht.account, ht.account_muxed, ht.account_sequence, ht.max_fee, " + + "COALESCE(ht.fee_charged, ht.max_fee) as fee_charged, ht.operation_count, " + + "ht.tx_envelope, ht.tx_result, ht.tx_meta, ht.tx_fee_meta, ht.created_at, " + + "ht.updated_at, COALESCE(ht.successful, true) as successful, ht.signatures, " + + "ht.memo_type, ht.memo, ht.time_bounds, ht.ledger_bounds, ht.min_account_sequence, " + + "ht.min_account_sequence_age, ht.min_account_sequence_ledger_gap, ht.extra_signers, " + + "hl.closed_at AS ledger_close_time, ht.inner_transaction_hash, ht.fee_account, " + + "ht.fee_account_muxed, ht.new_max_fee, ht.inner_signatures " + + "FROM history_transactions ht " + + "LEFT JOIN history_ledgers hl ON ht.ledger_sequence = hl.sequence " + + "JOIN history_transaction_liquidity_pools htlp ON htlp.history_transaction_id = ht.id " + + "WHERE htlp.history_liquidity_pool_id = ? AND htlp.history_transaction_id > ? " + + "ORDER BY htlp.history_transaction_id asc LIMIT 10", + []interface{}{int64(1), int64(8589938689)}, + }, + { + q.Transactions().Page(db2.PageQuery{Cursor: "8589938689", Order: "asc", Limit: 10}, 100), + "SELECT " + + "ht.id, ht.transaction_hash, ht.ledger_sequence, ht.application_order, " + + "ht.account, ht.account_muxed, ht.account_sequence, ht.max_fee, " + + "COALESCE(ht.fee_charged, ht.max_fee) as fee_charged, ht.operation_count, " + + "ht.tx_envelope, ht.tx_result, ht.tx_meta, ht.tx_fee_meta, ht.created_at, " + + "ht.updated_at, COALESCE(ht.successful, true) as successful, ht.signatures, " + + "ht.memo_type, ht.memo, ht.time_bounds, ht.ledger_bounds, ht.min_account_sequence, " + + "ht.min_account_sequence_age, ht.min_account_sequence_ledger_gap, ht.extra_signers, " + + "hl.closed_at AS ledger_close_time, ht.inner_transaction_hash, ht.fee_account, " + + "ht.fee_account_muxed, ht.new_max_fee, ht.inner_signatures " + + "FROM history_transactions ht " + + "LEFT JOIN history_ledgers hl ON ht.ledger_sequence = hl.sequence " + + "WHERE ht.id > ? " + + "ORDER BY ht.id asc LIMIT 10", + []interface{}{int64(8589938689)}, + }, + { + q.Transactions().ForAccount(tt.Ctx, address).Page(db2.PageQuery{Cursor: "8589938689", Order: "desc", Limit: 10}, 0), + "SELECT " + + "ht.id, ht.transaction_hash, ht.ledger_sequence, ht.application_order, " + + "ht.account, ht.account_muxed, ht.account_sequence, ht.max_fee, " + + "COALESCE(ht.fee_charged, ht.max_fee) as fee_charged, ht.operation_count, " + + "ht.tx_envelope, ht.tx_result, ht.tx_meta, ht.tx_fee_meta, ht.created_at, " + + "ht.updated_at, COALESCE(ht.successful, true) as successful, ht.signatures, " + + "ht.memo_type, ht.memo, ht.time_bounds, ht.ledger_bounds, ht.min_account_sequence, " + + "ht.min_account_sequence_age, ht.min_account_sequence_ledger_gap, ht.extra_signers, " + + "hl.closed_at AS ledger_close_time, ht.inner_transaction_hash, ht.fee_account, " + + "ht.fee_account_muxed, ht.new_max_fee, ht.inner_signatures " + + "FROM history_transactions ht " + + "LEFT JOIN history_ledgers hl ON ht.ledger_sequence = hl.sequence " + + "JOIN history_transaction_participants htp ON htp.history_transaction_id = ht.id " + + "WHERE htp.history_account_id = ? AND htp.history_transaction_id < ? " + + "ORDER BY htp.history_transaction_id desc LIMIT 10", + []interface{}{int64(1), int64(8589938689)}, + }, + { + q.Transactions().ForClaimableBalance(tt.Ctx, cbID).Page(db2.PageQuery{Cursor: "8589938689", Order: "desc", Limit: 10}, 0), + "SELECT " + + "ht.id, ht.transaction_hash, ht.ledger_sequence, ht.application_order, " + + "ht.account, ht.account_muxed, ht.account_sequence, ht.max_fee, " + + "COALESCE(ht.fee_charged, ht.max_fee) as fee_charged, ht.operation_count, " + + "ht.tx_envelope, ht.tx_result, ht.tx_meta, ht.tx_fee_meta, ht.created_at, " + + "ht.updated_at, COALESCE(ht.successful, true) as successful, ht.signatures, " + + "ht.memo_type, ht.memo, ht.time_bounds, ht.ledger_bounds, ht.min_account_sequence, " + + "ht.min_account_sequence_age, ht.min_account_sequence_ledger_gap, ht.extra_signers, " + + "hl.closed_at AS ledger_close_time, ht.inner_transaction_hash, ht.fee_account, " + + "ht.fee_account_muxed, ht.new_max_fee, ht.inner_signatures " + + "FROM history_transactions ht " + + "LEFT JOIN history_ledgers hl ON ht.ledger_sequence = hl.sequence " + + "JOIN history_transaction_claimable_balances htcb ON htcb.history_transaction_id = ht.id " + + "WHERE htcb.history_claimable_balance_id = ? AND htcb.history_transaction_id < ? " + + "ORDER BY htcb.history_transaction_id desc LIMIT 10", + []interface{}{int64(1), int64(8589938689)}, + }, + { + q.Transactions().ForLiquidityPool(tt.Ctx, lpID).Page(db2.PageQuery{Cursor: "8589938689", Order: "desc", Limit: 10}, 0), + "SELECT " + + "ht.id, ht.transaction_hash, ht.ledger_sequence, ht.application_order, " + + "ht.account, ht.account_muxed, ht.account_sequence, ht.max_fee, " + + "COALESCE(ht.fee_charged, ht.max_fee) as fee_charged, ht.operation_count, " + + "ht.tx_envelope, ht.tx_result, ht.tx_meta, ht.tx_fee_meta, ht.created_at, " + + "ht.updated_at, COALESCE(ht.successful, true) as successful, ht.signatures, " + + "ht.memo_type, ht.memo, ht.time_bounds, ht.ledger_bounds, ht.min_account_sequence, " + + "ht.min_account_sequence_age, ht.min_account_sequence_ledger_gap, ht.extra_signers, " + + "hl.closed_at AS ledger_close_time, ht.inner_transaction_hash, ht.fee_account, " + + "ht.fee_account_muxed, ht.new_max_fee, ht.inner_signatures " + + "FROM history_transactions ht " + + "LEFT JOIN history_ledgers hl ON ht.ledger_sequence = hl.sequence " + + "JOIN history_transaction_liquidity_pools htlp ON htlp.history_transaction_id = ht.id " + + "WHERE htlp.history_liquidity_pool_id = ? AND htlp.history_transaction_id < ? " + + "ORDER BY htlp.history_transaction_id desc LIMIT 10", + []interface{}{int64(1), int64(8589938689)}, + }, + { + q.Transactions().Page(db2.PageQuery{Cursor: "8589938689", Order: "desc", Limit: 10}, 0), + "SELECT " + + "ht.id, ht.transaction_hash, ht.ledger_sequence, ht.application_order, " + + "ht.account, ht.account_muxed, ht.account_sequence, ht.max_fee, " + + "COALESCE(ht.fee_charged, ht.max_fee) as fee_charged, ht.operation_count, " + + "ht.tx_envelope, ht.tx_result, ht.tx_meta, ht.tx_fee_meta, ht.created_at, " + + "ht.updated_at, COALESCE(ht.successful, true) as successful, ht.signatures, " + + "ht.memo_type, ht.memo, ht.time_bounds, ht.ledger_bounds, ht.min_account_sequence, " + + "ht.min_account_sequence_age, ht.min_account_sequence_ledger_gap, ht.extra_signers, " + + "hl.closed_at AS ledger_close_time, ht.inner_transaction_hash, ht.fee_account, " + + "ht.fee_account_muxed, ht.new_max_fee, ht.inner_signatures " + + "FROM history_transactions ht " + + "LEFT JOIN history_ledgers hl ON ht.ledger_sequence = hl.sequence " + + "WHERE ht.id < ? " + + "ORDER BY ht.id desc LIMIT 10", + []interface{}{int64(8589938689)}, + }, + { + q.Transactions().ForAccount(tt.Ctx, address).Page(db2.PageQuery{Cursor: "8589938689", Order: "desc", Limit: 10}, 100), + "SELECT " + + "ht.id, ht.transaction_hash, ht.ledger_sequence, ht.application_order, " + + "ht.account, ht.account_muxed, ht.account_sequence, ht.max_fee, " + + "COALESCE(ht.fee_charged, ht.max_fee) as fee_charged, ht.operation_count, " + + "ht.tx_envelope, ht.tx_result, ht.tx_meta, ht.tx_fee_meta, ht.created_at, " + + "ht.updated_at, COALESCE(ht.successful, true) as successful, ht.signatures, " + + "ht.memo_type, ht.memo, ht.time_bounds, ht.ledger_bounds, ht.min_account_sequence, " + + "ht.min_account_sequence_age, ht.min_account_sequence_ledger_gap, ht.extra_signers, " + + "hl.closed_at AS ledger_close_time, ht.inner_transaction_hash, ht.fee_account, " + + "ht.fee_account_muxed, ht.new_max_fee, ht.inner_signatures " + + "FROM history_transactions ht " + + "LEFT JOIN history_ledgers hl ON ht.ledger_sequence = hl.sequence " + + "JOIN history_transaction_participants htp ON htp.history_transaction_id = ht.id " + + "WHERE htp.history_account_id = ? AND htp.history_transaction_id > ? " + + "AND htp.history_transaction_id < ? " + + "ORDER BY htp.history_transaction_id desc LIMIT 10", + []interface{}{int64(1), int64(429496729599), int64(8589938689)}, + }, + { + q.Transactions().ForClaimableBalance(tt.Ctx, cbID).Page(db2.PageQuery{Cursor: "8589938689", Order: "desc", Limit: 10}, 100), + "SELECT " + + "ht.id, ht.transaction_hash, ht.ledger_sequence, ht.application_order, " + + "ht.account, ht.account_muxed, ht.account_sequence, ht.max_fee, " + + "COALESCE(ht.fee_charged, ht.max_fee) as fee_charged, ht.operation_count, " + + "ht.tx_envelope, ht.tx_result, ht.tx_meta, ht.tx_fee_meta, ht.created_at, " + + "ht.updated_at, COALESCE(ht.successful, true) as successful, ht.signatures, " + + "ht.memo_type, ht.memo, ht.time_bounds, ht.ledger_bounds, ht.min_account_sequence, " + + "ht.min_account_sequence_age, ht.min_account_sequence_ledger_gap, ht.extra_signers, " + + "hl.closed_at AS ledger_close_time, ht.inner_transaction_hash, ht.fee_account, " + + "ht.fee_account_muxed, ht.new_max_fee, ht.inner_signatures " + + "FROM history_transactions ht " + + "LEFT JOIN history_ledgers hl ON ht.ledger_sequence = hl.sequence " + + "JOIN history_transaction_claimable_balances htcb ON htcb.history_transaction_id = ht.id " + + "WHERE htcb.history_claimable_balance_id = ? AND htcb.history_transaction_id > ? " + + "AND htcb.history_transaction_id < ? " + + "ORDER BY htcb.history_transaction_id desc LIMIT 10", + []interface{}{int64(1), int64(429496729599), int64(8589938689)}, + }, + { + q.Transactions().ForLiquidityPool(tt.Ctx, lpID).Page(db2.PageQuery{Cursor: "8589938689", Order: "desc", Limit: 10}, 100), + "SELECT " + + "ht.id, ht.transaction_hash, ht.ledger_sequence, ht.application_order, " + + "ht.account, ht.account_muxed, ht.account_sequence, ht.max_fee, " + + "COALESCE(ht.fee_charged, ht.max_fee) as fee_charged, ht.operation_count, " + + "ht.tx_envelope, ht.tx_result, ht.tx_meta, ht.tx_fee_meta, ht.created_at, " + + "ht.updated_at, COALESCE(ht.successful, true) as successful, ht.signatures, " + + "ht.memo_type, ht.memo, ht.time_bounds, ht.ledger_bounds, ht.min_account_sequence, " + + "ht.min_account_sequence_age, ht.min_account_sequence_ledger_gap, ht.extra_signers, " + + "hl.closed_at AS ledger_close_time, ht.inner_transaction_hash, ht.fee_account, " + + "ht.fee_account_muxed, ht.new_max_fee, ht.inner_signatures " + + "FROM history_transactions ht " + + "LEFT JOIN history_ledgers hl ON ht.ledger_sequence = hl.sequence " + + "JOIN history_transaction_liquidity_pools htlp ON htlp.history_transaction_id = ht.id " + + "WHERE htlp.history_liquidity_pool_id = ? AND htlp.history_transaction_id > ? " + + "AND htlp.history_transaction_id < ? " + + "ORDER BY htlp.history_transaction_id desc LIMIT 10", + []interface{}{int64(1), int64(429496729599), int64(8589938689)}, + }, + { + q.Transactions().Page(db2.PageQuery{Cursor: "8589938689", Order: "desc", Limit: 10}, 100), + "SELECT " + + "ht.id, ht.transaction_hash, ht.ledger_sequence, ht.application_order, " + + "ht.account, ht.account_muxed, ht.account_sequence, ht.max_fee, " + + "COALESCE(ht.fee_charged, ht.max_fee) as fee_charged, ht.operation_count, " + + "ht.tx_envelope, ht.tx_result, ht.tx_meta, ht.tx_fee_meta, ht.created_at, " + + "ht.updated_at, COALESCE(ht.successful, true) as successful, ht.signatures, " + + "ht.memo_type, ht.memo, ht.time_bounds, ht.ledger_bounds, ht.min_account_sequence, " + + "ht.min_account_sequence_age, ht.min_account_sequence_ledger_gap, ht.extra_signers, " + + "hl.closed_at AS ledger_close_time, ht.inner_transaction_hash, ht.fee_account, " + + "ht.fee_account_muxed, ht.new_max_fee, ht.inner_signatures " + + "FROM history_transactions ht " + + "LEFT JOIN history_ledgers hl ON ht.ledger_sequence = hl.sequence " + + "WHERE ht.id > ? AND ht.id < ? " + + "ORDER BY ht.id desc LIMIT 10", + []interface{}{int64(429496729599), int64(8589938689)}, + }, + } { + tt.Assert.NoError(testCase.q.Err) + got, args, err := testCase.q.sql.ToSql() + tt.Assert.NoError(err) + tt.Assert.Equal(got, testCase.expectedSQL) + tt.Assert.Equal(args, testCase.expectedArgs) + } }