Skip to content
Open
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
18 changes: 12 additions & 6 deletions internal/data/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,10 @@ func TestAccountModelBatchGetByToIDs(t *testing.T) {
types.AddressBytea(address1), types.AddressBytea(address2))
require.NoError(t, err)

// Insert test transactions first
_, err = m.DB.ExecContext(ctx, "INSERT INTO transactions (hash, to_id, envelope_xdr, fee_charged, result_code, meta_xdr, ledger_number, ledger_created_at) VALUES ('tx1', $1, 'env1', 100, 'TransactionResultCodeTxSuccess', 'meta1', 1, NOW()), ('tx2', $2, 'env2', 200, 'TransactionResultCodeTxSuccess', 'meta2', 2, NOW())", toID1, toID2)
// Insert test transactions first (hash is BYTEA, using valid 64-char hex strings)
testHash1 := types.HashBytea("0000000000000000000000000000000000000000000000000000000000000001")
testHash2 := types.HashBytea("0000000000000000000000000000000000000000000000000000000000000002")
_, err = m.DB.ExecContext(ctx, "INSERT INTO transactions (hash, to_id, envelope_xdr, fee_charged, result_code, meta_xdr, ledger_number, ledger_created_at) VALUES ($1, $2, 'env1', 100, 'TransactionResultCodeTxSuccess', 'meta1', 1, NOW()), ($3, $4, 'env2', 200, 'TransactionResultCodeTxSuccess', 'meta2', 2, NOW())", testHash1, toID1, testHash2, toID2)
require.NoError(t, err)

// Insert test transactions_accounts links
Expand Down Expand Up @@ -318,8 +320,10 @@ func TestAccountModelBatchGetByOperationIDs(t *testing.T) {
types.AddressBytea(address1), types.AddressBytea(address2))
require.NoError(t, err)

// Insert test transactions first
_, err = m.DB.ExecContext(ctx, "INSERT INTO transactions (hash, to_id, envelope_xdr, fee_charged, result_code, meta_xdr, ledger_number, ledger_created_at) VALUES ('tx1', 4096, 'env1', 100, 'TransactionResultCodeTxSuccess', 'meta1', 1, NOW()), ('tx2', 8192, 'env2', 200, 'TransactionResultCodeTxSuccess', 'meta2', 2, NOW())")
// Insert test transactions first (hash is BYTEA, using valid 64-char hex strings)
testHash1 := types.HashBytea("0000000000000000000000000000000000000000000000000000000000000001")
testHash2 := types.HashBytea("0000000000000000000000000000000000000000000000000000000000000002")
_, err = m.DB.ExecContext(ctx, "INSERT INTO transactions (hash, to_id, envelope_xdr, fee_charged, result_code, meta_xdr, ledger_number, ledger_created_at) VALUES ($1, 4096, 'env1', 100, 'TransactionResultCodeTxSuccess', 'meta1', 1, NOW()), ($2, 8192, 'env2', 200, 'TransactionResultCodeTxSuccess', 'meta2', 2, NOW())", testHash1, testHash2)
require.NoError(t, err)

// Insert test operations (IDs don't need to be in TOID range here since we're just testing operations_accounts links)
Expand Down Expand Up @@ -411,8 +415,10 @@ func TestAccountModelBatchGetByStateChangeIDs(t *testing.T) {
types.AddressBytea(address1), types.AddressBytea(address2))
require.NoError(t, err)

// Insert test transactions first
_, err = m.DB.ExecContext(ctx, "INSERT INTO transactions (hash, to_id, envelope_xdr, fee_charged, result_code, meta_xdr, ledger_number, ledger_created_at) VALUES ('tx1', 4096, 'env1', 100, 'TransactionResultCodeTxSuccess', 'meta1', 1, NOW()), ('tx2', 8192, 'env2', 200, 'TransactionResultCodeTxSuccess', 'meta2', 2, NOW())")
// Insert test transactions first (hash is BYTEA, using valid 64-char hex strings)
testHash1 := types.HashBytea("0000000000000000000000000000000000000000000000000000000000000001")
testHash2 := types.HashBytea("0000000000000000000000000000000000000000000000000000000000000002")
_, err = m.DB.ExecContext(ctx, "INSERT INTO transactions (hash, to_id, envelope_xdr, fee_charged, result_code, meta_xdr, ledger_number, ledger_created_at) VALUES ($1, 4096, 'env1', 100, 'TransactionResultCodeTxSuccess', 'meta1', 1, NOW()), ($2, 8192, 'env2', 200, 'TransactionResultCodeTxSuccess', 'meta2', 2, NOW())", testHash1, testHash2)
require.NoError(t, err)

// Insert test operations (IDs must be in TOID range for each transaction)
Expand Down
78 changes: 47 additions & 31 deletions internal/data/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func Test_OperationModel_BatchInsert(t *testing.T) {
meta1, meta2 := "meta1", "meta2"
envelope1, envelope2 := "envelope1", "envelope2"
tx1 := types.Transaction{
Hash: "tx1",
Hash: "d176b7b0133690fbfb2de8fa9ca2273cb4f2e29447e0cf0e14a5f82d0daa4877",
ToID: 4096,
EnvelopeXDR: &envelope1,
FeeCharged: 100,
Expand All @@ -76,7 +76,7 @@ func Test_OperationModel_BatchInsert(t *testing.T) {
IsFeeBump: false,
}
tx2 := types.Transaction{
Hash: "tx2",
Hash: "e176b7b0133690fbfb2de8fa9ca2273cb4f2e29447e0cf0e14a5f82d0daa4877",
ToID: 8192,
EnvelopeXDR: &envelope2,
FeeCharged: 200,
Expand Down Expand Up @@ -252,7 +252,7 @@ func Test_OperationModel_BatchCopy(t *testing.T) {
meta1, meta2 := "meta1", "meta2"
envelope1, envelope2 := "envelope1", "envelope2"
tx1 := types.Transaction{
Hash: "tx1",
Hash: "d176b7b0133690fbfb2de8fa9ca2273cb4f2e29447e0cf0e14a5f82d0daa4877",
ToID: 4096,
EnvelopeXDR: &envelope1,
FeeCharged: 100,
Expand All @@ -263,7 +263,7 @@ func Test_OperationModel_BatchCopy(t *testing.T) {
IsFeeBump: false,
}
tx2 := types.Transaction{
Hash: "tx2",
Hash: "e176b7b0133690fbfb2de8fa9ca2273cb4f2e29447e0cf0e14a5f82d0daa4877",
ToID: 8192,
EnvelopeXDR: &envelope2,
FeeCharged: 200,
Expand Down Expand Up @@ -502,14 +502,17 @@ func TestOperationModel_GetAll(t *testing.T) {
ctx := context.Background()
now := time.Now()

// Create test transactions first
// Create test transactions first (hash is BYTEA, using valid 64-char hex strings)
testHash1 := types.HashBytea("0000000000000000000000000000000000000000000000000000000000000001")
testHash2 := types.HashBytea("0000000000000000000000000000000000000000000000000000000000000002")
testHash3 := types.HashBytea("0000000000000000000000000000000000000000000000000000000000000003")
_, err = dbConnectionPool.ExecContext(ctx, `
INSERT INTO transactions (hash, to_id, envelope_xdr, fee_charged, result_code, meta_xdr, ledger_number, ledger_created_at, is_fee_bump)
VALUES
('tx1', 1, 'env1', 100, 'TransactionResultCodeTxSuccess', 'meta1', 1, $1, false),
('tx2', 2, 'env2', 200, 'TransactionResultCodeTxSuccess', 'meta2', 2, $1, true),
('tx3', 3, 'env3', 300, 'TransactionResultCodeTxSuccess', 'meta3', 3, $1, false)
`, now)
($2, 1, 'env1', 100, 'TransactionResultCodeTxSuccess', 'meta1', 1, $1, false),
($3, 2, 'env2', 200, 'TransactionResultCodeTxSuccess', 'meta2', 2, $1, true),
($4, 3, 'env3', 300, 'TransactionResultCodeTxSuccess', 'meta3', 3, $1, false)
`, now, testHash1, testHash2, testHash3)
require.NoError(t, err)

// Create test operations (IDs must be in TOID range for each transaction: (to_id, to_id + 4096))
Expand Down Expand Up @@ -552,13 +555,16 @@ func TestOperationModel_BatchGetByToIDs(t *testing.T) {
// Create test transactions first with specific ToIDs
// ToID encoding: operations for a tx with to_id are in range (to_id, to_id + 4096)
// Using to_id values: 4096, 8192, 12288 (multiples of 4096 for clarity)
testHash1 := types.HashBytea("0000000000000000000000000000000000000000000000000000000000000001")
testHash2 := types.HashBytea("0000000000000000000000000000000000000000000000000000000000000002")
testHash3 := types.HashBytea("0000000000000000000000000000000000000000000000000000000000000003")
_, err = dbConnectionPool.ExecContext(ctx, `
INSERT INTO transactions (hash, to_id, envelope_xdr, fee_charged, result_code, meta_xdr, ledger_number, ledger_created_at, is_fee_bump)
VALUES
('tx1', 4096, 'env1', 100, 'TransactionResultCodeTxSuccess', 'meta1', 1, $1, false),
('tx2', 8192, 'env2', 200, 'TransactionResultCodeTxSuccess', 'meta2', 2, $1, true),
('tx3', 12288, 'env3', 300, 'TransactionResultCodeTxSuccess', 'meta3', 3, $1, false)
`, now)
($2, 4096, 'env1', 100, 'TransactionResultCodeTxSuccess', 'meta1', 1, $1, false),
($3, 8192, 'env2', 200, 'TransactionResultCodeTxSuccess', 'meta2', 2, $1, true),
($4, 12288, 'env3', 300, 'TransactionResultCodeTxSuccess', 'meta3', 3, $1, false)
`, now, testHash1, testHash2, testHash3)
require.NoError(t, err)

// Create test operations - IDs must be in TOID range for each transaction
Expand Down Expand Up @@ -742,13 +748,15 @@ func TestOperationModel_BatchGetByToID(t *testing.T) {
ctx := context.Background()
now := time.Now()

// Create test transactions first with specific ToIDs
// Create test transactions first with specific ToIDs (hash is BYTEA)
testHash1 := types.HashBytea("0000000000000000000000000000000000000000000000000000000000000001")
testHash2 := types.HashBytea("0000000000000000000000000000000000000000000000000000000000000002")
_, err = dbConnectionPool.ExecContext(ctx, `
INSERT INTO transactions (hash, to_id, envelope_xdr, fee_charged, result_code, meta_xdr, ledger_number, ledger_created_at, is_fee_bump)
VALUES
('tx1', 4096, 'env1', 100, 'TransactionResultCodeTxSuccess', 'meta1', 1, $1, false),
('tx2', 8192, 'env2', 200, 'TransactionResultCodeTxSuccess', 'meta2', 2, $1, true)
`, now)
($2, 4096, 'env1', 100, 'TransactionResultCodeTxSuccess', 'meta1', 1, $1, false),
($3, 8192, 'env2', 200, 'TransactionResultCodeTxSuccess', 'meta2', 2, $1, true)
`, now, testHash1, testHash2)
require.NoError(t, err)

// Create test operations - IDs must be in TOID range for each transaction
Expand Down Expand Up @@ -797,14 +805,17 @@ func TestOperationModel_BatchGetByAccountAddresses(t *testing.T) {
_, err = dbConnectionPool.ExecContext(ctx, "INSERT INTO accounts (stellar_address) VALUES ($1), ($2)", address1, address2)
require.NoError(t, err)

// Create test transactions first
// Create test transactions first (hash is BYTEA)
testHash1 := types.HashBytea("0000000000000000000000000000000000000000000000000000000000000001")
testHash2 := types.HashBytea("0000000000000000000000000000000000000000000000000000000000000002")
testHash3 := types.HashBytea("0000000000000000000000000000000000000000000000000000000000000003")
_, err = dbConnectionPool.ExecContext(ctx, `
INSERT INTO transactions (hash, to_id, envelope_xdr, fee_charged, result_code, meta_xdr, ledger_number, ledger_created_at, is_fee_bump)
VALUES
('tx1', 4096, 'env1', 100, 'TransactionResultCodeTxSuccess', 'meta1', 1, $1, false),
('tx2', 8192, 'env2', 200, 'TransactionResultCodeTxSuccess', 'meta2', 2, $1, true),
('tx3', 12288, 'env3', 300, 'TransactionResultCodeTxSuccess', 'meta3', 3, $1, false)
`, now)
($2, 4096, 'env1', 100, 'TransactionResultCodeTxSuccess', 'meta1', 1, $1, false),
($3, 8192, 'env2', 200, 'TransactionResultCodeTxSuccess', 'meta2', 2, $1, true),
($4, 12288, 'env3', 300, 'TransactionResultCodeTxSuccess', 'meta3', 3, $1, false)
`, now, testHash1, testHash2, testHash3)
require.NoError(t, err)

// Create test operations (IDs must be in TOID range for each transaction)
Expand Down Expand Up @@ -845,13 +856,15 @@ func TestOperationModel_GetByID(t *testing.T) {
ctx := context.Background()
now := time.Now()

// Create test transactions first
// Create test transactions first (hash is BYTEA)
testHash1 := types.HashBytea("0000000000000000000000000000000000000000000000000000000000000001")
testHash2 := types.HashBytea("0000000000000000000000000000000000000000000000000000000000000002")
_, err = dbConnectionPool.ExecContext(ctx, `
INSERT INTO transactions (hash, to_id, envelope_xdr, fee_charged, result_code, meta_xdr, ledger_number, ledger_created_at, is_fee_bump)
VALUES
('tx1', 4096, 'env1', 100, 'TransactionResultCodeTxSuccess', 'meta1', 1, $1, false),
('tx2', 8192, 'env2', 200, 'TransactionResultCodeTxSuccess', 'meta2', 2, $1, true)
`, now)
($2, 4096, 'env1', 100, 'TransactionResultCodeTxSuccess', 'meta1', 1, $1, false),
($3, 8192, 'env2', 200, 'TransactionResultCodeTxSuccess', 'meta2', 2, $1, true)
`, now, testHash1, testHash2)
require.NoError(t, err)

// Create test operations (IDs must be in TOID range for each transaction)
Expand Down Expand Up @@ -907,14 +920,17 @@ func TestOperationModel_BatchGetByStateChangeIDs(t *testing.T) {
_, err = dbConnectionPool.ExecContext(ctx, "INSERT INTO accounts (stellar_address) VALUES ($1)", address)
require.NoError(t, err)

// Create test transactions first
// Create test transactions first (hash is BYTEA)
testHash1 := types.HashBytea("0000000000000000000000000000000000000000000000000000000000000001")
testHash2 := types.HashBytea("0000000000000000000000000000000000000000000000000000000000000002")
testHash3 := types.HashBytea("0000000000000000000000000000000000000000000000000000000000000003")
_, err = dbConnectionPool.ExecContext(ctx, `
INSERT INTO transactions (hash, to_id, envelope_xdr, fee_charged, result_code, meta_xdr, ledger_number, ledger_created_at, is_fee_bump)
VALUES
('tx1', 4096, 'env1', 100, 'TransactionResultCodeTxSuccess', 'meta1', 1, $1, false),
('tx2', 8192, 'env2', 200, 'TransactionResultCodeTxSuccess', 'meta2', 2, $1, true),
('tx3', 12288, 'env3', 300, 'TransactionResultCodeTxSuccess', 'meta3', 3, $1, false)
`, now)
($2, 4096, 'env1', 100, 'TransactionResultCodeTxSuccess', 'meta1', 1, $1, false),
($3, 8192, 'env2', 200, 'TransactionResultCodeTxSuccess', 'meta2', 2, $1, true),
($4, 12288, 'env3', 300, 'TransactionResultCodeTxSuccess', 'meta3', 3, $1, false)
`, now, testHash1, testHash2, testHash3)
require.NoError(t, err)

// Create test operations (IDs must be in TOID range for each transaction)
Expand Down
2 changes: 1 addition & 1 deletion internal/data/statechanges.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (m *StateChangeModel) BatchGetByAccountAddress(ctx context.Context, account
// Add transaction hash filter if provided (uses subquery to find to_id by hash)
if txHash != nil {
queryBuilder.WriteString(fmt.Sprintf(" AND to_id = (SELECT to_id FROM transactions WHERE hash = $%d)", argIndex))
args = append(args, *txHash)
args = append(args, types.HashBytea(*txHash))
argIndex++
}

Expand Down
Loading
Loading