@dashevo/dashpay-contract 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,795 @@
1
+ const { expect } = require('chai');
2
+ const crypto = require('crypto');
3
+ const {
4
+ DashPlatformProtocol,
5
+ JsonSchemaError,
6
+ } = require('@dashevo/wasm-dpp');
7
+ const generateRandomIdentifier = require('@dashevo/wasm-dpp/lib/test/utils/generateRandomIdentifierAsync');
8
+ const schema = require('../../schema/v1/dashpay.schema.json');
9
+
10
+ const whitepaperMasternodeText = 'Full nodes are servers running on a P2P network that allow peers to use them to receive updates about the events on the network. These nodes utilize significant amounts of traffic and other resources that incur a substantial cost. As a result, a steady decrease in the amount of these nodes has been observed for some time on the Bitcoin network and as a result, block propagation times have been upwards of 40 seconds. Many solutions have been proposed such as a new reward scheme by Microsoft Research and the Bitnodes incentive program';
11
+ const encoded32Chars = '4fafc98bbfe597f7ba2c9f767d52036d';
12
+ const encoded64Chars = '4fafc98bbfe597f7ba2c9f767d52036d2226175960a908e355e5c575711eb166';
13
+
14
+ const expectJsonSchemaError = (validationResult, count = 1, index = 0) => {
15
+ const errors = validationResult.getErrors();
16
+ expect(errors)
17
+ .to
18
+ .have
19
+ .length(count);
20
+
21
+ const error = validationResult.getErrors()[index];
22
+ expect(error)
23
+ .to
24
+ .be
25
+ .instanceof(JsonSchemaError);
26
+
27
+ return error;
28
+ };
29
+
30
+ describe('Dashpay Contract', () => {
31
+ let dpp;
32
+ let contract;
33
+ let identityId;
34
+
35
+ beforeEach(async () => {
36
+ dpp = new DashPlatformProtocol(
37
+ { generate: () => crypto.randomBytes(32) },
38
+ );
39
+
40
+ identityId = await generateRandomIdentifier();
41
+ contract = dpp.dataContract.create(identityId, BigInt(1), schema);
42
+ });
43
+
44
+ it('should have a valid contract definition', async () => {
45
+ expect(() => dpp.dataContract.create(identityId, BigInt(1), schema))
46
+ .to
47
+ .not
48
+ .throw();
49
+ });
50
+
51
+ describe('Documents', () => {
52
+ describe('Profile', () => {
53
+ let profileData;
54
+
55
+ beforeEach(() => {
56
+ profileData = {
57
+ displayName: 'Bob',
58
+ };
59
+ });
60
+
61
+ describe('displayName', () => {
62
+ it('should have less than 25 chars length', async () => {
63
+ profileData.displayName = 'AliceAndBobAndCarolAndDanAndEveAndFrankAndIvanAndMikeAndWalterAndWendy';
64
+
65
+ const document = dpp.document.create(contract, identityId, 'profile', profileData);
66
+ const validationResult = document.validate(dpp.protocolVersion);
67
+ const error = expectJsonSchemaError(validationResult);
68
+
69
+ expect(error.keyword)
70
+ .to
71
+ .equal('maxLength');
72
+ expect(error.instancePath)
73
+ .to
74
+ .deep
75
+ .equal('/displayName');
76
+ });
77
+ });
78
+
79
+ describe('publicMessage', () => {
80
+ it('should have less than 256 chars length', async () => {
81
+ profileData.publicMessage = whitepaperMasternodeText;
82
+
83
+ const document = dpp.document.create(contract, identityId, 'profile', profileData);
84
+ const validationResult = document.validate(dpp.protocolVersion);
85
+ const error = expectJsonSchemaError(validationResult);
86
+
87
+ expect(error.keyword)
88
+ .to
89
+ .equal('maxLength');
90
+ expect(error.instancePath)
91
+ .to
92
+ .deep
93
+ .equal('/publicMessage');
94
+ });
95
+ });
96
+
97
+ describe('avatarUrl', () => {
98
+ it('should not be empty', async () => {
99
+ profileData = {
100
+ avatarUrl: '',
101
+ avatarHash: Buffer.alloc(32),
102
+ avatarFingerprint: Buffer.alloc(8),
103
+ };
104
+
105
+ const document = dpp.document.create(contract, identityId, 'profile', profileData);
106
+ const validationResult = document.validate(dpp.protocolVersion);
107
+ const error = expectJsonSchemaError(validationResult, 2);
108
+
109
+ expect(error.keyword)
110
+ .to
111
+ .equal('format');
112
+ expect(error.instancePath)
113
+ .to
114
+ .deep
115
+ .equal('/avatarUrl');
116
+ });
117
+
118
+ it('should have less than 2048 chars length', async () => {
119
+ profileData = {
120
+ avatarUrl: `https://github.com/dashpay/dash/wiki/Whitepaper?text=${encodeURI(whitepaperMasternodeText)}${encodeURI(whitepaperMasternodeText)}${encodeURI(whitepaperMasternodeText)}${encodeURI(whitepaperMasternodeText)}${encodeURI(whitepaperMasternodeText)}`,
121
+ avatarHash: Buffer.alloc(32),
122
+ avatarFingerprint: Buffer.alloc(8),
123
+ };
124
+
125
+ const document = dpp.document.create(contract, identityId, 'profile', profileData);
126
+ const validationResult = document.validate(dpp.protocolVersion);
127
+ const error = expectJsonSchemaError(validationResult);
128
+
129
+ expect(error.keyword)
130
+ .to
131
+ .equal('maxLength');
132
+ expect(error.instancePath)
133
+ .to
134
+ .deep
135
+ .equal('/avatarUrl');
136
+ });
137
+
138
+ it('should be of type URL', async () => {
139
+ profileData = {
140
+ avatarUrl: 'notAUrl',
141
+ avatarHash: Buffer.alloc(32),
142
+ avatarFingerprint: Buffer.alloc(8),
143
+ };
144
+
145
+ const document = dpp.document.create(contract, identityId, 'profile', profileData);
146
+ const validationResult = document.validate(dpp.protocolVersion);
147
+ const error = expectJsonSchemaError(validationResult);
148
+
149
+ expect(error.keyword)
150
+ .to
151
+ .equal('format');
152
+ expect(error.instancePath)
153
+ .to
154
+ .deep
155
+ .equal('/avatarUrl');
156
+ });
157
+
158
+ it('should be present if other avatar properties are present', async () => {
159
+ profileData = {
160
+ avatarHash: Buffer.alloc(32),
161
+ avatarFingerprint: Buffer.alloc(8),
162
+ };
163
+
164
+ const document = dpp.document.create(contract, identityId, 'profile', profileData);
165
+ const validationResult = document.validate(dpp.protocolVersion);
166
+ let error = expectJsonSchemaError(validationResult, 2, 0);
167
+
168
+ expect(error.keyword)
169
+ .to
170
+ .equal('required');
171
+ expect(error.params)
172
+ .to
173
+ .deep
174
+ .equal({ missingProperty: 'avatarUrl' });
175
+
176
+ error = expectJsonSchemaError(validationResult, 2, 1);
177
+
178
+ expect(error.keyword)
179
+ .to
180
+ .equal('required');
181
+ expect(error.params)
182
+ .to
183
+ .deep
184
+ .equal({ missingProperty: 'avatarUrl' });
185
+ });
186
+ });
187
+
188
+ describe('avatarHash', () => {
189
+ it('should have minimum length of 32', async () => {
190
+ profileData = {
191
+ avatarUrl: 'https://github.com/dashpay/dash.jpg',
192
+ avatarHash: Buffer.alloc(0),
193
+ avatarFingerprint: Buffer.alloc(8),
194
+ };
195
+
196
+ const document = dpp.document.create(contract, identityId, 'profile', profileData);
197
+ const validationResult = document.validate(dpp.protocolVersion);
198
+ const error = expectJsonSchemaError(validationResult);
199
+
200
+ expect(error.keyword)
201
+ .to
202
+ .equal('minItems');
203
+ expect(error.instancePath)
204
+ .to
205
+ .deep
206
+ .equal('/avatarHash');
207
+ });
208
+
209
+ it('should have maximum length of 32', async () => {
210
+ profileData = {
211
+ avatarUrl: 'https://github.com/dashpay/dash.jpg',
212
+ avatarHash: Buffer.alloc(33),
213
+ avatarFingerprint: Buffer.alloc(8),
214
+ };
215
+
216
+ const document = dpp.document.create(contract, identityId, 'profile', profileData);
217
+ const validationResult = document.validate(dpp.protocolVersion);
218
+ const error = expectJsonSchemaError(validationResult);
219
+
220
+ expect(error.keyword)
221
+ .to
222
+ .equal('maxItems');
223
+ expect(error.instancePath)
224
+ .to
225
+ .deep
226
+ .equal('/avatarHash');
227
+ });
228
+
229
+ it('should be of type array', async () => {
230
+ profileData = {
231
+ avatarUrl: 'https://github.com/dashpay/dash.jpg',
232
+ avatarHash: 'notAnArray',
233
+ avatarFingerprint: Buffer.alloc(8),
234
+ };
235
+
236
+ const document = dpp.document.create(contract, identityId, 'profile', profileData);
237
+ const validationResult = document.validate(dpp.protocolVersion);
238
+ const error = expectJsonSchemaError(validationResult, 2);
239
+
240
+ expect(error.keyword)
241
+ .to
242
+ .equal('type');
243
+ expect(error.instancePath)
244
+ .to
245
+ .deep
246
+ .equal('/avatarHash');
247
+ });
248
+
249
+ it('should be present if other avatar properties are present', async () => {
250
+ profileData = {
251
+ avatarUrl: 'https://github.com/dashpay/dash.jpg',
252
+ avatarFingerprint: Buffer.alloc(8),
253
+ };
254
+
255
+ const document = dpp.document.create(contract, identityId, 'profile', profileData);
256
+ const validationResult = document.validate(dpp.protocolVersion);
257
+ let error = expectJsonSchemaError(validationResult, 2, 0);
258
+
259
+ expect(error.keyword)
260
+ .to
261
+ .equal('required');
262
+ expect(error.params)
263
+ .to
264
+ .deep
265
+ .equal({ missingProperty: 'avatarHash' });
266
+
267
+ error = expectJsonSchemaError(validationResult, 2, 1);
268
+
269
+ expect(error.keyword)
270
+ .to
271
+ .equal('required');
272
+ expect(error.params)
273
+ .to
274
+ .deep
275
+ .equal({ missingProperty: 'avatarHash' });
276
+ });
277
+ });
278
+
279
+ describe('avatarFingerprint', () => {
280
+ it('should have minimum length of 8', async () => {
281
+ profileData = {
282
+ avatarUrl: 'https://github.com/dashpay/dash.jpg',
283
+ avatarHash: Buffer.alloc(32),
284
+ avatarFingerprint: Buffer.alloc(0),
285
+ };
286
+
287
+ const document = dpp.document.create(contract, identityId, 'profile', profileData);
288
+ const validationResult = document.validate(dpp.protocolVersion);
289
+ const error = expectJsonSchemaError(validationResult);
290
+
291
+ expect(error.keyword)
292
+ .to
293
+ .equal('minItems');
294
+ expect(error.instancePath)
295
+ .to
296
+ .deep
297
+ .equal('/avatarFingerprint');
298
+ });
299
+
300
+ it('should have maximum length of 8', async () => {
301
+ profileData = {
302
+ avatarUrl: 'https://github.com/dashpay/dash.jpg',
303
+ avatarHash: Buffer.alloc(32),
304
+ avatarFingerprint: Buffer.alloc(33),
305
+ };
306
+
307
+ const document = dpp.document.create(contract, identityId, 'profile', profileData);
308
+ const validationResult = document.validate(dpp.protocolVersion);
309
+ const error = expectJsonSchemaError(validationResult);
310
+
311
+ expect(error.keyword)
312
+ .to
313
+ .equal('maxItems');
314
+ expect(error.instancePath)
315
+ .to
316
+ .deep
317
+ .equal('/avatarFingerprint');
318
+ });
319
+
320
+ it('should be of type array', async () => {
321
+ profileData = {
322
+ avatarUrl: 'https://github.com/dashpay/dash.jpg',
323
+ avatarHash: Buffer.alloc(32),
324
+ avatarFingerprint: 'notAnArray',
325
+ };
326
+
327
+ const document = dpp.document.create(contract, identityId, 'profile', profileData);
328
+ const validationResult = document.validate(dpp.protocolVersion);
329
+ const error = expectJsonSchemaError(validationResult, 2);
330
+
331
+ expect(error.keyword)
332
+ .to
333
+ .equal('type');
334
+ expect(error.instancePath)
335
+ .to
336
+ .deep
337
+ .equal('/avatarFingerprint');
338
+ });
339
+
340
+ it('should be present if other avatar properties are present', async () => {
341
+ profileData = {
342
+ avatarUrl: 'https://github.com/dashpay/dash.jpg',
343
+ avatarHash: Buffer.alloc(32),
344
+ };
345
+
346
+ const document = dpp.document.create(contract, identityId, 'profile', profileData);
347
+ const validationResult = document.validate(dpp.protocolVersion);
348
+ let error = expectJsonSchemaError(validationResult, 2, 0);
349
+
350
+ expect(error.keyword)
351
+ .to
352
+ .equal('required');
353
+ expect(error.params)
354
+ .to
355
+ .deep
356
+ .equal({ missingProperty: 'avatarFingerprint' });
357
+
358
+ error = expectJsonSchemaError(validationResult, 2, 1);
359
+
360
+ expect(error.keyword)
361
+ .to
362
+ .equal('required');
363
+ expect(error.params)
364
+ .to
365
+ .deep
366
+ .equal({ missingProperty: 'avatarFingerprint' });
367
+ });
368
+ });
369
+
370
+ it('should not have additional properties', async () => {
371
+ profileData.someOtherProperty = 42;
372
+
373
+ const document = dpp.document.create(contract, identityId, 'profile', profileData);
374
+ const validationResult = document.validate(dpp.protocolVersion);
375
+ const error = expectJsonSchemaError(validationResult);
376
+
377
+ expect(error.keyword)
378
+ .to
379
+ .equal('additionalProperties');
380
+ expect(error.params.additionalProperties)
381
+ .to
382
+ .deep
383
+ .equal(['someOtherProperty']);
384
+ });
385
+
386
+ it('at least one of avatarUrl, publicMessage or displayName should be present', async () => {
387
+ const profile = dpp.document.create(contract, identityId, 'profile', { });
388
+
389
+ const result = profile.validate(dpp.protocolVersion);
390
+
391
+ const error = expectJsonSchemaError(result);
392
+
393
+ expect(error.keyword)
394
+ .to
395
+ .equal('minProperties');
396
+ });
397
+
398
+ it('should be valid', async () => {
399
+ const profile = dpp.document.create(contract, identityId, 'profile', profileData);
400
+
401
+ const result = profile.validate(dpp.protocolVersion);
402
+
403
+ expect(result.isValid())
404
+ .to
405
+ .be
406
+ .true();
407
+ });
408
+ });
409
+
410
+ describe('Contact info', () => {
411
+ let contactInfoData;
412
+
413
+ beforeEach(() => {
414
+ contactInfoData = {
415
+ encToUserId: Buffer.alloc(32),
416
+ privateData: Buffer.alloc(48),
417
+ rootEncryptionKeyIndex: 0,
418
+ derivationEncryptionKeyIndex: 0,
419
+ };
420
+ });
421
+
422
+ describe('encToUserId', () => {
423
+ it('should be defined', async () => {
424
+ delete contactInfoData.encToUserId;
425
+
426
+ const document = dpp.document.create(contract, identityId, 'contactInfo', contactInfoData);
427
+ const validationResult = document.validate(dpp.protocolVersion);
428
+ const error = expectJsonSchemaError(validationResult);
429
+
430
+ expect(error.keyword)
431
+ .to
432
+ .equal('required');
433
+ expect(error.params.missingProperty)
434
+ .to
435
+ .equal('encToUserId');
436
+ });
437
+
438
+ it('should have exactly 32 chars length', async () => {
439
+ contactInfoData.encToUserId = Buffer.from(`${encoded64Chars}11`, 'hex');
440
+
441
+ const document = dpp.document.create(contract, identityId, 'contactInfo', contactInfoData);
442
+ const validationResult = document.validate(dpp.protocolVersion);
443
+ const error = expectJsonSchemaError(validationResult);
444
+
445
+ expect(error.keyword)
446
+ .to
447
+ .equal('maxItems');
448
+ expect(error.instancePath)
449
+ .to
450
+ .equal('/encToUserId');
451
+ });
452
+
453
+ it('should have more or 32 chars length', async () => {
454
+ contactInfoData.encToUserId = Buffer.from(encoded32Chars, 'hex');
455
+
456
+ const document = dpp.document.create(contract, identityId, 'contactInfo', contactInfoData);
457
+ const validationResult = document.validate(dpp.protocolVersion);
458
+ const error = expectJsonSchemaError(validationResult);
459
+
460
+ expect(error.keyword)
461
+ .to
462
+ .equal('minItems');
463
+ expect(error.instancePath)
464
+ .to
465
+ .equal('/encToUserId');
466
+ });
467
+ });
468
+
469
+ describe('rootEncryptionKeyIndex', () => {
470
+ it('should be defined', async () => {
471
+ delete contactInfoData.rootEncryptionKeyIndex;
472
+
473
+ const document = dpp.document.create(contract, identityId, 'contactInfo', contactInfoData);
474
+ const validationResult = document.validate(dpp.protocolVersion);
475
+ const error = expectJsonSchemaError(validationResult);
476
+
477
+ expect(error.keyword)
478
+ .to
479
+ .equal('required');
480
+ expect(error.params.missingProperty)
481
+ .to
482
+ .equal('rootEncryptionKeyIndex');
483
+ });
484
+
485
+ it('should not be less than 0', async () => {
486
+ contactInfoData.rootEncryptionKeyIndex = -1;
487
+
488
+ const document = dpp.document.create(contract, identityId, 'contactInfo', contactInfoData);
489
+ const validationResult = document.validate(dpp.protocolVersion);
490
+ const error = expectJsonSchemaError(validationResult);
491
+
492
+ expect(error.keyword)
493
+ .to
494
+ .equal('minimum');
495
+ expect(error.instancePath)
496
+ .to
497
+ .equal('/rootEncryptionKeyIndex');
498
+ });
499
+ });
500
+
501
+ describe('privateData', () => {
502
+ it('should be defined', async () => {
503
+ delete contactInfoData.privateData;
504
+
505
+ const document = dpp.document.create(contract, identityId, 'contactInfo', contactInfoData);
506
+ const validationResult = document.validate(dpp.protocolVersion);
507
+ const error = expectJsonSchemaError(validationResult);
508
+
509
+ expect(error.keyword)
510
+ .to
511
+ .equal('required');
512
+ expect(error.params.missingProperty)
513
+ .to
514
+ .equal('privateData');
515
+ });
516
+ });
517
+
518
+ it('should not have additional properties', async () => {
519
+ contactInfoData.someOtherProperty = 42;
520
+
521
+ const document = dpp.document.create(contract, identityId, 'contactInfo', contactInfoData);
522
+ const validationResult = document.validate(dpp.protocolVersion);
523
+ const error = expectJsonSchemaError(validationResult);
524
+
525
+ expect(error.keyword)
526
+ .to
527
+ .equal('additionalProperties');
528
+ expect(error.params.additionalProperties)
529
+ .to
530
+ .deep
531
+ .equal(['someOtherProperty']);
532
+ });
533
+ });
534
+
535
+ describe('Contact Request', () => {
536
+ let contactRequestData;
537
+
538
+ beforeEach(() => {
539
+ contactRequestData = {
540
+ toUserId: Buffer.alloc(32),
541
+ encryptedPublicKey: Buffer.alloc(96),
542
+ senderKeyIndex: 0,
543
+ recipientKeyIndex: 0,
544
+ accountReference: 0,
545
+ };
546
+ });
547
+
548
+ describe('toUserId', () => {
549
+ it('should be defined', async () => {
550
+ delete contactRequestData.toUserId;
551
+
552
+ const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
553
+ const validationResult = document.validate(dpp.protocolVersion);
554
+ const error = expectJsonSchemaError(validationResult);
555
+
556
+ expect(error.keyword)
557
+ .to
558
+ .equal('required');
559
+ expect(error.params.missingProperty)
560
+ .to
561
+ .equal('toUserId');
562
+ });
563
+ });
564
+
565
+ describe('encryptedPublicKey', () => {
566
+ it('should be defined', async () => {
567
+ delete contactRequestData.encryptedPublicKey;
568
+
569
+ const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
570
+ const validationResult = document.validate(dpp.protocolVersion);
571
+ const error = expectJsonSchemaError(validationResult);
572
+
573
+ expect(error.keyword)
574
+ .to
575
+ .equal('required');
576
+ expect(error.params.missingProperty)
577
+ .to
578
+ .equal('encryptedPublicKey');
579
+ });
580
+ });
581
+
582
+ describe('senderKeyIndex', () => {
583
+ it('should be defined', async () => {
584
+ delete contactRequestData.senderKeyIndex;
585
+
586
+ const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
587
+ const validationResult = document.validate(dpp.protocolVersion);
588
+ const error = expectJsonSchemaError(validationResult);
589
+
590
+ expect(error.keyword)
591
+ .to
592
+ .equal('required');
593
+ expect(error.params.missingProperty)
594
+ .to
595
+ .equal('senderKeyIndex');
596
+ });
597
+
598
+ it('should not be less than 0', async () => {
599
+ contactRequestData.senderKeyIndex = -1;
600
+
601
+ const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
602
+ const validationResult = document.validate(dpp.protocolVersion);
603
+ const error = expectJsonSchemaError(validationResult);
604
+
605
+ expect(error.keyword)
606
+ .to
607
+ .equal('minimum');
608
+ expect(error.instancePath)
609
+ .to
610
+ .equal('/senderKeyIndex');
611
+ });
612
+ });
613
+
614
+ describe('recipientKeyIndex', () => {
615
+ it('should be defined', async () => {
616
+ delete contactRequestData.recipientKeyIndex;
617
+
618
+ const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
619
+ const validationResult = document.validate(dpp.protocolVersion);
620
+ const error = expectJsonSchemaError(validationResult);
621
+
622
+ expect(error.keyword)
623
+ .to
624
+ .equal('required');
625
+ expect(error.params.missingProperty)
626
+ .to
627
+ .equal('recipientKeyIndex');
628
+ });
629
+
630
+ it('should not be less than 0', async () => {
631
+ contactRequestData.recipientKeyIndex = -1;
632
+
633
+ const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
634
+ const validationResult = document.validate(dpp.protocolVersion);
635
+ const error = expectJsonSchemaError(validationResult);
636
+
637
+ expect(error.keyword)
638
+ .to
639
+ .equal('minimum');
640
+ expect(error.instancePath)
641
+ .to
642
+ .equal('/recipientKeyIndex');
643
+ });
644
+ });
645
+
646
+ describe('encryptedAccountLabel', () => {
647
+ it('should have minimum length of 48', async () => {
648
+ contactRequestData.encryptedAccountLabel = Buffer.alloc(0);
649
+
650
+ const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
651
+ const validationResult = document.validate(dpp.protocolVersion);
652
+ const error = expectJsonSchemaError(validationResult);
653
+
654
+ expect(error.keyword)
655
+ .to
656
+ .equal('minItems');
657
+ expect(error.instancePath)
658
+ .to
659
+ .deep
660
+ .equal('/encryptedAccountLabel');
661
+ });
662
+
663
+ it('should have maximum length of 80', async () => {
664
+ contactRequestData.encryptedAccountLabel = Buffer.alloc(82);
665
+
666
+ const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
667
+ const validationResult = document.validate(dpp.protocolVersion);
668
+ const error = expectJsonSchemaError(validationResult);
669
+
670
+ expect(error.keyword)
671
+ .to
672
+ .equal('maxItems');
673
+ expect(error.instancePath)
674
+ .to
675
+ .deep
676
+ .equal('/encryptedAccountLabel');
677
+ });
678
+
679
+ it('should be of type array', async () => {
680
+ contactRequestData.encryptedAccountLabel = 'notAnArray';
681
+
682
+ const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
683
+ const validationResult = document.validate(dpp.protocolVersion);
684
+ const error = expectJsonSchemaError(validationResult, 2);
685
+
686
+ expect(error.keyword)
687
+ .to
688
+ .equal('type');
689
+ expect(error.instancePath)
690
+ .to
691
+ .deep
692
+ .equal('/encryptedAccountLabel');
693
+ });
694
+ });
695
+
696
+ describe('autoAcceptProof', () => {
697
+ it('should have minimum length of 38', async () => {
698
+ contactRequestData.autoAcceptProof = Buffer.alloc(0);
699
+
700
+ const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
701
+ const validationResult = document.validate(dpp.protocolVersion);
702
+ const error = expectJsonSchemaError(validationResult);
703
+
704
+ expect(error.keyword)
705
+ .to
706
+ .equal('minItems');
707
+ expect(error.instancePath)
708
+ .to
709
+ .deep
710
+ .equal('/autoAcceptProof');
711
+ });
712
+
713
+ it('should have maximum length of 102', async () => {
714
+ contactRequestData.autoAcceptProof = Buffer.alloc(104);
715
+
716
+ const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
717
+ const validationResult = document.validate(dpp.protocolVersion);
718
+ const error = expectJsonSchemaError(validationResult);
719
+
720
+ expect(error.keyword)
721
+ .to
722
+ .equal('maxItems');
723
+ expect(error.instancePath)
724
+ .to
725
+ .deep
726
+ .equal('/autoAcceptProof');
727
+ });
728
+
729
+ it('should be of type array', async () => {
730
+ contactRequestData.autoAcceptProof = 'notAnArray';
731
+
732
+ const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
733
+ const validationResult = document.validate(dpp.protocolVersion);
734
+ const error = expectJsonSchemaError(validationResult, 2);
735
+
736
+ expect(error.keyword)
737
+ .to
738
+ .equal('type');
739
+ expect(error.instancePath)
740
+ .to
741
+ .deep
742
+ .equal('/autoAcceptProof');
743
+ });
744
+ });
745
+
746
+ describe('accountReference', () => {
747
+ it('should be defined', async () => {
748
+ delete contactRequestData.accountReference;
749
+
750
+ const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
751
+ const validationResult = document.validate(dpp.protocolVersion);
752
+ const error = expectJsonSchemaError(validationResult);
753
+
754
+ expect(error.keyword)
755
+ .to
756
+ .equal('required');
757
+ expect(error.params.missingProperty)
758
+ .to
759
+ .equal('accountReference');
760
+ });
761
+
762
+ it('should not be less than 0', async () => {
763
+ contactRequestData.accountReference = -1;
764
+
765
+ const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
766
+ const validationResult = document.validate(dpp.protocolVersion);
767
+ const error = expectJsonSchemaError(validationResult);
768
+
769
+ expect(error.keyword)
770
+ .to
771
+ .equal('minimum');
772
+ expect(error.instancePath)
773
+ .to
774
+ .equal('/accountReference');
775
+ });
776
+ });
777
+
778
+ it('should not have additional properties', async () => {
779
+ contactRequestData.someOtherProperty = 42;
780
+
781
+ const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
782
+ const validationResult = document.validate(dpp.protocolVersion);
783
+ const error = expectJsonSchemaError(validationResult);
784
+
785
+ expect(error.keyword)
786
+ .to
787
+ .equal('additionalProperties');
788
+ expect(error.params.additionalProperties)
789
+ .to
790
+ .deep
791
+ .equal(['someOtherProperty']);
792
+ });
793
+ });
794
+ });
795
+ });