@dashevo/dashpay-contract 1.0.0-pr.1902.1 → 1.0.0-pr.1935.A

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
@@ -1,7 +1,7 @@
1
1
  [package]
2
2
  name = "dashpay-contract"
3
3
  description = "DashPay data contract schema and tools"
4
- version = "1.0.0-pr.1902.1"
4
+ version = "1.0.0-pr.1935.A"
5
5
  edition = "2021"
6
6
  rust-version = "1.76"
7
7
  license = "MIT"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dashevo/dashpay-contract",
3
- "version": "1.0.0-pr.1902.1",
3
+ "version": "1.0.0-pr.1935.A",
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/wasm-dpp": "1.0.0-pr.1902.1",
28
+ "@dashevo/wasm-dpp": "1.0.0-pr.1935.A",
29
29
  "chai": "^4.3.10",
30
30
  "dirty-chai": "^2.0.1",
31
31
  "eslint": "^8.53.0",
@@ -27,6 +27,7 @@
27
27
  "avatarUrl": {
28
28
  "type": "string",
29
29
  "format": "uri",
30
+ "minLength": 1,
30
31
  "maxLength": 2048,
31
32
  "position": 0
32
33
  },
@@ -48,15 +49,23 @@
48
49
  },
49
50
  "publicMessage": {
50
51
  "type": "string",
52
+ "minLength": 1,
51
53
  "maxLength": 140,
52
54
  "position": 3
53
55
  },
54
56
  "displayName": {
55
57
  "type": "string",
58
+ "minLength": 1,
56
59
  "maxLength": 25,
57
60
  "position": 4
58
61
  }
59
62
  },
63
+ "minProperties": 1,
64
+ "dependentRequired": {
65
+ "avatarUrl": ["avatarHash", "avatarFingerprint"],
66
+ "avatarHash": ["avatarUrl", "avatarFingerprint"],
67
+ "avatarFingerprint": ["avatarUrl", "avatarHash"]
68
+ },
60
69
  "required": [
61
70
  "$createdAt",
62
71
  "$updatedAt"
@@ -230,15 +239,11 @@
230
239
  "minItems": 38,
231
240
  "maxItems": 102,
232
241
  "position": 6
233
- },
234
- "coreHeightCreatedAt": {
235
- "type": "integer",
236
- "minimum": 1,
237
- "position": 7
238
242
  }
239
243
  },
240
244
  "required": [
241
245
  "$createdAt",
246
+ "$createdAtCoreBlockHeight",
242
247
  "toUserId",
243
248
  "encryptedPublicKey",
244
249
  "senderKeyIndex",
package/src/v1/mod.rs CHANGED
@@ -7,8 +7,6 @@ pub mod document_types {
7
7
 
8
8
  pub mod properties {
9
9
  pub const TO_USER_ID: &str = "toUserId";
10
- pub const CORE_HEIGHT_CREATED_AT: &str = "coreHeightCreatedAt";
11
- pub const CORE_CHAIN_LOCKED_HEIGHT: &str = "coreChainLockedHeight";
12
10
  }
13
11
  }
14
12
  }
@@ -11,14 +11,14 @@ const whitepaperMasternodeText = 'Full nodes are servers running on a P2P networ
11
11
  const encoded32Chars = '4fafc98bbfe597f7ba2c9f767d52036d';
12
12
  const encoded64Chars = '4fafc98bbfe597f7ba2c9f767d52036d2226175960a908e355e5c575711eb166';
13
13
 
14
- const expectJsonSchemaError = (validationResult) => {
14
+ const expectJsonSchemaError = (validationResult, count = 1, index = 0) => {
15
15
  const errors = validationResult.getErrors();
16
16
  expect(errors)
17
17
  .to
18
18
  .have
19
- .length(1);
19
+ .length(count);
20
20
 
21
- const error = validationResult.getErrors()[0];
21
+ const error = validationResult.getErrors()[index];
22
22
  expect(error)
23
23
  .to
24
24
  .be
@@ -55,7 +55,6 @@ describe('Dashpay Contract', () => {
55
55
  beforeEach(() => {
56
56
  profileData = {
57
57
  displayName: 'Bob',
58
- publicMessage: 'Hello Dashpay!',
59
58
  };
60
59
  });
61
60
 
@@ -97,11 +96,15 @@ describe('Dashpay Contract', () => {
97
96
 
98
97
  describe('avatarUrl', () => {
99
98
  it('should not be empty', async () => {
100
- profileData.avatarUrl = '';
99
+ profileData = {
100
+ avatarUrl: '',
101
+ avatarHash: Buffer.alloc(32),
102
+ avatarFingerprint: Buffer.alloc(8),
103
+ };
101
104
 
102
105
  const document = dpp.document.create(contract, identityId, 'profile', profileData);
103
106
  const validationResult = document.validate(dpp.protocolVersion);
104
- const error = expectJsonSchemaError(validationResult);
107
+ const error = expectJsonSchemaError(validationResult, 2);
105
108
 
106
109
  expect(error.keyword)
107
110
  .to
@@ -113,7 +116,11 @@ describe('Dashpay Contract', () => {
113
116
  });
114
117
 
115
118
  it('should have less than 2048 chars length', async () => {
116
- profileData.avatarUrl = `https://github.com/dashpay/dash/wiki/Whitepaper?text=${encodeURI(whitepaperMasternodeText)}${encodeURI(whitepaperMasternodeText)}${encodeURI(whitepaperMasternodeText)}${encodeURI(whitepaperMasternodeText)}${encodeURI(whitepaperMasternodeText)}`;
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
+ };
117
124
 
118
125
  const document = dpp.document.create(contract, identityId, 'profile', profileData);
119
126
  const validationResult = document.validate(dpp.protocolVersion);
@@ -129,7 +136,11 @@ describe('Dashpay Contract', () => {
129
136
  });
130
137
 
131
138
  it('should be of type URL', async () => {
132
- profileData.avatarUrl = 'notAUrl';
139
+ profileData = {
140
+ avatarUrl: 'notAUrl',
141
+ avatarHash: Buffer.alloc(32),
142
+ avatarFingerprint: Buffer.alloc(8),
143
+ };
133
144
 
134
145
  const document = dpp.document.create(contract, identityId, 'profile', profileData);
135
146
  const validationResult = document.validate(dpp.protocolVersion);
@@ -143,11 +154,44 @@ describe('Dashpay Contract', () => {
143
154
  .deep
144
155
  .equal('/avatarUrl');
145
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
+ });
146
186
  });
147
187
 
148
188
  describe('avatarHash', () => {
149
189
  it('should have minimum length of 32', async () => {
150
- profileData.avatarHash = Buffer.alloc(0);
190
+ profileData = {
191
+ avatarUrl: 'https://github.com/dashpay/dash.jpg',
192
+ avatarHash: Buffer.alloc(0),
193
+ avatarFingerprint: Buffer.alloc(8),
194
+ };
151
195
 
152
196
  const document = dpp.document.create(contract, identityId, 'profile', profileData);
153
197
  const validationResult = document.validate(dpp.protocolVersion);
@@ -163,7 +207,11 @@ describe('Dashpay Contract', () => {
163
207
  });
164
208
 
165
209
  it('should have maximum length of 32', async () => {
166
- profileData.avatarHash = Buffer.alloc(33);
210
+ profileData = {
211
+ avatarUrl: 'https://github.com/dashpay/dash.jpg',
212
+ avatarHash: Buffer.alloc(33),
213
+ avatarFingerprint: Buffer.alloc(8),
214
+ };
167
215
 
168
216
  const document = dpp.document.create(contract, identityId, 'profile', profileData);
169
217
  const validationResult = document.validate(dpp.protocolVersion);
@@ -179,7 +227,11 @@ describe('Dashpay Contract', () => {
179
227
  });
180
228
 
181
229
  it('should be of type array', async () => {
182
- profileData.avatarHash = 'notAnArray';
230
+ profileData = {
231
+ avatarUrl: 'https://github.com/dashpay/dash.jpg',
232
+ avatarHash: 'notAnArray',
233
+ avatarFingerprint: Buffer.alloc(8),
234
+ };
183
235
 
184
236
  const document = dpp.document.create(contract, identityId, 'profile', profileData);
185
237
  const validationResult = document.validate(dpp.protocolVersion);
@@ -193,11 +245,44 @@ describe('Dashpay Contract', () => {
193
245
  .deep
194
246
  .equal('/avatarHash');
195
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
+ });
196
277
  });
197
278
 
198
279
  describe('avatarFingerprint', () => {
199
280
  it('should have minimum length of 8', async () => {
200
- profileData.avatarFingerprint = Buffer.alloc(0);
281
+ profileData = {
282
+ avatarUrl: 'https://github.com/dashpay/dash.jpg',
283
+ avatarHash: Buffer.alloc(32),
284
+ avatarFingerprint: Buffer.alloc(0),
285
+ };
201
286
 
202
287
  const document = dpp.document.create(contract, identityId, 'profile', profileData);
203
288
  const validationResult = document.validate(dpp.protocolVersion);
@@ -213,7 +298,11 @@ describe('Dashpay Contract', () => {
213
298
  });
214
299
 
215
300
  it('should have maximum length of 8', async () => {
216
- profileData.avatarFingerprint = Buffer.alloc(33);
301
+ profileData = {
302
+ avatarUrl: 'https://github.com/dashpay/dash.jpg',
303
+ avatarHash: Buffer.alloc(32),
304
+ avatarFingerprint: Buffer.alloc(33),
305
+ };
217
306
 
218
307
  const document = dpp.document.create(contract, identityId, 'profile', profileData);
219
308
  const validationResult = document.validate(dpp.protocolVersion);
@@ -229,7 +318,11 @@ describe('Dashpay Contract', () => {
229
318
  });
230
319
 
231
320
  it('should be of type array', async () => {
232
- profileData.avatarFingerprint = 'notAnArray';
321
+ profileData = {
322
+ avatarUrl: 'https://github.com/dashpay/dash.jpg',
323
+ avatarHash: Buffer.alloc(32),
324
+ avatarFingerprint: 'notAnArray',
325
+ };
233
326
 
234
327
  const document = dpp.document.create(contract, identityId, 'profile', profileData);
235
328
  const validationResult = document.validate(dpp.protocolVersion);
@@ -243,6 +336,35 @@ describe('Dashpay Contract', () => {
243
336
  .deep
244
337
  .equal('/avatarFingerprint');
245
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
+ });
246
368
  });
247
369
 
248
370
  it('should not have additional properties', async () => {
@@ -261,6 +383,18 @@ describe('Dashpay Contract', () => {
261
383
  .equal(['someOtherProperty']);
262
384
  });
263
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
+
264
398
  it('should be valid', async () => {
265
399
  const profile = dpp.document.create(contract, identityId, 'profile', profileData);
266
400
 
@@ -641,23 +775,6 @@ describe('Dashpay Contract', () => {
641
775
  });
642
776
  });
643
777
 
644
- describe('coreHeightCreatedAt', () => {
645
- it('should not be less than 1', async () => {
646
- contactRequestData.coreHeightCreatedAt = -1;
647
-
648
- const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
649
- const validationResult = document.validate(dpp.protocolVersion);
650
- const error = expectJsonSchemaError(validationResult);
651
-
652
- expect(error.keyword)
653
- .to
654
- .equal('minimum');
655
- expect(error.instancePath)
656
- .to
657
- .equal('/coreHeightCreatedAt');
658
- });
659
- });
660
-
661
778
  it('should not have additional properties', async () => {
662
779
  contactRequestData.someOtherProperty = 42;
663
780