@dashevo/wasm-dpp 0.24.0-dev.11 → 0.24.0-dev.13

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 (167) hide show
  1. package/Cargo.toml +3 -0
  2. package/README.md +5 -1
  3. package/dist/index.js +1 -1
  4. package/dist/index.js.LICENSE.txt +9 -0
  5. package/dist/lib/dpp.d.ts +9 -0
  6. package/dist/lib/errors/AbstractConsensusError.d.ts +10 -0
  7. package/dist/lib/errors/DPPError.d.ts +5 -0
  8. package/dist/lib/errors/patchConsensusErrors.d.ts +1 -0
  9. package/dist/lib/{patchIdentifier.d.ts → identifier/patchIdentifier.d.ts} +1 -1
  10. package/dist/{index.d.ts → lib/index.d.ts} +1 -1
  11. package/dist/lib/utils/extend.d.ts +1 -0
  12. package/dist/wasm/wasm_dpp.d.ts +1595 -518
  13. package/karma.conf.js +5 -0
  14. package/lib/dpp.ts +24 -0
  15. package/lib/errors/AbstractConsensusError.ts +13 -0
  16. package/lib/errors/DPPError.ts +15 -0
  17. package/lib/errors/patchConsensusErrors.ts +175 -0
  18. package/lib/{patchIdentifier.ts → identifier/patchIdentifier.ts} +6 -5
  19. package/{index.ts → lib/index.ts} +5 -4
  20. package/lib/test/bootstrap.js +5 -0
  21. package/lib/test/expect/expectError.js +4 -2
  22. package/lib/test/mocks/getBlsAdapterMock.js +36 -0
  23. package/lib/test/utils/newDocumentsContainer.js +36 -0
  24. package/lib/utils/extend.ts +6 -0
  25. package/package.json +9 -6
  26. package/src/bls_adapter.rs +16 -1
  27. package/src/data_contract/data_contract.rs +35 -7
  28. package/src/data_contract/errors/invalid_data_contract.rs +21 -0
  29. package/src/data_contract/errors/invalid_document_type.rs +1 -1
  30. package/src/data_contract/index.rs +56 -1
  31. package/src/data_contract/mod.rs +1 -0
  32. package/src/data_contract/state_transition/data_contract_create_transition/mod.rs +6 -8
  33. package/src/data_contract/state_transition/data_contract_create_transition/validation.rs +4 -4
  34. package/src/data_contract/state_transition/data_contract_update_transition/apply.rs +44 -0
  35. package/src/data_contract/state_transition/data_contract_update_transition/mod.rs +145 -0
  36. package/src/data_contract/state_transition/data_contract_update_transition/validation.rs +49 -0
  37. package/src/data_contract/state_transition/mod.rs +2 -0
  38. package/src/data_contract_factory/data_contract_factory.rs +25 -12
  39. package/src/document/errors/invalid_document_error.rs +10 -9
  40. package/src/document/errors/invalid_initial_revision_error.rs +1 -1
  41. package/src/document/errors/mismatch_owners_ids_error.rs +14 -4
  42. package/src/document/errors/mod.rs +17 -13
  43. package/src/document/errors/no_documents_supplied_error.rs +4 -4
  44. package/src/document/factory.rs +192 -0
  45. package/src/document/mod.rs +222 -30
  46. package/src/document/state_transition/document_batch_transition/document_transition/document_create_transition.rs +47 -1
  47. package/src/document/state_transition/document_batch_transition/document_transition/document_delete_transition.rs +25 -1
  48. package/src/document/state_transition/document_batch_transition/document_transition/document_replace_transition.rs +65 -0
  49. package/src/document/state_transition/document_batch_transition/document_transition/mod.rs +123 -3
  50. package/src/document/state_transition/document_batch_transition/mod.rs +378 -0
  51. package/src/document/validator.rs +30 -0
  52. package/src/errors/consensus/basic/data_contract/data_contract_max_depth_exceed_error.rs +5 -5
  53. package/src/errors/consensus/basic/document/duplicate_document_transitions_with_ids_error.rs +4 -4
  54. package/src/errors/consensus/basic/document/duplicate_document_transitions_with_indices_error.rs +36 -0
  55. package/src/errors/consensus/basic/document/missing_document_transition_type_error.rs +20 -0
  56. package/src/errors/consensus/basic/document/mod.rs +4 -0
  57. package/src/errors/consensus/basic/identity/duplicated_identity_public_key_error.rs +2 -2
  58. package/src/errors/consensus/basic/identity/duplicated_identity_public_key_id_error.rs +2 -2
  59. package/src/errors/consensus/basic/identity/identity_asset_lock_proof_locked_transaction_mismatch_error.rs +6 -2
  60. package/src/errors/consensus/basic/identity/identity_asset_lock_transaction_out_point_already_exists_error.rs +5 -2
  61. package/src/errors/consensus/basic/identity/invalid_asset_lock_proof_transaction_height_error.rs +3 -3
  62. package/src/errors/consensus/basic/identity/invalid_identity_public_key_security_level_error.rs +2 -2
  63. package/src/errors/consensus/basic/json_schema_error.rs +1 -1
  64. package/src/errors/consensus_error.rs +15 -8
  65. package/src/errors/dpp_error.rs +17 -0
  66. package/src/errors/from.rs +6 -1
  67. package/src/errors/js_conversion.rs +19 -4
  68. package/src/errors/mod.rs +3 -0
  69. package/src/errors/protocol_error.rs +15 -0
  70. package/src/{identifier.rs → identifier/mod.rs} +48 -3
  71. package/src/identity/errors/asset_lock_output_not_found_error.rs +11 -0
  72. package/src/identity/errors/asset_lock_transaction_is_not_found_error.rs +20 -0
  73. package/src/identity/errors/mod.rs +7 -0
  74. package/src/identity/errors/unknown_asset_lock_proof_type_error.rs +26 -0
  75. package/src/{identity_facade.rs → identity/identity_facade.rs} +3 -5
  76. package/src/{identity_public_key → identity/identity_public_key}/key_type.rs +0 -0
  77. package/src/{identity_public_key → identity/identity_public_key}/mod.rs +41 -10
  78. package/src/{identity_public_key → identity/identity_public_key}/purpose.rs +0 -0
  79. package/src/{identity_public_key → identity/identity_public_key}/security_level.rs +0 -0
  80. package/src/{identity.rs → identity/mod.rs} +20 -12
  81. package/src/identity/state_transition/asset_lock_proof/chain/chain_asset_lock_proof.rs +132 -0
  82. package/src/identity/state_transition/asset_lock_proof/chain/chain_asset_lock_proof_structure_validator.rs +72 -0
  83. package/src/identity/state_transition/asset_lock_proof/chain/mod.rs +4 -0
  84. package/src/identity/state_transition/asset_lock_proof/instant/instant_asset_lock_proof.rs +177 -0
  85. package/src/identity/state_transition/asset_lock_proof/instant/instant_asset_lock_proof_structure_validator.rs +72 -0
  86. package/src/identity/state_transition/asset_lock_proof/instant/mod.rs +4 -0
  87. package/src/identity/state_transition/asset_lock_proof/mod.rs +269 -0
  88. package/src/identity/state_transition/identity_create_transition/apply_identity_create_transition.rs +26 -0
  89. package/src/identity/state_transition/identity_create_transition/identity_create_transition.rs +335 -0
  90. package/src/identity/state_transition/identity_create_transition/identity_create_transition_basic_validator.rs +153 -0
  91. package/src/identity/state_transition/identity_create_transition/identity_create_transition_state_validator.rs +37 -0
  92. package/src/identity/state_transition/identity_create_transition/mod.rs +8 -0
  93. package/src/identity/state_transition/identity_create_transition/to_object.rs +46 -0
  94. package/src/identity/state_transition/identity_topup_transition/apply_identity_topup_transition.rs +31 -0
  95. package/src/identity/state_transition/identity_topup_transition/identity_topup_transition.rs +280 -0
  96. package/src/identity/state_transition/identity_topup_transition/identity_topup_transition_basic_validator.rs +113 -0
  97. package/src/identity/state_transition/identity_topup_transition/identity_topup_transition_state_validator.rs +37 -0
  98. package/src/identity/state_transition/identity_topup_transition/mod.rs +8 -0
  99. package/src/identity/state_transition/identity_topup_transition/to_object.rs +42 -0
  100. package/src/identity/state_transition/mod.rs +9 -0
  101. package/src/identity/state_transition/validate_public_key_signatures.rs +59 -0
  102. package/src/identity/validation/mod.rs +3 -0
  103. package/src/identity/validation/public_keys_validator.rs +76 -0
  104. package/src/identity_public_key/public_keys_validator.rs +1 -1
  105. package/src/lib.rs +3 -6
  106. package/src/lodash.rs +7 -0
  107. package/src/state_repository.rs +188 -36
  108. package/src/state_transition/mod.rs +12 -0
  109. package/src/utils.rs +102 -7
  110. package/src/validation/json_schema_validator.rs +41 -0
  111. package/src/validation/mod.rs +5 -0
  112. package/src/{validation_result.rs → validation/validation_result.rs} +23 -5
  113. package/src/version/mod.rs +2 -0
  114. package/src/version/protocol_version.rs +26 -0
  115. package/test/integration/dataContract/validation/validateDataContractFactory.spec.js +579 -502
  116. package/test/integration/identity/stateTransition/IdentityCreateTransition/validation/basic/validateIdentityCreateTransitionBasicFactory.spec.js +175 -165
  117. package/test/integration/identity/stateTransition/IdentityTopUpTransition/validation/basic/validateIdentityTopUpTransitionBasicFactory.spec.js +83 -114
  118. package/test/integration/identity/stateTransition/IdentityUpdateTransition/validation/state/validateIdentityUpdateTransitionStateFactory.spec.js +1 -1
  119. package/test/integration/identity/stateTransition/assetLockProof/chain/validateChainAssetLockProofStructureFactory.spec.js +82 -91
  120. package/test/integration/identity/stateTransition/assetLockProof/fetchAssetLockTransactionOutputFactory.spec.js +75 -31
  121. package/test/integration/identity/stateTransition/assetLockProof/instant/validateInstantAssetLockProofStructureFactory.spec.js +93 -148
  122. package/test/integration/identity/stateTransition/assetLockProof/validateAssetLockTransactionFactory.spec.js +63 -75
  123. package/test/integration/identity/stateTransition/validatePublicKeySignaturesFactory.spec.js +48 -19
  124. package/test/integration/identity/validation/validatePublicKeysFactory.spec.js +79 -114
  125. package/test/integration/stateTransition/AbstractStateTransitionIdentitySigned.spec.js +0 -11
  126. package/test/integration/stateTransition/StateTransitionFacade.spec.js +1 -1
  127. package/test/integration/stateTransition/calculateStateTransitionFeeFactory.spec.js +135 -0
  128. package/test/unit/dataContract/DataContract.spec.js +5 -9
  129. package/test/unit/dataContract/DataContractFactory.spec.js +13 -6
  130. package/test/unit/dataContract/createDataContract.spec.js +0 -1
  131. package/test/unit/dataContract/errors/InvalidDataContractError.spec.js +11 -3
  132. package/test/unit/dataContract/stateTransition/DataContractCreateTransition/DataContractCreateTransition.spec.js +3 -3
  133. package/test/unit/dataContract/stateTransition/DataContractCreateTransition/validation/state/validateDataContractCreateTransitionStateFactory.spec.js +20 -16
  134. package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/DataContractUpdateTransition.spec.js +24 -60
  135. package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/applyDataContractUpdateTransitionFactory.spec.js +27 -23
  136. package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/validation/basic/validateIndicesAreBackwardCompatible.spec.js +29 -12
  137. package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/validation/state/validateDataContractUpdateTransitionStateFactory.spec.js +66 -49
  138. package/test/unit/dataContract/validation/validateDataContractPatterns.spec.js +73 -0
  139. package/test/unit/decodeProtocolEntityFactory.spec.js +2 -2
  140. package/test/unit/document/Document.spec.js +147 -155
  141. package/test/unit/document/DocumentFactory.spec.js +325 -91
  142. package/test/unit/document/stateTransition/DocumetsBatchTransition/DocumentsBatchTransition.spec.js +142 -64
  143. package/test/unit/document/stateTransition/DocumetsBatchTransition/applyDocumentsBatchTransitionFactory.spec.js +1 -1
  144. package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/validateDocumentsBatchTransitionStateFactory.spec.js +1 -1
  145. package/test/unit/identity/Identity.spec.js +2 -2
  146. package/test/unit/identity/IdentityPublicKey.spec.js +25 -31
  147. package/test/unit/identity/stateTransition/IdentityCreateTransition/IdentityCreateTransition.spec.js +69 -30
  148. package/test/unit/identity/stateTransition/IdentityCreateTransition/applyIdentityCreateTransitionFactory.spec.js +32 -32
  149. package/test/unit/identity/stateTransition/IdentityCreateTransition/validation/state/validateIdentityCreateTransitionStateFactory.spec.js +56 -25
  150. package/test/unit/identity/stateTransition/IdentityTopUpTransition/IdentityTopUpTransition.spec.js +36 -16
  151. package/test/unit/identity/stateTransition/IdentityTopUpTransition/applyIdentityTopUpTransitionFactory.spec.js +48 -46
  152. package/test/unit/identity/stateTransition/IdentityTopUpTransition/validation/state/validateIdentityTopUpTransitionStateFactory.spec.js +24 -6
  153. package/test/unit/identity/stateTransition/assetLockProof/ChainAssetLockProof.spec.js +63 -0
  154. package/test/unit/identity/stateTransition/assetLockProof/InstantAssetLockProof.spec.js +90 -0
  155. package/test/unit/identity/stateTransition/assetLockProof/createAssetLockProofInstance.spec.js +18 -3
  156. package/test/unit/identity/stateTransition/assetLockProof/fetchAssetLockPublicKeyHashFactory.spec.js +38 -11
  157. package/tsconfig.json +1 -1
  158. package/wasm/package.json +5 -0
  159. package/wasm/wasm_dpp.d.ts +1595 -518
  160. package/wasm/wasm_dpp.js +5007 -2172
  161. package/wasm/wasm_dpp_bg.js +1 -1
  162. package/wasm/wasm_dpp_bg.wasm +0 -0
  163. package/wasm/wasm_dpp_bg.wasm.d.ts +566 -365
  164. package/webpack.config.js +10 -1
  165. package/test/integration/stateTransition/calculateStateTransitionFee.spec.js +0 -32
  166. package/test/unit/dataContract/validation/validateDataContractMaxDepthFactory.spec.js +0 -93
  167. package/test/unit/dataContract/validation/validateDataContractPatternsFactory.spec.js +0 -64
@@ -1,53 +1,59 @@
1
- const { getRE2Class } = require('@dashevo/wasm-re2');
2
-
3
- const createAjv = require('@dashevo/dpp/lib/ajv/createAjv');
1
+ const { Transaction, Script, PrivateKey } = require('@dashevo/dashcore-lib');
4
2
 
5
3
  const getChainAssetLockFixture = require('@dashevo/dpp/lib/test/fixtures/getChainAssetLockProofFixture');
6
- const JsonSchemaValidator = require('@dashevo/dpp/lib/validation/JsonSchemaValidator');
7
4
  const createStateRepositoryMock = require('@dashevo/dpp/lib/test/mocks/createStateRepositoryMock');
8
5
 
9
- const { expectValidationError, expectJsonSchemaError } = require(
10
- '@dashevo/dpp/lib/test/expect/expectError',
11
- );
6
+ const { expect } = require('chai');
7
+ const { expectJsonSchemaError, expectValidationError } = require('../../../../../../lib/test/expect/expectError');
12
8
 
13
- const validateChainAssetLockProofStructureFactory = require('@dashevo/dpp/lib/identity/stateTransition/assetLockProof/chain/validateChainAssetLockProofStructureFactory');
14
- const ValidationResult = require('@dashevo/dpp/lib/validation/ValidationResult');
15
- const IdentityAssetLockTransactionIsNotFoundError = require('@dashevo/dpp/lib/errors/consensus/basic/identity/IdentityAssetLockTransactionIsNotFoundError');
16
- const InvalidAssetLockProofCoreChainHeightError = require('@dashevo/dpp/lib/errors/consensus/basic/identity/InvalidAssetLockProofCoreChainHeightError');
17
- const InvalidAssetLockProofTransactionHeightError = require('@dashevo/dpp/lib/errors/consensus/basic/identity/InvalidAssetLockProofTransactionHeightError');
18
- const SomeConsensusError = require('@dashevo/dpp/lib/test/mocks/SomeConsensusError');
19
- const StateTransitionExecutionContext = require('@dashevo/dpp/lib/stateTransition/StateTransitionExecutionContext');
9
+ const { default: loadWasmDpp } = require('../../../../../../dist');
20
10
 
21
11
  describe('validateChainAssetLockProofStructureFactory', () => {
22
12
  let rawProof;
23
13
  let stateRepositoryMock;
24
- let validateChainAssetLockProofStructure;
25
- let jsonSchemaValidator;
26
- let validateAssetLockTransactionMock;
27
- let validateAssetLockTransactionResult;
28
14
  let publicKeyHash;
29
15
  let rawTransaction;
30
16
  let transactionHash;
31
17
  let executionContext;
18
+ let validateChainAssetLockProofStructure;
19
+
20
+ let StateTransitionExecutionContext;
21
+ let ValidationResult;
22
+ let InvalidAssetLockProofCoreChainHeightError;
23
+ let IdentityAssetLockTransactionIsNotFoundError;
24
+ let InvalidIdentityAssetLockTransactionOutputError;
25
+ let InvalidAssetLockProofTransactionHeightError;
26
+ let ChainAssetLockProofStructureValidator;
27
+
28
+ before(async () => {
29
+ ({
30
+ StateTransitionExecutionContext,
31
+ ValidationResult,
32
+ InvalidAssetLockProofCoreChainHeightError,
33
+ IdentityAssetLockTransactionIsNotFoundError,
34
+ InvalidIdentityAssetLockTransactionOutputError,
35
+ InvalidAssetLockProofTransactionHeightError,
36
+ ChainAssetLockProofStructureValidator,
37
+ } = await loadWasmDpp());
38
+ });
32
39
 
33
40
  beforeEach(async function beforeEach() {
34
41
  rawTransaction = '030000000137feb5676d0851337ea3c9a992496aab7a0b3eee60aeeb9774000b7f4bababa5000000006b483045022100d91557de37645c641b948c6cd03b4ae3791a63a650db3e2fee1dcf5185d1b10402200e8bd410bf516ca61715867666d31e44495428ce5c1090bf2294a829ebcfa4ef0121025c3cc7fbfc52f710c941497fd01876c189171ea227458f501afcb38a297d65b4ffffffff021027000000000000166a14152073ca2300a86b510fa2f123d3ea7da3af68dcf77cb0090a0000001976a914152073ca2300a86b510fa2f123d3ea7da3af68dc88ac00000000';
35
42
  transactionHash = '6e200d059fb567ba19e92f5c2dcd3dde522fd4e0a50af223752db16158dabb1d';
36
43
 
37
- const assetLock = getChainAssetLockFixture();
38
-
39
- rawProof = assetLock.toObject();
40
-
41
- const RE2 = await getRE2Class();
42
- const ajv = createAjv(RE2);
44
+ rawProof = getChainAssetLockFixture().toObject();
43
45
 
44
- jsonSchemaValidator = new JsonSchemaValidator(ajv);
46
+ // Change endianness of raw txId bytes in outPoint to match expectation of dashcore-rust
47
+ const txId = rawProof.outPoint.slice(0, 32);
48
+ const outputIndex = rawProof.outPoint.slice(32);
49
+ txId.reverse();
50
+ rawProof.outPoint = Buffer.concat([txId, outputIndex]);
45
51
 
46
52
  stateRepositoryMock = createStateRepositoryMock(this.sinonSandbox);
47
53
 
48
- stateRepositoryMock.fetchLatestPlatformCoreChainLockedHeight.resolves(42);
54
+ stateRepositoryMock.fetchLatestPlatformCoreChainLockedHeight.returns(42);
49
55
 
50
- stateRepositoryMock.fetchTransaction.resolves({
56
+ stateRepositoryMock.fetchTransaction.returns({
51
57
  data: Buffer.from(rawTransaction, 'hex'),
52
58
  height: 42,
53
59
  });
@@ -56,18 +62,14 @@ describe('validateChainAssetLockProofStructureFactory', () => {
56
62
 
57
63
  publicKeyHash = Buffer.from('152073ca2300a86b510fa2f123d3ea7da3af68dc', 'hex');
58
64
 
59
- validateAssetLockTransactionResult = new ValidationResult();
60
- validateAssetLockTransactionResult.setData({
61
- publicKeyHash,
62
- });
63
- validateAssetLockTransactionMock = this.sinonSandbox.stub().resolves(
64
- validateAssetLockTransactionResult,
65
+ const validator = new ChainAssetLockProofStructureValidator(
66
+ stateRepositoryMock,
65
67
  );
66
68
 
67
- validateChainAssetLockProofStructure = validateChainAssetLockProofStructureFactory(
68
- jsonSchemaValidator,
69
- stateRepositoryMock,
70
- validateAssetLockTransactionMock,
69
+ validateChainAssetLockProofStructure = (
70
+ proof, context,
71
+ ) => validator.validate(
72
+ rawProof, context,
71
73
  );
72
74
  });
73
75
 
@@ -80,7 +82,7 @@ describe('validateChainAssetLockProofStructureFactory', () => {
80
82
  executionContext,
81
83
  );
82
84
 
83
- expectJsonSchemaError(result);
85
+ await expectJsonSchemaError(result);
84
86
 
85
87
  const [error] = result.getErrors();
86
88
 
@@ -89,7 +91,6 @@ describe('validateChainAssetLockProofStructureFactory', () => {
89
91
  expect(error.getParams().missingProperty).to.equal('type');
90
92
 
91
93
  expect(stateRepositoryMock.fetchTransaction).to.not.be.called();
92
- expect(validateAssetLockTransactionMock).to.not.be.called();
93
94
  expect(stateRepositoryMock.fetchLatestPlatformCoreChainLockedHeight).to.not.be.called();
94
95
  });
95
96
 
@@ -101,7 +102,7 @@ describe('validateChainAssetLockProofStructureFactory', () => {
101
102
  executionContext,
102
103
  );
103
104
 
104
- expectJsonSchemaError(result);
105
+ await expectJsonSchemaError(result);
105
106
 
106
107
  const [error] = result.getErrors();
107
108
 
@@ -122,7 +123,7 @@ describe('validateChainAssetLockProofStructureFactory', () => {
122
123
  executionContext,
123
124
  );
124
125
 
125
- expectJsonSchemaError(result);
126
+ await expectJsonSchemaError(result);
126
127
 
127
128
  const [error] = result.getErrors();
128
129
 
@@ -131,7 +132,6 @@ describe('validateChainAssetLockProofStructureFactory', () => {
131
132
  expect(error.getParams().missingProperty).to.equal('coreChainLockedHeight');
132
133
 
133
134
  expect(stateRepositoryMock.fetchTransaction).to.not.be.called();
134
- expect(validateAssetLockTransactionMock).to.not.be.called();
135
135
  expect(stateRepositoryMock.fetchLatestPlatformCoreChainLockedHeight).to.not.be.called();
136
136
  });
137
137
 
@@ -143,7 +143,7 @@ describe('validateChainAssetLockProofStructureFactory', () => {
143
143
  executionContext,
144
144
  );
145
145
 
146
- expectJsonSchemaError(result);
146
+ await expectJsonSchemaError(result);
147
147
 
148
148
  const [error] = result.getErrors();
149
149
 
@@ -151,7 +151,6 @@ describe('validateChainAssetLockProofStructureFactory', () => {
151
151
  expect(error.getKeyword()).to.equal('type');
152
152
 
153
153
  expect(stateRepositoryMock.fetchTransaction).to.not.be.called();
154
- expect(validateAssetLockTransactionMock).to.not.be.called();
155
154
  expect(stateRepositoryMock.fetchLatestPlatformCoreChainLockedHeight).to.not.be.called();
156
155
  });
157
156
 
@@ -163,7 +162,7 @@ describe('validateChainAssetLockProofStructureFactory', () => {
163
162
  executionContext,
164
163
  );
165
164
 
166
- expectJsonSchemaError(result);
165
+ await expectJsonSchemaError(result);
167
166
 
168
167
  const [error] = result.getErrors();
169
168
 
@@ -171,7 +170,6 @@ describe('validateChainAssetLockProofStructureFactory', () => {
171
170
  expect(error.getKeyword()).to.equal('type');
172
171
 
173
172
  expect(stateRepositoryMock.fetchTransaction).to.not.be.called();
174
- expect(validateAssetLockTransactionMock).to.not.be.called();
175
173
  expect(stateRepositoryMock.fetchLatestPlatformCoreChainLockedHeight).to.not.be.called();
176
174
  });
177
175
 
@@ -183,7 +181,7 @@ describe('validateChainAssetLockProofStructureFactory', () => {
183
181
  executionContext,
184
182
  );
185
183
 
186
- expectJsonSchemaError(result);
184
+ await expectJsonSchemaError(result);
187
185
 
188
186
  const [error] = result.getErrors();
189
187
 
@@ -191,7 +189,6 @@ describe('validateChainAssetLockProofStructureFactory', () => {
191
189
  expect(error.getKeyword()).to.equal('minimum');
192
190
 
193
191
  expect(stateRepositoryMock.fetchTransaction).to.not.be.called();
194
- expect(validateAssetLockTransactionMock).to.not.be.called();
195
192
  expect(stateRepositoryMock.fetchLatestPlatformCoreChainLockedHeight).to.not.be.called();
196
193
  });
197
194
 
@@ -203,20 +200,19 @@ describe('validateChainAssetLockProofStructureFactory', () => {
203
200
  executionContext,
204
201
  );
205
202
 
206
- expectJsonSchemaError(result);
203
+ await expectJsonSchemaError(result);
207
204
 
208
205
  const [error] = result.getErrors();
209
206
 
210
- expect(error.instancePath).to.equal('/coreChainLockedHeight');
207
+ expect(error.getInstancePath()).to.equal('/coreChainLockedHeight');
211
208
  expect(error.getKeyword()).to.equal('maximum');
212
209
 
213
210
  expect(stateRepositoryMock.fetchTransaction).to.not.be.called();
214
- expect(validateAssetLockTransactionMock).to.not.be.called();
215
211
  expect(stateRepositoryMock.fetchLatestPlatformCoreChainLockedHeight).to.not.be.called();
216
212
  });
217
213
 
218
214
  it('should be less or equal to consensus core height', async () => {
219
- stateRepositoryMock.fetchLatestPlatformCoreChainLockedHeight.resolves(41);
215
+ stateRepositoryMock.fetchLatestPlatformCoreChainLockedHeight.returns(41);
220
216
 
221
217
  const result = await validateChainAssetLockProofStructure(
222
218
  rawProof,
@@ -242,16 +238,15 @@ describe('validateChainAssetLockProofStructureFactory', () => {
242
238
  executionContext,
243
239
  );
244
240
 
245
- expectJsonSchemaError(result);
241
+ await expectJsonSchemaError(result);
246
242
 
247
243
  const [error] = result.getErrors();
248
244
 
249
- expect(error.instancePath).to.equal('');
245
+ expect(error.getInstancePath()).to.equal('');
250
246
  expect(error.getKeyword()).to.equal('required');
251
247
  expect(error.getParams().missingProperty).to.equal('outPoint');
252
248
 
253
249
  expect(stateRepositoryMock.fetchTransaction).to.not.be.called();
254
- expect(validateAssetLockTransactionMock).to.not.be.called();
255
250
  expect(stateRepositoryMock.fetchLatestPlatformCoreChainLockedHeight).to.not.be.called();
256
251
  });
257
252
 
@@ -263,17 +258,14 @@ describe('validateChainAssetLockProofStructureFactory', () => {
263
258
  executionContext,
264
259
  );
265
260
 
266
- expectJsonSchemaError(result, 2);
261
+ await expectJsonSchemaError(result, 36);
267
262
 
268
- const [error, byteArrayError] = result.getErrors();
263
+ const [error] = result.getErrors();
269
264
 
270
- expect(error.instancePath).to.equal('/outPoint/0');
265
+ expect(error.getInstancePath()).to.equal('/outPoint/0');
271
266
  expect(error.getKeyword()).to.equal('type');
272
267
 
273
- expect(byteArrayError.getKeyword()).to.equal('byteArray');
274
-
275
268
  expect(stateRepositoryMock.fetchTransaction).to.not.be.called();
276
- expect(validateAssetLockTransactionMock).to.not.be.called();
277
269
  expect(stateRepositoryMock.fetchLatestPlatformCoreChainLockedHeight).to.not.be.called();
278
270
  });
279
271
 
@@ -285,15 +277,14 @@ describe('validateChainAssetLockProofStructureFactory', () => {
285
277
  executionContext,
286
278
  );
287
279
 
288
- expectJsonSchemaError(result);
280
+ await expectJsonSchemaError(result);
289
281
 
290
282
  const [error] = result.getErrors();
291
283
 
292
- expect(error.instancePath).to.equal('/outPoint');
284
+ expect(error.getInstancePath()).to.equal('/outPoint');
293
285
  expect(error.getKeyword()).to.equal('minItems');
294
286
 
295
287
  expect(stateRepositoryMock.fetchTransaction).to.not.be.called();
296
- expect(validateAssetLockTransactionMock).to.not.be.called();
297
288
  expect(stateRepositoryMock.fetchLatestPlatformCoreChainLockedHeight).to.not.be.called();
298
289
  });
299
290
 
@@ -305,27 +296,26 @@ describe('validateChainAssetLockProofStructureFactory', () => {
305
296
  executionContext,
306
297
  );
307
298
 
308
- expectJsonSchemaError(result);
299
+ await expectJsonSchemaError(result);
309
300
 
310
301
  const [error] = result.getErrors();
311
302
 
312
- expect(error.instancePath).to.equal('/outPoint');
303
+ expect(error.getInstancePath()).to.equal('/outPoint');
313
304
  expect(error.getKeyword()).to.equal('maxItems');
314
305
 
315
306
  expect(stateRepositoryMock.fetchTransaction).to.not.be.called();
316
- expect(validateAssetLockTransactionMock).to.not.be.called();
317
307
  expect(stateRepositoryMock.fetchLatestPlatformCoreChainLockedHeight).to.not.be.called();
318
308
  });
319
309
 
320
- it('should point to existing transaction', async () => {
321
- stateRepositoryMock.fetchTransaction.resolves(null);
310
+ it('should point to existing transaction', async function () {
311
+ stateRepositoryMock.fetchTransaction.returns(null);
322
312
 
323
313
  const result = await validateChainAssetLockProofStructure(
324
314
  rawProof,
325
315
  executionContext,
326
316
  );
327
317
 
328
- expectValidationError(result, IdentityAssetLockTransactionIsNotFoundError);
318
+ await expectValidationError(result, IdentityAssetLockTransactionIsNotFoundError);
329
319
 
330
320
  const [error] = result.getErrors();
331
321
 
@@ -336,39 +326,45 @@ describe('validateChainAssetLockProofStructureFactory', () => {
336
326
 
337
327
  expect(stateRepositoryMock.fetchTransaction).to.be.calledOnceWithExactly(
338
328
  transactionHash,
339
- executionContext,
329
+ this.sinonSandbox.match.instanceOf(StateTransitionExecutionContext),
340
330
  );
341
- expect(validateAssetLockTransactionMock).to.not.be.called();
342
331
  expect(stateRepositoryMock.fetchLatestPlatformCoreChainLockedHeight).to.be.calledOnce();
343
332
  });
344
333
 
345
334
  it('should point to valid transaction', async () => {
346
- const consensusError = new SomeConsensusError('test');
335
+ // Validator expects asset lock proof TX to have OP_RETURN in it's first output, break it
336
+ const parsedTx = new Transaction(Buffer.from(rawTransaction, 'hex'));
337
+ const fromAddress = new PrivateKey().toAddress();
338
+ parsedTx.outputs[0].setScript(Script.buildPublicKeyHashOut(fromAddress).toString());
347
339
 
348
- validateAssetLockTransactionResult.addError(consensusError);
340
+ stateRepositoryMock.fetchTransaction.returns({
341
+ data: parsedTx.toBuffer(),
342
+ height: 42,
343
+ });
349
344
 
350
345
  const result = await validateChainAssetLockProofStructure(
351
346
  rawProof,
352
347
  executionContext,
353
348
  );
354
349
 
355
- expectValidationError(result, SomeConsensusError);
356
-
357
- const [error] = result.getErrors();
358
-
359
- expect(error).to.deep.equal(consensusError);
350
+ await expectValidationError(
351
+ result,
352
+ InvalidIdentityAssetLockTransactionOutputError,
353
+ );
360
354
  });
361
355
 
362
- it('should point to transaction from block lower than core chain locked height', async () => {
356
+ it('should point to transaction from block lower than core chain locked height', async function () {
363
357
  rawProof.coreChainLockedHeight = 41;
364
- stateRepositoryMock.fetchLatestPlatformCoreChainLockedHeight.resolves(41);
358
+ stateRepositoryMock.fetchLatestPlatformCoreChainLockedHeight.returns(41);
365
359
 
366
360
  const result = await validateChainAssetLockProofStructure(
367
361
  rawProof,
368
362
  executionContext,
369
363
  );
370
364
 
371
- expectValidationError(result, InvalidAssetLockProofTransactionHeightError);
365
+ await expectValidationError(
366
+ result, InvalidAssetLockProofTransactionHeightError,
367
+ );
372
368
 
373
369
  const [error] = result.getErrors();
374
370
 
@@ -378,14 +374,13 @@ describe('validateChainAssetLockProofStructureFactory', () => {
378
374
 
379
375
  expect(stateRepositoryMock.fetchTransaction).to.be.calledOnceWithExactly(
380
376
  transactionHash,
381
- executionContext,
377
+ this.sinonSandbox.match.instanceOf(StateTransitionExecutionContext),
382
378
  );
383
- expect(validateAssetLockTransactionMock).to.not.be.called();
384
379
  expect(stateRepositoryMock.fetchLatestPlatformCoreChainLockedHeight).to.be.calledOnce();
385
380
  });
386
381
  });
387
382
 
388
- it('should return valid result', async () => {
383
+ it('should return valid result', async function () {
389
384
  const result = await validateChainAssetLockProofStructure(
390
385
  rawProof,
391
386
  executionContext,
@@ -397,13 +392,9 @@ describe('validateChainAssetLockProofStructureFactory', () => {
397
392
 
398
393
  expect(stateRepositoryMock.fetchTransaction).to.be.calledOnceWithExactly(
399
394
  transactionHash,
400
- executionContext,
401
- );
402
- expect(validateAssetLockTransactionMock).to.be.calledOnceWithExactly(
403
- Buffer.from(rawTransaction, 'hex'),
404
- 0,
405
- executionContext,
395
+ this.sinonSandbox.match.instanceOf(StateTransitionExecutionContext),
406
396
  );
397
+
407
398
  expect(stateRepositoryMock.fetchLatestPlatformCoreChainLockedHeight).to.be.calledOnce();
408
399
  });
409
400
  });
@@ -1,32 +1,52 @@
1
- const { Transaction, Script } = require('@dashevo/dashcore-lib');
2
- const Output = require('@dashevo/dashcore-lib/lib/transaction/output');
1
+ const { Transaction } = require('@dashevo/dashcore-lib');
3
2
 
4
- const fetchAssetLockTransactionOutputFactory = require('@dashevo/dpp/lib/identity/stateTransition/assetLockProof/fetchAssetLockTransactionOutputFactory');
5
3
  const getChainAssetLockFixture = require('@dashevo/dpp/lib/test/fixtures/getChainAssetLockProofFixture');
6
4
  const getInstantAssetLockProofFixture = require('@dashevo/dpp/lib/test/fixtures/getInstantAssetLockProofFixture');
7
5
  const createStateRepositoryMock = require('@dashevo/dpp/lib/test/mocks/createStateRepositoryMock');
8
-
9
- const UnknownAssetLockProofError = require('@dashevo/dpp/lib/identity/errors/UnknownAssetLockProofTypeError');
10
- const AssetLockTransactionIsNotFoundError = require('@dashevo/dpp/lib/identity/errors/AssetLockTransactionIsNotFoundError');
11
- const StateTransitionExecutionContext = require('@dashevo/dpp/lib/stateTransition/StateTransitionExecutionContext');
6
+ const { default: loadWasmDpp } = require('../../../../../dist');
12
7
 
13
8
  describe('fetchAssetLockTransactionOutputFactory', () => {
14
9
  let fetchAssetLockTransactionOutput;
15
10
  let stateRepositoryMock;
16
11
  let executionContext;
17
12
 
13
+ let StateTransitionExecutionContext;
14
+ let InstantAssetLockProof;
15
+ let ChainAssetLockProof;
16
+ let AssetLockTransactionIsNotFoundError;
17
+ let UnknownAssetLockProofTypeError;
18
+
19
+ let fetchAssetLockTransactionOutputDPP;
20
+
21
+ before(async () => {
22
+ ({
23
+ StateTransitionExecutionContext,
24
+ fetchAssetLockTransactionOutput: fetchAssetLockTransactionOutputDPP,
25
+ InstantAssetLockProof,
26
+ ChainAssetLockProof,
27
+ AssetLockTransactionIsNotFoundError,
28
+ UnknownAssetLockProofTypeError,
29
+ } = await loadWasmDpp());
30
+ });
31
+
18
32
  beforeEach(function beforeEach() {
19
33
  stateRepositoryMock = createStateRepositoryMock(this.sinonSandbox);
20
- fetchAssetLockTransactionOutput = fetchAssetLockTransactionOutputFactory(stateRepositoryMock);
21
34
 
22
35
  executionContext = new StateTransitionExecutionContext();
36
+
37
+ fetchAssetLockTransactionOutput = (proof, context) => fetchAssetLockTransactionOutputDPP(
38
+ stateRepositoryMock,
39
+ proof,
40
+ context,
41
+ );
23
42
  });
24
43
 
25
44
  describe('InstantAssetLockProof', () => {
26
45
  let assetLockProofFixture;
27
46
 
28
47
  beforeEach(() => {
29
- assetLockProofFixture = getInstantAssetLockProofFixture();
48
+ const assetLockProofFixtureJS = getInstantAssetLockProofFixture();
49
+ assetLockProofFixture = new InstantAssetLockProof(assetLockProofFixtureJS.toObject());
30
50
  });
31
51
 
32
52
  it('should return asset lock output', async () => {
@@ -47,34 +67,46 @@ describe('fetchAssetLockTransactionOutputFactory', () => {
47
67
 
48
68
  beforeEach(() => {
49
69
  const rawTransaction = '030000000137feb5676d0851337ea3c9a992496aab7a0b3eee60aeeb9774000b7f4bababa5000000006b483045022100d91557de37645c641b948c6cd03b4ae3791a63a650db3e2fee1dcf5185d1b10402200e8bd410bf516ca61715867666d31e44495428ce5c1090bf2294a829ebcfa4ef0121025c3cc7fbfc52f710c941497fd01876c189171ea227458f501afcb38a297d65b4ffffffff021027000000000000166a14152073ca2300a86b510fa2f123d3ea7da3af68dcf77cb0090a0000001976a914152073ca2300a86b510fa2f123d3ea7da3af68dc88ac00000000';
50
- assetLockProofFixture = getChainAssetLockFixture();
51
- stateRepositoryMock.fetchTransaction.resolves({
70
+ const assetLockProofFixtureJS = getChainAssetLockFixture();
71
+
72
+ const outPoint = Transaction
73
+ .parseOutPointBuffer(Buffer.from(assetLockProofFixtureJS.getOutPoint()));
74
+ ({ transactionHash } = outPoint);
75
+
76
+ const rawProof = assetLockProofFixtureJS.toObject();
77
+
78
+ // Change endianness of raw txId bytes in outPoint to match expectation of dashcore-rust
79
+ const txId = rawProof.outPoint.slice(0, 32);
80
+ const outputIndex = rawProof.outPoint.slice(32);
81
+ txId.reverse();
82
+ rawProof.outPoint = Buffer.concat([txId, outputIndex]);
83
+
84
+ assetLockProofFixture = new ChainAssetLockProof(rawProof);
85
+
86
+ stateRepositoryMock.fetchTransaction.returns({
52
87
  data: Buffer.from(rawTransaction, 'hex'),
53
88
  height: 42,
54
89
  });
55
90
 
56
91
  const transaction = new Transaction(rawTransaction);
57
92
  ([output] = transaction.outputs);
58
-
59
- const outPoint = Transaction.parseOutPointBuffer(assetLockProofFixture.getOutPoint());
60
- ({ transactionHash } = outPoint);
61
93
  });
62
94
 
63
- it('should fetch output from state repository', async () => {
95
+ it('should fetch output from state repository', async function () {
64
96
  const assetLockTransactionOutput = await fetchAssetLockTransactionOutput(
65
97
  assetLockProofFixture,
66
98
  executionContext,
67
99
  );
68
100
 
69
- expect(assetLockTransactionOutput).to.deep.equal(output);
101
+ expect(assetLockTransactionOutput).to.deep.equal(output.toObject());
70
102
 
71
103
  expect(stateRepositoryMock.fetchTransaction).to.be.calledOnceWithExactly(
72
104
  transactionHash,
73
- executionContext,
105
+ this.sinonSandbox.match.instanceOf(StateTransitionExecutionContext),
74
106
  );
75
107
  });
76
108
 
77
- it('should throw IdentityAssetLockTransactionIsNotFoundError when transaction is not found', async () => {
109
+ it('should throw AssetLockTransactionIsNotFoundError when transaction is not found', async () => {
78
110
  stateRepositoryMock.fetchTransaction.resolves(null);
79
111
 
80
112
  try {
@@ -83,14 +115,14 @@ describe('fetchAssetLockTransactionOutputFactory', () => {
83
115
  executionContext,
84
116
  );
85
117
 
86
- expect.fail('should throw IdentityAssetLockTransactionIsNotFoundError');
118
+ expect.fail('should throw AssetLockTransactionIsNotFoundError');
87
119
  } catch (e) {
88
120
  expect(e).to.be.an.instanceOf(AssetLockTransactionIsNotFoundError);
89
121
  expect(e.getTransactionId()).to.deep.equal(transactionHash);
90
122
  }
91
123
  });
92
124
 
93
- it('should return mocked output on dry run', async () => {
125
+ it('should return mocked output on dry run', async function () {
94
126
  executionContext.enableDryRun();
95
127
 
96
128
  const result = await fetchAssetLockTransactionOutput(
@@ -100,24 +132,36 @@ describe('fetchAssetLockTransactionOutputFactory', () => {
100
132
 
101
133
  executionContext.disableDryRun();
102
134
 
103
- expect(result).to.deep.equal(new Output({
135
+ expect(result).to.deep.equal({
104
136
  satoshis: 1000,
105
- script: new Script(),
106
- }));
137
+ script: '',
138
+ });
107
139
 
108
140
  expect(stateRepositoryMock.fetchTransaction).to.be.calledOnceWithExactly(
109
141
  transactionHash,
110
- executionContext,
142
+ this.sinonSandbox.match.instanceOf(StateTransitionExecutionContext),
111
143
  );
112
144
  });
113
145
  });
114
146
 
115
- it('should throw UnknownAssetLockProofError for unknown assetLockProof', async function it() {
116
- const type = 666;
147
+ it('should throw UnknownAssetLockProofTypeError for unknown assetLockProof', async () => {
148
+ try {
149
+ await fetchAssetLockTransactionOutput(
150
+ {},
151
+ executionContext,
152
+ );
153
+
154
+ expect.fail('should throw UnknownAssetLockProofTypeError');
155
+ } catch (e) {
156
+ expect(e).to.be.an.instanceOf(UnknownAssetLockProofTypeError);
157
+ }
158
+ });
159
+
160
+ it('should throw UnknownAssetLockProofTypeError for unknown assetLockProof type', async () => {
161
+ const type = 100;
117
162
 
118
- const assetLockProofFixture = {
119
- getType: this.sinonSandbox.stub().returns(type),
120
- };
163
+ const assetLockProofFixture = new ChainAssetLockProof(getChainAssetLockFixture().toObject());
164
+ assetLockProofFixture.getType = () => type;
121
165
 
122
166
  try {
123
167
  await fetchAssetLockTransactionOutput(
@@ -125,9 +169,9 @@ describe('fetchAssetLockTransactionOutputFactory', () => {
125
169
  executionContext,
126
170
  );
127
171
 
128
- expect.fail('should throw UnknownAssetLockProofError');
172
+ expect.fail('should throw UnknownAssetLockProofTypeError');
129
173
  } catch (e) {
130
- expect(e).to.be.an.instanceOf(UnknownAssetLockProofError);
174
+ expect(e).to.be.an.instanceOf(UnknownAssetLockProofTypeError);
131
175
  expect(e.getType()).to.equal(type);
132
176
  }
133
177
  });