@@ -3,7 +3,7 @@ import OurReadableStream from 'readable-stream';
3
3
import ReadableStream2 from 'readable-stream-2' ;
4
4
import ReadableStream3 from 'readable-stream-3' ;
5
5
6
- import type { JsonRpcRequest } from '@metamask/utils' ;
6
+ import { JsonRpcNotification , type JsonRpcRequest } from '@metamask/utils' ;
7
7
import createDupeReqFilterStream , {
8
8
THREE_MINUTES ,
9
9
} from './createDupeReqFilterStream' ;
@@ -26,7 +26,7 @@ function createTestStream(output: JsonRpcRequest[] = [], S = Transform) {
26
26
}
27
27
28
28
function runStreamTest (
29
- requests : JsonRpcRequest [ ] = [ ] ,
29
+ requests : ( JsonRpcRequest | JsonRpcNotification ) [ ] = [ ] ,
30
30
advanceTimersTime = 10 ,
31
31
S = Transform ,
32
32
) {
@@ -52,13 +52,13 @@ describe('createDupeReqFilterStream', () => {
52
52
53
53
it ( 'lets through requests with ids being seen for the first time' , async ( ) => {
54
54
const requests = [
55
- { id : 1 , method : 'foo' } ,
56
- { id : 2 , method : 'bar' } ,
55
+ { id : 1 , method : 'foo' , jsonrpc : '2.0' as const } ,
56
+ { id : 2 , method : 'bar' , jsonrpc : '2.0' as const } ,
57
57
] ;
58
58
59
59
const expectedOutput = [
60
- { id : 1 , method : 'foo' } ,
61
- { id : 2 , method : 'bar' } ,
60
+ { id : 1 , method : 'foo' , jsonrpc : '2.0' } ,
61
+ { id : 2 , method : 'bar' , jsonrpc : '2.0' } ,
62
62
] ;
63
63
64
64
const output = await runStreamTest ( requests ) ;
@@ -67,42 +67,48 @@ describe('createDupeReqFilterStream', () => {
67
67
68
68
it ( 'does not let through the request if the id has been seen before' , async ( ) => {
69
69
const requests = [
70
- { id : 1 , method : 'foo' } ,
71
- { id : 1 , method : 'foo' } , // duplicate
70
+ { id : 1 , method : 'foo' , jsonrpc : '2.0' as const } ,
71
+ { id : 1 , method : 'foo' , jsonrpc : '2.0' as const } , // duplicate
72
72
] ;
73
73
74
- const expectedOutput = [ { id : 1 , method : 'foo' } ] ;
74
+ const expectedOutput = [ { id : 1 , method : 'foo' , jsonrpc : '2.0' } ] ;
75
75
76
76
const output = await runStreamTest ( requests ) ;
77
77
expect ( output ) . toEqual ( expectedOutput ) ;
78
78
} ) ;
79
79
80
80
it ( "lets through requests if they don't have an id" , async ( ) => {
81
- const requests = [ { method : 'notify1' } , { method : 'notify2' } ] ;
81
+ const requests = [
82
+ { method : 'notify1' , jsonrpc : '2.0' as const } ,
83
+ { method : 'notify2' , jsonrpc : '2.0' as const } ,
84
+ ] ;
82
85
83
- const expectedOutput = [ { method : 'notify1' } , { method : 'notify2' } ] ;
86
+ const expectedOutput = [
87
+ { method : 'notify1' , jsonrpc : '2.0' } ,
88
+ { method : 'notify2' , jsonrpc : '2.0' } ,
89
+ ] ;
84
90
85
91
const output = await runStreamTest ( requests ) ;
86
92
expect ( output ) . toEqual ( expectedOutput ) ;
87
93
} ) ;
88
94
89
95
it ( 'handles a mix of request types' , async ( ) => {
90
96
const requests = [
91
- { id : 1 , method : 'foo' } ,
92
- { method : 'notify1' } ,
93
- { id : 1 , method : 'foo' } ,
94
- { id : 2 , method : 'bar' } ,
95
- { method : 'notify2' } ,
96
- { id : 2 , method : 'bar' } ,
97
- { id : 3 , method : 'baz' } ,
97
+ { id : 1 , method : 'foo' , jsonrpc : '2.0' as const } ,
98
+ { method : 'notify1' , jsonrpc : '2.0' as const } ,
99
+ { id : 1 , method : 'foo' , jsonrpc : '2.0' as const } ,
100
+ { id : 2 , method : 'bar' , jsonrpc : '2.0' as const } ,
101
+ { method : 'notify2' , jsonrpc : '2.0' as const } ,
102
+ { id : 2 , method : 'bar' , jsonrpc : '2.0' as const } ,
103
+ { id : 3 , method : 'baz' , jsonrpc : '2.0' as const } ,
98
104
] ;
99
105
100
106
const expectedOutput = [
101
- { id : 1 , method : 'foo' } ,
102
- { method : 'notify1' } ,
103
- { id : 2 , method : 'bar' } ,
104
- { method : 'notify2' } ,
105
- { id : 3 , method : 'baz' } ,
107
+ { id : 1 , method : 'foo' , jsonrpc : '2.0' } ,
108
+ { method : 'notify1' , jsonrpc : '2.0' } ,
109
+ { id : 2 , method : 'bar' , jsonrpc : '2.0' } ,
110
+ { method : 'notify2' , jsonrpc : '2.0' } ,
111
+ { id : 3 , method : 'baz' , jsonrpc : '2.0' } ,
106
112
] ;
107
113
108
114
const output = await runStreamTest ( requests ) ;
0 commit comments