@dashevo/wasm-dpp 0.24.0-dev.11 → 0.24.0-dev.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.toml +3 -0
- package/README.md +5 -1
- package/dist/index.js +1 -1
- package/dist/index.js.LICENSE.txt +9 -0
- package/dist/lib/dpp.d.ts +9 -0
- package/dist/lib/errors/AbstractConsensusError.d.ts +10 -0
- package/dist/lib/errors/DPPError.d.ts +5 -0
- package/dist/lib/errors/patchConsensusErrors.d.ts +1 -0
- package/dist/lib/{patchIdentifier.d.ts → identifier/patchIdentifier.d.ts} +1 -1
- package/dist/{index.d.ts → lib/index.d.ts} +1 -1
- package/dist/lib/utils/extend.d.ts +1 -0
- package/dist/wasm/wasm_dpp.d.ts +1595 -518
- package/karma.conf.js +5 -0
- package/lib/dpp.ts +24 -0
- package/lib/errors/AbstractConsensusError.ts +13 -0
- package/lib/errors/DPPError.ts +15 -0
- package/lib/errors/patchConsensusErrors.ts +175 -0
- package/lib/{patchIdentifier.ts → identifier/patchIdentifier.ts} +6 -5
- package/{index.ts → lib/index.ts} +5 -4
- package/lib/test/bootstrap.js +5 -0
- package/lib/test/expect/expectError.js +4 -2
- package/lib/test/mocks/getBlsAdapterMock.js +36 -0
- package/lib/test/utils/newDocumentsContainer.js +36 -0
- package/lib/utils/extend.ts +6 -0
- package/package.json +9 -6
- package/src/bls_adapter.rs +16 -1
- package/src/data_contract/data_contract.rs +35 -7
- package/src/data_contract/errors/invalid_data_contract.rs +21 -0
- package/src/data_contract/errors/invalid_document_type.rs +1 -1
- package/src/data_contract/index.rs +56 -1
- package/src/data_contract/mod.rs +1 -0
- package/src/data_contract/state_transition/data_contract_create_transition/mod.rs +6 -8
- package/src/data_contract/state_transition/data_contract_create_transition/validation.rs +4 -4
- package/src/data_contract/state_transition/data_contract_update_transition/apply.rs +44 -0
- package/src/data_contract/state_transition/data_contract_update_transition/mod.rs +145 -0
- package/src/data_contract/state_transition/data_contract_update_transition/validation.rs +49 -0
- package/src/data_contract/state_transition/mod.rs +2 -0
- package/src/data_contract_factory/data_contract_factory.rs +25 -12
- 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 +192 -0
- package/src/document/mod.rs +222 -30
- package/src/document/state_transition/document_batch_transition/document_transition/document_create_transition.rs +47 -1
- package/src/document/state_transition/document_batch_transition/document_transition/document_delete_transition.rs +25 -1
- package/src/document/state_transition/document_batch_transition/document_transition/document_replace_transition.rs +65 -0
- package/src/document/state_transition/document_batch_transition/document_transition/mod.rs +123 -3
- package/src/document/state_transition/document_batch_transition/mod.rs +378 -0
- package/src/document/validator.rs +30 -0
- package/src/errors/consensus/basic/data_contract/data_contract_max_depth_exceed_error.rs +5 -5
- package/src/errors/consensus/basic/document/duplicate_document_transitions_with_ids_error.rs +4 -4
- package/src/errors/consensus/basic/document/duplicate_document_transitions_with_indices_error.rs +36 -0
- package/src/errors/consensus/basic/document/missing_document_transition_type_error.rs +20 -0
- package/src/errors/consensus/basic/document/mod.rs +4 -0
- package/src/errors/consensus/basic/identity/duplicated_identity_public_key_error.rs +2 -2
- package/src/errors/consensus/basic/identity/duplicated_identity_public_key_id_error.rs +2 -2
- 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_public_key_security_level_error.rs +2 -2
- package/src/errors/consensus/basic/json_schema_error.rs +1 -1
- package/src/errors/consensus_error.rs +15 -8
- package/src/errors/dpp_error.rs +17 -0
- package/src/errors/from.rs +6 -1
- package/src/errors/js_conversion.rs +19 -4
- package/src/errors/mod.rs +3 -0
- package/src/errors/protocol_error.rs +15 -0
- package/src/{identifier.rs → identifier/mod.rs} +48 -3
- 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/mod.rs +7 -0
- package/src/identity/errors/unknown_asset_lock_proof_type_error.rs +26 -0
- package/src/{identity_facade.rs → identity/identity_facade.rs} +3 -5
- package/src/{identity_public_key → identity/identity_public_key}/key_type.rs +0 -0
- package/src/{identity_public_key → identity/identity_public_key}/mod.rs +41 -10
- package/src/{identity_public_key → identity/identity_public_key}/purpose.rs +0 -0
- package/src/{identity_public_key → identity/identity_public_key}/security_level.rs +0 -0
- package/src/{identity.rs → identity/mod.rs} +20 -12
- 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 +335 -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 +46 -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 +280 -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/mod.rs +9 -0
- package/src/identity/state_transition/validate_public_key_signatures.rs +59 -0
- package/src/identity/validation/mod.rs +3 -0
- package/src/identity/validation/public_keys_validator.rs +76 -0
- package/src/identity_public_key/public_keys_validator.rs +1 -1
- package/src/lib.rs +3 -6
- package/src/lodash.rs +7 -0
- package/src/state_repository.rs +188 -36
- package/src/state_transition/mod.rs +12 -0
- package/src/utils.rs +102 -7
- package/src/validation/json_schema_validator.rs +41 -0
- package/src/validation/mod.rs +5 -0
- package/src/{validation_result.rs → validation/validation_result.rs} +23 -5
- package/src/version/mod.rs +2 -0
- package/src/version/protocol_version.rs +26 -0
- package/test/integration/dataContract/validation/validateDataContractFactory.spec.js +579 -502
- package/test/integration/identity/stateTransition/IdentityCreateTransition/validation/basic/validateIdentityCreateTransitionBasicFactory.spec.js +175 -165
- package/test/integration/identity/stateTransition/IdentityTopUpTransition/validation/basic/validateIdentityTopUpTransitionBasicFactory.spec.js +83 -114
- package/test/integration/identity/stateTransition/IdentityUpdateTransition/validation/state/validateIdentityUpdateTransitionStateFactory.spec.js +1 -1
- package/test/integration/identity/stateTransition/assetLockProof/chain/validateChainAssetLockProofStructureFactory.spec.js +82 -91
- package/test/integration/identity/stateTransition/assetLockProof/fetchAssetLockTransactionOutputFactory.spec.js +75 -31
- package/test/integration/identity/stateTransition/assetLockProof/instant/validateInstantAssetLockProofStructureFactory.spec.js +93 -148
- package/test/integration/identity/stateTransition/assetLockProof/validateAssetLockTransactionFactory.spec.js +63 -75
- package/test/integration/identity/stateTransition/validatePublicKeySignaturesFactory.spec.js +48 -19
- package/test/integration/identity/validation/validatePublicKeysFactory.spec.js +79 -114
- package/test/integration/stateTransition/AbstractStateTransitionIdentitySigned.spec.js +0 -11
- package/test/integration/stateTransition/StateTransitionFacade.spec.js +1 -1
- package/test/integration/stateTransition/calculateStateTransitionFeeFactory.spec.js +135 -0
- package/test/unit/dataContract/DataContract.spec.js +5 -9
- package/test/unit/dataContract/DataContractFactory.spec.js +13 -6
- package/test/unit/dataContract/createDataContract.spec.js +0 -1
- package/test/unit/dataContract/errors/InvalidDataContractError.spec.js +11 -3
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/DataContractCreateTransition.spec.js +3 -3
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/validation/state/validateDataContractCreateTransitionStateFactory.spec.js +20 -16
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/DataContractUpdateTransition.spec.js +24 -60
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/applyDataContractUpdateTransitionFactory.spec.js +27 -23
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/validation/basic/validateIndicesAreBackwardCompatible.spec.js +29 -12
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/validation/state/validateDataContractUpdateTransitionStateFactory.spec.js +66 -49
- package/test/unit/dataContract/validation/validateDataContractPatterns.spec.js +73 -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 +325 -91
- package/test/unit/document/stateTransition/DocumetsBatchTransition/DocumentsBatchTransition.spec.js +142 -64
- package/test/unit/document/stateTransition/DocumetsBatchTransition/applyDocumentsBatchTransitionFactory.spec.js +1 -1
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/validateDocumentsBatchTransitionStateFactory.spec.js +1 -1
- package/test/unit/identity/Identity.spec.js +2 -2
- package/test/unit/identity/IdentityPublicKey.spec.js +25 -31
- package/test/unit/identity/stateTransition/IdentityCreateTransition/IdentityCreateTransition.spec.js +69 -30
- package/test/unit/identity/stateTransition/IdentityCreateTransition/applyIdentityCreateTransitionFactory.spec.js +32 -32
- package/test/unit/identity/stateTransition/IdentityCreateTransition/validation/state/validateIdentityCreateTransitionStateFactory.spec.js +56 -25
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/IdentityTopUpTransition.spec.js +36 -16
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/applyIdentityTopUpTransitionFactory.spec.js +48 -46
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/validation/state/validateIdentityTopUpTransitionStateFactory.spec.js +24 -6
- 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/tsconfig.json +1 -1
- package/wasm/package.json +5 -0
- package/wasm/wasm_dpp.d.ts +1595 -518
- package/wasm/wasm_dpp.js +5007 -2172
- package/wasm/wasm_dpp_bg.js +1 -1
- package/wasm/wasm_dpp_bg.wasm +0 -0
- package/wasm/wasm_dpp_bg.wasm.d.ts +566 -365
- package/webpack.config.js +10 -1
- package/test/integration/stateTransition/calculateStateTransitionFee.spec.js +0 -32
- package/test/unit/dataContract/validation/validateDataContractMaxDepthFactory.spec.js +0 -93
- package/test/unit/dataContract/validation/validateDataContractPatternsFactory.spec.js +0 -64
|
@@ -1,53 +1,103 @@
|
|
|
1
1
|
const bs58 = require('bs58');
|
|
2
|
-
|
|
3
|
-
const Document = require('@dashevo/dpp/lib/document/Document');
|
|
4
|
-
|
|
2
|
+
const DocumentJs = require('@dashevo/dpp/lib/document/Document');
|
|
5
3
|
const DocumentCreateTransition = require('@dashevo/dpp/lib/document/stateTransition/DocumentsBatchTransition/documentTransition/DocumentCreateTransition');
|
|
6
|
-
|
|
7
4
|
const getDocumentsFixture = require('@dashevo/dpp/lib/test/fixtures/getDocumentsFixture');
|
|
8
5
|
const getDataContractFixture = require('@dashevo/dpp/lib/test/fixtures/getDataContractFixture');
|
|
9
6
|
const getDocumentTransitionsFixture = require('@dashevo/dpp/lib/test/fixtures/getDocumentTransitionsFixture');
|
|
10
|
-
|
|
11
7
|
const ValidationResult = require('@dashevo/dpp/lib/validation/ValidationResult');
|
|
8
|
+
const IdentifierJs = require('@dashevo/dpp/lib/identifier/Identifier');
|
|
12
9
|
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const InvalidInitialRevisionError = require('@dashevo/dpp/lib/document/errors/InvalidInitialRevisionError');
|
|
21
|
-
const SerializedObjectParsingError = require('@dashevo/dpp/lib/errors/consensus/basic/decode/SerializedObjectParsingError');
|
|
10
|
+
const InvalidDocumentTypeErrorJs = require('@dashevo/dpp/lib/errors/InvalidDocumentTypeError');
|
|
11
|
+
const InvalidDocumentErrorJs = require('@dashevo/dpp/lib/document/errors/InvalidDocumentError');
|
|
12
|
+
const InvalidActionNameErrorJs = require('@dashevo/dpp/lib/document/errors/InvalidActionNameError');
|
|
13
|
+
const NoDocumentsSuppliedErrorJs = require('@dashevo/dpp/lib/document/errors/NoDocumentsSuppliedError');
|
|
14
|
+
const MismatchOwnerIdsErrorJs = require('@dashevo/dpp/lib/document/errors/MismatchOwnerIdsError');
|
|
15
|
+
const InvalidInitialRevisionErrorJs = require('@dashevo/dpp/lib/document/errors/InvalidInitialRevisionError');
|
|
16
|
+
const SerializedObjectParsingErrorJs = require('@dashevo/dpp/lib/errors/consensus/basic/decode/SerializedObjectParsingError');
|
|
22
17
|
|
|
18
|
+
const createStateRepositoryMock = require('@dashevo/dpp/lib/test/mocks/createStateRepositoryMock');
|
|
23
19
|
const generateRandomIdentifier = require('@dashevo/dpp/lib/test/utils/generateRandomIdentifier');
|
|
24
20
|
const createDPPMock = require('@dashevo/dpp/lib/test/mocks/createDPPMock');
|
|
25
21
|
const SomeConsensusError = require('@dashevo/dpp/lib/test/mocks/SomeConsensusError');
|
|
26
22
|
const entropyGenerator = require('@dashevo/dpp/lib/util/entropyGenerator');
|
|
27
|
-
const
|
|
23
|
+
const DocumentFactoryJS = require('@dashevo/dpp/lib/document/DocumentFactory');
|
|
24
|
+
|
|
25
|
+
const newDocumentsContainer = require('../../../lib/test/utils/newDocumentsContainer');
|
|
26
|
+
|
|
27
|
+
const { default: loadWasmDpp } = require('../../../dist');
|
|
28
|
+
|
|
29
|
+
let Identifier;
|
|
30
|
+
let DocumentFactory;
|
|
31
|
+
let DataContract;
|
|
32
|
+
let Document;
|
|
33
|
+
let DocumentValidator;
|
|
34
|
+
let ProtocolVersionValidator;
|
|
35
|
+
|
|
36
|
+
let InvalidDocumentTypeInDataContractError;
|
|
37
|
+
let InvalidDocumentError;
|
|
38
|
+
let JsonSchemaError;
|
|
39
|
+
let NoDocumentsSuppliedError;
|
|
40
|
+
let MismatchOwnerIdsError;
|
|
41
|
+
let InvalidInitialRevisionError;
|
|
28
42
|
|
|
29
43
|
describe('DocumentFactory', () => {
|
|
30
44
|
let decodeProtocolEntityMock;
|
|
31
45
|
let generateEntropyMock;
|
|
32
46
|
let validateDocumentMock;
|
|
33
47
|
let fetchAndValidateDataContractMock;
|
|
48
|
+
let stateRepositoryMock;
|
|
49
|
+
let ownerIdJs;
|
|
34
50
|
let ownerId;
|
|
35
51
|
let dataContract;
|
|
52
|
+
let dataContractJs;
|
|
36
53
|
let document;
|
|
54
|
+
let documentJs;
|
|
55
|
+
let documentsJs;
|
|
37
56
|
let documents;
|
|
38
57
|
let rawDocument;
|
|
58
|
+
let rawDocumentJs;
|
|
59
|
+
let factoryJs;
|
|
39
60
|
let factory;
|
|
40
61
|
let fakeTime;
|
|
41
62
|
let fakeTimeDate;
|
|
42
63
|
let entropy;
|
|
43
64
|
let dppMock;
|
|
44
65
|
|
|
66
|
+
beforeEach(async () => {
|
|
67
|
+
({
|
|
68
|
+
Identifier, ProtocolVersionValidator, DocumentValidator, DocumentFactory,
|
|
69
|
+
DataContract, Document,
|
|
70
|
+
// Errors:
|
|
71
|
+
InvalidDocumentTypeInDataContractError,
|
|
72
|
+
InvalidDocumentError,
|
|
73
|
+
JsonSchemaError,
|
|
74
|
+
NoDocumentsSuppliedError,
|
|
75
|
+
MismatchOwnerIdsError,
|
|
76
|
+
InvalidInitialRevisionError,
|
|
77
|
+
} = await loadWasmDpp());
|
|
78
|
+
});
|
|
79
|
+
|
|
45
80
|
beforeEach(function beforeEach() {
|
|
46
|
-
|
|
47
|
-
|
|
81
|
+
const protocolValidator = new ProtocolVersionValidator();
|
|
82
|
+
const documentValidator = new DocumentValidator(protocolValidator);
|
|
83
|
+
|
|
84
|
+
({ ownerId: ownerIdJs } = getDocumentsFixture);
|
|
85
|
+
ownerId = Identifier.from(ownerIdJs);
|
|
48
86
|
|
|
49
|
-
|
|
50
|
-
|
|
87
|
+
dataContractJs = getDataContractFixture();
|
|
88
|
+
dataContract = DataContract.fromBuffer(dataContractJs.toBuffer());
|
|
89
|
+
const dc = DataContract.fromBuffer(dataContractJs.toBuffer());
|
|
90
|
+
|
|
91
|
+
documentsJs = getDocumentsFixture(dataContractJs);
|
|
92
|
+
documents = documentsJs.map((d) => {
|
|
93
|
+
const doc = new Document(d.toObject(), dataContract);
|
|
94
|
+
doc.setEntropy(d.entropy);
|
|
95
|
+
return doc;
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
([, , , documentJs] = documentsJs);
|
|
99
|
+
rawDocumentJs = documentJs.toObject();
|
|
100
|
+
([, , , document] = documents);
|
|
51
101
|
rawDocument = document.toObject();
|
|
52
102
|
|
|
53
103
|
decodeProtocolEntityMock = this.sinonSandbox.stub();
|
|
@@ -55,19 +105,20 @@ describe('DocumentFactory', () => {
|
|
|
55
105
|
validateDocumentMock = this.sinonSandbox.stub();
|
|
56
106
|
|
|
57
107
|
validateDocumentMock.returns(new ValidationResult());
|
|
58
|
-
|
|
59
108
|
entropy = bs58.decode('789');
|
|
60
|
-
|
|
61
109
|
generateEntropyMock.returns(entropy);
|
|
62
110
|
|
|
63
111
|
const fetchContractResult = new ValidationResult();
|
|
64
|
-
fetchContractResult.setData(
|
|
112
|
+
fetchContractResult.setData(dataContractJs);
|
|
65
113
|
|
|
66
|
-
|
|
114
|
+
stateRepositoryMock = createStateRepositoryMock(this.sinonSandbox);
|
|
115
|
+
stateRepositoryMock.fetchDataContract.returns(dc);
|
|
67
116
|
|
|
117
|
+
fetchAndValidateDataContractMock = this.sinonSandbox.stub().returns(fetchContractResult);
|
|
68
118
|
dppMock = createDPPMock();
|
|
69
119
|
|
|
70
|
-
factory = new DocumentFactory(
|
|
120
|
+
factory = new DocumentFactory(1, documentValidator, stateRepositoryMock);
|
|
121
|
+
factoryJs = new DocumentFactoryJS(
|
|
71
122
|
dppMock,
|
|
72
123
|
validateDocumentMock,
|
|
73
124
|
fetchAndValidateDataContractMock,
|
|
@@ -85,54 +136,96 @@ describe('DocumentFactory', () => {
|
|
|
85
136
|
|
|
86
137
|
describe('create', () => {
|
|
87
138
|
it('should return new Document with specified type and data', () => {
|
|
139
|
+
// NiceDocument is used instead of IndexedDocument, because the NiceDocument
|
|
140
|
+
// should be valid for this test and it passes the DataContract validation.
|
|
141
|
+
// The previous version of test passed due to the fact that
|
|
142
|
+
// the mocked DataContract validator always returned true.
|
|
143
|
+
const [niceDocument] = documentsJs;
|
|
144
|
+
|
|
145
|
+
const newRawDocument = niceDocument.toObject();
|
|
88
146
|
const contractId = bs58.decode('FQco85WbwNgb5ix8QQAH6wurMcgEC5ENSCv5ixG9cj12');
|
|
89
147
|
const name = 'Cutie';
|
|
90
148
|
|
|
91
|
-
|
|
92
|
-
|
|
149
|
+
ownerIdJs = bs58.decode('5zcXZpTLWFwZjKjq3ME5KVavtZa9YUaZESVzrndehBhq');
|
|
150
|
+
ownerId = Identifier.from(ownerIdJs);
|
|
151
|
+
|
|
152
|
+
dataContractJs.id = IdentifierJs.from(contractId);
|
|
153
|
+
dataContract.setId(Identifier.from(contractId));
|
|
154
|
+
|
|
155
|
+
const newDocumentJs = factoryJs.create(
|
|
156
|
+
dataContractJs,
|
|
157
|
+
ownerIdJs,
|
|
158
|
+
newRawDocument.$type,
|
|
159
|
+
{ name },
|
|
160
|
+
);
|
|
93
161
|
|
|
94
162
|
const newDocument = factory.create(
|
|
95
163
|
dataContract,
|
|
96
|
-
|
|
97
|
-
|
|
164
|
+
ownerIdJs,
|
|
165
|
+
newRawDocument.$type,
|
|
98
166
|
{ name },
|
|
99
167
|
);
|
|
100
168
|
|
|
101
169
|
expect(newDocument).to.be.an.instanceOf(Document);
|
|
170
|
+
expect(newDocumentJs).to.be.an.instanceOf(DocumentJs);
|
|
102
171
|
|
|
103
|
-
expect(
|
|
172
|
+
expect(newDocumentJs.getType()).to.equal(newRawDocument.$type);
|
|
173
|
+
expect(newDocument.getType()).to.equal(newRawDocument.$type);
|
|
104
174
|
|
|
175
|
+
expect(newDocumentJs.get('name')).to.equal(name);
|
|
105
176
|
expect(newDocument.get('name')).to.equal(name);
|
|
106
177
|
|
|
178
|
+
expect(newDocumentJs.getDataContractId().toBuffer()).to.deep.equal(contractId);
|
|
107
179
|
expect(newDocument.getDataContractId().toBuffer()).to.deep.equal(contractId);
|
|
108
|
-
|
|
180
|
+
|
|
181
|
+
expect(newDocumentJs.getOwnerId().toBuffer()).to.deep.equal(ownerIdJs);
|
|
182
|
+
expect(newDocument.getOwnerId().toBuffer()).to.deep.equal(ownerIdJs);
|
|
109
183
|
|
|
110
184
|
expect(generateEntropyMock).to.have.been.calledOnce();
|
|
111
|
-
expect(
|
|
185
|
+
expect(newDocumentJs.getEntropy()).to.deep.equal(entropy);
|
|
112
186
|
|
|
187
|
+
expect(newDocumentJs.getRevision()).to.equal(DocumentCreateTransition.INITIAL_REVISION);
|
|
113
188
|
expect(newDocument.getRevision()).to.equal(DocumentCreateTransition.INITIAL_REVISION);
|
|
114
189
|
|
|
115
|
-
expect(
|
|
190
|
+
expect(newDocumentJs.getId()).to.deep.equal(bs58.decode('E9QpjZMD7CPAGa7x2ABuLFPvBLZjhPji4TMrUfSP3Hk9'));
|
|
191
|
+
// in case of rust version, it is impossible to test the ID, because the ID
|
|
192
|
+
// is generated based on entropy generator which generates different output
|
|
193
|
+
// every time and it cannot be mocked. ID generation should be verified
|
|
194
|
+
// in a true unit test. Not here.
|
|
195
|
+
expect(newDocument.getEntropy()).not.to.deep.be.equal(Buffer.alloc(32));
|
|
116
196
|
|
|
117
|
-
expect(
|
|
118
|
-
expect(newDocument.getCreatedAt()
|
|
197
|
+
expect(newDocumentJs.getCreatedAt().getTime()).to.be.equal(fakeTimeDate.getTime());
|
|
198
|
+
expect(newDocument.getCreatedAt()).to.be.an('number');
|
|
119
199
|
});
|
|
120
200
|
|
|
121
201
|
it('should throw an error if type is not defined', () => {
|
|
122
202
|
const type = 'wrong';
|
|
123
203
|
|
|
124
204
|
try {
|
|
125
|
-
|
|
205
|
+
factoryJs.create(dataContractJs, ownerIdJs, type);
|
|
206
|
+
|
|
207
|
+
expect.fail('InvalidDocumentTypeError should be thrown');
|
|
208
|
+
} catch (e) {
|
|
209
|
+
expect(e).to.be.an.instanceOf(InvalidDocumentTypeErrorJs);
|
|
210
|
+
expect(e.getType()).to.equal(type);
|
|
211
|
+
expect(e.getDataContract()).to.equal(dataContractJs);
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('should throw an error if type is not defined - Rust', () => {
|
|
216
|
+
const type = 'wrong';
|
|
217
|
+
|
|
218
|
+
try {
|
|
219
|
+
factory.create(dataContract, ownerId, type, {});
|
|
126
220
|
|
|
127
221
|
expect.fail('InvalidDocumentTypeError should be thrown');
|
|
128
222
|
} catch (e) {
|
|
129
|
-
expect(e).to.be.an.instanceOf(
|
|
223
|
+
expect(e).to.be.an.instanceOf(InvalidDocumentTypeInDataContractError);
|
|
130
224
|
expect(e.getType()).to.equal(type);
|
|
131
|
-
expect(e.getDataContract()).to.equal(dataContract);
|
|
132
225
|
}
|
|
133
226
|
});
|
|
134
227
|
|
|
135
|
-
it('should throw an error if validation
|
|
228
|
+
it('should throw an error if validation failed', () => {
|
|
136
229
|
const error = new Error('validation failed');
|
|
137
230
|
const validationResult = new ValidationResult();
|
|
138
231
|
validationResult.addError(error);
|
|
@@ -140,7 +233,23 @@ describe('DocumentFactory', () => {
|
|
|
140
233
|
validateDocumentMock.returns(validationResult);
|
|
141
234
|
|
|
142
235
|
try {
|
|
143
|
-
|
|
236
|
+
factoryJs.create(dataContractJs, ownerIdJs, rawDocumentJs.$type);
|
|
237
|
+
|
|
238
|
+
expect.fail('InvalidDocumentError should be thrown');
|
|
239
|
+
} catch (e) {
|
|
240
|
+
expect(e).to.be.an.instanceOf(InvalidDocumentErrorJs);
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it('should throw an error if validation failed - Rust', () => {
|
|
245
|
+
const error = new Error('validation failed');
|
|
246
|
+
const validationResult = new ValidationResult();
|
|
247
|
+
validationResult.addError(error);
|
|
248
|
+
|
|
249
|
+
validateDocumentMock.returns(validationResult);
|
|
250
|
+
|
|
251
|
+
try {
|
|
252
|
+
factory.create(dataContract, ownerId, rawDocumentJs.$type, {});
|
|
144
253
|
|
|
145
254
|
expect.fail('InvalidDocumentError should be thrown');
|
|
146
255
|
} catch (e) {
|
|
@@ -153,18 +262,27 @@ describe('DocumentFactory', () => {
|
|
|
153
262
|
it('should return new Data Contract with data from passed object', async () => {
|
|
154
263
|
validateDocumentMock.returns(new ValidationResult());
|
|
155
264
|
|
|
156
|
-
const result = await
|
|
265
|
+
const result = await factoryJs.createFromObject(rawDocumentJs);
|
|
157
266
|
|
|
158
|
-
expect(result).to.be.an.instanceOf(
|
|
159
|
-
expect(result.toObject()).to.deep.equal(
|
|
267
|
+
expect(result).to.be.an.instanceOf(DocumentJs);
|
|
268
|
+
expect(result.toObject()).to.deep.equal(documentJs.toObject());
|
|
160
269
|
|
|
161
|
-
expect(fetchAndValidateDataContractMock).to.have.been.calledOnceWithExactly(
|
|
270
|
+
expect(fetchAndValidateDataContractMock).to.have.been.calledOnceWithExactly(rawDocumentJs);
|
|
162
271
|
|
|
163
272
|
expect(validateDocumentMock).to.have.been.calledOnceWithExactly(
|
|
164
|
-
|
|
273
|
+
rawDocumentJs, dataContractJs,
|
|
165
274
|
);
|
|
166
275
|
});
|
|
167
276
|
|
|
277
|
+
it('should return new Data Contract with data from passed object - Rust', async () => {
|
|
278
|
+
const result = await factory.createFromObject(rawDocument);
|
|
279
|
+
|
|
280
|
+
expect(result).to.be.an.instanceOf(Document);
|
|
281
|
+
expect(result.toJSON()).to.deep.equal(document.toJSON());
|
|
282
|
+
|
|
283
|
+
expect(stateRepositoryMock.fetchDataContract).to.have.been.calledOnce();
|
|
284
|
+
});
|
|
285
|
+
|
|
168
286
|
it('should return new Document without validation if "skipValidation" option is passed', async function it() {
|
|
169
287
|
const resultMock = {
|
|
170
288
|
isValid: () => true,
|
|
@@ -174,16 +292,25 @@ describe('DocumentFactory', () => {
|
|
|
174
292
|
|
|
175
293
|
fetchAndValidateDataContractMock.resolves(resultMock);
|
|
176
294
|
|
|
177
|
-
const result = await
|
|
295
|
+
const result = await factoryJs.createFromObject(rawDocumentJs, { skipValidation: true });
|
|
178
296
|
|
|
179
|
-
expect(result).to.be.an.instanceOf(
|
|
180
|
-
expect(result.toObject()).to.deep.equal(
|
|
297
|
+
expect(result).to.be.an.instanceOf(DocumentJs);
|
|
298
|
+
expect(result.toObject()).to.deep.equal(documentJs.toObject());
|
|
181
299
|
|
|
182
|
-
expect(fetchAndValidateDataContractMock).to.have.been.calledOnceWithExactly(
|
|
300
|
+
expect(fetchAndValidateDataContractMock).to.have.been.calledOnceWithExactly(rawDocumentJs);
|
|
183
301
|
expect(validateDocumentMock).to.have.not.been.called();
|
|
184
302
|
expect(resultMock.merge).to.have.not.been.called();
|
|
185
303
|
});
|
|
186
304
|
|
|
305
|
+
it('should return new Document without validation if "skipValidation" option is passed - Rust', async () => {
|
|
306
|
+
delete rawDocument.lastName;
|
|
307
|
+
const result = await factory.createFromObject(rawDocument, { skipValidation: true });
|
|
308
|
+
expect(result).to.be.an.instanceOf(Document);
|
|
309
|
+
|
|
310
|
+
expect(result.toObject()).to.deep.equal(rawDocument);
|
|
311
|
+
expect(stateRepositoryMock.fetchDataContract).to.have.been.calledOnce();
|
|
312
|
+
});
|
|
313
|
+
|
|
187
314
|
it('should throw InvalidDocumentError if passed object is not valid', async () => {
|
|
188
315
|
const validationError = new SomeConsensusError('test');
|
|
189
316
|
|
|
@@ -192,20 +319,41 @@ describe('DocumentFactory', () => {
|
|
|
192
319
|
);
|
|
193
320
|
|
|
194
321
|
try {
|
|
195
|
-
await
|
|
322
|
+
await factoryJs.createFromObject(rawDocumentJs);
|
|
196
323
|
|
|
197
324
|
expect.fail('InvalidDocumentError should be thrown');
|
|
198
325
|
} catch (e) {
|
|
199
|
-
expect(e).to.be.an.instanceOf(
|
|
326
|
+
expect(e).to.be.an.instanceOf(InvalidDocumentErrorJs);
|
|
200
327
|
|
|
201
328
|
expect(e.getErrors()).to.have.length(1);
|
|
202
|
-
expect(e.getRawDocument()).to.equal(
|
|
329
|
+
expect(e.getRawDocument()).to.equal(rawDocumentJs);
|
|
203
330
|
|
|
204
331
|
const [consensusError] = e.getErrors();
|
|
205
332
|
expect(consensusError).to.equal(validationError);
|
|
206
333
|
|
|
207
|
-
expect(fetchAndValidateDataContractMock).to.have.been.calledOnceWithExactly(
|
|
208
|
-
expect(validateDocumentMock)
|
|
334
|
+
expect(fetchAndValidateDataContractMock).to.have.been.calledOnceWithExactly(rawDocumentJs);
|
|
335
|
+
expect(validateDocumentMock)
|
|
336
|
+
.to.have.been.calledOnceWithExactly(rawDocumentJs, dataContractJs);
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
it('should throw InvalidDocumentError if passed object is not valid - Rust', async () => {
|
|
341
|
+
delete rawDocument.lastName;
|
|
342
|
+
|
|
343
|
+
try {
|
|
344
|
+
await factory.createFromObject(rawDocument);
|
|
345
|
+
|
|
346
|
+
expect.fail('InvalidDocumentError should be thrown');
|
|
347
|
+
} catch (e) {
|
|
348
|
+
expect(e).to.be.an.instanceOf(InvalidDocumentError);
|
|
349
|
+
expect(e.getErrors()).to.have.length(1);
|
|
350
|
+
|
|
351
|
+
// TODO rawDocument cannot be converted back to the original form as it is invalid
|
|
352
|
+
// TODO so we cannot use valid fields DataContract to convert to buffer/identifier
|
|
353
|
+
// expect(e.getRawDocument()).to.equal(rawDocument);
|
|
354
|
+
|
|
355
|
+
const [consensusError] = e.getErrors();
|
|
356
|
+
expect(consensusError).to.be.an.instanceOf(JsonSchemaError);
|
|
209
357
|
}
|
|
210
358
|
});
|
|
211
359
|
|
|
@@ -217,20 +365,19 @@ describe('DocumentFactory', () => {
|
|
|
217
365
|
);
|
|
218
366
|
|
|
219
367
|
try {
|
|
220
|
-
await
|
|
368
|
+
await factoryJs.createFromObject(rawDocumentJs);
|
|
221
369
|
|
|
222
370
|
expect.fail('InvalidDocumentError should be thrown');
|
|
223
371
|
} catch (e) {
|
|
224
|
-
expect(e).to.be.an.instanceOf(
|
|
372
|
+
expect(e).to.be.an.instanceOf(InvalidDocumentErrorJs);
|
|
225
373
|
|
|
226
374
|
expect(e.getErrors()).to.have.length(1);
|
|
227
|
-
expect(e.getRawDocument()).to.equal(
|
|
375
|
+
expect(e.getRawDocument()).to.equal(rawDocumentJs);
|
|
228
376
|
|
|
229
377
|
const [consensusError] = e.getErrors();
|
|
230
378
|
|
|
231
379
|
expect(consensusError).to.equal(fetchContractError);
|
|
232
|
-
|
|
233
|
-
expect(fetchAndValidateDataContractMock).to.have.been.calledOnceWith(rawDocument);
|
|
380
|
+
expect(fetchAndValidateDataContractMock).to.have.been.calledOnceWith(rawDocumentJs);
|
|
234
381
|
expect(validateDocumentMock).to.have.not.been.called();
|
|
235
382
|
}
|
|
236
383
|
});
|
|
@@ -240,36 +387,40 @@ describe('DocumentFactory', () => {
|
|
|
240
387
|
let serializedDocument;
|
|
241
388
|
|
|
242
389
|
beforeEach(function beforeEach() {
|
|
243
|
-
this.sinonSandbox.stub(
|
|
390
|
+
this.sinonSandbox.stub(factoryJs, 'createFromObject');
|
|
244
391
|
// eslint-disable-next-line prefer-destructuring
|
|
245
|
-
|
|
392
|
+
documentJs = documentsJs[8]; // document with binary fields
|
|
246
393
|
|
|
247
|
-
serializedDocument =
|
|
248
|
-
|
|
394
|
+
serializedDocument = documentJs.toBuffer();
|
|
395
|
+
rawDocumentJs = documentJs.toObject();
|
|
249
396
|
});
|
|
250
397
|
|
|
251
398
|
afterEach(() => {
|
|
252
|
-
|
|
399
|
+
factoryJs.createFromObject.restore();
|
|
253
400
|
});
|
|
254
401
|
|
|
255
402
|
it('should return new Document from serialized one', async () => {
|
|
256
|
-
decodeProtocolEntityMock.returns([
|
|
403
|
+
decodeProtocolEntityMock.returns([rawDocumentJs.$protocolVersion, rawDocumentJs]);
|
|
257
404
|
|
|
258
|
-
|
|
405
|
+
factoryJs.createFromObject.returns(documentJs);
|
|
259
406
|
|
|
260
|
-
const result = await
|
|
261
|
-
|
|
262
|
-
expect(result).to.equal(document);
|
|
263
|
-
|
|
264
|
-
expect(factory.createFromObject).to.have.been.calledOnceWith(rawDocument);
|
|
407
|
+
const result = await factoryJs.createFromBuffer(serializedDocument);
|
|
265
408
|
|
|
409
|
+
expect(result).to.equal(documentJs);
|
|
410
|
+
expect(factoryJs.createFromObject).to.have.been.calledOnceWith(rawDocumentJs);
|
|
266
411
|
expect(decodeProtocolEntityMock).to.have.been.calledOnceWith(
|
|
267
412
|
serializedDocument,
|
|
268
413
|
);
|
|
269
414
|
});
|
|
270
415
|
|
|
416
|
+
it('should return new Document from serialized one - Rust', async () => {
|
|
417
|
+
const result = await factory.createFromBuffer(serializedDocument);
|
|
418
|
+
expect(result.toObject()).to.deep.equal(documentJs.toObject());
|
|
419
|
+
expect(stateRepositoryMock.fetchDataContract).to.have.been.calledOnce();
|
|
420
|
+
});
|
|
421
|
+
|
|
271
422
|
it('should throw InvalidDocumentError if the decoding fails with consensus error', async () => {
|
|
272
|
-
const parsingError = new
|
|
423
|
+
const parsingError = new SerializedObjectParsingErrorJs(
|
|
273
424
|
serializedDocument,
|
|
274
425
|
new Error(),
|
|
275
426
|
);
|
|
@@ -277,11 +428,11 @@ describe('DocumentFactory', () => {
|
|
|
277
428
|
decodeProtocolEntityMock.throws(parsingError);
|
|
278
429
|
|
|
279
430
|
try {
|
|
280
|
-
await
|
|
431
|
+
await factoryJs.createFromBuffer(serializedDocument);
|
|
281
432
|
|
|
282
433
|
expect.fail('should throw InvalidDocumentError');
|
|
283
434
|
} catch (e) {
|
|
284
|
-
expect(e).to.be.an.instanceOf(
|
|
435
|
+
expect(e).to.be.an.instanceOf(InvalidDocumentErrorJs);
|
|
285
436
|
|
|
286
437
|
const [innerError] = e.getErrors();
|
|
287
438
|
expect(innerError).to.equal(parsingError);
|
|
@@ -294,31 +445,63 @@ describe('DocumentFactory', () => {
|
|
|
294
445
|
decodeProtocolEntityMock.throws(parsingError);
|
|
295
446
|
|
|
296
447
|
try {
|
|
297
|
-
await
|
|
448
|
+
await factoryJs.createFromBuffer(serializedDocument);
|
|
298
449
|
|
|
299
450
|
expect.fail('should throw an error');
|
|
300
451
|
} catch (e) {
|
|
301
452
|
expect(e).to.equal(parsingError);
|
|
302
453
|
}
|
|
303
454
|
});
|
|
304
|
-
});
|
|
305
455
|
|
|
306
|
-
|
|
456
|
+
it('should throw an error if decoding fails with any other error - Rust', async () => {
|
|
457
|
+
const serializeDocument = Buffer.alloc(160, 1);
|
|
458
|
+
try {
|
|
459
|
+
await factory.createFromBuffer(serializeDocument);
|
|
460
|
+
|
|
461
|
+
expect.fail('should throw an error');
|
|
462
|
+
} catch (e) {
|
|
463
|
+
// TODO - parsing errors are not handled yet
|
|
464
|
+
expect(e).to.startsWith('Error conversion not implemented:');
|
|
465
|
+
}
|
|
466
|
+
});
|
|
467
|
+
}); describe('createStateTransition', () => {
|
|
307
468
|
it('should throw and error if documents have unknown action', () => {
|
|
308
469
|
try {
|
|
309
|
-
|
|
310
|
-
unknown:
|
|
470
|
+
factoryJs.createStateTransition({
|
|
471
|
+
unknown: documentsJs,
|
|
311
472
|
});
|
|
312
473
|
expect.fail('Error was not thrown');
|
|
313
474
|
} catch (e) {
|
|
314
|
-
expect(e).to.be.an.instanceOf(
|
|
475
|
+
expect(e).to.be.an.instanceOf(InvalidActionNameErrorJs);
|
|
315
476
|
expect(e.getActions()).to.have.deep.members(['unknown']);
|
|
316
477
|
}
|
|
317
478
|
});
|
|
318
479
|
|
|
480
|
+
it('should throw and error if documents have unknown action - Rust', async () => {
|
|
481
|
+
try {
|
|
482
|
+
factory.createStateTransition(await newDocumentsContainer({
|
|
483
|
+
unknown: documentsJs,
|
|
484
|
+
}));
|
|
485
|
+
|
|
486
|
+
expect.fail('Error was not thrown');
|
|
487
|
+
} catch (e) {
|
|
488
|
+
// newDocumentsContainer filter out unknown type, so the no documents is expected
|
|
489
|
+
expect(e).to.be.an.instanceOf(NoDocumentsSuppliedError);
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
|
|
319
493
|
it('should throw and error if no documents were supplied', () => {
|
|
320
494
|
try {
|
|
321
|
-
|
|
495
|
+
factoryJs.createStateTransition({});
|
|
496
|
+
expect.fail('Error was not thrown');
|
|
497
|
+
} catch (e) {
|
|
498
|
+
expect(e).to.be.an.instanceOf(NoDocumentsSuppliedErrorJs);
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
it('should throw and error if no documents were supplied - Rust', async () => {
|
|
503
|
+
try {
|
|
504
|
+
factory.createStateTransition(await newDocumentsContainer({}));
|
|
322
505
|
expect.fail('Error was not thrown');
|
|
323
506
|
} catch (e) {
|
|
324
507
|
expect(e).to.be.an.instanceOf(NoDocumentsSuppliedError);
|
|
@@ -326,43 +509,74 @@ describe('DocumentFactory', () => {
|
|
|
326
509
|
});
|
|
327
510
|
|
|
328
511
|
it('should throw and error if documents have mixed owner ids', () => {
|
|
329
|
-
|
|
512
|
+
documentsJs[0].ownerId = generateRandomIdentifier().toBuffer();
|
|
330
513
|
try {
|
|
331
|
-
|
|
332
|
-
create:
|
|
514
|
+
factoryJs.createStateTransition({
|
|
515
|
+
create: documentsJs,
|
|
333
516
|
});
|
|
334
517
|
expect.fail('Error was not thrown');
|
|
518
|
+
} catch (e) {
|
|
519
|
+
expect(e).to.be.an.instanceOf(MismatchOwnerIdsErrorJs);
|
|
520
|
+
expect(e.getDocuments()).to.have.deep.members(documentsJs);
|
|
521
|
+
}
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
it('should throw and error if documents have mixed owner ids - Rust', async () => {
|
|
525
|
+
const newId = generateRandomIdentifier().toBuffer();
|
|
526
|
+
documents[0].setOwnerId(new Identifier(newId));
|
|
527
|
+
const rawDocuments = documents.map((d) => d.toObject());
|
|
528
|
+
|
|
529
|
+
try {
|
|
530
|
+
factory.createStateTransition(await newDocumentsContainer({
|
|
531
|
+
create: documents,
|
|
532
|
+
}));
|
|
533
|
+
expect.fail('Error was not thrown');
|
|
335
534
|
} catch (e) {
|
|
336
535
|
expect(e).to.be.an.instanceOf(MismatchOwnerIdsError);
|
|
337
|
-
|
|
536
|
+
const rawDocumentsFromError = e.getDocuments().map((d) => d.toObject());
|
|
537
|
+
expect(rawDocumentsFromError).to.have.deep.members(rawDocuments);
|
|
338
538
|
}
|
|
339
539
|
});
|
|
340
540
|
|
|
341
541
|
it('should throw and error if create documents have invalid initial version', () => {
|
|
542
|
+
documentsJs[0].setRevision(3);
|
|
543
|
+
try {
|
|
544
|
+
factoryJs.createStateTransition({
|
|
545
|
+
create: documentsJs,
|
|
546
|
+
});
|
|
547
|
+
expect.fail('Error was not thrown');
|
|
548
|
+
} catch (e) {
|
|
549
|
+
expect(e).to.be.an.instanceOf(InvalidInitialRevisionErrorJs);
|
|
550
|
+
expect(e.getDocument()).to.deep.equal(documentsJs[0]);
|
|
551
|
+
}
|
|
552
|
+
});
|
|
553
|
+
|
|
554
|
+
it('should throw and error if create documents have invalid initial version - Rust', async () => {
|
|
342
555
|
documents[0].setRevision(3);
|
|
556
|
+
const expectedDocument = documents[0].toObject();
|
|
343
557
|
try {
|
|
344
|
-
factory.createStateTransition({
|
|
558
|
+
factory.createStateTransition(await newDocumentsContainer({
|
|
345
559
|
create: documents,
|
|
346
|
-
});
|
|
560
|
+
}));
|
|
347
561
|
expect.fail('Error was not thrown');
|
|
348
562
|
} catch (e) {
|
|
349
563
|
expect(e).to.be.an.instanceOf(InvalidInitialRevisionError);
|
|
350
|
-
expect(e.getDocument()).to.deep.equal(
|
|
564
|
+
expect(e.getDocument().toObject()).to.deep.equal(expectedDocument);
|
|
351
565
|
}
|
|
352
566
|
});
|
|
353
567
|
|
|
354
568
|
it('should create DocumentsBatchTransition with passed documents', () => {
|
|
355
|
-
const [newDocument] = getDocumentsFixture(
|
|
569
|
+
const [newDocument] = getDocumentsFixture(dataContractJs);
|
|
356
570
|
|
|
357
571
|
fakeTime.tick(1000);
|
|
358
572
|
|
|
359
|
-
const stateTransition =
|
|
360
|
-
create:
|
|
573
|
+
const stateTransition = factoryJs.createStateTransition({
|
|
574
|
+
create: documentsJs,
|
|
361
575
|
replace: [newDocument],
|
|
362
576
|
});
|
|
363
577
|
|
|
364
578
|
const expectedTransitions = getDocumentTransitionsFixture({
|
|
365
|
-
create:
|
|
579
|
+
create: documentsJs,
|
|
366
580
|
replace: [newDocument],
|
|
367
581
|
});
|
|
368
582
|
|
|
@@ -372,5 +586,25 @@ describe('DocumentFactory', () => {
|
|
|
372
586
|
expectedTransitions,
|
|
373
587
|
);
|
|
374
588
|
});
|
|
589
|
+
|
|
590
|
+
it('should create DocumentsBatchTransition with passed documents - Rust', async () => {
|
|
591
|
+
const [newDocumentJs] = getDocumentsFixture(dataContractJs);
|
|
592
|
+
const newDocument = new Document(newDocumentJs.toObject(), dataContract);
|
|
593
|
+
|
|
594
|
+
const stateTransitionJs = factoryJs.createStateTransition({
|
|
595
|
+
create: documentsJs,
|
|
596
|
+
replace: [newDocumentJs],
|
|
597
|
+
});
|
|
598
|
+
|
|
599
|
+
const stateTransition = factory.createStateTransition(await newDocumentsContainer({
|
|
600
|
+
create: documents,
|
|
601
|
+
replace: [newDocument],
|
|
602
|
+
}));
|
|
603
|
+
|
|
604
|
+
const transitions = stateTransition.getTransitions().map((t) => t.toJSON());
|
|
605
|
+
const transitionsJs = stateTransitionJs.getTransitions().map((t) => t.toJSON());
|
|
606
|
+
|
|
607
|
+
expect(transitionsJs).to.deep.equal(transitions);
|
|
608
|
+
});
|
|
375
609
|
});
|
|
376
610
|
});
|