@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,35 +1,40 @@
|
|
|
1
|
-
const { getRE2Class } = require('@dashevo/wasm-re2');
|
|
2
|
-
|
|
3
1
|
const DashCoreLib = require('@dashevo/dashcore-lib');
|
|
4
2
|
|
|
5
|
-
const createAjv = require('@dashevo/dpp/lib/ajv/createAjv');
|
|
6
|
-
|
|
7
3
|
const getInstantAssetLockFixture = require('@dashevo/dpp/lib/test/fixtures/getInstantAssetLockProofFixture');
|
|
8
|
-
const JsonSchemaValidator = require('@dashevo/dpp/lib/validation/JsonSchemaValidator');
|
|
9
4
|
const createStateRepositoryMock = require('@dashevo/dpp/lib/test/mocks/createStateRepositoryMock');
|
|
10
|
-
const InvalidIdentityAssetLockProofError = require('@dashevo/dpp/lib/errors/consensus/basic/identity/InvalidInstantAssetLockProofError');
|
|
11
|
-
const IdentityAssetLockProofLockedTransactionMismatchError = require('@dashevo/dpp/lib/errors/consensus/basic/identity/IdentityAssetLockProofLockedTransactionMismatchError');
|
|
12
|
-
const InvalidIdentityAssetLockProofSignatureError = require('@dashevo/dpp/lib/errors/consensus/basic/identity/InvalidInstantAssetLockProofSignatureError');
|
|
13
5
|
|
|
14
|
-
const {
|
|
15
|
-
|
|
16
|
-
);
|
|
6
|
+
const { expect } = require('chai');
|
|
7
|
+
const { expectJsonSchemaError, expectValidationError } = require('../../../../../../lib/test/expect/expectError');
|
|
17
8
|
|
|
18
|
-
const
|
|
19
|
-
const InvalidIdentityAssetLockTransactionError = require('@dashevo/dpp/lib/errors/consensus/basic/identity/InvalidIdentityAssetLockTransactionError');
|
|
20
|
-
const validateInstantAssetLockProofStructureFactory = require('@dashevo/dpp/lib/identity/stateTransition/assetLockProof/instant/validateInstantAssetLockProofStructureFactory');
|
|
9
|
+
const { default: loadWasmDpp } = require('../../../../../../dist');
|
|
21
10
|
|
|
22
11
|
describe('validateInstantAssetLockProofStructureFactory', () => {
|
|
23
12
|
let rawProof;
|
|
24
13
|
let transaction;
|
|
25
14
|
let stateRepositoryMock;
|
|
26
|
-
let
|
|
27
|
-
|
|
15
|
+
let executionContext;
|
|
16
|
+
|
|
17
|
+
let StateTransitionExecutionContext;
|
|
18
|
+
let ValidationResult;
|
|
19
|
+
let InvalidInstantAssetLockProofError;
|
|
20
|
+
let IdentityAssetLockProofLockedTransactionMismatchError;
|
|
21
|
+
let InvalidInstantAssetLockProofSignatureError;
|
|
22
|
+
let InvalidIdentityAssetLockTransactionError;
|
|
23
|
+
let InstantAssetLockProofStructureValidator;
|
|
24
|
+
|
|
28
25
|
let validateInstantAssetLockProofStructure;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
|
|
27
|
+
before(async () => {
|
|
28
|
+
({
|
|
29
|
+
StateTransitionExecutionContext,
|
|
30
|
+
ValidationResult,
|
|
31
|
+
InvalidInstantAssetLockProofError,
|
|
32
|
+
IdentityAssetLockProofLockedTransactionMismatchError,
|
|
33
|
+
InvalidInstantAssetLockProofSignatureError,
|
|
34
|
+
InvalidIdentityAssetLockTransactionError,
|
|
35
|
+
InstantAssetLockProofStructureValidator,
|
|
36
|
+
} = await loadWasmDpp());
|
|
37
|
+
});
|
|
33
38
|
|
|
34
39
|
beforeEach(async function beforeEach() {
|
|
35
40
|
const assetLock = getInstantAssetLockFixture();
|
|
@@ -37,50 +42,25 @@ describe('validateInstantAssetLockProofStructureFactory', () => {
|
|
|
37
42
|
|
|
38
43
|
rawProof = assetLock.toObject();
|
|
39
44
|
|
|
40
|
-
const RE2 = await getRE2Class();
|
|
41
|
-
const ajv = createAjv(RE2);
|
|
42
|
-
|
|
43
|
-
jsonSchemaValidator = new JsonSchemaValidator(ajv);
|
|
44
|
-
|
|
45
45
|
stateRepositoryMock = createStateRepositoryMock(this.sinonSandbox);
|
|
46
|
-
stateRepositoryMock.verifyInstantLock.
|
|
46
|
+
stateRepositoryMock.verifyInstantLock.returns(true);
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
txid: transaction.id,
|
|
50
|
-
verify: this.sinonSandbox.stub().resolves(true),
|
|
51
|
-
};
|
|
48
|
+
executionContext = new StateTransitionExecutionContext();
|
|
52
49
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
validateAssetLockTransactionResult = new ValidationResult();
|
|
58
|
-
validateAssetLockTransactionResult.setData({
|
|
59
|
-
publicKeyHash,
|
|
60
|
-
transaction,
|
|
61
|
-
});
|
|
62
|
-
validateAssetLockTransactionMock = this.sinonSandbox.stub().resolves(
|
|
63
|
-
validateAssetLockTransactionResult,
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
validateInstantAssetLockProofStructure = validateInstantAssetLockProofStructureFactory(
|
|
67
|
-
jsonSchemaValidator,
|
|
68
|
-
stateRepositoryMock,
|
|
69
|
-
validateAssetLockTransactionMock,
|
|
50
|
+
const validator = new InstantAssetLockProofStructureValidator(stateRepositoryMock);
|
|
51
|
+
validateInstantAssetLockProofStructure = (proof, context) => validator.validate(
|
|
52
|
+
proof,
|
|
53
|
+
context,
|
|
70
54
|
);
|
|
71
55
|
});
|
|
72
56
|
|
|
73
|
-
afterEach(() => {
|
|
74
|
-
instantLockFromBufferMock.restore();
|
|
75
|
-
});
|
|
76
|
-
|
|
77
57
|
describe('type', () => {
|
|
78
58
|
it('should be present', async () => {
|
|
79
59
|
delete rawProof.type;
|
|
80
60
|
|
|
81
|
-
const result = await validateInstantAssetLockProofStructure(rawProof);
|
|
61
|
+
const result = await validateInstantAssetLockProofStructure(rawProof, executionContext);
|
|
82
62
|
|
|
83
|
-
expectJsonSchemaError(result);
|
|
63
|
+
await expectJsonSchemaError(result);
|
|
84
64
|
|
|
85
65
|
const [error] = result.getErrors();
|
|
86
66
|
|
|
@@ -89,16 +69,14 @@ describe('validateInstantAssetLockProofStructureFactory', () => {
|
|
|
89
69
|
expect(error.getParams().missingProperty).to.equal('type');
|
|
90
70
|
|
|
91
71
|
expect(stateRepositoryMock.verifyInstantLock).to.not.be.called();
|
|
92
|
-
expect(instantLockMock.verify).to.not.be.called();
|
|
93
|
-
expect(validateAssetLockTransactionMock).to.not.be.called();
|
|
94
72
|
});
|
|
95
73
|
|
|
96
74
|
it('should be equal to 0', async () => {
|
|
97
75
|
rawProof.type = -1;
|
|
98
76
|
|
|
99
|
-
const result = await validateInstantAssetLockProofStructure(rawProof);
|
|
77
|
+
const result = await validateInstantAssetLockProofStructure(rawProof, executionContext);
|
|
100
78
|
|
|
101
|
-
expectJsonSchemaError(result);
|
|
79
|
+
await expectJsonSchemaError(result);
|
|
102
80
|
|
|
103
81
|
const [error] = result.getErrors();
|
|
104
82
|
|
|
@@ -106,8 +84,6 @@ describe('validateInstantAssetLockProofStructureFactory', () => {
|
|
|
106
84
|
expect(error.getKeyword()).to.equal('const');
|
|
107
85
|
|
|
108
86
|
expect(stateRepositoryMock.verifyInstantLock).to.not.be.called();
|
|
109
|
-
expect(instantLockMock.verify).to.not.be.called();
|
|
110
|
-
expect(validateAssetLockTransactionMock).to.not.be.called();
|
|
111
87
|
});
|
|
112
88
|
});
|
|
113
89
|
|
|
@@ -115,9 +91,9 @@ describe('validateInstantAssetLockProofStructureFactory', () => {
|
|
|
115
91
|
it('should be present', async () => {
|
|
116
92
|
delete rawProof.instantLock;
|
|
117
93
|
|
|
118
|
-
const result = await validateInstantAssetLockProofStructure(rawProof);
|
|
94
|
+
const result = await validateInstantAssetLockProofStructure(rawProof, executionContext);
|
|
119
95
|
|
|
120
|
-
expectJsonSchemaError(result);
|
|
96
|
+
await expectJsonSchemaError(result);
|
|
121
97
|
|
|
122
98
|
const [error] = result.getErrors();
|
|
123
99
|
|
|
@@ -126,35 +102,29 @@ describe('validateInstantAssetLockProofStructureFactory', () => {
|
|
|
126
102
|
expect(error.getParams().missingProperty).to.equal('instantLock');
|
|
127
103
|
|
|
128
104
|
expect(stateRepositoryMock.verifyInstantLock).to.not.be.called();
|
|
129
|
-
expect(instantLockMock.verify).to.not.be.called();
|
|
130
|
-
expect(validateAssetLockTransactionMock).to.not.be.called();
|
|
131
105
|
});
|
|
132
106
|
|
|
133
107
|
it('should be a byte array', async () => {
|
|
134
108
|
rawProof.instantLock = new Array(165).fill('string');
|
|
135
109
|
|
|
136
|
-
const result = await validateInstantAssetLockProofStructure(rawProof);
|
|
110
|
+
const result = await validateInstantAssetLockProofStructure(rawProof, executionContext);
|
|
137
111
|
|
|
138
|
-
expectJsonSchemaError(result,
|
|
112
|
+
await expectJsonSchemaError(result, 165);
|
|
139
113
|
|
|
140
|
-
const [error
|
|
114
|
+
const [error] = result.getErrors();
|
|
141
115
|
|
|
142
116
|
expect(error.getInstancePath()).to.equal('/instantLock/0');
|
|
143
117
|
expect(error.getKeyword()).to.equal('type');
|
|
144
118
|
|
|
145
|
-
expect(byteArrayError.getKeyword()).to.equal('byteArray');
|
|
146
|
-
|
|
147
119
|
expect(stateRepositoryMock.verifyInstantLock).to.not.be.called();
|
|
148
|
-
expect(instantLockMock.verify).to.not.be.called();
|
|
149
|
-
expect(validateAssetLockTransactionMock).to.not.be.called();
|
|
150
120
|
});
|
|
151
121
|
|
|
152
122
|
it('should not be shorter than 160 bytes', async () => {
|
|
153
123
|
rawProof.instantLock = Buffer.alloc(159);
|
|
154
124
|
|
|
155
|
-
const result = await validateInstantAssetLockProofStructure(rawProof);
|
|
125
|
+
const result = await validateInstantAssetLockProofStructure(rawProof, executionContext);
|
|
156
126
|
|
|
157
|
-
expectJsonSchemaError(result);
|
|
127
|
+
await expectJsonSchemaError(result);
|
|
158
128
|
|
|
159
129
|
const [error] = result.getErrors();
|
|
160
130
|
|
|
@@ -162,16 +132,14 @@ describe('validateInstantAssetLockProofStructureFactory', () => {
|
|
|
162
132
|
expect(error.getKeyword()).to.equal('minItems');
|
|
163
133
|
|
|
164
134
|
expect(stateRepositoryMock.verifyInstantLock).to.not.be.called();
|
|
165
|
-
expect(instantLockMock.verify).to.not.be.called();
|
|
166
|
-
expect(validateAssetLockTransactionMock).to.not.be.called();
|
|
167
135
|
});
|
|
168
136
|
|
|
169
137
|
it('should not be longer than 100 Kb', async () => {
|
|
170
138
|
rawProof.instantLock = Buffer.alloc(100001);
|
|
171
139
|
|
|
172
|
-
const result = await validateInstantAssetLockProofStructure(rawProof);
|
|
140
|
+
const result = await validateInstantAssetLockProofStructure(rawProof, executionContext);
|
|
173
141
|
|
|
174
|
-
expectJsonSchemaError(result);
|
|
142
|
+
await expectJsonSchemaError(result);
|
|
175
143
|
|
|
176
144
|
const [error] = result.getErrors();
|
|
177
145
|
|
|
@@ -179,37 +147,34 @@ describe('validateInstantAssetLockProofStructureFactory', () => {
|
|
|
179
147
|
expect(error.getKeyword()).to.equal('maxItems');
|
|
180
148
|
|
|
181
149
|
expect(stateRepositoryMock.verifyInstantLock).to.not.be.called();
|
|
182
|
-
expect(instantLockMock.verify).to.not.be.called();
|
|
183
|
-
expect(validateAssetLockTransactionMock).to.not.be.called();
|
|
184
150
|
});
|
|
185
151
|
|
|
186
152
|
it('should be valid', async () => {
|
|
187
|
-
const instantLockError = new Error('something is wrong');
|
|
188
|
-
|
|
189
|
-
instantLockFromBufferMock.throws(instantLockError);
|
|
190
|
-
|
|
191
153
|
rawProof.instantLock = Buffer.alloc(200);
|
|
192
154
|
|
|
193
|
-
const result = await validateInstantAssetLockProofStructure(rawProof);
|
|
194
|
-
expectValidationError(result,
|
|
155
|
+
const result = await validateInstantAssetLockProofStructure(rawProof, executionContext);
|
|
156
|
+
await expectValidationError(result, InvalidInstantAssetLockProofError);
|
|
195
157
|
|
|
196
158
|
const [error] = result.getErrors();
|
|
197
159
|
|
|
198
160
|
expect(error.getCode()).to.equal(1041);
|
|
199
|
-
expect(error.getValidationError()).to.equal(instantLockError);
|
|
200
161
|
|
|
201
162
|
expect(stateRepositoryMock.verifyInstantLock).to.not.be.called();
|
|
202
|
-
expect(instantLockMock.verify).to.not.be.called();
|
|
203
|
-
expect(validateAssetLockTransactionMock).to.not.be.called();
|
|
204
163
|
});
|
|
205
164
|
|
|
206
165
|
it('should lock the same transaction', async () => {
|
|
207
166
|
const txId = Buffer.alloc(32);
|
|
208
|
-
instantLockMock.txid = txId.toString('hex');
|
|
209
167
|
|
|
210
|
-
const
|
|
168
|
+
const instantLockParsed = new DashCoreLib.InstantLock(rawProof.instantLock);
|
|
169
|
+
instantLockParsed.txid = txId.toString('hex');
|
|
170
|
+
rawProof.instantLock = instantLockParsed.toBuffer();
|
|
171
|
+
|
|
172
|
+
const result = await validateInstantAssetLockProofStructure(rawProof, executionContext);
|
|
211
173
|
|
|
212
|
-
expectValidationError(
|
|
174
|
+
await expectValidationError(
|
|
175
|
+
result,
|
|
176
|
+
IdentityAssetLockProofLockedTransactionMismatchError,
|
|
177
|
+
);
|
|
213
178
|
|
|
214
179
|
const [error] = result.getErrors();
|
|
215
180
|
|
|
@@ -217,24 +182,24 @@ describe('validateInstantAssetLockProofStructureFactory', () => {
|
|
|
217
182
|
expect(error.getInstantLockTransactionId()).to.deep.equal(txId);
|
|
218
183
|
expect(error.getAssetLockTransactionId()).to.deep.equal(Buffer.from(transaction.id, 'hex'));
|
|
219
184
|
|
|
220
|
-
|
|
221
|
-
expect(instantLockMock.verify).to.not.be.called();
|
|
222
|
-
expect(validateAssetLockTransactionMock).to.be.calledOnce();
|
|
185
|
+
expect(stateRepositoryMock.verifyInstantLock).to.be.calledOnce();
|
|
223
186
|
});
|
|
224
187
|
|
|
225
188
|
it('should have valid signature', async () => {
|
|
226
189
|
stateRepositoryMock.verifyInstantLock.resolves(false);
|
|
227
190
|
|
|
228
|
-
const result = await validateInstantAssetLockProofStructure(rawProof);
|
|
191
|
+
const result = await validateInstantAssetLockProofStructure(rawProof, executionContext);
|
|
229
192
|
|
|
230
|
-
expectValidationError(
|
|
193
|
+
await expectValidationError(
|
|
194
|
+
result,
|
|
195
|
+
InvalidInstantAssetLockProofSignatureError,
|
|
196
|
+
);
|
|
231
197
|
|
|
232
198
|
const [error] = result.getErrors();
|
|
233
199
|
|
|
234
200
|
expect(error.getCode()).to.equal(1042);
|
|
235
201
|
|
|
236
202
|
expect(stateRepositoryMock.verifyInstantLock).to.be.calledOnce();
|
|
237
|
-
expect(validateAssetLockTransactionMock).to.not.be.called();
|
|
238
203
|
});
|
|
239
204
|
});
|
|
240
205
|
|
|
@@ -242,9 +207,9 @@ describe('validateInstantAssetLockProofStructureFactory', () => {
|
|
|
242
207
|
it('should be present', async () => {
|
|
243
208
|
delete rawProof.transaction;
|
|
244
209
|
|
|
245
|
-
const result = await validateInstantAssetLockProofStructure(rawProof);
|
|
210
|
+
const result = await validateInstantAssetLockProofStructure(rawProof, executionContext);
|
|
246
211
|
|
|
247
|
-
expectJsonSchemaError(result);
|
|
212
|
+
await expectJsonSchemaError(result);
|
|
248
213
|
|
|
249
214
|
const [error] = result.getErrors();
|
|
250
215
|
|
|
@@ -253,88 +218,66 @@ describe('validateInstantAssetLockProofStructureFactory', () => {
|
|
|
253
218
|
expect(error.getParams().missingProperty).to.equal('transaction');
|
|
254
219
|
|
|
255
220
|
expect(stateRepositoryMock.verifyInstantLock).to.not.be.called();
|
|
256
|
-
expect(instantLockMock.verify).to.not.be.called();
|
|
257
|
-
expect(validateAssetLockTransactionMock).to.not.be.called();
|
|
258
221
|
});
|
|
259
222
|
|
|
260
223
|
it('should be a byte array', async () => {
|
|
261
224
|
rawProof.transaction = new Array(65).fill('string');
|
|
262
225
|
|
|
263
|
-
const result = await validateInstantAssetLockProofStructure(rawProof);
|
|
226
|
+
const result = await validateInstantAssetLockProofStructure(rawProof, executionContext);
|
|
264
227
|
|
|
265
|
-
expectJsonSchemaError(result,
|
|
228
|
+
await expectJsonSchemaError(result, 65);
|
|
266
229
|
|
|
267
|
-
const [error
|
|
230
|
+
const [error] = result.getErrors();
|
|
268
231
|
|
|
269
232
|
expect(error.getInstancePath()).to.equal('/transaction/0');
|
|
270
233
|
expect(error.getKeyword()).to.equal('type');
|
|
271
234
|
|
|
272
|
-
expect(byteArrayError.getKeyword()).to.equal('byteArray');
|
|
273
|
-
|
|
274
235
|
expect(stateRepositoryMock.verifyInstantLock).to.not.be.called();
|
|
275
|
-
expect(instantLockMock.verify).to.not.be.called();
|
|
276
|
-
expect(validateAssetLockTransactionMock).to.not.be.called();
|
|
277
236
|
});
|
|
278
237
|
|
|
279
238
|
it('should not be shorter than 1 byte', async () => {
|
|
280
239
|
rawProof.transaction = Buffer.alloc(0);
|
|
281
240
|
|
|
282
|
-
const result = await validateInstantAssetLockProofStructure(rawProof);
|
|
241
|
+
const result = await validateInstantAssetLockProofStructure(rawProof, executionContext);
|
|
283
242
|
|
|
284
|
-
expectJsonSchemaError(result);
|
|
243
|
+
await expectJsonSchemaError(result);
|
|
285
244
|
|
|
286
245
|
const [error] = result.getErrors();
|
|
287
246
|
|
|
288
|
-
expect(error.
|
|
247
|
+
expect(error.getInstancePath()).to.equal('/transaction');
|
|
289
248
|
expect(error.getKeyword()).to.equal('minItems');
|
|
290
249
|
|
|
291
250
|
expect(stateRepositoryMock.verifyInstantLock).to.not.be.called();
|
|
292
|
-
expect(instantLockMock.verify).to.not.be.called();
|
|
293
|
-
expect(validateAssetLockTransactionMock).to.not.be.called();
|
|
294
251
|
});
|
|
295
252
|
|
|
296
253
|
it('should not be longer than 100 Kb', async () => {
|
|
297
254
|
rawProof.transaction = Buffer.alloc(100001);
|
|
298
255
|
|
|
299
|
-
const result = await validateInstantAssetLockProofStructure(rawProof);
|
|
256
|
+
const result = await validateInstantAssetLockProofStructure(rawProof, executionContext);
|
|
300
257
|
|
|
301
|
-
expectJsonSchemaError(result);
|
|
258
|
+
await expectJsonSchemaError(result);
|
|
302
259
|
|
|
303
260
|
const [error] = result.getErrors();
|
|
304
261
|
|
|
305
|
-
expect(error.
|
|
262
|
+
expect(error.getInstancePath()).to.equal('/transaction');
|
|
306
263
|
expect(error.getKeyword()).to.equal('maxItems');
|
|
307
264
|
|
|
308
265
|
expect(stateRepositoryMock.verifyInstantLock).to.not.be.called();
|
|
309
|
-
expect(instantLockMock.verify).to.not.be.called();
|
|
310
|
-
expect(validateAssetLockTransactionMock).to.not.be.called();
|
|
311
266
|
});
|
|
312
267
|
|
|
313
268
|
it('should should be valid', async () => {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
const consensusError = new InvalidIdentityAssetLockTransactionError(validationError.message);
|
|
269
|
+
rawProof.transaction = Buffer.alloc(1000);
|
|
317
270
|
|
|
318
|
-
|
|
271
|
+
const result = await validateInstantAssetLockProofStructure(rawProof, executionContext);
|
|
319
272
|
|
|
320
|
-
|
|
321
|
-
validateAssetLockTransactionMock.resolves(validateAssetLockTransactionResult);
|
|
322
|
-
|
|
323
|
-
const result = await validateInstantAssetLockProofStructure(rawProof);
|
|
324
|
-
|
|
325
|
-
expectValidationError(result, InvalidIdentityAssetLockTransactionError);
|
|
273
|
+
await expectValidationError(result, InvalidIdentityAssetLockTransactionError);
|
|
326
274
|
|
|
327
275
|
const [error] = result.getErrors();
|
|
328
276
|
|
|
329
277
|
expect(error.getCode()).to.equal(1038);
|
|
278
|
+
expect(error.getValidationError()).to.exist();
|
|
330
279
|
|
|
331
|
-
expect(
|
|
332
|
-
|
|
333
|
-
expect(error.getValidationError()).to.equal(validationError);
|
|
334
|
-
|
|
335
|
-
// expect(stateRepositoryMock.verifyInstantLock).to.be.calledOnce();
|
|
336
|
-
expect(instantLockMock.verify).to.not.be.called();
|
|
337
|
-
expect(validateAssetLockTransactionMock).to.be.calledOnce();
|
|
280
|
+
expect(stateRepositoryMock.verifyInstantLock).to.be.calledOnce();
|
|
338
281
|
});
|
|
339
282
|
});
|
|
340
283
|
|
|
@@ -342,60 +285,62 @@ describe('validateInstantAssetLockProofStructureFactory', () => {
|
|
|
342
285
|
it('should be present', async () => {
|
|
343
286
|
delete rawProof.outputIndex;
|
|
344
287
|
|
|
345
|
-
const result = await validateInstantAssetLockProofStructure(rawProof);
|
|
288
|
+
const result = await validateInstantAssetLockProofStructure(rawProof, executionContext);
|
|
346
289
|
|
|
347
|
-
expectJsonSchemaError(result);
|
|
290
|
+
await expectJsonSchemaError(result);
|
|
348
291
|
|
|
349
292
|
const [error] = result.getErrors();
|
|
350
293
|
|
|
351
|
-
expect(error.
|
|
294
|
+
expect(error.getInstancePath()).to.equal('');
|
|
352
295
|
expect(error.getKeyword()).to.equal('required');
|
|
353
296
|
expect(error.getParams().missingProperty).to.equal('outputIndex');
|
|
354
297
|
|
|
355
298
|
expect(stateRepositoryMock.verifyInstantLock).to.not.be.called();
|
|
356
|
-
expect(instantLockMock.verify).to.not.be.called();
|
|
357
299
|
});
|
|
358
300
|
|
|
359
301
|
it('should be an integer', async () => {
|
|
360
302
|
rawProof.outputIndex = 1.1;
|
|
361
303
|
|
|
362
|
-
const result = await validateInstantAssetLockProofStructure(rawProof);
|
|
304
|
+
const result = await validateInstantAssetLockProofStructure(rawProof, executionContext);
|
|
363
305
|
|
|
364
|
-
expectJsonSchemaError(result, 1);
|
|
306
|
+
await expectJsonSchemaError(result, 1);
|
|
365
307
|
|
|
366
308
|
const [error] = result.getErrors();
|
|
367
309
|
|
|
368
|
-
expect(error.
|
|
310
|
+
expect(error.getInstancePath()).to.equal('/outputIndex');
|
|
369
311
|
expect(error.getKeyword()).to.equal('type');
|
|
370
312
|
|
|
371
313
|
expect(stateRepositoryMock.verifyInstantLock).to.not.be.called();
|
|
372
|
-
expect(instantLockMock.verify).to.not.be.called();
|
|
373
314
|
});
|
|
374
315
|
|
|
375
316
|
it('should not be less than 0', async () => {
|
|
376
317
|
rawProof.outputIndex = -1;
|
|
377
318
|
|
|
378
|
-
const result = await validateInstantAssetLockProofStructure(rawProof);
|
|
319
|
+
const result = await validateInstantAssetLockProofStructure(rawProof, executionContext);
|
|
379
320
|
|
|
380
|
-
expectJsonSchemaError(result);
|
|
321
|
+
await expectJsonSchemaError(result);
|
|
381
322
|
|
|
382
323
|
const [error] = result.getErrors();
|
|
383
324
|
|
|
384
|
-
expect(error.
|
|
325
|
+
expect(error.getInstancePath()).to.equal('/outputIndex');
|
|
385
326
|
expect(error.getKeyword()).to.equal('minimum');
|
|
386
327
|
|
|
387
328
|
expect(stateRepositoryMock.verifyInstantLock).to.not.be.called();
|
|
388
|
-
expect(instantLockMock.verify).to.not.be.called();
|
|
389
329
|
});
|
|
390
330
|
});
|
|
391
331
|
|
|
392
332
|
it('should return valid result', async () => {
|
|
393
|
-
const result = await validateInstantAssetLockProofStructure(
|
|
333
|
+
const result = await validateInstantAssetLockProofStructure(
|
|
334
|
+
rawProof,
|
|
335
|
+
executionContext,
|
|
336
|
+
);
|
|
394
337
|
|
|
395
338
|
expect(result).to.be.an.instanceOf(ValidationResult);
|
|
396
339
|
expect(result.isValid()).to.be.true();
|
|
340
|
+
|
|
341
|
+
const publicKeyHash = transaction.outputs[0].script.getData();
|
|
397
342
|
expect(result.getData()).to.deep.equal(publicKeyHash);
|
|
398
343
|
|
|
399
|
-
|
|
344
|
+
expect(stateRepositoryMock.verifyInstantLock).to.be.calledOnce();
|
|
400
345
|
});
|
|
401
346
|
});
|