@dashevo/wasm-dpp 0.24.0-dev.10 → 0.24.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/Cargo.toml +2 -0
- package/dist/index.js +1 -1
- package/dist/wasm/wasm_dpp.d.ts +277 -183
- package/package.json +3 -3
- 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 +103 -2
- package/src/data_contract/state_transition/data_contract_create_transition/validation.rs +24 -0
- 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/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/lib.rs +3 -2
- package/src/state_repository.rs +229 -0
- package/src/state_transition/mod.rs +41 -0
- 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 +47 -44
- package/wasm/wasm_dpp.d.ts +277 -183
- package/wasm/wasm_dpp.js +473 -245
- package/wasm/wasm_dpp_bg.js +1 -1
- package/wasm/wasm_dpp_bg.wasm +0 -0
- package/wasm/wasm_dpp_bg.wasm.d.ts +201 -183
|
@@ -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,32 @@
|
|
|
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
|
+
|
|
17
|
+
before(async () => {
|
|
18
|
+
({
|
|
19
|
+
DataContractCreateTransition,
|
|
20
|
+
StateTransitionExecutionContext,
|
|
21
|
+
validateDataContractCreateTransitionState,
|
|
22
|
+
ValidationResult,
|
|
23
|
+
} = await loadWasmDpp());
|
|
24
|
+
});
|
|
20
25
|
|
|
21
|
-
beforeEach(
|
|
22
|
-
stateRepositoryMock = createStateRepositoryMock(this.sinonSandbox);
|
|
23
|
-
|
|
26
|
+
beforeEach(() => {
|
|
24
27
|
dataContract = getDataContractFixture();
|
|
25
28
|
stateTransition = new DataContractCreateTransition({
|
|
29
|
+
protocolVersion: protocolVersion.latestVersion,
|
|
26
30
|
dataContract: dataContract.toObject(),
|
|
27
31
|
entropy: dataContract.getEntropy(),
|
|
28
32
|
});
|
|
@@ -31,55 +35,54 @@ describe('validateDataContractCreateTransitionStateFactory', () => {
|
|
|
31
35
|
|
|
32
36
|
stateTransition.setExecutionContext(executionContext);
|
|
33
37
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
dataContractFetched = false;
|
|
39
|
+
|
|
40
|
+
const stateRepositoryLike = {
|
|
41
|
+
fetchDataContract: () => {
|
|
42
|
+
dataContractFetched = true;
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
factory = (t) => validateDataContractCreateTransitionState(stateRepositoryLike, t);
|
|
37
47
|
});
|
|
38
48
|
|
|
39
|
-
|
|
40
|
-
|
|
49
|
+
// TODO wait for error types
|
|
50
|
+
// it('should return invalid result if Data Contract is already exist', async () => {
|
|
51
|
+
// stateRepositoryMock.fetchDataContract.resolves(dataContract);
|
|
41
52
|
|
|
42
|
-
|
|
53
|
+
// const result = await validateDataContractCreateTransitionState(stateTransition);
|
|
43
54
|
|
|
44
|
-
|
|
55
|
+
// expectValidationError(result, DataContractAlreadyPresentError);
|
|
45
56
|
|
|
46
|
-
|
|
57
|
+
// const [error] = result.getErrors();
|
|
47
58
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
59
|
+
// expect(error.getCode()).to.equal(4000);
|
|
60
|
+
// expect(Buffer.isBuffer(error.getDataContractId())).to.be.true();
|
|
61
|
+
// expect(error.getDataContractId()).to.deep.equal(dataContract.getId().toBuffer());
|
|
51
62
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
});
|
|
63
|
+
// expect(stateRepositoryMock.fetchDataContract).to.be.calledOnceWithExactly(
|
|
64
|
+
// dataContract.getId(),
|
|
65
|
+
// executionContext,
|
|
66
|
+
// );
|
|
67
|
+
// });
|
|
57
68
|
|
|
58
69
|
it('should return valid result', async () => {
|
|
59
|
-
const result = await
|
|
70
|
+
const result = await factory(stateTransition);
|
|
71
|
+
|
|
72
|
+
expect(dataContractFetched).to.be.true();
|
|
60
73
|
|
|
61
74
|
expect(result).to.be.an.instanceOf(ValidationResult);
|
|
62
75
|
expect(result.isValid()).to.be.true();
|
|
63
|
-
|
|
64
|
-
expect(stateRepositoryMock.fetchDataContract).to.be.calledOnceWithExactly(
|
|
65
|
-
dataContract.getId(),
|
|
66
|
-
executionContext,
|
|
67
|
-
);
|
|
68
76
|
});
|
|
69
77
|
|
|
70
78
|
it('should return valid result on dry run', async () => {
|
|
71
|
-
stateRepositoryMock.fetchDataContract.resolves(dataContract);
|
|
72
|
-
|
|
73
79
|
executionContext.enableDryRun();
|
|
74
|
-
const result = await
|
|
80
|
+
const result = await factory(stateTransition);
|
|
75
81
|
executionContext.disableDryRun();
|
|
76
82
|
|
|
83
|
+
expect(dataContractFetched).to.be.true();
|
|
84
|
+
|
|
77
85
|
expect(result).to.be.an.instanceOf(ValidationResult);
|
|
78
86
|
expect(result.isValid()).to.be.true();
|
|
79
|
-
|
|
80
|
-
expect(stateRepositoryMock.fetchDataContract).to.be.calledOnceWithExactly(
|
|
81
|
-
dataContract.getId(),
|
|
82
|
-
executionContext,
|
|
83
|
-
);
|
|
84
87
|
});
|
|
85
88
|
});
|