1
- const { Server , AxiosClient , nativeToScVal } = SorobanClient ;
1
+ const { nativeToScVal , SorobanClient , Server , AxiosClient } = SorobanClient ;
2
2
3
- describe ( ' Server#getEvents' , function ( ) {
3
+ describe ( " Server#getEvents" , function ( ) {
4
4
beforeEach ( function ( ) {
5
5
this . server = new Server ( serverUrl ) ;
6
6
this . axiosMock = sinon . mock ( AxiosClient ) ;
@@ -11,16 +11,16 @@ describe('Server#getEvents', function () {
11
11
this . axiosMock . restore ( ) ;
12
12
} ) ;
13
13
14
- it ( ' requests the correct endpoint' , function ( done ) {
14
+ it ( " requests the correct endpoint" , function ( done ) {
15
15
let result = { latestLedger : 0 , events : [ ] } ;
16
16
setupMock (
17
17
this . axiosMock ,
18
18
{
19
19
filters : [ ] ,
20
20
pagination : { } ,
21
- startLedger : '1'
21
+ startLedger : "1" ,
22
22
} ,
23
- result
23
+ result ,
24
24
) ;
25
25
26
26
this . server
@@ -34,75 +34,76 @@ describe('Server#getEvents', function () {
34
34
} ) ;
35
35
} ) ;
36
36
37
- it ( ' can build wildcard filters' , function ( done ) {
37
+ it ( " can build wildcard filters" , function ( done ) {
38
38
let result = {
39
39
latestLedger : 1 ,
40
- events : filterEvents ( getEventsResponseFixture , ' */*' )
40
+ events : filterEvents ( getEventsResponseFixture , " */*" ) ,
41
41
} ;
42
42
expect ( result . events ) . to . not . have . lengthOf ( 0 , JSON . stringify ( result ) ) ;
43
43
44
44
setupMock (
45
45
this . axiosMock ,
46
46
{
47
- startLedger : '1' ,
47
+ startLedger : "1" ,
48
48
filters : [
49
49
{
50
- topics : [ [ '*' , '*' ] ]
51
- }
50
+ topics : [ [ "*" , "*" ] ] ,
51
+ } ,
52
52
] ,
53
- pagination : { }
53
+ pagination : { } ,
54
54
} ,
55
- result
55
+ result ,
56
56
) ;
57
57
58
58
this . server
59
59
. getEvents ( {
60
60
startLedger : 1 ,
61
61
filters : [
62
62
{
63
- topics : [ [ '*' , '*' ] ]
64
- }
65
- ]
63
+ topics : [ [ "*" , "*" ] ] ,
64
+ } ,
65
+ ] ,
66
66
} )
67
67
. then ( function ( response ) {
68
68
expect ( response ) . to . be . deep . equal ( parseEvents ( result ) ) ;
69
+ expect ( response . events [ 0 ] . contractId ) . to . be . undefined ;
69
70
done ( ) ;
70
71
} )
71
72
. catch ( done ) ;
72
73
} ) ;
73
74
74
- it ( ' can build matching filters' , function ( done ) {
75
+ it ( " can build matching filters" , function ( done ) {
75
76
let result = {
76
77
latestLedger : 1 ,
77
78
events : filterEvents (
78
79
getEventsResponseFixture ,
79
- `${ topicVals [ 0 ] } /${ topicVals [ 1 ] } `
80
- )
80
+ `${ topicVals [ 0 ] } /${ topicVals [ 1 ] } ` ,
81
+ ) ,
81
82
} ;
82
83
expect ( result . events ) . to . not . have . lengthOf ( 0 , JSON . stringify ( result ) ) ;
83
84
84
85
setupMock (
85
86
this . axiosMock ,
86
87
{
87
- startLedger : '1' ,
88
+ startLedger : "1" ,
88
89
filters : [
89
90
{
90
- topics : [ [ topicVals [ 0 ] , topicVals [ 1 ] ] ]
91
- }
91
+ topics : [ [ topicVals [ 0 ] , topicVals [ 1 ] ] ] ,
92
+ } ,
92
93
] ,
93
- pagination : { }
94
+ pagination : { } ,
94
95
} ,
95
- result
96
+ result ,
96
97
) ;
97
98
98
99
this . server
99
100
. getEvents ( {
100
101
startLedger : 1 ,
101
102
filters : [
102
103
{
103
- topics : [ [ topicVals [ 0 ] , topicVals [ 1 ] ] ]
104
- }
105
- ]
104
+ topics : [ [ topicVals [ 0 ] , topicVals [ 1 ] ] ] ,
105
+ } ,
106
+ ] ,
106
107
} )
107
108
. then ( function ( response ) {
108
109
expect ( response ) . to . be . deep . equal ( parseEvents ( result ) ) ;
@@ -111,38 +112,38 @@ describe('Server#getEvents', function () {
111
112
. catch ( done ) ;
112
113
} ) ;
113
114
114
- it ( ' can build mixed filters' , function ( done ) {
115
+ it ( " can build mixed filters" , function ( done ) {
115
116
let result = {
116
117
latestLedger : 3 ,
117
118
events : filterEventsByLedger (
118
119
filterEvents ( getEventsResponseFixture , `${ topicVals [ 0 ] } /*` ) ,
119
- 2
120
- )
120
+ 2 ,
121
+ ) ,
121
122
} ;
122
123
expect ( result . events ) . to . not . have . lengthOf ( 0 , JSON . stringify ( result ) ) ;
123
124
124
125
setupMock (
125
126
this . axiosMock ,
126
127
{
127
- startLedger : '2' ,
128
+ startLedger : "2" ,
128
129
filters : [
129
130
{
130
- topics : [ [ topicVals [ 0 ] , '*' ] ]
131
- }
131
+ topics : [ [ topicVals [ 0 ] , "*" ] ] ,
132
+ } ,
132
133
] ,
133
- pagination : { }
134
+ pagination : { } ,
134
135
} ,
135
- result
136
+ result ,
136
137
) ;
137
138
138
139
this . server
139
140
. getEvents ( {
140
141
startLedger : 2 ,
141
142
filters : [
142
143
{
143
- topics : [ [ topicVals [ 0 ] , '*' ] ]
144
- }
145
- ]
144
+ topics : [ [ topicVals [ 0 ] , "*" ] ] ,
145
+ } ,
146
+ ] ,
146
147
} )
147
148
. then ( function ( response ) {
148
149
expect ( response ) . to . be . deep . equal ( parseEvents ( result ) ) ;
@@ -151,13 +152,13 @@ describe('Server#getEvents', function () {
151
152
. catch ( done ) ;
152
153
} ) ;
153
154
154
- it ( ' can paginate' , function ( done ) {
155
+ it ( " can paginate" , function ( done ) {
155
156
let result = {
156
157
latestLedger : 3 ,
157
158
events : filterEventsByLedger (
158
- filterEvents ( getEventsResponseFixture , ' */*' ) ,
159
- 2
160
- )
159
+ filterEvents ( getEventsResponseFixture , " */*" ) ,
160
+ 2 ,
161
+ ) ,
161
162
} ;
162
163
expect ( result . events ) . to . not . have . lengthOf ( 0 , JSON . stringify ( result ) ) ;
163
164
@@ -166,26 +167,26 @@ describe('Server#getEvents', function () {
166
167
{
167
168
filters : [
168
169
{
169
- topics : [ [ '*' , '*' ] ]
170
- }
170
+ topics : [ [ "*" , "*" ] ] ,
171
+ } ,
171
172
] ,
172
173
pagination : {
173
174
limit : 10 ,
174
- cursor : ' 0164090849041387521-0000000000'
175
- }
175
+ cursor : " 0164090849041387521-0000000000" ,
176
+ } ,
176
177
} ,
177
- result
178
+ result ,
178
179
) ;
179
180
180
181
this . server
181
182
. getEvents ( {
182
183
filters : [
183
184
{
184
- topics : [ [ '*' , '*' ] ]
185
- }
185
+ topics : [ [ "*" , "*" ] ] ,
186
+ } ,
186
187
] ,
187
- cursor : ' 0164090849041387521-0000000000' ,
188
- limit : 10
188
+ cursor : " 0164090849041387521-0000000000" ,
189
+ limit : 10 ,
189
190
} )
190
191
. then ( function ( response ) {
191
192
expect ( response ) . to . be . deep . equal ( parseEvents ( result ) ) ;
@@ -196,11 +197,11 @@ describe('Server#getEvents', function () {
196
197
} ) ;
197
198
198
199
function filterEvents ( events , filter ) {
199
- const parts = filter . split ( '/' ) ;
200
+ const parts = filter . split ( "/" ) ;
200
201
return events . filter (
201
202
( e , i ) =>
202
203
e . topic . length == parts . length &&
203
- e . topic . every ( ( s , j ) => s === parts [ j ] || parts [ j ] === '*' )
204
+ e . topic . every ( ( s , j ) => s === parts [ j ] || parts [ j ] === "*" ) ,
204
205
) ;
205
206
}
206
207
@@ -212,12 +213,12 @@ function filterEventsByLedger(events, start) {
212
213
213
214
function setupMock ( axiosMock , params , result ) {
214
215
axiosMock
215
- . expects ( ' post' )
216
+ . expects ( " post" )
216
217
. withArgs ( serverUrl , {
217
- jsonrpc : ' 2.0' ,
218
+ jsonrpc : " 2.0" ,
218
219
id : 1 ,
219
- method : ' getEvents' ,
220
- params : params
220
+ method : " getEvents" ,
221
+ params : params ,
221
222
} )
222
223
. returns ( Promise . resolve ( { data : { result } } ) ) ;
223
224
}
@@ -226,64 +227,64 @@ function parseEvents(result) {
226
227
return SorobanClient . parseRawEvents ( result ) ;
227
228
}
228
229
229
- const contractId = ' CA3D5KRYM6CB7OWQ6TWYRR3Z4T7GNZLKERYNZGGA5SOAOPIFY6YQGAXE' ;
230
+ const contractId = " CA3D5KRYM6CB7OWQ6TWYRR3Z4T7GNZLKERYNZGGA5SOAOPIFY6YQGAXE" ;
230
231
const topicVals = [
231
- nativeToScVal ( ' transfer' , { type : ' symbol' } ) . toXDR ( ' base64' ) ,
232
- nativeToScVal ( contractId , { type : ' address' } ) . toXDR ( ' base64' ) ,
233
- nativeToScVal ( 1234 ) . toXDR ( ' base64' )
232
+ nativeToScVal ( " transfer" , { type : " symbol" } ) . toXDR ( " base64" ) ,
233
+ nativeToScVal ( contractId , { type : " address" } ) . toXDR ( " base64" ) ,
234
+ nativeToScVal ( 1234 ) . toXDR ( " base64" ) ,
234
235
] ;
235
- let eventVal = nativeToScVal ( ' wassup' ) . toXDR ( ' base64' ) ;
236
+ let eventVal = nativeToScVal ( " wassup" ) . toXDR ( " base64" ) ;
236
237
let getEventsResponseFixture = [
237
238
{
238
- type : ' system' ,
239
- ledger : '1' ,
240
- ledgerClosedAt : ' 2022-11-16T16:10:41Z' ,
241
- contractId,
242
- id : ' 0164090849041387521-0000000003' ,
243
- pagingToken : ' 164090849041387521-3' ,
239
+ type : " system" ,
240
+ ledger : "1" ,
241
+ ledgerClosedAt : " 2022-11-16T16:10:41Z" ,
242
+ contractId : "" ,
243
+ id : " 0164090849041387521-0000000003" ,
244
+ pagingToken : " 164090849041387521-3" ,
244
245
inSuccessfulContractCall : true ,
245
246
topic : topicVals . slice ( 0 , 2 ) ,
246
247
value : {
247
- xdr : eventVal
248
- }
248
+ xdr : eventVal ,
249
+ } ,
249
250
} ,
250
251
{
251
- type : ' contract' ,
252
- ledger : '2' ,
253
- ledgerClosedAt : ' 2022-11-16T16:10:41Z' ,
252
+ type : " contract" ,
253
+ ledger : "2" ,
254
+ ledgerClosedAt : " 2022-11-16T16:10:41Z" ,
254
255
contractId,
255
- id : ' 0164090849041387521-0000000003' ,
256
- pagingToken : ' 164090849041387521-3' ,
256
+ id : " 0164090849041387521-0000000003" ,
257
+ pagingToken : " 164090849041387521-3" ,
257
258
inSuccessfulContractCall : true ,
258
259
topic : topicVals . slice ( 0 , 2 ) ,
259
260
value : {
260
- xdr : eventVal
261
- }
261
+ xdr : eventVal ,
262
+ } ,
262
263
} ,
263
264
{
264
- type : ' diagnostic' ,
265
- ledger : '2' ,
266
- ledgerClosedAt : ' 2022-11-16T16:10:41Z' ,
265
+ type : " diagnostic" ,
266
+ ledger : "2" ,
267
+ ledgerClosedAt : " 2022-11-16T16:10:41Z" ,
267
268
contractId,
268
- id : ' 0164090849041387521-0000000003' ,
269
- pagingToken : ' 164090849041387521-3' ,
269
+ id : " 0164090849041387521-0000000003" ,
270
+ pagingToken : " 164090849041387521-3" ,
270
271
inSuccessfulContractCall : true ,
271
272
topic : [ topicVals [ 0 ] ] ,
272
273
value : {
273
- xdr : eventVal
274
- }
274
+ xdr : eventVal ,
275
+ } ,
275
276
} ,
276
277
{
277
- type : ' contract' ,
278
- ledger : '3' ,
279
- ledgerClosedAt : ' 2022-12-14T01:01:20Z' ,
278
+ type : " contract" ,
279
+ ledger : "3" ,
280
+ ledgerClosedAt : " 2022-12-14T01:01:20Z" ,
280
281
contractId,
281
- id : ' 0000000171798695936-0000000001' ,
282
- pagingToken : ' 0000000171798695936-0000000001' ,
282
+ id : " 0000000171798695936-0000000001" ,
283
+ pagingToken : " 0000000171798695936-0000000001" ,
283
284
inSuccessfulContractCall : true ,
284
285
topic : topicVals ,
285
286
value : {
286
- xdr : eventVal
287
- }
288
- }
287
+ xdr : eventVal ,
288
+ } ,
289
+ } ,
289
290
] ;
0 commit comments