From 699b21942a0682ee320b1a7f9dd194d9976be5ee Mon Sep 17 00:00:00 2001 From: pritsheth Date: Thu, 8 Feb 2024 10:36:20 -0800 Subject: [PATCH] Fix tests and Adress review comments. --- cmd/soroban-rpc/internal/methods/get_transaction.go | 3 ++- cmd/soroban-rpc/internal/methods/get_transaction_test.go | 3 +++ cmd/soroban-rpc/internal/transactions/transactions.go | 8 ++++---- .../internal/transactions/transactions_test.go | 1 + go.sum | 2 -- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/cmd/soroban-rpc/internal/methods/get_transaction.go b/cmd/soroban-rpc/internal/methods/get_transaction.go index 8187d3f0..de58be64 100644 --- a/cmd/soroban-rpc/internal/methods/get_transaction.go +++ b/cmd/soroban-rpc/internal/methods/get_transaction.go @@ -108,11 +108,12 @@ func GetTransaction(getter transactionGetter, request GetTransactionRequest) (Ge response.ResultXdr = base64.StdEncoding.EncodeToString(tx.Result) response.EnvelopeXdr = base64.StdEncoding.EncodeToString(tx.Envelope) response.ResultMetaXdr = base64.StdEncoding.EncodeToString(tx.Meta) + response.DiagnosticEventsXDR = base64EncodeSlice(tx.Events) + if tx.Successful { response.Status = TransactionStatusSuccess } else { response.Status = TransactionStatusFailed - response.DiagnosticEventsXDR = base64EncodeSlice(tx.Events) } return response, nil } diff --git a/cmd/soroban-rpc/internal/methods/get_transaction_test.go b/cmd/soroban-rpc/internal/methods/get_transaction_test.go index 85847f00..dd5f9637 100644 --- a/cmd/soroban-rpc/internal/methods/get_transaction_test.go +++ b/cmd/soroban-rpc/internal/methods/get_transaction_test.go @@ -154,6 +154,7 @@ func TestGetTransaction(t *testing.T) { ResultMetaXdr: expectedTxMeta, Ledger: 101, LedgerCloseTime: 2625, + DiagnosticEventsXDR: []string{}, }, tx) // ingest another (failed) transaction @@ -177,6 +178,7 @@ func TestGetTransaction(t *testing.T) { ResultMetaXdr: expectedTxMeta, Ledger: 101, LedgerCloseTime: 2625, + DiagnosticEventsXDR: []string{}, }, tx) // the new transaction should also be there @@ -206,5 +208,6 @@ func TestGetTransaction(t *testing.T) { ResultMetaXdr: expectedTxMeta, Ledger: 102, LedgerCloseTime: 2650, + DiagnosticEventsXDR: []string{}, }, tx) } diff --git a/cmd/soroban-rpc/internal/transactions/transactions.go b/cmd/soroban-rpc/internal/transactions/transactions.go index 91f4aaad..5a0c31ad 100644 --- a/cmd/soroban-rpc/internal/transactions/transactions.go +++ b/cmd/soroban-rpc/internal/transactions/transactions.go @@ -200,18 +200,18 @@ func (m *MemoryStore) GetTransaction(hash xdr.Hash) (Transaction, bool, StoreRan return Transaction{}, false, storeRange } - var tx_meta xdr.TransactionMeta - err := tx_meta.UnmarshalBinary(internalTx.meta) + var txMeta xdr.TransactionMeta + err := txMeta.UnmarshalBinary(internalTx.meta) if err != nil { return Transaction{}, false, storeRange } - txEvents, err := tx_meta.GetDiagnosticEvents() + txEvents, err := txMeta.GetDiagnosticEvents() if err != nil { return Transaction{}, false, storeRange } - var events [][]byte + var events = make([][]byte, 0, len(txEvents)) for _, e := range txEvents { diagnosticEventXDR, err := e.MarshalBinary() diff --git a/cmd/soroban-rpc/internal/transactions/transactions_test.go b/cmd/soroban-rpc/internal/transactions/transactions_test.go index 888d5329..c07c6105 100644 --- a/cmd/soroban-rpc/internal/transactions/transactions_test.go +++ b/cmd/soroban-rpc/internal/transactions/transactions_test.go @@ -359,6 +359,7 @@ func TestGetTransactionsWithEventData(t *testing.T) { tx, ok, _ := store.GetTransaction(txHash(1, false)) require.True(t, ok) require.NotNil(t, tx.Events) + require.Equal(t, 1, len(tx.Events)) } diff --git a/go.sum b/go.sum index 82213b40..32930a08 100644 --- a/go.sum +++ b/go.sum @@ -366,8 +366,6 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/viper v1.17.0 h1:I5txKw7MJasPL/BrfkbA0Jyo/oELqVmux4pR/UxOMfI= github.com/spf13/viper v1.17.0/go.mod h1:BmMMMLQXSbcHK6KAOiFLz0l5JHrU89OdIRHvsk0+yVI= -github.com/stellar/go v0.0.0-20240202231803-b0df9f046eb4 h1:1DQT7eta18GSv+z6wF7AMUf7NqQ0qOrr2uJPGMRakRg= -github.com/stellar/go v0.0.0-20240202231803-b0df9f046eb4/go.mod h1:Ka4piwZT4Q9799f+BZeaKkAiYo4UpIWXyu0oSUbCVfM= github.com/stellar/go v0.0.0-20240207003209-73de95c8eb55 h1:YBpAp7uPf/lzGxKPOGh1D05bX7uDVybA39BYoPXpRu4= github.com/stellar/go v0.0.0-20240207003209-73de95c8eb55/go.mod h1:Ka4piwZT4Q9799f+BZeaKkAiYo4UpIWXyu0oSUbCVfM= github.com/stellar/go-xdr v0.0.0-20231122183749-b53fb00bcac2 h1:OzCVd0SV5qE3ZcDeSFCmOWLZfEWZ3Oe8KtmSOYKEVWE=