pshenmic-dpp 1.0.3 → 1.0.5

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.
Files changed (83) hide show
  1. package/.github/workflows/build.yml +8 -0
  2. package/.github/workflows/publish.yml +8 -0
  3. package/Cargo.lock +89 -28
  4. package/Cargo.toml +22 -18
  5. package/README.md +66 -23
  6. package/babel.config.json +19 -0
  7. package/dist/wasm/pshenmic_dpp.js +2992 -402
  8. package/dist/wasm/pshenmic_dpp_bg.js +1 -1
  9. package/package.json +13 -6
  10. package/packages/{cbor-conversation → cbor_conversation}/Cargo.toml +1 -5
  11. package/packages/data_contract/Cargo.toml +3 -7
  12. package/packages/data_contract/src/lib.rs +234 -47
  13. package/packages/{document_batch → data_contract_transitions}/Cargo.toml +6 -14
  14. package/packages/data_contract_transitions/src/create/mod.rs +161 -0
  15. package/packages/data_contract_transitions/src/lib.rs +2 -0
  16. package/packages/data_contract_transitions/src/update/mod.rs +144 -0
  17. package/packages/document/Cargo.toml +2 -7
  18. package/packages/document/src/lib.rs +1 -1
  19. package/packages/document/src/methods/mod.rs +370 -2
  20. package/packages/documents_batch/Cargo.toml +19 -0
  21. package/packages/documents_batch/src/document_base_transition/mod.rs +92 -0
  22. package/packages/documents_batch/src/document_transition/mod.rs +166 -0
  23. package/packages/documents_batch/src/generators.rs +122 -0
  24. package/packages/documents_batch/src/lib.rs +188 -0
  25. package/packages/documents_batch/src/prefunded_voting_balance/mod.rs +45 -0
  26. package/packages/documents_batch/src/transitions/create/mod.rs +123 -0
  27. package/packages/documents_batch/src/transitions/delete/mod.rs +67 -0
  28. package/packages/documents_batch/src/transitions/mod.rs +6 -0
  29. package/packages/documents_batch/src/transitions/purchase/mod.rs +91 -0
  30. package/packages/documents_batch/src/transitions/replace/mod.rs +93 -0
  31. package/packages/documents_batch/src/transitions/transfer/mod.rs +86 -0
  32. package/packages/documents_batch/src/transitions/update_price/mod.rs +75 -0
  33. package/packages/enums/Cargo.toml +2 -5
  34. package/packages/enums/src/batch/batch_enum.rs +75 -10
  35. package/packages/enums/src/keys/key_type.rs +46 -0
  36. package/packages/enums/src/keys/purpose.rs +55 -0
  37. package/packages/enums/src/keys/security_level.rs +46 -0
  38. package/packages/enums/src/lib.rs +1 -0
  39. package/packages/enums/src/network/mod.rs +67 -0
  40. package/packages/enums/src/platform/mod.rs +66 -8
  41. package/packages/identity/Cargo.toml +2 -7
  42. package/packages/identity/src/lib.rs +25 -14
  43. package/packages/{public_key → identity_public_key}/Cargo.toml +2 -6
  44. package/packages/{public_key → identity_public_key}/src/lib.rs +74 -27
  45. package/packages/identity_transitions/Cargo.toml +3 -7
  46. package/packages/identity_transitions/src/create_transition/mod.rs +5 -3
  47. package/packages/identity_transitions/src/create_transition/public_key_in_creation/mod.rs +25 -21
  48. package/packages/mock_bls/Cargo.toml +2 -6
  49. package/packages/private_key/Cargo.toml +2 -5
  50. package/packages/private_key/src/lib.rs +44 -6
  51. package/packages/state_transition/Cargo.toml +4 -7
  52. package/packages/state_transition/src/lib.rs +106 -40
  53. package/packages/utils/Cargo.toml +1 -6
  54. package/packages/utils/src/lib.rs +17 -15
  55. package/scripts/build-js.sh +8 -6
  56. package/scripts/build.sh +22 -1
  57. package/src/lib.rs +8 -1
  58. package/tests/DataContract.spec.js +175 -0
  59. package/tests/DataContractCreateStateTransition.spec.js +109 -0
  60. package/tests/DataContractUpdateStateTransition.spec.js +109 -0
  61. package/tests/Document.spec.js +232 -0
  62. package/tests/DocumentBatchTransition.spec.js +109 -0
  63. package/tests/DocumentTransition.spec.js +97 -0
  64. package/tests/DocumentsTransitions.spec.js +705 -0
  65. package/tests/Identity.spec.js +113 -0
  66. package/tests/IdentityPublicKey.spec.js +132 -0
  67. package/tests/PrivateKey.spec.js +73 -0
  68. package/tests/mocks/DataContract/DataContract.json +153 -0
  69. package/tests/mocks/DataContract/index.js +6 -0
  70. package/tests/mocks/Document/DataContract.json +23 -0
  71. package/tests/mocks/Document/document.json +3 -0
  72. package/tests/mocks/Document/document2.json +3 -0
  73. package/tests/mocks/Document/index.js +11 -0
  74. package/tests/mocks/Identity/index.js +7 -0
  75. package/tests/mocks/PrivateKey/index.js +5 -0
  76. package/tests/mocks/PublicKey/index.js +14 -0
  77. package/tests/utils/hex.js +15 -0
  78. package/tests/utils/wasm.js +14 -0
  79. package/packages/document/src/methods/js.rs +0 -260
  80. package/packages/document/src/methods/rust.rs +0 -92
  81. package/packages/document_batch/src/generators.rs +0 -63
  82. package/packages/document_batch/src/lib.rs +0 -228
  83. /package/packages/{cbor-conversation → cbor_conversation}/src/lib.rs +0 -0
@@ -0,0 +1,705 @@
1
+ const assert = require('assert')
2
+ const { describe, it, before } = require('mocha')
3
+ const initWasm = require('./utils/wasm')
4
+ const { document, documentTypeName, revision, dataContractId, ownerId, id } = require('./mocks/Document')
5
+
6
+ let wasm
7
+
8
+ describe('DocumentsTransitions', function () {
9
+ before(async function () {
10
+ wasm = initWasm()
11
+ })
12
+
13
+ describe('serialization / deserialization', function () {
14
+ describe('document Create transition', function () {
15
+ it('should allow to create CreateTransition from document', () => {
16
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
17
+ const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1), 'preorder')
18
+
19
+ assert.notEqual(documentInstance.__wbg_ptr, 0)
20
+ assert.notEqual(createTransition.__wbg_ptr, 0)
21
+ })
22
+
23
+ it('should allow to create Document Transition from Create transition', () => {
24
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
25
+ const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1), 'preorder')
26
+
27
+ const documentTransition = createTransition.toDocumentTransition()
28
+
29
+ assert.notEqual(documentInstance.__wbg_ptr, 0)
30
+ assert.notEqual(createTransition.__wbg_ptr, 0)
31
+ assert.notEqual(documentTransition.__wbg_ptr, 0)
32
+ })
33
+
34
+ it('should allow to create Document Batch Transition from Document Transitions', () => {
35
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
36
+ const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1), 'preorder')
37
+
38
+ const documentTransition = createTransition.toDocumentTransition()
39
+
40
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], Array.from(documentInstance.getOwnerId()), 1, 1)
41
+
42
+ assert.notEqual(documentInstance.__wbg_ptr, 0)
43
+ assert.notEqual(createTransition.__wbg_ptr, 0)
44
+ assert.notEqual(documentTransition.__wbg_ptr, 0)
45
+ assert.notEqual(batchTransition.__wbg_ptr, 0)
46
+ })
47
+
48
+ it('should allow to create state transitions from document and convert state transition to document batch', () => {
49
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
50
+ const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1), 'preorder')
51
+
52
+ const documentTransition = createTransition.toDocumentTransition()
53
+
54
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], Array.from(documentInstance.getOwnerId()), 1, 1)
55
+
56
+ const st = batchTransition.toStateTransition()
57
+
58
+ const deserializedBatch = wasm.DocumentsBatchWASM.fromStateTransition(st)
59
+
60
+ const deserializedTransitions = deserializedBatch.transitions
61
+
62
+ assert.equal(deserializedTransitions.length, 2)
63
+
64
+ const deserializedPurchaseTransition = deserializedTransitions[0].createTransition
65
+
66
+ assert.notEqual(documentInstance.__wbg_ptr, 0)
67
+ assert.notEqual(createTransition.__wbg_ptr, 0)
68
+ assert.notEqual(documentTransition.__wbg_ptr, 0)
69
+ assert.notEqual(batchTransition.__wbg_ptr, 0)
70
+ assert.notEqual(st.__wbg_ptr, 0)
71
+ assert.notEqual(deserializedBatch.__wbg_ptr, 0)
72
+ assert.notEqual(deserializedPurchaseTransition.__wbg_ptr, 0)
73
+ })
74
+ })
75
+
76
+ describe('document Delete transition', function () {
77
+ it('should allow to create DeleteTransition from document', () => {
78
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
79
+ const deleteTransition = new wasm.DocumentDeleteTransitionWASM(documentInstance, BigInt(1), 'preorder')
80
+
81
+ assert.notEqual(documentInstance.__wbg_ptr, 0)
82
+ assert.notEqual(deleteTransition.__wbg_ptr, 0)
83
+ })
84
+
85
+ it('should allow to create Document Transition from Delete transition', () => {
86
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
87
+ const deleteTransition = new wasm.DocumentDeleteTransitionWASM(documentInstance, BigInt(1), 'preorder')
88
+
89
+ const documentTransition = deleteTransition.toDocumentTransition()
90
+
91
+ assert.notEqual(documentInstance.__wbg_ptr, 0)
92
+ assert.notEqual(deleteTransition.__wbg_ptr, 0)
93
+ assert.notEqual(documentTransition.__wbg_ptr, 0)
94
+ })
95
+
96
+ it('should allow to create Document Batch Transition from Document Transitions', () => {
97
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
98
+ const deleteTransition = new wasm.DocumentDeleteTransitionWASM(documentInstance, BigInt(1), 'preorder')
99
+
100
+ const documentTransition = deleteTransition.toDocumentTransition()
101
+
102
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], Array.from(documentInstance.getOwnerId()), 1, 1)
103
+
104
+ assert.notEqual(documentInstance.__wbg_ptr, 0)
105
+ assert.notEqual(deleteTransition.__wbg_ptr, 0)
106
+ assert.notEqual(documentTransition.__wbg_ptr, 0)
107
+ assert.notEqual(batchTransition.__wbg_ptr, 0)
108
+ })
109
+
110
+ it('should allow to create state transitions from document and convert state transition to document batch', () => {
111
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
112
+ const deleteTransition = new wasm.DocumentDeleteTransitionWASM(documentInstance, BigInt(1), 'preorder')
113
+
114
+ const documentTransition = deleteTransition.toDocumentTransition()
115
+
116
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], Array.from(documentInstance.getOwnerId()), 1, 1)
117
+
118
+ const st = batchTransition.toStateTransition()
119
+
120
+ const deserializedBatch = wasm.DocumentsBatchWASM.fromStateTransition(st)
121
+
122
+ const deserializedTransitions = deserializedBatch.transitions
123
+
124
+ assert.equal(deserializedTransitions.length, 2)
125
+
126
+ const deserializedPurchaseTransition = deserializedTransitions[0].deleteTransition
127
+
128
+ assert.notEqual(documentInstance.__wbg_ptr, 0)
129
+ assert.notEqual(deleteTransition.__wbg_ptr, 0)
130
+ assert.notEqual(documentTransition.__wbg_ptr, 0)
131
+ assert.notEqual(batchTransition.__wbg_ptr, 0)
132
+ assert.notEqual(st.__wbg_ptr, 0)
133
+ assert.notEqual(deserializedBatch.__wbg_ptr, 0)
134
+ assert.notEqual(deserializedPurchaseTransition.__wbg_ptr, 0)
135
+ })
136
+ })
137
+
138
+ describe('document Replace transition', function () {
139
+ it('should allow to create ReplaceTransition from document', () => {
140
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
141
+ const replaceTransition = new wasm.DocumentReplaceTransitionWASM(documentInstance, BigInt(1), 'preorder')
142
+
143
+ assert.notEqual(documentInstance.__wbg_ptr, 0)
144
+ assert.notEqual(replaceTransition.__wbg_ptr, 0)
145
+ })
146
+
147
+ it('should allow to create Document Transition from Replace transition', () => {
148
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
149
+ const replaceTransition = new wasm.DocumentReplaceTransitionWASM(documentInstance, BigInt(1), 'preorder')
150
+
151
+ const documentTransition = replaceTransition.toDocumentTransition()
152
+
153
+ assert.notEqual(replaceTransition.__wbg_ptr, 0)
154
+ assert.notEqual(replaceTransition.__wbg_ptr, 0)
155
+ assert.notEqual(documentTransition.__wbg_ptr, 0)
156
+ })
157
+
158
+ it('should allow to create Document Batch Transition from Document Transitions', () => {
159
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
160
+ const replaceTransition = new wasm.DocumentReplaceTransitionWASM(documentInstance, BigInt(1), 'preorder')
161
+
162
+ const documentTransition = replaceTransition.toDocumentTransition()
163
+
164
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], Array.from(documentInstance.getOwnerId()), 1, 1)
165
+
166
+ assert.notEqual(documentInstance.__wbg_ptr, 0)
167
+ assert.notEqual(replaceTransition.__wbg_ptr, 0)
168
+ assert.notEqual(documentTransition.__wbg_ptr, 0)
169
+ assert.notEqual(batchTransition.__wbg_ptr, 0)
170
+ })
171
+
172
+ it('should allow to create state transitions from document and convert state transition to document batch', () => {
173
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
174
+ const replaceTransition = new wasm.DocumentReplaceTransitionWASM(documentInstance, BigInt(1), 'preorder')
175
+
176
+ const documentTransition = replaceTransition.toDocumentTransition()
177
+
178
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], Array.from(documentInstance.getOwnerId()), 1, 1)
179
+
180
+ const st = batchTransition.toStateTransition()
181
+
182
+ const deserializedBatch = wasm.DocumentsBatchWASM.fromStateTransition(st)
183
+
184
+ const deserializedTransitions = deserializedBatch.transitions
185
+
186
+ assert.equal(deserializedTransitions.length, 2)
187
+
188
+ const deserializedPurchaseTransition = deserializedTransitions[0].replaceTransition
189
+
190
+ assert.notEqual(documentInstance.__wbg_ptr, 0)
191
+ assert.notEqual(replaceTransition.__wbg_ptr, 0)
192
+ assert.notEqual(documentTransition.__wbg_ptr, 0)
193
+ assert.notEqual(batchTransition.__wbg_ptr, 0)
194
+ assert.notEqual(st.__wbg_ptr, 0)
195
+ assert.notEqual(deserializedBatch.__wbg_ptr, 0)
196
+ assert.notEqual(deserializedPurchaseTransition.__wbg_ptr, 0)
197
+ })
198
+ })
199
+
200
+ describe('document Transfer transition', function () {
201
+ it('should allow to create ReplaceTransition from document', () => {
202
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
203
+ const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), 'preorder', Array.from(documentInstance.getOwnerId()))
204
+
205
+ assert.notEqual(documentInstance.__wbg_ptr, 0)
206
+ assert.notEqual(transferTransition.__wbg_ptr, 0)
207
+ })
208
+
209
+ it('should allow to create Document Transition from Replace transition', () => {
210
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
211
+ const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), 'preorder', Array.from(documentInstance.getOwnerId()))
212
+
213
+ const documentTransition = transferTransition.toDocumentTransition()
214
+
215
+ assert.notEqual(transferTransition.__wbg_ptr, 0)
216
+ assert.notEqual(transferTransition.__wbg_ptr, 0)
217
+ assert.notEqual(documentTransition.__wbg_ptr, 0)
218
+ })
219
+
220
+ it('should allow to create Document Batch Transition from Document Transitions', () => {
221
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
222
+ const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), 'preorder', Array.from(documentInstance.getOwnerId()))
223
+
224
+ const documentTransition = transferTransition.toDocumentTransition()
225
+
226
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], Array.from(documentInstance.getOwnerId()), 1, 1)
227
+
228
+ assert.notEqual(documentInstance.__wbg_ptr, 0)
229
+ assert.notEqual(transferTransition.__wbg_ptr, 0)
230
+ assert.notEqual(documentTransition.__wbg_ptr, 0)
231
+ assert.notEqual(batchTransition.__wbg_ptr, 0)
232
+ })
233
+
234
+ it('should allow to create state transitions from document and convert state transition to document batch', () => {
235
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
236
+ const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), 'preorder', Array.from(documentInstance.getOwnerId()))
237
+
238
+ const documentTransition = transferTransition.toDocumentTransition()
239
+
240
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], Array.from(documentInstance.getOwnerId()), 1, 1)
241
+
242
+ const st = batchTransition.toStateTransition()
243
+
244
+ const deserializedBatch = wasm.DocumentsBatchWASM.fromStateTransition(st)
245
+
246
+ const deserializedTransitions = deserializedBatch.transitions
247
+
248
+ assert.equal(deserializedTransitions.length, 2)
249
+
250
+ const deserializedPurchaseTransition = deserializedTransitions[0].transferTransition
251
+
252
+ assert.notEqual(documentInstance.__wbg_ptr, 0)
253
+ assert.notEqual(transferTransition.__wbg_ptr, 0)
254
+ assert.notEqual(documentTransition.__wbg_ptr, 0)
255
+ assert.notEqual(batchTransition.__wbg_ptr, 0)
256
+ assert.notEqual(st.__wbg_ptr, 0)
257
+ assert.notEqual(deserializedBatch.__wbg_ptr, 0)
258
+ assert.notEqual(deserializedPurchaseTransition.__wbg_ptr, 0)
259
+ })
260
+ })
261
+
262
+ describe('document UpdatePrice transition', function () {
263
+ it('should allow to create UpdatePriceTransition from document', () => {
264
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
265
+ const updatePriceTransition = new wasm.DocumentUpdatePriceTransitionWASM(documentInstance, BigInt(1), 'preorder', BigInt(100))
266
+
267
+ assert.notEqual(documentInstance.__wbg_ptr, 0)
268
+ assert.notEqual(updatePriceTransition.__wbg_ptr, 0)
269
+ })
270
+
271
+ it('should allow to create Document Transition from UpdatePrice transition', () => {
272
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
273
+ const updatePriceTransition = new wasm.DocumentUpdatePriceTransitionWASM(documentInstance, BigInt(1), 'preorder', BigInt(100))
274
+
275
+ const documentTransition = updatePriceTransition.toDocumentTransition()
276
+
277
+ assert.notEqual(documentInstance.__wbg_ptr, 0)
278
+ assert.notEqual(updatePriceTransition.__wbg_ptr, 0)
279
+ assert.notEqual(documentTransition.__wbg_ptr, 0)
280
+ })
281
+
282
+ it('should allow to create Document Batch Transition from Document Transitions', () => {
283
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
284
+ const updatePriceTransition = new wasm.DocumentUpdatePriceTransitionWASM(documentInstance, BigInt(1), 'preorder', BigInt(100))
285
+
286
+ const documentTransition = updatePriceTransition.toDocumentTransition()
287
+
288
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], Array.from(documentInstance.getOwnerId()), 1, 1)
289
+
290
+ assert.notEqual(documentInstance.__wbg_ptr, 0)
291
+ assert.notEqual(updatePriceTransition.__wbg_ptr, 0)
292
+ assert.notEqual(documentTransition.__wbg_ptr, 0)
293
+ assert.notEqual(batchTransition.__wbg_ptr, 0)
294
+ })
295
+
296
+ it('should allow to create state transitions from document and convert state transition to document batch', () => {
297
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
298
+ const updatePriceTransition = new wasm.DocumentUpdatePriceTransitionWASM(documentInstance, BigInt(1), 'preorder', BigInt(100))
299
+
300
+ const documentTransition = updatePriceTransition.toDocumentTransition()
301
+
302
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], Array.from(documentInstance.getOwnerId()), 1, 1)
303
+
304
+ const st = batchTransition.toStateTransition()
305
+
306
+ const deserializedBatch = wasm.DocumentsBatchWASM.fromStateTransition(st)
307
+
308
+ const deserializedTransitions = deserializedBatch.transitions
309
+
310
+ assert.equal(deserializedTransitions.length, 2)
311
+
312
+ const deserializedPurchaseTransition = deserializedTransitions[0].updatePriceTransition
313
+
314
+ assert.notEqual(documentInstance.__wbg_ptr, 0)
315
+ assert.notEqual(updatePriceTransition.__wbg_ptr, 0)
316
+ assert.notEqual(documentTransition.__wbg_ptr, 0)
317
+ assert.notEqual(batchTransition.__wbg_ptr, 0)
318
+ assert.notEqual(st.__wbg_ptr, 0)
319
+ assert.notEqual(deserializedBatch.__wbg_ptr, 0)
320
+ assert.notEqual(deserializedPurchaseTransition.__wbg_ptr, 0)
321
+ })
322
+ })
323
+
324
+ describe('document Purchase transition', function () {
325
+ it('should allow to create PurchaseTransition from document', () => {
326
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
327
+ const purchaseTransition = new wasm.DocumentPurchaseTransitionWASM(documentInstance, BigInt(1), 'preorder', BigInt(100))
328
+
329
+ assert.notEqual(documentInstance.__wbg_ptr, 0)
330
+ assert.notEqual(purchaseTransition.__wbg_ptr, 0)
331
+ })
332
+
333
+ it('should allow to create Document Transition from PurchaseTransition transition', () => {
334
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
335
+ const purchaseTransition = new wasm.DocumentPurchaseTransitionWASM(documentInstance, BigInt(1), 'preorder', BigInt(100))
336
+
337
+ const documentTransition = purchaseTransition.toDocumentTransition()
338
+
339
+ assert.notEqual(documentInstance.__wbg_ptr, 0)
340
+ assert.notEqual(purchaseTransition.__wbg_ptr, 0)
341
+ assert.notEqual(documentTransition.__wbg_ptr, 0)
342
+ })
343
+
344
+ it('should allow to create Document Batch Transition from Document Transitions', () => {
345
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
346
+ const purchaseTransition = new wasm.DocumentPurchaseTransitionWASM(documentInstance, BigInt(1), 'preorder', BigInt(100))
347
+
348
+ const documentTransition = purchaseTransition.toDocumentTransition()
349
+
350
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], Array.from(documentInstance.getOwnerId()), 1, 1)
351
+
352
+ assert.notEqual(documentInstance.__wbg_ptr, 0)
353
+ assert.notEqual(purchaseTransition.__wbg_ptr, 0)
354
+ assert.notEqual(documentTransition.__wbg_ptr, 0)
355
+ assert.notEqual(batchTransition.__wbg_ptr, 0)
356
+ })
357
+
358
+ it('should allow to create state transitions from document and convert state transition to document batch', () => {
359
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
360
+ const purchaseTransition = new wasm.DocumentPurchaseTransitionWASM(documentInstance, BigInt(1), 'preorder', BigInt(100))
361
+
362
+ const documentTransition = purchaseTransition.toDocumentTransition()
363
+
364
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], Array.from(documentInstance.getOwnerId()), 1, 1)
365
+
366
+ const st = batchTransition.toStateTransition()
367
+
368
+ const deserializedBatch = wasm.DocumentsBatchWASM.fromStateTransition(st)
369
+
370
+ const deserializedTransitions = deserializedBatch.transitions
371
+
372
+ assert.equal(deserializedTransitions.length, 2)
373
+
374
+ const deserializedPurchaseTransition = deserializedTransitions[0].purchaseTransition
375
+
376
+ assert.notEqual(documentInstance.__wbg_ptr, 0)
377
+ assert.notEqual(purchaseTransition.__wbg_ptr, 0)
378
+ assert.notEqual(documentTransition.__wbg_ptr, 0)
379
+ assert.notEqual(batchTransition.__wbg_ptr, 0)
380
+ assert.notEqual(st.__wbg_ptr, 0)
381
+ assert.notEqual(deserializedBatch.__wbg_ptr, 0)
382
+ assert.notEqual(deserializedPurchaseTransition.__wbg_ptr, 0)
383
+ })
384
+ })
385
+ })
386
+ describe('getters', function () {
387
+ describe('document Create transition', function () {
388
+ it('get data', () => {
389
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
390
+ const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1), 'preorder')
391
+
392
+ assert.deepEqual(createTransition.data, document)
393
+ })
394
+
395
+ it('get base', () => {
396
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
397
+ const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1), 'preorder')
398
+
399
+ assert.equal(createTransition.base.constructor.name, 'DocumentBaseTransitionWASM')
400
+ })
401
+
402
+ it('get entropy', () => {
403
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
404
+ const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1), 'preorder')
405
+
406
+ assert.deepEqual(createTransition.entropy, documentInstance.getEntropy())
407
+ })
408
+
409
+ it('get prefunded voting balance', () => {
410
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
411
+ const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1), 'preorder')
412
+
413
+ assert.equal(createTransition.prefundedVotingBalance, undefined)
414
+ })
415
+ })
416
+
417
+ describe('document Delete transition', function () {
418
+ it('get base', () => {
419
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
420
+ const deleteTransition = new wasm.DocumentDeleteTransitionWASM(documentInstance, BigInt(1), 'preorder')
421
+
422
+ assert.equal(deleteTransition.base.constructor.name, 'DocumentBaseTransitionWASM')
423
+ })
424
+ })
425
+
426
+ describe('document Replace transition', function () {
427
+ it('get data', () => {
428
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
429
+ const replaceTransition = new wasm.DocumentReplaceTransitionWASM(documentInstance, BigInt(1), 'preorder')
430
+
431
+ assert.deepEqual(replaceTransition.data, document)
432
+ })
433
+
434
+ it('get base', () => {
435
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
436
+ const replaceTransition = new wasm.DocumentReplaceTransitionWASM(documentInstance, BigInt(1), 'preorder')
437
+
438
+ assert.equal(replaceTransition.base.constructor.name, 'DocumentBaseTransitionWASM')
439
+ })
440
+
441
+ it('get revision', () => {
442
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
443
+ const replaceTransition = new wasm.DocumentReplaceTransitionWASM(documentInstance, BigInt(1), 'preorder')
444
+
445
+ assert.equal(replaceTransition.revision, BigInt(1))
446
+ })
447
+ })
448
+
449
+ describe('document Transfer transition', function () {
450
+ it('get base', () => {
451
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
452
+ const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), 'preorder', Array.from(documentInstance.getOwnerId()))
453
+
454
+ assert.equal(transferTransition.base.constructor.name, 'DocumentBaseTransitionWASM')
455
+ })
456
+
457
+ it('get recipient', () => {
458
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
459
+ const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), 'preorder', Array.from(documentInstance.getOwnerId()))
460
+
461
+ assert.deepEqual(transferTransition.recipientId, documentInstance.getOwnerId())
462
+ })
463
+ })
464
+
465
+ describe('document Update Price transition', function () {
466
+ it('get base', () => {
467
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
468
+ const updatePriceTransition = new wasm.DocumentUpdatePriceTransitionWASM(documentInstance, BigInt(1), 'preorder', BigInt(100))
469
+
470
+ assert.equal(updatePriceTransition.base.constructor.name, 'DocumentBaseTransitionWASM')
471
+ })
472
+
473
+ it('get price', () => {
474
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
475
+ const updatePriceTransition = new wasm.DocumentUpdatePriceTransitionWASM(documentInstance, BigInt(1), 'preorder', BigInt(100))
476
+
477
+ assert.deepEqual(updatePriceTransition.price, BigInt(100))
478
+ })
479
+ })
480
+
481
+ describe('document Purchase transition', function () {
482
+ it('get base', () => {
483
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
484
+ const purchaseTransition = new wasm.DocumentPurchaseTransitionWASM(documentInstance, BigInt(1), 'preorder', BigInt(100))
485
+
486
+ assert.equal(purchaseTransition.base.constructor.name, 'DocumentBaseTransitionWASM')
487
+ })
488
+
489
+ it('get price', () => {
490
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
491
+ const purchaseTransition = new wasm.DocumentPurchaseTransitionWASM(documentInstance, BigInt(1), 'preorder', BigInt(100))
492
+
493
+ assert.deepEqual(purchaseTransition.price, BigInt(100))
494
+ })
495
+ })
496
+ })
497
+
498
+ describe('setters', function () {
499
+ describe('document Create transition', function () {
500
+ it('set data', () => {
501
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
502
+ const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1), 'preorder')
503
+
504
+ const newData = { message: 'bebra' }
505
+
506
+ createTransition.data = newData
507
+
508
+ assert.deepEqual(createTransition.data, newData)
509
+ })
510
+
511
+ it('set base', () => {
512
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
513
+ const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1), 'preorder')
514
+
515
+ const newBase = new wasm.DocumentBaseTransitionWASM(
516
+ documentInstance.getId(),
517
+ BigInt(12350),
518
+ 'bbbbb',
519
+ dataContractId
520
+ )
521
+
522
+ createTransition.base = newBase
523
+
524
+ assert.equal(createTransition.base.identityContractNonce, newBase.identityContractNonce)
525
+ assert.notEqual(newBase.__wbg_ptr, 0)
526
+ })
527
+
528
+ it('set entropy', () => {
529
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
530
+ const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1), 'preorder')
531
+
532
+ const newEntropy = new Uint8Array(32)
533
+
534
+ createTransition.entropy = newEntropy
535
+
536
+ assert.deepEqual(createTransition.entropy, newEntropy)
537
+ })
538
+
539
+ it('set prefunded voting balance', () => {
540
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
541
+ const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1), 'preorder')
542
+
543
+ const newPrefundedVotingBalance = new wasm.PrefundedVotingBalanceWASM('note', BigInt(9999))
544
+
545
+ createTransition.prefundedVotingBalance = newPrefundedVotingBalance
546
+
547
+ assert.equal(createTransition.prefundedVotingBalance.indexName, newPrefundedVotingBalance.indexName)
548
+ assert.equal(createTransition.prefundedVotingBalance.credits, newPrefundedVotingBalance.credits)
549
+ })
550
+ })
551
+
552
+ describe('document Delete transition', function () {
553
+ it('set base', () => {
554
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
555
+ const deleteTransition = new wasm.DocumentDeleteTransitionWASM(documentInstance, BigInt(1), 'preorder')
556
+
557
+ const newBase = new wasm.DocumentBaseTransitionWASM(
558
+ documentInstance.getId(),
559
+ BigInt(12350),
560
+ 'bbbbb',
561
+ dataContractId
562
+ )
563
+
564
+ deleteTransition.base = newBase
565
+
566
+ assert.equal(deleteTransition.base.identityContractNonce, newBase.identityContractNonce)
567
+ assert.notEqual(newBase.__wbg_ptr, 0)
568
+ })
569
+ })
570
+
571
+ describe('document Replace transition', function () {
572
+ it('set data', () => {
573
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
574
+ const replaceTransition = new wasm.DocumentReplaceTransitionWASM(documentInstance, BigInt(1), 'preorder')
575
+
576
+ const newData = { message: 'bebra' }
577
+
578
+ replaceTransition.data = newData
579
+
580
+ assert.deepEqual(replaceTransition.data, newData)
581
+ })
582
+
583
+ it('set base', () => {
584
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
585
+ const replaceTransition = new wasm.DocumentReplaceTransitionWASM(documentInstance, BigInt(1), 'preorder')
586
+
587
+ const newBase = new wasm.DocumentBaseTransitionWASM(
588
+ documentInstance.getId(),
589
+ BigInt(12350),
590
+ 'bbbbb',
591
+ dataContractId
592
+ )
593
+
594
+ replaceTransition.base = newBase
595
+
596
+ assert.equal(replaceTransition.base.identityContractNonce, newBase.identityContractNonce)
597
+ assert.notEqual(newBase.__wbg_ptr, 0)
598
+ })
599
+
600
+ it('set revision', () => {
601
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
602
+ const replaceTransition = new wasm.DocumentReplaceTransitionWASM(documentInstance, BigInt(1), 'preorder')
603
+
604
+ replaceTransition.revision = BigInt(11)
605
+
606
+ assert.equal(replaceTransition.revision, BigInt(11))
607
+ })
608
+ })
609
+
610
+ describe('document Transfer transition', function () {
611
+ it('set base', () => {
612
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
613
+ const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), 'preorder', Array.from(documentInstance.getOwnerId()))
614
+
615
+ const newBase = new wasm.DocumentBaseTransitionWASM(
616
+ documentInstance.getId(),
617
+ BigInt(12350),
618
+ 'bbbbb',
619
+ dataContractId
620
+ )
621
+
622
+ transferTransition.base = newBase
623
+
624
+ assert.equal(transferTransition.base.identityContractNonce, newBase.identityContractNonce)
625
+ assert.notEqual(newBase.__wbg_ptr, 0)
626
+ })
627
+
628
+ it('set recipient', () => {
629
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
630
+ const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), 'preorder', Array.from(documentInstance.getOwnerId()))
631
+
632
+ const newRecipient = new Uint8Array(32)
633
+
634
+ transferTransition.recipientId = newRecipient
635
+
636
+ assert.deepEqual(transferTransition.recipientId, newRecipient)
637
+ })
638
+ })
639
+
640
+ describe('document Update Price transition', function () {
641
+ it('set base', () => {
642
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
643
+ const updatePriceTransition = new wasm.DocumentUpdatePriceTransitionWASM(documentInstance, BigInt(1), 'preorder', BigInt(100))
644
+
645
+ const newBase = new wasm.DocumentBaseTransitionWASM(
646
+ documentInstance.getId(),
647
+ BigInt(12350),
648
+ 'bbbbb',
649
+ dataContractId
650
+ )
651
+
652
+ updatePriceTransition.base = newBase
653
+
654
+ assert.equal(updatePriceTransition.base.identityContractNonce, newBase.identityContractNonce)
655
+ assert.notEqual(newBase.__wbg_ptr, 0)
656
+ })
657
+
658
+ it('set price', () => {
659
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
660
+ const updatePriceTransition = new wasm.DocumentUpdatePriceTransitionWASM(documentInstance, BigInt(1), 'preorder', BigInt(100))
661
+
662
+ updatePriceTransition.price = BigInt(1111)
663
+
664
+ assert.deepEqual(updatePriceTransition.price, BigInt(1111))
665
+ })
666
+ })
667
+
668
+ describe('document Purchase transition', function () {
669
+ it('set base', () => {
670
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
671
+ const purchaseTransition = new wasm.DocumentPurchaseTransitionWASM(documentInstance, BigInt(1), 'preorder', BigInt(100))
672
+
673
+ const newBase = new wasm.DocumentBaseTransitionWASM(
674
+ documentInstance.getId(),
675
+ BigInt(12350),
676
+ 'bbbbb',
677
+ dataContractId
678
+ )
679
+
680
+ purchaseTransition.base = newBase
681
+
682
+ assert.equal(purchaseTransition.base.identityContractNonce, newBase.identityContractNonce)
683
+ assert.notEqual(newBase.__wbg_ptr, 0)
684
+ })
685
+
686
+ it('set price', () => {
687
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
688
+ const purchaseTransition = new wasm.DocumentPurchaseTransitionWASM(documentInstance, BigInt(1), 'preorder', BigInt(100))
689
+
690
+ purchaseTransition.price = BigInt(1111)
691
+
692
+ assert.deepEqual(purchaseTransition.price, BigInt(1111))
693
+ })
694
+
695
+ it('set revision', () => {
696
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
697
+ const purchaseTransition = new wasm.DocumentPurchaseTransitionWASM(documentInstance, BigInt(1), 'preorder', BigInt(100))
698
+
699
+ purchaseTransition.revision = BigInt(1111)
700
+
701
+ assert.deepEqual(purchaseTransition.revision, BigInt(1111))
702
+ })
703
+ })
704
+ })
705
+ })