@dashevo/wasm-dpp 0.24.0-dev.10 → 0.24.0-dev.12
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 +2 -0
- package/dist/index.js +1 -1
- package/dist/lib/dpp.d.ts +9 -0
- package/dist/lib/errors/AbstractConsensusError.d.ts +10 -0
- package/dist/lib/errors/DPPError.d.ts +5 -0
- package/dist/lib/errors/patchConsensusErrors.d.ts +1 -0
- package/dist/lib/{patchIdentifier.d.ts → identifier/patchIdentifier.d.ts} +1 -1
- package/dist/{index.d.ts → lib/index.d.ts} +1 -1
- package/dist/lib/utils/extend.d.ts +1 -0
- package/dist/wasm/wasm_dpp.d.ts +503 -262
- package/lib/dpp.ts +24 -0
- package/lib/errors/AbstractConsensusError.ts +13 -0
- package/lib/errors/DPPError.ts +15 -0
- package/lib/errors/patchConsensusErrors.ts +175 -0
- package/lib/{patchIdentifier.ts → identifier/patchIdentifier.ts} +1 -1
- package/{index.ts → lib/index.ts} +4 -3
- package/lib/test/expect/expectError.js +4 -2
- package/lib/utils/extend.ts +6 -0
- package/package.json +5 -5
- package/src/data_contract/errors/invalid_data_contract.rs +21 -0
- package/src/data_contract/state_transition/data_contract_create_transition/apply.rs +44 -0
- package/src/data_contract/state_transition/data_contract_create_transition/mod.rs +107 -6
- package/src/data_contract/state_transition/data_contract_create_transition/validation.rs +24 -0
- package/src/data_contract/state_transition/data_contract_update_transition/apply.rs +44 -0
- package/src/data_contract/state_transition/data_contract_update_transition/mod.rs +147 -0
- package/src/data_contract/state_transition/data_contract_update_transition/validation.rs +46 -0
- package/src/data_contract/state_transition/mod.rs +2 -0
- package/src/data_contract_factory/data_contract_factory.rs +27 -12
- package/src/document/errors/document_already_exists_error.rs +1 -1
- package/src/document/errors/document_not_provided_error.rs +1 -1
- package/src/document/errors/invalid_document_action_error.rs +1 -1
- package/src/errors/consensus/basic/data_contract/data_contract_max_depth_exceed_error.rs +5 -5
- package/src/errors/consensus/basic/document/duplicate_document_transitions_with_ids_error.rs +4 -4
- package/src/errors/consensus/basic/document/duplicate_document_transitions_with_indices_error.rs +36 -0
- package/src/errors/consensus/basic/document/missing_document_transition_type_error.rs +20 -0
- package/src/errors/consensus/basic/document/mod.rs +4 -0
- package/src/errors/consensus/basic/identity/duplicated_identity_public_key_error.rs +2 -2
- package/src/errors/consensus/basic/identity/duplicated_identity_public_key_id_error.rs +2 -2
- package/src/errors/consensus/basic/identity/invalid_identity_public_key_security_level_error.rs +2 -2
- package/src/errors/consensus/basic/json_schema_error.rs +1 -1
- package/src/errors/consensus/state/data_contract/data_trigger/data_trigger_condition_error.rs +1 -1
- package/src/errors/consensus/state/data_contract/data_trigger/data_trigger_execution_error.rs +1 -1
- package/src/errors/consensus/state/data_contract/data_trigger/data_trigger_invalid_result_error.rs +1 -1
- package/src/errors/consensus_error.rs +15 -8
- package/src/errors/from.rs +1 -1
- package/src/errors/mod.rs +1 -0
- package/src/errors/protocol_error.rs +12 -0
- package/src/{identifier.rs → identifier/mod.rs} +0 -0
- package/src/{identity_facade.rs → identity/identity_facade.rs} +1 -1
- package/src/{identity_public_key → identity/identity_public_key}/key_type.rs +0 -0
- package/src/{identity_public_key → identity/identity_public_key}/mod.rs +0 -3
- package/src/{identity_public_key → identity/identity_public_key}/purpose.rs +0 -0
- package/src/{identity_public_key → identity/identity_public_key}/security_level.rs +0 -0
- package/src/{identity.rs → identity/mod.rs} +6 -7
- package/src/identity/validation/mod.rs +3 -0
- package/src/identity/validation/public_keys_validator.rs +70 -0
- package/src/lib.rs +4 -8
- package/src/state_repository.rs +229 -0
- package/src/state_transition/mod.rs +41 -0
- package/src/utils.rs +2 -2
- package/src/validation/mod.rs +3 -0
- package/src/{validation_result.rs → validation/validation_result.rs} +0 -0
- package/test/integration/identity/stateTransition/IdentityUpdateTransition/validation/state/validateIdentityUpdateTransitionStateFactory.spec.js +1 -1
- package/test/integration/identity/validation/validatePublicKeysFactory.spec.js +79 -114
- package/test/integration/stateTransition/AbstractStateTransitionIdentitySigned.spec.js +0 -11
- package/test/integration/stateTransition/StateTransitionFacade.spec.js +1 -1
- package/test/integration/stateTransition/calculateStateTransitionFeeFactory.spec.js +135 -0
- package/test/unit/dataContract/DataContract.spec.js +5 -9
- package/test/unit/dataContract/DataContractFactory.spec.js +13 -6
- package/test/unit/dataContract/errors/InvalidDataContractError.spec.js +11 -3
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/DataContractCreateTransition.spec.js +17 -64
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/applyDataContractCreateTransitionFactory.spec.js +28 -22
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/validation/state/validateDataContractCreateTransitionStateFactory.spec.js +49 -42
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/DataContractUpdateTransition.spec.js +23 -59
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/applyDataContractUpdateTransitionFactory.spec.js +27 -23
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/validation/basic/validateIndicesAreBackwardCompatible.spec.js +29 -12
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/validation/state/validateDataContractUpdateTransitionStateFactory.spec.js +66 -49
- package/test/unit/dataContract/validation/validateDataContractPatterns.spec.js +73 -0
- package/test/unit/document/stateTransition/DocumetsBatchTransition/applyDocumentsBatchTransitionFactory.spec.js +1 -1
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/validateDocumentsBatchTransitionStateFactory.spec.js +1 -1
- package/test/unit/identity/IdentityPublicKey.spec.js +25 -31
- package/tsconfig.json +1 -1
- package/wasm/wasm_dpp.d.ts +503 -262
- package/wasm/wasm_dpp.js +925 -310
- package/wasm/wasm_dpp_bg.js +1 -1
- package/wasm/wasm_dpp_bg.wasm +0 -0
- package/wasm/wasm_dpp_bg.wasm.d.ts +273 -225
- package/webpack.config.js +1 -1
- package/src/identity_public_key/public_keys_validator.rs +0 -44
- package/test/integration/stateTransition/calculateStateTransitionFee.spec.js +0 -32
- package/test/unit/dataContract/validation/validateDataContractMaxDepthFactory.spec.js +0 -93
- package/test/unit/dataContract/validation/validateDataContractPatternsFactory.spec.js +0 -64
|
@@ -194,13 +194,12 @@ describe('DataContract', () => {
|
|
|
194
194
|
|
|
195
195
|
describe('#getDocumentSchema', () => {
|
|
196
196
|
it('should throw error if Document is not defined', () => {
|
|
197
|
-
let error;
|
|
198
197
|
try {
|
|
199
198
|
dataContract.getDocumentSchema('undefinedObject');
|
|
199
|
+
expect.fail('Error was not thrown');
|
|
200
200
|
} catch (e) {
|
|
201
|
-
|
|
201
|
+
expect(e.getDocType()).to.equal('undefinedObject');
|
|
202
202
|
}
|
|
203
|
-
expect(error.getDocType()).to.equal('undefinedObject');
|
|
204
203
|
});
|
|
205
204
|
|
|
206
205
|
it('should return Document Schema', () => {
|
|
@@ -212,13 +211,12 @@ describe('DataContract', () => {
|
|
|
212
211
|
|
|
213
212
|
describe('#getDocumentSchemaRef', () => {
|
|
214
213
|
it('should throw error if Document is not defined', () => {
|
|
215
|
-
let error;
|
|
216
214
|
try {
|
|
217
215
|
dataContract.getDocumentSchemaRef('undefinedObject');
|
|
216
|
+
expect.fail('Error was not thrown');
|
|
218
217
|
} catch (e) {
|
|
219
|
-
|
|
218
|
+
expect(e.getDocType()).to.equal('undefinedObject');
|
|
220
219
|
}
|
|
221
|
-
expect(error.getDocType()).to.equal('undefinedObject');
|
|
222
220
|
});
|
|
223
221
|
|
|
224
222
|
it('should return schema ref', () => {
|
|
@@ -324,14 +322,12 @@ describe('DataContract', () => {
|
|
|
324
322
|
});
|
|
325
323
|
|
|
326
324
|
it('should throw an error if document type is not found', () => {
|
|
327
|
-
let error;
|
|
328
325
|
try {
|
|
329
326
|
dataContract.getBinaryProperties('unknown');
|
|
330
327
|
expect.fail('Error was not thrown');
|
|
331
328
|
} catch (e) {
|
|
332
|
-
|
|
329
|
+
expect(e.getDocType()).to.equal('unknown');
|
|
333
330
|
}
|
|
334
|
-
expect(error.getDocType()).to.equal('unknown');
|
|
335
331
|
});
|
|
336
332
|
});
|
|
337
333
|
|
|
@@ -9,6 +9,8 @@ describe('DataContractFactory', () => {
|
|
|
9
9
|
let DataContractValidator;
|
|
10
10
|
let DataContract;
|
|
11
11
|
let InvalidDataContractError;
|
|
12
|
+
let SerializedObjectParsingError;
|
|
13
|
+
let JsonSchemaError;
|
|
12
14
|
|
|
13
15
|
let factory;
|
|
14
16
|
let jsDataContract;
|
|
@@ -17,7 +19,12 @@ describe('DataContractFactory', () => {
|
|
|
17
19
|
|
|
18
20
|
before(async () => {
|
|
19
21
|
({
|
|
20
|
-
DataContractFactory,
|
|
22
|
+
DataContractFactory,
|
|
23
|
+
DataContractValidator,
|
|
24
|
+
DataContract,
|
|
25
|
+
InvalidDataContractError,
|
|
26
|
+
SerializedObjectParsingError,
|
|
27
|
+
JsonSchemaError,
|
|
21
28
|
} = await loadWasmDpp());
|
|
22
29
|
});
|
|
23
30
|
|
|
@@ -73,8 +80,9 @@ describe('DataContractFactory', () => {
|
|
|
73
80
|
expect(e).to.be.an.instanceOf(InvalidDataContractError);
|
|
74
81
|
expect(e.getRawDataContract()).to.deep.equal(alteredContract);
|
|
75
82
|
expect(e.getErrors()).to.have.length(1);
|
|
76
|
-
|
|
77
|
-
|
|
83
|
+
|
|
84
|
+
const [consensusError] = e.getErrors();
|
|
85
|
+
expect(consensusError).to.be.an.instanceOf(JsonSchemaError);
|
|
78
86
|
}
|
|
79
87
|
});
|
|
80
88
|
});
|
|
@@ -99,9 +107,8 @@ describe('DataContractFactory', () => {
|
|
|
99
107
|
await factory.createFromBuffer(serializedDataContract);
|
|
100
108
|
expect.fail('should throw InvalidDataContractError');
|
|
101
109
|
} catch (e) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
expect(e).to.match(/Parsing of serialized object failed/);
|
|
110
|
+
expect(e).to.be.an.instanceOf(SerializedObjectParsingError);
|
|
111
|
+
expect(e.getParsingError()).to.match(/Decode protocol entity/);
|
|
105
112
|
}
|
|
106
113
|
});
|
|
107
114
|
});
|
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
const InvalidDataContractError = require('@dashevo/dpp/lib/dataContract/errors/InvalidDataContractError');
|
|
2
1
|
const getDataContractFixture = require('@dashevo/dpp/lib/test/fixtures/getDataContractFixture');
|
|
3
2
|
|
|
3
|
+
const { default: loadWasmDpp } = require('../../../../dist');
|
|
4
|
+
|
|
4
5
|
describe('InvalidDataContractError', () => {
|
|
5
6
|
let rawDataContract;
|
|
6
7
|
let error;
|
|
8
|
+
let InvalidDataContractError;
|
|
9
|
+
|
|
10
|
+
before(async () => {
|
|
11
|
+
({
|
|
12
|
+
InvalidDataContractError,
|
|
13
|
+
} = await loadWasmDpp());
|
|
14
|
+
});
|
|
7
15
|
|
|
8
16
|
beforeEach(() => {
|
|
9
17
|
error = new Error('Some error');
|
|
@@ -33,7 +41,7 @@ describe('InvalidDataContractError', () => {
|
|
|
33
41
|
|
|
34
42
|
const invalidDataContractError = new InvalidDataContractError(errors, rawDataContract);
|
|
35
43
|
|
|
36
|
-
expect(invalidDataContractError.
|
|
44
|
+
expect(invalidDataContractError.getMessage()).to.equal(`Data contract decode error: "${error.message}"`);
|
|
37
45
|
});
|
|
38
46
|
|
|
39
47
|
it('should contain message for multiple errors', async () => {
|
|
@@ -41,6 +49,6 @@ describe('InvalidDataContractError', () => {
|
|
|
41
49
|
|
|
42
50
|
const invalidDataContractError = new InvalidDataContractError(errors, rawDataContract);
|
|
43
51
|
|
|
44
|
-
expect(invalidDataContractError.
|
|
52
|
+
expect(invalidDataContractError.getMessage()).to.equal(`Data contract decode error: "${error.message}" and 1 more`);
|
|
45
53
|
});
|
|
46
54
|
});
|
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
const getDataContractFixture = require('@dashevo/dpp/lib/test/fixtures/getDataContractFixture');
|
|
2
2
|
const stateTransitionTypes = require('@dashevo/dpp/lib/stateTransition/stateTransitionTypes');
|
|
3
3
|
|
|
4
|
-
const Identifier = require('@dashevo/dpp/lib/identifier/Identifier');
|
|
5
4
|
const protocolVersion = require('@dashevo/dpp/lib/version/protocolVersion');
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const serializer = require('@dashevo/dpp/lib/util/serializer');
|
|
5
|
+
|
|
6
|
+
const { default: loadWasmDpp } = require('../../../../../dist');
|
|
9
7
|
|
|
10
8
|
describe('DataContractCreateTransition', () => {
|
|
11
9
|
let stateTransition;
|
|
12
10
|
let dataContract;
|
|
13
|
-
let
|
|
14
|
-
let
|
|
11
|
+
let DataContractCreateTransition;
|
|
12
|
+
let Identifier;
|
|
15
13
|
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
before(async () => {
|
|
15
|
+
({
|
|
16
|
+
DataContractCreateTransition, Identifier,
|
|
17
|
+
} = await loadWasmDpp());
|
|
18
|
+
});
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
dataContract = getDataContractFixture();
|
|
21
22
|
|
|
22
23
|
stateTransition = new DataContractCreateTransition({
|
|
23
24
|
protocolVersion: protocolVersion.latestVersion,
|
|
@@ -26,11 +27,6 @@ describe('DataContractCreateTransition', () => {
|
|
|
26
27
|
});
|
|
27
28
|
});
|
|
28
29
|
|
|
29
|
-
afterEach(() => {
|
|
30
|
-
encodeMock.restore();
|
|
31
|
-
hashMock.restore();
|
|
32
|
-
});
|
|
33
|
-
|
|
34
30
|
describe('#getProtocolVersion', () => {
|
|
35
31
|
it('should return the current protocol version', () => {
|
|
36
32
|
const result = stateTransition.getProtocolVersion();
|
|
@@ -57,12 +53,10 @@ describe('DataContractCreateTransition', () => {
|
|
|
57
53
|
|
|
58
54
|
describe('#toJSON', () => {
|
|
59
55
|
it('should return State Transition as plain JS object', () => {
|
|
60
|
-
expect(stateTransition.toJSON()).to.deep.equal({
|
|
56
|
+
expect(stateTransition.toJSON(true)).to.deep.equal({
|
|
61
57
|
protocolVersion: protocolVersion.latestVersion,
|
|
62
58
|
type: stateTransitionTypes.DATA_CONTRACT_CREATE,
|
|
63
59
|
dataContract: dataContract.toJSON(),
|
|
64
|
-
signaturePublicKeyId: undefined,
|
|
65
|
-
signature: undefined,
|
|
66
60
|
entropy: dataContract.getEntropy().toString('base64'),
|
|
67
61
|
});
|
|
68
62
|
});
|
|
@@ -70,61 +64,20 @@ describe('DataContractCreateTransition', () => {
|
|
|
70
64
|
|
|
71
65
|
describe('#toBuffer', () => {
|
|
72
66
|
it('should return serialized State Transition', () => {
|
|
73
|
-
const serializedStateTransition = Buffer.from('123');
|
|
74
|
-
|
|
75
|
-
encodeMock.returns(serializedStateTransition);
|
|
76
|
-
|
|
77
67
|
const protocolVersionUInt32 = Buffer.alloc(4);
|
|
78
|
-
protocolVersionUInt32.writeUInt32LE(stateTransition.
|
|
68
|
+
protocolVersionUInt32.writeUInt32LE(stateTransition.getProtocolVersion(), 0);
|
|
79
69
|
|
|
80
70
|
const result = stateTransition.toBuffer();
|
|
81
|
-
|
|
82
|
-
expect(result).to.deep.equal(
|
|
83
|
-
Buffer.concat([protocolVersionUInt32, serializedStateTransition]),
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
const dataToEncode = stateTransition.toObject();
|
|
87
|
-
delete dataToEncode.protocolVersion;
|
|
88
|
-
|
|
89
|
-
expect(encodeMock.getCall(0).args).to.have.deep.members([
|
|
90
|
-
dataToEncode,
|
|
91
|
-
]);
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
describe('#hash', () => {
|
|
96
|
-
it('should return State Transition hash as hex', () => {
|
|
97
|
-
const serializedDocument = Buffer.from('123');
|
|
98
|
-
const hashedDocument = '456';
|
|
99
|
-
|
|
100
|
-
encodeMock.returns(serializedDocument);
|
|
101
|
-
hashMock.returns(hashedDocument);
|
|
102
|
-
|
|
103
|
-
const result = stateTransition.hash();
|
|
104
|
-
|
|
105
|
-
expect(result).to.equal(hashedDocument);
|
|
106
|
-
|
|
107
|
-
const dataToEncode = stateTransition.toObject();
|
|
108
|
-
delete dataToEncode.protocolVersion;
|
|
109
|
-
|
|
110
|
-
expect(encodeMock.getCall(0).args).to.have.deep.members([
|
|
111
|
-
dataToEncode,
|
|
112
|
-
]);
|
|
113
|
-
|
|
114
|
-
const protocolVersionUInt32 = Buffer.alloc(4);
|
|
115
|
-
protocolVersionUInt32.writeUInt32LE(stateTransition.protocolVersion, 0);
|
|
116
|
-
|
|
117
|
-
expect(hashMock).to.have.been.calledOnceWith(
|
|
118
|
-
Buffer.concat([protocolVersionUInt32, serializedDocument]),
|
|
119
|
-
);
|
|
71
|
+
expect(result.compare(protocolVersionUInt32, 0, 4, 0, 4)).equals(0);
|
|
120
72
|
});
|
|
121
73
|
});
|
|
122
74
|
|
|
123
75
|
describe('#getOwnerId', () => {
|
|
124
76
|
it('should return owner id', async () => {
|
|
125
77
|
const result = stateTransition.getOwnerId();
|
|
78
|
+
const reference = stateTransition.getDataContract().getOwnerId();
|
|
126
79
|
|
|
127
|
-
expect(result).to.equal(
|
|
80
|
+
expect(result.toBuffer()).to.deep.equal(reference.toBuffer());
|
|
128
81
|
});
|
|
129
82
|
});
|
|
130
83
|
|
|
@@ -136,7 +89,7 @@ describe('DataContractCreateTransition', () => {
|
|
|
136
89
|
const contractId = result[0];
|
|
137
90
|
|
|
138
91
|
expect(contractId).to.be.an.instanceOf(Identifier);
|
|
139
|
-
expect(contractId).to.be.deep.equal(dataContract.getId());
|
|
92
|
+
expect(contractId.toBuffer()).to.be.deep.equal(dataContract.getId().toBuffer());
|
|
140
93
|
});
|
|
141
94
|
});
|
|
142
95
|
|
|
@@ -1,27 +1,33 @@
|
|
|
1
|
-
const DataContractCreateTransition = require(
|
|
2
|
-
'@dashevo/dpp/lib/dataContract/stateTransition/DataContractCreateTransition/DataContractCreateTransition',
|
|
3
|
-
);
|
|
4
|
-
|
|
5
1
|
const getDataContractFixture = require('@dashevo/dpp/lib/test/fixtures/getDataContractFixture');
|
|
6
2
|
|
|
7
|
-
const
|
|
8
|
-
'@dashevo/dpp/lib/dataContract/stateTransition/DataContractCreateTransition/applyDataContractCreateTransitionFactory',
|
|
9
|
-
);
|
|
3
|
+
const protocolVersion = require('@dashevo/dpp/lib/version/protocolVersion');
|
|
10
4
|
|
|
11
|
-
const
|
|
12
|
-
const StateTransitionExecutionContext = require('@dashevo/dpp/lib/stateTransition/StateTransitionExecutionContext');
|
|
5
|
+
const { default: loadWasmDpp } = require('../../../../../dist');
|
|
13
6
|
|
|
14
7
|
describe('applyDataContractCreateTransitionFactory', () => {
|
|
15
8
|
let stateTransition;
|
|
16
9
|
let dataContract;
|
|
17
|
-
let
|
|
18
|
-
let applyDataContractCreateTransition;
|
|
10
|
+
let factory;
|
|
19
11
|
let executionContext;
|
|
12
|
+
let DataContractCreateTransition;
|
|
13
|
+
let ApplyDataContractCreateTransition;
|
|
14
|
+
let StateTransitionExecutionContext;
|
|
15
|
+
|
|
16
|
+
let dataContractStored;
|
|
17
|
+
|
|
18
|
+
before(async () => {
|
|
19
|
+
({
|
|
20
|
+
DataContractCreateTransition,
|
|
21
|
+
ApplyDataContractCreateTransition,
|
|
22
|
+
StateTransitionExecutionContext,
|
|
23
|
+
} = await loadWasmDpp());
|
|
24
|
+
});
|
|
20
25
|
|
|
21
|
-
beforeEach(
|
|
26
|
+
beforeEach(() => {
|
|
22
27
|
dataContract = getDataContractFixture();
|
|
23
28
|
|
|
24
29
|
stateTransition = new DataContractCreateTransition({
|
|
30
|
+
protocolVersion: protocolVersion.latestVersion,
|
|
25
31
|
dataContract: dataContract.toObject(),
|
|
26
32
|
entropy: Buffer.alloc(32),
|
|
27
33
|
});
|
|
@@ -30,19 +36,19 @@ describe('applyDataContractCreateTransitionFactory', () => {
|
|
|
30
36
|
|
|
31
37
|
stateTransition.setExecutionContext(executionContext);
|
|
32
38
|
|
|
33
|
-
|
|
39
|
+
const stateRepositoryLike = {
|
|
40
|
+
storeDataContract: () => {
|
|
41
|
+
dataContractStored = true;
|
|
42
|
+
},
|
|
43
|
+
};
|
|
34
44
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
45
|
+
factory = new ApplyDataContractCreateTransition(stateRepositoryLike);
|
|
46
|
+
|
|
47
|
+
dataContractStored = false;
|
|
38
48
|
});
|
|
39
49
|
|
|
40
50
|
it('should store a data contract from state transition in the repository', async () => {
|
|
41
|
-
await applyDataContractCreateTransition(stateTransition);
|
|
42
|
-
|
|
43
|
-
expect(stateRepositoryMock.createDataContract).to.have.been.calledOnceWithExactly(
|
|
44
|
-
stateTransition.getDataContract(),
|
|
45
|
-
executionContext,
|
|
46
|
-
);
|
|
51
|
+
await factory.applyDataContractCreateTransition(stateTransition);
|
|
52
|
+
expect(dataContractStored).to.be.true();
|
|
47
53
|
});
|
|
48
54
|
});
|
|
@@ -1,28 +1,36 @@
|
|
|
1
|
-
const validateDataContractCreateTransitionStateFactory = require('@dashevo/dpp/lib/dataContract/stateTransition/DataContractCreateTransition/validation/state/validateDataContractCreateTransitionStateFactory');
|
|
2
|
-
const DataContractCreateTransition = require('@dashevo/dpp/lib/dataContract/stateTransition/DataContractCreateTransition/DataContractCreateTransition');
|
|
3
|
-
|
|
4
|
-
const createStateRepositoryMock = require('@dashevo/dpp/lib/test/mocks/createStateRepositoryMock');
|
|
5
1
|
const getDataContractFixture = require('@dashevo/dpp/lib/test/fixtures/getDataContractFixture');
|
|
2
|
+
const protocolVersion = require('@dashevo/dpp/lib/version/protocolVersion');
|
|
6
3
|
|
|
7
|
-
const {
|
|
8
|
-
|
|
9
|
-
const ValidationResult = require('@dashevo/dpp/lib/validation/ValidationResult');
|
|
10
|
-
|
|
11
|
-
const DataContractAlreadyPresentError = require('@dashevo/dpp/lib/errors/consensus/state/dataContract/DataContractAlreadyPresentError');
|
|
12
|
-
const StateTransitionExecutionContext = require('@dashevo/dpp/lib/stateTransition/StateTransitionExecutionContext');
|
|
4
|
+
const { default: loadWasmDpp } = require('../../../../../../../dist');
|
|
13
5
|
|
|
14
6
|
describe('validateDataContractCreateTransitionStateFactory', () => {
|
|
15
7
|
let validateDataContractCreateTransitionState;
|
|
16
8
|
let dataContract;
|
|
17
9
|
let stateTransition;
|
|
18
|
-
let stateRepositoryMock;
|
|
19
10
|
let executionContext;
|
|
11
|
+
let ValidationResult;
|
|
12
|
+
let DataContractCreateTransition;
|
|
13
|
+
let StateTransitionExecutionContext;
|
|
14
|
+
let factory;
|
|
15
|
+
let dataContractFetched;
|
|
16
|
+
let DataContractFactory;
|
|
17
|
+
let DataContractValidator;
|
|
18
|
+
|
|
19
|
+
before(async () => {
|
|
20
|
+
({
|
|
21
|
+
DataContractCreateTransition,
|
|
22
|
+
StateTransitionExecutionContext,
|
|
23
|
+
validateDataContractCreateTransitionState,
|
|
24
|
+
ValidationResult,
|
|
25
|
+
DataContractFactory,
|
|
26
|
+
DataContractValidator,
|
|
27
|
+
} = await loadWasmDpp());
|
|
28
|
+
});
|
|
20
29
|
|
|
21
|
-
beforeEach(
|
|
22
|
-
stateRepositoryMock = createStateRepositoryMock(this.sinonSandbox);
|
|
23
|
-
|
|
30
|
+
beforeEach(() => {
|
|
24
31
|
dataContract = getDataContractFixture();
|
|
25
32
|
stateTransition = new DataContractCreateTransition({
|
|
33
|
+
protocolVersion: protocolVersion.latestVersion,
|
|
26
34
|
dataContract: dataContract.toObject(),
|
|
27
35
|
entropy: dataContract.getEntropy(),
|
|
28
36
|
});
|
|
@@ -31,55 +39,54 @@ describe('validateDataContractCreateTransitionStateFactory', () => {
|
|
|
31
39
|
|
|
32
40
|
stateTransition.setExecutionContext(executionContext);
|
|
33
41
|
|
|
34
|
-
|
|
35
|
-
stateRepositoryMock,
|
|
36
|
-
);
|
|
37
|
-
});
|
|
42
|
+
dataContractFetched = false;
|
|
38
43
|
|
|
39
|
-
|
|
40
|
-
|
|
44
|
+
const stateRepositoryLike = {
|
|
45
|
+
fetchDataContract: () => {
|
|
46
|
+
dataContractFetched = true;
|
|
47
|
+
},
|
|
48
|
+
};
|
|
41
49
|
|
|
42
|
-
|
|
50
|
+
factory = (t) => validateDataContractCreateTransitionState(stateRepositoryLike, t);
|
|
51
|
+
});
|
|
43
52
|
|
|
44
|
-
|
|
53
|
+
it('should return invalid result if Data Contract is already exist', async () => {
|
|
54
|
+
// This time our state repository should return a data contract on fetch
|
|
55
|
+
const validator = new DataContractValidator();
|
|
56
|
+
const dataContractFactory = new DataContractFactory(1, validator);
|
|
57
|
+
const wasmDataContract = await dataContractFactory.createFromBuffer(dataContract.toBuffer());
|
|
45
58
|
|
|
59
|
+
const stateRepositoryLikeWithContract = {
|
|
60
|
+
fetchDataContract: () => wasmDataContract,
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const result = await validateDataContractCreateTransitionState(
|
|
64
|
+
stateRepositoryLikeWithContract,
|
|
65
|
+
stateTransition,
|
|
66
|
+
);
|
|
46
67
|
const [error] = result.getErrors();
|
|
47
68
|
|
|
48
69
|
expect(error.getCode()).to.equal(4000);
|
|
49
|
-
expect(Buffer.isBuffer(error.getDataContractId())).to.be.true();
|
|
50
70
|
expect(error.getDataContractId()).to.deep.equal(dataContract.getId().toBuffer());
|
|
51
|
-
|
|
52
|
-
expect(stateRepositoryMock.fetchDataContract).to.be.calledOnceWithExactly(
|
|
53
|
-
dataContract.getId(),
|
|
54
|
-
executionContext,
|
|
55
|
-
);
|
|
56
71
|
});
|
|
57
72
|
|
|
58
73
|
it('should return valid result', async () => {
|
|
59
|
-
const result = await
|
|
74
|
+
const result = await factory(stateTransition);
|
|
75
|
+
|
|
76
|
+
expect(dataContractFetched).to.be.true();
|
|
60
77
|
|
|
61
78
|
expect(result).to.be.an.instanceOf(ValidationResult);
|
|
62
79
|
expect(result.isValid()).to.be.true();
|
|
63
|
-
|
|
64
|
-
expect(stateRepositoryMock.fetchDataContract).to.be.calledOnceWithExactly(
|
|
65
|
-
dataContract.getId(),
|
|
66
|
-
executionContext,
|
|
67
|
-
);
|
|
68
80
|
});
|
|
69
81
|
|
|
70
82
|
it('should return valid result on dry run', async () => {
|
|
71
|
-
stateRepositoryMock.fetchDataContract.resolves(dataContract);
|
|
72
|
-
|
|
73
83
|
executionContext.enableDryRun();
|
|
74
|
-
const result = await
|
|
84
|
+
const result = await factory(stateTransition);
|
|
75
85
|
executionContext.disableDryRun();
|
|
76
86
|
|
|
87
|
+
expect(dataContractFetched).to.be.true();
|
|
88
|
+
|
|
77
89
|
expect(result).to.be.an.instanceOf(ValidationResult);
|
|
78
90
|
expect(result.isValid()).to.be.true();
|
|
79
|
-
|
|
80
|
-
expect(stateRepositoryMock.fetchDataContract).to.be.calledOnceWithExactly(
|
|
81
|
-
dataContract.getId(),
|
|
82
|
-
executionContext,
|
|
83
|
-
);
|
|
84
91
|
});
|
|
85
92
|
});
|
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
const getDataContractFixture = require('@dashevo/dpp/lib/test/fixtures/getDataContractFixture');
|
|
2
2
|
const stateTransitionTypes = require('@dashevo/dpp/lib/stateTransition/stateTransitionTypes');
|
|
3
|
-
|
|
4
|
-
const Identifier = require('@dashevo/dpp/lib/identifier/Identifier');
|
|
5
3
|
const protocolVersion = require('@dashevo/dpp/lib/version/protocolVersion');
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
const
|
|
4
|
+
const JsDataContractUpdateTransition = require('@dashevo/dpp/lib/dataContract/stateTransition/DataContractUpdateTransition/DataContractUpdateTransition');
|
|
5
|
+
|
|
6
|
+
const { default: loadWasmDpp } = require('../../../../../dist');
|
|
9
7
|
|
|
10
8
|
describe('DataContractUpdateTransition', () => {
|
|
11
9
|
let stateTransition;
|
|
12
10
|
let dataContract;
|
|
13
|
-
let
|
|
14
|
-
let
|
|
11
|
+
let DataContractUpdateTransition;
|
|
12
|
+
let Identifier;
|
|
15
13
|
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
before(async () => {
|
|
15
|
+
({
|
|
16
|
+
DataContractUpdateTransition, Identifier,
|
|
17
|
+
} = await loadWasmDpp());
|
|
18
|
+
});
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
dataContract = getDataContractFixture();
|
|
21
22
|
|
|
22
23
|
stateTransition = new DataContractUpdateTransition({
|
|
23
24
|
protocolVersion: protocolVersion.latestVersion,
|
|
@@ -25,11 +26,6 @@ describe('DataContractUpdateTransition', () => {
|
|
|
25
26
|
});
|
|
26
27
|
});
|
|
27
28
|
|
|
28
|
-
afterEach(() => {
|
|
29
|
-
encodeMock.restore();
|
|
30
|
-
hashMock.restore();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
29
|
describe('#getProtocolVersion', () => {
|
|
34
30
|
it('should return the current protocol version', () => {
|
|
35
31
|
const result = stateTransition.getProtocolVersion();
|
|
@@ -56,73 +52,41 @@ describe('DataContractUpdateTransition', () => {
|
|
|
56
52
|
|
|
57
53
|
describe('#toJSON', () => {
|
|
58
54
|
it('should return State Transition as plain JS object', () => {
|
|
59
|
-
expect(stateTransition.toJSON()).to.deep.equal({
|
|
55
|
+
expect(stateTransition.toJSON(true)).to.deep.equal({
|
|
60
56
|
protocolVersion: protocolVersion.latestVersion,
|
|
61
57
|
type: stateTransitionTypes.DATA_CONTRACT_UPDATE,
|
|
62
58
|
dataContract: dataContract.toJSON(),
|
|
63
|
-
signaturePublicKeyId: undefined,
|
|
64
|
-
signature: undefined,
|
|
65
59
|
});
|
|
66
60
|
});
|
|
67
61
|
});
|
|
68
62
|
|
|
69
63
|
describe('#toBuffer', () => {
|
|
70
|
-
it('should return serialized State Transition', () => {
|
|
71
|
-
const serializedStateTransition = Buffer.from('123');
|
|
72
|
-
|
|
73
|
-
encodeMock.returns(serializedStateTransition);
|
|
74
|
-
|
|
64
|
+
it('should return serialized State Transition that starts with protocol version', () => {
|
|
75
65
|
const protocolVersionUInt32 = Buffer.alloc(4);
|
|
76
|
-
protocolVersionUInt32.writeUInt32LE(stateTransition.
|
|
66
|
+
protocolVersionUInt32.writeUInt32LE(stateTransition.getProtocolVersion(), 0);
|
|
77
67
|
|
|
78
68
|
const result = stateTransition.toBuffer();
|
|
79
|
-
|
|
80
|
-
expect(result).to.deep.equal(
|
|
81
|
-
Buffer.concat([protocolVersionUInt32, serializedStateTransition]),
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
const dataToEncode = stateTransition.toObject();
|
|
85
|
-
delete dataToEncode.protocolVersion;
|
|
86
|
-
|
|
87
|
-
expect(encodeMock.getCall(0).args).to.have.deep.members([
|
|
88
|
-
dataToEncode,
|
|
89
|
-
]);
|
|
69
|
+
expect(result.compare(protocolVersionUInt32, 0, 4, 0, 4)).equals(0);
|
|
90
70
|
});
|
|
91
71
|
});
|
|
92
72
|
|
|
93
|
-
describe('#hash', () => {
|
|
73
|
+
describe.skip('#hash', () => {
|
|
94
74
|
it('should return State Transition hash as hex', () => {
|
|
95
|
-
const
|
|
96
|
-
const hashedDocument = '456';
|
|
97
|
-
|
|
98
|
-
encodeMock.returns(serializedDocument);
|
|
99
|
-
hashMock.returns(hashedDocument);
|
|
75
|
+
const jsStateTransition = new JsDataContractUpdateTransition(stateTransition.toJSON());
|
|
100
76
|
|
|
101
77
|
const result = stateTransition.hash();
|
|
78
|
+
const resultJs = jsStateTransition.hash();
|
|
102
79
|
|
|
103
|
-
expect(result).to.equal(
|
|
104
|
-
|
|
105
|
-
const dataToEncode = stateTransition.toObject();
|
|
106
|
-
delete dataToEncode.protocolVersion;
|
|
107
|
-
|
|
108
|
-
expect(encodeMock.getCall(0).args).to.have.deep.members([
|
|
109
|
-
dataToEncode,
|
|
110
|
-
]);
|
|
111
|
-
|
|
112
|
-
const protocolVersionUInt32 = Buffer.alloc(4);
|
|
113
|
-
protocolVersionUInt32.writeUInt32LE(stateTransition.protocolVersion, 0);
|
|
114
|
-
|
|
115
|
-
expect(hashMock).to.have.been.calledOnceWith(
|
|
116
|
-
Buffer.concat([protocolVersionUInt32, serializedDocument]),
|
|
117
|
-
);
|
|
80
|
+
expect(result).to.equal(resultJs);
|
|
118
81
|
});
|
|
119
82
|
});
|
|
120
83
|
|
|
121
84
|
describe('#getOwnerId', () => {
|
|
122
85
|
it('should return owner id', async () => {
|
|
123
86
|
const result = stateTransition.getOwnerId();
|
|
87
|
+
const reference = stateTransition.getDataContract().getOwnerId();
|
|
124
88
|
|
|
125
|
-
expect(result).to.equal(
|
|
89
|
+
expect(result.toBuffer()).to.deep.equal(reference.toBuffer());
|
|
126
90
|
});
|
|
127
91
|
});
|
|
128
92
|
|
|
@@ -134,7 +98,7 @@ describe('DataContractUpdateTransition', () => {
|
|
|
134
98
|
const contractId = result[0];
|
|
135
99
|
|
|
136
100
|
expect(contractId).to.be.an.instanceOf(Identifier);
|
|
137
|
-
expect(contractId).to.be.deep.equal(dataContract.getId());
|
|
101
|
+
expect(contractId.toBuffer()).to.be.deep.equal(dataContract.getId().toBuffer());
|
|
138
102
|
});
|
|
139
103
|
});
|
|
140
104
|
|