pshenmic-dpp 1.0.4 → 1.0.6

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 (152) hide show
  1. package/.github/workflows/build.yml +9 -1
  2. package/.github/workflows/publish.yml +9 -1
  3. package/Cargo.lock +222 -76
  4. package/Cargo.toml +28 -19
  5. package/README.md +75 -23
  6. package/babel.config.json +19 -0
  7. package/dist/wasm/index.d.ts +52 -0
  8. package/dist/wasm/pshenmic_dpp.d.ts +962 -0
  9. package/dist/wasm/pshenmic_dpp.js +5565 -966
  10. package/dist/wasm/pshenmic_dpp_bg.js +1 -1
  11. package/dist/wasm/pshenmic_dpp_bg.wasm.d.ts +440 -0
  12. package/docs/AssetLockProof.md +107 -0
  13. package/docs/Building.md +50 -0
  14. package/docs/ChainLockProof.md +63 -0
  15. package/docs/CoreScript.md +17 -0
  16. package/docs/DataContract.md +192 -0
  17. package/docs/DataContractCreateTransition.md +84 -0
  18. package/docs/DataContractUpdateTransition.md +84 -0
  19. package/docs/Document.md +396 -0
  20. package/docs/DocumentBaseTransition.md +111 -0
  21. package/docs/DocumentCreateTransition.md +132 -0
  22. package/docs/DocumentDeleteTransition.md +82 -0
  23. package/docs/DocumentPurchaseTransition.md +109 -0
  24. package/docs/DocumentReplaceTransition.md +112 -0
  25. package/docs/DocumentTransferTransition.md +96 -0
  26. package/docs/DocumentTransition.md +125 -0
  27. package/docs/DocumentUpdatePriceTransition.md +109 -0
  28. package/docs/DocumentsBatch.md +133 -0
  29. package/docs/Enums.md +103 -0
  30. package/docs/Home.md +28 -0
  31. package/docs/Identifier.md +37 -0
  32. package/docs/Identity.md +140 -0
  33. package/docs/IdentityCreateTransition.md +155 -0
  34. package/docs/IdentityCreditTransfer.md +187 -0
  35. package/docs/IdentityCreditWithdrawalTransition.md +244 -0
  36. package/docs/IdentityPublicKey.md +348 -0
  37. package/docs/IdentityPublicKeyInCreation.md +141 -0
  38. package/docs/IdentityTopUpTransition.md +166 -0
  39. package/docs/IdentityUpdateTransition.md +234 -0
  40. package/docs/InstantAssetLockProof.md +117 -0
  41. package/docs/InstantLock.md +100 -0
  42. package/docs/OutPoint.md +80 -0
  43. package/docs/PrefundedVotingBalance.md +48 -0
  44. package/docs/PrivateKey.md +112 -0
  45. package/docs/TxOut.md +93 -0
  46. package/package.json +15 -8
  47. package/packages/asset_lock_proof/Cargo.toml +19 -0
  48. package/packages/asset_lock_proof/src/chain/mod.rs +79 -0
  49. package/packages/asset_lock_proof/src/instant/instant_lock.rs +111 -0
  50. package/packages/asset_lock_proof/src/instant/mod.rs +115 -0
  51. package/packages/asset_lock_proof/src/lib.rs +133 -0
  52. package/packages/asset_lock_proof/src/outpoint/mod.rs +79 -0
  53. package/packages/asset_lock_proof/src/tx_out/mod.rs +80 -0
  54. package/packages/cbor_conversation/Cargo.toml +2 -2
  55. package/packages/core_script/Cargo.toml +13 -0
  56. package/packages/core_script/src/lib.rs +69 -0
  57. package/packages/data_contract/Cargo.toml +4 -3
  58. package/packages/data_contract/src/lib.rs +209 -33
  59. package/packages/data_contract_transitions/Cargo.toml +2 -2
  60. package/packages/data_contract_transitions/src/create/mod.rs +23 -16
  61. package/packages/data_contract_transitions/src/update/mod.rs +21 -12
  62. package/packages/document/Cargo.toml +3 -2
  63. package/packages/document/src/lib.rs +14 -13
  64. package/packages/document/src/methods/mod.rs +373 -2
  65. package/packages/{document_batch → documents_batch}/Cargo.toml +7 -4
  66. package/packages/documents_batch/src/document_base_transition/mod.rs +88 -0
  67. package/packages/documents_batch/src/document_transition/mod.rs +166 -0
  68. package/packages/documents_batch/src/generators.rs +122 -0
  69. package/packages/documents_batch/src/lib.rs +195 -0
  70. package/packages/documents_batch/src/prefunded_voting_balance/mod.rs +45 -0
  71. package/packages/documents_batch/src/transitions/create/mod.rs +126 -0
  72. package/packages/documents_batch/src/transitions/delete/mod.rs +67 -0
  73. package/packages/documents_batch/src/transitions/mod.rs +6 -0
  74. package/packages/documents_batch/src/transitions/purchase/mod.rs +91 -0
  75. package/packages/documents_batch/src/transitions/replace/mod.rs +93 -0
  76. package/packages/documents_batch/src/transitions/transfer/mod.rs +84 -0
  77. package/packages/documents_batch/src/transitions/update_price/mod.rs +75 -0
  78. package/packages/enums/Cargo.toml +4 -4
  79. package/packages/enums/src/batch/batch_enum.rs +75 -10
  80. package/packages/enums/src/keys/key_type.rs +46 -0
  81. package/packages/enums/src/keys/purpose.rs +55 -0
  82. package/packages/enums/src/keys/security_level.rs +46 -0
  83. package/packages/enums/src/lib.rs +3 -0
  84. package/packages/enums/src/lock_types/mod.rs +65 -0
  85. package/packages/enums/src/network/mod.rs +67 -0
  86. package/packages/enums/src/platform/mod.rs +68 -8
  87. package/packages/enums/src/withdrawal/mod.rs +72 -0
  88. package/packages/identifier/Cargo.toml +9 -0
  89. package/packages/identifier/src/lib.rs +105 -0
  90. package/packages/identity/Cargo.toml +5 -5
  91. package/packages/identity/src/lib.rs +31 -25
  92. package/packages/{public_key → identity_public_key}/Cargo.toml +2 -2
  93. package/packages/{public_key → identity_public_key}/src/lib.rs +74 -27
  94. package/packages/identity_transitions/Cargo.toml +8 -4
  95. package/packages/identity_transitions/src/create_transition/mod.rs +102 -37
  96. package/packages/identity_transitions/src/credit_withdrawal_transition/mod.rs +212 -0
  97. package/packages/identity_transitions/src/identity_credit_transfer_transition/mod.rs +169 -0
  98. package/packages/identity_transitions/src/lib.rs +6 -1
  99. package/packages/identity_transitions/src/public_key_in_creation/mod.rs +197 -0
  100. package/packages/identity_transitions/src/top_up_transition/mod.rs +141 -0
  101. package/packages/identity_transitions/src/update_transition/mod.rs +213 -0
  102. package/packages/mock_bls/Cargo.toml +1 -1
  103. package/packages/private_key/Cargo.toml +4 -3
  104. package/packages/private_key/src/lib.rs +44 -6
  105. package/packages/state_transition/Cargo.toml +6 -4
  106. package/packages/state_transition/src/lib.rs +102 -36
  107. package/packages/utils/Cargo.toml +3 -4
  108. package/packages/utils/src/lib.rs +17 -18
  109. package/scripts/build-js.sh +22 -5
  110. package/scripts/build.sh +27 -2
  111. package/src/lib.rs +8 -1
  112. package/tests/AssetLockProof.spec.js +80 -0
  113. package/tests/ChainLockProof.spec.js +69 -0
  114. package/tests/CoreScript.spec.js +37 -0
  115. package/tests/DataContract.spec.js +178 -0
  116. package/tests/DataContractCreateStateTransition.spec.js +109 -0
  117. package/tests/DataContractUpdateStateTransition.spec.js +109 -0
  118. package/tests/Document.spec.js +238 -0
  119. package/tests/DocumentBatchTransition.spec.js +109 -0
  120. package/tests/DocumentTransition.spec.js +97 -0
  121. package/tests/DocumentsTransitions.spec.js +705 -0
  122. package/tests/Identifier.spec.js +84 -0
  123. package/tests/Identity.spec.js +113 -0
  124. package/tests/IdentityCreateTransition.spec.js +93 -0
  125. package/tests/IdentityCreditTransferTransition.spec.js +146 -0
  126. package/tests/IdentityCreditWithdrawalTransition.spec.js +192 -0
  127. package/tests/IdentityPublicKey.spec.js +132 -0
  128. package/tests/IdentityTopUpTransition.spec.js +131 -0
  129. package/tests/IdentityUpdateTransition.spec.js +147 -0
  130. package/tests/InstantLockProof.spec.js +97 -0
  131. package/tests/OutPoint.spec.js +55 -0
  132. package/tests/PrivateKey.spec.js +73 -0
  133. package/tests/PublicKeyInCreation.spec.js +258 -0
  134. package/tests/TxOut.spec.js +76 -0
  135. package/tests/mocks/DataContract/DataContract.json +153 -0
  136. package/tests/mocks/DataContract/index.js +6 -0
  137. package/tests/mocks/Document/DataContract.json +23 -0
  138. package/tests/mocks/Document/document.json +3 -0
  139. package/tests/mocks/Document/document2.json +3 -0
  140. package/tests/mocks/Document/index.js +11 -0
  141. package/tests/mocks/Identity/index.js +7 -0
  142. package/tests/mocks/Locks/index.js +5 -0
  143. package/tests/mocks/PrivateKey/index.js +5 -0
  144. package/tests/mocks/PublicKey/index.js +14 -0
  145. package/tests/utils/hex.js +15 -0
  146. package/tests/utils/wasm.js +14 -0
  147. package/typings/index.d.ts +52 -0
  148. package/packages/document/src/methods/js.rs +0 -260
  149. package/packages/document/src/methods/rust.rs +0 -92
  150. package/packages/document_batch/src/generators.rs +0 -63
  151. package/packages/document_batch/src/lib.rs +0 -228
  152. package/packages/identity_transitions/src/create_transition/public_key_in_creation/mod.rs +0 -146
@@ -0,0 +1,178 @@
1
+ const assert = require('assert')
2
+ const { describe, it, before } = require('mocha')
3
+ const initWasm = require('./utils/wasm')
4
+ const { value, id, ownerId } = require('./mocks/DataContract')
5
+ const { PlatformVersionWASM } = require('../dist/cjs/wasm/pshenmic_dpp')
6
+ const { fromHexString } = require('./utils/hex')
7
+
8
+ let wasm
9
+
10
+ let dataContractsBytes
11
+
12
+ describe('DataContract', function () {
13
+ before(async function () {
14
+ wasm = initWasm()
15
+
16
+ dataContractsBytes = ['003662bb61e17fae3ea294cf603197fb0aab6d51180bd8b6104c4944a62fe2d97f00000000000101000001000000000000000000000000000000000000000000000000000000000000000000010a7769746864726177616c1607120b6465736372697074696f6e12805769746864726177616c20646f63756d656e7420746f20747261636b20756e6465726c79696e67207769746864726177616c207472616e73616374696f6e732e205769746864726177616c732073686f756c6420626520637265617465642077697468204964656e746974795769746864726177616c5472616e736974696f6e12176372656174696f6e5265737472696374696f6e4d6f6465020212047479706512066f626a6563741207696e64696365731504160312046e616d65120e6964656e74697479537461747573120a70726f70657274696573150316011208246f776e6572496412036173631601120673746174757312036173631601120a2463726561746564417412036173631206756e697175651300160312046e616d65120e6964656e74697479526563656e74120a70726f70657274696573150316011208246f776e6572496412036173631601120a2475706461746564417412036173631601120673746174757312036173631206756e697175651300160312046e616d651207706f6f6c696e67120a70726f70657274696573150416011206737461747573120361736316011207706f6f6c696e6712036173631601120e636f72654665655065724279746512036173631601120a2475706461746564417412036173631206756e697175651300160312046e616d65120b7472616e73616374696f6e120a70726f706572746965731502160112067374617475731203617363160112107472616e73616374696f6e496e64657812036173631206756e697175651300120a70726f70657274696573160712107472616e73616374696f6e496e64657816041204747970651207696e7465676572120b6465736372697074696f6e127953657175656e7469616c20696e646578206f6620617373657420756e6c6f636b20287769746864726177616c29207472616e73616374696f6e2e20506f70756c61746564207768656e2061207769746864726177616c20706f6f6c656420696e746f207769746864726177616c207472616e73616374696f6e12076d696e696d756d02011208706f736974696f6e020012157472616e73616374696f6e5369676e48656967687416041204747970651207696e7465676572120b6465736372697074696f6e122f54686520436f726520686569676874206f6e207768696368207472616e73616374696f6e20776173207369676e656412076d696e696d756d02011208706f736974696f6e02011206616d6f756e7416041204747970651207696e7465676572120b6465736372697074696f6e121a54686520616d6f756e7420746f2062652077697468647261776e12076d696e696d756d02fb03e81208706f736974696f6e0202120e636f72654665655065724279746516051204747970651207696e7465676572120b6465736372697074696f6e1250546869732069732074686520666565207468617420796f75206172652077696c6c696e6720746f207370656e6420666f722074686973207472616e73616374696f6e20696e2044756666732f4279746512076d696e696d756d020112076d6178696d756d02fcffffffff1208706f736974696f6e02031207706f6f6c696e6716041204747970651207696e7465676572120b6465736372697074696f6e124e5468697320696e6469636174656420746865206c6576656c20617420776869636820506c6174666f726d2073686f756c642074727920746f20706f6f6c2074686973207472616e73616374696f6e1204656e756d15030200020102021208706f736974696f6e0204120c6f75747075745363726970741605120474797065120561727261791209627974654172726179130112086d696e4974656d73021712086d61784974656d7302191208706f736974696f6e0205120673746174757316041204747970651207696e74656765721204656e756d150502000201020202030204120b6465736372697074696f6e124330202d2050656e64696e672c2031202d205369676e65642c2032202d2042726f61646361737465642c2033202d20436f6d706c6574652c2034202d20457870697265641208706f736974696f6e020612146164646974696f6e616c50726f706572746965731300120872657175697265641507120a24637265617465644174120a247570646174656441741206616d6f756e74120e636f7265466565506572427974651207706f6f6c696e67120c6f75747075745363726970741206737461747573']
17
+ })
18
+
19
+ describe('serialization / deserialization', function () {
20
+ it('should allows to create DataContract from schema without full validation', function () {
21
+ const identifier = new wasm.IdentifierWASM(value.ownerId)
22
+
23
+ const dataContract = new wasm.DataContractWASM(identifier, BigInt(2), value.documentSchemas, null, false)
24
+
25
+ assert.notEqual(dataContract.__wbg_ptr, 0)
26
+ })
27
+
28
+ it('should allows to create DataContract from schema with full validation', function () {
29
+ const identifier = new wasm.IdentifierWASM(value.ownerId)
30
+
31
+ const dataContract = new wasm.DataContractWASM(identifier, BigInt(2), value.documentSchemas, null, true)
32
+
33
+ assert.notEqual(dataContract.__wbg_ptr, 0)
34
+ })
35
+
36
+ it('should allows to create DataContract from value with full validation and without platform version', function () {
37
+ const dataContract = wasm.DataContractWASM.fromValue(value, true)
38
+
39
+ assert.notEqual(dataContract.__wbg_ptr, 0)
40
+ })
41
+
42
+ it('should allows to convert DataContract to bytes and from bytes', function () {
43
+ const [dataContractBytes] = dataContractsBytes
44
+
45
+ const dataContract = wasm.DataContractWASM.fromValue(value, true)
46
+
47
+ assert.deepEqual(dataContract.toBytes(), fromHexString(dataContractBytes))
48
+
49
+ const dataContractFromBytes = wasm.DataContractWASM.fromBytes(dataContract.toBytes(), false, PlatformVersionWASM.PLATFORM_V1)
50
+
51
+ assert.notEqual(dataContract.__wbg_ptr, 0)
52
+
53
+ assert.deepEqual(dataContractFromBytes.toBytes(), fromHexString(dataContractBytes))
54
+ })
55
+
56
+ it('should allows to create DataContract from bytes without full validation', function () {
57
+ const [dataContractBytes] = dataContractsBytes
58
+
59
+ const dataContractFromBytes = wasm.DataContractWASM.fromBytes(fromHexString(dataContractBytes), false, PlatformVersionWASM.PLATFORM_V1)
60
+ const dataContractFromValue = wasm.DataContractWASM.fromValue(value, true)
61
+
62
+ assert.deepEqual(dataContractFromBytes.toValue(), dataContractFromValue.toValue())
63
+ })
64
+
65
+ it('should allows to create DataContract from bytes with full validation and without version', function () {
66
+ const [dataContractBytes] = dataContractsBytes
67
+
68
+ const dataContractFromBytes = wasm.DataContractWASM.fromBytes(fromHexString(dataContractBytes), true)
69
+ const dataContractFromValue = wasm.DataContractWASM.fromValue(value, true)
70
+
71
+ assert.deepEqual(dataContractFromBytes.toValue(), dataContractFromValue.toValue())
72
+ })
73
+
74
+ it('should allow to get json', function () {
75
+ const dataContract = wasm.DataContractWASM.fromValue(value, true)
76
+
77
+ assert.deepEqual(dataContract.toJson(), value)
78
+ })
79
+ })
80
+
81
+ describe('getters', function () {
82
+ it('should allow to get schemas', function () {
83
+ const dataContract = wasm.DataContractWASM.fromValue(value, true)
84
+
85
+ assert.deepEqual(dataContract.getSchema(), value.documentSchemas)
86
+ })
87
+
88
+ it('should allow to get version', function () {
89
+ const dataContract = wasm.DataContractWASM.fromValue(value, true)
90
+
91
+ assert.deepEqual(dataContract.getVersion(), value.version)
92
+ })
93
+
94
+ it('should allow to get id', function () {
95
+ const dataContract = wasm.DataContractWASM.fromValue(value, true)
96
+
97
+ assert.deepEqual(dataContract.getId().base58(), id)
98
+ })
99
+
100
+ it('should allow to get owner id', function () {
101
+ const dataContract = wasm.DataContractWASM.fromValue(value, true)
102
+
103
+ assert.deepEqual(dataContract.getOwnerId().base58(), ownerId)
104
+ })
105
+
106
+ it('should allow to get config', function () {
107
+ const dataContract = wasm.DataContractWASM.fromValue(value, true)
108
+
109
+ assert.deepEqual(dataContract.getConfig(), value.config)
110
+ })
111
+ })
112
+
113
+ describe('setters', function () {
114
+ it('should allow to set id', function () {
115
+ const dataContract = wasm.DataContractWASM.fromValue(value, true)
116
+
117
+ const identifier = new wasm.IdentifierWASM('7ckT6Y19HnjfqoPFmfL995i4z2HwgZ8UttNmP99LtCBH')
118
+
119
+ dataContract.setId(identifier)
120
+
121
+ assert.deepEqual(dataContract.getId().base58(), '7ckT6Y19HnjfqoPFmfL995i4z2HwgZ8UttNmP99LtCBH')
122
+ })
123
+
124
+ it('should allow to set owner id', function () {
125
+ const dataContract = wasm.DataContractWASM.fromValue(value, true)
126
+
127
+ const identifier = new wasm.IdentifierWASM('3bx13Wd5k4LwHAvXJrayc5HdKPyiccKWYECPQGGYfnVL')
128
+
129
+ dataContract.setOwnerId(identifier)
130
+
131
+ assert.deepEqual(dataContract.getOwnerId().base58(), '3bx13Wd5k4LwHAvXJrayc5HdKPyiccKWYECPQGGYfnVL')
132
+ })
133
+
134
+ it('should allow to set version', function () {
135
+ const dataContract = wasm.DataContractWASM.fromValue(value, true)
136
+
137
+ dataContract.setVersion(20)
138
+
139
+ assert.equal(dataContract.getVersion(), 20)
140
+ })
141
+
142
+ it('should allow to set config', function () {
143
+ const dataContract = wasm.DataContractWASM.fromValue(value, true)
144
+
145
+ const oldConfig = dataContract.getConfig()
146
+
147
+ const newConfig = { ...oldConfig, canBeDeleted: !oldConfig.canBeDeleted }
148
+
149
+ dataContract.setConfig(newConfig)
150
+
151
+ assert.deepEqual(dataContract.getConfig(), newConfig)
152
+ })
153
+
154
+ it('should allow to set schema', function () {
155
+ const dataContract = wasm.DataContractWASM.fromValue(value, true)
156
+
157
+ const oldSchema = dataContract.getSchema()
158
+
159
+ const newSchema = {
160
+ pupup: oldSchema.withdrawal
161
+ }
162
+
163
+ dataContract.setSchema(newSchema)
164
+
165
+ assert.deepEqual(dataContract.getSchema(), newSchema)
166
+ })
167
+ })
168
+
169
+ describe('static', function () {
170
+ it('should allow to generate id', function () {
171
+ const identifier = new wasm.IdentifierWASM('3bx13Wd5k4LwHAvXJrayc5HdKPyiccKWYECPQGGYfnVL')
172
+
173
+ const id = wasm.DataContractWASM.generateId(identifier, BigInt(4))
174
+
175
+ assert.deepEqual(id.base58(), '7ckT6Y19HnjfqoPFmfL995i4z2HwgZ8UttNmP99LtCBH')
176
+ })
177
+ })
178
+ })
@@ -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 Create 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.DataContractCreateTransitionWASM(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.DataContractCreateTransitionWASM(dataContract, BigInt(1))
29
+
30
+ const bytes = dataContractTransition.toBytes()
31
+
32
+ const newDataContractTransition = wasm.DataContractCreateTransitionWASM.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.DataContractCreateTransitionWASM(dataContract, BigInt(1))
44
+
45
+ const stateTransition = dataContractTransition.toStateTransition()
46
+
47
+ const newDataContractTransition = wasm.DataContractCreateTransitionWASM.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.DataContractCreateTransitionWASM(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.DataContractCreateTransitionWASM(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.DataContractCreateTransitionWASM(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.DataContractCreateTransitionWASM(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.DataContractCreateTransitionWASM(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), dataContractTransition.getDataContract().toBytes())
107
+ })
108
+ })
109
+ })
@@ -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,238 @@
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
+
9
+ let wasm
10
+
11
+ describe('Document', function () {
12
+ before(async function () {
13
+ wasm = initWasm()
14
+ })
15
+
16
+ describe('serialization / deserialization', function () {
17
+ it('should allows to create Document from values', function () {
18
+ const dataContractIdentifier = new wasm.IdentifierWASM(dataContractId)
19
+ const ownerIdentifier = new wasm.IdentifierWASM(ownerId)
20
+
21
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractIdentifier, ownerIdentifier)
22
+
23
+ assert.notEqual(documentInstance.__wbg_ptr, 0)
24
+ })
25
+
26
+ it('should allows to create Document from values with custom id', function () {
27
+ const dataContractIdentifier = new wasm.IdentifierWASM(dataContractId)
28
+ const ownerIdentifier = new wasm.IdentifierWASM(ownerId)
29
+ const identifier = new wasm.IdentifierWASM(id)
30
+
31
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractIdentifier, ownerIdentifier, identifier)
32
+
33
+ assert.notEqual(documentInstance.__wbg_ptr, 0)
34
+ })
35
+
36
+ it('should allows to create Document from bytes and convert to bytes', function () {
37
+ const dataContract = wasm.DataContractWASM.fromValue(dataContractValue, false)
38
+ const documentInstance = wasm.DocumentWASM.fromBytes(fromHexString(documentBytes), dataContract, 'note')
39
+
40
+ const bytes = documentInstance.toBytes(dataContract, 'note')
41
+
42
+ assert.deepEqual(bytes, fromHexString(documentBytes))
43
+ assert.notEqual(dataContract.__wbg_ptr, 0)
44
+ })
45
+ })
46
+
47
+ describe('getters', function () {
48
+ it('should return document id', () => {
49
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
50
+
51
+ assert.deepEqual(documentInstance.getId().base58(), id)
52
+ })
53
+
54
+ it('should return owner id', () => {
55
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
56
+
57
+ assert.deepEqual(documentInstance.getOwnerId().base58(), ownerId)
58
+ })
59
+
60
+ it('should return data contract id', () => {
61
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
62
+
63
+ assert.deepEqual(documentInstance.getDataContractId().base58(), dataContractId)
64
+ })
65
+
66
+ it('should return properties', () => {
67
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
68
+
69
+ assert.deepEqual(documentInstance.getProperties(), document)
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
+ it('should return revision', () => {
79
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
80
+
81
+ assert.deepEqual(documentInstance.getRevision(), revision)
82
+ })
83
+ })
84
+
85
+ describe('setters', function () {
86
+ it('should allow to set document id', () => {
87
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
88
+
89
+ documentInstance.setId(ownerId)
90
+
91
+ assert.deepEqual(documentInstance.getId().base58(), ownerId)
92
+ })
93
+
94
+ it('should allow to set document owner id', () => {
95
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
96
+
97
+ documentInstance.setOwnerId(id)
98
+
99
+ assert.deepEqual(documentInstance.getOwnerId().base58(), id)
100
+ })
101
+
102
+ it('should allow to set entropy', () => {
103
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
104
+
105
+ const newEntropy = new Array(documentInstance.getEntropy().length).fill(0)
106
+
107
+ documentInstance.setEntropy(newEntropy)
108
+
109
+ assert.deepEqual(Array.from(documentInstance.getEntropy()), newEntropy)
110
+ })
111
+
112
+ it('should allow to set properties', () => {
113
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
114
+
115
+ documentInstance.setProperties(document2)
116
+
117
+ assert.deepEqual(documentInstance.getProperties(), document2)
118
+ })
119
+
120
+ it('should allow to set revision', () => {
121
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
122
+
123
+ const newRevision = BigInt(1000)
124
+
125
+ documentInstance.setRevision(newRevision)
126
+
127
+ assert.deepEqual(documentInstance.getRevision(), newRevision)
128
+ })
129
+
130
+ it('should allow to set created at', () => {
131
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
132
+
133
+ const createdAt = BigInt(new Date(1123).getTime())
134
+
135
+ documentInstance.setCreatedAt(createdAt)
136
+
137
+ assert.deepEqual(documentInstance.getCreatedAt(), createdAt)
138
+ })
139
+
140
+ it('should allow to set updated at', () => {
141
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
142
+
143
+ const updatedAt = BigInt(new Date(1123).getTime())
144
+
145
+ documentInstance.setUpdatedAt(updatedAt)
146
+
147
+ assert.deepEqual(documentInstance.getUpdatedAt(), updatedAt)
148
+ })
149
+
150
+ it('should allow to set transferred at', () => {
151
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
152
+
153
+ const transferredAt = BigInt(new Date(11231).getTime())
154
+
155
+ documentInstance.setTransferredAt(transferredAt)
156
+
157
+ assert.deepEqual(documentInstance.getTransferredAt(), transferredAt)
158
+ })
159
+
160
+ it('should allow to set create at Block Height', () => {
161
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
162
+
163
+ const createdAtHeight = BigInt(9172)
164
+
165
+ documentInstance.setCreatedAtBlockHeight(createdAtHeight)
166
+
167
+ assert.deepEqual(documentInstance.getCreatedAtBlockHeight(), createdAtHeight)
168
+ })
169
+
170
+ it('should allow to set updated at Block Height', () => {
171
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
172
+
173
+ const updatedAtHeight = BigInt(9172)
174
+
175
+ documentInstance.setUpdatedAtBlockHeight(updatedAtHeight)
176
+
177
+ assert.deepEqual(documentInstance.getUpdatedAtBlockHeight(), updatedAtHeight)
178
+ })
179
+
180
+ it('should allow to set transferred at Block Height', () => {
181
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
182
+
183
+ const transferredAtHeight = BigInt(9172)
184
+
185
+ documentInstance.setTransferredAtBlockHeight(transferredAtHeight)
186
+
187
+ assert.deepEqual(documentInstance.getTransferredAtBlockHeight(), transferredAtHeight)
188
+ })
189
+
190
+ it('should allow to set create at core Block Height', () => {
191
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
192
+
193
+ const createdAtHeight = 91721
194
+
195
+ documentInstance.setCreatedAtCoreBlockHeight(createdAtHeight)
196
+
197
+ assert.deepEqual(documentInstance.getCreatedAtCoreBlockHeight(), createdAtHeight)
198
+ })
199
+
200
+ it('should allow to set updated at Block Height', () => {
201
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
202
+
203
+ const updatedAtHeight = 91722
204
+
205
+ documentInstance.setUpdatedAtCoreBlockHeight(updatedAtHeight)
206
+
207
+ assert.deepEqual(documentInstance.getUpdatedAtCoreBlockHeight(), updatedAtHeight)
208
+ })
209
+
210
+ it('should allow to set transferred at Block Height', () => {
211
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
212
+
213
+ const transferredAtHeight = 91723
214
+
215
+ documentInstance.setTransferredAtCoreBlockHeight(transferredAtHeight)
216
+
217
+ assert.deepEqual(documentInstance.getTransferredAtCoreBlockHeight(), transferredAtHeight)
218
+ })
219
+
220
+ it('should allow to set document type name', () => {
221
+ const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id)
222
+
223
+ const newDocumentTypeName = 'bbbb'
224
+
225
+ documentInstance.setDocumentTypeName(newDocumentTypeName)
226
+
227
+ assert.deepEqual(documentInstance.getDocumentTypeName(), newDocumentTypeName)
228
+ })
229
+ })
230
+
231
+ describe('static', function () {
232
+ it('should allow to generate id', () => {
233
+ const generatedId = wasm.DocumentWASM.generateId('note', ownerId, dataContractId)
234
+
235
+ assert.equal(Array.from(generatedId).length, 32)
236
+ })
237
+ })
238
+ })