@dashevo/wasm-dpp 0.25.8 → 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,382 +0,0 @@
|
|
|
1
|
-
const createDomainDataTrigger = require('@dashevo/dpp/lib/dataTrigger/dpnsTriggers/createDomainDataTrigger');
|
|
2
|
-
|
|
3
|
-
const DataTriggerExecutionContext = require('@dashevo/dpp/lib/dataTrigger/DataTriggerExecutionContext');
|
|
4
|
-
const DataTriggerExecutionResult = require('@dashevo/dpp/lib/dataTrigger/DataTriggerExecutionResult');
|
|
5
|
-
|
|
6
|
-
const { getParentDocumentFixture, getChildDocumentFixture, getTopDocumentFixture } = require('@dashevo/dpp/lib/test/fixtures/getDpnsDocumentFixture');
|
|
7
|
-
const getPreorderDocumentFixture = require('@dashevo/dpp/lib/test/fixtures/getPreorderDocumentFixture');
|
|
8
|
-
const getDpnsContractFixture = require('@dashevo/dpp/lib/test/fixtures/getDpnsContractFixture');
|
|
9
|
-
const getDocumentTransitionFixture = require('@dashevo/dpp/lib/test/fixtures/getDocumentTransitionsFixture');
|
|
10
|
-
const createStateRepositoryMock = require('@dashevo/dpp/lib/test/mocks/createStateRepositoryMock');
|
|
11
|
-
|
|
12
|
-
const { hash } = require('@dashevo/dpp/lib/util/hash');
|
|
13
|
-
|
|
14
|
-
const DataTriggerConditionError = require('@dashevo/dpp/lib/errors/consensus/state/dataContract/dataTrigger/DataTriggerConditionError');
|
|
15
|
-
const Identifier = require('@dashevo/dpp/lib/identifier/Identifier');
|
|
16
|
-
const StateTransitionExecutionContext = require('@dashevo/dpp/lib/stateTransition/StateTransitionExecutionContext');
|
|
17
|
-
|
|
18
|
-
describe.skip('createDomainDataTrigger', () => {
|
|
19
|
-
let parentDocumentTransition;
|
|
20
|
-
let childDocumentTransition;
|
|
21
|
-
let childDocument;
|
|
22
|
-
let parentDocument;
|
|
23
|
-
let topDocument;
|
|
24
|
-
let context;
|
|
25
|
-
let stateRepositoryMock;
|
|
26
|
-
let dataContract;
|
|
27
|
-
let topLevelIdentity;
|
|
28
|
-
let executionContext;
|
|
29
|
-
|
|
30
|
-
beforeEach(function beforeEach() {
|
|
31
|
-
dataContract = getDpnsContractFixture();
|
|
32
|
-
|
|
33
|
-
topDocument = getTopDocumentFixture();
|
|
34
|
-
parentDocument = getParentDocumentFixture();
|
|
35
|
-
childDocument = getChildDocumentFixture();
|
|
36
|
-
const preorderDocument = getPreorderDocumentFixture();
|
|
37
|
-
|
|
38
|
-
[parentDocumentTransition] = getDocumentTransitionFixture({
|
|
39
|
-
create: [parentDocument],
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
[childDocumentTransition] = getDocumentTransitionFixture({
|
|
43
|
-
create: [childDocument],
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
const {
|
|
47
|
-
preorderSalt, records, normalizedParentDomainName, normalizedLabel,
|
|
48
|
-
} = childDocument.getData();
|
|
49
|
-
|
|
50
|
-
let fullDomainName = normalizedLabel;
|
|
51
|
-
if (normalizedParentDomainName.length > 0) {
|
|
52
|
-
fullDomainName = `${normalizedLabel}.${normalizedParentDomainName}`;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
stateRepositoryMock = createStateRepositoryMock(this.sinonSandbox);
|
|
56
|
-
stateRepositoryMock.fetchDocuments.resolves([]);
|
|
57
|
-
|
|
58
|
-
const [normalizedParentLabel] = normalizedParentDomainName.split('.');
|
|
59
|
-
const normalizedGrandParentDomainName = normalizedParentDomainName.split('.')
|
|
60
|
-
.slice(1)
|
|
61
|
-
.join('.');
|
|
62
|
-
|
|
63
|
-
stateRepositoryMock.fetchDocuments
|
|
64
|
-
.withArgs(
|
|
65
|
-
dataContract.getId(),
|
|
66
|
-
childDocument.getType(),
|
|
67
|
-
{
|
|
68
|
-
where: [
|
|
69
|
-
['normalizedParentDomainName', '==', normalizedGrandParentDomainName],
|
|
70
|
-
['normalizedLabel', '==', normalizedParentLabel],
|
|
71
|
-
],
|
|
72
|
-
},
|
|
73
|
-
)
|
|
74
|
-
.resolves([parentDocument]);
|
|
75
|
-
|
|
76
|
-
const saltedDomainHashBuffer = Buffer.concat([
|
|
77
|
-
preorderSalt,
|
|
78
|
-
Buffer.from(fullDomainName),
|
|
79
|
-
]);
|
|
80
|
-
|
|
81
|
-
const saltedDomainHash = hash(saltedDomainHashBuffer);
|
|
82
|
-
|
|
83
|
-
stateRepositoryMock.fetchDocuments
|
|
84
|
-
.withArgs(
|
|
85
|
-
dataContract.getId(),
|
|
86
|
-
'preorder',
|
|
87
|
-
{ where: [['saltedDomainHash', '==', saltedDomainHash]] },
|
|
88
|
-
)
|
|
89
|
-
.resolves([preorderDocument.toObject()]);
|
|
90
|
-
|
|
91
|
-
stateRepositoryMock.fetchTransaction.resolves(null);
|
|
92
|
-
|
|
93
|
-
stateRepositoryMock.fetchTransaction
|
|
94
|
-
.withArgs(
|
|
95
|
-
records.dashUniqueIdentityId,
|
|
96
|
-
)
|
|
97
|
-
.resolves({ confirmations: 10 });
|
|
98
|
-
|
|
99
|
-
executionContext = new StateTransitionExecutionContext();
|
|
100
|
-
|
|
101
|
-
context = new DataTriggerExecutionContext(
|
|
102
|
-
stateRepositoryMock,
|
|
103
|
-
records.dashUniqueIdentityId,
|
|
104
|
-
dataContract,
|
|
105
|
-
executionContext,
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
topLevelIdentity = context.getOwnerId();
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('should successfully execute if document is valid', async () => {
|
|
112
|
-
const result = await createDomainDataTrigger(
|
|
113
|
-
childDocumentTransition, context, topLevelIdentity,
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
expect(result.isOk()).to.be.true();
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it('should fail with invalid normalizedLabel', async () => {
|
|
120
|
-
childDocument = getChildDocumentFixture({ normalizedLabel: childDocument.getData().label });
|
|
121
|
-
stateRepositoryMock.fetchTransaction
|
|
122
|
-
.withArgs(
|
|
123
|
-
childDocument.getData().records.dashUniqueIdentityId,
|
|
124
|
-
)
|
|
125
|
-
.resolves({ confirmations: 10 });
|
|
126
|
-
|
|
127
|
-
[childDocumentTransition] = getDocumentTransitionFixture({
|
|
128
|
-
create: [childDocument],
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
const result = await createDomainDataTrigger(
|
|
132
|
-
childDocumentTransition, context, topLevelIdentity,
|
|
133
|
-
);
|
|
134
|
-
|
|
135
|
-
expect(result).to.be.an.instanceOf(DataTriggerExecutionResult);
|
|
136
|
-
expect(result.isOk()).to.be.false();
|
|
137
|
-
|
|
138
|
-
const [error] = result.getErrors();
|
|
139
|
-
|
|
140
|
-
expect(error).to.be.an.instanceOf(DataTriggerConditionError);
|
|
141
|
-
expect(error.message).to.equal('Normalized label doesn\'t match label');
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it('should fail with invalid parent domain', async () => {
|
|
145
|
-
childDocument = getChildDocumentFixture({
|
|
146
|
-
label: 'label',
|
|
147
|
-
normalizedLabel: 'label',
|
|
148
|
-
normalizedParentDomainName: 'parent.invalidname',
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
stateRepositoryMock.fetchTransaction
|
|
152
|
-
.withArgs(
|
|
153
|
-
childDocument.getData().records.dashUniqueIdentityId,
|
|
154
|
-
)
|
|
155
|
-
.resolves({ confirmations: 10 });
|
|
156
|
-
|
|
157
|
-
[childDocumentTransition] = getDocumentTransitionFixture({
|
|
158
|
-
create: [childDocument],
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
const result = await createDomainDataTrigger(
|
|
162
|
-
childDocumentTransition, context, topLevelIdentity,
|
|
163
|
-
);
|
|
164
|
-
|
|
165
|
-
expect(result).to.be.an.instanceOf(DataTriggerExecutionResult);
|
|
166
|
-
expect(result.isOk()).to.be.false();
|
|
167
|
-
|
|
168
|
-
const [error] = result.getErrors();
|
|
169
|
-
|
|
170
|
-
expect(error).to.be.an.instanceOf(DataTriggerConditionError);
|
|
171
|
-
expect(error.message).to.equal('Parent domain is not present');
|
|
172
|
-
|
|
173
|
-
expect(stateRepositoryMock.fetchDocuments).to.have.been.calledOnceWithExactly(
|
|
174
|
-
context.getDataContract().getId(),
|
|
175
|
-
'domain',
|
|
176
|
-
{
|
|
177
|
-
where: [
|
|
178
|
-
['normalizedParentDomainName', '==', 'invalidname'],
|
|
179
|
-
['normalizedLabel', '==', 'parent'],
|
|
180
|
-
],
|
|
181
|
-
},
|
|
182
|
-
executionContext,
|
|
183
|
-
);
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
it('should fail with invalid dashUniqueIdentityId', async () => {
|
|
187
|
-
const dashUniqueIdentityId = Identifier.from(
|
|
188
|
-
Buffer.alloc(32, 5),
|
|
189
|
-
);
|
|
190
|
-
|
|
191
|
-
childDocument = getChildDocumentFixture({
|
|
192
|
-
records: {
|
|
193
|
-
dashUniqueIdentityId: dashUniqueIdentityId.toBuffer(),
|
|
194
|
-
},
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
[childDocumentTransition] = getDocumentTransitionFixture({
|
|
198
|
-
create: [childDocument],
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
const result = await createDomainDataTrigger(
|
|
202
|
-
childDocumentTransition, context, topLevelIdentity,
|
|
203
|
-
);
|
|
204
|
-
|
|
205
|
-
expect(result).to.be.an.instanceOf(DataTriggerExecutionResult);
|
|
206
|
-
expect(result.isOk()).to.be.false();
|
|
207
|
-
|
|
208
|
-
const [error] = result.getErrors();
|
|
209
|
-
|
|
210
|
-
expect(error).to.be.an.instanceOf(DataTriggerConditionError);
|
|
211
|
-
expect(error.message).to.equal(`ownerId ${childDocument.getOwnerId()} doesn't match dashUniqueIdentityId ${dashUniqueIdentityId}`);
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
it('should fail with invalid dashAliasIdentityId', async () => {
|
|
215
|
-
const dashUniqueIdentityId = Identifier.from(
|
|
216
|
-
Buffer.alloc(32, 2),
|
|
217
|
-
);
|
|
218
|
-
|
|
219
|
-
childDocument = getChildDocumentFixture({
|
|
220
|
-
records: {
|
|
221
|
-
dashAliasIdentityId: dashUniqueIdentityId.toBuffer(),
|
|
222
|
-
},
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
[childDocumentTransition] = getDocumentTransitionFixture({
|
|
226
|
-
create: [childDocument],
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
const result = await createDomainDataTrigger(
|
|
230
|
-
childDocumentTransition, context, topLevelIdentity,
|
|
231
|
-
);
|
|
232
|
-
|
|
233
|
-
expect(result).to.be.an.instanceOf(DataTriggerExecutionResult);
|
|
234
|
-
expect(result.isOk()).to.be.false();
|
|
235
|
-
|
|
236
|
-
const [error] = result.getErrors();
|
|
237
|
-
|
|
238
|
-
expect(error).to.be.an.instanceOf(DataTriggerConditionError);
|
|
239
|
-
expect(error.message).to.equal(`ownerId ${childDocument.getOwnerId()} doesn't match dashAliasIdentityId ${dashUniqueIdentityId}`);
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
it('should fail with preorder document was not found', async () => {
|
|
243
|
-
childDocument = getChildDocumentFixture({
|
|
244
|
-
preorderSalt: Buffer.alloc(256, '012fd'),
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
[childDocumentTransition] = getDocumentTransitionFixture({
|
|
248
|
-
create: [childDocument],
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
const result = await createDomainDataTrigger(
|
|
252
|
-
childDocumentTransition, context, topLevelIdentity,
|
|
253
|
-
);
|
|
254
|
-
|
|
255
|
-
expect(result).to.be.an.instanceOf(DataTriggerExecutionResult);
|
|
256
|
-
expect(result.isOk()).to.be.false();
|
|
257
|
-
|
|
258
|
-
const [error] = result.getErrors();
|
|
259
|
-
|
|
260
|
-
expect(error).to.be.an.instanceOf(DataTriggerConditionError);
|
|
261
|
-
expect(error.message).to.equal('preorderDocument was not found');
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
it('should fail with invalid full domain name length', async () => {
|
|
265
|
-
childDocument = getChildDocumentFixture({
|
|
266
|
-
normalizedParentDomainName: 'a'.repeat(512),
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
[childDocumentTransition] = getDocumentTransitionFixture({
|
|
270
|
-
create: [childDocument],
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
const result = await createDomainDataTrigger(
|
|
274
|
-
childDocumentTransition, context, topLevelIdentity,
|
|
275
|
-
);
|
|
276
|
-
|
|
277
|
-
expect(result).to.be.an.instanceOf(DataTriggerExecutionResult);
|
|
278
|
-
expect(result.isOk()).to.be.false();
|
|
279
|
-
|
|
280
|
-
const [error] = result.getErrors();
|
|
281
|
-
|
|
282
|
-
expect(error).to.be.an.instanceOf(DataTriggerConditionError);
|
|
283
|
-
expect(error.message).to.equal(
|
|
284
|
-
'Full domain name length can not be more than 253 characters long but got 518',
|
|
285
|
-
);
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
it('should fail with identity can\'t create top level domain', async () => {
|
|
289
|
-
parentDocumentTransition.data.normalizedParentDomainName = '';
|
|
290
|
-
|
|
291
|
-
topLevelIdentity = Buffer.from('someIdentity');
|
|
292
|
-
|
|
293
|
-
const result = await createDomainDataTrigger(
|
|
294
|
-
parentDocumentTransition, context, topLevelIdentity,
|
|
295
|
-
);
|
|
296
|
-
|
|
297
|
-
expect(result).to.be.an.instanceOf(DataTriggerExecutionResult);
|
|
298
|
-
expect(result.isOk()).to.be.false();
|
|
299
|
-
|
|
300
|
-
const [error] = result.getErrors();
|
|
301
|
-
|
|
302
|
-
expect(error).to.be.an.instanceOf(DataTriggerConditionError);
|
|
303
|
-
expect(error.message).to.equal(
|
|
304
|
-
'Can\'t create top level domain for this identity',
|
|
305
|
-
);
|
|
306
|
-
});
|
|
307
|
-
|
|
308
|
-
it('should fail with disallowed domain creation', async () => {
|
|
309
|
-
parentDocument.ownerId = Buffer.from('newId');
|
|
310
|
-
|
|
311
|
-
const result = await createDomainDataTrigger(
|
|
312
|
-
childDocumentTransition, context, topLevelIdentity,
|
|
313
|
-
);
|
|
314
|
-
|
|
315
|
-
expect(result).to.be.an.instanceOf(DataTriggerExecutionResult);
|
|
316
|
-
expect(result.isOk()).to.be.false();
|
|
317
|
-
|
|
318
|
-
const [error] = result.getErrors();
|
|
319
|
-
expect(error).to.be.an.instanceOf(DataTriggerConditionError);
|
|
320
|
-
expect(error.message).to.equal(
|
|
321
|
-
'The subdomain can be created only by the parent domain owner',
|
|
322
|
-
);
|
|
323
|
-
});
|
|
324
|
-
|
|
325
|
-
it('should fail with allowing subdomains for non top level domain', async () => {
|
|
326
|
-
childDocument = getChildDocumentFixture({ subdomainRules: { allowSubdomains: true } });
|
|
327
|
-
|
|
328
|
-
[childDocumentTransition] = getDocumentTransitionFixture({
|
|
329
|
-
create: [childDocument],
|
|
330
|
-
});
|
|
331
|
-
|
|
332
|
-
const result = await createDomainDataTrigger(
|
|
333
|
-
childDocumentTransition, context, topLevelIdentity,
|
|
334
|
-
);
|
|
335
|
-
|
|
336
|
-
expect(result).to.be.an.instanceOf(DataTriggerExecutionResult);
|
|
337
|
-
expect(result.isOk()).to.be.false();
|
|
338
|
-
|
|
339
|
-
const [error] = result.getErrors();
|
|
340
|
-
|
|
341
|
-
expect(error).to.be.an.instanceOf(DataTriggerConditionError);
|
|
342
|
-
expect(error.message).to.equal(
|
|
343
|
-
'Allowing subdomains registration is forbidden for non top level domains',
|
|
344
|
-
);
|
|
345
|
-
});
|
|
346
|
-
|
|
347
|
-
it('should allow creating a second level domain by any identity', async () => {
|
|
348
|
-
topDocument.ownerId = 'anotherId';
|
|
349
|
-
|
|
350
|
-
stateRepositoryMock.fetchDocuments.resolves([topDocument]);
|
|
351
|
-
|
|
352
|
-
const result = await createDomainDataTrigger(
|
|
353
|
-
parentDocumentTransition, context, topLevelIdentity,
|
|
354
|
-
);
|
|
355
|
-
|
|
356
|
-
expect(result.isOk()).to.be.true();
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
it('should return DataTriggerExecutionResult om dry run', async () => {
|
|
360
|
-
context.getStateTransitionExecutionContext().enableDryRun();
|
|
361
|
-
|
|
362
|
-
childDocument = getChildDocumentFixture({ normalizedLabel: childDocument.getData().label });
|
|
363
|
-
stateRepositoryMock.fetchTransaction
|
|
364
|
-
.withArgs(
|
|
365
|
-
childDocument.getData().records.dashUniqueIdentityId,
|
|
366
|
-
)
|
|
367
|
-
.resolves({ confirmations: 10 });
|
|
368
|
-
|
|
369
|
-
[childDocumentTransition] = getDocumentTransitionFixture({
|
|
370
|
-
create: [childDocument],
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
const result = await createDomainDataTrigger(
|
|
374
|
-
childDocumentTransition, context, topLevelIdentity,
|
|
375
|
-
);
|
|
376
|
-
|
|
377
|
-
context.getStateTransitionExecutionContext().disableDryRun();
|
|
378
|
-
|
|
379
|
-
expect(result).to.be.an.instanceOf(DataTriggerExecutionResult);
|
|
380
|
-
expect(result.isOk()).to.be.true();
|
|
381
|
-
});
|
|
382
|
-
});
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
const Long = require('long');
|
|
2
|
-
|
|
3
|
-
const createFeatureFlagDataTrigger = require('@dashevo/dpp/lib/dataTrigger/featureFlagsDataTriggers/createFeatureFlagDataTrigger');
|
|
4
|
-
|
|
5
|
-
const getIdentityFixture = require('@dashevo/dpp/lib/test/fixtures/getIdentityFixture');
|
|
6
|
-
const getFeatureFlagsDocumentsFixture = require('@dashevo/dpp/lib/test/fixtures/getFeatureFlagsDocumentsFixture');
|
|
7
|
-
const getDocumentTransitionsFixture = require('@dashevo/dpp/lib/test/fixtures/getDocumentTransitionsFixture');
|
|
8
|
-
const createStateRepositoryMock = require('@dashevo/dpp/lib/test/mocks/createStateRepositoryMock');
|
|
9
|
-
const DataTriggerExecutionResult = require('@dashevo/dpp/lib/dataTrigger/DataTriggerExecutionResult');
|
|
10
|
-
const DataTriggerConditionError = require('@dashevo/dpp/lib/errors/consensus/state/dataContract/dataTrigger/DataTriggerConditionError');
|
|
11
|
-
const Identifier = require('@dashevo/dpp/lib/identifier/Identifier');
|
|
12
|
-
const StateTransitionExecutionContext = require('@dashevo/dpp/lib/stateTransition/StateTransitionExecutionContext');
|
|
13
|
-
|
|
14
|
-
describe('createFeatureFlagDataTrigger', () => {
|
|
15
|
-
let contextMock;
|
|
16
|
-
let stateRepositoryMock;
|
|
17
|
-
let documentTransition;
|
|
18
|
-
let topLevelIdentityId;
|
|
19
|
-
|
|
20
|
-
beforeEach(function beforeEach() {
|
|
21
|
-
topLevelIdentityId = getIdentityFixture().getId();
|
|
22
|
-
|
|
23
|
-
stateRepositoryMock = createStateRepositoryMock(this.sinonSandbox);
|
|
24
|
-
stateRepositoryMock.fetchLatestPlatformBlockHeight.resolves(new Long(42));
|
|
25
|
-
|
|
26
|
-
const [document] = getFeatureFlagsDocumentsFixture();
|
|
27
|
-
|
|
28
|
-
[documentTransition] = getDocumentTransitionsFixture({
|
|
29
|
-
create: [document],
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
const context = new StateTransitionExecutionContext();
|
|
33
|
-
|
|
34
|
-
contextMock = {
|
|
35
|
-
getStateRepository: () => stateRepositoryMock,
|
|
36
|
-
getOwnerId: this.sinonSandbox.stub(),
|
|
37
|
-
getDataContract: () => getFeatureFlagsDocumentsFixture.dataContract,
|
|
38
|
-
getStateTransitionExecutionContext: () => context,
|
|
39
|
-
};
|
|
40
|
-
contextMock.getOwnerId.returns(topLevelIdentityId);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('should return an error if height is lower than block height', async () => {
|
|
44
|
-
documentTransition.data.enableAtHeight = 1;
|
|
45
|
-
|
|
46
|
-
const result = await createFeatureFlagDataTrigger(
|
|
47
|
-
documentTransition, contextMock, topLevelIdentityId,
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
expect(result).to.be.an.instanceOf(DataTriggerExecutionResult);
|
|
51
|
-
expect(result.isOk()).to.be.false();
|
|
52
|
-
|
|
53
|
-
const [error] = result.getErrors();
|
|
54
|
-
|
|
55
|
-
expect(error).to.be.an.instanceOf(DataTriggerConditionError);
|
|
56
|
-
expect(error.message).to.equal('Feature flag cannot be enabled in the past on block 1. Current block height is 42');
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('should return an error if owner id is not equal to top level identity id', async () => {
|
|
60
|
-
contextMock.getOwnerId.returns(Identifier.from(Buffer.alloc(32, 1)));
|
|
61
|
-
|
|
62
|
-
const result = await createFeatureFlagDataTrigger(
|
|
63
|
-
documentTransition, contextMock, topLevelIdentityId,
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
expect(result).to.be.an.instanceOf(DataTriggerExecutionResult);
|
|
67
|
-
expect(result.isOk()).to.be.false();
|
|
68
|
-
|
|
69
|
-
const [error] = result.getErrors();
|
|
70
|
-
|
|
71
|
-
expect(error).to.be.an.instanceOf(DataTriggerConditionError);
|
|
72
|
-
expect(error.message).to.equal('This identity can\'t activate selected feature flag');
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('should pass', async () => {
|
|
76
|
-
const result = await createFeatureFlagDataTrigger(
|
|
77
|
-
documentTransition, contextMock, topLevelIdentityId,
|
|
78
|
-
);
|
|
79
|
-
|
|
80
|
-
expect(result).to.be.an.instanceOf(DataTriggerExecutionResult);
|
|
81
|
-
expect(result.isOk()).to.be.true();
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('should pass on dry run', async () => {
|
|
85
|
-
contextMock.getStateTransitionExecutionContext().enableDryRun();
|
|
86
|
-
|
|
87
|
-
const result = await createFeatureFlagDataTrigger(
|
|
88
|
-
documentTransition, contextMock, topLevelIdentityId,
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
contextMock.getStateTransitionExecutionContext().disableDryRun();
|
|
92
|
-
|
|
93
|
-
expect(result).to.be.an.instanceOf(DataTriggerExecutionResult);
|
|
94
|
-
expect(result.isOk()).to.be.true();
|
|
95
|
-
|
|
96
|
-
expect(contextMock.getOwnerId).to.not.be.called();
|
|
97
|
-
expect(stateRepositoryMock.fetchLatestPlatformBlockHeight).to.not.be.called();
|
|
98
|
-
});
|
|
99
|
-
});
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
contractId: dpnsContractId,
|
|
3
|
-
ownerId: dpnsOwnerId,
|
|
4
|
-
} = require('@dashevo/dpns-contract/lib/systemIds');
|
|
5
|
-
|
|
6
|
-
const AbstractDocumentTransition = require('@dashevo/dpp/lib/document/stateTransition/DocumentsBatchTransition/documentTransition/AbstractDocumentTransition');
|
|
7
|
-
|
|
8
|
-
const getDataTriggersFactory = require('@dashevo/dpp/lib/dataTrigger/getDataTriggersFactory');
|
|
9
|
-
|
|
10
|
-
const getDpnsDocumentFixture = require('@dashevo/dpp/lib/test/fixtures/getDpnsDocumentFixture');
|
|
11
|
-
|
|
12
|
-
const DataTrigger = require('@dashevo/dpp/lib/dataTrigger/DataTrigger');
|
|
13
|
-
|
|
14
|
-
const createDomainDataTrigger = require('@dashevo/dpp/lib/dataTrigger/dpnsTriggers/createDomainDataTrigger');
|
|
15
|
-
const rejectDataTrigger = require('@dashevo/dpp/lib/dataTrigger/rejectDataTrigger');
|
|
16
|
-
const Identifier = require('@dashevo/dpp/lib/identifier/Identifier');
|
|
17
|
-
|
|
18
|
-
describe('getDataTriggers', () => {
|
|
19
|
-
let getDataTriggers;
|
|
20
|
-
|
|
21
|
-
let createDocument;
|
|
22
|
-
let updateDocument;
|
|
23
|
-
let deleteDocument;
|
|
24
|
-
|
|
25
|
-
let createTrigger;
|
|
26
|
-
let updateTrigger;
|
|
27
|
-
let deleteTrigger;
|
|
28
|
-
|
|
29
|
-
let updatePreorderTrigger;
|
|
30
|
-
let deletePreorderTrigger;
|
|
31
|
-
|
|
32
|
-
let dataContractId;
|
|
33
|
-
let topLevelIdentity;
|
|
34
|
-
|
|
35
|
-
let processMock;
|
|
36
|
-
|
|
37
|
-
beforeEach(function beforeEach() {
|
|
38
|
-
createDocument = getDpnsDocumentFixture.getChildDocumentFixture();
|
|
39
|
-
updateDocument = getDpnsDocumentFixture.getChildDocumentFixture();
|
|
40
|
-
deleteDocument = getDpnsDocumentFixture.getChildDocumentFixture();
|
|
41
|
-
deleteDocument.data = {};
|
|
42
|
-
|
|
43
|
-
dataContractId = Identifier.from(dpnsContractId);
|
|
44
|
-
topLevelIdentity = Identifier.from(dpnsOwnerId);
|
|
45
|
-
|
|
46
|
-
createTrigger = new DataTrigger(
|
|
47
|
-
dataContractId, 'domain', AbstractDocumentTransition.ACTIONS.CREATE, createDomainDataTrigger, topLevelIdentity,
|
|
48
|
-
);
|
|
49
|
-
updateTrigger = new DataTrigger(
|
|
50
|
-
dataContractId, 'domain', AbstractDocumentTransition.ACTIONS.REPLACE, rejectDataTrigger,
|
|
51
|
-
);
|
|
52
|
-
deleteTrigger = new DataTrigger(
|
|
53
|
-
dataContractId, 'domain', AbstractDocumentTransition.ACTIONS.DELETE, rejectDataTrigger,
|
|
54
|
-
);
|
|
55
|
-
updatePreorderTrigger = new DataTrigger(
|
|
56
|
-
dataContractId, 'preorder', AbstractDocumentTransition.ACTIONS.REPLACE, rejectDataTrigger,
|
|
57
|
-
);
|
|
58
|
-
deletePreorderTrigger = new DataTrigger(
|
|
59
|
-
dataContractId, 'preorder', AbstractDocumentTransition.ACTIONS.DELETE, rejectDataTrigger,
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
processMock = this.sinonSandbox.stub(process, 'env').value({
|
|
63
|
-
DPNS_CONTRACT_ID: dataContractId,
|
|
64
|
-
DPNS_TOP_LEVEL_IDENTITY: topLevelIdentity,
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
getDataTriggers = getDataTriggersFactory();
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
afterEach(() => {
|
|
71
|
-
processMock.restore();
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('should return matching triggers', () => {
|
|
75
|
-
let result = getDataTriggers(
|
|
76
|
-
dataContractId, createDocument.getType(), AbstractDocumentTransition.ACTIONS.CREATE,
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
expect(result).to.deep.equal([createTrigger]);
|
|
80
|
-
|
|
81
|
-
result = getDataTriggers(
|
|
82
|
-
dataContractId, updateDocument.getType(), AbstractDocumentTransition.ACTIONS.REPLACE,
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
expect(result).to.deep.equal([updateTrigger]);
|
|
86
|
-
|
|
87
|
-
result = getDataTriggers(
|
|
88
|
-
dataContractId, deleteDocument.getType(), AbstractDocumentTransition.ACTIONS.DELETE,
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
expect(result).to.deep.equal([deleteTrigger]);
|
|
92
|
-
|
|
93
|
-
result = getDataTriggers(
|
|
94
|
-
dataContractId, 'preorder', AbstractDocumentTransition.ACTIONS.REPLACE,
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
expect(result).to.deep.equal([updatePreorderTrigger]);
|
|
98
|
-
|
|
99
|
-
result = getDataTriggers(
|
|
100
|
-
dataContractId, 'preorder', AbstractDocumentTransition.ACTIONS.DELETE,
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
expect(result).to.deep.equal([deletePreorderTrigger]);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('should return empty trigger array for any other type except `domain`', () => {
|
|
107
|
-
const result = getDataTriggers(
|
|
108
|
-
dataContractId, 'otherType', AbstractDocumentTransition.ACTIONS.CREATE,
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
expect(result).to.deep.equal([]);
|
|
112
|
-
});
|
|
113
|
-
});
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
const bs58 = require('bs58');
|
|
2
|
-
const rejectDataTrigger = require('@dashevo/dpp/lib/dataTrigger/rejectDataTrigger');
|
|
3
|
-
|
|
4
|
-
const DataTriggerExecutionContext = require('@dashevo/dpp/lib/dataTrigger/DataTriggerExecutionContext');
|
|
5
|
-
|
|
6
|
-
const { getChildDocumentFixture } = require('@dashevo/dpp/lib/test/fixtures/getDpnsDocumentFixture');
|
|
7
|
-
|
|
8
|
-
const createStateRepositoryMock = require('@dashevo/dpp/lib/test/mocks/createStateRepositoryMock');
|
|
9
|
-
|
|
10
|
-
const getDpnsContractFixture = require('@dashevo/dpp/lib/test/fixtures/getDpnsContractFixture');
|
|
11
|
-
const getDocumentTransitionFixture = require('@dashevo/dpp/lib/test/fixtures/getDocumentTransitionsFixture');
|
|
12
|
-
|
|
13
|
-
const DataTriggerExecutionResult = require('@dashevo/dpp/lib/dataTrigger/DataTriggerExecutionResult');
|
|
14
|
-
const StateTransitionExecutionContext = require('@dashevo/dpp/lib/stateTransition/StateTransitionExecutionContext');
|
|
15
|
-
|
|
16
|
-
describe('rejectDataTrigger', () => {
|
|
17
|
-
let documentTransition;
|
|
18
|
-
let context;
|
|
19
|
-
let stateRepositoryMock;
|
|
20
|
-
let dataContract;
|
|
21
|
-
|
|
22
|
-
beforeEach(function beforeEach() {
|
|
23
|
-
dataContract = getDpnsContractFixture();
|
|
24
|
-
const document = getChildDocumentFixture();
|
|
25
|
-
|
|
26
|
-
[documentTransition] = getDocumentTransitionFixture({
|
|
27
|
-
create: [],
|
|
28
|
-
delete: [document],
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
stateRepositoryMock = createStateRepositoryMock(this.sinonSandbox);
|
|
32
|
-
context = new DataTriggerExecutionContext(
|
|
33
|
-
stateRepositoryMock,
|
|
34
|
-
bs58.decode('5zcXZpTLWFwZjKjq3ME5KVavtZa9YUaZESVzrndehBhq'),
|
|
35
|
-
dataContract,
|
|
36
|
-
new StateTransitionExecutionContext(),
|
|
37
|
-
);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('should always fail', async () => {
|
|
41
|
-
const result = await rejectDataTrigger(documentTransition, context);
|
|
42
|
-
|
|
43
|
-
expect(result).to.be.an.instanceOf(DataTriggerExecutionResult);
|
|
44
|
-
|
|
45
|
-
expect(result.isOk()).to.be.false();
|
|
46
|
-
|
|
47
|
-
const [error] = result.getErrors();
|
|
48
|
-
|
|
49
|
-
expect(error.message).to.equal('Action is not allowed');
|
|
50
|
-
});
|
|
51
|
-
});
|