@dashevo/wasm-dpp 0.25.6 → 0.25.9
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 -2
- package/README.md +1 -1
- package/dist/wasm/wasm_dpp.d.ts +808 -712
- package/dist/wasm/wasm_dpp.js +853 -452
- package/dist/wasm/wasm_dpp_bg.js +1 -1
- package/lib/bls/bls.js +48 -0
- package/lib/test/fixtures/getChainAssetLockProofFixture.js +20 -1
- package/lib/test/fixtures/getDataContractFixture.js +4 -6
- package/lib/test/fixtures/getDocumentTransitionsFixture.js +31 -1
- package/lib/test/fixtures/getInstantAssetLockProofFixture.js +32 -12
- package/lib/test/mocks/getBlsAdapterMock.js +1 -1
- package/lib/utils/creditsConverter.js +14 -0
- package/lib/utils/hash.js +18 -0
- package/lib/wasm/wasm_dpp.d.ts +808 -712
- package/package.json +3 -5
- package/src/dash_platform_protocol.rs +5 -5
- package/src/document/errors/invalid_document_error.rs +5 -0
- package/src/document/extended_document.rs +15 -0
- package/src/document/state_transition/document_batch_transition/document_transition/document_create_transition.rs +219 -214
- package/src/document/state_transition/document_batch_transition/document_transition/mod.rs +1 -1
- package/src/errors/consensus/basic/identity/identity_insufficient_balance_error.rs +4 -2
- package/src/errors/consensus/basic/json_schema_error.rs +35 -5
- package/src/identity/identity_facade.rs +7 -5
- package/src/identity/state_transition/asset_lock_proof/chain/chain_asset_lock_proof.rs +32 -17
- package/src/identity/state_transition/asset_lock_proof/instant/instant_asset_lock_proof.rs +22 -13
- package/src/identity/state_transition/asset_lock_proof/mod.rs +12 -11
- package/src/identity/state_transition/identity_create_transition/identity_create_transition.rs +1 -0
- package/src/identity/state_transition/identity_create_transition/to_object.rs +1 -0
- package/src/identity/state_transition/identity_topup_transition/identity_topup_transition.rs +1 -0
- package/src/identity/state_transition/identity_topup_transition/to_object.rs +1 -0
- package/src/lib.rs +1 -1
- package/src/validation/mod.rs +2 -2
- package/src/validation/validation_result.rs +16 -15
- package/test/integration/document/DocumentFacade.spec.js +11 -27
- package/test/integration/document/stateTransition/DocumentsBatchTransition/DocumentBatchTransition.spec.js +9 -19
- package/test/integration/document/stateTransition/DocumentsBatchTransition/validation/basic/validateDocumentsBatchTransitionBasicFactory.spec.js +2 -2
- package/test/integration/document/validation/validateDocumentFactory.spec.js +2 -2
- package/test/integration/identity/IdentityFacade.spec.js +1 -2
- package/test/integration/identity/stateTransition/assetLockProof/instant/validateInstantAssetLockProofStructureFactory.spec.js +2 -2
- package/test/integration/identity/stateTransition/validatePublicKeySignaturesFactory.spec.js +2 -2
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/DataContractUpdateTransition.spec.js +6 -8
- package/test/unit/document/Document.spec.js +30 -52
- package/test/unit/document/DocumentFactory.spec.js +2 -2
- package/test/unit/document/errors/InvalidDocumentError.spec.js +9 -9
- package/test/unit/document/stateTransition/DocumetsBatchTransition/DocumentsBatchTransition.spec.js +158 -155
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/basic/findDuplicatesByIndices.spec.js +132 -134
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/basic/validatePartialCompoundIndices.spec.js +3 -3
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/validateDocumentsBatchTransitionStateFactory.spec.js +568 -591
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/validateDocumentsUniquenessByIndicesFactory.spec.js +5 -13
- package/test/unit/identity/Identity.spec.js +2 -2
- package/test/unit/identity/stateTransition/assetLockProof/ChainAssetLockProof.spec.js +9 -28
- package/test/unit/identity/stateTransition/assetLockProof/InstantAssetLockProof.spec.js +19 -27
- package/lib/test/fixtures/getDashPayContractFixture.js +0 -1
- package/lib/test/fixtures/getDashPayDocumentFixture.js +0 -1
- package/lib/test/fixtures/getDpnsContractFixture.js +0 -1
- package/lib/test/fixtures/getDpnsDocumentFixture.js +0 -1
- package/lib/test/fixtures/getFeatureFlagsContractFixture.js +0 -1
- package/lib/test/fixtures/getFeatureFlagsDocumentsFixture.js +0 -1
- package/lib/test/fixtures/getIdentityTopUpTransitionFixtureJs.js +0 -1
- package/lib/test/fixtures/getMasternodeRewardShareDocumentsFixture.js +0 -1
- package/lib/test/fixtures/getMasternodeRewardSharesContractFixture.js +0 -1
- package/lib/test/fixtures/getPreorderDocumentFixture.js +0 -1
- package/lib/test/fixtures/getRawTransactionFixture.js +0 -1
- package/lib/test/fixtures/js/generateRandomIdentifier.js +0 -1
- package/lib/test/fixtures/js/getChainAssetLockProofFixture.js +0 -1
- package/lib/test/fixtures/js/getDataContractFixture.js +0 -1
- package/lib/test/fixtures/js/getDocumentTransitionsFixture.js +0 -1
- package/lib/test/fixtures/js/getDocumentsFixture.js +0 -1
- package/lib/test/fixtures/js/getInstantAssetLockProofFixture.js +0 -1
- package/test/integration/DashPlatformProtocol.spec.js +0 -53
- package/test/integration/document/stateTransition/DocumentsBatchTransition/validation/state/executeDataTriggersFactory.spec.js +0 -195
- package/test/integration/stateTransition/AbstractStateTransitionIdentitySigned.spec.js +0 -500
- package/test/integration/stateTransition/calculateStateTransitionFeeFromOperationsFactory.spec.js +0 -53
- package/test/unit/dataContract/getBinaryPropertiesFromSchema.spec.js +0 -103
- package/test/unit/dataContract/getPropertyDefinitionByPath.spec.js +0 -84
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/applyDataContractCreateTransitionFactory.spec.js +0 -45
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/applyDataContractUpdateTransitionFactory.spec.js +0 -49
- package/test/unit/dataTrigger/DataTrigger.spec.js +0 -132
- package/test/unit/dataTrigger/DataTriggerExecutionContext.spec.js +0 -29
- package/test/unit/dataTrigger/dashpayDataTriggers/createContactRequestDataTrigger.spec.js +0 -107
- package/test/unit/dataTrigger/dpnsTriggers/createDomainDataTrigger.spec.js +0 -382
- package/test/unit/dataTrigger/featureFlagDataTriggers/createFeatureFlagDataTrigger.spec.js +0 -99
- package/test/unit/dataTrigger/getDataTriggersFactory.spec.js +0 -113
- package/test/unit/dataTrigger/rejectDataTrigger.spec.js +0 -51
- package/test/unit/dataTrigger/rewardShareDataTriggers/createMasternodeRewardSharesDataTrigger.spec.js +0 -202
- package/test/unit/document/stateTransition/DocumetsBatchTransition/applyDocumentsBatchTransitionFactory.spec.js +0 -256
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/fetchDocumentsFactory.spec.js +0 -94
- package/test/unit/errors/consensus/codes.spec.js +0 -102
- package/test/unit/identity/creditsConverter.spec.js +0 -34
- package/test/unit/identity/stateTransition/IdentityCreateTransition/applyIdentityCreateTransitionFactory.spec.js +0 -83
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/applyIdentityTopUpTransitionFactory.spec.js +0 -138
- package/test/unit/identity/stateTransition/IdentityUpdateTransition/applyIdentityUpdateTransitionFactory.spec.js +0 -100
- package/test/unit/identity/stateTransition/assetLockProof/createAssetLockProofInstance.spec.js +0 -36
- package/test/unit/identity/stateTransition/assetLockProof/fetchAssetLockPublicKeyHashFactory.spec.js +0 -63
- package/test/unit/identity/validation/validateRequiredPurposeAndSecurityLevelFactory.spec.js +0 -47
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
const getDocumentsFixture = require('@dashevo/dpp/lib/test/fixtures/getDocumentsFixture');
|
|
2
|
-
const getContractFixture = require('@dashevo/dpp/lib/test/fixtures/getDataContractFixture');
|
|
3
|
-
const getDocumentTransitionsFixture = require('@dashevo/dpp/lib/test/fixtures/getDocumentTransitionsFixture');
|
|
4
|
-
|
|
5
|
-
const createStateRepositoryMock = require('@dashevo/dpp/lib/test/mocks/createStateRepositoryMock');
|
|
6
|
-
|
|
7
1
|
const sinon = require('sinon');
|
|
2
|
+
const getDocumentsFixture = require('../../../../../../../lib/test/fixtures/getDocumentsFixture');
|
|
3
|
+
const getContractFixture = require('../../../../../../../lib/test/fixtures/getDataContractFixture');
|
|
4
|
+
const getDocumentTransitionsFixture = require('../../../../../../../lib/test/fixtures/getDocumentTransitionsFixture');
|
|
5
|
+
|
|
8
6
|
const { expectValidationError } = require('../../../../../../../lib/test/expect/expectError');
|
|
9
7
|
const { default: loadWasmDpp } = require('../../../../../../../dist');
|
|
10
8
|
|
|
@@ -30,7 +28,7 @@ describe.skip('validateDocumentsUniquenessByIndices', () => {
|
|
|
30
28
|
let ownerId;
|
|
31
29
|
let executionContext;
|
|
32
30
|
|
|
33
|
-
beforeEach(async
|
|
31
|
+
beforeEach(async () => {
|
|
34
32
|
({
|
|
35
33
|
Document,
|
|
36
34
|
DataContract,
|
|
@@ -63,12 +61,6 @@ describe.skip('validateDocumentsUniquenessByIndices', () => {
|
|
|
63
61
|
),
|
|
64
62
|
);
|
|
65
63
|
|
|
66
|
-
stateRepositoryMock = createStateRepositoryMock(this.sinonSandbox);
|
|
67
|
-
stateRepositoryMock.fetchDocuments.resolves([]);
|
|
68
|
-
|
|
69
|
-
stateRepositoryMockJs = createStateRepositoryMock(this.sinonSandbox);
|
|
70
|
-
stateRepositoryMockJs.fetchDocuments.resolves([]);
|
|
71
|
-
|
|
72
64
|
executionContext = new StateTransitionExecutionContext();
|
|
73
65
|
});
|
|
74
66
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const { hash: hashFunction } = require('@dashevo/dpp/lib/util/hash');
|
|
2
1
|
const { expect } = require('chai');
|
|
2
|
+
const { hash: hashFunction } = require('../../../lib/utils/hash');
|
|
3
3
|
const generateRandomIdentifierAsync = require('../../../lib/test/utils/generateRandomIdentifierAsync');
|
|
4
4
|
const {
|
|
5
5
|
Identity, Metadata, IdentityPublicKey, KeyPurpose, KeyType, KeySecurityLevel,
|
|
@@ -131,7 +131,7 @@ describe('Identity', () => {
|
|
|
131
131
|
});
|
|
132
132
|
|
|
133
133
|
describe('#hash', () => {
|
|
134
|
-
it('should
|
|
134
|
+
it('should has identity', () => {
|
|
135
135
|
const expectedHash = hashFunction(identity.toBuffer());
|
|
136
136
|
const result = identity.hash();
|
|
137
137
|
expect(result).to.deep.equal(expectedHash);
|
|
@@ -1,63 +1,44 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
const { default: loadWasmDpp } = require('../../../../../dist');
|
|
1
|
+
const { ChainAssetLockProof } = require('../../../../../dist');
|
|
2
|
+
const getChainAssetLockProofFixture = require('../../../../../lib/test/fixtures/getChainAssetLockProofFixture');
|
|
4
3
|
|
|
5
4
|
describe('ChainAssetLockProof', () => {
|
|
6
|
-
let
|
|
5
|
+
let rawChainAssetLockProof;
|
|
7
6
|
let chainAssetLockProof;
|
|
8
|
-
let chainAssetLockProofJS;
|
|
9
7
|
|
|
10
8
|
before(async () => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
chainAssetLockProofJS = getChainAssetLockFixture();
|
|
9
|
+
rawChainAssetLockProof = getChainAssetLockProofFixture().toObject();
|
|
14
10
|
chainAssetLockProof = new ChainAssetLockProof(
|
|
15
|
-
|
|
11
|
+
rawChainAssetLockProof,
|
|
16
12
|
);
|
|
17
13
|
});
|
|
18
14
|
|
|
19
|
-
describe('#getType', () => {
|
|
20
|
-
it('should return correct type', () => {
|
|
21
|
-
expect(chainAssetLockProof.getType())
|
|
22
|
-
.to.equal(chainAssetLockProofJS.getType());
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
|
|
26
15
|
describe('#getCoreChainLockedHeight', () => {
|
|
27
16
|
it('should return correct coreChainLockedHeight', () => {
|
|
28
17
|
expect(chainAssetLockProof.getCoreChainLockedHeight())
|
|
29
|
-
.to.equal(
|
|
18
|
+
.to.equal(rawChainAssetLockProof.coreChainLockedHeight);
|
|
30
19
|
});
|
|
31
20
|
});
|
|
32
21
|
|
|
33
22
|
describe('#getOutPoint', () => {
|
|
34
23
|
it('should return correct outPoint', () => {
|
|
35
24
|
expect(chainAssetLockProof.getOutPoint())
|
|
36
|
-
.to.deep.equal(
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
describe('#toJSON', () => {
|
|
41
|
-
it('should return correct JSON', () => {
|
|
42
|
-
expect(chainAssetLockProof.toJSON())
|
|
43
|
-
.to.deep.equal(chainAssetLockProofJS.toJSON());
|
|
25
|
+
.to.deep.equal(rawChainAssetLockProof.outPoint);
|
|
44
26
|
});
|
|
45
27
|
});
|
|
46
28
|
|
|
47
29
|
describe('#toObject', () => {
|
|
48
30
|
it('should return correct object', () => {
|
|
49
31
|
expect(chainAssetLockProof.toObject())
|
|
50
|
-
.to.deep.equal(
|
|
32
|
+
.to.deep.equal(rawChainAssetLockProof);
|
|
51
33
|
});
|
|
52
34
|
});
|
|
53
35
|
|
|
54
36
|
describe('#createIdentifier', () => {
|
|
55
37
|
it('should return correct identifier', () => {
|
|
56
38
|
const identifier = chainAssetLockProof.createIdentifier();
|
|
57
|
-
const identifierJS = chainAssetLockProofJS.createIdentifier();
|
|
58
39
|
|
|
59
40
|
expect(identifier.toBuffer())
|
|
60
|
-
.to.
|
|
41
|
+
.to.have.length(32);
|
|
61
42
|
});
|
|
62
43
|
});
|
|
63
44
|
});
|
|
@@ -1,90 +1,82 @@
|
|
|
1
|
-
const getInstantAssetLockProofFixture = require('
|
|
2
|
-
|
|
3
|
-
const { default: loadWasmDpp } = require('../../../../../dist');
|
|
1
|
+
const getInstantAssetLockProofFixture = require('../../../../../lib/test/fixtures/getInstantAssetLockProofFixture');
|
|
2
|
+
const { InstantAssetLockProof } = require('../../../../../dist');
|
|
4
3
|
|
|
5
4
|
describe('InstantAssetLockProof', () => {
|
|
6
|
-
let InstantAssetLockProof;
|
|
7
5
|
let instantAssetLockProof;
|
|
8
|
-
let
|
|
6
|
+
let rawInstantAssetLockProof;
|
|
9
7
|
|
|
10
8
|
before(async () => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
instantAssetLockProofJS = getInstantAssetLockProofFixture();
|
|
9
|
+
rawInstantAssetLockProof = (await getInstantAssetLockProofFixture()).toObject();
|
|
14
10
|
instantAssetLockProof = new InstantAssetLockProof(
|
|
15
|
-
|
|
11
|
+
rawInstantAssetLockProof,
|
|
16
12
|
);
|
|
17
13
|
});
|
|
18
14
|
|
|
19
|
-
describe('#getType', () => {
|
|
20
|
-
it('should return correct type', () => {
|
|
21
|
-
expect(instantAssetLockProof.getType())
|
|
22
|
-
.to.equal(instantAssetLockProofJS.getType());
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
|
|
26
15
|
describe('#getOutputIndex', () => {
|
|
27
16
|
it('should return correct type', () => {
|
|
28
17
|
expect(instantAssetLockProof.getOutputIndex())
|
|
29
|
-
.to.equal(
|
|
18
|
+
.to.equal(rawInstantAssetLockProof.outputIndex);
|
|
30
19
|
});
|
|
31
20
|
});
|
|
32
21
|
|
|
33
22
|
describe('#getOutPoint', () => {
|
|
34
23
|
it('should return correct outPoint', () => {
|
|
35
24
|
expect(instantAssetLockProof.getOutPoint())
|
|
36
|
-
.to.
|
|
25
|
+
.to.have.length(36);
|
|
37
26
|
});
|
|
38
27
|
});
|
|
39
28
|
|
|
40
29
|
describe('#getOutput', () => {
|
|
41
30
|
it('should return correct output', () => {
|
|
42
31
|
expect(instantAssetLockProof.getOutput())
|
|
43
|
-
.to.
|
|
32
|
+
.to.have.property('script');
|
|
33
|
+
expect(instantAssetLockProof.getOutput())
|
|
34
|
+
.to.have.property('satoshis');
|
|
44
35
|
});
|
|
45
36
|
});
|
|
46
37
|
|
|
47
38
|
describe('#createIdentifier', () => {
|
|
48
39
|
it('should return correct identifier', () => {
|
|
49
40
|
const identifier = instantAssetLockProof.createIdentifier();
|
|
50
|
-
const identifierJS = instantAssetLockProofJS.createIdentifier();
|
|
51
41
|
|
|
52
42
|
expect(identifier.toBuffer())
|
|
53
|
-
.to.
|
|
43
|
+
.to.have.length(32);
|
|
54
44
|
});
|
|
55
45
|
});
|
|
56
46
|
|
|
57
47
|
describe('#getInstantLock', () => {
|
|
58
48
|
it('should return correct instant lock', () => {
|
|
59
49
|
const instantLock = instantAssetLockProof.getInstantLock();
|
|
60
|
-
const instantLockJS = instantAssetLockProofJS.getInstantLock();
|
|
61
50
|
|
|
62
51
|
expect(instantLock)
|
|
63
|
-
.to.deep.equal(
|
|
52
|
+
.to.deep.equal(rawInstantAssetLockProof.instantLock);
|
|
64
53
|
});
|
|
65
54
|
});
|
|
66
55
|
|
|
67
56
|
describe('#getTransaction', () => {
|
|
68
57
|
it('should return correct transaction', () => {
|
|
69
58
|
const transaction = instantAssetLockProof.getTransaction();
|
|
70
|
-
const transactionJS = instantAssetLockProofJS.getTransaction();
|
|
71
59
|
|
|
72
60
|
expect(transaction)
|
|
73
|
-
.to.deep.equal(
|
|
61
|
+
.to.deep.equal(rawInstantAssetLockProof.transaction);
|
|
74
62
|
});
|
|
75
63
|
});
|
|
76
64
|
|
|
77
65
|
describe('#toObject', () => {
|
|
78
66
|
it('should return correct object', () => {
|
|
79
67
|
expect(instantAssetLockProof.toObject())
|
|
80
|
-
.to.deep.equal(
|
|
68
|
+
.to.deep.equal(rawInstantAssetLockProof);
|
|
81
69
|
});
|
|
82
70
|
});
|
|
83
71
|
|
|
84
72
|
describe('#toJSON', () => {
|
|
85
73
|
it('should return correct JSON', () => {
|
|
86
74
|
expect(instantAssetLockProof.toJSON())
|
|
87
|
-
.to.deep.equal(
|
|
75
|
+
.to.deep.equal({
|
|
76
|
+
instantLock: instantAssetLockProof.getInstantLock().toString('base64'),
|
|
77
|
+
outputIndex: instantAssetLockProof.getOutputIndex(),
|
|
78
|
+
transaction: instantAssetLockProof.getTransaction().toString('hex'),
|
|
79
|
+
});
|
|
88
80
|
});
|
|
89
81
|
});
|
|
90
82
|
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('@dashevo/dpp/lib/test/fixtures/getDashPayContractFixture');
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('@dashevo/dpp/lib/test/fixtures/getDashPayDocumentFixture');
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('@dashevo/dpp/lib/test/fixtures/getDpnsContractFixture');
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('@dashevo/dpp/lib/test/fixtures/getDpnsDocumentFixture');
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('@dashevo/dpp/lib/test/fixtures/getFeatureFlagsContractFixture');
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('@dashevo/dpp/lib/test/fixtures/getFeatureFlagsDocumentsFixture');
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('@dashevo/dpp/lib/test/fixtures/getIdentityTopUpTransitionFixture');
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('@dashevo/dpp/lib/test/fixtures/getMasternodeRewardShareDocumentsFixture');
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('@dashevo/dpp/lib/test/fixtures/getMasternodeRewardSharesContractFixture');
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('@dashevo/dpp/lib/test/fixtures/getPreorderDocumentFixture');
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('@dashevo/dpp/lib/test/fixtures/getRawTransactionFixture');
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('@dashevo/dpp/lib/test/utils/generateRandomIdentifier');
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('@dashevo/dpp/lib/test/fixtures/getChainAssetLockProofFixture');
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('@dashevo/dpp/lib/test/fixtures/getDataContractFixture');
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('@dashevo/dpp/lib/test/fixtures/getDocumentTransitionsFixture');
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('@dashevo/dpp/lib/test/fixtures/getDocumentsFixture');
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('@dashevo/dpp/lib/test/fixtures/getInstantAssetLockProofFixture');
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
const DashPlatformProtocol = require('@dashevo/dpp/lib/DashPlatformProtocol');
|
|
2
|
-
const protocolVersion = require('@dashevo/dpp/lib/version/protocolVersion');
|
|
3
|
-
const getChainAssetLockProofFixture = require('@dashevo/dpp/lib/test/fixtures/getChainAssetLockProofFixture');
|
|
4
|
-
const generateRandomIdentifier = require('@dashevo/dpp/lib/test/utils/generateRandomIdentifier');
|
|
5
|
-
|
|
6
|
-
describe('DashPlatformProtocol', () => {
|
|
7
|
-
let dpp;
|
|
8
|
-
|
|
9
|
-
beforeEach(async () => {
|
|
10
|
-
dpp = new DashPlatformProtocol({});
|
|
11
|
-
await dpp.initialize();
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it('should propagate protocol version to factories', async () => {
|
|
15
|
-
let dataContract = dpp.dataContract.create(generateRandomIdentifier(), {
|
|
16
|
-
niceDocument: {
|
|
17
|
-
type: 'object',
|
|
18
|
-
properties: {
|
|
19
|
-
name: {
|
|
20
|
-
type: 'string',
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
required: ['$createdAt'],
|
|
24
|
-
additionalProperties: false,
|
|
25
|
-
},
|
|
26
|
-
});
|
|
27
|
-
const document = dpp.document.create(dataContract, generateRandomIdentifier(), 'niceDocument', {});
|
|
28
|
-
let identity = dpp.identity.create(getChainAssetLockProofFixture(), []);
|
|
29
|
-
|
|
30
|
-
expect(dataContract.protocolVersion).to.equal(protocolVersion.latestVersion);
|
|
31
|
-
expect(document.protocolVersion).to.equal(protocolVersion.latestVersion);
|
|
32
|
-
expect(identity.protocolVersion).to.equal(protocolVersion.latestVersion);
|
|
33
|
-
|
|
34
|
-
dpp.setProtocolVersion(42);
|
|
35
|
-
|
|
36
|
-
dataContract = dpp.dataContract.create(generateRandomIdentifier(), {
|
|
37
|
-
niceDocument: {
|
|
38
|
-
type: 'object',
|
|
39
|
-
properties: {
|
|
40
|
-
name: {
|
|
41
|
-
type: 'string',
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
required: ['$createdAt'],
|
|
45
|
-
additionalProperties: false,
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
identity = dpp.identity.create(getChainAssetLockProofFixture(), []);
|
|
49
|
-
|
|
50
|
-
expect(dataContract.protocolVersion).to.equal(42);
|
|
51
|
-
expect(identity.protocolVersion).to.equal(42);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
const dpnsSystemIds = require('@dashevo/dpns-contract/lib/systemIds');
|
|
2
|
-
const getDpnsContractFixture = require('@dashevo/dpp/lib/test/fixtures/getDpnsContractFixture');
|
|
3
|
-
const dpnsDocumentFixture = require('@dashevo/dpp/lib/test/fixtures/getDpnsDocumentFixture');
|
|
4
|
-
const getDocumentsFixture = require('@dashevo/dpp/lib/test/fixtures/getDocumentsFixture');
|
|
5
|
-
const getDocumentTransitionsFixture = require('@dashevo/dpp/lib/test/fixtures/getDocumentTransitionsFixture');
|
|
6
|
-
const getDataContractFixture = require('@dashevo/dpp/lib/test/fixtures/getDataContractFixture');
|
|
7
|
-
|
|
8
|
-
const IdentifierJs = require('@dashevo/dpp/lib/identifier/Identifier');
|
|
9
|
-
const createStateRepositoryMock = require('../../../../../../../lib/test/mocks/createStateRepositoryMock');
|
|
10
|
-
|
|
11
|
-
const { default: loadWasmDpp } = require('../../../../../../../dist');
|
|
12
|
-
|
|
13
|
-
let DataContract;
|
|
14
|
-
let DocumentTransition;
|
|
15
|
-
let DocumentCreateTransition;
|
|
16
|
-
let DataTriggerExecutionContext;
|
|
17
|
-
let Document;
|
|
18
|
-
let DataTriggerExecutionResult;
|
|
19
|
-
let StateTransitionExecutionContext;
|
|
20
|
-
let getAllDataTriggers;
|
|
21
|
-
|
|
22
|
-
describe.skip('executeDataTriggersFactory', () => {
|
|
23
|
-
let childDocumentJs;
|
|
24
|
-
let childDocument;
|
|
25
|
-
let contractMock;
|
|
26
|
-
let stateTransitionExecutionContext;
|
|
27
|
-
let context;
|
|
28
|
-
let documentTransitions;
|
|
29
|
-
|
|
30
|
-
let executeDataTriggers;
|
|
31
|
-
let dataContractJs;
|
|
32
|
-
let dataContract;
|
|
33
|
-
let stateRepositoryMock;
|
|
34
|
-
|
|
35
|
-
beforeEach(async function beforeEach() {
|
|
36
|
-
({
|
|
37
|
-
DataContract,
|
|
38
|
-
DocumentTransition,
|
|
39
|
-
DocumentCreateTransition,
|
|
40
|
-
DataTriggerExecutionContext,
|
|
41
|
-
Document,
|
|
42
|
-
DataTriggerExecutionResult,
|
|
43
|
-
StateTransitionExecutionContext,
|
|
44
|
-
executeDataTriggers,
|
|
45
|
-
getAllDataTriggers,
|
|
46
|
-
} = await loadWasmDpp());
|
|
47
|
-
|
|
48
|
-
dataContractJs = getDataContractFixture();
|
|
49
|
-
dataContract = new DataContract(dataContractJs.toObject());
|
|
50
|
-
|
|
51
|
-
contractMock = new DataContract(getDpnsContractFixture().toObject());
|
|
52
|
-
|
|
53
|
-
childDocumentJs = dpnsDocumentFixture.getChildDocumentFixture();
|
|
54
|
-
childDocument = new Document(
|
|
55
|
-
childDocumentJs.toObject(),
|
|
56
|
-
dataContract.clone(),
|
|
57
|
-
childDocumentJs.getType(),
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
stateRepositoryMock = createStateRepositoryMock(this.sinonSandbox);
|
|
61
|
-
|
|
62
|
-
contractMock.setId(dpnsSystemIds.contractId);
|
|
63
|
-
stateRepositoryMock = createStateRepositoryMock(this.sinonSandbox);
|
|
64
|
-
stateRepositoryMock.fetchDocuments.resolves([childDocument]);
|
|
65
|
-
|
|
66
|
-
stateTransitionExecutionContext = new StateTransitionExecutionContext();
|
|
67
|
-
stateTransitionExecutionContext.disableDryRun();
|
|
68
|
-
|
|
69
|
-
context = new DataTriggerExecutionContext(
|
|
70
|
-
stateRepositoryMock,
|
|
71
|
-
childDocument.getOwnerId(),
|
|
72
|
-
contractMock.clone(),
|
|
73
|
-
stateTransitionExecutionContext,
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
const documentTransitionsJs = getDocumentTransitionsFixture({
|
|
77
|
-
create: [childDocumentJs],
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
documentTransitions = documentTransitionsJs.map((transition) => {
|
|
81
|
-
const transitionCreate = new DocumentCreateTransition(
|
|
82
|
-
transition.toObject(), dataContract.clone(),
|
|
83
|
-
);
|
|
84
|
-
return DocumentTransition.fromTransitionCreate(transitionCreate);
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('should return an array of DataTriggerExecutionResult - Rust', async () => {
|
|
89
|
-
const dataTriggerExecutionResults = await executeDataTriggers(
|
|
90
|
-
documentTransitions, context, getAllDataTriggers(),
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
expect(dataTriggerExecutionResults).to.have.a.lengthOf(1);
|
|
94
|
-
|
|
95
|
-
const [result] = dataTriggerExecutionResults;
|
|
96
|
-
|
|
97
|
-
expect(result).to.be.an.instanceOf(DataTriggerExecutionResult);
|
|
98
|
-
expect(result.getErrors()).to.have.a.lengthOf(0);
|
|
99
|
-
expect(result.isOk()).to.be.true();
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('should return multiple data triggers if there is more than one data trigger for'
|
|
103
|
-
+ ' the same document and action in the contract - Rust', async () => {
|
|
104
|
-
const dataTriggersList = getAllDataTriggers();
|
|
105
|
-
const dataTriggerListWithDuplicates = [
|
|
106
|
-
dataTriggersList[0],
|
|
107
|
-
dataTriggersList[0],
|
|
108
|
-
dataTriggersList[0],
|
|
109
|
-
];
|
|
110
|
-
|
|
111
|
-
const expectedTriggersCount = 3;
|
|
112
|
-
const dataTriggerExecutionResults = await executeDataTriggers(
|
|
113
|
-
documentTransitions, context, dataTriggerListWithDuplicates,
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
expect(dataTriggerExecutionResults).to.have.a.lengthOf(expectedTriggersCount);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it('should return a result for each passed document with success or error - Rust', async () => {
|
|
120
|
-
const documentTransition = documentTransitions[0];
|
|
121
|
-
const rawDocumentTransition = documentTransition.toObject();
|
|
122
|
-
rawDocumentTransition.normalizedLabel = 'a'.repeat(257);
|
|
123
|
-
|
|
124
|
-
const invalidDocumentCreateTransition = new DocumentCreateTransition(
|
|
125
|
-
rawDocumentTransition, dataContract.clone(),
|
|
126
|
-
);
|
|
127
|
-
const invalidDocumentTransition = DocumentTransition.fromTransitionCreate(
|
|
128
|
-
invalidDocumentCreateTransition,
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
const dataTriggerExecutionResults = await executeDataTriggers(
|
|
132
|
-
[documentTransition, invalidDocumentTransition], context, getAllDataTriggers(),
|
|
133
|
-
);
|
|
134
|
-
|
|
135
|
-
expect(dataTriggerExecutionResults).to.have.a.lengthOf(2);
|
|
136
|
-
|
|
137
|
-
const [validResult, invalidResult] = dataTriggerExecutionResults;
|
|
138
|
-
expect(validResult.isOk()).to.be.true();
|
|
139
|
-
expect(invalidResult.isOk()).to.be.false();
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it("should not call any triggers if documents have no triggers associated with it's type or action - Rust", async () => {
|
|
143
|
-
const dataTriggers = [getAllDataTriggers()[1]];
|
|
144
|
-
const dataTriggerExecutionResults = await executeDataTriggers(
|
|
145
|
-
documentTransitions, context, dataTriggers,
|
|
146
|
-
);
|
|
147
|
-
|
|
148
|
-
expect(dataTriggerExecutionResults).to.have.a.lengthOf(0);
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
it("should call only one trigger if there's one document with a trigger and one without - Rust", async () => {
|
|
152
|
-
const dataContractId = getDataContractFixture().getId();
|
|
153
|
-
childDocumentJs.dataContractId = dataContractId;
|
|
154
|
-
childDocumentJs.dataContract.id = dataContractId;
|
|
155
|
-
childDocumentJs.ownerId = IdentifierJs.from(
|
|
156
|
-
getDocumentsFixture.ownerId,
|
|
157
|
-
);
|
|
158
|
-
|
|
159
|
-
const documentTransitionsJs = getDocumentTransitionsFixture({
|
|
160
|
-
create: [childDocumentJs].concat(getDocumentsFixture(dataContractJs)),
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
documentTransitions = documentTransitionsJs.map((transition) => {
|
|
164
|
-
const transitionCreate = new DocumentCreateTransition(
|
|
165
|
-
transition.toObject(), dataContract.clone(),
|
|
166
|
-
);
|
|
167
|
-
return DocumentTransition.fromTransitionCreate(transitionCreate);
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
const dataTriggerExecutionResults = await executeDataTriggers(
|
|
171
|
-
documentTransitions, context, getAllDataTriggers(),
|
|
172
|
-
);
|
|
173
|
-
|
|
174
|
-
expect(dataTriggerExecutionResults).to.have.a.lengthOf(1);
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
it("should not call any triggers if there's no triggers in the contract - Rust", async () => {
|
|
178
|
-
const documentTransitionsJs = getDocumentTransitionsFixture({
|
|
179
|
-
create: getDocumentsFixture(dataContractJs),
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
documentTransitions = documentTransitionsJs.map((transition) => {
|
|
183
|
-
const transitionCreate = new DocumentCreateTransition(
|
|
184
|
-
transition.toObject(), dataContract.clone(),
|
|
185
|
-
);
|
|
186
|
-
return DocumentTransition.fromTransitionCreate(transitionCreate);
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
const dataTriggerExecutionResults = await executeDataTriggers(
|
|
190
|
-
documentTransitions, context, getAllDataTriggers(),
|
|
191
|
-
);
|
|
192
|
-
|
|
193
|
-
expect(dataTriggerExecutionResults).to.have.a.lengthOf(0);
|
|
194
|
-
});
|
|
195
|
-
});
|