From ddaba9e74d7be6220af7c3f1ab07a9b37f790480 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Wed, 16 Nov 2022 13:32:39 +0300 Subject: [PATCH] rpcsrv: fix "subscribe" parameters handling If it's a subscription for AERs, we need to check the filter's state only if it has been provided, otherwise filter is always valid. --- pkg/services/rpcsrv/server.go | 2 +- pkg/services/rpcsrv/subscription_test.go | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/pkg/services/rpcsrv/server.go b/pkg/services/rpcsrv/server.go index 83a192a01..c0b68c686 100644 --- a/pkg/services/rpcsrv/server.go +++ b/pkg/services/rpcsrv/server.go @@ -2429,7 +2429,7 @@ func (s *Server) subscribe(reqParams params.Params, sub *subscriber) (interface{ case neorpc.ExecutionEventID: flt := new(neorpc.ExecutionFilter) err = jd.Decode(flt) - if err == nil && (flt.State != nil && (*flt.State == "HALT" || *flt.State == "FAULT")) { + if err == nil && (flt.State == nil || (*flt.State == "HALT" || *flt.State == "FAULT")) { filter = *flt } else if err == nil { err = errors.New("invalid state") diff --git a/pkg/services/rpcsrv/subscription_test.go b/pkg/services/rpcsrv/subscription_test.go index 41a8191dc..d7f2a2100 100644 --- a/pkg/services/rpcsrv/subscription_test.go +++ b/pkg/services/rpcsrv/subscription_test.go @@ -228,7 +228,7 @@ func TestFilteredSubscriptions(t *testing.T) { require.Equal(t, "my_pretty_notification", n) }, }, - "execution matching": { + "execution matching state": { params: `["transaction_executed", {"state":"HALT"}]`, check: func(t *testing.T, resp *neorpc.Notification) { rmap := resp.Payload[0].(map[string]interface{}) @@ -237,6 +237,26 @@ func TestFilteredSubscriptions(t *testing.T) { require.Equal(t, "HALT", st) }, }, + "execution matching container": { + params: `["transaction_executed", {"container":"` + deploymentTxHash + `"}]`, + check: func(t *testing.T, resp *neorpc.Notification) { + rmap := resp.Payload[0].(map[string]interface{}) + require.Equal(t, neorpc.ExecutionEventID, resp.Event) + tx := rmap["container"].(string) + require.Equal(t, "0x"+deploymentTxHash, tx) + }, + }, + "execution matching state and container": { + params: `["transaction_executed", {"state":"HALT", "container":"` + deploymentTxHash + `"}]`, + check: func(t *testing.T, resp *neorpc.Notification) { + rmap := resp.Payload[0].(map[string]interface{}) + require.Equal(t, neorpc.ExecutionEventID, resp.Event) + tx := rmap["container"].(string) + require.Equal(t, "0x"+deploymentTxHash, tx) + st := rmap["vmstate"].(string) + require.Equal(t, "HALT", st) + }, + }, "tx non-matching": { params: `["transaction_added", {"sender":"00112233445566778899aabbccddeeff00112233"}]`, check: func(t *testing.T, _ *neorpc.Notification) {