pshenmic-dpp 1.0.4 → 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 (81) hide show
  1. package/.github/workflows/build.yml +8 -0
  2. package/.github/workflows/publish.yml +8 -0
  3. package/Cargo.lock +79 -31
  4. package/Cargo.toml +20 -17
  5. package/README.md +66 -23
  6. package/babel.config.json +19 -0
  7. package/dist/wasm/pshenmic_dpp.js +2487 -355
  8. package/dist/wasm/pshenmic_dpp_bg.js +1 -1
  9. package/package.json +13 -6
  10. package/packages/cbor_conversation/Cargo.toml +1 -1
  11. package/packages/data_contract/Cargo.toml +2 -2
  12. package/packages/data_contract/src/lib.rs +195 -23
  13. package/packages/data_contract_transitions/Cargo.toml +1 -1
  14. package/packages/data_contract_transitions/src/create/mod.rs +23 -16
  15. package/packages/data_contract_transitions/src/update/mod.rs +21 -12
  16. package/packages/document/Cargo.toml +1 -1
  17. package/packages/document/src/lib.rs +1 -1
  18. package/packages/document/src/methods/mod.rs +370 -2
  19. package/packages/{document_batch → documents_batch}/Cargo.toml +6 -4
  20. package/packages/documents_batch/src/document_base_transition/mod.rs +92 -0
  21. package/packages/documents_batch/src/document_transition/mod.rs +166 -0
  22. package/packages/documents_batch/src/generators.rs +122 -0
  23. package/packages/documents_batch/src/lib.rs +188 -0
  24. package/packages/documents_batch/src/prefunded_voting_balance/mod.rs +45 -0
  25. package/packages/documents_batch/src/transitions/create/mod.rs +123 -0
  26. package/packages/documents_batch/src/transitions/delete/mod.rs +67 -0
  27. package/packages/documents_batch/src/transitions/mod.rs +6 -0
  28. package/packages/documents_batch/src/transitions/purchase/mod.rs +91 -0
  29. package/packages/documents_batch/src/transitions/replace/mod.rs +93 -0
  30. package/packages/documents_batch/src/transitions/transfer/mod.rs +86 -0
  31. package/packages/documents_batch/src/transitions/update_price/mod.rs +75 -0
  32. package/packages/enums/Cargo.toml +3 -3
  33. package/packages/enums/src/batch/batch_enum.rs +75 -10
  34. package/packages/enums/src/keys/key_type.rs +46 -0
  35. package/packages/enums/src/keys/purpose.rs +55 -0
  36. package/packages/enums/src/keys/security_level.rs +46 -0
  37. package/packages/enums/src/lib.rs +1 -0
  38. package/packages/enums/src/network/mod.rs +67 -0
  39. package/packages/enums/src/platform/mod.rs +66 -8
  40. package/packages/identity/Cargo.toml +3 -4
  41. package/packages/identity/src/lib.rs +25 -14
  42. package/packages/{public_key → identity_public_key}/Cargo.toml +1 -1
  43. package/packages/{public_key → identity_public_key}/src/lib.rs +74 -27
  44. package/packages/identity_transitions/Cargo.toml +2 -2
  45. package/packages/identity_transitions/src/create_transition/mod.rs +3 -1
  46. package/packages/identity_transitions/src/create_transition/public_key_in_creation/mod.rs +25 -21
  47. package/packages/mock_bls/Cargo.toml +1 -1
  48. package/packages/private_key/Cargo.toml +3 -2
  49. package/packages/private_key/src/lib.rs +44 -6
  50. package/packages/state_transition/Cargo.toml +5 -4
  51. package/packages/state_transition/src/lib.rs +101 -36
  52. package/packages/utils/Cargo.toml +1 -2
  53. package/packages/utils/src/lib.rs +17 -15
  54. package/scripts/build-js.sh +6 -5
  55. package/scripts/build.sh +22 -1
  56. package/src/lib.rs +7 -1
  57. package/tests/DataContract.spec.js +175 -0
  58. package/tests/DataContractCreateStateTransition.spec.js +109 -0
  59. package/tests/DataContractUpdateStateTransition.spec.js +109 -0
  60. package/tests/Document.spec.js +232 -0
  61. package/tests/DocumentBatchTransition.spec.js +109 -0
  62. package/tests/DocumentTransition.spec.js +97 -0
  63. package/tests/DocumentsTransitions.spec.js +705 -0
  64. package/tests/Identity.spec.js +113 -0
  65. package/tests/IdentityPublicKey.spec.js +132 -0
  66. package/tests/PrivateKey.spec.js +73 -0
  67. package/tests/mocks/DataContract/DataContract.json +153 -0
  68. package/tests/mocks/DataContract/index.js +6 -0
  69. package/tests/mocks/Document/DataContract.json +23 -0
  70. package/tests/mocks/Document/document.json +3 -0
  71. package/tests/mocks/Document/document2.json +3 -0
  72. package/tests/mocks/Document/index.js +11 -0
  73. package/tests/mocks/Identity/index.js +7 -0
  74. package/tests/mocks/PrivateKey/index.js +5 -0
  75. package/tests/mocks/PublicKey/index.js +14 -0
  76. package/tests/utils/hex.js +15 -0
  77. package/tests/utils/wasm.js +14 -0
  78. package/packages/document/src/methods/js.rs +0 -260
  79. package/packages/document/src/methods/rust.rs +0 -92
  80. package/packages/document_batch/src/generators.rs +0 -63
  81. package/packages/document_batch/src/lib.rs +0 -228
@@ -0,0 +1,109 @@
1
+ const assert = require('assert')
2
+ const { describe, it, before } = require('mocha')
3
+ const initWasm = require('./utils/wasm')
4
+ const { value, dataContractsBytes } = require('./mocks/DataContract')
5
+ const { PlatformVersionWASM } = require('../dist/cjs/wasm/pshenmic_dpp')
6
+ const { fromHexString } = require('./utils/hex')
7
+
8
+ let wasm
9
+
10
+ describe('DataContract Updatet Transition', function () {
11
+ before(async function () {
12
+ wasm = initWasm()
13
+ })
14
+
15
+ describe('serialization / deserialization', function () {
16
+ it('should allow to create transitions from data contract', () => {
17
+ const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1)
18
+
19
+ const dataContractTransition = new wasm.DataContractUpdateTransitionWASM(dataContract, BigInt(1))
20
+
21
+ assert.notEqual(dataContractTransition.__wbg_ptr, 0)
22
+ assert.notEqual(dataContract.__wbg_ptr, 0)
23
+ })
24
+
25
+ it('should allow to convert transitions to bytes and create from bytes', () => {
26
+ const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1)
27
+
28
+ const dataContractTransition = new wasm.DataContractUpdateTransitionWASM(dataContract, BigInt(1))
29
+
30
+ const bytes = dataContractTransition.toBytes()
31
+
32
+ const newDataContractTransition = wasm.DataContractUpdateTransitionWASM.fromBytes(bytes)
33
+
34
+ assert.deepEqual(newDataContractTransition.toBytes(), bytes)
35
+ assert.notEqual(newDataContractTransition.__wbg_ptr, 0)
36
+ assert.notEqual(dataContractTransition.__wbg_ptr, 0)
37
+ assert.notEqual(dataContract.__wbg_ptr, 0)
38
+ })
39
+
40
+ it('should allow to convert data contract transition to state transitions and create data contract transition from state transition', () => {
41
+ const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1)
42
+
43
+ const dataContractTransition = new wasm.DataContractUpdateTransitionWASM(dataContract, BigInt(1))
44
+
45
+ const stateTransition = dataContractTransition.toStateTransition()
46
+
47
+ const newDataContractTransition = wasm.DataContractUpdateTransitionWASM.fromStateTransition(stateTransition)
48
+
49
+ assert.deepEqual(dataContractTransition.toBytes(), newDataContractTransition.toBytes())
50
+ })
51
+ })
52
+
53
+ describe('getters', function () {
54
+ it('should allow to get feature version', () => {
55
+ const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1)
56
+
57
+ const dataContractTransition = new wasm.DataContractUpdateTransitionWASM(dataContract, BigInt(1))
58
+
59
+ assert.equal(dataContractTransition.getFeatureVersion(), 0)
60
+ })
61
+
62
+ it('should allow to verify protocol version', () => {
63
+ const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1)
64
+
65
+ const dataContractTransition = new wasm.DataContractUpdateTransitionWASM(dataContract, BigInt(1))
66
+
67
+ assert.equal(dataContractTransition.verifyProtocolVersion(1), true)
68
+ })
69
+
70
+ it('should allow to verify incorrect protocol version', () => {
71
+ const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1)
72
+
73
+ const dataContractTransition = new wasm.DataContractUpdateTransitionWASM(dataContract, BigInt(1))
74
+
75
+ try {
76
+ dataContractTransition.verifyProtocolVersion(20)
77
+ assert.equal(true, false)
78
+ } catch (error) {
79
+ assert.equal(false, false)
80
+ }
81
+ })
82
+
83
+ it('should allow to get data contract', () => {
84
+ const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1)
85
+
86
+ const dataContractTransition = new wasm.DataContractUpdateTransitionWASM(dataContract, BigInt(1))
87
+
88
+ const newDataContract = dataContractTransition.getDataContract()
89
+
90
+ assert.deepEqual(dataContract.toBytes(), newDataContract.toBytes())
91
+ })
92
+ })
93
+
94
+ describe('setters', function () {
95
+ it('should allow to set the data contract', () => {
96
+ const [dataContractBytes] = dataContractsBytes
97
+
98
+ const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1)
99
+
100
+ const dataContractTransition = new wasm.DataContractUpdateTransitionWASM(dataContract, BigInt(1))
101
+
102
+ const newDataContract = wasm.DataContractWASM.fromBytes(fromHexString(dataContractBytes), false, PlatformVersionWASM.PLATFORM_V1)
103
+
104
+ dataContractTransition.setDataContract(newDataContract)
105
+
106
+ assert.deepEqual(fromHexString(dataContractBytes), newDataContract.toBytes())
107
+ })
108
+ })
109
+ })
@@ -0,0 +1,232 @@
1
+ const assert = require('assert')
2
+ const { describe, it, before } = require('mocha')
3
+ const initWasm = require('./utils/wasm')
4
+ const {
5
+ document, dataContractId, ownerId, documentTypeName, revision, dataContractValue, id, document2, documentBytes
6
+ } = require('./mocks/Document')
7
+ const { fromHexString } = require('./utils/hex')
8
+ const { base58 } = require('@scure/base')
9
+
10
+ let wasm
11
+
12
+ describe('Document', function () {
13
+ before(async function () {
14
+ wasm = initWasm()
15
+ })
16
+
17
+ describe('serialization / deserialization', function () {
18
+ it('should allows to create Document from values', function () {
19
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId)
20
+
21
+ assert.notEqual(documentInstance.__wbg_ptr, 0)
22
+ })
23
+
24
+ it('should allows to create Document from values with custom id', function () {
25
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
26
+
27
+ assert.notEqual(documentInstance.__wbg_ptr, 0)
28
+ })
29
+
30
+ it('should allows to create Document from bytes and convert to bytes', function () {
31
+ const dataContract = wasm.DataContractWASM.fromValue(dataContractValue, false)
32
+ const documentInstance = wasm.DocumentWASM.fromBytes(fromHexString(documentBytes), dataContract, 'note')
33
+
34
+ const bytes = documentInstance.toBytes(dataContract, 'note')
35
+
36
+ assert.deepEqual(bytes, fromHexString(documentBytes))
37
+ assert.notEqual(dataContract.__wbg_ptr, 0)
38
+ })
39
+ })
40
+
41
+ describe('getters', function () {
42
+ it('should return document id', () => {
43
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
44
+
45
+ assert.deepEqual(documentInstance.getId(), base58.decode(id))
46
+ })
47
+
48
+ it('should return owner id', () => {
49
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
50
+
51
+ assert.deepEqual(documentInstance.getOwnerId(), base58.decode(ownerId))
52
+ })
53
+
54
+ it('should return data contract id', () => {
55
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
56
+
57
+ assert.deepEqual(documentInstance.getDataContractId(), base58.decode(dataContractId))
58
+ })
59
+
60
+ it('should return properties', () => {
61
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
62
+
63
+ assert.deepEqual(documentInstance.getProperties(), document)
64
+ })
65
+
66
+ it('should return revision', () => {
67
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
68
+
69
+ assert.deepEqual(documentInstance.getRevision(), revision)
70
+ })
71
+
72
+ it('should return revision', () => {
73
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
74
+
75
+ assert.deepEqual(documentInstance.getRevision(), revision)
76
+ })
77
+ })
78
+
79
+ describe('setters', function () {
80
+ it('should allow to set document id', () => {
81
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
82
+
83
+ documentInstance.setId(ownerId)
84
+
85
+ assert.deepEqual(documentInstance.getId(), base58.decode(ownerId))
86
+ })
87
+
88
+ it('should allow to set document owner id', () => {
89
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
90
+
91
+ documentInstance.setOwnerId(id)
92
+
93
+ assert.deepEqual(documentInstance.getOwnerId(), base58.decode(id))
94
+ })
95
+
96
+ it('should allow to set entropy', () => {
97
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
98
+
99
+ const newEntropy = new Array(documentInstance.getEntropy().length).fill(0)
100
+
101
+ documentInstance.setEntropy(newEntropy)
102
+
103
+ assert.deepEqual(Array.from(documentInstance.getEntropy()), newEntropy)
104
+ })
105
+
106
+ it('should allow to set properties', () => {
107
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
108
+
109
+ documentInstance.setProperties(document2)
110
+
111
+ assert.deepEqual(documentInstance.getProperties(), document2)
112
+ })
113
+
114
+ it('should allow to set revision', () => {
115
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
116
+
117
+ const newRevision = BigInt(1000)
118
+
119
+ documentInstance.setRevision(newRevision)
120
+
121
+ assert.deepEqual(documentInstance.getRevision(), newRevision)
122
+ })
123
+
124
+ it('should allow to set created at', () => {
125
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
126
+
127
+ const createdAt = BigInt(new Date(1123).getTime())
128
+
129
+ documentInstance.setCreatedAt(createdAt)
130
+
131
+ assert.deepEqual(documentInstance.getCreatedAt(), createdAt)
132
+ })
133
+
134
+ it('should allow to set updated at', () => {
135
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
136
+
137
+ const updatedAt = BigInt(new Date(1123).getTime())
138
+
139
+ documentInstance.setUpdatedAt(updatedAt)
140
+
141
+ assert.deepEqual(documentInstance.getUpdatedAt(), updatedAt)
142
+ })
143
+
144
+ it('should allow to set transferred at', () => {
145
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
146
+
147
+ const transferredAt = BigInt(new Date(11231).getTime())
148
+
149
+ documentInstance.setTransferredAt(transferredAt)
150
+
151
+ assert.deepEqual(documentInstance.getTransferredAt(), transferredAt)
152
+ })
153
+
154
+ it('should allow to set create at Block Height', () => {
155
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
156
+
157
+ const createdAtHeight = BigInt(9172)
158
+
159
+ documentInstance.setCreatedAtBlockHeight(createdAtHeight)
160
+
161
+ assert.deepEqual(documentInstance.getCreatedAtBlockHeight(), createdAtHeight)
162
+ })
163
+
164
+ it('should allow to set updated at Block Height', () => {
165
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
166
+
167
+ const updatedAtHeight = BigInt(9172)
168
+
169
+ documentInstance.setUpdatedAtBlockHeight(updatedAtHeight)
170
+
171
+ assert.deepEqual(documentInstance.getUpdatedAtBlockHeight(), updatedAtHeight)
172
+ })
173
+
174
+ it('should allow to set transferred at Block Height', () => {
175
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
176
+
177
+ const transferredAtHeight = BigInt(9172)
178
+
179
+ documentInstance.setTransferredAtBlockHeight(transferredAtHeight)
180
+
181
+ assert.deepEqual(documentInstance.getTransferredAtBlockHeight(), transferredAtHeight)
182
+ })
183
+
184
+ it('should allow to set create at core Block Height', () => {
185
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
186
+
187
+ const createdAtHeight = 91721
188
+
189
+ documentInstance.setCreatedAtCoreBlockHeight(createdAtHeight)
190
+
191
+ assert.deepEqual(documentInstance.getCreatedAtCoreBlockHeight(), createdAtHeight)
192
+ })
193
+
194
+ it('should allow to set updated at Block Height', () => {
195
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
196
+
197
+ const updatedAtHeight = 91722
198
+
199
+ documentInstance.setUpdatedAtCoreBlockHeight(updatedAtHeight)
200
+
201
+ assert.deepEqual(documentInstance.getUpdatedAtCoreBlockHeight(), updatedAtHeight)
202
+ })
203
+
204
+ it('should allow to set transferred at Block Height', () => {
205
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
206
+
207
+ const transferredAtHeight = 91723
208
+
209
+ documentInstance.setTransferredAtCoreBlockHeight(transferredAtHeight)
210
+
211
+ assert.deepEqual(documentInstance.getTransferredAtCoreBlockHeight(), transferredAtHeight)
212
+ })
213
+
214
+ it('should allow to set document type name', () => {
215
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
216
+
217
+ const newDocumentTypeName = 'bbbb'
218
+
219
+ documentInstance.setDocumentTypeName(newDocumentTypeName)
220
+
221
+ assert.deepEqual(documentInstance.getDocumentTypeName(), newDocumentTypeName)
222
+ })
223
+ })
224
+
225
+ describe('static', function () {
226
+ it('should allow to generate id', () => {
227
+ const generatedId = wasm.DocumentWASM.generateId('note', ownerId, dataContractId)
228
+
229
+ assert.equal(Array.from(generatedId).length, 32)
230
+ })
231
+ })
232
+ })
@@ -0,0 +1,109 @@
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('PrivateKey', function () {
9
+ before(async function () {
10
+ wasm = initWasm()
11
+ })
12
+
13
+ describe('serialization / deserialization', function () {
14
+ it('should allow to create from transitions', function () {
15
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
16
+ const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1), 'preorder')
17
+
18
+ const documentTransition = createTransition.toDocumentTransition()
19
+
20
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], Array.from(documentInstance.getOwnerId()), 1)
21
+
22
+ assert.notEqual(documentInstance.__wbg_ptr, 0)
23
+ assert.notEqual(createTransition.__wbg_ptr, 0)
24
+ assert.notEqual(documentTransition.__wbg_ptr, 0)
25
+ assert.notEqual(batchTransition.__wbg_ptr, 0)
26
+ })
27
+ })
28
+
29
+ describe('getters', function () {
30
+ it('should allow to get transitions', function () {
31
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
32
+ const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1), 'preorder')
33
+
34
+ const documentTransition = createTransition.toDocumentTransition()
35
+
36
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], Array.from(documentInstance.getOwnerId()), 1, 1)
37
+
38
+ assert.equal(batchTransition.transitions.length, 2)
39
+ })
40
+
41
+ it('should allow to get signature', function () {
42
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
43
+ const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1), 'preorder')
44
+
45
+ const documentTransition = createTransition.toDocumentTransition()
46
+
47
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], Array.from(documentInstance.getOwnerId()), 1, 1)
48
+
49
+ assert.deepEqual(batchTransition.signature, new Uint8Array(0))
50
+ })
51
+
52
+ it('should allow to get signature public key id', function () {
53
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
54
+ const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1), 'preorder')
55
+
56
+ const documentTransition = createTransition.toDocumentTransition()
57
+
58
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], Array.from(documentInstance.getOwnerId()), 1, 1)
59
+
60
+ assert.equal(batchTransition.signaturePublicKeyId, 1)
61
+ })
62
+
63
+ it('should allow to get all purchases amount', function () {
64
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
65
+ const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1), 'preorder')
66
+ const purchaseTransition = new wasm.DocumentPurchaseTransitionWASM(documentInstance, BigInt(1), 'preorder', BigInt(100))
67
+
68
+ const documentTransition = createTransition.toDocumentTransition()
69
+ const documentTransition2 = purchaseTransition.toDocumentTransition()
70
+
71
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition2], Array.from(documentInstance.getOwnerId()), 1, 1)
72
+
73
+ assert.deepEqual(batchTransition.allPurchasesAmount, BigInt(100))
74
+ })
75
+
76
+ it('should allow to get owner id', function () {
77
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
78
+ const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1), 'preorder')
79
+
80
+ const documentTransition = createTransition.toDocumentTransition()
81
+
82
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], Array.from(documentInstance.getOwnerId()), 1, 1)
83
+
84
+ assert.deepEqual(batchTransition.ownerId, documentInstance.getOwnerId())
85
+ })
86
+
87
+ it('should allow to get modified data ids', function () {
88
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
89
+ const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1), 'preorder')
90
+
91
+ const documentTransition = createTransition.toDocumentTransition()
92
+
93
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], Array.from(documentInstance.getOwnerId()), 1, 1)
94
+
95
+ assert.deepEqual(batchTransition.modifiedDataIds, [Array.from(documentTransition.id), Array.from(documentTransition.id)])
96
+ })
97
+
98
+ it('should allow to get allConflictingIndexCollateralVotingFunds', function () {
99
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
100
+ const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1), 'preorder')
101
+
102
+ const documentTransition = createTransition.toDocumentTransition()
103
+
104
+ const batchTransition = new wasm.DocumentsBatchWASM([documentTransition, documentTransition], Array.from(documentInstance.getOwnerId()), 1, 1)
105
+
106
+ assert.deepEqual(batchTransition.allConflictingIndexCollateralVotingFunds, undefined)
107
+ })
108
+ })
109
+ })
@@ -0,0 +1,97 @@
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
+ let documentInstance
8
+ let createTransition
9
+ let replaceTransition
10
+
11
+ describe('PrivateKey', function () {
12
+ before(async function () {
13
+ wasm = initWasm()
14
+
15
+ documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
16
+ createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1), 'note')
17
+ replaceTransition = new wasm.DocumentReplaceTransitionWASM(documentInstance, BigInt(1), 'preorder')
18
+ })
19
+
20
+ describe('serialization / deserialization', function () {
21
+ it('should allow to create from documents transitions', function () {
22
+ const documentTransition = createTransition.toDocumentTransition()
23
+
24
+ assert.notEqual(documentTransition.__wbg_ptr, 0)
25
+ })
26
+ })
27
+
28
+ describe('getters', function () {
29
+ it('should allow to get action type', function () {
30
+ const documentTransition = createTransition.toDocumentTransition()
31
+
32
+ assert.equal(documentTransition.actionType, 'create')
33
+ })
34
+
35
+ it('should allow to get dataContractId', function () {
36
+ const documentTransition = createTransition.toDocumentTransition()
37
+
38
+ assert.deepEqual(documentTransition.dataContractId, documentInstance.getDataContractId())
39
+ })
40
+
41
+ it('should allow to get id', function () {
42
+ const documentTransition = createTransition.toDocumentTransition()
43
+
44
+ assert.deepEqual(documentTransition.id, documentInstance.getId())
45
+ })
46
+
47
+ it('should allow to get documentTypeName', function () {
48
+ const documentTransition = createTransition.toDocumentTransition()
49
+
50
+ assert.equal(documentTransition.documentTypeName, documentTypeName)
51
+ })
52
+
53
+ it('should allow to get identityContractNonce', function () {
54
+ const documentTransition = createTransition.toDocumentTransition()
55
+
56
+ assert.equal(documentTransition.identityContractNonce, BigInt(1))
57
+ })
58
+
59
+ it('should allow to get revision', function () {
60
+ const documentTransition = createTransition.toDocumentTransition()
61
+
62
+ assert.equal(documentTransition.revision, BigInt(1))
63
+ })
64
+
65
+ it('should allow to get entropy', function () {
66
+ const documentTransition = createTransition.toDocumentTransition()
67
+
68
+ assert.deepEqual(documentTransition.entropy, documentInstance.getEntropy())
69
+ })
70
+ })
71
+
72
+ describe('setters', function () {
73
+ it('should allow to set dataContractId', function () {
74
+ const documentTransition = createTransition.toDocumentTransition()
75
+
76
+ documentTransition.dataContractId = new Uint8Array(32)
77
+
78
+ assert.deepEqual(documentTransition.dataContractId, new Uint8Array(32))
79
+ })
80
+
81
+ it('should allow to set identityContractNonce', function () {
82
+ const documentTransition = createTransition.toDocumentTransition()
83
+
84
+ documentTransition.identityContractNonce = BigInt(3333)
85
+
86
+ assert.equal(documentTransition.identityContractNonce, BigInt(3333))
87
+ })
88
+
89
+ it('should allow to set revision', function () {
90
+ const documentTransition = replaceTransition.toDocumentTransition()
91
+
92
+ documentTransition.revision = BigInt(123)
93
+
94
+ assert.equal(documentTransition.revision, BigInt(123))
95
+ })
96
+ })
97
+ })