@dashevo/wasm-dpp 0.24.0-dev.12 → 0.24.0-dev.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.mocharc.yml +1 -1
- package/Cargo.toml +5 -2
- package/README.md +5 -1
- package/dist/index.js +1 -1
- package/dist/index.js.LICENSE.txt +9 -0
- package/dist/wasm/wasm_dpp.d.ts +3397 -1237
- package/karma.conf.js +5 -0
- package/lib/identifier/patchIdentifier.ts +5 -4
- package/lib/index.ts +1 -1
- package/lib/test/bootstrap.js +5 -0
- package/lib/test/fixtures/getDataContractFixture.js +267 -0
- package/lib/test/fixtures/getDocumentsFixture.js +43 -0
- package/lib/test/mocks/createStateRepositoryMock.js +64 -0
- package/lib/test/mocks/getBlsAdapterMock.js +51 -0
- package/package.json +11 -8
- package/src/bls_adapter.rs +17 -1
- package/src/buffer.rs +3 -0
- package/src/dash_platform_protocol.rs +107 -10
- package/src/data_contract/data_contract.rs +59 -10
- package/src/data_contract/data_contract_facade.rs +128 -0
- package/src/data_contract/errors/invalid_data_contract.rs +16 -16
- package/src/data_contract/errors/invalid_document_type.rs +8 -8
- package/src/data_contract/errors/mod.rs +10 -16
- package/src/data_contract/index.rs +56 -1
- package/src/data_contract/mod.rs +4 -0
- package/src/data_contract/state_transition/data_contract_create_transition/apply.rs +1 -1
- package/src/data_contract/state_transition/data_contract_create_transition/mod.rs +41 -10
- package/src/data_contract/state_transition/data_contract_create_transition/validation.rs +35 -4
- package/src/data_contract/state_transition/data_contract_update_transition/apply.rs +1 -1
- package/src/data_contract/state_transition/data_contract_update_transition/mod.rs +20 -7
- package/src/data_contract/state_transition/data_contract_update_transition/validation.rs +47 -11
- package/src/data_contract_factory/data_contract_factory.rs +19 -17
- package/src/data_trigger/data_trigger_execution_context.rs +95 -0
- package/src/data_trigger/data_trigger_execution_result.rs +48 -0
- package/src/data_trigger/execute_data_triggers_factory.rs +60 -0
- package/src/data_trigger/get_data_triggers_factory.rs +65 -0
- package/src/data_trigger/mod.rs +121 -0
- package/src/document/document_facade.rs +125 -0
- package/src/document/errors/invalid_document_error.rs +10 -9
- package/src/document/errors/invalid_initial_revision_error.rs +1 -1
- package/src/document/errors/mismatch_owners_ids_error.rs +14 -4
- package/src/document/errors/mod.rs +17 -13
- package/src/document/errors/no_documents_supplied_error.rs +4 -4
- package/src/document/factory.rs +257 -0
- package/src/document/fetch_and_validate_data_contract.rs +77 -0
- package/src/document/generate_document_id.rs +17 -0
- package/src/document/mod.rs +311 -37
- package/src/document/state_transition/document_batch_transition/apply_document_batch_transition.rs +22 -0
- package/src/document/state_transition/document_batch_transition/document_transition/document_create_transition.rs +253 -1
- package/src/document/state_transition/document_batch_transition/document_transition/document_delete_transition.rs +60 -1
- package/src/document/state_transition/document_batch_transition/document_transition/document_replace_transition.rs +263 -0
- package/src/document/state_transition/document_batch_transition/document_transition/mod.rs +302 -3
- package/src/document/state_transition/document_batch_transition/mod.rs +378 -0
- package/src/document/state_transition/document_batch_transition/validation/basic/find_duplicates_by_id.rs +40 -0
- package/src/document/state_transition/document_batch_transition/validation/basic/find_duplicates_by_indices.rs +50 -0
- package/src/document/state_transition/document_batch_transition/validation/basic/mod.rs +8 -0
- package/src/document/state_transition/document_batch_transition/validation/basic/validate_documents_batch_transition_basic.rs +34 -0
- package/src/document/state_transition/document_batch_transition/validation/basic/validate_partial_compound_indices.rs +39 -0
- package/src/document/state_transition/document_batch_transition/validation/mod.rs +2 -0
- package/src/document/state_transition/document_batch_transition/validation/state/fetch_documents.rs +43 -0
- package/src/document/state_transition/document_batch_transition/validation/state/mod.rs +3 -0
- package/src/document/state_transition/document_batch_transition/validation/state/validate_documents_batch_transitions_state.rs +27 -0
- package/src/document/state_transition/document_batch_transition/validation/state/validate_documents_uniqueness_by_indices.rs +47 -0
- package/src/document/validator.rs +52 -0
- package/src/errors/compatible_protocol_version_is_not_defined_error.rs +24 -0
- package/src/errors/consensus/basic/document/duplicate_document_transitions_with_ids_error.rs +1 -1
- package/src/errors/consensus/basic/document/duplicate_document_transitions_with_indices_error.rs +1 -1
- package/src/errors/consensus/basic/document/inconsistent_compound_index_data_error.rs +2 -2
- package/src/errors/consensus/basic/document/invalid_document_type_error.rs +15 -1
- package/src/errors/consensus/basic/document/missing_data_contract_id_error.rs +16 -2
- package/src/errors/consensus/basic/identity/duplicated_identity_public_key_error.rs +1 -1
- package/src/errors/consensus/basic/identity/duplicated_identity_public_key_id_error.rs +1 -1
- package/src/errors/consensus/basic/identity/identity_asset_lock_proof_locked_transaction_mismatch_error.rs +6 -2
- package/src/errors/consensus/basic/identity/identity_asset_lock_transaction_out_point_already_exists_error.rs +5 -2
- package/src/errors/consensus/basic/identity/invalid_asset_lock_proof_transaction_height_error.rs +3 -3
- package/src/errors/consensus/basic/identity/invalid_identity_credit_withdrawal_transition_core_fee_error.rs +2 -2
- package/src/errors/consensus/basic/identity/invalid_identity_credit_withdrawal_transition_pooling_error.rs +29 -0
- package/src/errors/consensus/basic/identity/invalid_identity_key_signature_error.rs +4 -3
- package/src/errors/consensus/basic/identity/invalid_identity_public_key_data_error.rs +1 -1
- package/src/errors/consensus/basic/identity/invalid_identity_public_key_security_level_error.rs +1 -1
- package/src/errors/consensus/basic/identity/missing_public_key_error.rs +4 -3
- package/src/errors/consensus/basic/identity/mod.rs +2 -0
- package/src/errors/consensus/basic/invalid_identifier_error.rs +1 -1
- package/src/errors/consensus/basic/json_schema_error.rs +8 -2
- package/src/errors/consensus/basic/public_key_is_disabled_error.rs +1 -1
- package/src/errors/consensus/state/document/document_timestamp_window_violation_error.rs +9 -9
- package/src/errors/consensus/state/document/invalid_document_revision_error.rs +4 -4
- package/src/errors/consensus/state/identity/duplicated_identity_public_key_id_state_error.rs +35 -0
- package/src/errors/consensus/state/identity/duplicated_identity_public_key_state_error.rs +34 -0
- package/src/errors/consensus/state/identity/identity_public_key_disabled_at_window_violation_error.rs +10 -7
- package/src/errors/consensus/state/identity/identity_public_key_is_disabled_error.rs +2 -3
- package/src/errors/consensus/state/identity/identity_public_key_is_read_only_error.rs +7 -3
- package/src/errors/consensus/state/identity/invalid_identity_public_key_id_error.rs +2 -3
- package/src/errors/consensus/state/identity/invalid_identity_revision_error.rs +7 -4
- package/src/errors/consensus/state/identity/max_identity_public_key_limit_reached_error.rs +2 -1
- package/src/errors/consensus/state/identity/mod.rs +4 -0
- package/src/errors/consensus_error.rs +218 -268
- package/src/errors/data_contract_not_present_error.rs +23 -0
- package/src/errors/dpp_error.rs +17 -0
- package/src/errors/from.rs +22 -0
- package/src/errors/js_conversion.rs +52 -5
- package/src/errors/mod.rs +6 -0
- package/src/errors/protocol_error.rs +14 -3
- package/src/identifier/errors.rs +30 -0
- package/src/identifier/mod.rs +95 -11
- package/src/identity/errors/asset_lock_output_not_found_error.rs +11 -0
- package/src/identity/errors/asset_lock_transaction_is_not_found_error.rs +20 -0
- package/src/identity/errors/invalid_identity_error.rs +32 -0
- package/src/identity/errors/mod.rs +9 -0
- package/src/identity/errors/unknown_asset_lock_proof_type_error.rs +26 -0
- package/src/identity/factory_utils.rs +87 -0
- package/src/identity/identity_facade.rs +194 -20
- package/src/identity/identity_factory.rs +209 -0
- package/src/identity/identity_public_key/mod.rs +51 -40
- package/src/identity/mod.rs +31 -17
- package/src/identity/state_transition/asset_lock_proof/chain/chain_asset_lock_proof.rs +132 -0
- package/src/identity/state_transition/asset_lock_proof/chain/chain_asset_lock_proof_structure_validator.rs +72 -0
- package/src/identity/state_transition/asset_lock_proof/chain/mod.rs +4 -0
- package/src/identity/state_transition/asset_lock_proof/instant/instant_asset_lock_proof.rs +177 -0
- package/src/identity/state_transition/asset_lock_proof/instant/instant_asset_lock_proof_structure_validator.rs +72 -0
- package/src/identity/state_transition/asset_lock_proof/instant/mod.rs +4 -0
- package/src/identity/state_transition/asset_lock_proof/mod.rs +269 -0
- package/src/identity/state_transition/identity_create_transition/apply_identity_create_transition.rs +26 -0
- package/src/identity/state_transition/identity_create_transition/identity_create_transition.rs +337 -0
- package/src/identity/state_transition/identity_create_transition/identity_create_transition_basic_validator.rs +153 -0
- package/src/identity/state_transition/identity_create_transition/identity_create_transition_state_validator.rs +37 -0
- package/src/identity/state_transition/identity_create_transition/mod.rs +8 -0
- package/src/identity/state_transition/identity_create_transition/to_object.rs +45 -0
- package/src/identity/state_transition/identity_public_key_transitions.rs +207 -0
- package/src/identity/state_transition/identity_topup_transition/apply_identity_topup_transition.rs +31 -0
- package/src/identity/state_transition/identity_topup_transition/identity_topup_transition.rs +278 -0
- package/src/identity/state_transition/identity_topup_transition/identity_topup_transition_basic_validator.rs +113 -0
- package/src/identity/state_transition/identity_topup_transition/identity_topup_transition_state_validator.rs +37 -0
- package/src/identity/state_transition/identity_topup_transition/mod.rs +8 -0
- package/src/identity/state_transition/identity_topup_transition/to_object.rs +42 -0
- package/src/identity/state_transition/identity_update_transition/apply_identity_update_transition.rs +24 -0
- package/src/identity/state_transition/identity_update_transition/identity_update_public_keys_validator.rs +55 -0
- package/src/identity/state_transition/identity_update_transition/identity_update_transition.rs +448 -0
- package/src/identity/state_transition/identity_update_transition/identity_update_transition_basic_validator.rs +94 -0
- package/src/identity/state_transition/identity_update_transition/identity_update_transition_state_validator.rs +53 -0
- package/src/identity/state_transition/identity_update_transition/mod.rs +9 -0
- package/src/identity/state_transition/identity_update_transition/to_object.rs +66 -0
- package/src/identity/state_transition/mod.rs +12 -0
- package/src/identity/state_transition/validate_public_key_signatures.rs +61 -0
- package/src/identity/validation/identity_validator.rs +50 -0
- package/src/identity/validation/mod.rs +2 -0
- package/src/identity/validation/public_keys_validator.rs +14 -13
- package/src/identity_public_key/public_keys_validator.rs +44 -0
- package/src/lib.rs +6 -0
- package/src/lodash.rs +7 -0
- package/src/metadata.rs +54 -10
- package/src/state_repository.rs +598 -101
- package/src/state_transition/conversion.rs +104 -0
- package/src/state_transition/errors/invalid_state_transition_error.rs +32 -0
- package/src/state_transition/errors/mod.rs +1 -0
- package/src/state_transition/mod.rs +46 -0
- package/src/state_transition/state_transition_facade.rs +263 -0
- package/src/state_transition/state_transition_factory.rs +216 -0
- package/src/state_transition/validation/mod.rs +1 -0
- package/src/state_transition/validation/validate_state_transition_key_signature.rs +62 -0
- package/src/utils.rs +210 -8
- package/src/validation/json_schema_validator.rs +41 -0
- package/src/validation/mod.rs +2 -0
- package/src/validation/validation_result.rs +29 -5
- package/src/version/mod.rs +2 -0
- package/src/version/protocol_version.rs +103 -0
- package/test/integration/dataContract/DataContractFacade.spec.js +46 -30
- package/test/integration/dataContract/stateTransition/DataContractCreateTransition/validation/basic/validateDataContractCreateTransitionBasicFactory.spec.js +45 -127
- package/test/integration/dataContract/stateTransition/DataContractUpdateTransition/validation/basic/validateDataContractUpdateTransitionBasicFactory.spec.js +91 -139
- package/test/integration/dataContract/validation/validateDataContractFactory.spec.js +577 -503
- package/test/integration/document/Document.spec.js +55 -29
- package/test/integration/document/DocumentFacade.spec.js +51 -64
- package/test/integration/document/stateTransition/DocumentsBatchTransition/DocumentBatchTransition.spec.js +38 -16
- package/test/integration/document/stateTransition/DocumentsBatchTransition/validation/basic/validateDocumentsBatchTransitionBasicFactory.spec.js +341 -396
- package/test/integration/document/stateTransition/DocumentsBatchTransition/validation/state/executeDataTriggersFactory.spec.js +116 -218
- package/test/integration/document/validation/validateDocumentFactory.spec.js +123 -171
- package/test/integration/identity/IdentityFacade.spec.js +52 -27
- package/test/integration/identity/stateTransition/IdentityCreateTransition/validation/basic/validateIdentityCreateTransitionBasicFactory.spec.js +185 -164
- package/test/integration/identity/stateTransition/IdentityTopUpTransition/validation/basic/validateIdentityTopUpTransitionBasicFactory.spec.js +84 -114
- package/test/integration/identity/stateTransition/IdentityUpdateTransition/validation/basic/validateIdentityUpdateTransitionBasicFactory.spec.js +120 -137
- package/test/integration/identity/stateTransition/IdentityUpdateTransition/validation/state/validateIdentityUpdateTransitionStateFactory.spec.js +106 -91
- package/test/integration/identity/stateTransition/IdentityUpdateTransition/validation/state/validatePublicKeysState.spec.js +50 -16
- package/test/integration/identity/stateTransition/assetLockProof/chain/validateChainAssetLockProofStructureFactory.spec.js +78 -86
- package/test/integration/identity/stateTransition/assetLockProof/fetchAssetLockTransactionOutputFactory.spec.js +74 -30
- package/test/integration/identity/stateTransition/assetLockProof/instant/validateInstantAssetLockProofStructureFactory.spec.js +93 -147
- package/test/integration/identity/stateTransition/assetLockProof/validateAssetLockTransactionFactory.spec.js +65 -77
- package/test/integration/identity/stateTransition/validatePublicKeySignaturesFactory.spec.js +60 -23
- package/test/integration/identity/validation/validateIdentityFactory.spec.js +46 -114
- package/test/integration/identity/validation/validatePublicKeysFactory.spec.js +9 -3
- package/test/integration/stateTransition/AbstractStateTransitionIdentitySigned.spec.js +12 -8
- package/test/integration/stateTransition/StateTransitionFacade.spec.js +95 -233
- package/test/integration/stateTransition/calculateStateTransitionFeeFromOperationsFactory.spec.js +53 -0
- package/test/unit/Identifier.spec.js +36 -36
- package/test/unit/Metadata.spec.js +17 -3
- package/test/unit/dataContract/DataContract.spec.js +9 -4
- package/test/unit/dataContract/createDataContract.spec.js +0 -1
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/DataContractCreateTransition.spec.js +3 -3
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/applyDataContractCreateTransitionFactory.spec.js +1 -1
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/validation/state/validateDataContractCreateTransitionStateFactory.spec.js +2 -2
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/DataContractUpdateTransition.spec.js +3 -3
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/applyDataContractUpdateTransitionFactory.spec.js +1 -1
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/validation/basic/validateIndicesAreBackwardCompatible.spec.js +25 -31
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/validation/state/validateDataContractUpdateTransitionStateFactory.spec.js +3 -3
- package/test/unit/dataTrigger/rewardShareDataTriggers/createMasternodeRewardSharesDataTrigger.spec.js +2 -0
- package/test/unit/decodeProtocolEntityFactory.spec.js +2 -2
- package/test/unit/document/Document.spec.js +147 -155
- package/test/unit/document/DocumentFactory.spec.js +153 -153
- package/test/unit/document/fetchAndValidateDataContractFactory.spec.js +59 -14
- package/test/unit/document/stateTransition/DocumetsBatchTransition/DocumentsBatchTransition.spec.js +131 -62
- package/test/unit/document/stateTransition/DocumetsBatchTransition/applyDocumentsBatchTransitionFactory.spec.js +144 -56
- package/test/unit/document/stateTransition/DocumetsBatchTransition/documentTransition/DocumentCreateTransition.spec.js +38 -8
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/basic/findDuplicatesById.spec.js +11 -7
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/basic/findDuplicatesByIndices.spec.js +29 -18
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/basic/validatePartialCompoundIndices.spec.js +38 -29
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/fetchDocumentsFactory.spec.js +53 -91
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/validateDocumentsBatchTransitionStateFactory.spec.js +357 -493
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/validateDocumentsUniquenessByIndicesFactory.spec.js +133 -72
- package/test/unit/identity/Identity.spec.js +26 -9
- package/test/unit/identity/IdentityFactory.spec.js +81 -89
- package/test/unit/identity/stateTransition/IdentityCreateTransition/IdentityCreateTransition.spec.js +73 -30
- package/test/unit/identity/stateTransition/IdentityCreateTransition/applyIdentityCreateTransitionFactory.spec.js +38 -38
- package/test/unit/identity/stateTransition/IdentityCreateTransition/validation/state/validateIdentityCreateTransitionStateFactory.spec.js +34 -25
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/IdentityTopUpTransition.spec.js +36 -16
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/applyIdentityTopUpTransitionFactory.spec.js +85 -50
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/validation/state/validateIdentityTopUpTransitionStateFactory.spec.js +24 -6
- package/test/unit/identity/stateTransition/IdentityUpdateTransition/IdentityUpdateTransition.spec.js +44 -22
- package/test/unit/identity/stateTransition/IdentityUpdateTransition/applyIdentityUpdateTransitionFactory.spec.js +58 -103
- package/test/unit/identity/stateTransition/assetLockProof/ChainAssetLockProof.spec.js +63 -0
- package/test/unit/identity/stateTransition/assetLockProof/InstantAssetLockProof.spec.js +90 -0
- package/test/unit/identity/stateTransition/assetLockProof/createAssetLockProofInstance.spec.js +18 -3
- package/test/unit/identity/stateTransition/assetLockProof/fetchAssetLockPublicKeyHashFactory.spec.js +38 -11
- package/test/unit/stateTransition/StateTransitionFactory.spec.js +49 -101
- package/test/unit/stateTransition/validation/validateStateTransitionFeeFactory.spec.js +23 -25
- package/test/unit/stateTransition/validation/validateStateTransitionKeySignatureFactory.spec.js +73 -46
- package/test/unit/version/validateProtocolVersionFactory.spec.js +45 -27
- package/wasm/package.json +5 -0
- package/wasm/wasm_dpp.d.ts +3397 -1237
- package/wasm/wasm_dpp.js +7158 -1384
- package/wasm/wasm_dpp_bg.js +1 -1
- package/wasm/wasm_dpp_bg.wasm +0 -0
- package/wasm/wasm_dpp_bg.wasm.d.ts +777 -389
- package/webpack.config.js +9 -0
- package/src/document/state_transition/document_batch_transition/document_transition/document_update_transition.rs +0 -22
- package/test/integration/stateTransition/calculateStateTransitionFeeFactory.spec.js +0 -135
- package/test/unit/dataContract/errors/InvalidDataContractError.spec.js +0 -54
|
@@ -1,63 +1,67 @@
|
|
|
1
|
-
const { getRE2Class } = require('@dashevo/wasm-re2');
|
|
2
|
-
|
|
3
|
-
const createAjv = require('@dashevo/dpp/lib/ajv/createAjv');
|
|
4
|
-
|
|
5
1
|
const protocolVersion = require('@dashevo/dpp/lib/version/protocolVersion');
|
|
6
|
-
|
|
7
|
-
const JsonSchemaValidator = require('@dashevo/dpp/lib/validation/JsonSchemaValidator');
|
|
8
|
-
|
|
9
2
|
const generateRandomIdentifier = require('@dashevo/dpp/lib/test/utils/generateRandomIdentifier');
|
|
10
|
-
|
|
11
|
-
const enrichDataContractWithBaseSchema = require('@dashevo/dpp/lib/dataContract/enrichDataContractWithBaseSchema');
|
|
12
|
-
|
|
13
|
-
const DocumentsBatchTransition = require('@dashevo/dpp/lib/document/stateTransition/DocumentsBatchTransition/DocumentsBatchTransition');
|
|
14
|
-
|
|
15
3
|
const getDocumentTransitionsFixture = require('@dashevo/dpp/lib/test/fixtures/getDocumentTransitionsFixture');
|
|
16
4
|
const getDocumentsFixture = require('@dashevo/dpp/lib/test/fixtures/getDocumentsFixture');
|
|
17
5
|
const getDataContractFixture = require('@dashevo/dpp/lib/test/fixtures/getDataContractFixture');
|
|
18
|
-
|
|
19
|
-
const ValidationResult = require('@dashevo/dpp/lib/validation/ValidationResult');
|
|
20
|
-
|
|
21
|
-
const validateDocumentsBatchTransitionBasicFactory = require('@dashevo/dpp/lib/document/stateTransition/DocumentsBatchTransition/validation/basic/validateDocumentsBatchTransitionBasicFactory');
|
|
22
|
-
|
|
23
|
-
const { expectValidationError, expectJsonSchemaError } = require('@dashevo/dpp/lib/test/expect/expectError');
|
|
24
|
-
|
|
25
6
|
const createStateRepositoryMock = require('@dashevo/dpp/lib/test/mocks/createStateRepositoryMock');
|
|
26
7
|
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
8
|
+
const { default: loadWasmDpp } = require('../../../../../../../dist');
|
|
9
|
+
const { expectJsonSchemaError, expectValidationError } = require('../../../../../../../lib/test/expect/expectError');
|
|
10
|
+
|
|
11
|
+
let DataContract;
|
|
12
|
+
let DocumentsBatchTransition;
|
|
13
|
+
let StateTransitionExecutionContext;
|
|
14
|
+
let validateDocumentsBatchTransitionBasic;
|
|
15
|
+
let generateDocumentId;
|
|
16
|
+
let MissingDataContractIdError;
|
|
17
|
+
let InvalidIdentifierError;
|
|
18
|
+
let DataContractNotPresentError;
|
|
19
|
+
let MissingDocumentTransitionTypeError;
|
|
20
|
+
let InvalidDocumentTypeError;
|
|
21
|
+
let MissingDocumentTransitionActionError;
|
|
22
|
+
let InvalidDocumentTransitionActionError;
|
|
23
|
+
let InvalidDocumentTransitionIdError;
|
|
24
|
+
let DuplicateDocumentTransitionsWithIndicesError;
|
|
25
|
+
let DuplicateDocumentTransitionsWithIdsError;
|
|
26
|
+
let ValidationResult;
|
|
27
|
+
let ProtocolVersionValidator;
|
|
39
28
|
|
|
40
29
|
describe('validateDocumentsBatchTransitionBasicFactory', () => {
|
|
41
30
|
let dataContract;
|
|
42
31
|
let documents;
|
|
43
32
|
let rawStateTransition;
|
|
44
|
-
let findDuplicatesByIdMock;
|
|
45
|
-
let findDuplicatesByIndicesMock;
|
|
46
|
-
let validateDocumentsBatchTransitionBasic;
|
|
47
33
|
let stateTransition;
|
|
48
34
|
let ownerId;
|
|
49
35
|
let stateRepositoryMock;
|
|
50
|
-
let validator;
|
|
51
|
-
let enrichSpy;
|
|
52
36
|
let documentTransitions;
|
|
53
|
-
let
|
|
54
|
-
let validateProtocolVersionMock;
|
|
37
|
+
let protocolVersionValidator;
|
|
55
38
|
let executionContext;
|
|
56
39
|
|
|
57
40
|
beforeEach(async function beforeEach() {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
41
|
+
({
|
|
42
|
+
ProtocolVersionValidator,
|
|
43
|
+
DataContract,
|
|
44
|
+
StateTransitionExecutionContext,
|
|
45
|
+
DocumentsBatchTransition,
|
|
46
|
+
ValidationResult,
|
|
47
|
+
validateDocumentsBatchTransitionBasic,
|
|
48
|
+
generateDocumentId,
|
|
49
|
+
InvalidIdentifierError,
|
|
50
|
+
MissingDataContractIdError,
|
|
51
|
+
DataContractNotPresentError,
|
|
52
|
+
MissingDocumentTransitionTypeError,
|
|
53
|
+
InvalidDocumentTypeError,
|
|
54
|
+
MissingDocumentTransitionActionError,
|
|
55
|
+
InvalidDocumentTransitionActionError,
|
|
56
|
+
InvalidDocumentTransitionIdError,
|
|
57
|
+
DuplicateDocumentTransitionsWithIndicesError,
|
|
58
|
+
DuplicateDocumentTransitionsWithIdsError,
|
|
59
|
+
} = await loadWasmDpp());
|
|
60
|
+
|
|
61
|
+
const dataContractJs = getDataContractFixture();
|
|
62
|
+
dataContract = new DataContract(dataContractJs.toObject());
|
|
63
|
+
|
|
64
|
+
documents = getDocumentsFixture(dataContractJs);
|
|
61
65
|
ownerId = getDocumentsFixture.ownerId;
|
|
62
66
|
|
|
63
67
|
documentTransitions = getDocumentTransitionsFixture({
|
|
@@ -73,53 +77,28 @@ describe('validateDocumentsBatchTransitionBasicFactory', () => {
|
|
|
73
77
|
transitions: documentTransitions.map((t) => t.toObject()),
|
|
74
78
|
signature: Buffer.alloc(65),
|
|
75
79
|
signaturePublicKeyId: 0,
|
|
76
|
-
}, [dataContract]);
|
|
80
|
+
}, [dataContract.clone()]);
|
|
77
81
|
|
|
78
82
|
rawStateTransition = stateTransition.toObject();
|
|
79
83
|
|
|
80
|
-
findDuplicatesByIdMock = this.sinonSandbox.stub().returns([]);
|
|
81
|
-
findDuplicatesByIndicesMock = this.sinonSandbox.stub().returns([]);
|
|
82
|
-
|
|
83
|
-
const dataContractValidationResult = new ValidationResult();
|
|
84
|
-
dataContractValidationResult.setData(dataContract);
|
|
85
|
-
|
|
86
84
|
stateRepositoryMock = createStateRepositoryMock(this.sinonSandbox);
|
|
87
|
-
stateRepositoryMock.fetchDataContract.resolves(dataContract);
|
|
85
|
+
stateRepositoryMock.fetchDataContract.resolves(dataContract.clone());
|
|
88
86
|
|
|
89
|
-
|
|
90
|
-
const ajv = createAjv(RE2);
|
|
91
|
-
|
|
92
|
-
validator = new JsonSchemaValidator(ajv);
|
|
93
|
-
|
|
94
|
-
enrichSpy = this.sinonSandbox.spy(enrichDataContractWithBaseSchema);
|
|
95
|
-
|
|
96
|
-
validatePartialCompoundIndicesMock = this.sinonSandbox.stub().returns(
|
|
97
|
-
new ValidationResult(),
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
validateProtocolVersionMock = this.sinonSandbox.stub().returns(new ValidationResult());
|
|
101
|
-
|
|
102
|
-
validateDocumentsBatchTransitionBasic = validateDocumentsBatchTransitionBasicFactory(
|
|
103
|
-
findDuplicatesByIdMock,
|
|
104
|
-
findDuplicatesByIndicesMock,
|
|
105
|
-
stateRepositoryMock,
|
|
106
|
-
validator,
|
|
107
|
-
enrichSpy,
|
|
108
|
-
validatePartialCompoundIndicesMock,
|
|
109
|
-
validateProtocolVersionMock,
|
|
110
|
-
);
|
|
87
|
+
protocolVersionValidator = new ProtocolVersionValidator();
|
|
111
88
|
});
|
|
112
89
|
|
|
113
90
|
describe('protocolVersion', () => {
|
|
114
|
-
it('should be present', async () => {
|
|
91
|
+
it('should be present - Rust', async () => {
|
|
115
92
|
delete rawStateTransition.protocolVersion;
|
|
116
93
|
|
|
117
94
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
95
|
+
protocolVersionValidator,
|
|
96
|
+
stateRepositoryMock,
|
|
118
97
|
rawStateTransition,
|
|
119
98
|
executionContext,
|
|
120
99
|
);
|
|
121
100
|
|
|
122
|
-
expectJsonSchemaError(result);
|
|
101
|
+
await expectJsonSchemaError(result, 1);
|
|
123
102
|
|
|
124
103
|
const [error] = result.getErrors();
|
|
125
104
|
|
|
@@ -128,15 +107,17 @@ describe('validateDocumentsBatchTransitionBasicFactory', () => {
|
|
|
128
107
|
expect(error.getParams().missingProperty).to.equal('protocolVersion');
|
|
129
108
|
});
|
|
130
109
|
|
|
131
|
-
it('should be an integer', async () => {
|
|
110
|
+
it('should be an integer - Rust', async () => {
|
|
132
111
|
rawStateTransition.protocolVersion = '1';
|
|
133
112
|
|
|
134
113
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
114
|
+
protocolVersionValidator,
|
|
115
|
+
stateRepositoryMock,
|
|
135
116
|
rawStateTransition,
|
|
136
117
|
executionContext,
|
|
137
118
|
);
|
|
138
119
|
|
|
139
|
-
expectJsonSchemaError(result);
|
|
120
|
+
await expectJsonSchemaError(result, 1);
|
|
140
121
|
|
|
141
122
|
const [error] = result.getErrors();
|
|
142
123
|
|
|
@@ -144,43 +125,33 @@ describe('validateDocumentsBatchTransitionBasicFactory', () => {
|
|
|
144
125
|
expect(error.getKeyword()).to.equal('type');
|
|
145
126
|
});
|
|
146
127
|
|
|
147
|
-
it('should be valid', async () => {
|
|
128
|
+
it('should be valid - Rust', async () => {
|
|
148
129
|
rawStateTransition.protocolVersion = -1;
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
executionContext,
|
|
160
|
-
);
|
|
161
|
-
|
|
162
|
-
expectValidationError(result, SomeConsensusError);
|
|
163
|
-
|
|
164
|
-
const [error] = result.getErrors();
|
|
165
|
-
|
|
166
|
-
expect(error).to.equal(protocolVersionError);
|
|
167
|
-
|
|
168
|
-
expect(validateProtocolVersionMock).to.be.calledOnceWith(
|
|
169
|
-
rawStateTransition.protocolVersion,
|
|
170
|
-
);
|
|
130
|
+
try {
|
|
131
|
+
await validateDocumentsBatchTransitionBasic(
|
|
132
|
+
protocolVersionValidator,
|
|
133
|
+
stateRepositoryMock,
|
|
134
|
+
rawStateTransition,
|
|
135
|
+
executionContext,
|
|
136
|
+
);
|
|
137
|
+
} catch (e) {
|
|
138
|
+
expect(e).equal('Error conversion not implemented: unable convert -1 to u64');
|
|
139
|
+
}
|
|
171
140
|
});
|
|
172
141
|
});
|
|
173
142
|
|
|
174
143
|
describe('type', () => {
|
|
175
|
-
it('should be present', async () => {
|
|
144
|
+
it('should be present - Rust', async () => {
|
|
176
145
|
delete rawStateTransition.type;
|
|
177
146
|
|
|
178
147
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
148
|
+
protocolVersionValidator,
|
|
149
|
+
stateRepositoryMock,
|
|
179
150
|
rawStateTransition,
|
|
180
151
|
executionContext,
|
|
181
152
|
);
|
|
182
153
|
|
|
183
|
-
expectJsonSchemaError(result);
|
|
154
|
+
await expectJsonSchemaError(result, 1);
|
|
184
155
|
|
|
185
156
|
const [error] = result.getErrors();
|
|
186
157
|
|
|
@@ -189,15 +160,17 @@ describe('validateDocumentsBatchTransitionBasicFactory', () => {
|
|
|
189
160
|
expect(error.getParams().missingProperty).to.equal('type');
|
|
190
161
|
});
|
|
191
162
|
|
|
192
|
-
it('should be equal 1', async () => {
|
|
163
|
+
it('should be equal 1 - Rust', async () => {
|
|
193
164
|
rawStateTransition.type = 666;
|
|
194
165
|
|
|
195
166
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
167
|
+
protocolVersionValidator,
|
|
168
|
+
stateRepositoryMock,
|
|
196
169
|
rawStateTransition,
|
|
197
170
|
executionContext,
|
|
198
171
|
);
|
|
199
172
|
|
|
200
|
-
expectJsonSchemaError(result);
|
|
173
|
+
await expectJsonSchemaError(result, 1);
|
|
201
174
|
|
|
202
175
|
const [error] = result.getErrors();
|
|
203
176
|
|
|
@@ -208,15 +181,17 @@ describe('validateDocumentsBatchTransitionBasicFactory', () => {
|
|
|
208
181
|
});
|
|
209
182
|
|
|
210
183
|
describe('ownerId', () => {
|
|
211
|
-
it('should be present', async () => {
|
|
184
|
+
it('should be present - Rust', async () => {
|
|
212
185
|
delete rawStateTransition.ownerId;
|
|
213
186
|
|
|
214
187
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
188
|
+
protocolVersionValidator,
|
|
189
|
+
stateRepositoryMock,
|
|
215
190
|
rawStateTransition,
|
|
216
191
|
executionContext,
|
|
217
192
|
);
|
|
218
193
|
|
|
219
|
-
expectJsonSchemaError(result);
|
|
194
|
+
await expectJsonSchemaError(result, 1);
|
|
220
195
|
|
|
221
196
|
const [error] = result.getErrors();
|
|
222
197
|
|
|
@@ -225,439 +200,425 @@ describe('validateDocumentsBatchTransitionBasicFactory', () => {
|
|
|
225
200
|
expect(error.getParams().missingProperty).to.equal('ownerId');
|
|
226
201
|
});
|
|
227
202
|
|
|
228
|
-
it('should be a byte array', async () => {
|
|
203
|
+
it('should be a byte array - Rust', async () => {
|
|
229
204
|
rawStateTransition.ownerId = new Array(32).fill('string');
|
|
230
205
|
|
|
231
206
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
207
|
+
protocolVersionValidator,
|
|
208
|
+
stateRepositoryMock,
|
|
232
209
|
rawStateTransition,
|
|
233
210
|
executionContext,
|
|
234
211
|
);
|
|
235
212
|
|
|
236
|
-
expectJsonSchemaError(result,
|
|
213
|
+
await expectJsonSchemaError(result, 32);
|
|
237
214
|
|
|
238
|
-
const [error
|
|
215
|
+
const [error] = result.getErrors();
|
|
239
216
|
|
|
240
217
|
expect(error.getInstancePath()).to.equal('/ownerId/0');
|
|
241
218
|
expect(error.getKeyword()).to.equal('type');
|
|
242
|
-
|
|
243
|
-
expect(byteArrayError.getKeyword()).to.equal('byteArray');
|
|
244
219
|
});
|
|
245
220
|
|
|
246
|
-
it('should be no less than 32 bytes', async () => {
|
|
221
|
+
it('should be no less than 32 bytes - Rust', async () => {
|
|
247
222
|
rawStateTransition.ownerId = Buffer.alloc(31);
|
|
248
223
|
|
|
249
224
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
225
|
+
protocolVersionValidator,
|
|
226
|
+
stateRepositoryMock,
|
|
250
227
|
rawStateTransition,
|
|
251
228
|
executionContext,
|
|
252
229
|
);
|
|
253
230
|
|
|
254
|
-
expectJsonSchemaError(result);
|
|
231
|
+
await expectJsonSchemaError(result, 1);
|
|
255
232
|
|
|
256
233
|
const [error] = result.getErrors();
|
|
257
234
|
|
|
258
|
-
expect(error.
|
|
235
|
+
expect(error.getInstancePath()).to.equal('/ownerId');
|
|
259
236
|
expect(error.getKeyword()).to.equal('minItems');
|
|
260
237
|
});
|
|
261
238
|
|
|
262
|
-
it('should be no longer than 32 bytes', async () => {
|
|
239
|
+
it('should be no longer than 32 bytes - Rust', async () => {
|
|
263
240
|
rawStateTransition.ownerId = Buffer.alloc(33);
|
|
264
241
|
|
|
265
242
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
243
|
+
protocolVersionValidator,
|
|
244
|
+
stateRepositoryMock,
|
|
266
245
|
rawStateTransition,
|
|
267
246
|
executionContext,
|
|
268
247
|
);
|
|
269
248
|
|
|
270
|
-
expectJsonSchemaError(result);
|
|
249
|
+
await expectJsonSchemaError(result, 1);
|
|
271
250
|
|
|
272
251
|
const [error] = result.getErrors();
|
|
273
252
|
|
|
274
|
-
expect(error.
|
|
253
|
+
expect(error.getInstancePath()).to.equal('/ownerId');
|
|
275
254
|
expect(error.getKeyword()).to.equal('maxItems');
|
|
276
255
|
});
|
|
277
256
|
});
|
|
278
257
|
|
|
279
258
|
describe('document transitions', () => {
|
|
280
|
-
it('should be present', async () => {
|
|
259
|
+
it('should be present Rust', async () => {
|
|
281
260
|
delete rawStateTransition.transitions;
|
|
282
261
|
|
|
283
262
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
263
|
+
protocolVersionValidator,
|
|
264
|
+
stateRepositoryMock,
|
|
284
265
|
rawStateTransition,
|
|
285
266
|
executionContext,
|
|
286
267
|
);
|
|
287
|
-
|
|
288
|
-
expectJsonSchemaError(result);
|
|
268
|
+
await expectJsonSchemaError(result, 1);
|
|
289
269
|
|
|
290
270
|
const [error] = result.getErrors();
|
|
291
271
|
|
|
292
|
-
expect(error.
|
|
272
|
+
expect(error.getInstancePath()).to.equal('');
|
|
293
273
|
expect(error.getKeyword()).to.equal('required');
|
|
294
274
|
expect(error.getParams().missingProperty).to.equal('transitions');
|
|
295
275
|
});
|
|
296
276
|
|
|
297
|
-
it('should be an array', async () => {
|
|
277
|
+
it('should be an array - Rust', async () => {
|
|
298
278
|
rawStateTransition.transitions = {};
|
|
299
279
|
|
|
300
280
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
281
|
+
protocolVersionValidator,
|
|
282
|
+
stateRepositoryMock,
|
|
301
283
|
rawStateTransition,
|
|
302
284
|
executionContext,
|
|
303
285
|
);
|
|
304
286
|
|
|
305
|
-
expectJsonSchemaError(result);
|
|
287
|
+
await expectJsonSchemaError(result, 1);
|
|
306
288
|
|
|
307
289
|
const [error] = result.getErrors();
|
|
308
290
|
|
|
309
|
-
expect(error.
|
|
291
|
+
expect(error.getInstancePath()).to.equal('/transitions');
|
|
310
292
|
expect(error.getKeyword()).to.equal('type');
|
|
311
293
|
});
|
|
312
294
|
|
|
313
|
-
it('should have at least one element', async () => {
|
|
295
|
+
it('should have at least one element - Rust', async () => {
|
|
314
296
|
rawStateTransition.transitions = [];
|
|
315
297
|
|
|
316
298
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
299
|
+
protocolVersionValidator,
|
|
300
|
+
stateRepositoryMock,
|
|
317
301
|
rawStateTransition,
|
|
318
302
|
executionContext,
|
|
319
303
|
);
|
|
320
304
|
|
|
321
|
-
expectJsonSchemaError(result);
|
|
305
|
+
await expectJsonSchemaError(result, 1);
|
|
322
306
|
|
|
323
307
|
const [error] = result.getErrors();
|
|
324
308
|
|
|
325
|
-
expect(error.
|
|
309
|
+
expect(error.getInstancePath()).to.equal('/transitions');
|
|
326
310
|
expect(error.getKeyword()).to.equal('minItems');
|
|
327
|
-
expect(error.getParams().
|
|
311
|
+
expect(error.getParams().minItems).to.equal(1);
|
|
328
312
|
});
|
|
329
313
|
|
|
330
|
-
it('should have no more than 10 elements', async () => {
|
|
314
|
+
it('should have no more than 10 elements - Rust', async () => {
|
|
331
315
|
rawStateTransition.transitions = Array(11).fill({});
|
|
332
316
|
|
|
333
317
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
318
|
+
protocolVersionValidator,
|
|
319
|
+
stateRepositoryMock,
|
|
334
320
|
rawStateTransition,
|
|
335
321
|
executionContext,
|
|
336
322
|
);
|
|
337
323
|
|
|
338
|
-
expectJsonSchemaError(result);
|
|
324
|
+
await expectJsonSchemaError(result, 1);
|
|
339
325
|
|
|
340
326
|
const [error] = result.getErrors();
|
|
341
327
|
|
|
342
|
-
expect(error.
|
|
328
|
+
expect(error.getInstancePath()).to.equal('/transitions');
|
|
343
329
|
expect(error.getKeyword()).to.equal('maxItems');
|
|
344
|
-
expect(error.getParams().
|
|
330
|
+
expect(error.getParams().maxItems).to.equal(10);
|
|
345
331
|
});
|
|
346
332
|
|
|
347
|
-
it('should have objects as elements', async () => {
|
|
333
|
+
it('should have objects as elements - Rust', async () => {
|
|
348
334
|
rawStateTransition.transitions = [1];
|
|
349
335
|
|
|
350
336
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
337
|
+
protocolVersionValidator,
|
|
338
|
+
stateRepositoryMock,
|
|
351
339
|
rawStateTransition,
|
|
352
340
|
executionContext,
|
|
353
341
|
);
|
|
354
342
|
|
|
355
|
-
expectJsonSchemaError(result);
|
|
343
|
+
await expectJsonSchemaError(result, 1);
|
|
356
344
|
|
|
357
345
|
const [error] = result.getErrors();
|
|
358
346
|
|
|
359
|
-
expect(error.
|
|
347
|
+
expect(error.getInstancePath()).to.equal('/transitions/0');
|
|
360
348
|
expect(error.getKeyword()).to.equal('type');
|
|
361
349
|
});
|
|
362
350
|
|
|
363
351
|
describe('document transition', () => {
|
|
364
352
|
describe('$id', () => {
|
|
365
|
-
it('should be present', async () => {
|
|
353
|
+
it('should be present - Rust', async () => {
|
|
366
354
|
const [documentTransition] = rawStateTransition.transitions;
|
|
367
|
-
|
|
368
355
|
delete documentTransition.$id;
|
|
369
356
|
|
|
370
357
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
358
|
+
protocolVersionValidator,
|
|
359
|
+
stateRepositoryMock,
|
|
371
360
|
rawStateTransition,
|
|
372
361
|
executionContext,
|
|
373
362
|
);
|
|
374
363
|
|
|
375
|
-
expectJsonSchemaError(result);
|
|
364
|
+
await expectJsonSchemaError(result, 1);
|
|
376
365
|
|
|
377
366
|
const [error] = result.getErrors();
|
|
378
367
|
|
|
379
|
-
expect(error.
|
|
368
|
+
expect(error.getInstancePath()).to.equal('');
|
|
380
369
|
expect(error.getKeyword()).to.equal('required');
|
|
381
370
|
expect(error.getParams().missingProperty).to.equal('$id');
|
|
382
371
|
});
|
|
383
372
|
|
|
384
|
-
it('should be a byte array', async () => {
|
|
373
|
+
it('should be a byte array - Rust', async () => {
|
|
385
374
|
const [documentTransition] = rawStateTransition.transitions;
|
|
386
375
|
|
|
387
376
|
documentTransition.$id = new Array(32).fill('string');
|
|
388
377
|
|
|
389
378
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
379
|
+
protocolVersionValidator,
|
|
380
|
+
stateRepositoryMock,
|
|
390
381
|
rawStateTransition,
|
|
391
382
|
executionContext,
|
|
392
383
|
);
|
|
393
384
|
|
|
394
|
-
expectJsonSchemaError(result,
|
|
385
|
+
await expectJsonSchemaError(result, 32);
|
|
395
386
|
|
|
396
|
-
const [error
|
|
387
|
+
const [error] = result.getErrors();
|
|
397
388
|
|
|
398
|
-
expect(error.
|
|
389
|
+
expect(error.getInstancePath()).to.equal('/$id/0');
|
|
399
390
|
expect(error.getKeyword()).to.equal('type');
|
|
400
|
-
|
|
401
|
-
expect(byteArrayError.getKeyword()).to.equal('byteArray');
|
|
402
391
|
});
|
|
403
392
|
|
|
404
|
-
it('should be no less than 32 bytes', async () => {
|
|
393
|
+
it('should be no less than 32 bytes - Rust', async () => {
|
|
405
394
|
const [documentTransition] = rawStateTransition.transitions;
|
|
406
395
|
|
|
407
396
|
documentTransition.$id = Buffer.alloc(31);
|
|
408
397
|
|
|
409
398
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
399
|
+
protocolVersionValidator,
|
|
400
|
+
stateRepositoryMock,
|
|
410
401
|
rawStateTransition,
|
|
411
402
|
executionContext,
|
|
412
403
|
);
|
|
413
404
|
|
|
414
|
-
expectJsonSchemaError(result);
|
|
405
|
+
await expectJsonSchemaError(result);
|
|
415
406
|
|
|
416
407
|
const [error] = result.getErrors();
|
|
417
408
|
|
|
418
|
-
expect(error.
|
|
409
|
+
expect(error.getInstancePath()).to.equal('/$id');
|
|
419
410
|
expect(error.getKeyword()).to.equal('minItems');
|
|
420
|
-
expect(error.getParams().
|
|
411
|
+
expect(error.getParams().minItems).to.equal(32);
|
|
421
412
|
});
|
|
422
413
|
|
|
423
|
-
it('should be no longer than 32 bytes', async () => {
|
|
414
|
+
it('should be no longer than 32 bytes - Rust', async () => {
|
|
424
415
|
const [documentTransition] = rawStateTransition.transitions;
|
|
425
416
|
|
|
426
417
|
documentTransition.$id = Buffer.alloc(33);
|
|
427
418
|
|
|
428
419
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
420
|
+
protocolVersionValidator,
|
|
421
|
+
stateRepositoryMock,
|
|
429
422
|
rawStateTransition,
|
|
430
423
|
executionContext,
|
|
431
424
|
);
|
|
432
|
-
|
|
433
|
-
expectJsonSchemaError(result);
|
|
425
|
+
await expectJsonSchemaError(result);
|
|
434
426
|
|
|
435
427
|
const [error] = result.getErrors();
|
|
436
428
|
|
|
437
|
-
expect(error.
|
|
429
|
+
expect(error.getInstancePath()).to.equal('/$id');
|
|
438
430
|
expect(error.getKeyword()).to.equal('maxItems');
|
|
439
|
-
expect(error.getParams().
|
|
431
|
+
expect(error.getParams().maxItems).to.equal(32);
|
|
440
432
|
});
|
|
441
433
|
|
|
442
|
-
it('should no have duplicate IDs in the state transition', async () => {
|
|
443
|
-
const
|
|
434
|
+
it('should no have duplicate IDs in the state transition - Rust', async () => {
|
|
435
|
+
const [documentTransition] = documentTransitions.map((t) => t.toObject());
|
|
436
|
+
|
|
437
|
+
stateTransition = new DocumentsBatchTransition({
|
|
438
|
+
protocolVersion: protocolVersion.latestVersion,
|
|
439
|
+
ownerId,
|
|
440
|
+
contractId: dataContract.getId(),
|
|
441
|
+
transitions: [documentTransition, documentTransition],
|
|
442
|
+
signature: Buffer.alloc(65),
|
|
443
|
+
signaturePublicKeyId: 0,
|
|
444
|
+
}, [dataContract.clone()]);
|
|
444
445
|
|
|
445
|
-
|
|
446
|
+
rawStateTransition = stateTransition.toObject();
|
|
446
447
|
|
|
447
448
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
449
|
+
protocolVersionValidator,
|
|
450
|
+
stateRepositoryMock,
|
|
448
451
|
rawStateTransition,
|
|
449
452
|
executionContext,
|
|
450
453
|
);
|
|
451
454
|
|
|
452
|
-
expectValidationError(result, DuplicateDocumentTransitionsWithIdsError);
|
|
455
|
+
await expectValidationError(result, DuplicateDocumentTransitionsWithIdsError);
|
|
453
456
|
|
|
454
457
|
const [error] = result.getErrors();
|
|
455
458
|
|
|
456
459
|
expect(error.getCode()).to.equal(1019);
|
|
457
|
-
expect(error.getDocumentTransitionReferences()).to.deep.equal(
|
|
458
|
-
duplicates.map((d) => [d.$type, d.$id]),
|
|
459
|
-
);
|
|
460
460
|
|
|
461
|
-
expect(stateRepositoryMock.fetchDataContract).to.have.been.
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
);
|
|
465
|
-
expect(enrichSpy).to.have.been.calledThrice();
|
|
466
|
-
expect(findDuplicatesByIdMock).to.have.been.calledOnceWithExactly(
|
|
467
|
-
rawStateTransition.transitions,
|
|
468
|
-
);
|
|
469
|
-
expect(findDuplicatesByIndicesMock).to.have.been.calledOnceWithExactly(
|
|
470
|
-
rawStateTransition.transitions, dataContract,
|
|
471
|
-
);
|
|
461
|
+
expect(stateRepositoryMock.fetchDataContract).to.have.been.calledOnce();
|
|
462
|
+
const [fetchDataContractId] = stateRepositoryMock.fetchDataContract.getCall(0).args;
|
|
463
|
+
expect(fetchDataContractId.toBuffer()).is.deep.equal(dataContract.getId().toBuffer());
|
|
472
464
|
});
|
|
473
465
|
});
|
|
474
466
|
|
|
475
467
|
describe('$dataContractId', () => {
|
|
476
|
-
it('should be present', async () => {
|
|
468
|
+
it('should be present - Rust', async () => {
|
|
477
469
|
const [firstDocumentTransition] = rawStateTransition.transitions;
|
|
478
470
|
|
|
479
471
|
delete firstDocumentTransition.$dataContractId;
|
|
480
472
|
|
|
481
473
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
474
|
+
protocolVersionValidator,
|
|
475
|
+
stateRepositoryMock,
|
|
482
476
|
rawStateTransition,
|
|
483
477
|
executionContext,
|
|
484
478
|
);
|
|
485
479
|
|
|
486
|
-
expectValidationError(result, MissingDataContractIdError);
|
|
480
|
+
await expectValidationError(result, MissingDataContractIdError);
|
|
487
481
|
|
|
488
482
|
const [error] = result.getErrors();
|
|
489
|
-
|
|
490
483
|
expect(error.getCode()).to.equal(1025);
|
|
491
484
|
|
|
492
|
-
expect(stateRepositoryMock.fetchDataContract).to.have.been.
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
);
|
|
496
|
-
|
|
497
|
-
expect(enrichSpy).to.have.been.calledThrice();
|
|
498
|
-
|
|
499
|
-
expect(findDuplicatesByIdMock).to.have.been.calledOnceWithExactly(
|
|
500
|
-
rawStateTransition.transitions.slice(1),
|
|
501
|
-
);
|
|
502
|
-
expect(findDuplicatesByIndicesMock).to.have.been.calledOnceWithExactly(
|
|
503
|
-
rawStateTransition.transitions.slice(1), dataContract,
|
|
504
|
-
);
|
|
485
|
+
expect(stateRepositoryMock.fetchDataContract).to.have.been.calledOnce();
|
|
486
|
+
const [fetchDataContractId] = stateRepositoryMock.fetchDataContract.getCall(0).args;
|
|
487
|
+
expect(fetchDataContractId.toBuffer()).is.deep.equal(dataContract.getId().toBuffer());
|
|
505
488
|
});
|
|
506
489
|
|
|
507
|
-
it('should be a byte array', async () => {
|
|
490
|
+
it('should be a byte array - Rust', async () => {
|
|
508
491
|
const [firstDocumentTransition] = rawStateTransition.transitions;
|
|
509
492
|
|
|
510
|
-
firstDocumentTransition.$dataContractId =
|
|
493
|
+
firstDocumentTransition.$dataContractId = Buffer.alloc(2);
|
|
511
494
|
|
|
512
495
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
496
|
+
protocolVersionValidator,
|
|
497
|
+
stateRepositoryMock,
|
|
513
498
|
rawStateTransition,
|
|
514
499
|
executionContext,
|
|
515
500
|
);
|
|
516
501
|
|
|
517
|
-
expectValidationError(result, InvalidIdentifierError);
|
|
502
|
+
await expectValidationError(result, InvalidIdentifierError);
|
|
518
503
|
|
|
519
504
|
const [error] = result.getErrors();
|
|
520
505
|
|
|
521
506
|
expect(error.getCode()).to.equal(1006);
|
|
522
507
|
|
|
523
508
|
expect(error.getIdentifierName()).to.equal('$dataContractId');
|
|
509
|
+
expect(error.getIdentifierError()).to.equal('Identifier Error: Identifier must be 32 bytes long');
|
|
524
510
|
|
|
525
|
-
expect(
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
expect(stateRepositoryMock.fetchDataContract).to.have.been.calledOnceWithExactly(
|
|
529
|
-
dataContract.getId(),
|
|
530
|
-
executionContext,
|
|
531
|
-
);
|
|
532
|
-
|
|
533
|
-
expect(enrichSpy).to.have.been.calledThrice();
|
|
534
|
-
|
|
535
|
-
expect(findDuplicatesByIdMock).to.have.been.calledOnceWithExactly(
|
|
536
|
-
rawStateTransition.transitions.slice(1),
|
|
537
|
-
);
|
|
538
|
-
expect(findDuplicatesByIndicesMock).to.have.been.calledOnceWithExactly(
|
|
539
|
-
rawStateTransition.transitions.slice(1), dataContract,
|
|
540
|
-
);
|
|
511
|
+
expect(stateRepositoryMock.fetchDataContract).to.have.been.calledOnce();
|
|
512
|
+
const [fetchDataContractId] = stateRepositoryMock.fetchDataContract.getCall(0).args;
|
|
513
|
+
expect(fetchDataContractId.toBuffer()).is.deep.equal(dataContract.getId().toBuffer());
|
|
541
514
|
});
|
|
542
515
|
|
|
543
|
-
it('should exists in the state', async () => {
|
|
516
|
+
it('should exists in the state - Rust', async () => {
|
|
544
517
|
stateRepositoryMock.fetchDataContract.resolves(undefined);
|
|
545
518
|
|
|
546
519
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
520
|
+
protocolVersionValidator,
|
|
521
|
+
stateRepositoryMock,
|
|
547
522
|
rawStateTransition,
|
|
548
523
|
executionContext,
|
|
549
524
|
);
|
|
550
525
|
|
|
551
|
-
expectValidationError(result, DataContractNotPresentError);
|
|
526
|
+
await expectValidationError(result, DataContractNotPresentError);
|
|
552
527
|
|
|
553
528
|
const [error] = result.getErrors();
|
|
554
529
|
|
|
555
530
|
expect(error.getCode()).to.equal(1018);
|
|
556
|
-
expect(error.getDataContractId()).to.deep.equal(dataContract.getId());
|
|
557
|
-
|
|
558
|
-
expect(stateRepositoryMock.fetchDataContract).to.have.been.calledOnceWithExactly(
|
|
559
|
-
dataContract.getId(),
|
|
560
|
-
executionContext,
|
|
561
|
-
);
|
|
531
|
+
expect(error.getDataContractId()).to.deep.equal(dataContract.getId().toBuffer());
|
|
562
532
|
|
|
563
|
-
expect(
|
|
564
|
-
|
|
565
|
-
expect(
|
|
533
|
+
expect(stateRepositoryMock.fetchDataContract).to.have.been.calledOnce();
|
|
534
|
+
const [fetchDataContractId] = stateRepositoryMock.fetchDataContract.getCall(0).args;
|
|
535
|
+
expect(fetchDataContractId.toBuffer()).is.deep.equal(dataContract.getId().toBuffer());
|
|
566
536
|
});
|
|
567
537
|
});
|
|
568
538
|
|
|
569
539
|
describe('$type', () => {
|
|
570
|
-
it('should be present', async () => {
|
|
540
|
+
it('should be present - Rust', async () => {
|
|
571
541
|
const [firstDocumentTransition] = rawStateTransition.transitions;
|
|
572
542
|
|
|
573
543
|
delete firstDocumentTransition.$type;
|
|
574
544
|
|
|
575
545
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
546
|
+
protocolVersionValidator,
|
|
547
|
+
stateRepositoryMock,
|
|
576
548
|
rawStateTransition,
|
|
577
549
|
executionContext,
|
|
578
550
|
);
|
|
579
|
-
|
|
580
|
-
expectValidationError(result, MissingDocumentTransitionTypeError);
|
|
551
|
+
await expectValidationError(result, MissingDocumentTransitionTypeError);
|
|
581
552
|
|
|
582
553
|
const [error] = result.getErrors();
|
|
583
554
|
|
|
584
555
|
expect(error.getCode()).to.equal(1027);
|
|
585
556
|
|
|
586
|
-
expect(stateRepositoryMock.fetchDataContract).to.have.been.
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
);
|
|
590
|
-
|
|
591
|
-
expect(enrichSpy).to.have.been.calledThrice();
|
|
592
|
-
expect(findDuplicatesByIdMock).to.have.not.been.called();
|
|
593
|
-
expect(findDuplicatesByIndicesMock).to.have.not.been.called();
|
|
557
|
+
expect(stateRepositoryMock.fetchDataContract).to.have.been.calledOnce();
|
|
558
|
+
const [fetchDataContractId] = stateRepositoryMock.fetchDataContract.getCall(0).args;
|
|
559
|
+
expect(fetchDataContractId.toBuffer()).is.deep.equal(dataContract.getId().toBuffer());
|
|
594
560
|
});
|
|
595
561
|
|
|
596
|
-
it('should be defined in Data Contract', async () => {
|
|
562
|
+
it('should be defined in Data Contract - Rust', async () => {
|
|
597
563
|
const [firstDocumentTransition] = rawStateTransition.transitions;
|
|
598
564
|
|
|
599
565
|
firstDocumentTransition.$type = 'wrong';
|
|
600
566
|
|
|
601
567
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
568
|
+
protocolVersionValidator,
|
|
569
|
+
stateRepositoryMock,
|
|
602
570
|
rawStateTransition,
|
|
603
571
|
executionContext,
|
|
604
572
|
);
|
|
605
573
|
|
|
606
|
-
expectValidationError(result, InvalidDocumentTypeError);
|
|
574
|
+
await expectValidationError(result, InvalidDocumentTypeError);
|
|
607
575
|
|
|
608
576
|
const [error] = result.getErrors();
|
|
609
577
|
|
|
610
578
|
expect(error.getCode()).to.equal(1024);
|
|
611
579
|
expect(error.getType()).to.equal(firstDocumentTransition.$type);
|
|
612
580
|
|
|
613
|
-
expect(Buffer.isBuffer(error.getDataContractId())).to.be.true();
|
|
614
581
|
expect(error.getDataContractId()).to.deep.equal(dataContract.getId().toBuffer());
|
|
615
582
|
|
|
616
|
-
expect(stateRepositoryMock.fetchDataContract).to.have.been.
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
);
|
|
620
|
-
|
|
621
|
-
expect(enrichSpy).to.have.been.calledThrice();
|
|
622
|
-
expect(findDuplicatesByIdMock).to.have.not.been.called();
|
|
623
|
-
expect(findDuplicatesByIndicesMock).to.have.not.been.called();
|
|
583
|
+
expect(stateRepositoryMock.fetchDataContract).to.have.been.calledOnce();
|
|
584
|
+
const [fetchDataContractId] = stateRepositoryMock.fetchDataContract.getCall(0).args;
|
|
585
|
+
expect(fetchDataContractId.toBuffer()).is.deep.equal(dataContract.getId().toBuffer());
|
|
624
586
|
});
|
|
625
587
|
});
|
|
626
588
|
|
|
627
589
|
describe('$action', () => {
|
|
628
|
-
it('should be present', async () => {
|
|
590
|
+
it('should be present - Rust', async () => {
|
|
629
591
|
const [firstDocumentTransition] = rawStateTransition.transitions;
|
|
630
592
|
|
|
631
593
|
delete firstDocumentTransition.$action;
|
|
632
594
|
|
|
633
595
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
596
|
+
protocolVersionValidator,
|
|
597
|
+
stateRepositoryMock,
|
|
634
598
|
rawStateTransition,
|
|
635
599
|
executionContext,
|
|
636
600
|
);
|
|
637
601
|
|
|
638
|
-
expectValidationError(result, MissingDocumentTransitionActionError);
|
|
602
|
+
await expectValidationError(result, MissingDocumentTransitionActionError);
|
|
639
603
|
|
|
640
604
|
const [error] = result.getErrors();
|
|
641
605
|
|
|
642
606
|
expect(error.getCode()).to.equal(1026);
|
|
643
607
|
|
|
644
|
-
expect(stateRepositoryMock.fetchDataContract).to.have.been.
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
);
|
|
648
|
-
|
|
649
|
-
expect(enrichSpy).to.have.been.calledThrice();
|
|
650
|
-
expect(findDuplicatesByIdMock).to.have.not.been.called();
|
|
651
|
-
expect(findDuplicatesByIndicesMock).to.have.not.been.called();
|
|
608
|
+
expect(stateRepositoryMock.fetchDataContract).to.have.been.calledOnce();
|
|
609
|
+
const [fetchDataContractId] = stateRepositoryMock.fetchDataContract.getCall(0).args;
|
|
610
|
+
expect(fetchDataContractId.toBuffer()).is.deep.equal(dataContract.getId().toBuffer());
|
|
652
611
|
});
|
|
653
612
|
|
|
654
|
-
it('should throw InvalidDocumentTransitionActionError if action is not valid', async () => {
|
|
613
|
+
it('should throw InvalidDocumentTransitionActionError if action is not valid - Rust', async () => {
|
|
655
614
|
const [firstDocumentTransition] = rawStateTransition.transitions;
|
|
656
615
|
|
|
657
616
|
firstDocumentTransition.$action = 4;
|
|
658
617
|
|
|
659
618
|
try {
|
|
660
619
|
await validateDocumentsBatchTransitionBasic(
|
|
620
|
+
protocolVersionValidator,
|
|
621
|
+
stateRepositoryMock,
|
|
661
622
|
rawStateTransition,
|
|
662
623
|
executionContext,
|
|
663
624
|
);
|
|
@@ -666,130 +627,126 @@ describe('validateDocumentsBatchTransitionBasicFactory', () => {
|
|
|
666
627
|
expect(e.getAction()).to.equal(firstDocumentTransition.$action);
|
|
667
628
|
expect(e.getRawDocumentTransition()).to.deep.equal(firstDocumentTransition);
|
|
668
629
|
|
|
669
|
-
expect(stateRepositoryMock.fetchDataContract).to.have.been.
|
|
670
|
-
|
|
671
|
-
);
|
|
672
|
-
|
|
673
|
-
expect(enrichSpy).to.have.been.calledThrice();
|
|
674
|
-
expect(findDuplicatesByIdMock).to.have.not.been.called();
|
|
675
|
-
expect(findDuplicatesByIndicesMock).to.have.not.been.called();
|
|
630
|
+
expect(stateRepositoryMock.fetchDataContract).to.have.been.calledOnce();
|
|
631
|
+
const [fetchDataContractId] = stateRepositoryMock.fetchDataContract.getCall(0).args;
|
|
632
|
+
expect(fetchDataContractId.toBuffer()).is.deep.equal(dataContract.getId().toBuffer());
|
|
676
633
|
}
|
|
677
634
|
});
|
|
678
635
|
});
|
|
679
636
|
|
|
680
637
|
describe('create', () => {
|
|
681
638
|
describe('$id', () => {
|
|
682
|
-
it('should be valid generated ID', async () => {
|
|
639
|
+
it('should be valid generated ID - Rust', async () => {
|
|
683
640
|
const [firstTransition] = rawStateTransition.transitions;
|
|
684
641
|
|
|
685
642
|
const expectedId = firstTransition.$id;
|
|
686
|
-
firstTransition.$id = generateRandomIdentifier();
|
|
643
|
+
firstTransition.$id = generateRandomIdentifier().toBuffer();
|
|
687
644
|
|
|
688
645
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
646
|
+
protocolVersionValidator,
|
|
647
|
+
stateRepositoryMock,
|
|
689
648
|
rawStateTransition,
|
|
690
649
|
executionContext,
|
|
691
650
|
);
|
|
692
651
|
|
|
693
|
-
expectValidationError(result, InvalidDocumentTransitionIdError);
|
|
694
|
-
|
|
695
652
|
const [error] = result.getErrors();
|
|
653
|
+
console.log(error.toString());
|
|
654
|
+
|
|
655
|
+
await expectValidationError(result, InvalidDocumentTransitionIdError);
|
|
696
656
|
|
|
697
657
|
expect(error.getCode()).to.equal(1023);
|
|
698
658
|
|
|
699
|
-
expect(Buffer.isBuffer(error.getExpectedId())).to.be.true();
|
|
700
659
|
expect(error.getExpectedId()).to.deep.equal(expectedId);
|
|
701
|
-
|
|
702
|
-
expect(Buffer.isBuffer(error.getInvalidId())).to.be.true();
|
|
703
660
|
expect(error.getInvalidId()).to.deep.equal(firstTransition.$id);
|
|
704
661
|
|
|
705
|
-
expect(stateRepositoryMock.fetchDataContract).to.have.been.
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
);
|
|
709
|
-
|
|
710
|
-
expect(enrichSpy).to.have.been.calledThrice();
|
|
711
|
-
|
|
712
|
-
expect(findDuplicatesByIdMock).to.have.not.been.called();
|
|
713
|
-
expect(findDuplicatesByIndicesMock).to.have.not.been.called();
|
|
662
|
+
expect(stateRepositoryMock.fetchDataContract).to.have.been.calledOnce();
|
|
663
|
+
const [fetchDataContractId] = stateRepositoryMock.fetchDataContract.getCall(0).args;
|
|
664
|
+
expect(fetchDataContractId.toBuffer()).is.deep.equal(dataContract.getId().toBuffer());
|
|
714
665
|
});
|
|
715
666
|
});
|
|
716
667
|
|
|
717
668
|
describe('$entropy', () => {
|
|
718
|
-
it('should be present', async () => {
|
|
669
|
+
it('should be present - Rust', async () => {
|
|
719
670
|
const [documentTransition] = rawStateTransition.transitions;
|
|
720
671
|
|
|
721
672
|
delete documentTransition.$entropy;
|
|
722
673
|
|
|
723
674
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
675
|
+
protocolVersionValidator,
|
|
676
|
+
stateRepositoryMock,
|
|
724
677
|
rawStateTransition,
|
|
725
678
|
executionContext,
|
|
726
679
|
);
|
|
727
680
|
|
|
728
|
-
expectJsonSchemaError(result);
|
|
681
|
+
await expectJsonSchemaError(result);
|
|
729
682
|
|
|
730
683
|
const [error] = result.getErrors();
|
|
731
684
|
|
|
732
|
-
expect(error.
|
|
685
|
+
expect(error.getInstancePath()).to.equal('');
|
|
733
686
|
expect(error.getKeyword()).to.equal('required');
|
|
734
687
|
expect(error.getParams().missingProperty).to.equal('$entropy');
|
|
735
688
|
});
|
|
736
689
|
|
|
737
|
-
it('should be a byte array', async () => {
|
|
690
|
+
it('should be a byte array - Rust', async () => {
|
|
738
691
|
const [documentTransition] = rawStateTransition.transitions;
|
|
739
692
|
|
|
740
693
|
documentTransition.$entropy = new Array(32).fill('string');
|
|
741
694
|
|
|
742
695
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
696
|
+
protocolVersionValidator,
|
|
697
|
+
stateRepositoryMock,
|
|
743
698
|
rawStateTransition,
|
|
744
699
|
executionContext,
|
|
745
700
|
);
|
|
746
701
|
|
|
747
|
-
expectJsonSchemaError(result,
|
|
702
|
+
await expectJsonSchemaError(result, 32);
|
|
748
703
|
|
|
749
|
-
const [error
|
|
704
|
+
const [error] = result.getErrors();
|
|
750
705
|
|
|
751
|
-
expect(error.
|
|
706
|
+
expect(error.getInstancePath()).to.equal('/$entropy/0');
|
|
752
707
|
expect(error.getKeyword()).to.equal('type');
|
|
753
|
-
|
|
754
|
-
expect(byteArrayError.getKeyword()).to.equal('byteArray');
|
|
755
708
|
});
|
|
756
709
|
|
|
757
|
-
it('should be no less than 32 bytes', async () => {
|
|
710
|
+
it('should be no less than 32 bytes - Rust', async () => {
|
|
758
711
|
const [documentTransition] = rawStateTransition.transitions;
|
|
759
712
|
|
|
760
713
|
documentTransition.$entropy = Buffer.alloc(31);
|
|
761
714
|
|
|
762
715
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
716
|
+
protocolVersionValidator,
|
|
717
|
+
stateRepositoryMock,
|
|
763
718
|
rawStateTransition,
|
|
764
719
|
executionContext,
|
|
765
720
|
);
|
|
766
721
|
|
|
767
|
-
expectJsonSchemaError(result);
|
|
722
|
+
await expectJsonSchemaError(result);
|
|
768
723
|
|
|
769
724
|
const [error] = result.getErrors();
|
|
770
725
|
|
|
771
|
-
expect(error.
|
|
726
|
+
expect(error.getInstancePath()).to.equal('/$entropy');
|
|
772
727
|
expect(error.getKeyword()).to.equal('minItems');
|
|
773
|
-
expect(error.getParams().
|
|
728
|
+
expect(error.getParams().minItems).to.equal(32);
|
|
774
729
|
});
|
|
775
730
|
|
|
776
|
-
it('should be no longer than 32 bytes', async () => {
|
|
731
|
+
it('should be no longer than 32 bytes - Rust', async () => {
|
|
777
732
|
const [documentTransition] = rawStateTransition.transitions;
|
|
778
733
|
|
|
779
734
|
documentTransition.$entropy = Buffer.alloc(33);
|
|
780
735
|
|
|
781
736
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
737
|
+
protocolVersionValidator,
|
|
738
|
+
stateRepositoryMock,
|
|
782
739
|
rawStateTransition,
|
|
783
740
|
executionContext,
|
|
784
741
|
);
|
|
785
742
|
|
|
786
|
-
expectJsonSchemaError(result);
|
|
743
|
+
await expectJsonSchemaError(result);
|
|
787
744
|
|
|
788
745
|
const [error] = result.getErrors();
|
|
789
746
|
|
|
790
|
-
expect(error.
|
|
747
|
+
expect(error.getInstancePath()).to.equal('/$entropy');
|
|
791
748
|
expect(error.getKeyword()).to.equal('maxItems');
|
|
792
|
-
expect(error.getParams().
|
|
749
|
+
expect(error.getParams().maxItems).to.equal(32);
|
|
793
750
|
});
|
|
794
751
|
});
|
|
795
752
|
});
|
|
@@ -808,23 +765,25 @@ describe('validateDocumentsBatchTransitionBasicFactory', () => {
|
|
|
808
765
|
transitions: documentTransitions.map((t) => t.toObject()),
|
|
809
766
|
signature: Buffer.alloc(65),
|
|
810
767
|
signaturePublicKeyId: 0,
|
|
811
|
-
}, [dataContract]);
|
|
768
|
+
}, [dataContract.clone()]);
|
|
812
769
|
|
|
813
770
|
rawStateTransition = stateTransition.toObject();
|
|
814
771
|
});
|
|
815
772
|
|
|
816
773
|
describe('$revision', () => {
|
|
817
|
-
it('should be present', async () => {
|
|
774
|
+
it('should be present - Rust', async () => {
|
|
818
775
|
const [documentTransition] = rawStateTransition.transitions;
|
|
819
776
|
|
|
820
777
|
delete documentTransition.$revision;
|
|
821
778
|
|
|
822
779
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
780
|
+
protocolVersionValidator,
|
|
781
|
+
stateRepositoryMock,
|
|
823
782
|
rawStateTransition,
|
|
824
783
|
executionContext,
|
|
825
784
|
);
|
|
826
785
|
|
|
827
|
-
expectJsonSchemaError(result);
|
|
786
|
+
await expectJsonSchemaError(result);
|
|
828
787
|
|
|
829
788
|
const [error] = result.getErrors();
|
|
830
789
|
|
|
@@ -832,57 +791,63 @@ describe('validateDocumentsBatchTransitionBasicFactory', () => {
|
|
|
832
791
|
expect(error.getKeyword()).to.equal('required');
|
|
833
792
|
});
|
|
834
793
|
|
|
835
|
-
it('should be a number', async () => {
|
|
794
|
+
it('should be a number - Rust', async () => {
|
|
836
795
|
const [documentTransition] = rawStateTransition.transitions;
|
|
837
796
|
|
|
838
797
|
documentTransition.$revision = '1';
|
|
839
798
|
|
|
840
799
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
800
|
+
protocolVersionValidator,
|
|
801
|
+
stateRepositoryMock,
|
|
841
802
|
rawStateTransition,
|
|
842
803
|
executionContext,
|
|
843
804
|
);
|
|
844
805
|
|
|
845
|
-
expectJsonSchemaError(result);
|
|
806
|
+
await expectJsonSchemaError(result);
|
|
846
807
|
|
|
847
808
|
const [error] = result.getErrors();
|
|
848
809
|
|
|
849
|
-
expect(error.
|
|
810
|
+
expect(error.getInstancePath()).to.equal('/$revision');
|
|
850
811
|
expect(error.getKeyword()).to.equal('type');
|
|
851
812
|
});
|
|
852
813
|
|
|
853
|
-
it('should be multiple of 1.0', async () => {
|
|
814
|
+
it('should be multiple of 1.0 - Rust', async () => {
|
|
854
815
|
const [documentTransition] = rawStateTransition.transitions;
|
|
855
816
|
|
|
856
817
|
documentTransition.$revision = 1.2;
|
|
857
818
|
|
|
858
819
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
820
|
+
protocolVersionValidator,
|
|
821
|
+
stateRepositoryMock,
|
|
859
822
|
rawStateTransition,
|
|
860
823
|
executionContext,
|
|
861
824
|
);
|
|
862
825
|
|
|
863
|
-
expectJsonSchemaError(result);
|
|
826
|
+
await expectJsonSchemaError(result);
|
|
864
827
|
|
|
865
828
|
const [error] = result.getErrors();
|
|
866
829
|
|
|
867
|
-
expect(error.
|
|
830
|
+
expect(error.getInstancePath()).to.equal('/$revision');
|
|
868
831
|
expect(error.getKeyword()).to.equal('type');
|
|
869
832
|
});
|
|
870
833
|
|
|
871
|
-
it('should have a minimum value of 1', async () => {
|
|
834
|
+
it('should have a minimum value of 1 - Rust', async () => {
|
|
872
835
|
const [documentTransition] = rawStateTransition.transitions;
|
|
873
836
|
|
|
874
837
|
documentTransition.$revision = 0;
|
|
875
838
|
|
|
876
839
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
840
|
+
protocolVersionValidator,
|
|
841
|
+
stateRepositoryMock,
|
|
877
842
|
rawStateTransition,
|
|
878
843
|
executionContext,
|
|
879
844
|
);
|
|
880
845
|
|
|
881
|
-
expectJsonSchemaError(result);
|
|
846
|
+
await expectJsonSchemaError(result);
|
|
882
847
|
|
|
883
848
|
const [error] = result.getErrors();
|
|
884
849
|
|
|
885
|
-
expect(error.
|
|
850
|
+
expect(error.getInstancePath()).to.equal('/$revision');
|
|
886
851
|
expect(error.getKeyword()).to.equal('minimum');
|
|
887
852
|
});
|
|
888
853
|
});
|
|
@@ -903,22 +868,24 @@ describe('validateDocumentsBatchTransitionBasicFactory', () => {
|
|
|
903
868
|
transitions: documentTransitions.map((t) => t.toObject()),
|
|
904
869
|
signature: Buffer.alloc(65),
|
|
905
870
|
signaturePublicKeyId: 0,
|
|
906
|
-
}, [dataContract]);
|
|
871
|
+
}, [dataContract.clone()]);
|
|
907
872
|
|
|
908
873
|
rawStateTransition = stateTransition.toObject();
|
|
909
874
|
});
|
|
910
875
|
|
|
911
|
-
it('should return invalid result if delete transaction is not valid', async () => {
|
|
876
|
+
it('should return invalid result if delete transaction is not valid - Rust', async () => {
|
|
912
877
|
const [documentTransition] = rawStateTransition.transitions;
|
|
913
878
|
|
|
914
879
|
delete documentTransition.$id;
|
|
915
880
|
|
|
916
881
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
882
|
+
protocolVersionValidator,
|
|
883
|
+
stateRepositoryMock,
|
|
917
884
|
rawStateTransition,
|
|
918
885
|
executionContext,
|
|
919
886
|
);
|
|
920
887
|
|
|
921
|
-
expectJsonSchemaError(result);
|
|
888
|
+
await expectJsonSchemaError(result);
|
|
922
889
|
|
|
923
890
|
const [error] = result.getErrors();
|
|
924
891
|
|
|
@@ -927,179 +894,169 @@ describe('validateDocumentsBatchTransitionBasicFactory', () => {
|
|
|
927
894
|
});
|
|
928
895
|
});
|
|
929
896
|
|
|
930
|
-
it('should return invalid result if there are duplicate unique index values', async () => {
|
|
931
|
-
const
|
|
932
|
-
|
|
933
|
-
findDuplicatesByIndicesMock.returns(duplicates);
|
|
934
|
-
|
|
935
|
-
const result = await validateDocumentsBatchTransitionBasic(
|
|
936
|
-
rawStateTransition,
|
|
937
|
-
executionContext,
|
|
938
|
-
);
|
|
939
|
-
|
|
940
|
-
expectValidationError(result, DuplicateDocumentTransitionsWithIndicesError);
|
|
897
|
+
it('should return invalid result if there are duplicate unique index values - Rust', async () => {
|
|
898
|
+
const [, , , indexedTransition] = documentTransitions.map((t) => t.toObject());
|
|
899
|
+
const duplicatedTransition = { ...indexedTransition };
|
|
941
900
|
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
expect(error.getCode()).to.equal(1020);
|
|
945
|
-
|
|
946
|
-
expect(error.getDocumentTransitionReferences()).to.deep.equal(
|
|
947
|
-
duplicates.map((d) => [d.$type, d.$id]),
|
|
948
|
-
);
|
|
949
|
-
|
|
950
|
-
expect(stateRepositoryMock.fetchDataContract).to.have.been.calledOnceWithExactly(
|
|
901
|
+
duplicatedTransition.$entropy = Buffer.alloc(32, 'b');
|
|
902
|
+
duplicatedTransition.$id = generateDocumentId(
|
|
951
903
|
dataContract.getId(),
|
|
952
|
-
|
|
904
|
+
ownerId,
|
|
905
|
+
duplicatedTransition.$type,
|
|
906
|
+
duplicatedTransition.$entropy,
|
|
953
907
|
);
|
|
954
|
-
|
|
955
|
-
expect(findDuplicatesByIdMock).to.have.been.calledOnceWithExactly(
|
|
956
|
-
rawStateTransition.transitions,
|
|
957
|
-
);
|
|
958
|
-
expect(findDuplicatesByIndicesMock).to.have.been.calledOnceWithExactly(
|
|
959
|
-
rawStateTransition.transitions, dataContract,
|
|
960
|
-
);
|
|
961
|
-
});
|
|
908
|
+
const duplicates = [duplicatedTransition, indexedTransition];
|
|
962
909
|
|
|
963
|
-
|
|
964
|
-
|
|
910
|
+
stateTransition = new DocumentsBatchTransition({
|
|
911
|
+
protocolVersion: protocolVersion.latestVersion,
|
|
912
|
+
ownerId,
|
|
913
|
+
contractId: dataContract.getId(),
|
|
914
|
+
transitions: duplicates,
|
|
915
|
+
signature: Buffer.alloc(65),
|
|
916
|
+
signaturePublicKeyId: 0,
|
|
917
|
+
}, [dataContract.clone()]);
|
|
965
918
|
|
|
966
|
-
|
|
967
|
-
new ValidationResult([consensusError]),
|
|
968
|
-
);
|
|
919
|
+
rawStateTransition = stateTransition.toObject();
|
|
969
920
|
|
|
970
921
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
922
|
+
protocolVersionValidator,
|
|
923
|
+
stateRepositoryMock,
|
|
971
924
|
rawStateTransition,
|
|
972
925
|
executionContext,
|
|
973
926
|
);
|
|
974
927
|
|
|
975
|
-
expectValidationError(result);
|
|
928
|
+
await expectValidationError(result, DuplicateDocumentTransitionsWithIndicesError);
|
|
976
929
|
|
|
977
930
|
const [error] = result.getErrors();
|
|
978
931
|
|
|
979
|
-
expect(error).to.equal(
|
|
980
|
-
|
|
981
|
-
expect(validatePartialCompoundIndicesMock).to.be.calledOnceWithExactly(
|
|
982
|
-
ownerId.toBuffer(),
|
|
983
|
-
rawStateTransition.transitions,
|
|
984
|
-
dataContract,
|
|
985
|
-
);
|
|
932
|
+
expect(error.getCode()).to.equal(1020);
|
|
986
933
|
|
|
987
|
-
expect(stateRepositoryMock.fetchDataContract).to.have.been.
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
);
|
|
991
|
-
expect(enrichSpy).to.have.been.calledThrice();
|
|
934
|
+
expect(stateRepositoryMock.fetchDataContract).to.have.been.calledOnce();
|
|
935
|
+
const [fetchDataContractId] = stateRepositoryMock.fetchDataContract.getCall(0).args;
|
|
936
|
+
expect(fetchDataContractId.toBuffer()).is.deep.equal(dataContract.getId().toBuffer());
|
|
992
937
|
});
|
|
993
938
|
});
|
|
994
939
|
});
|
|
995
940
|
|
|
996
941
|
describe('signature', () => {
|
|
997
|
-
it('should be present', async () => {
|
|
942
|
+
it('should be present - Rust', async () => {
|
|
998
943
|
delete rawStateTransition.signature;
|
|
999
944
|
|
|
1000
945
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
946
|
+
protocolVersionValidator,
|
|
947
|
+
stateRepositoryMock,
|
|
1001
948
|
rawStateTransition,
|
|
1002
949
|
executionContext,
|
|
1003
950
|
);
|
|
1004
951
|
|
|
1005
|
-
expectJsonSchemaError(result);
|
|
952
|
+
await expectJsonSchemaError(result);
|
|
1006
953
|
|
|
1007
954
|
const [error] = result.getErrors();
|
|
1008
955
|
|
|
1009
|
-
expect(error.
|
|
956
|
+
expect(error.getInstancePath()).to.equal('');
|
|
1010
957
|
expect(error.getKeyword()).to.equal('required');
|
|
1011
958
|
expect(error.getParams().missingProperty).to.equal('signature');
|
|
1012
959
|
});
|
|
1013
960
|
|
|
1014
|
-
it('should be a byte array', async () => {
|
|
961
|
+
it('should be a byte array - Rust', async () => {
|
|
1015
962
|
rawStateTransition.signature = new Array(65).fill('string');
|
|
1016
963
|
|
|
1017
964
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
965
|
+
protocolVersionValidator,
|
|
966
|
+
stateRepositoryMock,
|
|
1018
967
|
rawStateTransition,
|
|
1019
968
|
executionContext,
|
|
1020
969
|
);
|
|
1021
970
|
|
|
1022
|
-
expectJsonSchemaError(result,
|
|
971
|
+
await expectJsonSchemaError(result, 65);
|
|
1023
972
|
|
|
1024
|
-
const [error
|
|
973
|
+
const [error] = result.getErrors();
|
|
1025
974
|
|
|
1026
|
-
expect(error.
|
|
975
|
+
expect(error.getInstancePath()).to.equal('/signature/0');
|
|
1027
976
|
expect(error.getKeyword()).to.equal('type');
|
|
1028
|
-
|
|
1029
|
-
expect(byteArrayError.getKeyword()).to.equal('byteArray');
|
|
1030
977
|
});
|
|
1031
978
|
|
|
1032
|
-
it('should be not less than 65 bytes', async () => {
|
|
979
|
+
it('should be not less than 65 bytes - Rust', async () => {
|
|
1033
980
|
rawStateTransition.signature = Buffer.alloc(64);
|
|
1034
981
|
|
|
1035
982
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
983
|
+
protocolVersionValidator,
|
|
984
|
+
stateRepositoryMock,
|
|
1036
985
|
rawStateTransition,
|
|
1037
986
|
executionContext,
|
|
1038
987
|
);
|
|
1039
988
|
|
|
1040
|
-
expectJsonSchemaError(result);
|
|
989
|
+
await expectJsonSchemaError(result);
|
|
1041
990
|
|
|
1042
991
|
const [error] = result.getErrors();
|
|
1043
992
|
|
|
1044
|
-
expect(error.
|
|
993
|
+
expect(error.getInstancePath()).to.equal('/signature');
|
|
1045
994
|
expect(error.getKeyword()).to.equal('minItems');
|
|
1046
|
-
expect(error.getParams().
|
|
995
|
+
expect(error.getParams().minItems).to.equal(65);
|
|
1047
996
|
});
|
|
1048
997
|
|
|
1049
|
-
it('should be not longer than 96 bytes', async () => {
|
|
998
|
+
it('should be not longer than 96 bytes - Rust', async () => {
|
|
1050
999
|
rawStateTransition.signature = Buffer.alloc(97);
|
|
1051
1000
|
|
|
1052
1001
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
1002
|
+
protocolVersionValidator,
|
|
1003
|
+
stateRepositoryMock,
|
|
1053
1004
|
rawStateTransition,
|
|
1054
1005
|
executionContext,
|
|
1055
1006
|
);
|
|
1056
1007
|
|
|
1057
|
-
expectJsonSchemaError(result);
|
|
1008
|
+
await expectJsonSchemaError(result);
|
|
1058
1009
|
|
|
1059
1010
|
const [error] = result.getErrors();
|
|
1060
1011
|
|
|
1061
|
-
expect(error.
|
|
1012
|
+
expect(error.getInstancePath()).to.equal('/signature');
|
|
1062
1013
|
expect(error.getKeyword()).to.equal('maxItems');
|
|
1063
|
-
expect(error.getParams().
|
|
1014
|
+
expect(error.getParams().maxItems).to.equal(96);
|
|
1064
1015
|
});
|
|
1065
1016
|
});
|
|
1066
1017
|
|
|
1067
1018
|
describe('signaturePublicKeyId', () => {
|
|
1068
|
-
it('should be an integer', async () => {
|
|
1019
|
+
it('should be an integer - Rust', async () => {
|
|
1069
1020
|
rawStateTransition.signaturePublicKeyId = 1.4;
|
|
1070
1021
|
|
|
1071
1022
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
1023
|
+
protocolVersionValidator,
|
|
1024
|
+
stateRepositoryMock,
|
|
1072
1025
|
rawStateTransition,
|
|
1073
1026
|
executionContext,
|
|
1074
1027
|
);
|
|
1075
1028
|
|
|
1076
|
-
expectJsonSchemaError(result, 1);
|
|
1029
|
+
await expectJsonSchemaError(result, 1);
|
|
1077
1030
|
|
|
1078
1031
|
const [error] = result.getErrors();
|
|
1079
1032
|
|
|
1080
|
-
expect(error.
|
|
1033
|
+
expect(error.getInstancePath()).to.equal('/signaturePublicKeyId');
|
|
1081
1034
|
expect(error.getKeyword()).to.equal('type');
|
|
1082
1035
|
});
|
|
1083
1036
|
|
|
1084
|
-
it('should not be < 0', async () => {
|
|
1037
|
+
it('should not be < 0 - Rust', async () => {
|
|
1085
1038
|
rawStateTransition.signaturePublicKeyId = -1;
|
|
1086
1039
|
|
|
1087
1040
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
1041
|
+
protocolVersionValidator,
|
|
1042
|
+
stateRepositoryMock,
|
|
1088
1043
|
rawStateTransition,
|
|
1089
1044
|
executionContext,
|
|
1090
1045
|
);
|
|
1091
1046
|
|
|
1092
|
-
expectJsonSchemaError(result, 1);
|
|
1047
|
+
await expectJsonSchemaError(result, 1);
|
|
1093
1048
|
|
|
1094
1049
|
const [error] = result.getErrors();
|
|
1095
1050
|
|
|
1096
|
-
expect(error.
|
|
1051
|
+
expect(error.getInstancePath()).to.equal('/signaturePublicKeyId');
|
|
1097
1052
|
expect(error.getKeyword()).to.equal('minimum');
|
|
1098
1053
|
});
|
|
1099
1054
|
});
|
|
1100
1055
|
|
|
1101
|
-
it('should return valid result', async () => {
|
|
1056
|
+
it('should return valid result - Rust', async () => {
|
|
1102
1057
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
1058
|
+
protocolVersionValidator,
|
|
1059
|
+
stateRepositoryMock,
|
|
1103
1060
|
rawStateTransition,
|
|
1104
1061
|
executionContext,
|
|
1105
1062
|
);
|
|
@@ -1107,40 +1064,28 @@ describe('validateDocumentsBatchTransitionBasicFactory', () => {
|
|
|
1107
1064
|
expect(result).to.be.an.instanceOf(ValidationResult);
|
|
1108
1065
|
expect(result.isValid()).to.be.true();
|
|
1109
1066
|
|
|
1110
|
-
expect(stateRepositoryMock.fetchDataContract).to.have.been.
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
);
|
|
1114
|
-
|
|
1115
|
-
expect(enrichSpy).to.have.been.calledThrice();
|
|
1116
|
-
|
|
1117
|
-
expect(findDuplicatesByIdMock).to.have.been.calledOnceWithExactly(
|
|
1118
|
-
rawStateTransition.transitions,
|
|
1119
|
-
);
|
|
1120
|
-
|
|
1121
|
-
expect(findDuplicatesByIndicesMock).to.have.been.calledOnceWithExactly(
|
|
1122
|
-
rawStateTransition.transitions, dataContract,
|
|
1123
|
-
);
|
|
1067
|
+
expect(stateRepositoryMock.fetchDataContract).to.have.been.calledOnce();
|
|
1068
|
+
const [fetchDataContractId] = stateRepositoryMock.fetchDataContract.getCall(0).args;
|
|
1069
|
+
expect(fetchDataContractId.toBuffer()).is.deep.equal(dataContract.getId().toBuffer());
|
|
1124
1070
|
});
|
|
1125
1071
|
|
|
1126
|
-
it('should not validate Document transitions on dry run', async () => {
|
|
1072
|
+
it('should not validate Document transitions on dry run - Rust', async () => {
|
|
1127
1073
|
stateRepositoryMock.fetchDataContract.resolves(null);
|
|
1128
1074
|
|
|
1129
1075
|
executionContext.enableDryRun();
|
|
1130
1076
|
|
|
1131
1077
|
const result = await validateDocumentsBatchTransitionBasic(
|
|
1078
|
+
protocolVersionValidator,
|
|
1079
|
+
stateRepositoryMock,
|
|
1132
1080
|
rawStateTransition,
|
|
1133
1081
|
executionContext,
|
|
1134
1082
|
);
|
|
1135
1083
|
|
|
1136
|
-
executionContext.disableDryRun();
|
|
1137
|
-
|
|
1138
1084
|
expect(result).to.be.an.instanceOf(ValidationResult);
|
|
1139
1085
|
expect(result.isValid()).to.be.true();
|
|
1140
1086
|
|
|
1141
|
-
expect(stateRepositoryMock.fetchDataContract).to.have.been.
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
);
|
|
1087
|
+
expect(stateRepositoryMock.fetchDataContract).to.have.been.calledOnce();
|
|
1088
|
+
const [fetchDataContractId] = stateRepositoryMock.fetchDataContract.getCall(0).args;
|
|
1089
|
+
expect(fetchDataContractId.toBuffer()).is.deep.equal(dataContract.getId().toBuffer());
|
|
1145
1090
|
});
|
|
1146
1091
|
});
|