@dashevo/dashpay-contract 0.25.6 → 0.25.9

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.
package/Cargo.toml CHANGED
@@ -3,6 +3,7 @@ name = "dashpay-contract"
3
3
  description = "DashPay data contract schema and tools"
4
4
  version = "0.25.0"
5
5
  edition = "2021"
6
+ rust-version = "1.73"
6
7
  license = "MIT"
7
8
 
8
9
  [dependencies]
@@ -4,9 +4,14 @@ const sinonChai = require('sinon-chai');
4
4
  const { expect, use } = require('chai');
5
5
  const dirtyChai = require('dirty-chai');
6
6
 
7
+ const {
8
+ default: loadWasmDpp,
9
+ } = require('@dashevo/wasm-dpp');
10
+
7
11
  use(dirtyChai);
8
12
  use(sinonChai);
9
13
 
14
+ before(loadWasmDpp);
10
15
  beforeEach(function beforeEach() {
11
16
  if (!this.sinon) {
12
17
  this.sinon = sinon.createSandbox();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dashevo/dashpay-contract",
3
- "version": "0.25.6",
3
+ "version": "0.25.9",
4
4
  "description": "Reference contract of the DashPay DPA on Dash Evolution",
5
5
  "scripts": {
6
6
  "lint": "eslint .",
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "homepage": "https://github.com/dashevo/dashpay-contract#readme",
27
27
  "devDependencies": {
28
- "@dashevo/dpp": "0.25.6",
28
+ "@dashevo/wasm-dpp": "0.25.9",
29
29
  "chai": "^4.3.9",
30
30
  "dirty-chai": "^2.0.1",
31
31
  "eslint": "^7.32.0",
@@ -1,42 +1,39 @@
1
1
  const { expect } = require('chai');
2
- const DashPlatformProtocol = require('@dashevo/dpp');
3
- const generateRandomIdentifier = require('@dashevo/dpp/lib/test/utils/generateRandomIdentifier');
2
+ const crypto = require('crypto');
3
+ const { DashPlatformProtocol, JsonSchemaError } = require('@dashevo/wasm-dpp');
4
+ const generateRandomIdentifier = require('@dashevo/wasm-dpp/lib/test/utils/generateRandomIdentifierAsync');
4
5
  const schema = require('../../schema/dashpay.schema.json');
5
6
 
6
7
  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';
7
8
  const encoded32Chars = '4fafc98bbfe597f7ba2c9f767d52036d';
8
9
  const encoded64Chars = '4fafc98bbfe597f7ba2c9f767d52036d2226175960a908e355e5c575711eb166';
9
10
 
10
- // TODO: consider restoring with wasm-dpp
11
- describe.skip('Dashpay Contract', () => {
12
- let dpp;
13
- let contract;
14
- let identityId;
11
+ const expectJsonSchemaError = (validationResult) => {
12
+ const errors = validationResult.getErrors();
13
+ expect(errors).to.have.length(1);
15
14
 
16
- beforeEach(async function beforeEach() {
17
- const fetchContractStub = this.sinon.stub();
15
+ const error = validationResult.getErrors()[0];
16
+ expect(error).to.be.instanceof(JsonSchemaError);
18
17
 
19
- dpp = new DashPlatformProtocol({
20
- stateRepository: {
21
- fetchDataContract: fetchContractStub,
22
- },
23
- });
18
+ return error;
19
+ };
24
20
 
25
- await dpp.initialize();
21
+ describe('Dashpay Contract', () => {
22
+ let dpp;
23
+ let contract;
24
+ let identityId;
26
25
 
27
- identityId = generateRandomIdentifier();
26
+ beforeEach(async () => {
27
+ dpp = new DashPlatformProtocol(
28
+ { generate: () => crypto.randomBytes(32) },
29
+ );
28
30
 
31
+ identityId = await generateRandomIdentifier();
29
32
  contract = dpp.dataContract.create(identityId, schema);
30
-
31
- fetchContractStub.resolves(contract);
32
33
  });
33
34
 
34
- it('should have a valid contract definition', async function shouldHaveValidContract() {
35
- this.timeout(5000);
36
-
37
- const validationResult = await dpp.dataContract.validate(contract);
38
-
39
- expect(validationResult.isValid()).to.be.true();
35
+ it('should have a valid contract definition', async () => {
36
+ expect(() => dpp.dataContract.create(identityId, schema)).to.not.throw();
40
37
  });
41
38
 
42
39
  describe('Documents', () => {
@@ -54,20 +51,12 @@ describe.skip('Dashpay Contract', () => {
54
51
  it('should have less than 25 chars length', async () => {
55
52
  profileData.displayName = 'AliceAndBobAndCarolAndDanAndEveAndFrankAndIvanAndMikeAndWalterAndWendy';
56
53
 
57
- try {
58
- dpp.document.create(contract, identityId, 'profile', profileData);
54
+ const document = dpp.document.create(contract, identityId, 'profile', profileData);
55
+ const validationResult = document.validate(dpp.protocolVersion);
56
+ const error = expectJsonSchemaError(validationResult);
59
57
 
60
- expect.fail('should throw error');
61
- } catch (e) {
62
- expect(e.name).to.equal('InvalidDocumentError');
63
- expect(e.errors).to.have.a.lengthOf(1);
64
-
65
- const [error] = e.errors;
66
-
67
- expect(error.name).to.equal('JsonSchemaError');
68
- expect(error.keyword).to.equal('maxLength');
69
- expect(error.instancePath).to.equal('/displayName');
70
- }
58
+ expect(error.keyword).to.equal('maxLength');
59
+ expect(error.instancePath).to.deep.equal('/displayName');
71
60
  });
72
61
  });
73
62
 
@@ -75,20 +64,12 @@ describe.skip('Dashpay Contract', () => {
75
64
  it('should have less than 256 chars length', async () => {
76
65
  profileData.publicMessage = whitepaperMasternodeText;
77
66
 
78
- try {
79
- dpp.document.create(contract, identityId, 'profile', profileData);
80
-
81
- expect.fail('should throw error');
82
- } catch (e) {
83
- expect(e.name).to.equal('InvalidDocumentError');
84
- expect(e.errors).to.have.a.lengthOf(1);
67
+ const document = dpp.document.create(contract, identityId, 'profile', profileData);
68
+ const validationResult = document.validate(dpp.protocolVersion);
69
+ const error = expectJsonSchemaError(validationResult);
85
70
 
86
- const [error] = e.errors;
87
-
88
- expect(error.name).to.equal('JsonSchemaError');
89
- expect(error.keyword).to.equal('maxLength');
90
- expect(error.instancePath).to.equal('/publicMessage');
91
- }
71
+ expect(error.keyword).to.equal('maxLength');
72
+ expect(error.instancePath).to.deep.equal('/publicMessage');
92
73
  });
93
74
  });
94
75
 
@@ -96,58 +77,34 @@ describe.skip('Dashpay Contract', () => {
96
77
  it('should not be empty', async () => {
97
78
  profileData.avatarUrl = '';
98
79
 
99
- try {
100
- dpp.document.create(contract, identityId, 'profile', profileData);
101
-
102
- expect.fail('should throw error');
103
- } catch (e) {
104
- expect(e.name).to.equal('InvalidDocumentError');
105
- expect(e.errors).to.have.a.lengthOf(1);
80
+ const document = dpp.document.create(contract, identityId, 'profile', profileData);
81
+ const validationResult = document.validate(dpp.protocolVersion);
82
+ const error = expectJsonSchemaError(validationResult);
106
83
 
107
- const [error] = e.errors;
108
-
109
- expect(error.name).to.equal('JsonSchemaError');
110
- expect(error.keyword).to.equal('format');
111
- expect(error.instancePath).to.equal('/avatarUrl');
112
- }
84
+ expect(error.keyword).to.equal('format');
85
+ expect(error.instancePath).to.deep.equal('/avatarUrl');
113
86
  });
114
87
 
115
88
  it('should have less than 2048 chars length', async () => {
116
89
  profileData.avatarUrl = `https://github.com/dashpay/dash/wiki/Whitepaper?text=${encodeURI(whitepaperMasternodeText)}${encodeURI(whitepaperMasternodeText)}${encodeURI(whitepaperMasternodeText)}${encodeURI(whitepaperMasternodeText)}${encodeURI(whitepaperMasternodeText)}`;
117
90
 
118
- try {
119
- dpp.document.create(contract, identityId, 'profile', profileData);
120
-
121
- expect.fail('should throw error');
122
- } catch (e) {
123
- expect(e.name).to.equal('InvalidDocumentError');
124
- expect(e.errors).to.have.a.lengthOf(1);
91
+ const document = dpp.document.create(contract, identityId, 'profile', profileData);
92
+ const validationResult = document.validate(dpp.protocolVersion);
93
+ const error = expectJsonSchemaError(validationResult);
125
94
 
126
- const [error] = e.errors;
127
-
128
- expect(error.name).to.equal('JsonSchemaError');
129
- expect(error.keyword).to.equal('maxLength');
130
- expect(error.instancePath).to.equal('/avatarUrl');
131
- }
95
+ expect(error.keyword).to.equal('maxLength');
96
+ expect(error.instancePath).to.deep.equal('/avatarUrl');
132
97
  });
133
98
 
134
99
  it('should be of type URL', async () => {
135
100
  profileData.avatarUrl = 'notAUrl';
136
101
 
137
- try {
138
- dpp.document.create(contract, identityId, 'profile', profileData);
139
-
140
- expect.fail('should throw error');
141
- } catch (e) {
142
- expect(e.name).to.equal('InvalidDocumentError');
143
- expect(e.errors).to.have.a.lengthOf(1);
144
-
145
- const [error] = e.errors;
102
+ const document = dpp.document.create(contract, identityId, 'profile', profileData);
103
+ const validationResult = document.validate(dpp.protocolVersion);
104
+ const error = expectJsonSchemaError(validationResult);
146
105
 
147
- expect(error.name).to.equal('JsonSchemaError');
148
- expect(error.keyword).to.equal('format');
149
- expect(error.instancePath).to.equal('/avatarUrl');
150
- }
106
+ expect(error.keyword).to.equal('format');
107
+ expect(error.instancePath).to.deep.equal('/avatarUrl');
151
108
  });
152
109
  });
153
110
 
@@ -155,52 +112,34 @@ describe.skip('Dashpay Contract', () => {
155
112
  it('should have minimum length of 32', async () => {
156
113
  profileData.avatarHash = Buffer.alloc(0);
157
114
 
158
- try {
159
- dpp.document.create(contract, identityId, 'profile', profileData);
115
+ const document = dpp.document.create(contract, identityId, 'profile', profileData);
116
+ const validationResult = document.validate(dpp.protocolVersion);
117
+ const error = expectJsonSchemaError(validationResult);
160
118
 
161
- expect.fail('should throw error');
162
- } catch (e) {
163
- expect(e.name).to.equal('InvalidDocumentError');
164
- expect(e.errors).to.have.a.lengthOf(1);
165
- const [error] = e.errors;
166
- expect(error.name).to.equal('JsonSchemaError');
167
- expect(error.keyword).to.equal('minItems');
168
- expect(error.instancePath).to.equal('/avatarHash');
169
- }
119
+ expect(error.keyword).to.equal('minItems');
120
+ expect(error.instancePath).to.deep.equal('/avatarHash');
170
121
  });
171
122
 
172
123
  it('should have maximum length of 32', async () => {
173
124
  profileData.avatarHash = Buffer.alloc(33);
174
125
 
175
- try {
176
- dpp.document.create(contract, identityId, 'profile', profileData);
126
+ const document = dpp.document.create(contract, identityId, 'profile', profileData);
127
+ const validationResult = document.validate(dpp.protocolVersion);
128
+ const error = expectJsonSchemaError(validationResult);
177
129
 
178
- expect.fail('should throw error');
179
- } catch (e) {
180
- expect(e.name).to.equal('InvalidDocumentError');
181
- expect(e.errors).to.have.a.lengthOf(1);
182
- const [error] = e.errors;
183
- expect(error.name).to.equal('JsonSchemaError');
184
- expect(error.keyword).to.equal('maxItems');
185
- expect(error.instancePath).to.equal('/avatarHash');
186
- }
130
+ expect(error.keyword).to.equal('maxItems');
131
+ expect(error.instancePath).to.deep.equal('/avatarHash');
187
132
  });
188
133
 
189
134
  it('should be of type array', async () => {
190
135
  profileData.avatarHash = 'notAnArray';
191
136
 
192
- try {
193
- dpp.document.create(contract, identityId, 'profile', profileData);
137
+ const document = dpp.document.create(contract, identityId, 'profile', profileData);
138
+ const validationResult = document.validate(dpp.protocolVersion);
139
+ const error = expectJsonSchemaError(validationResult);
194
140
 
195
- expect.fail('should throw error');
196
- } catch (e) {
197
- expect(e.name).to.equal('InvalidDocumentError');
198
- expect(e.errors).to.have.a.lengthOf(1);
199
- const [error] = e.errors;
200
- expect(error.name).to.equal('JsonSchemaError');
201
- expect(error.keyword).to.equal('type');
202
- expect(error.instancePath).to.equal('/avatarHash');
203
- }
141
+ expect(error.keyword).to.equal('type');
142
+ expect(error.instancePath).to.deep.equal('/avatarHash');
204
143
  });
205
144
  });
206
145
 
@@ -208,78 +147,52 @@ describe.skip('Dashpay Contract', () => {
208
147
  it('should have minimum length of 8', async () => {
209
148
  profileData.avatarFingerprint = Buffer.alloc(0);
210
149
 
211
- try {
212
- dpp.document.create(contract, identityId, 'profile', profileData);
150
+ const document = dpp.document.create(contract, identityId, 'profile', profileData);
151
+ const validationResult = document.validate(dpp.protocolVersion);
152
+ const error = expectJsonSchemaError(validationResult);
213
153
 
214
- expect.fail('should throw error');
215
- } catch (e) {
216
- expect(e.name).to.equal('InvalidDocumentError');
217
- expect(e.errors).to.have.a.lengthOf(1);
218
- const [error] = e.errors;
219
- expect(error.name).to.equal('JsonSchemaError');
220
- expect(error.keyword).to.equal('minItems');
221
- expect(error.instancePath).to.equal('/avatarFingerprint');
222
- }
154
+ expect(error.keyword).to.equal('minItems');
155
+ expect(error.instancePath).to.deep.equal('/avatarFingerprint');
223
156
  });
224
157
 
225
158
  it('should have maximum length of 8', async () => {
226
159
  profileData.avatarFingerprint = Buffer.alloc(33);
227
160
 
228
- try {
229
- dpp.document.create(contract, identityId, 'profile', profileData);
161
+ const document = dpp.document.create(contract, identityId, 'profile', profileData);
162
+ const validationResult = document.validate(dpp.protocolVersion);
163
+ const error = expectJsonSchemaError(validationResult);
230
164
 
231
- expect.fail('should throw error');
232
- } catch (e) {
233
- expect(e.name).to.equal('InvalidDocumentError');
234
- expect(e.errors).to.have.a.lengthOf(1);
235
- const [error] = e.errors;
236
- expect(error.name).to.equal('JsonSchemaError');
237
- expect(error.keyword).to.equal('maxItems');
238
- expect(error.instancePath).to.equal('/avatarFingerprint');
239
- }
165
+ expect(error.keyword).to.equal('maxItems');
166
+ expect(error.instancePath).to.deep.equal('/avatarFingerprint');
240
167
  });
241
168
 
242
169
  it('should be of type array', async () => {
243
170
  profileData.avatarFingerprint = 'notAnArray';
244
171
 
245
- try {
246
- dpp.document.create(contract, identityId, 'profile', profileData);
172
+ const document = dpp.document.create(contract, identityId, 'profile', profileData);
173
+ const validationResult = document.validate(dpp.protocolVersion);
174
+ const error = expectJsonSchemaError(validationResult);
247
175
 
248
- expect.fail('should throw error');
249
- } catch (e) {
250
- expect(e.name).to.equal('InvalidDocumentError');
251
- expect(e.errors).to.have.a.lengthOf(1);
252
- const [error] = e.errors;
253
- expect(error.name).to.equal('JsonSchemaError');
254
- expect(error.keyword).to.equal('type');
255
- expect(error.instancePath).to.equal('/avatarFingerprint');
256
- }
176
+ expect(error.keyword).to.equal('type');
177
+ expect(error.instancePath).to.deep.equal('/avatarFingerprint');
257
178
  });
258
179
  });
259
180
 
260
181
  it('should not have additional properties', async () => {
261
182
  profileData.someOtherProperty = 42;
262
183
 
263
- try {
264
- dpp.document.create(contract, identityId, 'profile', profileData);
184
+ const document = dpp.document.create(contract, identityId, 'profile', profileData);
185
+ const validationResult = document.validate(dpp.protocolVersion);
186
+ const error = expectJsonSchemaError(validationResult);
265
187
 
266
- expect.fail('should throw error');
267
- } catch (e) {
268
- expect(e.name).to.equal('InvalidDocumentError');
269
- expect(e.errors).to.have.a.lengthOf(1);
270
-
271
- const [error] = e.errors;
272
-
273
- expect(error.name).to.equal('JsonSchemaError');
274
- expect(error.keyword).to.equal('additionalProperties');
275
- expect(error.params.additionalProperty).to.equal('someOtherProperty');
276
- }
188
+ expect(error.keyword).to.equal('additionalProperties');
189
+ expect(error.params.additionalProperties).to.deep.equal(['someOtherProperty']);
277
190
  });
278
191
 
279
192
  it('should be valid', async () => {
280
193
  const profile = dpp.document.create(contract, identityId, 'profile', profileData);
281
194
 
282
- const result = await dpp.document.validate(profile);
195
+ const result = profile.validate(dpp.protocolVersion);
283
196
 
284
197
  expect(result.isValid()).to.be.true();
285
198
  });
@@ -301,58 +214,34 @@ describe.skip('Dashpay Contract', () => {
301
214
  it('should be defined', async () => {
302
215
  delete contactInfoData.encToUserId;
303
216
 
304
- try {
305
- dpp.document.create(contract, identityId, 'contactInfo', contactInfoData);
306
-
307
- expect.fail('should throw error');
308
- } catch (e) {
309
- expect(e.name).to.equal('InvalidDocumentError');
310
- expect(e.errors).to.have.a.lengthOf(1);
217
+ const document = dpp.document.create(contract, identityId, 'contactInfo', contactInfoData);
218
+ const validationResult = document.validate(dpp.protocolVersion);
219
+ const error = expectJsonSchemaError(validationResult);
311
220
 
312
- const [error] = e.errors;
313
-
314
- expect(error.name).to.equal('JsonSchemaError');
315
- expect(error.keyword).to.equal('required');
316
- expect(error.params.missingProperty).to.equal('encToUserId');
317
- }
221
+ expect(error.keyword).to.equal('required');
222
+ expect(error.params.missingProperty).to.equal('encToUserId');
318
223
  });
319
224
 
320
225
  it('should have exactly 32 chars length', async () => {
321
226
  contactInfoData.encToUserId = Buffer.from(`${encoded64Chars}11`, 'hex');
322
227
 
323
- try {
324
- dpp.document.create(contract, identityId, 'contactInfo', contactInfoData);
325
-
326
- expect.fail('should throw error');
327
- } catch (e) {
328
- expect(e.name).to.equal('InvalidDocumentError');
329
- expect(e.errors).to.have.a.lengthOf(1);
330
-
331
- const [error] = e.errors;
228
+ const document = dpp.document.create(contract, identityId, 'contactInfo', contactInfoData);
229
+ const validationResult = document.validate(dpp.protocolVersion);
230
+ const error = expectJsonSchemaError(validationResult);
332
231
 
333
- expect(error.name).to.equal('JsonSchemaError');
334
- expect(error.keyword).to.equal('maxItems');
335
- expect(error.instancePath).to.equal('/encToUserId');
336
- }
232
+ expect(error.keyword).to.equal('maxItems');
233
+ expect(error.instancePath).to.equal('/encToUserId');
337
234
  });
338
235
 
339
236
  it('should have more or 32 chars length', async () => {
340
237
  contactInfoData.encToUserId = Buffer.from(encoded32Chars, 'hex');
341
238
 
342
- try {
343
- dpp.document.create(contract, identityId, 'contactInfo', contactInfoData);
239
+ const document = dpp.document.create(contract, identityId, 'contactInfo', contactInfoData);
240
+ const validationResult = document.validate(dpp.protocolVersion);
241
+ const error = expectJsonSchemaError(validationResult);
344
242
 
345
- expect.fail('should throw error');
346
- } catch (e) {
347
- expect(e.name).to.equal('InvalidDocumentError');
348
- expect(e.errors).to.have.a.lengthOf(1);
349
-
350
- const [error] = e.errors;
351
-
352
- expect(error.name).to.equal('JsonSchemaError');
353
- expect(error.keyword).to.equal('minItems');
354
- expect(error.instancePath).to.equal('/encToUserId');
355
- }
243
+ expect(error.keyword).to.equal('minItems');
244
+ expect(error.instancePath).to.equal('/encToUserId');
356
245
  });
357
246
  });
358
247
 
@@ -360,39 +249,23 @@ describe.skip('Dashpay Contract', () => {
360
249
  it('should be defined', async () => {
361
250
  delete contactInfoData.rootEncryptionKeyIndex;
362
251
 
363
- try {
364
- dpp.document.create(contract, identityId, 'contactInfo', contactInfoData);
365
-
366
- expect.fail('should throw error');
367
- } catch (e) {
368
- expect(e.name).to.equal('InvalidDocumentError');
369
- expect(e.errors).to.have.a.lengthOf(1);
370
-
371
- const [error] = e.errors;
252
+ const document = dpp.document.create(contract, identityId, 'contactInfo', contactInfoData);
253
+ const validationResult = document.validate(dpp.protocolVersion);
254
+ const error = expectJsonSchemaError(validationResult);
372
255
 
373
- expect(error.name).to.equal('JsonSchemaError');
374
- expect(error.keyword).to.equal('required');
375
- expect(error.params.missingProperty).to.equal('rootEncryptionKeyIndex');
376
- }
256
+ expect(error.keyword).to.equal('required');
257
+ expect(error.params.missingProperty).to.equal('rootEncryptionKeyIndex');
377
258
  });
378
259
 
379
260
  it('should not be less than 0', async () => {
380
261
  contactInfoData.rootEncryptionKeyIndex = -1;
381
262
 
382
- try {
383
- dpp.document.create(contract, identityId, 'contactInfo', contactInfoData);
263
+ const document = dpp.document.create(contract, identityId, 'contactInfo', contactInfoData);
264
+ const validationResult = document.validate(dpp.protocolVersion);
265
+ const error = expectJsonSchemaError(validationResult);
384
266
 
385
- expect.fail('should throw error');
386
- } catch (e) {
387
- expect(e.name).to.equal('InvalidDocumentError');
388
- expect(e.errors).to.have.a.lengthOf(1);
389
-
390
- const [error] = e.errors;
391
-
392
- expect(error.name).to.equal('JsonSchemaError');
393
- expect(error.keyword).to.equal('minimum');
394
- expect(error.instancePath).to.equal('/rootEncryptionKeyIndex');
395
- }
267
+ expect(error.keyword).to.equal('minimum');
268
+ expect(error.instancePath).to.equal('/rootEncryptionKeyIndex');
396
269
  });
397
270
  });
398
271
 
@@ -400,40 +273,24 @@ describe.skip('Dashpay Contract', () => {
400
273
  it('should be defined', async () => {
401
274
  delete contactInfoData.privateData;
402
275
 
403
- try {
404
- dpp.document.create(contract, identityId, 'contactInfo', contactInfoData);
405
-
406
- expect.fail('should throw error');
407
- } catch (e) {
408
- expect(e.name).to.equal('InvalidDocumentError');
409
- expect(e.errors).to.have.a.lengthOf(1);
276
+ const document = dpp.document.create(contract, identityId, 'contactInfo', contactInfoData);
277
+ const validationResult = document.validate(dpp.protocolVersion);
278
+ const error = expectJsonSchemaError(validationResult);
410
279
 
411
- const [error] = e.errors;
412
-
413
- expect(error.name).to.equal('JsonSchemaError');
414
- expect(error.keyword).to.equal('required');
415
- expect(error.params.missingProperty).to.equal('privateData');
416
- }
280
+ expect(error.keyword).to.equal('required');
281
+ expect(error.params.missingProperty).to.equal('privateData');
417
282
  });
418
283
  });
419
284
 
420
285
  it('should not have additional properties', async () => {
421
286
  contactInfoData.someOtherProperty = 42;
422
287
 
423
- try {
424
- dpp.document.create(contract, identityId, 'contactInfo', contactInfoData);
425
-
426
- expect.fail('should throw error');
427
- } catch (e) {
428
- expect(e.name).to.equal('InvalidDocumentError');
429
- expect(e.errors).to.have.a.lengthOf(1);
430
-
431
- const [error] = e.errors;
288
+ const document = dpp.document.create(contract, identityId, 'contactInfo', contactInfoData);
289
+ const validationResult = document.validate(dpp.protocolVersion);
290
+ const error = expectJsonSchemaError(validationResult);
432
291
 
433
- expect(error.name).to.equal('JsonSchemaError');
434
- expect(error.keyword).to.equal('additionalProperties');
435
- expect(error.params.additionalProperty).to.equal('someOtherProperty');
436
- }
292
+ expect(error.keyword).to.equal('additionalProperties');
293
+ expect(error.params.additionalProperties).to.deep.equal(['someOtherProperty']);
437
294
  });
438
295
  });
439
296
 
@@ -454,20 +311,12 @@ describe.skip('Dashpay Contract', () => {
454
311
  it('should be defined', async () => {
455
312
  delete contactRequestData.toUserId;
456
313
 
457
- try {
458
- dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
314
+ const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
315
+ const validationResult = document.validate(dpp.protocolVersion);
316
+ const error = expectJsonSchemaError(validationResult);
459
317
 
460
- expect.fail('should throw error');
461
- } catch (e) {
462
- expect(e.name).to.equal('InvalidDocumentError');
463
- expect(e.errors).to.have.a.lengthOf(1);
464
-
465
- const [error] = e.errors;
466
-
467
- expect(error.name).to.equal('JsonSchemaError');
468
- expect(error.keyword).to.equal('required');
469
- expect(error.params.missingProperty).to.equal('toUserId');
470
- }
318
+ expect(error.keyword).to.equal('required');
319
+ expect(error.params.missingProperty).to.equal('toUserId');
471
320
  });
472
321
  });
473
322
 
@@ -475,20 +324,12 @@ describe.skip('Dashpay Contract', () => {
475
324
  it('should be defined', async () => {
476
325
  delete contactRequestData.encryptedPublicKey;
477
326
 
478
- try {
479
- dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
480
-
481
- expect.fail('should throw error');
482
- } catch (e) {
483
- expect(e.name).to.equal('InvalidDocumentError');
484
- expect(e.errors).to.have.a.lengthOf(1);
327
+ const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
328
+ const validationResult = document.validate(dpp.protocolVersion);
329
+ const error = expectJsonSchemaError(validationResult);
485
330
 
486
- const [error] = e.errors;
487
-
488
- expect(error.name).to.equal('JsonSchemaError');
489
- expect(error.keyword).to.equal('required');
490
- expect(error.params.missingProperty).to.equal('encryptedPublicKey');
491
- }
331
+ expect(error.keyword).to.equal('required');
332
+ expect(error.params.missingProperty).to.equal('encryptedPublicKey');
492
333
  });
493
334
  });
494
335
 
@@ -496,39 +337,23 @@ describe.skip('Dashpay Contract', () => {
496
337
  it('should be defined', async () => {
497
338
  delete contactRequestData.senderKeyIndex;
498
339
 
499
- try {
500
- dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
501
-
502
- expect.fail('should throw error');
503
- } catch (e) {
504
- expect(e.name).to.equal('InvalidDocumentError');
505
- expect(e.errors).to.have.a.lengthOf(1);
340
+ const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
341
+ const validationResult = document.validate(dpp.protocolVersion);
342
+ const error = expectJsonSchemaError(validationResult);
506
343
 
507
- const [error] = e.errors;
508
-
509
- expect(error.name).to.equal('JsonSchemaError');
510
- expect(error.keyword).to.equal('required');
511
- expect(error.params.missingProperty).to.equal('senderKeyIndex');
512
- }
344
+ expect(error.keyword).to.equal('required');
345
+ expect(error.params.missingProperty).to.equal('senderKeyIndex');
513
346
  });
514
347
 
515
348
  it('should not be less than 0', async () => {
516
349
  contactRequestData.senderKeyIndex = -1;
517
350
 
518
- try {
519
- dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
520
-
521
- expect.fail('should throw error');
522
- } catch (e) {
523
- expect(e.name).to.equal('InvalidDocumentError');
524
- expect(e.errors).to.have.a.lengthOf(1);
351
+ const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
352
+ const validationResult = document.validate(dpp.protocolVersion);
353
+ const error = expectJsonSchemaError(validationResult);
525
354
 
526
- const [error] = e.errors;
527
-
528
- expect(error.name).to.equal('JsonSchemaError');
529
- expect(error.keyword).to.equal('minimum');
530
- expect(error.instancePath).to.equal('/senderKeyIndex');
531
- }
355
+ expect(error.keyword).to.equal('minimum');
356
+ expect(error.instancePath).to.equal('/senderKeyIndex');
532
357
  });
533
358
  });
534
359
 
@@ -536,39 +361,23 @@ describe.skip('Dashpay Contract', () => {
536
361
  it('should be defined', async () => {
537
362
  delete contactRequestData.recipientKeyIndex;
538
363
 
539
- try {
540
- dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
541
-
542
- expect.fail('should throw error');
543
- } catch (e) {
544
- expect(e.name).to.equal('InvalidDocumentError');
545
- expect(e.errors).to.have.a.lengthOf(1);
546
-
547
- const [error] = e.errors;
364
+ const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
365
+ const validationResult = document.validate(dpp.protocolVersion);
366
+ const error = expectJsonSchemaError(validationResult);
548
367
 
549
- expect(error.name).to.equal('JsonSchemaError');
550
- expect(error.keyword).to.equal('required');
551
- expect(error.params.missingProperty).to.equal('recipientKeyIndex');
552
- }
368
+ expect(error.keyword).to.equal('required');
369
+ expect(error.params.missingProperty).to.equal('recipientKeyIndex');
553
370
  });
554
371
 
555
372
  it('should not be less than 0', async () => {
556
373
  contactRequestData.recipientKeyIndex = -1;
557
374
 
558
- try {
559
- dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
375
+ const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
376
+ const validationResult = document.validate(dpp.protocolVersion);
377
+ const error = expectJsonSchemaError(validationResult);
560
378
 
561
- expect.fail('should throw error');
562
- } catch (e) {
563
- expect(e.name).to.equal('InvalidDocumentError');
564
- expect(e.errors).to.have.a.lengthOf(1);
565
-
566
- const [error] = e.errors;
567
-
568
- expect(error.name).to.equal('JsonSchemaError');
569
- expect(error.keyword).to.equal('minimum');
570
- expect(error.instancePath).to.equal('/recipientKeyIndex');
571
- }
379
+ expect(error.keyword).to.equal('minimum');
380
+ expect(error.instancePath).to.equal('/recipientKeyIndex');
572
381
  });
573
382
  });
574
383
 
@@ -576,51 +385,34 @@ describe.skip('Dashpay Contract', () => {
576
385
  it('should have minimum length of 48', async () => {
577
386
  contactRequestData.encryptedAccountLabel = Buffer.alloc(0);
578
387
 
579
- try {
580
- dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
388
+ const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
389
+ const validationResult = document.validate(dpp.protocolVersion);
390
+ const error = expectJsonSchemaError(validationResult);
581
391
 
582
- expect.fail('should throw error');
583
- } catch (e) {
584
- expect(e.name).to.equal('InvalidDocumentError');
585
- expect(e.errors).to.have.a.lengthOf(1);
586
- const [error] = e.errors;
587
- expect(error.name).to.equal('JsonSchemaError');
588
- expect(error.keyword).to.equal('minItems');
589
- expect(error.instancePath).to.equal('/encryptedAccountLabel');
590
- }
392
+ expect(error.keyword).to.equal('minItems');
393
+ expect(error.instancePath).to.deep.equal('/encryptedAccountLabel');
591
394
  });
592
395
 
593
396
  it('should have maximum length of 80', async () => {
594
397
  contactRequestData.encryptedAccountLabel = Buffer.alloc(82);
595
398
 
596
- try {
597
- dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
399
+ const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
400
+ const validationResult = document.validate(dpp.protocolVersion);
401
+ const error = expectJsonSchemaError(validationResult);
598
402
 
599
- expect.fail('should throw error');
600
- } catch (e) {
601
- expect(e.name).to.equal('InvalidDocumentError');
602
- expect(e.errors).to.have.a.lengthOf(1);
603
- const [error] = e.errors;
604
- expect(error.name).to.equal('JsonSchemaError');
605
- expect(error.keyword).to.equal('maxItems');
606
- expect(error.instancePath).to.equal('/encryptedAccountLabel');
607
- }
403
+ expect(error.keyword).to.equal('maxItems');
404
+ expect(error.instancePath).to.deep.equal('/encryptedAccountLabel');
608
405
  });
609
406
 
610
407
  it('should be of type array', async () => {
611
408
  contactRequestData.encryptedAccountLabel = 'notAnArray';
612
- try {
613
- dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
614
-
615
- expect.fail('should throw error');
616
- } catch (e) {
617
- expect(e.name).to.equal('InvalidDocumentError');
618
- expect(e.errors).to.have.a.lengthOf(1);
619
- const [error] = e.errors;
620
- expect(error.name).to.equal('JsonSchemaError');
621
- expect(error.keyword).to.equal('type');
622
- expect(error.instancePath).to.equal('/encryptedAccountLabel');
623
- }
409
+
410
+ const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
411
+ const validationResult = document.validate(dpp.protocolVersion);
412
+ const error = expectJsonSchemaError(validationResult);
413
+
414
+ expect(error.keyword).to.equal('type');
415
+ expect(error.instancePath).to.deep.equal('/encryptedAccountLabel');
624
416
  });
625
417
  });
626
418
 
@@ -628,52 +420,34 @@ describe.skip('Dashpay Contract', () => {
628
420
  it('should have minimum length of 38', async () => {
629
421
  contactRequestData.autoAcceptProof = Buffer.alloc(0);
630
422
 
631
- try {
632
- dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
423
+ const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
424
+ const validationResult = document.validate(dpp.protocolVersion);
425
+ const error = expectJsonSchemaError(validationResult);
633
426
 
634
- expect.fail('should throw error');
635
- } catch (e) {
636
- expect(e.name).to.equal('InvalidDocumentError');
637
- expect(e.errors).to.have.a.lengthOf(1);
638
- const [error] = e.errors;
639
- expect(error.name).to.equal('JsonSchemaError');
640
- expect(error.keyword).to.equal('minItems');
641
- expect(error.instancePath).to.equal('/autoAcceptProof');
642
- }
427
+ expect(error.keyword).to.equal('minItems');
428
+ expect(error.instancePath).to.deep.equal('/autoAcceptProof');
643
429
  });
644
430
 
645
431
  it('should have maximum length of 102', async () => {
646
432
  contactRequestData.autoAcceptProof = Buffer.alloc(104);
647
433
 
648
- try {
649
- dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
434
+ const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
435
+ const validationResult = document.validate(dpp.protocolVersion);
436
+ const error = expectJsonSchemaError(validationResult);
650
437
 
651
- expect.fail('should throw error');
652
- } catch (e) {
653
- expect(e.name).to.equal('InvalidDocumentError');
654
- expect(e.errors).to.have.a.lengthOf(1);
655
- const [error] = e.errors;
656
- expect(error.name).to.equal('JsonSchemaError');
657
- expect(error.keyword).to.equal('maxItems');
658
- expect(error.instancePath).to.equal('/autoAcceptProof');
659
- }
438
+ expect(error.keyword).to.equal('maxItems');
439
+ expect(error.instancePath).to.deep.equal('/autoAcceptProof');
660
440
  });
661
441
 
662
442
  it('should be of type array', async () => {
663
443
  contactRequestData.autoAcceptProof = 'notAnArray';
664
444
 
665
- try {
666
- dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
445
+ const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
446
+ const validationResult = document.validate(dpp.protocolVersion);
447
+ const error = expectJsonSchemaError(validationResult);
667
448
 
668
- expect.fail('should throw error');
669
- } catch (e) {
670
- expect(e.name).to.equal('InvalidDocumentError');
671
- expect(e.errors).to.have.a.lengthOf(1);
672
- const [error] = e.errors;
673
- expect(error.name).to.equal('JsonSchemaError');
674
- expect(error.keyword).to.equal('type');
675
- expect(error.instancePath).to.equal('/autoAcceptProof');
676
- }
449
+ expect(error.keyword).to.equal('type');
450
+ expect(error.instancePath).to.deep.equal('/autoAcceptProof');
677
451
  });
678
452
  });
679
453
 
@@ -681,35 +455,23 @@ describe.skip('Dashpay Contract', () => {
681
455
  it('should be defined', async () => {
682
456
  delete contactRequestData.accountReference;
683
457
 
684
- try {
685
- dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
458
+ const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
459
+ const validationResult = document.validate(dpp.protocolVersion);
460
+ const error = expectJsonSchemaError(validationResult);
686
461
 
687
- expect.fail('should throw error');
688
- } catch (e) {
689
- expect(e.name).to.equal('InvalidDocumentError');
690
- expect(e.errors).to.have.a.lengthOf(1);
691
- const [error] = e.errors;
692
- expect(error.name).to.equal('JsonSchemaError');
693
- expect(error.keyword).to.equal('required');
694
- expect(error.params.missingProperty).to.equal('accountReference');
695
- }
462
+ expect(error.keyword).to.equal('required');
463
+ expect(error.params.missingProperty).to.equal('accountReference');
696
464
  });
697
465
 
698
466
  it('should not be less than 0', async () => {
699
467
  contactRequestData.accountReference = -1;
700
468
 
701
- try {
702
- dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
469
+ const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
470
+ const validationResult = document.validate(dpp.protocolVersion);
471
+ const error = expectJsonSchemaError(validationResult);
703
472
 
704
- expect.fail('should throw error');
705
- } catch (e) {
706
- expect(e.name).to.equal('InvalidDocumentError');
707
- expect(e.errors).to.have.a.lengthOf(1);
708
- const [error] = e.errors;
709
- expect(error.name).to.equal('JsonSchemaError');
710
- expect(error.keyword).to.equal('minimum');
711
- expect(error.instancePath).to.equal('/accountReference');
712
- }
473
+ expect(error.keyword).to.equal('minimum');
474
+ expect(error.instancePath).to.equal('/accountReference');
713
475
  });
714
476
  });
715
477
 
@@ -717,38 +479,24 @@ describe.skip('Dashpay Contract', () => {
717
479
  it('should not be less than 1', async () => {
718
480
  contactRequestData.coreHeightCreatedAt = -1;
719
481
 
720
- try {
721
- dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
482
+ const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
483
+ const validationResult = document.validate(dpp.protocolVersion);
484
+ const error = expectJsonSchemaError(validationResult);
722
485
 
723
- expect.fail('should throw error');
724
- } catch (e) {
725
- expect(e.name).to.equal('InvalidDocumentError');
726
- expect(e.errors).to.have.a.lengthOf(1);
727
- const [error] = e.errors;
728
- expect(error.name).to.equal('JsonSchemaError');
729
- expect(error.keyword).to.equal('minimum');
730
- expect(error.instancePath).to.equal('/coreHeightCreatedAt');
731
- }
486
+ expect(error.keyword).to.equal('minimum');
487
+ expect(error.instancePath).to.equal('/coreHeightCreatedAt');
732
488
  });
733
489
  });
734
490
 
735
491
  it('should not have additional properties', async () => {
736
492
  contactRequestData.someOtherProperty = 42;
737
493
 
738
- try {
739
- dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
740
-
741
- expect.fail('should throw error');
742
- } catch (e) {
743
- expect(e.name).to.equal('InvalidDocumentError');
744
- expect(e.errors).to.have.a.lengthOf(1);
745
-
746
- const [error] = e.errors;
494
+ const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
495
+ const validationResult = document.validate(dpp.protocolVersion);
496
+ const error = expectJsonSchemaError(validationResult);
747
497
 
748
- expect(error.name).to.equal('JsonSchemaError');
749
- expect(error.keyword).to.equal('additionalProperties');
750
- expect(error.params.additionalProperty).to.equal('someOtherProperty');
751
- }
498
+ expect(error.keyword).to.equal('additionalProperties');
499
+ expect(error.params.additionalProperties).to.deep.equal(['someOtherProperty']);
752
500
  });
753
501
  });
754
502
  });