mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-01-02 23:22:49 +00:00
rpcsrv: fix TestFilteredSubscriptions
Close #3693 Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
This commit is contained in:
parent
6a7d2bc250
commit
0bd378770d
1 changed files with 51 additions and 23 deletions
|
@ -200,9 +200,11 @@ func TestFilteredSubscriptions(t *testing.T) {
|
|||
var cases = map[string]struct {
|
||||
params string
|
||||
check func(*testing.T, *neorpc.Notification)
|
||||
shouldCheck bool
|
||||
}{
|
||||
"tx matching sender": {
|
||||
params: `["transaction_added", {"sender":"` + goodSender.StringLE() + `"}]`,
|
||||
shouldCheck: true,
|
||||
check: func(t *testing.T, resp *neorpc.Notification) {
|
||||
rmap := resp.Payload[0].(map[string]any)
|
||||
require.Equal(t, neorpc.TransactionEventID, resp.Event)
|
||||
|
@ -212,6 +214,7 @@ func TestFilteredSubscriptions(t *testing.T) {
|
|||
},
|
||||
"tx matching signer": {
|
||||
params: `["transaction_added", {"signer":"` + goodSender.StringLE() + `"}]`,
|
||||
shouldCheck: true,
|
||||
check: func(t *testing.T, resp *neorpc.Notification) {
|
||||
rmap := resp.Payload[0].(map[string]any)
|
||||
require.Equal(t, neorpc.TransactionEventID, resp.Event)
|
||||
|
@ -223,6 +226,7 @@ func TestFilteredSubscriptions(t *testing.T) {
|
|||
},
|
||||
"tx matching sender and signer": {
|
||||
params: `["transaction_added", {"sender":"` + goodSender.StringLE() + `", "signer":"` + goodSender.StringLE() + `"}]`,
|
||||
shouldCheck: true,
|
||||
check: func(t *testing.T, resp *neorpc.Notification) {
|
||||
rmap := resp.Payload[0].(map[string]any)
|
||||
require.Equal(t, neorpc.TransactionEventID, resp.Event)
|
||||
|
@ -236,6 +240,7 @@ func TestFilteredSubscriptions(t *testing.T) {
|
|||
},
|
||||
"notification matching contract hash": {
|
||||
params: `["notification_from_execution", {"contract":"` + testContractHashLE + `"}]`,
|
||||
shouldCheck: true,
|
||||
check: func(t *testing.T, resp *neorpc.Notification) {
|
||||
rmap := resp.Payload[0].(map[string]any)
|
||||
require.Equal(t, neorpc.NotificationEventID, resp.Event)
|
||||
|
@ -244,27 +249,30 @@ func TestFilteredSubscriptions(t *testing.T) {
|
|||
},
|
||||
},
|
||||
"notification matching name": {
|
||||
params: `["notification_from_execution", {"name":"my_pretty_notification"}]`,
|
||||
params: `["notification_from_execution", {"name":"Transfer"}]`,
|
||||
shouldCheck: true,
|
||||
check: func(t *testing.T, resp *neorpc.Notification) {
|
||||
rmap := resp.Payload[0].(map[string]any)
|
||||
require.Equal(t, neorpc.NotificationEventID, resp.Event)
|
||||
n := rmap["name"].(string)
|
||||
require.Equal(t, "my_pretty_notification", n)
|
||||
n := rmap["eventname"].(string)
|
||||
require.Equal(t, "Transfer", n)
|
||||
},
|
||||
},
|
||||
"notification matching contract hash and name": {
|
||||
params: `["notification_from_execution", {"contract":"` + testContractHashLE + `", "name":"my_pretty_notification"}]`,
|
||||
params: `["notification_from_execution", {"contract":"` + testContractHashLE + `", "name":"Transfer"}]`,
|
||||
shouldCheck: true,
|
||||
check: func(t *testing.T, resp *neorpc.Notification) {
|
||||
rmap := resp.Payload[0].(map[string]any)
|
||||
require.Equal(t, neorpc.NotificationEventID, resp.Event)
|
||||
c := rmap["contract"].(string)
|
||||
require.Equal(t, "0x"+testContractHashLE, c)
|
||||
n := rmap["name"].(string)
|
||||
require.Equal(t, "my_pretty_notification", n)
|
||||
n := rmap["eventname"].(string)
|
||||
require.Equal(t, "Transfer", n)
|
||||
},
|
||||
},
|
||||
"notification matching contract hash and parameter": {
|
||||
params: `["notification_from_execution", {"contract":"` + testContractHashLE + `", "parameters":[{"type":"Any","value":null},{"type":"Hash160","value":"` + testContractHashLE + `"}]}]`,
|
||||
shouldCheck: true,
|
||||
check: func(t *testing.T, resp *neorpc.Notification) {
|
||||
rmap := resp.Payload[0].(map[string]any)
|
||||
require.Equal(t, neorpc.NotificationEventID, resp.Event)
|
||||
|
@ -287,12 +295,14 @@ func TestFilteredSubscriptions(t *testing.T) {
|
|||
},
|
||||
"notification matching contract hash but unknown parameter": {
|
||||
params: `["notification_from_execution", {"contract":"` + testContractHashLE + `", "parameters":[{"type":"Any","value":null},{"type":"Hash160","value":"ffffffffffffffffffffffffffffffffffffffff"}]}]`,
|
||||
shouldCheck: false,
|
||||
check: func(t *testing.T, resp *neorpc.Notification) {
|
||||
t.Fatal("this filter should not return any notification from test contract")
|
||||
},
|
||||
},
|
||||
"execution matching state": {
|
||||
params: `["transaction_executed", {"state":"HALT"}]`,
|
||||
shouldCheck: true,
|
||||
check: func(t *testing.T, resp *neorpc.Notification) {
|
||||
rmap := resp.Payload[0].(map[string]any)
|
||||
require.Equal(t, neorpc.ExecutionEventID, resp.Event)
|
||||
|
@ -302,6 +312,7 @@ func TestFilteredSubscriptions(t *testing.T) {
|
|||
},
|
||||
"execution matching container": {
|
||||
params: `["transaction_executed", {"container":"` + deploymentTxHash + `"}]`,
|
||||
shouldCheck: true,
|
||||
check: func(t *testing.T, resp *neorpc.Notification) {
|
||||
rmap := resp.Payload[0].(map[string]any)
|
||||
require.Equal(t, neorpc.ExecutionEventID, resp.Event)
|
||||
|
@ -311,6 +322,7 @@ func TestFilteredSubscriptions(t *testing.T) {
|
|||
},
|
||||
"execution matching state and container": {
|
||||
params: `["transaction_executed", {"state":"HALT", "container":"` + deploymentTxHash + `"}]`,
|
||||
shouldCheck: true,
|
||||
check: func(t *testing.T, resp *neorpc.Notification) {
|
||||
rmap := resp.Payload[0].(map[string]any)
|
||||
require.Equal(t, neorpc.ExecutionEventID, resp.Event)
|
||||
|
@ -322,12 +334,14 @@ func TestFilteredSubscriptions(t *testing.T) {
|
|||
},
|
||||
"tx non-matching": {
|
||||
params: `["transaction_added", {"sender":"00112233445566778899aabbccddeeff00112233"}]`,
|
||||
shouldCheck: false,
|
||||
check: func(t *testing.T, _ *neorpc.Notification) {
|
||||
t.Fatal("unexpected match for EnrollmentTransaction")
|
||||
},
|
||||
},
|
||||
"notification non-matching": {
|
||||
params: `["notification_from_execution", {"contract":"00112233445566778899aabbccddeeff00112233"}]`,
|
||||
shouldCheck: false,
|
||||
check: func(t *testing.T, _ *neorpc.Notification) {
|
||||
t.Fatal("unexpected match for contract 00112233445566778899aabbccddeeff00112233")
|
||||
},
|
||||
|
@ -335,12 +349,14 @@ func TestFilteredSubscriptions(t *testing.T) {
|
|||
"execution non-matching": {
|
||||
// We have single FAULTed transaction in chain, this, use the wrong hash for this test instead of FAULT state.
|
||||
params: `["transaction_executed", {"container":"0x` + util.Uint256{}.StringLE() + `"}]`,
|
||||
shouldCheck: false,
|
||||
check: func(t *testing.T, n *neorpc.Notification) {
|
||||
t.Fatal("unexpected match for faulted execution")
|
||||
},
|
||||
},
|
||||
"header of added block": {
|
||||
params: `["header_of_added_block", {"primary": 0, "since": 5}]`,
|
||||
shouldCheck: true,
|
||||
check: func(t *testing.T, resp *neorpc.Notification) {
|
||||
rmap := resp.Payload[0].(map[string]any)
|
||||
require.Equal(t, neorpc.HeaderOfAddedBlockEventID, resp.Event)
|
||||
|
@ -360,7 +376,10 @@ func TestFilteredSubscriptions(t *testing.T) {
|
|||
blockSubID := callSubscribe(t, c, respMsgs, `["block_added"]`)
|
||||
subID := callSubscribe(t, c, respMsgs, this.params)
|
||||
|
||||
var lastBlock uint32
|
||||
var (
|
||||
lastBlock uint32
|
||||
checked = false
|
||||
)
|
||||
for _, b := range getTestBlocks(t) {
|
||||
require.NoError(t, chain.AddBlock(b))
|
||||
lastBlock = b.Index
|
||||
|
@ -376,7 +395,16 @@ func TestFilteredSubscriptions(t *testing.T) {
|
|||
}
|
||||
continue
|
||||
}
|
||||
if this.shouldCheck {
|
||||
checked = true
|
||||
this.check(t, resp)
|
||||
} else {
|
||||
t.Fatalf("unexpected notification: %s", resp.EventID())
|
||||
}
|
||||
}
|
||||
|
||||
if this.shouldCheck && !checked {
|
||||
t.Fatal("expected check is not performed")
|
||||
}
|
||||
|
||||
callUnsubscribe(t, c, respMsgs, subID)
|
||||
|
|
Loading…
Reference in a new issue