Skip to content

Commit

Permalink
Fix trace pending txns
Browse files Browse the repository at this point in the history
Co-authored-by: IronGauntlets <[email protected]>
  • Loading branch information
wojciechos and IronGauntlets committed Jan 20, 2025
1 parent d3ff578 commit 313c163
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
3 changes: 2 additions & 1 deletion rpc/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/NethermindEth/juno/blockchain"
"github.com/NethermindEth/juno/core"
"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/juno/db"
"github.com/NethermindEth/juno/jsonrpc"
"github.com/NethermindEth/juno/starknet"
"github.com/NethermindEth/juno/sync"
Expand Down Expand Up @@ -141,7 +142,7 @@ func (h *Handler) traceTransaction(ctx context.Context, hash *felt.Felt) (*vm.Tr
httpHeader := http.Header{}
httpHeader.Set(ExecutionStepsHeader, "0")

if err != nil {
if err != nil && !errors.Is(err, db.ErrKeyNotFound) {
return nil, httpHeader, ErrTxnHashNotFound
}

Expand Down
28 changes: 21 additions & 7 deletions rpc/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,28 @@ func TestTraceTransaction(t *testing.T) {
handler := rpc.New(mockReader, mockSyncReader, mockVM, "", utils.NewNopZapLogger())

t.Run("not found", func(t *testing.T) {
hash := utils.HexToFelt(t, "0xBBBB")
// Receipt() returns error related to db
mockReader.EXPECT().Receipt(hash).Return(nil, nil, uint64(0), db.ErrKeyNotFound)
t.Run("key not found", func(t *testing.T) {
hash := utils.HexToFelt(t, "0xBBBB")
// Receipt() returns error related to db
mockReader.EXPECT().Receipt(hash).Return(nil, nil, uint64(0), db.ErrKeyNotFound)
mockSyncReader.EXPECT().Pending().Return(&sync.Pending{Block: &core.Block{}}, nil)

trace, httpHeader, err := handler.TraceTransaction(context.Background(), *hash)
assert.Nil(t, trace)
assert.Equal(t, rpc.ErrTxnHashNotFound, err)
assert.Equal(t, httpHeader.Get(rpc.ExecutionStepsHeader), "0")
})

trace, httpHeader, err := handler.TraceTransaction(context.Background(), *hash)
assert.Nil(t, trace)
assert.Equal(t, rpc.ErrTxnHashNotFound, err)
assert.Equal(t, httpHeader.Get(rpc.ExecutionStepsHeader), "0")
t.Run("other error", func(t *testing.T) {
hash := utils.HexToFelt(t, "0xBBBB")
// Receipt() returns some other error
mockReader.EXPECT().Receipt(hash).Return(nil, nil, uint64(0), errors.New("database error"))

trace, httpHeader, err := handler.TraceTransaction(context.Background(), *hash)
assert.Nil(t, trace)
assert.Equal(t, rpc.ErrTxnHashNotFound, err)
assert.Equal(t, httpHeader.Get(rpc.ExecutionStepsHeader), "0")
})
})
t.Run("ok", func(t *testing.T) {
hash := utils.HexToFelt(t, "0x37b244ea7dc6b3f9735fba02d183ef0d6807a572dd91a63cc1b14b923c1ac0")
Expand Down

0 comments on commit 313c163

Please sign in to comment.