@dashevo/wasm-dpp 0.25.0-dev.1 → 0.25.0-dev.11
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/dist/wasm/wasm_dpp.d.ts +431 -436
- package/dist/wasm/wasm_dpp.js +39 -44
- package/dist/wasm/wasm_dpp_bg.js +1 -1
- package/lib/test/fixtures/getDocumentsFixture.js +5 -1
- package/lib/wasm/wasm_dpp.d.ts +431 -436
- package/package.json +3 -3
- package/src/dash_platform_protocol.rs +1 -1
- package/src/data_contract/data_contract.rs +2 -1
- package/src/data_contract/state_transition/data_contract_create_transition/mod.rs +6 -5
- package/src/data_contract/state_transition/data_contract_update_transition/mod.rs +6 -5
- package/src/document/extended_document.rs +2 -2
- package/src/document/state_transition/document_batch_transition/mod.rs +6 -9
- package/src/errors/consensus/basic/invalid_signature_public_key_security_level_error.rs +6 -6
- package/src/identity/factory_utils.rs +4 -4
- package/src/identity/mod.rs +4 -2
- package/src/identity/state_transition/identity_create_transition/identity_create_transition.rs +11 -19
- package/src/identity/state_transition/identity_create_transition/to_object.rs +2 -2
- package/src/identity/state_transition/identity_public_key_transitions.rs +10 -10
- package/src/identity/state_transition/identity_topup_transition/identity_topup_transition.rs +7 -15
- package/src/identity/state_transition/identity_update_transition/identity_update_public_keys_validator.rs +2 -2
- package/src/identity/state_transition/identity_update_transition/identity_update_transition.rs +10 -18
- package/src/identity/state_transition/identity_update_transition/to_object.rs +2 -2
- package/src/identity/state_transition/validate_public_key_signatures.rs +2 -2
- package/src/state_transition/state_transition_facade.rs +3 -7
- package/src/state_transition/validation/validate_state_transition_identity_signature.rs +20 -6
- package/test/integration/dataContract/DataContractFacade.spec.js +17 -20
- package/test/integration/dataContract/stateTransition/DataContractUpdateTransition/validation/basic/validateDataContractUpdateTransitionBasicFactory.spec.js +5 -4
- package/test/integration/stateTransition/StateTransitionFacade.spec.js +1 -1
- package/test/unit/dataContract/DataContract.spec.js +9 -21
- package/test/unit/dataContract/DataContractFactory.spec.js +19 -28
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/DataContractCreateTransition.spec.js +2 -4
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/validation/state/validateDataContractCreateTransitionStateFactory.spec.js +6 -5
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/DataContractUpdateTransition.spec.js +3 -5
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/validation/state/validateDataContractUpdateTransitionStateFactory.spec.js +5 -4
- package/test/unit/decodeProtocolEntityFactory.spec.js +4 -1
- package/test/unit/document/Document.spec.js +9 -7
- package/test/unit/document/DocumentFactory.spec.js +38 -90
- package/test/unit/document/stateTransition/DocumetsBatchTransition/DocumentsBatchTransition.spec.js +2 -3
- package/test/unit/identity/Identity.spec.js +3 -8
- package/test/unit/identity/IdentityFactory.spec.js +3 -4
- package/test/unit/stateTransition/validation/validateStateTransitionBasicFactory.spec.js +2 -2
- package/test/unit/stateTransition/validation/validateStateTransitionFeeFactory.spec.js +4 -16
- package/test/unit/stateTransition/validation/validateStateTransitionIdentitySignatureFactory.spec.js +8 -4
|
@@ -2,50 +2,38 @@ const bs58 = require('bs58');
|
|
|
2
2
|
|
|
3
3
|
const DocumentCreateTransition = require('@dashevo/dpp/lib/document/stateTransition/DocumentsBatchTransition/documentTransition/DocumentCreateTransition');
|
|
4
4
|
const ValidationResult = require('@dashevo/dpp/lib/validation/ValidationResult');
|
|
5
|
-
const createDPPMock = require('@dashevo/dpp/lib/test/mocks/createDPPMock');
|
|
6
|
-
const DocumentFactoryJS = require('@dashevo/dpp/lib/document/DocumentFactory');
|
|
7
5
|
|
|
8
|
-
const
|
|
9
|
-
const
|
|
6
|
+
const getDataContractFixture = require('../../../lib/test/fixtures/getDataContractFixture');
|
|
7
|
+
const getDocumentsFixture = require('../../../lib/test/fixtures/getDocumentsFixture');
|
|
10
8
|
const createStateRepositoryMock = require('../../../lib/test/mocks/createStateRepositoryMock');
|
|
11
9
|
const generateRandomIdentifierAsync = require('../../../lib/test/utils/generateRandomIdentifierAsync');
|
|
12
10
|
|
|
13
11
|
let {
|
|
14
|
-
Identifier, DocumentFactory,
|
|
12
|
+
Identifier, DocumentFactory, ExtendedDocument, DocumentValidator,
|
|
15
13
|
ProtocolVersionValidator, InvalidDocumentTypeInDataContractError, InvalidDocumentError,
|
|
16
14
|
JsonSchemaError, NoDocumentsSuppliedError, MismatchOwnerIdsError, InvalidInitialRevisionError,
|
|
17
|
-
InvalidActionNameError,
|
|
15
|
+
InvalidActionNameError,
|
|
18
16
|
} = require('../../..');
|
|
19
17
|
|
|
20
|
-
const { default: loadWasmDpp } = require('../../..');
|
|
18
|
+
const { default: loadWasmDpp, SerializedObjectParsingError } = require('../../..');
|
|
21
19
|
|
|
22
20
|
describe('DocumentFactory', () => {
|
|
23
|
-
let decodeProtocolEntityMock;
|
|
24
|
-
let validateDocumentMock;
|
|
25
|
-
let fetchAndValidateDataContractMock;
|
|
26
21
|
let stateRepositoryMock;
|
|
27
22
|
let ownerIdJs;
|
|
28
23
|
let ownerId;
|
|
29
24
|
let dataContract;
|
|
30
25
|
let dataContractJs;
|
|
31
26
|
let document;
|
|
32
|
-
let documentJs;
|
|
33
|
-
let documentsJs;
|
|
34
27
|
let documents;
|
|
35
28
|
let rawDocument;
|
|
36
|
-
let rawDocumentJs;
|
|
37
|
-
let factoryJs;
|
|
38
29
|
let factory;
|
|
39
|
-
let fakeTime;
|
|
40
|
-
let fakeTimeDate;
|
|
41
|
-
let dppMock;
|
|
42
30
|
let dataContractId;
|
|
43
31
|
let documentValidator;
|
|
44
32
|
|
|
45
33
|
beforeEach(async () => {
|
|
46
34
|
({
|
|
47
35
|
Identifier, ProtocolVersionValidator, DocumentValidator, DocumentFactory,
|
|
48
|
-
|
|
36
|
+
ExtendedDocument,
|
|
49
37
|
// Errors:
|
|
50
38
|
InvalidDocumentTypeInDataContractError,
|
|
51
39
|
InvalidDocumentError,
|
|
@@ -54,62 +42,29 @@ describe('DocumentFactory', () => {
|
|
|
54
42
|
MismatchOwnerIdsError,
|
|
55
43
|
InvalidInitialRevisionError,
|
|
56
44
|
InvalidActionNameError,
|
|
57
|
-
PlatformValueError,
|
|
58
45
|
} = await loadWasmDpp());
|
|
59
46
|
});
|
|
60
47
|
|
|
61
|
-
beforeEach(function beforeEach() {
|
|
48
|
+
beforeEach(async function beforeEach() {
|
|
62
49
|
const protocolValidator = new ProtocolVersionValidator();
|
|
63
50
|
documentValidator = new DocumentValidator(protocolValidator);
|
|
64
51
|
|
|
65
|
-
|
|
66
|
-
|
|
52
|
+
dataContract = await getDataContractFixture();
|
|
53
|
+
dataContractId = dataContract.getId();
|
|
67
54
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const dc = DataContract.fromBuffer(dataContractJs.toBuffer());
|
|
71
|
-
dataContractId = dataContractJs.getId().toBuffer();
|
|
55
|
+
documents = await getDocumentsFixture(dataContract);
|
|
56
|
+
ownerId = documents[0].getOwnerId();
|
|
72
57
|
|
|
73
|
-
documentsJs = getDocumentsFixtureJs(dataContractJs);
|
|
74
|
-
documents = documentsJs.map((d) => {
|
|
75
|
-
const doc = new ExtendedDocument(d.toObject(), dataContract);
|
|
76
|
-
doc.setEntropy(d.entropy);
|
|
77
|
-
return doc;
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
([, , , documentJs] = documentsJs);
|
|
81
|
-
rawDocumentJs = documentJs.toObject();
|
|
82
58
|
([, , , document] = documents);
|
|
83
59
|
rawDocument = document.toObject();
|
|
84
60
|
|
|
85
|
-
decodeProtocolEntityMock = this.sinonSandbox.stub();
|
|
86
|
-
validateDocumentMock = this.sinonSandbox.stub();
|
|
87
|
-
|
|
88
|
-
validateDocumentMock.returns(new ValidationResult());
|
|
89
|
-
|
|
90
61
|
const fetchContractResult = new ValidationResult();
|
|
91
62
|
fetchContractResult.setData(dataContractJs);
|
|
92
63
|
|
|
93
64
|
stateRepositoryMock = createStateRepositoryMock(this.sinonSandbox);
|
|
94
|
-
stateRepositoryMock.fetchDataContract.resolves(
|
|
95
|
-
|
|
96
|
-
fetchAndValidateDataContractMock = this.sinonSandbox.stub().returns(fetchContractResult);
|
|
97
|
-
dppMock = createDPPMock();
|
|
65
|
+
stateRepositoryMock.fetchDataContract.resolves(dataContract);
|
|
98
66
|
|
|
99
67
|
factory = new DocumentFactory(1, documentValidator, stateRepositoryMock);
|
|
100
|
-
factoryJs = new DocumentFactoryJS(
|
|
101
|
-
dppMock,
|
|
102
|
-
validateDocumentMock,
|
|
103
|
-
fetchAndValidateDataContractMock,
|
|
104
|
-
decodeProtocolEntityMock,
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
fakeTimeDate = new Date();
|
|
108
|
-
fakeTime = this.sinonSandbox.useFakeTimers(fakeTimeDate);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
afterEach(() => {
|
|
112
|
-
fakeTime.reset();
|
|
113
68
|
});
|
|
114
69
|
|
|
115
70
|
describe('create', () => {
|
|
@@ -118,7 +73,7 @@ describe('DocumentFactory', () => {
|
|
|
118
73
|
// should be valid for this test and it passes the DataContract validation.
|
|
119
74
|
// The previous version of test passed due to the fact that
|
|
120
75
|
// the mocked DataContract validator always returned true.
|
|
121
|
-
const [niceDocument] =
|
|
76
|
+
const [niceDocument] = documents;
|
|
122
77
|
|
|
123
78
|
const newRawDocument = niceDocument.toObject();
|
|
124
79
|
const contractId = bs58.decode('FQco85WbwNgb5ix8QQAH6wurMcgEC5ENSCv5ixG9cj12');
|
|
@@ -227,12 +182,11 @@ describe('DocumentFactory', () => {
|
|
|
227
182
|
});
|
|
228
183
|
|
|
229
184
|
it('should throw InvalidDocumentError if Data Contract is not valid', async () => {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
stateRepositoryMock.fetchDataContract.resolves(dc);
|
|
185
|
+
dataContract.setDocuments({ '$%34': { '^&*': 'Keck' } });
|
|
186
|
+
stateRepositoryMock.fetchDataContract.resolves(dataContract);
|
|
233
187
|
|
|
234
188
|
try {
|
|
235
|
-
await factory.createFromObject(
|
|
189
|
+
await factory.createFromObject(rawDocument);
|
|
236
190
|
|
|
237
191
|
expect.fail('InvalidDocumentTypeInDataContractError should be thrown');
|
|
238
192
|
} catch (e) {
|
|
@@ -241,7 +195,7 @@ describe('DocumentFactory', () => {
|
|
|
241
195
|
expect(stateRepositoryMock.fetchDataContract.callCount).to.be.equal(1);
|
|
242
196
|
const callArguments = stateRepositoryMock.fetchDataContract.getCall(0).args[0];
|
|
243
197
|
|
|
244
|
-
expect(callArguments.toBuffer()).to.be.deep.equal(
|
|
198
|
+
expect(callArguments.toBuffer()).to.be.deep.equal(dataContract.getId().toBuffer());
|
|
245
199
|
}
|
|
246
200
|
});
|
|
247
201
|
});
|
|
@@ -249,28 +203,22 @@ describe('DocumentFactory', () => {
|
|
|
249
203
|
describe('createFromBuffer', () => {
|
|
250
204
|
let serializedDocument;
|
|
251
205
|
|
|
252
|
-
beforeEach(
|
|
253
|
-
this.sinonSandbox.stub(factoryJs, 'createFromObject');
|
|
206
|
+
beforeEach(() => {
|
|
254
207
|
// eslint-disable-next-line prefer-destructuring
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
rawDocumentJs = documentJs.toObject();
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
afterEach(() => {
|
|
262
|
-
factoryJs.createFromObject.restore();
|
|
208
|
+
document = documents[8]; // document with binary fields
|
|
209
|
+
serializedDocument = document.toBuffer();
|
|
210
|
+
rawDocument = document.toObject();
|
|
263
211
|
});
|
|
264
212
|
|
|
265
213
|
it('should return new Document from serialized one', async () => {
|
|
266
214
|
const result = await factory.createFromBuffer(serializedDocument);
|
|
267
|
-
expect(result.toObject()).to.deep.equal(
|
|
215
|
+
expect(result.toObject()).to.deep.equal(document.toObject());
|
|
268
216
|
expect(stateRepositoryMock.fetchDataContract).to.have.been.calledOnce();
|
|
269
217
|
});
|
|
270
218
|
|
|
271
219
|
it('should throw InvalidDocumentError if the decoding fails with consensus error', async () => {
|
|
272
|
-
|
|
273
|
-
serializedDocument =
|
|
220
|
+
stateRepositoryMock.fetchDataContract.resolves(null);
|
|
221
|
+
serializedDocument = document.toBuffer();
|
|
274
222
|
|
|
275
223
|
try {
|
|
276
224
|
await factory.createFromBuffer(serializedDocument);
|
|
@@ -281,18 +229,19 @@ describe('DocumentFactory', () => {
|
|
|
281
229
|
}
|
|
282
230
|
});
|
|
283
231
|
|
|
284
|
-
it('should throw an error if decoding fails with any other error
|
|
232
|
+
it('should throw an error if decoding fails with any other error', async () => {
|
|
285
233
|
const serializeDocument = Buffer.alloc(160, 1);
|
|
286
234
|
try {
|
|
287
235
|
await factory.createFromBuffer(serializeDocument);
|
|
288
236
|
|
|
289
237
|
expect.fail('should throw an error');
|
|
290
238
|
} catch (e) {
|
|
291
|
-
expect(e).to.be.instanceOf(
|
|
292
|
-
expect(e.getMessage()).to.equal('structure error: value is not a map');
|
|
239
|
+
expect(e).to.be.instanceOf(SerializedObjectParsingError);
|
|
293
240
|
}
|
|
294
241
|
});
|
|
295
|
-
});
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
describe('createStateTransition', () => {
|
|
296
245
|
it('should throw and error if documents have unknown action', async () => {
|
|
297
246
|
try {
|
|
298
247
|
factory.createStateTransition({
|
|
@@ -348,23 +297,22 @@ describe('DocumentFactory', () => {
|
|
|
348
297
|
});
|
|
349
298
|
|
|
350
299
|
it('should create DocumentsBatchTransition with passed documents', async () => {
|
|
351
|
-
const [
|
|
352
|
-
|
|
300
|
+
const [newDocument] = await getDocumentsFixture(dataContract);
|
|
301
|
+
newDocument.setData({ lastName: 'Keck' });
|
|
353
302
|
|
|
354
303
|
const stateTransition = factory.createStateTransition({
|
|
355
304
|
create: documents,
|
|
356
305
|
replace: [newDocument],
|
|
357
306
|
});
|
|
358
307
|
|
|
359
|
-
const
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
const transitions = stateTransition.getTransitions().map((t) => t.toObject());
|
|
365
|
-
const expectedTransitions = stateTransitionJs.getTransitions().map((t) => t.toObject());
|
|
308
|
+
const replaceDocuments = stateTransition.getTransitions()
|
|
309
|
+
.filter((t) => t.getAction() === 1);
|
|
310
|
+
const createDocuments = stateTransition.getTransitions()
|
|
311
|
+
.filter((t) => t.getAction() === 0);
|
|
366
312
|
|
|
367
|
-
expect(
|
|
313
|
+
expect(replaceDocuments[0].getId()).to.deep.equal(newDocument.getId());
|
|
314
|
+
expect(replaceDocuments[0].getRevision()).to.deep.equal(2);
|
|
315
|
+
expect(createDocuments).to.have.lengthOf(documents.length);
|
|
368
316
|
});
|
|
369
317
|
});
|
|
370
318
|
});
|
package/test/unit/document/stateTransition/DocumetsBatchTransition/DocumentsBatchTransition.spec.js
CHANGED
|
@@ -105,10 +105,9 @@ describe('DocumentsBatchTransition', () => {
|
|
|
105
105
|
|
|
106
106
|
describe('#toBuffer', () => {
|
|
107
107
|
it('should return the same bytes as JS version', () => {
|
|
108
|
-
const bufferJs = stateTransitionJs.toBuffer();
|
|
109
108
|
const buffer = stateTransition.toBuffer();
|
|
110
|
-
|
|
111
|
-
expect(
|
|
109
|
+
expect(buffer).to.be.instanceOf(Buffer);
|
|
110
|
+
expect(buffer).to.have.length(23960);
|
|
112
111
|
});
|
|
113
112
|
});
|
|
114
113
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
const varint = require('varint');
|
|
2
2
|
const JSIdentityPublicKey = require('@dashevo/dpp/lib/identity/IdentityPublicKey');
|
|
3
3
|
const protocolVersion = require('@dashevo/dpp/lib/version/protocolVersion');
|
|
4
|
-
const JSIdentity = require('@dashevo/dpp/lib/identity/Identity');
|
|
5
4
|
|
|
6
5
|
const { hash: hashFunction } = require('@dashevo/dpp/lib/util/hash');
|
|
7
6
|
const { expect } = require('chai');
|
|
@@ -135,14 +134,10 @@ describe('Identity', () => {
|
|
|
135
134
|
});
|
|
136
135
|
|
|
137
136
|
describe('#toBuffer', () => {
|
|
138
|
-
it('should return
|
|
139
|
-
// Due to browser polyfill, we got two different versions of buffers, and makes
|
|
140
|
-
// the compatibility test to fail in karma, so hence this hack here.
|
|
141
|
-
rawIdentity.id = Buffer.from(rawIdentity.id.toBuffer());
|
|
142
|
-
const oldIdentity = new JSIdentity(rawIdentity);
|
|
137
|
+
it('should return buffer', () => {
|
|
143
138
|
const result = identity.toBuffer();
|
|
144
|
-
|
|
145
|
-
expect(result).to.
|
|
139
|
+
expect(result).to.be.instanceOf(Buffer);
|
|
140
|
+
expect(result).to.have.length(87);
|
|
146
141
|
});
|
|
147
142
|
});
|
|
148
143
|
|
|
@@ -2,7 +2,7 @@ const IdentityPublicKey = require('@dashevo/dpp/lib/identity/IdentityPublicKey')
|
|
|
2
2
|
const getInstantAssetLockProofFixture = require('@dashevo/dpp/lib/test/fixtures/getInstantAssetLockProofFixture');
|
|
3
3
|
const getIdentityFixture = require('@dashevo/dpp/lib/test/fixtures/getIdentityFixture');
|
|
4
4
|
const getChainAssetLockProofFixture = require('../../../lib/test/fixtures/getChainAssetLockProofFixture');
|
|
5
|
-
const { default: loadWasmDpp } = require('../../../dist');
|
|
5
|
+
const { default: loadWasmDpp, SerializedObjectParsingError } = require('../../../dist');
|
|
6
6
|
const getBlsAdapterMock = require('../../../lib/test/mocks/getBlsAdapterMock');
|
|
7
7
|
|
|
8
8
|
describe('IdentityFactory', () => {
|
|
@@ -21,7 +21,6 @@ describe('IdentityFactory', () => {
|
|
|
21
21
|
let IdentityUpdateTransition;
|
|
22
22
|
let IdentityPublicKeyWithWitness;
|
|
23
23
|
let InvalidIdentityError;
|
|
24
|
-
let PlatformValueError;
|
|
25
24
|
let UnsupportedProtocolVersionError;
|
|
26
25
|
let ChainAssetLockProof;
|
|
27
26
|
|
|
@@ -30,7 +29,7 @@ describe('IdentityFactory', () => {
|
|
|
30
29
|
Identity, IdentityFactory, IdentityValidator,
|
|
31
30
|
InstantAssetLockProof, ChainAssetLockProof, IdentityUpdateTransition,
|
|
32
31
|
IdentityCreateTransition, IdentityTopUpTransition, IdentityPublicKeyWithWitness,
|
|
33
|
-
InvalidIdentityError, UnsupportedProtocolVersionError,
|
|
32
|
+
InvalidIdentityError, UnsupportedProtocolVersionError,
|
|
34
33
|
} = await loadWasmDpp());
|
|
35
34
|
});
|
|
36
35
|
|
|
@@ -149,7 +148,7 @@ describe('IdentityFactory', () => {
|
|
|
149
148
|
|
|
150
149
|
expect.fail('should throw an error');
|
|
151
150
|
} catch (e) {
|
|
152
|
-
expect(e).to.be.instanceOf(
|
|
151
|
+
expect(e).to.be.instanceOf(SerializedObjectParsingError);
|
|
153
152
|
}
|
|
154
153
|
});
|
|
155
154
|
});
|
|
@@ -87,11 +87,11 @@ describe('validateStateTransitionBasicFactory', () => {
|
|
|
87
87
|
expect(error).to.instanceof(JsonSchemaError);
|
|
88
88
|
});
|
|
89
89
|
|
|
90
|
-
it('should return invalid result if ST size is more than
|
|
90
|
+
it('should return invalid result if ST size is more than 25 kb', async () => {
|
|
91
91
|
const largeDocument = rawStateTransition.dataContract.documents.niceDocument;
|
|
92
92
|
|
|
93
93
|
// generate big state transition
|
|
94
|
-
for (let i = 0; i <
|
|
94
|
+
for (let i = 0; i < 7; i++) {
|
|
95
95
|
largeDocument.properties[`name${i}`] = { type: 'string' };
|
|
96
96
|
}
|
|
97
97
|
for (let i = 0; i < 90; i++) {
|
|
@@ -42,10 +42,9 @@ describe('validateStateTransitionFeeFactory', () => {
|
|
|
42
42
|
|
|
43
43
|
const validator = new StateTransitionFeeValidator(stateRepositoryMock);
|
|
44
44
|
|
|
45
|
-
validateStateTransitionFee = (st) => validator.validate(st);
|
|
46
|
-
|
|
47
45
|
executionContext = new StateTransitionExecutionContext();
|
|
48
46
|
executionContext.disableDryRun();
|
|
47
|
+
validateStateTransitionFee = (st) => validator.validate(st, executionContext);
|
|
49
48
|
|
|
50
49
|
dataContract = await getDataContractFixture();
|
|
51
50
|
});
|
|
@@ -61,7 +60,6 @@ describe('validateStateTransitionFeeFactory', () => {
|
|
|
61
60
|
|
|
62
61
|
it('should return invalid result if balance is not enough', async () => {
|
|
63
62
|
executionContext.addOperation(new PreCalculatedOperation(0, 42, []));
|
|
64
|
-
dataContractCreateTransition.setExecutionContext(executionContext);
|
|
65
63
|
stateRepositoryMock.fetchIdentityBalance.resolves(1);
|
|
66
64
|
|
|
67
65
|
const result = await validateStateTransitionFee(dataContractCreateTransition);
|
|
@@ -83,7 +81,6 @@ describe('validateStateTransitionFeeFactory', () => {
|
|
|
83
81
|
stateRepositoryMock.fetchIdentityBalance.resolves(42);
|
|
84
82
|
|
|
85
83
|
executionContext.addOperation(new PreCalculatedOperation(0, 42, []));
|
|
86
|
-
dataContractCreateTransition.setExecutionContext(executionContext);
|
|
87
84
|
|
|
88
85
|
const result = await validateStateTransitionFee(dataContractCreateTransition);
|
|
89
86
|
|
|
@@ -112,7 +109,6 @@ describe('validateStateTransitionFeeFactory', () => {
|
|
|
112
109
|
stateRepositoryMock.fetchIdentityBalance.resolves(1);
|
|
113
110
|
|
|
114
111
|
executionContext.addOperation(new PreCalculatedOperation(0, 42, []));
|
|
115
|
-
documentsBatchTransition.setExecutionContext(executionContext);
|
|
116
112
|
|
|
117
113
|
const result = await validateStateTransitionFee(documentsBatchTransition);
|
|
118
114
|
|
|
@@ -133,7 +129,6 @@ describe('validateStateTransitionFeeFactory', () => {
|
|
|
133
129
|
stateRepositoryMock.fetchIdentityBalance.resolves(42);
|
|
134
130
|
|
|
135
131
|
executionContext.addOperation(new PreCalculatedOperation(0, 42, []));
|
|
136
|
-
documentsBatchTransition.setExecutionContext(executionContext);
|
|
137
132
|
|
|
138
133
|
const result = await validateStateTransitionFee(documentsBatchTransition);
|
|
139
134
|
|
|
@@ -151,11 +146,10 @@ describe('validateStateTransitionFeeFactory', () => {
|
|
|
151
146
|
executionContext.enableDryRun();
|
|
152
147
|
|
|
153
148
|
executionContext.addOperation(new PreCalculatedOperation(0, 42, []));
|
|
154
|
-
documentsBatchTransition.setExecutionContext(executionContext);
|
|
155
149
|
|
|
156
150
|
const result = await validateStateTransitionFee(documentsBatchTransition);
|
|
157
151
|
|
|
158
|
-
|
|
152
|
+
executionContext.disableDryRun();
|
|
159
153
|
|
|
160
154
|
expect(result.isValid()).to.be.true();
|
|
161
155
|
|
|
@@ -182,7 +176,6 @@ describe('validateStateTransitionFeeFactory', () => {
|
|
|
182
176
|
|
|
183
177
|
it('should return invalid result if asset lock output amount is not enough', async () => {
|
|
184
178
|
executionContext.addOperation(new PreCalculatedOperation(0, outputAmount + 1, []));
|
|
185
|
-
identityCreateTransition.setExecutionContext(executionContext);
|
|
186
179
|
|
|
187
180
|
const result = await validateStateTransitionFee(identityCreateTransition);
|
|
188
181
|
|
|
@@ -198,7 +191,6 @@ describe('validateStateTransitionFeeFactory', () => {
|
|
|
198
191
|
|
|
199
192
|
it('should return valid result', async () => {
|
|
200
193
|
executionContext.addOperation(new PreCalculatedOperation(0, outputAmount, []));
|
|
201
|
-
identityCreateTransition.setExecutionContext(executionContext);
|
|
202
194
|
|
|
203
195
|
const result = await validateStateTransitionFee(identityCreateTransition);
|
|
204
196
|
|
|
@@ -210,11 +202,10 @@ describe('validateStateTransitionFeeFactory', () => {
|
|
|
210
202
|
it('should not increase balance on dry run', async () => {
|
|
211
203
|
executionContext.enableDryRun();
|
|
212
204
|
executionContext.addOperation(new PreCalculatedOperation(0, outputAmount + 1, []));
|
|
213
|
-
identityCreateTransition.setExecutionContext(executionContext);
|
|
214
205
|
|
|
215
206
|
const result = await validateStateTransitionFee(identityCreateTransition);
|
|
216
207
|
|
|
217
|
-
|
|
208
|
+
executionContext.disableDryRun();
|
|
218
209
|
|
|
219
210
|
expect(result.isValid()).to.be.true();
|
|
220
211
|
});
|
|
@@ -240,7 +231,6 @@ describe('validateStateTransitionFeeFactory', () => {
|
|
|
240
231
|
stateRepositoryMock.fetchIdentityBalanceWithDebt.resolves(1);
|
|
241
232
|
|
|
242
233
|
executionContext.addOperation(new PreCalculatedOperation(0, outputAmount + 2, []));
|
|
243
|
-
identityTopUpTransition.setExecutionContext(executionContext);
|
|
244
234
|
|
|
245
235
|
const result = await validateStateTransitionFee(identityTopUpTransition);
|
|
246
236
|
|
|
@@ -261,7 +251,6 @@ describe('validateStateTransitionFeeFactory', () => {
|
|
|
261
251
|
stateRepositoryMock.fetchIdentityBalanceWithDebt.resolves(41);
|
|
262
252
|
|
|
263
253
|
executionContext.addOperation(new PreCalculatedOperation(0, outputAmount - 1, []));
|
|
264
|
-
identityTopUpTransition.setExecutionContext(executionContext);
|
|
265
254
|
|
|
266
255
|
const result = await validateStateTransitionFee(identityTopUpTransition);
|
|
267
256
|
|
|
@@ -278,11 +267,10 @@ describe('validateStateTransitionFeeFactory', () => {
|
|
|
278
267
|
|
|
279
268
|
executionContext.enableDryRun();
|
|
280
269
|
executionContext.addOperation(new PreCalculatedOperation(0, outputAmount + 42, []));
|
|
281
|
-
identityTopUpTransition.setExecutionContext(executionContext);
|
|
282
270
|
|
|
283
271
|
const result = await validateStateTransitionFee(identityTopUpTransition);
|
|
284
272
|
|
|
285
|
-
|
|
273
|
+
executionContext.disableDryRun();
|
|
286
274
|
|
|
287
275
|
expect(result.isValid()).to.be.true();
|
|
288
276
|
|
package/test/unit/stateTransition/validation/validateStateTransitionIdentitySignatureFactory.spec.js
CHANGED
|
@@ -70,12 +70,13 @@ describe('validateStateTransitionIdentitySignatureFactory', () => {
|
|
|
70
70
|
identity.addPublicKey(identityPublicKey);
|
|
71
71
|
|
|
72
72
|
stateTransition.sign(identity.getPublicKeyById(2), privateKey, getBlsMock());
|
|
73
|
-
stateTransition.setExecutionContext(executionContext);
|
|
74
73
|
|
|
75
74
|
stateRepositoryMock = createStateRepositoryMock(this.sinonSandbox);
|
|
76
75
|
stateRepositoryMock.fetchIdentity.resolves(identity);
|
|
77
76
|
|
|
78
|
-
validateStateTransitionIdentitySignature = (st) => validate(
|
|
77
|
+
validateStateTransitionIdentitySignature = (st) => validate(
|
|
78
|
+
stateRepositoryMock, st, executionContext, blsMock,
|
|
79
|
+
);
|
|
79
80
|
});
|
|
80
81
|
|
|
81
82
|
it('should pass properly signed state transition', async () => {
|
|
@@ -227,10 +228,13 @@ describe('validateStateTransitionIdentitySignatureFactory', () => {
|
|
|
227
228
|
|
|
228
229
|
expect(error).to.be.instanceOf(InvalidSignaturePublicKeySecurityLevelError);
|
|
229
230
|
expect(error.getPublicKeySecurityLevel()).to.equal(IdentityPublicKey.SECURITY_LEVELS.MASTER);
|
|
230
|
-
expect(error.getKeySecurityLevelRequirement()).to.equal(2);
|
|
231
|
+
expect(error.getKeySecurityLevelRequirement()).to.deep.equal([2]);
|
|
231
232
|
});
|
|
232
233
|
|
|
233
|
-
|
|
234
|
+
// TODO: the error is not used anymore,
|
|
235
|
+
// remove the test and remaining `match` variants in rs-dpp
|
|
236
|
+
// that still expecting to receive this error?
|
|
237
|
+
it.skip('should return PublicKeySecurityLevelNotMetConsensusError if PublicKeySecurityLevelNotMetError was thrown', async () => {
|
|
234
238
|
const publicKeys = identity.getPublicKeys();
|
|
235
239
|
publicKeys[2].setSecurityLevel(IdentityPublicKey.SECURITY_LEVELS.MEDIUM);
|
|
236
240
|
identity.setPublicKeys(publicKeys);
|