diff --git a/rpc/events_test.go b/rpc/events_test.go index 4f942d0cd..85a7d96f7 100644 --- a/rpc/events_test.go +++ b/rpc/events_test.go @@ -262,12 +262,6 @@ func TestSubscribeNewHeads(t *testing.T) { handler, syncer, server := setupSubscriptionTest(t, ctx) - require.NoError(t, server.RegisterMethods(jsonrpc.Method{ - Name: "starknet_subscribeNewHeads", - Params: []jsonrpc.Parameter{{Name: "block", Optional: true}}, - Handler: handler.SubscribeNewHeads, - })) - ws := jsonrpc.NewWebsocket(server, utils.NewNopZapLogger()) httpSrv := httptest.NewServer(ws) @@ -299,16 +293,6 @@ func TestMultipleSubscribeNewHeadsAndUnsubscribe(t *testing.T) { handler, syncer, server := setupSubscriptionTest(t, ctx) - require.NoError(t, server.RegisterMethods(jsonrpc.Method{ - Name: "starknet_subscribeNewHeads", - Params: []jsonrpc.Parameter{{Name: "block", Optional: true}}, - Handler: handler.SubscribeNewHeads, - }, jsonrpc.Method{ - Name: "juno_unsubscribe", - Params: []jsonrpc.Parameter{{Name: "id"}}, - Handler: handler.Unsubscribe, - })) - ws := jsonrpc.NewWebsocket(server, utils.NewNopZapLogger()) httpSrv := httptest.NewServer(ws) @@ -382,12 +366,8 @@ func TestSubscribeNewHeadsHistorical(t *testing.T) { time.Sleep(50 * time.Millisecond) server := jsonrpc.NewServer(1, log) - - require.NoError(t, server.RegisterMethods(jsonrpc.Method{ - Name: "starknet_subscribeNewHeads", - Params: []jsonrpc.Parameter{{Name: "block", Optional: true}}, - Handler: handler.SubscribeNewHeads, - })) + methods, _ := handler.Methods() + require.NoError(t, server.RegisterMethods(methods...)) ws := jsonrpc.NewWebsocket(server, log) httpSrv := httptest.NewServer(ws) @@ -429,12 +409,6 @@ func TestSubscriptionReorg(t *testing.T) { handler, syncer, server := setupSubscriptionTest(t, ctx) - require.NoError(t, server.RegisterMethods(jsonrpc.Method{ - Name: "starknet_subscribeNewHeads", - Params: []jsonrpc.Parameter{{Name: "block", Optional: true}}, - Handler: handler.SubscribeNewHeads, - })) - ws := jsonrpc.NewWebsocket(server, utils.NewNopZapLogger()) httpSrv := httptest.NewServer(ws) @@ -472,12 +446,6 @@ func TestSubscribePendingTxs(t *testing.T) { handler, syncer, server := setupSubscriptionTest(t, ctx) - require.NoError(t, server.RegisterMethods(jsonrpc.Method{ - Name: "starknet_subscribePendingTransactions", - Params: []jsonrpc.Parameter{{Name: "transaction_details", Optional: true}, {Name: "sender_address", Optional: true}}, - Handler: handler.SubscribePendingTxs, - })) - ws := jsonrpc.NewWebsocket(server, utils.NewNopZapLogger()) httpSrv := httptest.NewServer(ws) @@ -635,6 +603,8 @@ func setupSubscriptionTest(t *testing.T, ctx context.Context) (*rpc.Handler, *fa time.Sleep(50 * time.Millisecond) server := jsonrpc.NewServer(1, log) + methods, _ := handler.Methods() + require.NoError(t, server.RegisterMethods(methods...)) return handler, syncer, server } diff --git a/rpc/handlers.go b/rpc/handlers.go index d41ca5eeb..0831a7869 100644 --- a/rpc/handlers.go +++ b/rpc/handlers.go @@ -330,6 +330,11 @@ func (h *Handler) Methods() ([]jsonrpc.Method, string) { //nolint: funlen Params: []jsonrpc.Parameter{{Name: "block", Optional: true}}, Handler: h.SubscribeNewHeads, }, + { + Name: "starknet_subscribePendingTransactions", + Params: []jsonrpc.Parameter{{Name: "transaction_details", Optional: true}, {Name: "sender_address", Optional: true}}, + Handler: h.SubscribePendingTxs, + }, { Name: "juno_unsubscribe", Params: []jsonrpc.Parameter{{Name: "id"}}, @@ -484,17 +489,11 @@ func (h *Handler) MethodsV0_7() ([]jsonrpc.Method, string) { //nolint: funlen Name: "starknet_specVersion", Handler: h.SpecVersionV0_7, }, - { Name: "starknet_subscribeNewHeads", Params: []jsonrpc.Parameter{{Name: "block", Optional: true}}, Handler: h.SubscribeNewHeads, }, - { - Name: "starknet_subscribePendingTransactions", - Params: []jsonrpc.Parameter{{Name: "transaction_details", Optional: true}, {Name: "sender_address", Optional: true}}, - Handler: h.SubscribePendingTxs, - }, { Name: "juno_unsubscribe", Params: []jsonrpc.Parameter{{Name: "id"}},