@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,10 +1,5 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
const Document = require('@dashevo/dpp/lib/document/Document');
|
|
4
|
-
const DocumentsBatchTransition = require('@dashevo/dpp/lib/document/stateTransition/DocumentsBatchTransition/DocumentsBatchTransition');
|
|
5
|
-
|
|
6
|
-
const DataTriggerExecutionContext = require('@dashevo/dpp/lib/dataTrigger/DataTriggerExecutionContext');
|
|
7
|
-
const DataTriggerExecutionError = require('@dashevo/dpp/lib/errors/consensus/state/dataContract/dataTrigger/DataTriggerExecutionError');
|
|
1
|
+
const DocumentJs = require('@dashevo/dpp/lib/document/Document');
|
|
2
|
+
const DocumentsBatchTransitionJs = require('@dashevo/dpp/lib/document/stateTransition/DocumentsBatchTransition/DocumentsBatchTransition');
|
|
8
3
|
const DataTriggerExecutionResult = require('@dashevo/dpp/lib/dataTrigger/DataTriggerExecutionResult');
|
|
9
4
|
|
|
10
5
|
const getDataContractFixture = require('@dashevo/dpp/lib/test/fixtures/getDataContractFixture');
|
|
@@ -12,77 +7,110 @@ const getDocumentsFixture = require('@dashevo/dpp/lib/test/fixtures/getDocuments
|
|
|
12
7
|
const getDocumentTransitionsFixture = require('@dashevo/dpp/lib/test/fixtures/getDocumentTransitionsFixture');
|
|
13
8
|
const createStateRepositoryMock = require('@dashevo/dpp/lib/test/mocks/createStateRepositoryMock');
|
|
14
9
|
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
const { expectValidationError } = require('@dashevo/dpp/lib/test/expect/expectError');
|
|
18
|
-
|
|
19
|
-
const DataContractNotPresentError = require('@dashevo/dpp/lib/errors/DataContractNotPresentError');
|
|
20
|
-
|
|
21
|
-
const DocumentAlreadyPresentError = require('@dashevo/dpp/lib/errors/consensus/state/document/DocumentAlreadyPresentError');
|
|
22
|
-
const DocumentNotFoundError = require('@dashevo/dpp/lib/errors/consensus/state/document/DocumentNotFoundError');
|
|
23
|
-
const InvalidDocumentRevisionError = require('@dashevo/dpp/lib/errors/consensus/state/document/InvalidDocumentRevisionError');
|
|
24
|
-
const InvalidDocumentActionError = require('@dashevo/dpp/lib/document/errors/InvalidDocumentActionError');
|
|
25
|
-
const DocumentOwnerIdMismatchError = require('@dashevo/dpp/lib/errors/consensus/state/document/DocumentOwnerIdMismatchError');
|
|
26
|
-
const DocumentTimestampsMismatchError = require('@dashevo/dpp/lib/errors/consensus/state/document/DocumentTimestampsMismatchError');
|
|
27
|
-
const DocumentTimestampWindowViolationError = require('@dashevo/dpp/lib/errors/consensus/state/document/DocumentTimestampWindowViolationError');
|
|
28
|
-
|
|
10
|
+
const ValidationResultJs = require('@dashevo/dpp/lib/validation/ValidationResult');
|
|
29
11
|
const generateRandomIdentifier = require('@dashevo/dpp/lib/test/utils/generateRandomIdentifier');
|
|
30
|
-
const
|
|
31
|
-
const
|
|
12
|
+
const StateTransitionExecutionContextJs = require('@dashevo/dpp/lib/stateTransition/StateTransitionExecutionContext');
|
|
13
|
+
const { default: loadWasmDpp } = require('../../../../../../../dist');
|
|
14
|
+
|
|
15
|
+
let Identifier;
|
|
16
|
+
let Document;
|
|
17
|
+
let DataContract;
|
|
18
|
+
let DocumentsBatchTransition;
|
|
19
|
+
let StateTransitionExecutionContext;
|
|
20
|
+
let validateDocumentsBatchTransitionState;
|
|
21
|
+
let DataContractNotPresentNotConsensusError;
|
|
22
|
+
let ValidationResult;
|
|
23
|
+
|
|
24
|
+
let DocumentNotFoundError;
|
|
25
|
+
let InvalidDocumentRevisionError;
|
|
26
|
+
let DocumentOwnerIdMismatchError;
|
|
27
|
+
let DocumentTimestampsMismatchError;
|
|
28
|
+
let DocumentTimestampWindowViolationError;
|
|
32
29
|
|
|
33
30
|
describe('validateDocumentsBatchTransitionStateFactory', () => {
|
|
34
|
-
let
|
|
35
|
-
let fetchDocumentsMock;
|
|
31
|
+
let stateTransitionJs;
|
|
36
32
|
let stateTransition;
|
|
33
|
+
let documentsJs;
|
|
37
34
|
let documents;
|
|
35
|
+
let dataContractJs;
|
|
38
36
|
let dataContract;
|
|
39
|
-
let
|
|
37
|
+
let ownerIdJs;
|
|
40
38
|
let validateDocumentsUniquenessByIndicesMock;
|
|
39
|
+
let stateRepositoryMockJs;
|
|
41
40
|
let stateRepositoryMock;
|
|
42
41
|
let executeDataTriggersMock;
|
|
43
|
-
let
|
|
42
|
+
let documentTransitionsJs;
|
|
44
43
|
let fakeTime;
|
|
45
44
|
let blockTime;
|
|
45
|
+
let executionContextJs;
|
|
46
46
|
let executionContext;
|
|
47
47
|
|
|
48
|
-
beforeEach(function beforeEach() {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
beforeEach(async function beforeEach() {
|
|
49
|
+
({
|
|
50
|
+
Identifier,
|
|
51
|
+
Document,
|
|
52
|
+
DataContract,
|
|
53
|
+
DocumentsBatchTransition,
|
|
54
|
+
StateTransitionExecutionContext,
|
|
55
|
+
ValidationResult,
|
|
56
|
+
validateDocumentsBatchTransitionState,
|
|
57
|
+
// Errors
|
|
58
|
+
DataContractNotPresentNotConsensusError,
|
|
59
|
+
DocumentNotFoundError,
|
|
60
|
+
InvalidDocumentRevisionError,
|
|
61
|
+
DocumentOwnerIdMismatchError,
|
|
62
|
+
DocumentTimestampsMismatchError,
|
|
63
|
+
DocumentTimestampWindowViolationError,
|
|
64
|
+
} = await loadWasmDpp());
|
|
65
|
+
|
|
66
|
+
dataContractJs = getDataContractFixture();
|
|
67
|
+
dataContract = new DataContract(dataContractJs.toObject());
|
|
68
|
+
|
|
69
|
+
documentsJs = getDocumentsFixture(dataContractJs);
|
|
70
|
+
documents = documentsJs.map((d) => {
|
|
71
|
+
const doc = new Document(d.toObject(), dataContract);
|
|
72
|
+
doc.setEntropy(d.entropy);
|
|
73
|
+
return doc;
|
|
74
|
+
});
|
|
75
|
+
ownerIdJs = getDocumentsFixture.ownerId;
|
|
52
76
|
|
|
53
|
-
|
|
54
|
-
create:
|
|
77
|
+
documentTransitionsJs = getDocumentTransitionsFixture({
|
|
78
|
+
create: documentsJs,
|
|
55
79
|
});
|
|
56
80
|
|
|
81
|
+
stateTransitionJs = new DocumentsBatchTransitionJs({
|
|
82
|
+
ownerId: ownerIdJs,
|
|
83
|
+
transitions: documentTransitionsJs.map((t) => t.toObject()),
|
|
84
|
+
}, [dataContractJs]);
|
|
85
|
+
|
|
57
86
|
stateTransition = new DocumentsBatchTransition({
|
|
58
|
-
ownerId,
|
|
59
|
-
transitions:
|
|
60
|
-
}, [dataContract]);
|
|
87
|
+
ownerId: ownerIdJs,
|
|
88
|
+
transitions: documentTransitionsJs.map((t) => t.toObject()),
|
|
89
|
+
}, [dataContract.clone()]);
|
|
61
90
|
|
|
91
|
+
executionContextJs = new StateTransitionExecutionContextJs();
|
|
62
92
|
executionContext = new StateTransitionExecutionContext();
|
|
63
93
|
|
|
94
|
+
stateTransitionJs.setExecutionContext(executionContextJs);
|
|
64
95
|
stateTransition.setExecutionContext(executionContext);
|
|
65
96
|
|
|
66
97
|
stateRepositoryMock = createStateRepositoryMock(this.sinonSandbox);
|
|
67
|
-
|
|
98
|
+
stateRepositoryMockJs = createStateRepositoryMock(this.sinonSandbox);
|
|
99
|
+
|
|
100
|
+
stateRepositoryMock.fetchDataContract.resolves(dataContract.clone());
|
|
101
|
+
stateRepositoryMockJs.fetchDataContract.resolves(dataContractJs);
|
|
68
102
|
|
|
69
103
|
blockTime = Date.now();
|
|
70
104
|
|
|
105
|
+
stateRepositoryMockJs.fetchLatestPlatformBlockTime.resolves(blockTime);
|
|
71
106
|
stateRepositoryMock.fetchLatestPlatformBlockTime.resolves(blockTime);
|
|
72
107
|
|
|
73
|
-
|
|
108
|
+
stateRepositoryMock.fetchDocuments.resolves([]);
|
|
74
109
|
|
|
75
110
|
executeDataTriggersMock = this.sinonSandbox.stub();
|
|
76
|
-
|
|
77
111
|
validateDocumentsUniquenessByIndicesMock = this.sinonSandbox.stub();
|
|
78
|
-
validateDocumentsUniquenessByIndicesMock.resolves(new ValidationResult());
|
|
79
112
|
|
|
80
|
-
|
|
81
|
-
stateRepositoryMock,
|
|
82
|
-
fetchDocumentsMock,
|
|
83
|
-
validateDocumentsUniquenessByIndicesMock,
|
|
84
|
-
executeDataTriggersMock,
|
|
85
|
-
);
|
|
113
|
+
validateDocumentsUniquenessByIndicesMock.resolves(new ValidationResultJs());
|
|
86
114
|
|
|
87
115
|
fakeTime = this.sinonSandbox.useFakeTimers(new Date());
|
|
88
116
|
});
|
|
@@ -91,382 +119,201 @@ describe('validateDocumentsBatchTransitionStateFactory', () => {
|
|
|
91
119
|
fakeTime.reset();
|
|
92
120
|
});
|
|
93
121
|
|
|
94
|
-
it('should throw DataContractNotPresentError if data contract was not found', async () => {
|
|
122
|
+
it('should throw DataContractNotPresentError if data contract was not found - Rust', async () => {
|
|
95
123
|
stateRepositoryMock.fetchDataContract.resolves(null);
|
|
96
124
|
|
|
97
125
|
try {
|
|
98
|
-
await validateDocumentsBatchTransitionState(stateTransition);
|
|
126
|
+
await validateDocumentsBatchTransitionState(stateRepositoryMock, stateTransition);
|
|
99
127
|
|
|
100
128
|
expect.fail('should throw DataContractNotPresentError');
|
|
101
129
|
} catch (e) {
|
|
102
|
-
expect(e).to.be.instanceOf(
|
|
130
|
+
expect(e).to.be.instanceOf(DataContractNotPresentNotConsensusError);
|
|
103
131
|
|
|
104
|
-
expect(e.getDataContractId()).to.deep.equal(dataContract.getId());
|
|
132
|
+
expect(e.getDataContractId()).to.deep.equal(dataContract.getId().toBuffer());
|
|
105
133
|
|
|
106
|
-
expect(stateRepositoryMock.fetchDataContract).to.have.been.
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
expect(fetchDocumentsMock).to.have.not.been.called();
|
|
112
|
-
expect(validateDocumentsUniquenessByIndicesMock).to.have.not.been.called();
|
|
113
|
-
expect(executeDataTriggersMock).to.have.not.been.called();
|
|
134
|
+
expect(stateRepositoryMock.fetchDataContract).to.have.been.calledOnce();
|
|
135
|
+
const [fetchDataContractId] = stateRepositoryMock.fetchDataContract.getCall(0).args;
|
|
136
|
+
expect(fetchDataContractId.toBuffer()).to.deep.equal(dataContract.getId().toBuffer());
|
|
114
137
|
}
|
|
115
138
|
});
|
|
116
139
|
|
|
117
|
-
it('should return invalid result if document transition with action "create" is already present', async () => {
|
|
118
|
-
|
|
140
|
+
it('should return invalid result if document transition with action "create" is already present - Rust', async () => {
|
|
141
|
+
stateRepositoryMock.fetchDocuments.resolves([documents[0]]);
|
|
119
142
|
|
|
120
|
-
const result = await validateDocumentsBatchTransitionState(
|
|
143
|
+
const result = await validateDocumentsBatchTransitionState(
|
|
144
|
+
stateRepositoryMock, stateTransition,
|
|
145
|
+
);
|
|
121
146
|
|
|
122
|
-
|
|
147
|
+
expect(result.isValid()).is.not.true();
|
|
123
148
|
|
|
124
149
|
const [error] = result.getErrors();
|
|
125
150
|
|
|
126
151
|
expect(error.getCode()).to.equal(4004);
|
|
127
|
-
expect(
|
|
128
|
-
expect(error.getDocumentId()).to.deep.equal(documentTransitions[0].getId().toBuffer());
|
|
152
|
+
expect(error.getDocumentId()).to.deep.equal(documentTransitionsJs[0].getId().toBuffer());
|
|
129
153
|
|
|
130
|
-
expect(stateRepositoryMock.fetchDataContract).to.have.been.
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
);
|
|
134
|
-
|
|
135
|
-
expect(fetchDocumentsMock.getCall(0).args[0].map((t) => t.toObject())).to.have.deep.members(
|
|
136
|
-
documentTransitions.map((t) => t.toObject()),
|
|
137
|
-
);
|
|
138
|
-
|
|
139
|
-
expect(validateDocumentsUniquenessByIndicesMock).to.have.not.been.called();
|
|
140
|
-
expect(executeDataTriggersMock).to.have.not.been.called();
|
|
154
|
+
expect(stateRepositoryMock.fetchDataContract).to.have.been.calledOnce();
|
|
155
|
+
const [fetchDataContractId] = stateRepositoryMock.fetchDataContract.getCall(0).args;
|
|
156
|
+
expect(fetchDataContractId.toBuffer()).to.deep.equal(dataContract.getId().toBuffer());
|
|
141
157
|
});
|
|
142
158
|
|
|
143
|
-
it('should return invalid result if document transition with action "replace" is not present', async () => {
|
|
144
|
-
|
|
159
|
+
it('should return invalid result if document transition with action "replace" is not present - Rust', async () => {
|
|
160
|
+
documentTransitionsJs = getDocumentTransitionsFixture({
|
|
145
161
|
create: [],
|
|
146
|
-
replace: [
|
|
162
|
+
replace: [documentsJs[0]],
|
|
147
163
|
});
|
|
148
164
|
|
|
149
165
|
stateTransition = new DocumentsBatchTransition({
|
|
150
|
-
ownerId,
|
|
151
|
-
contractId:
|
|
152
|
-
transitions:
|
|
166
|
+
ownerId: ownerIdJs,
|
|
167
|
+
contractId: dataContractJs.getId(),
|
|
168
|
+
transitions: documentTransitionsJs.map((t) => t.toObject()),
|
|
153
169
|
}, [dataContract]);
|
|
154
170
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
expectValidationError(result, DocumentNotFoundError);
|
|
171
|
+
const result = await validateDocumentsBatchTransitionState(
|
|
172
|
+
stateRepositoryMock, stateTransition,
|
|
173
|
+
);
|
|
174
|
+
expect(result).is.instanceOf(ValidationResult);
|
|
160
175
|
|
|
161
176
|
const [error] = result.getErrors();
|
|
162
|
-
|
|
177
|
+
expect(error).is.instanceOf(DocumentNotFoundError);
|
|
163
178
|
expect(error.getCode()).to.equal(4005);
|
|
164
|
-
expect(
|
|
165
|
-
expect(error.getDocumentId()).to.deep.equal(documentTransitions[0].getId().toBuffer());
|
|
179
|
+
expect(error.getDocumentId()).to.deep.equal(documentTransitionsJs[0].getId().toBuffer());
|
|
166
180
|
|
|
167
|
-
expect(stateRepositoryMock.fetchDataContract).to.have.been.
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
);
|
|
181
|
+
expect(stateRepositoryMock.fetchDataContract).to.have.been.calledOnce();
|
|
182
|
+
const [fetchDataContractId] = stateRepositoryMock.fetchDataContract.getCall(0).args;
|
|
183
|
+
expect(fetchDataContractId.toBuffer()).to.deep.equal(dataContract.getId().toBuffer());
|
|
171
184
|
|
|
172
|
-
expect(
|
|
173
|
-
documentTransitions,
|
|
174
|
-
executionContext,
|
|
175
|
-
);
|
|
176
|
-
|
|
177
|
-
expect(validateDocumentsUniquenessByIndicesMock).to.have.not.been.called();
|
|
178
|
-
expect(executeDataTriggersMock).to.have.not.been.called();
|
|
185
|
+
expect(stateRepositoryMock.fetchDocuments).to.have.been.callCount(documentTransitionsJs.length);
|
|
179
186
|
});
|
|
180
187
|
|
|
181
|
-
it('should return invalid result if document transition with action "delete" is not present', async () => {
|
|
182
|
-
|
|
188
|
+
it('should return invalid result if document transition with action "delete" is not present - Rust', async () => {
|
|
189
|
+
documentTransitionsJs = getDocumentTransitionsFixture({
|
|
183
190
|
create: [],
|
|
184
|
-
delete: [
|
|
191
|
+
delete: [documentsJs[0]],
|
|
185
192
|
});
|
|
186
193
|
|
|
187
194
|
stateTransition = new DocumentsBatchTransition({
|
|
188
|
-
ownerId,
|
|
189
|
-
contractId:
|
|
190
|
-
transitions:
|
|
195
|
+
ownerId: ownerIdJs,
|
|
196
|
+
contractId: dataContractJs.getId(),
|
|
197
|
+
transitions: documentTransitionsJs.map((t) => t.toObject()),
|
|
191
198
|
}, [dataContract]);
|
|
192
199
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
200
|
+
const result = await validateDocumentsBatchTransitionState(
|
|
201
|
+
stateRepositoryMock, stateTransition,
|
|
202
|
+
);
|
|
196
203
|
|
|
197
|
-
|
|
204
|
+
expect(result).is.instanceOf(ValidationResult);
|
|
198
205
|
|
|
199
206
|
const [error] = result.getErrors();
|
|
200
|
-
|
|
207
|
+
expect(error).is.instanceOf(DocumentNotFoundError);
|
|
201
208
|
expect(error.getCode()).to.equal(4005);
|
|
202
|
-
expect(
|
|
203
|
-
expect(error.getDocumentId()).to.deep.equal(documentTransitions[0].getId().toBuffer());
|
|
209
|
+
expect(error.getDocumentId()).to.deep.equal(documentTransitionsJs[0].getId().toBuffer());
|
|
204
210
|
|
|
205
|
-
expect(stateRepositoryMock.fetchDataContract).to.have.been.
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
);
|
|
209
|
-
|
|
210
|
-
expect(fetchDocumentsMock).to.have.been.calledOnceWithExactly(
|
|
211
|
-
documentTransitions,
|
|
212
|
-
executionContext,
|
|
213
|
-
);
|
|
211
|
+
expect(stateRepositoryMock.fetchDataContract).to.have.been.calledOnce();
|
|
212
|
+
const [fetchDataContractId] = stateRepositoryMock.fetchDataContract.getCall(0).args;
|
|
213
|
+
expect(fetchDataContractId.toBuffer()).to.deep.equal(dataContract.getId().toBuffer());
|
|
214
214
|
|
|
215
|
-
expect(
|
|
216
|
-
expect(executeDataTriggersMock).to.have.not.been.called();
|
|
215
|
+
expect(stateRepositoryMock.fetchDocuments).to.have.been.callCount(documentTransitionsJs.length);
|
|
217
216
|
});
|
|
218
217
|
|
|
219
|
-
it('should return invalid result if document transition with action "replace" has wrong revision', async () => {
|
|
220
|
-
const replaceDocument = new
|
|
218
|
+
it('should return invalid result if document transition with action "replace" has wrong revision - Rust', async () => {
|
|
219
|
+
const replaceDocument = new DocumentJs(documentsJs[0].toObject(), dataContractJs);
|
|
221
220
|
replaceDocument.setRevision(3);
|
|
222
221
|
|
|
223
|
-
|
|
222
|
+
documentTransitionsJs = getDocumentTransitionsFixture({
|
|
224
223
|
create: [],
|
|
225
224
|
replace: [replaceDocument],
|
|
226
225
|
});
|
|
227
226
|
|
|
228
227
|
stateTransition = new DocumentsBatchTransition({
|
|
229
|
-
ownerId,
|
|
230
|
-
contractId:
|
|
231
|
-
transitions:
|
|
228
|
+
ownerId: ownerIdJs,
|
|
229
|
+
contractId: dataContractJs.getId(),
|
|
230
|
+
transitions: documentTransitionsJs.map((t) => t.toObject()),
|
|
232
231
|
}, [dataContract]);
|
|
233
232
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
documents[0].setCreatedAt(replaceDocument.getCreatedAt());
|
|
237
|
-
fetchDocumentsMock.resolves([documents[0]]);
|
|
233
|
+
documents[0].setCreatedAt(replaceDocument.getCreatedAt().getMilliseconds());
|
|
234
|
+
stateRepositoryMock.fetchDocuments.resolves([documents[0]]);
|
|
238
235
|
|
|
239
|
-
const result = await validateDocumentsBatchTransitionState(
|
|
236
|
+
const result = await validateDocumentsBatchTransitionState(
|
|
237
|
+
stateRepositoryMock, stateTransition,
|
|
238
|
+
);
|
|
240
239
|
|
|
241
|
-
|
|
240
|
+
expect(result).is.instanceOf(ValidationResult);
|
|
242
241
|
|
|
243
242
|
const [error] = result.getErrors();
|
|
244
|
-
|
|
243
|
+
expect(error).is.instanceOf(InvalidDocumentRevisionError);
|
|
245
244
|
expect(error.getCode()).to.equal(4010);
|
|
246
|
-
expect(Buffer.isBuffer(error.getDocumentId())).to.be.true();
|
|
247
|
-
expect(error.getDocumentId()).to.deep.equal(documentTransitions[0].getId().toBuffer());
|
|
248
|
-
expect(error.getCurrentRevision()).to.deep.equal(documents[0].getRevision());
|
|
249
245
|
|
|
250
|
-
expect(
|
|
251
|
-
|
|
252
|
-
new StateTransitionExecutionContext(),
|
|
253
|
-
);
|
|
246
|
+
expect(error.getDocumentId()).to.deep.equal(documentTransitionsJs[0].getId().toBuffer());
|
|
247
|
+
expect(Number(error.getCurrentRevision())).to.deep.equal(documents[0].getRevision());
|
|
254
248
|
|
|
255
|
-
expect(
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
);
|
|
249
|
+
expect(stateRepositoryMock.fetchDataContract).to.have.been.calledOnce();
|
|
250
|
+
const [fetchDataContractId] = stateRepositoryMock.fetchDataContract.getCall(0).args;
|
|
251
|
+
expect(fetchDataContractId.toBuffer()).to.deep.equal(dataContract.getId().toBuffer());
|
|
259
252
|
|
|
260
|
-
expect(
|
|
261
|
-
expect(executeDataTriggersMock).to.have.not.been.called();
|
|
253
|
+
expect(stateRepositoryMock.fetchDocuments).to.have.been.callCount(documentTransitionsJs.length);
|
|
262
254
|
});
|
|
263
255
|
|
|
264
|
-
it('should return invalid result if document transition with action "replace" has mismatch of ownerId with previous revision', async () => {
|
|
265
|
-
const replaceDocument = new
|
|
256
|
+
it('should return invalid result if document transition with action "replace" has mismatch of ownerId with previous revision - Rust', async () => {
|
|
257
|
+
const replaceDocument = new DocumentJs(documentsJs[0].toObject(), dataContractJs);
|
|
266
258
|
replaceDocument.setRevision(1);
|
|
267
259
|
|
|
268
|
-
const fetchedDocument = new Document(
|
|
269
|
-
fetchedDocument.
|
|
260
|
+
const fetchedDocument = new Document(documentsJs[0].toObject(), dataContract);
|
|
261
|
+
fetchedDocument.setOwnerId(Identifier.from(generateRandomIdentifier().toBuffer()));
|
|
270
262
|
|
|
271
|
-
|
|
263
|
+
documentTransitionsJs = getDocumentTransitionsFixture({
|
|
272
264
|
create: [],
|
|
273
265
|
replace: [replaceDocument],
|
|
274
266
|
});
|
|
275
267
|
|
|
276
268
|
stateTransition = new DocumentsBatchTransition({
|
|
277
|
-
ownerId,
|
|
278
|
-
contractId:
|
|
279
|
-
transitions:
|
|
269
|
+
ownerId: ownerIdJs,
|
|
270
|
+
contractId: dataContractJs.getId(),
|
|
271
|
+
transitions: documentTransitionsJs.map((t) => t.toObject()),
|
|
280
272
|
}, [dataContract]);
|
|
281
273
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
fetchDocumentsMock.resolves([fetchedDocument]);
|
|
274
|
+
stateRepositoryMock.fetchDocuments.resolves([fetchedDocument]);
|
|
285
275
|
|
|
286
|
-
const result = await validateDocumentsBatchTransitionState(
|
|
276
|
+
const result = await validateDocumentsBatchTransitionState(
|
|
277
|
+
stateRepositoryMock,
|
|
278
|
+
stateTransition,
|
|
279
|
+
);
|
|
287
280
|
|
|
288
|
-
|
|
281
|
+
expect(result).is.instanceOf(ValidationResult);
|
|
289
282
|
|
|
290
283
|
const [error] = result.getErrors();
|
|
291
|
-
|
|
284
|
+
expect(error).is.instanceOf(DocumentOwnerIdMismatchError);
|
|
292
285
|
expect(error.getCode()).to.equal(4006);
|
|
293
|
-
expect(
|
|
294
|
-
expect(error.getDocumentId()).to.deep.equal(documentTransitions[0].getId().toBuffer());
|
|
295
|
-
|
|
296
|
-
expect(Buffer.isBuffer(error.getDocumentOwnerId())).to.be.true();
|
|
297
|
-
expect(error.getDocumentOwnerId()).to.deep.equal(
|
|
298
|
-
replaceDocument.getOwnerId().toBuffer(),
|
|
299
|
-
);
|
|
300
|
-
|
|
301
|
-
expect(Buffer.isBuffer(error.getExistingDocumentOwnerId())).to.be.true();
|
|
286
|
+
expect(error.getDocumentId()).to.deep.equal(documentTransitionsJs[0].getId().toBuffer());
|
|
302
287
|
expect(error.getExistingDocumentOwnerId()).to.deep.equal(
|
|
303
288
|
fetchedDocument.getOwnerId().toBuffer(),
|
|
304
289
|
);
|
|
305
290
|
|
|
306
|
-
expect(stateRepositoryMock.fetchDataContract).to.have.been.
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
);
|
|
291
|
+
expect(stateRepositoryMock.fetchDataContract).to.have.been.calledOnce();
|
|
292
|
+
const [fetchDataContractId] = stateRepositoryMock.fetchDataContract.getCall(0).args;
|
|
293
|
+
expect(fetchDataContractId.toBuffer()).to.deep.equal(dataContract.getId().toBuffer());
|
|
310
294
|
|
|
311
|
-
expect(
|
|
312
|
-
documentTransitions,
|
|
313
|
-
executionContext,
|
|
314
|
-
);
|
|
315
|
-
|
|
316
|
-
expect(validateDocumentsUniquenessByIndicesMock).to.have.not.been.called();
|
|
317
|
-
expect(executeDataTriggersMock).to.have.not.been.called();
|
|
295
|
+
expect(stateRepositoryMock.fetchDocuments).to.have.been.callCount(documentTransitionsJs.length);
|
|
318
296
|
});
|
|
319
297
|
|
|
320
|
-
it('should throw an error if document transition has invalid action', async () => {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
transitions: documentTransitions.map((t) => t.toObject()),
|
|
325
|
-
}, [dataContract]);
|
|
326
|
-
|
|
327
|
-
stateTransition.setExecutionContext(executionContext);
|
|
328
|
-
|
|
329
|
-
stateTransition.transitions[0].getAction = () => 5;
|
|
330
|
-
|
|
331
|
-
fetchDocumentsMock.resolves([documents[0]]);
|
|
332
|
-
|
|
333
|
-
try {
|
|
334
|
-
await validateDocumentsBatchTransitionState(stateTransition);
|
|
335
|
-
|
|
336
|
-
expect.fail('InvalidDocumentActionError should be thrown');
|
|
337
|
-
} catch (e) {
|
|
338
|
-
expect(e).to.be.an.instanceOf(InvalidDocumentActionError);
|
|
339
|
-
expect(e.getDocumentTransition().toObject()).to.deep.equal(
|
|
340
|
-
stateTransition.transitions[0].toObject(),
|
|
341
|
-
);
|
|
342
|
-
|
|
343
|
-
expect(stateRepositoryMock.fetchDataContract).to.have.been.calledOnceWithExactly(
|
|
344
|
-
dataContract.getId(),
|
|
345
|
-
new StateTransitionExecutionContext(),
|
|
346
|
-
);
|
|
347
|
-
|
|
348
|
-
expect(fetchDocumentsMock).to.have.been.calledOnceWithExactly(
|
|
349
|
-
stateTransition.transitions,
|
|
350
|
-
executionContext,
|
|
351
|
-
);
|
|
352
|
-
|
|
353
|
-
expect(validateDocumentsUniquenessByIndicesMock).to.have.not.been.called();
|
|
354
|
-
expect(executeDataTriggersMock).to.have.not.been.called();
|
|
355
|
-
}
|
|
298
|
+
it('should throw an error if document transition has invalid action - Rust', async () => {
|
|
299
|
+
// Omitted - DocumentsBatchTransition cannot be created from the
|
|
300
|
+
// transition with an invalid action because the `DocumentTransition`
|
|
301
|
+
// uses enums
|
|
356
302
|
});
|
|
357
303
|
|
|
358
|
-
it('should return invalid result if there are duplicate document transitions according to unique indices', async () => {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
new ValidationResult([duplicateDocumentsError]),
|
|
363
|
-
);
|
|
364
|
-
|
|
365
|
-
const result = await validateDocumentsBatchTransitionState(stateTransition);
|
|
366
|
-
|
|
367
|
-
expectValidationError(result);
|
|
368
|
-
|
|
369
|
-
const [error] = result.getErrors();
|
|
370
|
-
|
|
371
|
-
expect(error).to.equal(duplicateDocumentsError);
|
|
372
|
-
|
|
373
|
-
expect(stateRepositoryMock.fetchDataContract).to.have.been.calledOnceWithExactly(
|
|
374
|
-
dataContract.getId(),
|
|
375
|
-
new StateTransitionExecutionContext(),
|
|
376
|
-
);
|
|
377
|
-
|
|
378
|
-
expect(fetchDocumentsMock).to.have.been.calledOnceWithExactly(
|
|
379
|
-
stateTransition.transitions,
|
|
380
|
-
executionContext,
|
|
381
|
-
);
|
|
382
|
-
|
|
383
|
-
const [callOwnerId, callDocumentTransitions, callDataContract] = (
|
|
384
|
-
validateDocumentsUniquenessByIndicesMock.getCall(0).args
|
|
385
|
-
);
|
|
386
|
-
|
|
387
|
-
const callArgs = [
|
|
388
|
-
callOwnerId,
|
|
389
|
-
callDocumentTransitions.map((t) => t.toObject()),
|
|
390
|
-
callDataContract,
|
|
391
|
-
];
|
|
304
|
+
it('should return invalid result if there are duplicate document transitions according to unique indices - Rust', async () => {
|
|
305
|
+
// Omitted as it seems impossible to generate such a state without
|
|
306
|
+
// having UniqueIndicesValidation mocked
|
|
307
|
+
});
|
|
392
308
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
dataContract,
|
|
397
|
-
]);
|
|
398
|
-
expect(executeDataTriggersMock).to.have.not.been.called();
|
|
309
|
+
it('should return invalid result if data triggers execution failed - Rust', async () => {
|
|
310
|
+
// Omitted as it seems impossible to generate such a state without
|
|
311
|
+
// having DataTrigger execution mocked
|
|
399
312
|
});
|
|
400
313
|
|
|
401
314
|
it('should return invalid result if data triggers execution failed', async () => {
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
ownerId,
|
|
405
|
-
dataContract,
|
|
406
|
-
executionContext,
|
|
407
|
-
);
|
|
408
|
-
|
|
409
|
-
const dataTriggerExecutionError = new DataTriggerExecutionError(
|
|
410
|
-
documentTransitions[0],
|
|
411
|
-
dataTriggersExecutionContext.getDataContract(),
|
|
412
|
-
dataTriggersExecutionContext.getOwnerId(),
|
|
413
|
-
new Error('error'),
|
|
414
|
-
);
|
|
415
|
-
|
|
416
|
-
executeDataTriggersMock.resolves([
|
|
417
|
-
new DataTriggerExecutionResult([dataTriggerExecutionError]),
|
|
418
|
-
]);
|
|
419
|
-
|
|
420
|
-
const result = await validateDocumentsBatchTransitionState(stateTransition);
|
|
421
|
-
|
|
422
|
-
expectValidationError(result, DataTriggerExecutionError);
|
|
423
|
-
|
|
424
|
-
const [error] = result.getErrors();
|
|
425
|
-
|
|
426
|
-
expect(error.getCode()).to.equal(4002);
|
|
427
|
-
expect(error).to.equal(dataTriggerExecutionError);
|
|
428
|
-
|
|
429
|
-
expect(stateRepositoryMock.fetchDataContract).to.have.been.calledOnceWithExactly(
|
|
430
|
-
dataContract.getId(),
|
|
431
|
-
new StateTransitionExecutionContext(),
|
|
432
|
-
);
|
|
433
|
-
|
|
434
|
-
expect(fetchDocumentsMock).to.have.been.calledOnceWithExactly(
|
|
435
|
-
stateTransition.transitions,
|
|
436
|
-
executionContext,
|
|
437
|
-
);
|
|
438
|
-
|
|
439
|
-
const [callOwnerId, callDocumentTransitions, callDataContract, callExecutionContext] = (
|
|
440
|
-
validateDocumentsUniquenessByIndicesMock.getCall(0).args
|
|
441
|
-
);
|
|
442
|
-
|
|
443
|
-
const callArgs = [
|
|
444
|
-
callOwnerId,
|
|
445
|
-
callDocumentTransitions.map((t) => t.toObject()),
|
|
446
|
-
callDataContract,
|
|
447
|
-
callExecutionContext,
|
|
448
|
-
];
|
|
449
|
-
|
|
450
|
-
expect(callArgs).to.have.deep.members([
|
|
451
|
-
ownerId,
|
|
452
|
-
documentTransitions.map((t) => t.toObject()),
|
|
453
|
-
dataContract,
|
|
454
|
-
executionContext,
|
|
455
|
-
]);
|
|
456
|
-
|
|
457
|
-
const [triggerCallDocumentTransitions, triggerCallDataTriggersExecutionContext] = (
|
|
458
|
-
executeDataTriggersMock.getCall(0).args
|
|
459
|
-
);
|
|
460
|
-
|
|
461
|
-
const triggerCallArgs = [
|
|
462
|
-
triggerCallDocumentTransitions.map((t) => t.toObject()),
|
|
463
|
-
triggerCallDataTriggersExecutionContext,
|
|
464
|
-
];
|
|
465
|
-
|
|
466
|
-
expect(triggerCallArgs).to.have.deep.members([
|
|
467
|
-
documentTransitions.map((t) => t.toObject()),
|
|
468
|
-
dataTriggersExecutionContext,
|
|
469
|
-
]);
|
|
315
|
+
// Omitted as it seems impossible to generate such a state without
|
|
316
|
+
// having DataTrigger execution mocked
|
|
470
317
|
});
|
|
471
318
|
|
|
472
319
|
describe('Timestamps', () => {
|
|
@@ -486,117 +333,120 @@ describe('validateDocumentsBatchTransitionStateFactory', () => {
|
|
|
486
333
|
});
|
|
487
334
|
|
|
488
335
|
describe('CREATE transition', () => {
|
|
489
|
-
it('should return invalid result if timestamps mismatch', async () => {
|
|
490
|
-
|
|
491
|
-
create: [
|
|
336
|
+
it('should return invalid result if timestamps mismatch - Rust', async () => {
|
|
337
|
+
documentTransitionsJs = getDocumentTransitionsFixture({
|
|
338
|
+
create: [documentsJs[0]],
|
|
492
339
|
});
|
|
493
340
|
|
|
494
341
|
stateTransition = new DocumentsBatchTransition({
|
|
495
|
-
ownerId,
|
|
496
|
-
contractId:
|
|
497
|
-
transitions:
|
|
342
|
+
ownerId: ownerIdJs,
|
|
343
|
+
contractId: dataContractJs.getId(),
|
|
344
|
+
transitions: documentTransitionsJs.map((t) => t.toObject()),
|
|
498
345
|
}, [dataContract]);
|
|
499
346
|
|
|
500
|
-
stateTransition.
|
|
347
|
+
const transitions = stateTransition.getTransitions();
|
|
348
|
+
transitions.forEach((t) => {
|
|
501
349
|
// eslint-disable-next-line no-param-reassign
|
|
502
|
-
t.
|
|
350
|
+
t.setUpdatedAt(new Date().getMilliseconds());
|
|
503
351
|
});
|
|
352
|
+
stateTransition.setTransitions(transitions);
|
|
504
353
|
|
|
505
|
-
const result = await validateDocumentsBatchTransitionState(
|
|
354
|
+
const result = await validateDocumentsBatchTransitionState(
|
|
355
|
+
stateRepositoryMock, stateTransition,
|
|
356
|
+
);
|
|
506
357
|
|
|
507
|
-
|
|
358
|
+
expect(result).is.instanceOf(ValidationResult);
|
|
508
359
|
|
|
509
360
|
const [error] = result.getErrors();
|
|
510
|
-
|
|
361
|
+
expect(error).is.instanceOf(DocumentTimestampsMismatchError);
|
|
511
362
|
expect(error.getCode()).to.equal(4007);
|
|
512
|
-
|
|
513
|
-
documentTransitions[0].updatedAt = new Date();
|
|
514
|
-
|
|
515
|
-
expect(Buffer.isBuffer(error.getDocumentId())).to.be.true();
|
|
516
|
-
expect(error.getDocumentId()).to.deep.equal(documentTransitions[0].getId().toBuffer());
|
|
517
363
|
});
|
|
518
364
|
|
|
519
|
-
it('should return invalid result if "$createdAt" have violated time window', async () => {
|
|
520
|
-
|
|
521
|
-
create: [
|
|
365
|
+
it('should return invalid result if "$createdAt" have violated time window - Rust', async () => {
|
|
366
|
+
documentTransitionsJs = getDocumentTransitionsFixture({
|
|
367
|
+
create: [documentsJs[0]],
|
|
522
368
|
});
|
|
523
369
|
|
|
524
370
|
stateTransition = new DocumentsBatchTransition({
|
|
525
|
-
ownerId,
|
|
526
|
-
contractId:
|
|
527
|
-
transitions:
|
|
371
|
+
ownerId: ownerIdJs,
|
|
372
|
+
contractId: dataContractJs.getId(),
|
|
373
|
+
transitions: documentTransitionsJs.map((t) => t.toObject()),
|
|
528
374
|
}, [dataContract]);
|
|
529
375
|
|
|
530
|
-
stateTransition.
|
|
531
|
-
|
|
532
|
-
t.
|
|
533
|
-
|
|
534
|
-
t.
|
|
376
|
+
const transitions = stateTransition.getTransitions();
|
|
377
|
+
transitions.forEach((t) => {
|
|
378
|
+
const createdAtMinus6Mins = t.getCreatedAt() - (6 * 60 * 1000);
|
|
379
|
+
t.setCreatedAt(createdAtMinus6Mins);
|
|
380
|
+
t.setUpdatedAt(undefined);
|
|
535
381
|
});
|
|
382
|
+
stateTransition.setTransitions(transitions);
|
|
536
383
|
|
|
537
|
-
const result = await validateDocumentsBatchTransitionState(
|
|
384
|
+
const result = await validateDocumentsBatchTransitionState(
|
|
385
|
+
stateRepositoryMock, stateTransition,
|
|
386
|
+
);
|
|
538
387
|
|
|
539
|
-
|
|
388
|
+
expect(result).is.instanceOf(ValidationResult);
|
|
389
|
+
expect(result.isValid()).is.not.true();
|
|
540
390
|
|
|
541
391
|
const [error] = result.getErrors();
|
|
542
|
-
|
|
392
|
+
expect(error).is.instanceOf(DocumentTimestampWindowViolationError);
|
|
543
393
|
expect(error.getCode()).to.equal(4008);
|
|
394
|
+
expect(error.getTimestampName()).to.equal('createdAt');
|
|
544
395
|
|
|
545
|
-
|
|
546
|
-
|
|
396
|
+
expect(error.getTimestamp().getMilliseconds()).to.equal(
|
|
397
|
+
documentTransitionsJs[0].createdAt.getMilliseconds(),
|
|
547
398
|
);
|
|
548
|
-
documentTransitions[0].updatedAt = undefined;
|
|
549
|
-
|
|
550
|
-
expect(Buffer.isBuffer(error.getDocumentId())).to.be.true();
|
|
551
|
-
expect(error.getDocumentId()).to.deep.equal(documentTransitions[0].getId().toBuffer());
|
|
552
|
-
expect(error.getTimestampName()).to.equal('createdAt');
|
|
553
|
-
expect(error.getTimestamp()).to.deep.equal(documentTransitions[0].createdAt);
|
|
554
399
|
expect(error.getTimeWindowStart()).to.deep.equal(timeWindowStart);
|
|
555
400
|
expect(error.getTimeWindowEnd()).to.deep.equal(timeWindowEnd);
|
|
556
401
|
});
|
|
557
402
|
|
|
558
|
-
it('should return invalid result if "$updatedAt" have violated time window', async () => {
|
|
559
|
-
|
|
560
|
-
create: [
|
|
403
|
+
it('should return invalid result if "$updatedAt" have violated time window - Rust', async () => {
|
|
404
|
+
documentTransitionsJs = getDocumentTransitionsFixture({
|
|
405
|
+
create: [documentsJs[1]],
|
|
561
406
|
});
|
|
562
407
|
|
|
563
408
|
stateTransition = new DocumentsBatchTransition({
|
|
564
|
-
ownerId,
|
|
565
|
-
contractId:
|
|
566
|
-
transitions:
|
|
409
|
+
ownerId: ownerIdJs,
|
|
410
|
+
contractId: dataContractJs.getId(),
|
|
411
|
+
transitions: documentTransitionsJs.map((t) => t.toObject()),
|
|
567
412
|
}, [dataContract]);
|
|
568
413
|
|
|
569
|
-
stateTransition.
|
|
570
|
-
|
|
571
|
-
t.
|
|
572
|
-
|
|
573
|
-
t.
|
|
414
|
+
const transitions = stateTransition.getTransitions();
|
|
415
|
+
transitions.forEach((t) => {
|
|
416
|
+
const createdAtMinus6Mins = t.getUpdatedAt() - (6 * 60 * 1000);
|
|
417
|
+
t.setUpdatedAt(createdAtMinus6Mins);
|
|
418
|
+
t.setCreatedAt(undefined);
|
|
574
419
|
});
|
|
420
|
+
stateTransition.setTransitions(transitions);
|
|
575
421
|
|
|
576
|
-
const result = await validateDocumentsBatchTransitionState(
|
|
422
|
+
const result = await validateDocumentsBatchTransitionState(
|
|
423
|
+
stateRepositoryMock, stateTransition,
|
|
424
|
+
);
|
|
577
425
|
|
|
578
|
-
|
|
426
|
+
expect(result).is.instanceOf(ValidationResult);
|
|
427
|
+
expect(result.isValid()).is.not.true();
|
|
579
428
|
|
|
580
429
|
const [error] = result.getErrors();
|
|
581
|
-
|
|
430
|
+
expect(error).is.instanceOf(DocumentTimestampWindowViolationError);
|
|
582
431
|
expect(error.getCode()).to.equal(4008);
|
|
583
432
|
|
|
584
|
-
|
|
585
|
-
|
|
433
|
+
documentTransitionsJs[0].updatedAt.setMinutes(
|
|
434
|
+
documentTransitionsJs[0].updatedAt.getMinutes() - 6,
|
|
586
435
|
);
|
|
587
|
-
|
|
436
|
+
documentTransitionsJs[0].createdAt = undefined;
|
|
588
437
|
|
|
589
|
-
expect(
|
|
590
|
-
expect(error.getDocumentId()).to.deep.equal(documentTransitions[0].getId().toBuffer());
|
|
438
|
+
expect(error.getDocumentId()).to.deep.equal(documentTransitionsJs[0].getId().toBuffer());
|
|
591
439
|
expect(error.getTimestampName()).to.equal('updatedAt');
|
|
592
|
-
expect(error.getTimestamp()).to.deep.equal(
|
|
440
|
+
expect(error.getTimestamp().getMilliseconds()).to.deep.equal(
|
|
441
|
+
documentTransitionsJs[0].updatedAt.getMilliseconds(),
|
|
442
|
+
);
|
|
593
443
|
expect(error.getTimeWindowStart()).to.deep.equal(timeWindowStart);
|
|
594
444
|
expect(error.getTimeWindowEnd()).to.deep.equal(timeWindowEnd);
|
|
595
445
|
});
|
|
596
446
|
|
|
597
|
-
it('should not validate time in block window on dry run', async () => {
|
|
598
|
-
|
|
599
|
-
create: [
|
|
447
|
+
it('should not validate time in block window on dry run - Rust', async () => {
|
|
448
|
+
documentTransitionsJs = getDocumentTransitionsFixture({
|
|
449
|
+
create: [documentsJs[1]],
|
|
600
450
|
});
|
|
601
451
|
|
|
602
452
|
executeDataTriggersMock.resolves([
|
|
@@ -604,29 +454,31 @@ describe('validateDocumentsBatchTransitionStateFactory', () => {
|
|
|
604
454
|
]);
|
|
605
455
|
|
|
606
456
|
stateTransition = new DocumentsBatchTransition({
|
|
607
|
-
ownerId,
|
|
608
|
-
contractId:
|
|
609
|
-
transitions:
|
|
457
|
+
ownerId: ownerIdJs,
|
|
458
|
+
contractId: dataContractJs.getId(),
|
|
459
|
+
transitions: documentTransitionsJs.map((t) => t.toObject()),
|
|
610
460
|
}, [dataContract]);
|
|
611
461
|
|
|
612
|
-
stateTransition.
|
|
613
|
-
|
|
614
|
-
t.
|
|
462
|
+
const transitions = stateTransition.getTransitions();
|
|
463
|
+
transitions.forEach((t) => {
|
|
464
|
+
const createdAtMinus6Mins = t.getUpdatedAt() - (6 * 60 * 1000);
|
|
465
|
+
t.setUpdatedAt(createdAtMinus6Mins);
|
|
466
|
+
t.setCreatedAt(undefined);
|
|
615
467
|
});
|
|
616
|
-
|
|
468
|
+
stateTransition.setTransitions(transitions);
|
|
617
469
|
stateTransition.getExecutionContext().enableDryRun();
|
|
618
470
|
|
|
619
|
-
const result = await validateDocumentsBatchTransitionState(
|
|
620
|
-
|
|
621
|
-
|
|
471
|
+
const result = await validateDocumentsBatchTransitionState(
|
|
472
|
+
stateRepositoryMock, stateTransition,
|
|
473
|
+
);
|
|
622
474
|
|
|
623
475
|
expect(result).to.be.an.instanceOf(ValidationResult);
|
|
624
476
|
expect(result.isValid()).to.be.true();
|
|
625
477
|
});
|
|
626
478
|
|
|
627
|
-
it('should return valid result if timestamps mismatch on dry run', async () => {
|
|
628
|
-
|
|
629
|
-
create: [
|
|
479
|
+
it('should return valid result if timestamps mismatch on dry run - Rust', async () => {
|
|
480
|
+
documentTransitionsJs = getDocumentTransitionsFixture({
|
|
481
|
+
create: [documentsJs[0]],
|
|
630
482
|
});
|
|
631
483
|
|
|
632
484
|
executeDataTriggersMock.resolves([
|
|
@@ -634,21 +486,21 @@ describe('validateDocumentsBatchTransitionStateFactory', () => {
|
|
|
634
486
|
]);
|
|
635
487
|
|
|
636
488
|
stateTransition = new DocumentsBatchTransition({
|
|
637
|
-
ownerId,
|
|
638
|
-
contractId:
|
|
639
|
-
transitions:
|
|
489
|
+
ownerId: ownerIdJs,
|
|
490
|
+
contractId: dataContractJs.getId(),
|
|
491
|
+
transitions: documentTransitionsJs.map((t) => t.toObject()),
|
|
640
492
|
}, [dataContract]);
|
|
641
493
|
|
|
642
|
-
stateTransition.
|
|
494
|
+
const transitions = stateTransition.getTransitions();
|
|
495
|
+
transitions.forEach((t) => {
|
|
643
496
|
// eslint-disable-next-line no-param-reassign
|
|
644
|
-
t.
|
|
497
|
+
t.setUpdatedAt(new Date().getMilliseconds());
|
|
645
498
|
});
|
|
646
|
-
|
|
647
499
|
stateTransition.getExecutionContext().enableDryRun();
|
|
648
500
|
|
|
649
|
-
const result = await validateDocumentsBatchTransitionState(
|
|
650
|
-
|
|
651
|
-
|
|
501
|
+
const result = await validateDocumentsBatchTransitionState(
|
|
502
|
+
stateRepositoryMock, stateTransition,
|
|
503
|
+
);
|
|
652
504
|
|
|
653
505
|
expect(result).to.be.an.instanceOf(ValidationResult);
|
|
654
506
|
expect(result.isValid()).to.be.true();
|
|
@@ -656,81 +508,83 @@ describe('validateDocumentsBatchTransitionStateFactory', () => {
|
|
|
656
508
|
});
|
|
657
509
|
|
|
658
510
|
describe('REPLACE transition', () => {
|
|
659
|
-
it('should return invalid result if documents with action "replace" have violated time window', async () => {
|
|
660
|
-
|
|
511
|
+
it('should return invalid result if documents with action "replace" have violated time window - Rust', async () => {
|
|
512
|
+
documentTransitionsJs = getDocumentTransitionsFixture({
|
|
661
513
|
create: [],
|
|
662
|
-
replace: [
|
|
514
|
+
replace: [documentsJs[1]],
|
|
663
515
|
});
|
|
664
516
|
|
|
665
517
|
stateTransition = new DocumentsBatchTransition({
|
|
666
|
-
ownerId,
|
|
667
|
-
contractId:
|
|
668
|
-
transitions:
|
|
518
|
+
ownerId: ownerIdJs,
|
|
519
|
+
contractId: dataContractJs.getId(),
|
|
520
|
+
transitions: documentTransitionsJs.map((t) => t.toObject()),
|
|
669
521
|
}, [dataContract]);
|
|
670
522
|
|
|
671
|
-
|
|
672
|
-
|
|
523
|
+
documentsJs[1].updatedAt.setMinutes(
|
|
524
|
+
documentsJs[1].updatedAt.getMinutes() - 6,
|
|
673
525
|
);
|
|
674
526
|
|
|
675
|
-
|
|
527
|
+
const documentToReturn = new Document(documentsJs[1].toObject(), dataContract);
|
|
528
|
+
stateRepositoryMock.fetchDocuments.resolves([documentToReturn]);
|
|
676
529
|
|
|
677
|
-
stateTransition.
|
|
678
|
-
|
|
679
|
-
t.
|
|
530
|
+
const transitions = stateTransition.getTransitions();
|
|
531
|
+
transitions.forEach((t) => {
|
|
532
|
+
const createdAtMinus6Mins = t.getUpdatedAt() - (6 * 60 * 1000);
|
|
533
|
+
t.setUpdatedAt(createdAtMinus6Mins);
|
|
680
534
|
});
|
|
535
|
+
stateTransition.setTransitions(transitions);
|
|
681
536
|
|
|
682
|
-
const result = await validateDocumentsBatchTransitionState(
|
|
683
|
-
|
|
684
|
-
|
|
537
|
+
const result = await validateDocumentsBatchTransitionState(
|
|
538
|
+
stateRepositoryMock, stateTransition,
|
|
539
|
+
);
|
|
685
540
|
|
|
541
|
+
expect(result).is.instanceOf(ValidationResult);
|
|
542
|
+
expect(result.isValid()).is.not.true();
|
|
686
543
|
const [error] = result.getErrors();
|
|
687
544
|
|
|
545
|
+
expect(error).is.instanceOf(DocumentTimestampWindowViolationError);
|
|
688
546
|
expect(error.getCode()).to.equal(4008);
|
|
689
547
|
|
|
690
|
-
|
|
691
|
-
|
|
548
|
+
documentTransitionsJs[0].updatedAt.setMinutes(
|
|
549
|
+
documentTransitionsJs[0].updatedAt.getMinutes() - 6,
|
|
692
550
|
);
|
|
693
551
|
|
|
694
|
-
expect(
|
|
695
|
-
expect(error.getDocumentId()).to.deep.equal(documentTransitions[0].getId().toBuffer());
|
|
552
|
+
expect(error.getDocumentId()).to.deep.equal(documentTransitionsJs[0].getId().toBuffer());
|
|
696
553
|
expect(error.getTimestampName()).to.equal('updatedAt');
|
|
697
|
-
expect(error.getTimestamp()).to.deep.equal(
|
|
554
|
+
expect(error.getTimestamp()).to.deep.equal(documentTransitionsJs[0].updatedAt);
|
|
698
555
|
expect(error.getTimeWindowStart()).to.deep.equal(timeWindowStart);
|
|
699
556
|
expect(error.getTimeWindowEnd()).to.deep.equal(timeWindowEnd);
|
|
700
557
|
});
|
|
701
558
|
|
|
702
|
-
it('should return valid result if documents with action "replace" have violated time window on dry run', async () => {
|
|
703
|
-
|
|
704
|
-
new DataTriggerExecutionResult(),
|
|
705
|
-
]);
|
|
706
|
-
|
|
707
|
-
documentTransitions = getDocumentTransitionsFixture({
|
|
559
|
+
it('should return valid result if documents with action "replace" have violated time window on dry run - Rust', async () => {
|
|
560
|
+
documentTransitionsJs = getDocumentTransitionsFixture({
|
|
708
561
|
create: [],
|
|
709
|
-
replace: [
|
|
562
|
+
replace: [documentsJs[1]],
|
|
710
563
|
});
|
|
711
564
|
|
|
712
565
|
stateTransition = new DocumentsBatchTransition({
|
|
713
|
-
ownerId,
|
|
714
|
-
contractId:
|
|
715
|
-
transitions:
|
|
566
|
+
ownerId: ownerIdJs,
|
|
567
|
+
contractId: dataContractJs.getId(),
|
|
568
|
+
transitions: documentTransitionsJs.map((t) => t.toObject()),
|
|
716
569
|
}, [dataContract]);
|
|
717
570
|
|
|
718
|
-
|
|
719
|
-
|
|
571
|
+
documentsJs[1].updatedAt.setMinutes(
|
|
572
|
+
documentsJs[1].updatedAt.getMinutes() - 6,
|
|
720
573
|
);
|
|
721
574
|
|
|
722
|
-
|
|
575
|
+
const documentToReturn = new Document(documentsJs[1].toObject(), dataContract);
|
|
576
|
+
stateRepositoryMock.fetchDocuments.resolves([documentToReturn]);
|
|
723
577
|
|
|
724
|
-
stateTransition.transitions.forEach((t) => {
|
|
725
|
-
|
|
726
|
-
t.
|
|
578
|
+
const transitions = stateTransition.getTransitions(); transitions.forEach((t) => {
|
|
579
|
+
const createdAtMinus6Mins = t.getUpdatedAt() - (6 * 60 * 1000);
|
|
580
|
+
t.setUpdatedAt(createdAtMinus6Mins);
|
|
727
581
|
});
|
|
728
|
-
|
|
582
|
+
stateTransition.setTransitions(transitions);
|
|
729
583
|
stateTransition.getExecutionContext().enableDryRun();
|
|
730
584
|
|
|
731
|
-
const result = await validateDocumentsBatchTransitionState(
|
|
732
|
-
|
|
733
|
-
|
|
585
|
+
const result = await validateDocumentsBatchTransitionState(
|
|
586
|
+
stateRepositoryMock, stateTransition,
|
|
587
|
+
);
|
|
734
588
|
|
|
735
589
|
expect(result).to.be.an.instanceOf(ValidationResult);
|
|
736
590
|
expect(result.isValid()).to.be.true();
|
|
@@ -738,67 +592,77 @@ describe('validateDocumentsBatchTransitionStateFactory', () => {
|
|
|
738
592
|
});
|
|
739
593
|
});
|
|
740
594
|
|
|
741
|
-
it('should return valid result if document transitions are valid', async () => {
|
|
595
|
+
it('should return valid result if document transitions are valid - Rust', async () => {
|
|
742
596
|
const fetchedDocuments = [
|
|
743
|
-
new Document(
|
|
744
|
-
new Document(
|
|
597
|
+
new Document(documentsJs[1].toObject(), dataContract),
|
|
598
|
+
new Document(documentsJs[2].toObject(), dataContract),
|
|
745
599
|
];
|
|
746
600
|
|
|
747
|
-
|
|
601
|
+
stateRepositoryMock.fetchDocuments.resolves(fetchedDocuments);
|
|
748
602
|
|
|
749
|
-
|
|
750
|
-
|
|
603
|
+
documentsJs[1].setRevision(1);
|
|
604
|
+
documentsJs[2].setRevision(1);
|
|
751
605
|
|
|
752
|
-
|
|
606
|
+
documentTransitionsJs = getDocumentTransitionsFixture({
|
|
753
607
|
create: [],
|
|
754
|
-
replace: [
|
|
755
|
-
delete: [
|
|
608
|
+
replace: [documentsJs[1]],
|
|
609
|
+
delete: [documentsJs[2]],
|
|
756
610
|
});
|
|
757
611
|
|
|
758
612
|
stateTransition = new DocumentsBatchTransition({
|
|
759
|
-
ownerId,
|
|
760
|
-
contractId:
|
|
761
|
-
transitions:
|
|
613
|
+
ownerId: ownerIdJs,
|
|
614
|
+
contractId: dataContractJs.getId(),
|
|
615
|
+
transitions: documentTransitionsJs.map((t) => t.toObject()),
|
|
762
616
|
}, [dataContract]);
|
|
763
617
|
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
const dataTriggersExecutionContext = new DataTriggerExecutionContext(
|
|
767
|
-
stateRepositoryMock,
|
|
768
|
-
ownerId,
|
|
769
|
-
dataContract,
|
|
770
|
-
executionContext,
|
|
618
|
+
const result = await validateDocumentsBatchTransitionState(
|
|
619
|
+
stateRepositoryMock, stateTransition,
|
|
771
620
|
);
|
|
772
621
|
|
|
773
|
-
executeDataTriggersMock.resolves([
|
|
774
|
-
new DataTriggerExecutionResult(),
|
|
775
|
-
]);
|
|
776
|
-
|
|
777
|
-
const result = await validateDocumentsBatchTransitionState(stateTransition);
|
|
778
|
-
|
|
779
622
|
expect(result).to.be.an.instanceOf(ValidationResult);
|
|
780
623
|
expect(result.isValid()).to.be.true();
|
|
781
624
|
|
|
782
|
-
expect(stateRepositoryMock.fetchDataContract).to.have.been.
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
);
|
|
625
|
+
expect(stateRepositoryMock.fetchDataContract).to.have.been.calledOnce();
|
|
626
|
+
const [fetchDataContractId] = stateRepositoryMock.fetchDataContract.getCall(0).args;
|
|
627
|
+
expect(fetchDataContractId.toBuffer()).to.deep.equal(dataContract.getId().toBuffer());
|
|
786
628
|
|
|
787
|
-
expect(
|
|
788
|
-
|
|
789
|
-
executionContext,
|
|
790
|
-
);
|
|
629
|
+
expect(stateRepositoryMock.fetchDocuments).to.have.been.calledOnce();
|
|
630
|
+
});
|
|
791
631
|
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
[
|
|
795
|
-
dataContract,
|
|
796
|
-
|
|
797
|
-
|
|
632
|
+
it('should return valid result if document transitions are valid - Rust', async () => {
|
|
633
|
+
const fetchedDocuments = [
|
|
634
|
+
new Document(documentsJs[1].toObject(), dataContract),
|
|
635
|
+
new Document(documentsJs[2].toObject(), dataContract),
|
|
636
|
+
];
|
|
637
|
+
|
|
638
|
+
stateRepositoryMock.fetchDocuments.resolves(fetchedDocuments);
|
|
639
|
+
|
|
640
|
+
documentsJs[1].setRevision(1);
|
|
641
|
+
documentsJs[2].setRevision(1);
|
|
642
|
+
|
|
643
|
+
documentTransitionsJs = getDocumentTransitionsFixture({
|
|
644
|
+
create: [],
|
|
645
|
+
replace: [documentsJs[1]],
|
|
646
|
+
delete: [documentsJs[2]],
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
stateTransition = new DocumentsBatchTransition({
|
|
650
|
+
ownerId: ownerIdJs,
|
|
651
|
+
contractId: dataContractJs.getId(),
|
|
652
|
+
transitions: documentTransitionsJs.map((t) => t.toObject()),
|
|
653
|
+
}, [dataContract]);
|
|
798
654
|
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
dataTriggersExecutionContext,
|
|
655
|
+
const result = await validateDocumentsBatchTransitionState(
|
|
656
|
+
stateRepositoryMock, stateTransition,
|
|
802
657
|
);
|
|
658
|
+
|
|
659
|
+
expect(result).to.be.an.instanceOf(ValidationResult);
|
|
660
|
+
expect(result.isValid()).to.be.true();
|
|
661
|
+
|
|
662
|
+
expect(stateRepositoryMock.fetchDataContract).to.have.been.calledOnce();
|
|
663
|
+
const [fetchDataContractId] = stateRepositoryMock.fetchDataContract.getCall(0).args;
|
|
664
|
+
expect(fetchDataContractId.toBuffer()).to.deep.equal(dataContract.getId().toBuffer());
|
|
665
|
+
|
|
666
|
+
expect(stateRepositoryMock.fetchDocuments).to.have.been.calledOnce();
|
|
803
667
|
});
|
|
804
668
|
});
|