@dashevo/wasm-dpp 0.25.8 → 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 +3 -2
- package/README.md +1 -1
- package/dist/wasm/wasm_dpp.d.ts +808 -712
- package/dist/wasm/wasm_dpp.js +853 -452
- package/dist/wasm/wasm_dpp_bg.js +1 -1
- package/lib/bls/bls.js +48 -0
- package/lib/test/fixtures/getChainAssetLockProofFixture.js +20 -1
- package/lib/test/fixtures/getDataContractFixture.js +4 -6
- package/lib/test/fixtures/getDocumentTransitionsFixture.js +31 -1
- package/lib/test/fixtures/getInstantAssetLockProofFixture.js +32 -12
- package/lib/test/mocks/getBlsAdapterMock.js +1 -1
- package/lib/utils/creditsConverter.js +14 -0
- package/lib/utils/hash.js +18 -0
- package/lib/wasm/wasm_dpp.d.ts +808 -712
- package/package.json +3 -5
- package/src/dash_platform_protocol.rs +5 -5
- package/src/document/errors/invalid_document_error.rs +5 -0
- package/src/document/extended_document.rs +15 -0
- package/src/document/state_transition/document_batch_transition/document_transition/document_create_transition.rs +219 -214
- package/src/document/state_transition/document_batch_transition/document_transition/mod.rs +1 -1
- package/src/errors/consensus/basic/identity/identity_insufficient_balance_error.rs +4 -2
- package/src/errors/consensus/basic/json_schema_error.rs +35 -5
- package/src/identity/identity_facade.rs +7 -5
- package/src/identity/state_transition/asset_lock_proof/chain/chain_asset_lock_proof.rs +32 -17
- package/src/identity/state_transition/asset_lock_proof/instant/instant_asset_lock_proof.rs +22 -13
- package/src/identity/state_transition/asset_lock_proof/mod.rs +12 -11
- package/src/identity/state_transition/identity_create_transition/identity_create_transition.rs +1 -0
- package/src/identity/state_transition/identity_create_transition/to_object.rs +1 -0
- package/src/identity/state_transition/identity_topup_transition/identity_topup_transition.rs +1 -0
- package/src/identity/state_transition/identity_topup_transition/to_object.rs +1 -0
- package/src/lib.rs +1 -1
- package/src/validation/mod.rs +2 -2
- package/src/validation/validation_result.rs +16 -15
- package/test/integration/document/DocumentFacade.spec.js +11 -27
- package/test/integration/document/stateTransition/DocumentsBatchTransition/DocumentBatchTransition.spec.js +9 -19
- package/test/integration/document/stateTransition/DocumentsBatchTransition/validation/basic/validateDocumentsBatchTransitionBasicFactory.spec.js +2 -2
- package/test/integration/document/validation/validateDocumentFactory.spec.js +2 -2
- package/test/integration/identity/IdentityFacade.spec.js +1 -2
- package/test/integration/identity/stateTransition/assetLockProof/instant/validateInstantAssetLockProofStructureFactory.spec.js +2 -2
- package/test/integration/identity/stateTransition/validatePublicKeySignaturesFactory.spec.js +2 -2
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/DataContractUpdateTransition.spec.js +6 -8
- package/test/unit/document/Document.spec.js +30 -52
- package/test/unit/document/DocumentFactory.spec.js +2 -2
- package/test/unit/document/errors/InvalidDocumentError.spec.js +9 -9
- package/test/unit/document/stateTransition/DocumetsBatchTransition/DocumentsBatchTransition.spec.js +158 -155
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/basic/findDuplicatesByIndices.spec.js +132 -134
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/basic/validatePartialCompoundIndices.spec.js +3 -3
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/validateDocumentsBatchTransitionStateFactory.spec.js +568 -591
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/validateDocumentsUniquenessByIndicesFactory.spec.js +5 -13
- package/test/unit/identity/Identity.spec.js +2 -2
- package/test/unit/identity/stateTransition/assetLockProof/ChainAssetLockProof.spec.js +9 -28
- package/test/unit/identity/stateTransition/assetLockProof/InstantAssetLockProof.spec.js +19 -27
- package/lib/test/fixtures/getDashPayContractFixture.js +0 -1
- package/lib/test/fixtures/getDashPayDocumentFixture.js +0 -1
- package/lib/test/fixtures/getDpnsContractFixture.js +0 -1
- package/lib/test/fixtures/getDpnsDocumentFixture.js +0 -1
- package/lib/test/fixtures/getFeatureFlagsContractFixture.js +0 -1
- package/lib/test/fixtures/getFeatureFlagsDocumentsFixture.js +0 -1
- package/lib/test/fixtures/getIdentityTopUpTransitionFixtureJs.js +0 -1
- package/lib/test/fixtures/getMasternodeRewardShareDocumentsFixture.js +0 -1
- package/lib/test/fixtures/getMasternodeRewardSharesContractFixture.js +0 -1
- package/lib/test/fixtures/getPreorderDocumentFixture.js +0 -1
- package/lib/test/fixtures/getRawTransactionFixture.js +0 -1
- package/lib/test/fixtures/js/generateRandomIdentifier.js +0 -1
- package/lib/test/fixtures/js/getChainAssetLockProofFixture.js +0 -1
- package/lib/test/fixtures/js/getDataContractFixture.js +0 -1
- package/lib/test/fixtures/js/getDocumentTransitionsFixture.js +0 -1
- package/lib/test/fixtures/js/getDocumentsFixture.js +0 -1
- package/lib/test/fixtures/js/getInstantAssetLockProofFixture.js +0 -1
- package/test/integration/DashPlatformProtocol.spec.js +0 -53
- package/test/integration/document/stateTransition/DocumentsBatchTransition/validation/state/executeDataTriggersFactory.spec.js +0 -195
- package/test/integration/stateTransition/AbstractStateTransitionIdentitySigned.spec.js +0 -500
- package/test/integration/stateTransition/calculateStateTransitionFeeFromOperationsFactory.spec.js +0 -53
- package/test/unit/dataContract/getBinaryPropertiesFromSchema.spec.js +0 -103
- package/test/unit/dataContract/getPropertyDefinitionByPath.spec.js +0 -84
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/applyDataContractCreateTransitionFactory.spec.js +0 -45
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/applyDataContractUpdateTransitionFactory.spec.js +0 -49
- package/test/unit/dataTrigger/DataTrigger.spec.js +0 -132
- package/test/unit/dataTrigger/DataTriggerExecutionContext.spec.js +0 -29
- package/test/unit/dataTrigger/dashpayDataTriggers/createContactRequestDataTrigger.spec.js +0 -107
- package/test/unit/dataTrigger/dpnsTriggers/createDomainDataTrigger.spec.js +0 -382
- package/test/unit/dataTrigger/featureFlagDataTriggers/createFeatureFlagDataTrigger.spec.js +0 -99
- package/test/unit/dataTrigger/getDataTriggersFactory.spec.js +0 -113
- package/test/unit/dataTrigger/rejectDataTrigger.spec.js +0 -51
- package/test/unit/dataTrigger/rewardShareDataTriggers/createMasternodeRewardSharesDataTrigger.spec.js +0 -202
- package/test/unit/document/stateTransition/DocumetsBatchTransition/applyDocumentsBatchTransitionFactory.spec.js +0 -256
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/fetchDocumentsFactory.spec.js +0 -94
- package/test/unit/errors/consensus/codes.spec.js +0 -102
- package/test/unit/identity/creditsConverter.spec.js +0 -34
- package/test/unit/identity/stateTransition/IdentityCreateTransition/applyIdentityCreateTransitionFactory.spec.js +0 -83
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/applyIdentityTopUpTransitionFactory.spec.js +0 -138
- package/test/unit/identity/stateTransition/IdentityUpdateTransition/applyIdentityUpdateTransitionFactory.spec.js +0 -100
- package/test/unit/identity/stateTransition/assetLockProof/createAssetLockProofInstance.spec.js +0 -36
- package/test/unit/identity/stateTransition/assetLockProof/fetchAssetLockPublicKeyHashFactory.spec.js +0 -63
- package/test/unit/identity/validation/validateRequiredPurposeAndSecurityLevelFactory.spec.js +0 -47
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const DataTriggerExecutionResult = require('@dashevo/dpp/lib/dataTrigger/DataTriggerExecutionResult');
|
|
4
|
-
const ValidationResultJs = require('@dashevo/dpp/lib/validation/ValidationResult');
|
|
5
|
-
const StateTransitionExecutionContextJs = require('@dashevo/dpp/lib/stateTransition/StateTransitionExecutionContext');
|
|
6
|
-
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
// TODO: fix this test?
|
|
7
3
|
const generateRandomIdentifier = require('../../../../../../../lib/test/utils/generateRandomIdentifierAsync');
|
|
8
|
-
const getDataContractFixture = require('../../../../../../../lib/test/fixtures/
|
|
9
|
-
const getDocumentsFixture = require('../../../../../../../lib/test/fixtures/
|
|
4
|
+
const getDataContractFixture = require('../../../../../../../lib/test/fixtures/getDataContractFixture');
|
|
5
|
+
const getDocumentsFixture = require('../../../../../../../lib/test/fixtures/getDocumentsFixture');
|
|
10
6
|
const getDocumentTransitionsFixture = require('../../../../../../../lib/test/fixtures/getDocumentTransitionsFixture');
|
|
11
7
|
const createStateRepositoryMock = require('../../../../../../../lib/test/mocks/createStateRepositoryMock');
|
|
12
8
|
|
|
@@ -34,15 +30,14 @@ describe.skip('validateDocumentsBatchTransitionStateFactory', () => {
|
|
|
34
30
|
let documents;
|
|
35
31
|
let dataContractJs;
|
|
36
32
|
let dataContract;
|
|
37
|
-
let
|
|
33
|
+
let ownerId;
|
|
38
34
|
let validateDocumentsUniquenessByIndicesMock;
|
|
39
35
|
let stateRepositoryMockJs;
|
|
40
36
|
let stateRepositoryMock;
|
|
41
37
|
let executeDataTriggersMock;
|
|
42
|
-
let
|
|
38
|
+
let documentTransitions;
|
|
43
39
|
let fakeTime;
|
|
44
40
|
let blockTime;
|
|
45
|
-
let executionContextJs;
|
|
46
41
|
let executionContext;
|
|
47
42
|
|
|
48
43
|
beforeEach(async function beforeEach() {
|
|
@@ -63,41 +58,23 @@ describe.skip('validateDocumentsBatchTransitionStateFactory', () => {
|
|
|
63
58
|
DocumentTimestampWindowViolationError,
|
|
64
59
|
} = await loadWasmDpp());
|
|
65
60
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
documentsJs = getDocumentsFixture(dataContractJs);
|
|
70
|
-
documents = documentsJs.map((d) => {
|
|
71
|
-
const doc = new ExtendedDocument(d.toObject(), dataContract);
|
|
72
|
-
doc.setEntropy(d.entropy);
|
|
73
|
-
return doc;
|
|
74
|
-
});
|
|
75
|
-
ownerIdJs = getDocumentsFixture.ownerId;
|
|
61
|
+
dataContract = await getDataContractFixture();
|
|
62
|
+
documents = await getDocumentsFixture(dataContract);
|
|
63
|
+
ownerId = getDocumentsFixture.ownerId;
|
|
76
64
|
|
|
77
|
-
|
|
78
|
-
create:
|
|
65
|
+
documentTransitions = await getDocumentTransitionsFixture({
|
|
66
|
+
create: documents,
|
|
79
67
|
});
|
|
80
68
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
69
|
+
stateTransition = new DocumentsBatchTransition();
|
|
70
|
+
// TODO: add method
|
|
71
|
+
// stateTransition.setOwnerId(ownerId)
|
|
72
|
+
stateTransition.setTransitions(documentTransitions);
|
|
85
73
|
|
|
86
|
-
stateTransition = new DocumentsBatchTransition({
|
|
87
|
-
ownerId: ownerIdJs,
|
|
88
|
-
transitions: documentTransitionsJs.map((t) => t.toObject()),
|
|
89
|
-
}, [dataContract.clone()]);
|
|
90
|
-
|
|
91
|
-
executionContextJs = new StateTransitionExecutionContextJs();
|
|
92
74
|
executionContext = new StateTransitionExecutionContext();
|
|
93
75
|
|
|
94
|
-
stateTransitionJs.setExecutionContext(executionContextJs);
|
|
95
|
-
|
|
96
76
|
stateRepositoryMock = createStateRepositoryMock(this.sinonSandbox);
|
|
97
|
-
stateRepositoryMockJs = createStateRepositoryMock(this.sinonSandbox);
|
|
98
|
-
|
|
99
77
|
stateRepositoryMock.fetchDataContract.resolves(dataContract.clone());
|
|
100
|
-
stateRepositoryMockJs.fetchDataContract.resolves(dataContractJs);
|
|
101
78
|
|
|
102
79
|
blockTime = Date.now();
|
|
103
80
|
|
|
@@ -119,557 +96,557 @@ describe.skip('validateDocumentsBatchTransitionStateFactory', () => {
|
|
|
119
96
|
fakeTime.reset();
|
|
120
97
|
});
|
|
121
98
|
|
|
122
|
-
it('should throw DataContractNotPresentError if data contract was not found - Rust', async () => {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it('should return invalid result if document transition with action "create" is already present - Rust', async () => {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it('should return invalid result if document transition with action "replace" is not present - Rust', async () => {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
it('should return invalid result if document transition with action "delete" is not present - Rust', async () => {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
it('should return invalid result if document transition with action "replace" has wrong revision - Rust', async () => {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
it('should return invalid result if document transition with action "replace" has mismatch of ownerId with previous revision - Rust', async () => {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
it('should throw an error if document transition has invalid action - Rust', async () => {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
it('should return invalid result if there are duplicate document transitions according to unique indices - Rust', async () => {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
});
|
|
315
|
-
|
|
316
|
-
it('should return invalid result if data triggers execution failed - Rust', async () => {
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
});
|
|
320
|
-
|
|
321
|
-
it('should return invalid result if data triggers execution failed', async () => {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
describe('Timestamps', () => {
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
});
|
|
601
|
-
|
|
602
|
-
it('should return valid result if document transitions are valid - Rust', async () => {
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
});
|
|
638
|
-
|
|
639
|
-
it('should return valid result if document transitions are valid - Rust', async () => {
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
});
|
|
99
|
+
// it('should throw DataContractNotPresentError if data contract was not found - Rust', async () => {
|
|
100
|
+
// stateRepositoryMock.fetchDataContract.resolves(null);
|
|
101
|
+
//
|
|
102
|
+
// try {
|
|
103
|
+
// await validateDocumentsBatchTransitionState(
|
|
104
|
+
// stateRepositoryMock, stateTransition, executionContext,
|
|
105
|
+
// );
|
|
106
|
+
//
|
|
107
|
+
// expect.fail('should throw DataContractNotPresentError');
|
|
108
|
+
// } catch (e) {
|
|
109
|
+
// expect(e).to.be.instanceOf(DataContractNotPresentNotConsensusError);
|
|
110
|
+
//
|
|
111
|
+
// expect(e.getDataContractId()).to.deep.equal(dataContract.getId().toBuffer());
|
|
112
|
+
//
|
|
113
|
+
// expect(stateRepositoryMock.fetchDataContract).to.have.been.calledOnce();
|
|
114
|
+
// const [fetchDataContractId] = stateRepositoryMock.fetchDataContract.getCall(0).args;
|
|
115
|
+
// expect(fetchDataContractId.toBuffer()).to.deep.equal(dataContract.getId().toBuffer());
|
|
116
|
+
// }
|
|
117
|
+
// });
|
|
118
|
+
//
|
|
119
|
+
// it('should return invalid result if document transition with action "create" is already present - Rust', async () => {
|
|
120
|
+
// stateRepositoryMock.fetchDocuments.resolves([documents[0].getDocument()]);
|
|
121
|
+
//
|
|
122
|
+
// const result = await validateDocumentsBatchTransitionState(
|
|
123
|
+
// stateRepositoryMock, stateTransition, executionContext,
|
|
124
|
+
// );
|
|
125
|
+
//
|
|
126
|
+
// expect(result.isValid()).is.not.true();
|
|
127
|
+
//
|
|
128
|
+
// const [error] = result.getErrors();
|
|
129
|
+
//
|
|
130
|
+
// expect(error.getCode()).to.equal(4004);
|
|
131
|
+
// expect(error.getDocumentId()).to.deep.equal(documentTransitionsJs[0].getId().toBuffer());
|
|
132
|
+
//
|
|
133
|
+
// expect(stateRepositoryMock.fetchDataContract).to.have.been.calledOnce();
|
|
134
|
+
// const [fetchDataContractId] = stateRepositoryMock.fetchDataContract.getCall(0).args;
|
|
135
|
+
// expect(fetchDataContractId.toBuffer()).to.deep.equal(dataContract.getId().toBuffer());
|
|
136
|
+
// });
|
|
137
|
+
//
|
|
138
|
+
// it('should return invalid result if document transition with action "replace" is not present - Rust', async () => {
|
|
139
|
+
// documentTransitionsJs = getDocumentTransitionsFixture({
|
|
140
|
+
// create: [],
|
|
141
|
+
// replace: [documentsJs[0]],
|
|
142
|
+
// });
|
|
143
|
+
//
|
|
144
|
+
// stateTransition = new DocumentsBatchTransition({
|
|
145
|
+
// ownerId: ownerIdJs,
|
|
146
|
+
// contractId: dataContractJs.getId(),
|
|
147
|
+
// transitions: documentTransitionsJs.map((t) => t.toObject()),
|
|
148
|
+
// }, [dataContract]);
|
|
149
|
+
//
|
|
150
|
+
// const result = await validateDocumentsBatchTransitionState(
|
|
151
|
+
// stateRepositoryMock, stateTransition, executionContext,
|
|
152
|
+
// );
|
|
153
|
+
// expect(result).is.instanceOf(ValidationResult);
|
|
154
|
+
//
|
|
155
|
+
// const [error] = result.getErrors();
|
|
156
|
+
// expect(error).is.instanceOf(DocumentNotFoundError);
|
|
157
|
+
// expect(error.getCode()).to.equal(4005);
|
|
158
|
+
// expect(error.getDocumentId()).to.deep.equal(documentTransitionsJs[0].getId().toBuffer());
|
|
159
|
+
//
|
|
160
|
+
// expect(stateRepositoryMock.fetchDataContract).to.have.been.calledOnce();
|
|
161
|
+
// const [fetchDataContractId] = stateRepositoryMock.fetchDataContract.getCall(0).args;
|
|
162
|
+
// expect(fetchDataContractId.toBuffer()).to.deep.equal(dataContract.getId().toBuffer());
|
|
163
|
+
//
|
|
164
|
+
// expect(stateRepositoryMock.fetchDocuments)
|
|
165
|
+
// .to.have.been.callCount(documentTransitionsJs.length);
|
|
166
|
+
// });
|
|
167
|
+
//
|
|
168
|
+
// it('should return invalid result if document transition with action "delete" is not present - Rust', async () => {
|
|
169
|
+
// documentTransitionsJs = getDocumentTransitionsFixture({
|
|
170
|
+
// create: [],
|
|
171
|
+
// delete: [documentsJs[0]],
|
|
172
|
+
// });
|
|
173
|
+
//
|
|
174
|
+
// stateTransition = new DocumentsBatchTransition({
|
|
175
|
+
// ownerId: ownerIdJs,
|
|
176
|
+
// contractId: dataContractJs.getId(),
|
|
177
|
+
// transitions: documentTransitionsJs.map((t) => t.toObject()),
|
|
178
|
+
// }, [dataContract]);
|
|
179
|
+
//
|
|
180
|
+
// const result = await validateDocumentsBatchTransitionState(
|
|
181
|
+
// stateRepositoryMock, stateTransition, executionContext,
|
|
182
|
+
// );
|
|
183
|
+
//
|
|
184
|
+
// expect(result).is.instanceOf(ValidationResult);
|
|
185
|
+
//
|
|
186
|
+
// const [error] = result.getErrors();
|
|
187
|
+
// expect(error).is.instanceOf(DocumentNotFoundError);
|
|
188
|
+
// expect(error.getCode()).to.equal(4005);
|
|
189
|
+
// expect(error.getDocumentId()).to.deep.equal(documentTransitionsJs[0].getId().toBuffer());
|
|
190
|
+
//
|
|
191
|
+
// expect(stateRepositoryMock.fetchDataContract).to.have.been.calledOnce();
|
|
192
|
+
// const [fetchDataContractId] = stateRepositoryMock.fetchDataContract.getCall(0).args;
|
|
193
|
+
// expect(fetchDataContractId.toBuffer()).to.deep.equal(dataContract.getId().toBuffer());
|
|
194
|
+
//
|
|
195
|
+
// expect(stateRepositoryMock.fetchDocuments).to.have.been
|
|
196
|
+
// .callCount(documentTransitionsJs.length);
|
|
197
|
+
// });
|
|
198
|
+
//
|
|
199
|
+
// it('should return invalid result if document transition with action "replace" has wrong revision - Rust', async () => {
|
|
200
|
+
// const replaceDocument = new DocumentJs(documentsJs[0].toObject(), dataContractJs);
|
|
201
|
+
// replaceDocument.setRevision(3);
|
|
202
|
+
//
|
|
203
|
+
// documentTransitionsJs = getDocumentTransitionsFixture({
|
|
204
|
+
// create: [],
|
|
205
|
+
// replace: [replaceDocument],
|
|
206
|
+
// });
|
|
207
|
+
//
|
|
208
|
+
// stateTransition = new DocumentsBatchTransition({
|
|
209
|
+
// ownerId: ownerIdJs,
|
|
210
|
+
// contractId: dataContractJs.getId(),
|
|
211
|
+
// transitions: documentTransitionsJs.map((t) => t.toObject()),
|
|
212
|
+
// }, [dataContract]);
|
|
213
|
+
//
|
|
214
|
+
// documents[0].setCreatedAt(replaceDocument.getCreatedAt());
|
|
215
|
+
// stateRepositoryMock.fetchDocuments.resolves([documents[0].getDocument()]);
|
|
216
|
+
//
|
|
217
|
+
// const result = await validateDocumentsBatchTransitionState(
|
|
218
|
+
// stateRepositoryMock, stateTransition, executionContext,
|
|
219
|
+
// );
|
|
220
|
+
//
|
|
221
|
+
// expect(result).is.instanceOf(ValidationResult);
|
|
222
|
+
//
|
|
223
|
+
// const [error] = result.getErrors();
|
|
224
|
+
// expect(error).is.instanceOf(InvalidDocumentRevisionError);
|
|
225
|
+
// expect(error.getCode()).to.equal(4010);
|
|
226
|
+
//
|
|
227
|
+
// expect(error.getDocumentId()).to.deep.equal(documentTransitionsJs[0].getId().toBuffer());
|
|
228
|
+
// expect(Number(error.getCurrentRevision())).to.deep.equal(documents[0].getRevision());
|
|
229
|
+
//
|
|
230
|
+
// expect(stateRepositoryMock.fetchDataContract).to.have.been.calledOnce();
|
|
231
|
+
// const [fetchDataContractId] = stateRepositoryMock.fetchDataContract.getCall(0).args;
|
|
232
|
+
// expect(fetchDataContractId.toBuffer()).to.deep.equal(dataContract.getId().toBuffer());
|
|
233
|
+
//
|
|
234
|
+
// expect(stateRepositoryMock.fetchDocuments).to.have.been
|
|
235
|
+
// .callCount(documentTransitionsJs.length);
|
|
236
|
+
// });
|
|
237
|
+
//
|
|
238
|
+
// it('should return invalid result if document transition with action "replace" has mismatch of ownerId with previous revision - Rust', async () => {
|
|
239
|
+
// const replaceDocument = new DocumentJs(documentsJs[0].toObject(), dataContractJs);
|
|
240
|
+
// replaceDocument.setRevision(1);
|
|
241
|
+
//
|
|
242
|
+
// const fetchedDocument = new ExtendedDocument(documentsJs[0].toObject(), dataContract);
|
|
243
|
+
// fetchedDocument.setOwnerId(Identifier.from((await generateRandomIdentifier()).toBuffer()));
|
|
244
|
+
//
|
|
245
|
+
// documentTransitionsJs = getDocumentTransitionsFixture({
|
|
246
|
+
// create: [],
|
|
247
|
+
// replace: [replaceDocument],
|
|
248
|
+
// });
|
|
249
|
+
//
|
|
250
|
+
// stateTransition = new DocumentsBatchTransition({
|
|
251
|
+
// ownerId: ownerIdJs,
|
|
252
|
+
// contractId: dataContractJs.getId(),
|
|
253
|
+
// transitions: documentTransitionsJs.map((t) => t.toObject()),
|
|
254
|
+
// }, [dataContract]);
|
|
255
|
+
//
|
|
256
|
+
// stateRepositoryMock.fetchDocuments.resolves([fetchedDocument.getDocument()]);
|
|
257
|
+
//
|
|
258
|
+
// const result = await validateDocumentsBatchTransitionState(
|
|
259
|
+
// stateRepositoryMock,
|
|
260
|
+
// stateTransition,
|
|
261
|
+
// executionContext,
|
|
262
|
+
// );
|
|
263
|
+
//
|
|
264
|
+
// expect(result).is.instanceOf(ValidationResult);
|
|
265
|
+
//
|
|
266
|
+
// const [error] = result.getErrors();
|
|
267
|
+
// expect(error).is.instanceOf(DocumentOwnerIdMismatchError);
|
|
268
|
+
// expect(error.getCode()).to.equal(4006);
|
|
269
|
+
// expect(error.getDocumentId()).to.deep.equal(documentTransitionsJs[0].getId().toBuffer());
|
|
270
|
+
// expect(error.getExistingDocumentOwnerId()).to.deep.equal(
|
|
271
|
+
// fetchedDocument.getOwnerId().toBuffer(),
|
|
272
|
+
// );
|
|
273
|
+
//
|
|
274
|
+
// expect(stateRepositoryMock.fetchDataContract).to.have.been.calledOnce();
|
|
275
|
+
// const [fetchDataContractId] = stateRepositoryMock.fetchDataContract.getCall(0).args;
|
|
276
|
+
// expect(fetchDataContractId.toBuffer()).to.deep.equal(dataContract.getId().toBuffer());
|
|
277
|
+
//
|
|
278
|
+
// expect(stateRepositoryMock.fetchDocuments).to.have.been
|
|
279
|
+
// .callCount(documentTransitionsJs.length);
|
|
280
|
+
// });
|
|
281
|
+
//
|
|
282
|
+
// it('should throw an error if document transition has invalid action - Rust', async () => {
|
|
283
|
+
// // Omitted - DocumentsBatchTransition cannot be created from the
|
|
284
|
+
// // transition with an invalid action because the `DocumentTransition`
|
|
285
|
+
// // uses enums
|
|
286
|
+
// });
|
|
287
|
+
//
|
|
288
|
+
// it('should return invalid result if there are duplicate document transitions according to unique indices - Rust', async () => {
|
|
289
|
+
// // Omitted as it seems impossible to generate such a state without
|
|
290
|
+
// // having UniqueIndicesValidation mocked
|
|
291
|
+
// });
|
|
292
|
+
//
|
|
293
|
+
// it('should return invalid result if data triggers execution failed - Rust', async () => {
|
|
294
|
+
// // Omitted as it seems impossible to generate such a state without
|
|
295
|
+
// // having DataTrigger execution mocked
|
|
296
|
+
// });
|
|
297
|
+
//
|
|
298
|
+
// it('should return invalid result if data triggers execution failed', async () => {
|
|
299
|
+
// // Omitted as it seems impossible to generate such a state without
|
|
300
|
+
// // having DataTrigger execution mocked
|
|
301
|
+
// });
|
|
302
|
+
//
|
|
303
|
+
// describe('Timestamps', () => {
|
|
304
|
+
// let timeWindowStart;
|
|
305
|
+
// let timeWindowEnd;
|
|
306
|
+
//
|
|
307
|
+
// beforeEach(() => {
|
|
308
|
+
// timeWindowStart = new Date(blockTime);
|
|
309
|
+
// timeWindowStart.setMinutes(
|
|
310
|
+
// timeWindowStart.getMinutes() - 5,
|
|
311
|
+
// );
|
|
312
|
+
//
|
|
313
|
+
// timeWindowEnd = new Date(blockTime);
|
|
314
|
+
// timeWindowEnd.setMinutes(
|
|
315
|
+
// timeWindowEnd.getMinutes() + 5,
|
|
316
|
+
// );
|
|
317
|
+
// });
|
|
318
|
+
//
|
|
319
|
+
// describe('CREATE transition', () => {
|
|
320
|
+
// it('should return invalid result if timestamps mismatch - Rust', async () => {
|
|
321
|
+
// documentTransitionsJs = getDocumentTransitionsFixture({
|
|
322
|
+
// create: [documentsJs[0]],
|
|
323
|
+
// });
|
|
324
|
+
//
|
|
325
|
+
// stateTransition = new DocumentsBatchTransition({
|
|
326
|
+
// ownerId: ownerIdJs,
|
|
327
|
+
// contractId: dataContractJs.getId(),
|
|
328
|
+
// transitions: documentTransitionsJs.map((t) => t.toObject()),
|
|
329
|
+
// }, [dataContract]);
|
|
330
|
+
//
|
|
331
|
+
// const transitions = stateTransition.getTransitions();
|
|
332
|
+
// transitions.forEach((t) => {
|
|
333
|
+
// // eslint-disable-next-line no-param-reassign
|
|
334
|
+
// t.setUpdatedAt(new Date());
|
|
335
|
+
// });
|
|
336
|
+
// stateTransition.setTransitions(transitions);
|
|
337
|
+
//
|
|
338
|
+
// const result = await validateDocumentsBatchTransitionState(
|
|
339
|
+
// stateRepositoryMock, stateTransition, executionContext,
|
|
340
|
+
// );
|
|
341
|
+
//
|
|
342
|
+
// expect(result).is.instanceOf(ValidationResult);
|
|
343
|
+
//
|
|
344
|
+
// const [error] = result.getErrors();
|
|
345
|
+
// expect(error).is.instanceOf(DocumentTimestampsMismatchError);
|
|
346
|
+
// expect(error.getCode()).to.equal(4007);
|
|
347
|
+
// });
|
|
348
|
+
//
|
|
349
|
+
// it('should return invalid result if "$createdAt" have violated time window - Rust', async () => {
|
|
350
|
+
// documentTransitionsJs = getDocumentTransitionsFixture({
|
|
351
|
+
// create: [documentsJs[0]],
|
|
352
|
+
// });
|
|
353
|
+
//
|
|
354
|
+
// stateTransition = new DocumentsBatchTransition({
|
|
355
|
+
// ownerId: ownerIdJs,
|
|
356
|
+
// contractId: dataContractJs.getId(),
|
|
357
|
+
// transitions: documentTransitionsJs.map((t) => t.toObject()),
|
|
358
|
+
// }, [dataContract]);
|
|
359
|
+
//
|
|
360
|
+
// const transitions = stateTransition.getTransitions();
|
|
361
|
+
// transitions.forEach((t) => {
|
|
362
|
+
// const createdAtMinus6Mins = t.getCreatedAt().getTime() - (6 * 60 * 1000);
|
|
363
|
+
// t.setCreatedAt(new Date(createdAtMinus6Mins));
|
|
364
|
+
// t.setUpdatedAt(undefined);
|
|
365
|
+
// });
|
|
366
|
+
// stateTransition.setTransitions(transitions);
|
|
367
|
+
//
|
|
368
|
+
// const result = await validateDocumentsBatchTransitionState(
|
|
369
|
+
// stateRepositoryMock, stateTransition, executionContext,
|
|
370
|
+
// );
|
|
371
|
+
//
|
|
372
|
+
// expect(result).is.instanceOf(ValidationResult);
|
|
373
|
+
// expect(result.isValid()).is.not.true();
|
|
374
|
+
//
|
|
375
|
+
// const [error] = result.getErrors();
|
|
376
|
+
// expect(error).is.instanceOf(DocumentTimestampWindowViolationError);
|
|
377
|
+
// expect(error.getCode()).to.equal(4008);
|
|
378
|
+
// expect(error.getTimestampName()).to.equal('createdAt');
|
|
379
|
+
//
|
|
380
|
+
// expect(error.getTimestamp().getMilliseconds()).to.equal(
|
|
381
|
+
// documentTransitionsJs[0].createdAt.getMilliseconds(),
|
|
382
|
+
// );
|
|
383
|
+
// expect(error.getTimeWindowStart()).to.deep.equal(timeWindowStart);
|
|
384
|
+
// expect(error.getTimeWindowEnd()).to.deep.equal(timeWindowEnd);
|
|
385
|
+
// });
|
|
386
|
+
//
|
|
387
|
+
// it('should return invalid result if "$updatedAt" have violated time window - Rust', async () => {
|
|
388
|
+
// documentTransitionsJs = getDocumentTransitionsFixture({
|
|
389
|
+
// create: [documentsJs[1]],
|
|
390
|
+
// });
|
|
391
|
+
//
|
|
392
|
+
// stateTransition = new DocumentsBatchTransition({
|
|
393
|
+
// ownerId: ownerIdJs,
|
|
394
|
+
// contractId: dataContractJs.getId(),
|
|
395
|
+
// transitions: documentTransitionsJs.map((t) => t.toObject()),
|
|
396
|
+
// }, [dataContract]);
|
|
397
|
+
//
|
|
398
|
+
// const transitions = stateTransition.getTransitions();
|
|
399
|
+
// transitions.forEach((t) => {
|
|
400
|
+
// const createdAtMinus6Mins = t.getUpdatedAt().getTime() - (6 * 60 * 1000);
|
|
401
|
+
// t.setUpdatedAt(new Date(createdAtMinus6Mins));
|
|
402
|
+
// t.setCreatedAt(undefined);
|
|
403
|
+
// });
|
|
404
|
+
// stateTransition.setTransitions(transitions);
|
|
405
|
+
//
|
|
406
|
+
// const result = await validateDocumentsBatchTransitionState(
|
|
407
|
+
// stateRepositoryMock, stateTransition, executionContext,
|
|
408
|
+
// );
|
|
409
|
+
//
|
|
410
|
+
// expect(result).is.instanceOf(ValidationResult);
|
|
411
|
+
// expect(result.isValid()).is.not.true();
|
|
412
|
+
//
|
|
413
|
+
// const [error] = result.getErrors();
|
|
414
|
+
// expect(error).is.instanceOf(DocumentTimestampWindowViolationError);
|
|
415
|
+
// expect(error.getCode()).to.equal(4008);
|
|
416
|
+
//
|
|
417
|
+
// documentTransitionsJs[0].updatedAt.setMinutes(
|
|
418
|
+
// documentTransitionsJs[0].updatedAt.getMinutes() - 6,
|
|
419
|
+
// );
|
|
420
|
+
// documentTransitionsJs[0].createdAt = undefined;
|
|
421
|
+
//
|
|
422
|
+
// expect(error.getDocumentId()).to.deep.equal(documentTransitionsJs[0].getId().toBuffer());
|
|
423
|
+
// expect(error.getTimestampName()).to.equal('updatedAt');
|
|
424
|
+
// expect(error.getTimestamp().getMilliseconds()).to.deep.equal(
|
|
425
|
+
// documentTransitionsJs[0].updatedAt.getMilliseconds(),
|
|
426
|
+
// );
|
|
427
|
+
// expect(error.getTimeWindowStart()).to.deep.equal(timeWindowStart);
|
|
428
|
+
// expect(error.getTimeWindowEnd()).to.deep.equal(timeWindowEnd);
|
|
429
|
+
// });
|
|
430
|
+
//
|
|
431
|
+
// it('should not validate time in block window on dry run - Rust', async () => {
|
|
432
|
+
// documentTransitionsJs = getDocumentTransitionsFixture({
|
|
433
|
+
// create: [documentsJs[1]],
|
|
434
|
+
// });
|
|
435
|
+
//
|
|
436
|
+
// executeDataTriggersMock.resolves([
|
|
437
|
+
// new DataTriggerExecutionResult(),
|
|
438
|
+
// ]);
|
|
439
|
+
//
|
|
440
|
+
// stateTransition = new DocumentsBatchTransition({
|
|
441
|
+
// ownerId: ownerIdJs,
|
|
442
|
+
// contractId: dataContractJs.getId(),
|
|
443
|
+
// transitions: documentTransitionsJs.map((t) => t.toObject()),
|
|
444
|
+
// }, [dataContract]);
|
|
445
|
+
//
|
|
446
|
+
// const transitions = stateTransition.getTransitions();
|
|
447
|
+
// transitions.forEach((t) => {
|
|
448
|
+
// const createdAtMinus6Mins = t.getUpdatedAt().getTime() - (6 * 60 * 1000);
|
|
449
|
+
// t.setUpdatedAt(new Date(createdAtMinus6Mins));
|
|
450
|
+
// t.setCreatedAt(undefined);
|
|
451
|
+
// });
|
|
452
|
+
// stateTransition.setTransitions(transitions);
|
|
453
|
+
// executionContext.enableDryRun();
|
|
454
|
+
//
|
|
455
|
+
// const result = await validateDocumentsBatchTransitionState(
|
|
456
|
+
// stateRepositoryMock, stateTransition, executionContext,
|
|
457
|
+
// );
|
|
458
|
+
//
|
|
459
|
+
// expect(result).to.be.an.instanceOf(ValidationResult);
|
|
460
|
+
// expect(result.isValid()).to.be.true();
|
|
461
|
+
// });
|
|
462
|
+
//
|
|
463
|
+
// it('should return valid result if timestamps mismatch on dry run - Rust', async () => {
|
|
464
|
+
// documentTransitionsJs = getDocumentTransitionsFixture({
|
|
465
|
+
// create: [documentsJs[0]],
|
|
466
|
+
// });
|
|
467
|
+
//
|
|
468
|
+
// executeDataTriggersMock.resolves([
|
|
469
|
+
// new DataTriggerExecutionResult(),
|
|
470
|
+
// ]);
|
|
471
|
+
//
|
|
472
|
+
// stateTransition = new DocumentsBatchTransition({
|
|
473
|
+
// ownerId: ownerIdJs,
|
|
474
|
+
// contractId: dataContractJs.getId(),
|
|
475
|
+
// transitions: documentTransitionsJs.map((t) => t.toObject()),
|
|
476
|
+
// }, [dataContract]);
|
|
477
|
+
//
|
|
478
|
+
// const transitions = stateTransition.getTransitions();
|
|
479
|
+
// transitions.forEach((t) => {
|
|
480
|
+
// // eslint-disable-next-line no-param-reassign
|
|
481
|
+
// t.setUpdatedAt(new Date());
|
|
482
|
+
// });
|
|
483
|
+
// executionContext.enableDryRun();
|
|
484
|
+
//
|
|
485
|
+
// const result = await validateDocumentsBatchTransitionState(
|
|
486
|
+
// stateRepositoryMock, stateTransition, executionContext,
|
|
487
|
+
// );
|
|
488
|
+
//
|
|
489
|
+
// expect(result).to.be.an.instanceOf(ValidationResult);
|
|
490
|
+
// expect(result.isValid()).to.be.true();
|
|
491
|
+
// });
|
|
492
|
+
// });
|
|
493
|
+
//
|
|
494
|
+
// describe('REPLACE transition', () => {
|
|
495
|
+
// it('should return invalid result if documents with action "replace" have violated time window - Rust', async () => {
|
|
496
|
+
// documentTransitionsJs = getDocumentTransitionsFixture({
|
|
497
|
+
// create: [],
|
|
498
|
+
// replace: [documentsJs[1]],
|
|
499
|
+
// });
|
|
500
|
+
//
|
|
501
|
+
// stateTransition = new DocumentsBatchTransition({
|
|
502
|
+
// ownerId: ownerIdJs,
|
|
503
|
+
// contractId: dataContractJs.getId(),
|
|
504
|
+
// transitions: documentTransitionsJs.map((t) => t.toObject()),
|
|
505
|
+
// }, [dataContract]);
|
|
506
|
+
//
|
|
507
|
+
// documentsJs[1].updatedAt.setMinutes(
|
|
508
|
+
// documentsJs[1].updatedAt.getMinutes() - 6,
|
|
509
|
+
// );
|
|
510
|
+
//
|
|
511
|
+
// const documentToReturn = new ExtendedDocument(documentsJs[1].toObject(), dataContract);
|
|
512
|
+
// stateRepositoryMock.fetchExtendedDocuments.resolves([documentToReturn]);
|
|
513
|
+
//
|
|
514
|
+
// const transitions = stateTransition.getTransitions();
|
|
515
|
+
// transitions.forEach((t) => {
|
|
516
|
+
// const createdAtMinus6Mins = t.getUpdatedAt().getTime() - (6 * 60 * 1000);
|
|
517
|
+
// t.setUpdatedAt(new Date(createdAtMinus6Mins));
|
|
518
|
+
// });
|
|
519
|
+
// stateTransition.setTransitions(transitions);
|
|
520
|
+
//
|
|
521
|
+
// const result = await validateDocumentsBatchTransitionState(
|
|
522
|
+
// stateRepositoryMock, stateTransition, executionContext,
|
|
523
|
+
// );
|
|
524
|
+
//
|
|
525
|
+
// expect(result).is.instanceOf(ValidationResult);
|
|
526
|
+
// expect(result.isValid()).is.not.true();
|
|
527
|
+
// const [error] = result.getErrors();
|
|
528
|
+
//
|
|
529
|
+
// expect(error).is.instanceOf(DocumentTimestampWindowViolationError);
|
|
530
|
+
// expect(error.getCode()).to.equal(4008);
|
|
531
|
+
//
|
|
532
|
+
// documentTransitionsJs[0].updatedAt.setMinutes(
|
|
533
|
+
// documentTransitionsJs[0].updatedAt.getMinutes() - 6,
|
|
534
|
+
// );
|
|
535
|
+
//
|
|
536
|
+
// expect(error.getDocumentId()).to.deep.equal(documentTransitionsJs[0].getId().toBuffer());
|
|
537
|
+
// expect(error.getTimestampName()).to.equal('updatedAt');
|
|
538
|
+
// expect(error.getTimestamp()).to.deep.equal(documentTransitionsJs[0].updatedAt);
|
|
539
|
+
// expect(error.getTimeWindowStart()).to.deep.equal(timeWindowStart);
|
|
540
|
+
// expect(error.getTimeWindowEnd()).to.deep.equal(timeWindowEnd);
|
|
541
|
+
// });
|
|
542
|
+
//
|
|
543
|
+
// it('should return valid result if documents with action "replace" have violated time window on dry run - Rust', async () => {
|
|
544
|
+
// documentTransitionsJs = getDocumentTransitionsFixture({
|
|
545
|
+
// create: [],
|
|
546
|
+
// replace: [documentsJs[1]],
|
|
547
|
+
// });
|
|
548
|
+
//
|
|
549
|
+
// stateTransition = new DocumentsBatchTransition({
|
|
550
|
+
// ownerId: ownerIdJs,
|
|
551
|
+
// contractId: dataContractJs.getId(),
|
|
552
|
+
// transitions: documentTransitionsJs.map((t) => t.toObject()),
|
|
553
|
+
// }, [dataContract]);
|
|
554
|
+
//
|
|
555
|
+
// documentsJs[1].updatedAt.setMinutes(
|
|
556
|
+
// documentsJs[1].updatedAt.getMinutes() - 6,
|
|
557
|
+
// );
|
|
558
|
+
//
|
|
559
|
+
// const documentToReturn = new ExtendedDocument(documentsJs[1].toObject(), dataContract);
|
|
560
|
+
// stateRepositoryMock.fetchExtendedDocuments.resolves([documentToReturn]);
|
|
561
|
+
//
|
|
562
|
+
// const transitions = stateTransition.getTransitions(); transitions.forEach((t) => {
|
|
563
|
+
// const createdAtMinus6Mins = t.getUpdatedAt().getTime() - (6 * 60 * 1000);
|
|
564
|
+
// t.setUpdatedAt(new Date(createdAtMinus6Mins));
|
|
565
|
+
// });
|
|
566
|
+
// stateTransition.setTransitions(transitions);
|
|
567
|
+
// executionContext.enableDryRun();
|
|
568
|
+
//
|
|
569
|
+
// const result = await validateDocumentsBatchTransitionState(
|
|
570
|
+
// stateRepositoryMock, stateTransition, executionContext,
|
|
571
|
+
// );
|
|
572
|
+
//
|
|
573
|
+
// expect(result).to.be.an.instanceOf(ValidationResult);
|
|
574
|
+
// expect(result.isValid()).to.be.true();
|
|
575
|
+
// });
|
|
576
|
+
// });
|
|
577
|
+
// });
|
|
578
|
+
//
|
|
579
|
+
// it('should return valid result if document transitions are valid - Rust', async () => {
|
|
580
|
+
// const fetchedDocuments = [
|
|
581
|
+
// new ExtendedDocument(documentsJs[1].toObject(), dataContract).getDocument(),
|
|
582
|
+
// new ExtendedDocument(documentsJs[2].toObject(), dataContract).getDocument(),
|
|
583
|
+
// ];
|
|
584
|
+
//
|
|
585
|
+
// stateRepositoryMock.fetchDocuments.resolves(fetchedDocuments);
|
|
586
|
+
//
|
|
587
|
+
// documentsJs[1].setRevision(1);
|
|
588
|
+
// documentsJs[2].setRevision(1);
|
|
589
|
+
//
|
|
590
|
+
// documentTransitionsJs = getDocumentTransitionsFixture({
|
|
591
|
+
// create: [],
|
|
592
|
+
// replace: [documentsJs[1]],
|
|
593
|
+
// delete: [documentsJs[2]],
|
|
594
|
+
// });
|
|
595
|
+
//
|
|
596
|
+
// stateTransition = new DocumentsBatchTransition({
|
|
597
|
+
// ownerId: ownerIdJs,
|
|
598
|
+
// contractId: dataContractJs.getId(),
|
|
599
|
+
// transitions: documentTransitionsJs.map((t) => t.toObject()),
|
|
600
|
+
// }, [dataContract]);
|
|
601
|
+
//
|
|
602
|
+
// const result = await validateDocumentsBatchTransitionState(
|
|
603
|
+
// stateRepositoryMock, stateTransition, executionContext,
|
|
604
|
+
// );
|
|
605
|
+
//
|
|
606
|
+
// expect(result).to.be.an.instanceOf(ValidationResult);
|
|
607
|
+
// expect(result.isValid()).to.be.true();
|
|
608
|
+
//
|
|
609
|
+
// expect(stateRepositoryMock.fetchDataContract).to.have.been.calledOnce();
|
|
610
|
+
// const [fetchDataContractId] = stateRepositoryMock.fetchDataContract.getCall(0).args;
|
|
611
|
+
// expect(fetchDataContractId.toBuffer()).to.deep.equal(dataContract.getId().toBuffer());
|
|
612
|
+
//
|
|
613
|
+
// expect(stateRepositoryMock.fetchDocuments).to.have.been.calledOnce();
|
|
614
|
+
// });
|
|
615
|
+
//
|
|
616
|
+
// it('should return valid result if document transitions are valid - Rust', async () => {
|
|
617
|
+
// const fetchedDocuments = [
|
|
618
|
+
// new ExtendedDocument(documentsJs[1].toObject(), dataContract).getDocument(),
|
|
619
|
+
// new ExtendedDocument(documentsJs[2].toObject(), dataContract).getDocument(),
|
|
620
|
+
// ];
|
|
621
|
+
//
|
|
622
|
+
// stateRepositoryMock.fetchDocuments.resolves(fetchedDocuments);
|
|
623
|
+
//
|
|
624
|
+
// documentsJs[1].setRevision(1);
|
|
625
|
+
// documentsJs[2].setRevision(1);
|
|
626
|
+
//
|
|
627
|
+
// documentTransitionsJs = getDocumentTransitionsFixture({
|
|
628
|
+
// create: [],
|
|
629
|
+
// replace: [documentsJs[1]],
|
|
630
|
+
// delete: [documentsJs[2]],
|
|
631
|
+
// });
|
|
632
|
+
//
|
|
633
|
+
// stateTransition = new DocumentsBatchTransition({
|
|
634
|
+
// ownerId: ownerIdJs,
|
|
635
|
+
// contractId: dataContractJs.getId(),
|
|
636
|
+
// transitions: documentTransitionsJs.map((t) => t.toObject()),
|
|
637
|
+
// }, [dataContract]);
|
|
638
|
+
//
|
|
639
|
+
// const result = await validateDocumentsBatchTransitionState(
|
|
640
|
+
// stateRepositoryMock, stateTransition, executionContext,
|
|
641
|
+
// );
|
|
642
|
+
//
|
|
643
|
+
// expect(result).to.be.an.instanceOf(ValidationResult);
|
|
644
|
+
// expect(result.isValid()).to.be.true();
|
|
645
|
+
//
|
|
646
|
+
// expect(stateRepositoryMock.fetchDataContract).to.have.been.calledOnce();
|
|
647
|
+
// const [fetchDataContractId] = stateRepositoryMock.fetchDataContract.getCall(0).args;
|
|
648
|
+
// expect(fetchDataContractId.toBuffer()).to.deep.equal(dataContract.getId().toBuffer());
|
|
649
|
+
//
|
|
650
|
+
// expect(stateRepositoryMock.fetchDocuments).to.have.been.calledOnce();
|
|
651
|
+
// });
|
|
675
652
|
});
|