Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Reuse v6 starknet_getTransactionByHash handler for v7 #2486

Merged
merged 9 commits into from
Mar 6, 2025
5 changes: 5 additions & 0 deletions rpc/v6/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"github.com/NethermindEth/juno/clients/gateway"
"github.com/NethermindEth/juno/core"
"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/juno/db"
"github.com/NethermindEth/juno/jsonrpc"
rpccore "github.com/NethermindEth/juno/rpc/rpccore"
"github.com/NethermindEth/juno/starknet"
Expand Down Expand Up @@ -427,6 +428,10 @@
func (h *Handler) TransactionByHash(hash felt.Felt) (*Transaction, *jsonrpc.Error) {
txn, err := h.bcReader.TransactionByHash(&hash)
if err != nil {
if !errors.Is(err, db.ErrKeyNotFound) {
return nil, rpccore.ErrInternal.CloneWithData(err)
}

Check warning on line 433 in rpc/v6/transaction.go

View check run for this annotation

Codecov / codecov/patch

rpc/v6/transaction.go#L432-L433

Added lines #L432 - L433 were not covered by tests

return nil, rpccore.ErrTxnHashNotFound
}
return AdaptTransaction(txn), nil
Expand Down
2 changes: 1 addition & 1 deletion rpc/v6/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestTransactionByHashNotFound(t *testing.T) {

n := utils.Ptr(utils.Mainnet)
txHash := new(felt.Felt).SetBytes([]byte("random hash"))
mockReader.EXPECT().TransactionByHash(txHash).Return(nil, errors.New("tx not found"))
mockReader.EXPECT().TransactionByHash(txHash).Return(nil, db.ErrKeyNotFound)

handler := rpc.New(mockReader, nil, nil, "", n, nil)

Expand Down
Loading