@dashevo/wasm-dpp 0.25.0-dev.11 → 0.25.0-dev.13
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 +6 -5
- package/dist/wasm/wasm_dpp.d.ts +685 -639
- package/dist/wasm/wasm_dpp.js +64 -50
- package/dist/wasm/wasm_dpp_bg.js +1 -1
- package/lib/test/fixtures/getIdentityCreateTransitionFixture.js +2 -2
- package/lib/test/fixtures/js/generateRandomIdentifier.js +1 -0
- package/lib/test/fixtures/js/getChainAssetLockProofFixture.js +1 -0
- package/lib/test/fixtures/js/getDataContractFixture.js +1 -0
- package/lib/test/fixtures/js/getDocumentTransitionsFixture.js +1 -0
- package/lib/test/fixtures/js/getDocumentsFixture.js +1 -0
- package/lib/test/fixtures/js/getInstantAssetLockProofFixture.js +1 -0
- package/lib/test/mocks/createStateRepositoryMock.js +1 -0
- package/lib/wasm/wasm_dpp.d.ts +685 -639
- package/package.json +4 -4
- package/scripts/build-wasm.sh +26 -29
- package/src/data_contract/data_contract.rs +99 -54
- package/src/data_contract/data_contract_facade.rs +5 -2
- package/src/data_contract/state_transition/data_contract_update_transition/mod.rs +0 -5
- package/src/data_contract_factory/data_contract_factory.rs +5 -1
- package/src/document/mod.rs +4 -4
- package/src/errors/consensus/consensus_error.rs +5 -0
- package/src/errors/consensus/state/document/document_timestamps_are_equal_error.rs +42 -0
- package/src/errors/consensus/state/document/mod.rs +2 -0
- package/src/errors/value_error.rs +5 -0
- package/src/identity/identity_public_key/mod.rs +1 -1
- package/src/identity/mod.rs +8 -1
- package/src/identity/state_transition/mod.rs +1 -0
- package/src/identity/state_transition/transition_types.rs +30 -0
- package/src/lib.rs +1 -2
- package/src/protocol_version.rs +7 -0
- package/src/state_transition/errors/invalid_state_transition_error.rs +14 -1
- package/src/state_transition/state_transition_facade.rs +6 -1
- package/test/integration/dataContract/stateTransition/DataContractCreateTransition/validation/basic/validateDataContractCreateTransitionBasicFactory.spec.js +5 -5
- package/test/integration/dataContract/stateTransition/DataContractUpdateTransition/validation/basic/validateDataContractUpdateTransitionBasicFactory.spec.js +5 -5
- package/test/integration/dataContract/validation/validateDataContractFactory.spec.js +2 -2
- package/test/integration/document/DocumentFacade.spec.js +4 -4
- package/test/integration/document/stateTransition/DocumentsBatchTransition/DocumentBatchTransition.spec.js +5 -6
- package/test/integration/document/stateTransition/DocumentsBatchTransition/validation/basic/validateDocumentsBatchTransitionBasicFactory.spec.js +14 -14
- package/test/integration/document/stateTransition/DocumentsBatchTransition/validation/state/executeDataTriggersFactory.spec.js +1 -1
- package/test/integration/document/validation/validateDocumentFactory.spec.js +2 -2
- package/test/integration/identity/IdentityFacade.spec.js +8 -8
- package/test/integration/identity/stateTransition/IdentityCreateTransition/validation/basic/validateIdentityCreateTransitionBasicFactory.spec.js +4 -6
- package/test/integration/identity/stateTransition/IdentityTopUpTransition/validation/basic/validateIdentityTopUpTransitionBasicFactory.spec.js +3 -6
- package/test/integration/identity/stateTransition/IdentityUpdateTransition/validation/state/validateIdentityUpdateTransitionStateFactory.spec.js +20 -23
- package/test/integration/identity/stateTransition/IdentityUpdateTransition/validation/state/validatePublicKeysState.spec.js +1 -1
- package/test/integration/identity/stateTransition/assetLockProof/chain/validateChainAssetLockProofStructureFactory.spec.js +3 -3
- package/test/integration/identity/stateTransition/assetLockProof/fetchAssetLockTransactionOutputFactory.spec.js +5 -8
- package/test/integration/identity/stateTransition/assetLockProof/instant/validateInstantAssetLockProofStructureFactory.spec.js +3 -4
- package/test/integration/identity/stateTransition/assetLockProof/validateAssetLockTransactionFactory.spec.js +2 -3
- package/test/integration/identity/stateTransition/validatePublicKeySignaturesFactory.spec.js +2 -6
- package/test/integration/identity/validation/validateIdentityFactory.spec.js +6 -5
- package/test/integration/identity/validation/validatePublicKeysFactory.spec.js +4 -24
- package/test/integration/stateTransition/StateTransitionFacade.spec.js +11 -15
- package/test/unit/DashPlatformProtocol.spec.js +6 -7
- package/test/unit/dataContract/DataContract.spec.js +9 -9
- package/test/unit/dataContract/DataContractFactory.spec.js +3 -3
- package/test/unit/dataContract/createDataContract.spec.js +5 -5
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/DataContractCreateTransition.spec.js +14 -14
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/applyDataContractCreateTransitionFactory.spec.js +6 -8
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/validation/state/validateDataContractCreateTransitionStateFactory.spec.js +3 -3
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/DataContractUpdateTransition.spec.js +14 -12
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/applyDataContractUpdateTransitionFactory.spec.js +6 -6
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/validation/basic/validateIndicesAreBackwardCompatible.spec.js +4 -4
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/validation/state/validateDataContractUpdateTransitionStateFactory.spec.js +5 -5
- package/test/unit/dataContract/validation/validateDataContractPatterns.spec.js +6 -6
- package/test/unit/document/Document.spec.js +5 -4
- package/test/unit/document/stateTransition/DocumetsBatchTransition/applyDocumentsBatchTransitionFactory.spec.js +10 -11
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/validateDocumentsBatchTransitionStateFactory.spec.js +8 -8
- package/test/unit/identity/Identity.spec.js +14 -6
- package/test/unit/identity/IdentityFactory.spec.js +11 -11
- package/test/unit/identity/IdentityPublicKey.spec.js +2 -2
- package/test/unit/identity/stateTransition/IdentityCreateTransition/IdentityCreateTransition.spec.js +13 -14
- package/test/unit/identity/stateTransition/IdentityCreateTransition/applyIdentityCreateTransitionFactory.spec.js +7 -13
- package/test/unit/identity/stateTransition/IdentityCreateTransition/validation/state/validateIdentityCreateTransitionStateFactory.spec.js +3 -7
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/IdentityTopUpTransition.spec.js +13 -14
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/applyIdentityTopUpTransitionFactory.spec.js +5 -9
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/validation/state/validateIdentityTopUpTransitionStateFactory.spec.js +4 -8
- package/test/unit/identity/stateTransition/IdentityUpdateTransition/IdentityUpdateTransition.spec.js +11 -16
- package/test/unit/identity/stateTransition/IdentityUpdateTransition/applyIdentityUpdateTransitionFactory.spec.js +1 -1
- package/test/unit/stateTransition/StateTransitionFactory.spec.js +6 -7
- package/test/unit/stateTransition/createStateTransitionFactory.spec.js +41 -19
- package/test/unit/stateTransition/validation/validateStateTransitionKeySignatureFactory.spec.js +6 -12
- package/src/decode_protocol_entity.rs +0 -25
- package/test/integration/ajv/keywords/byteArray/addByteArrayKeyword.spec.js +0 -148
- package/test/integration/util/generateEntropy.spec.js +0 -17
- package/test/integration/util/serializer.spec.js +0 -24
- package/test/unit/decodeProtocolEntityFactory.spec.js +0 -72
- package/test/unit/identity/errors/InvalidIdentityError.spec.js +0 -46
- package/test/unit/stateTransition/errors/InvalidStateTransitionError.spec.js +0 -51
|
@@ -1,32 +1,53 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
const crypto = require('crypto');
|
|
2
|
+
|
|
3
|
+
const getDataContractFixture = require('../../../lib/test/fixtures/getDataContractFixture');
|
|
4
|
+
const getDocumentsFixture = require('../../../lib/test/fixtures/getDocumentsFixture');
|
|
5
|
+
const getDocumentTransitionsFixture = require('../../../lib/test/fixtures/getDocumentTransitionsFixture');
|
|
6
|
+
|
|
7
|
+
const createStateRepositoryMock = require('../../../lib/test/mocks/createStateRepositoryMock');
|
|
8
|
+
const { default: loadWasmDpp } = require('../../..');
|
|
9
|
+
const {
|
|
10
|
+
DashPlatformProtocol,
|
|
11
|
+
DataContractCreateTransition,
|
|
12
|
+
DocumentsBatchTransition,
|
|
13
|
+
InvalidStateTransitionTypeError,
|
|
14
|
+
} = require('../../..');
|
|
15
|
+
const getBlsAdapterMock = require('../../../lib/test/mocks/getBlsAdapterMock');
|
|
13
16
|
|
|
14
17
|
describe('createStateTransitionFactory', () => {
|
|
15
18
|
let createStateTransition;
|
|
16
19
|
let stateRepositoryMock;
|
|
17
20
|
let dataContract;
|
|
21
|
+
let dpp;
|
|
22
|
+
let blsAdapter;
|
|
23
|
+
|
|
24
|
+
before(async () => {
|
|
25
|
+
await loadWasmDpp();
|
|
26
|
+
});
|
|
18
27
|
|
|
19
|
-
beforeEach(function beforeEach() {
|
|
20
|
-
|
|
28
|
+
beforeEach(async function beforeEach() {
|
|
29
|
+
blsAdapter = await getBlsAdapterMock();
|
|
21
30
|
stateRepositoryMock = createStateRepositoryMock(this.sinonSandbox);
|
|
31
|
+
|
|
32
|
+
dpp = new DashPlatformProtocol(
|
|
33
|
+
blsAdapter,
|
|
34
|
+
stateRepositoryMock,
|
|
35
|
+
{ generate: () => crypto.randomBytes(32) },
|
|
36
|
+
1,
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
dataContract = await getDataContractFixture();
|
|
22
40
|
stateRepositoryMock.fetchDataContract.resolves(dataContract);
|
|
23
|
-
createStateTransition =
|
|
41
|
+
createStateTransition = (st) => dpp.stateTransition.createFromObject(
|
|
42
|
+
st, { skipValidation: true },
|
|
43
|
+
);
|
|
24
44
|
});
|
|
25
45
|
|
|
26
46
|
it('should return DataContractCreateTransition if type is DATA_CONTRACT_CREATE', async () => {
|
|
27
47
|
const stateTransition = new DataContractCreateTransition({
|
|
28
48
|
dataContract: dataContract.toObject(),
|
|
29
49
|
entropy: dataContract.getEntropy(),
|
|
50
|
+
protocolVersion: 1,
|
|
30
51
|
});
|
|
31
52
|
|
|
32
53
|
const result = await createStateTransition(stateTransition.toObject());
|
|
@@ -36,13 +57,14 @@ describe('createStateTransitionFactory', () => {
|
|
|
36
57
|
});
|
|
37
58
|
|
|
38
59
|
it('should return DocumentsBatchTransition if type is DOCUMENTS', async () => {
|
|
39
|
-
const documents = getDocumentsFixture(dataContract);
|
|
40
|
-
const
|
|
60
|
+
const documents = await getDocumentsFixture(dataContract);
|
|
61
|
+
const ownerId = documents[0].getOwnerId();
|
|
62
|
+
const documentTransitions = getDocumentTransitionsFixture({
|
|
41
63
|
create: documents,
|
|
42
64
|
});
|
|
43
65
|
|
|
44
66
|
const stateTransition = new DocumentsBatchTransition({
|
|
45
|
-
ownerId
|
|
67
|
+
ownerId,
|
|
46
68
|
contractId: dataContract.getId(),
|
|
47
69
|
transitions: documentTransitions.map((t) => t.toObject()),
|
|
48
70
|
}, [dataContract]);
|
|
@@ -57,7 +79,7 @@ describe('createStateTransitionFactory', () => {
|
|
|
57
79
|
|
|
58
80
|
it('should throw InvalidStateTransitionTypeError if type is invalid', async () => {
|
|
59
81
|
const rawStateTransition = {
|
|
60
|
-
type:
|
|
82
|
+
type: 253,
|
|
61
83
|
};
|
|
62
84
|
|
|
63
85
|
try {
|
package/test/unit/stateTransition/validation/validateStateTransitionKeySignatureFactory.spec.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const { Transaction, PrivateKey, Script } = require('@dashevo/dashcore-lib');
|
|
2
2
|
|
|
3
|
-
const createStateRepositoryMock = require('
|
|
4
|
-
const getIdentityCreateTransitionFixture = require('
|
|
5
|
-
const getIdentityTopUpTransitionFixture = require('../../../../lib/test/fixtures/
|
|
3
|
+
const createStateRepositoryMock = require('../../../../lib/test/mocks/createStateRepositoryMock');
|
|
4
|
+
const getIdentityCreateTransitionFixture = require('../../../../lib/test/fixtures/getIdentityCreateTransitionFixture');
|
|
5
|
+
const getIdentityTopUpTransitionFixture = require('../../../../lib/test/fixtures/getIdentityTopUpTransitionFixture');
|
|
6
6
|
const { expectValidationError } = require('../../../../lib/test/expect/expectError');
|
|
7
7
|
|
|
8
8
|
const { default: loadWasmDpp } = require('../../../../dist');
|
|
@@ -17,7 +17,6 @@ describe('validateStateTransitionKeySignatureFactory', () => {
|
|
|
17
17
|
let StateTransitionKeySignatureValidator;
|
|
18
18
|
let StateTransitionExecutionContext;
|
|
19
19
|
let IdentityCreateTransition;
|
|
20
|
-
let IdentityTopUpTransition;
|
|
21
20
|
let IdentityNotFoundError;
|
|
22
21
|
let ValidationResult;
|
|
23
22
|
|
|
@@ -27,18 +26,14 @@ describe('validateStateTransitionKeySignatureFactory', () => {
|
|
|
27
26
|
StateTransitionKeySignatureValidator,
|
|
28
27
|
StateTransitionExecutionContext,
|
|
29
28
|
IdentityCreateTransition,
|
|
30
|
-
IdentityTopUpTransition,
|
|
31
29
|
IdentityNotFoundError,
|
|
32
30
|
ValidationResult,
|
|
33
31
|
} = await loadWasmDpp());
|
|
34
32
|
});
|
|
35
33
|
|
|
36
|
-
beforeEach(function beforeEach() {
|
|
34
|
+
beforeEach(async function beforeEach() {
|
|
37
35
|
executionContext = new StateTransitionExecutionContext();
|
|
38
|
-
|
|
39
|
-
const rawStateTransition = stateTransitionJS.toObject();
|
|
40
|
-
|
|
41
|
-
stateTransition = new IdentityCreateTransition(rawStateTransition);
|
|
36
|
+
stateTransition = await getIdentityCreateTransitionFixture();
|
|
42
37
|
|
|
43
38
|
stateRepositoryMock = createStateRepositoryMock(this.sinonSandbox);
|
|
44
39
|
|
|
@@ -91,8 +86,7 @@ describe('validateStateTransitionKeySignatureFactory', () => {
|
|
|
91
86
|
});
|
|
92
87
|
|
|
93
88
|
it('should return IdentityNotFoundError if identity not exist on topup transaction', async function () {
|
|
94
|
-
|
|
95
|
-
stateTransition = new IdentityTopUpTransition(stateTransitionJS.toObject());
|
|
89
|
+
stateTransition = await getIdentityTopUpTransitionFixture();
|
|
96
90
|
stateRepositoryMock.fetchIdentityBalance.resolves(undefined);
|
|
97
91
|
|
|
98
92
|
const result = await validateStateTransitionKeySignature(
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
use js_sys::Array;
|
|
2
|
-
|
|
3
|
-
use wasm_bindgen::prelude::wasm_bindgen;
|
|
4
|
-
use wasm_bindgen::JsValue;
|
|
5
|
-
|
|
6
|
-
#[wasm_bindgen(js_name=decodeProtocolEntity)]
|
|
7
|
-
pub fn decode_protocol_entity(_buffer: Vec<u8>) -> Result<Array, JsValue> {
|
|
8
|
-
// TODO(v0.24-backport): revisit.
|
|
9
|
-
// This code was not used anywhere but js-drive and wallet-lib.
|
|
10
|
-
// In wallet-lib it is replaceable.
|
|
11
|
-
todo!()
|
|
12
|
-
// let (protocol_version, value) = DecodeProtocolEntity::decode_protocol_entity_to_value(buffer)
|
|
13
|
-
// .map_err(from_protocol_error)?;
|
|
14
|
-
//
|
|
15
|
-
// let serializer = serde_wasm_bindgen::Serializer::json_compatible();
|
|
16
|
-
// let js_value = value
|
|
17
|
-
// .try_to_validating_json()
|
|
18
|
-
// .map_err(|e| from_protocol_error(ProtocolError::ValueError(e)))?
|
|
19
|
-
// .serialize(&serializer)
|
|
20
|
-
// .map_err(|e| from_protocol_error(ProtocolError::EncodingError(e.to_string())))?;
|
|
21
|
-
// Ok(Array::from_iter(vec![
|
|
22
|
-
// JsValue::from(protocol_version),
|
|
23
|
-
// js_value,
|
|
24
|
-
// ]))
|
|
25
|
-
}
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
const { default: Ajv } = require('ajv');
|
|
2
|
-
|
|
3
|
-
const addByteArrayKeyword = require('@dashevo/dpp/lib/ajv/keywords/byteArray/addByteArrayKeyword');
|
|
4
|
-
const byteArray = require('@dashevo/dpp/lib/ajv/keywords/byteArray/byteArray');
|
|
5
|
-
|
|
6
|
-
describe('addByteArrayKeyword', () => {
|
|
7
|
-
let ajv;
|
|
8
|
-
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
ajv = new Ajv();
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it('should add byteArray keyword', () => {
|
|
14
|
-
addByteArrayKeyword(ajv);
|
|
15
|
-
|
|
16
|
-
expect(
|
|
17
|
-
ajv.getKeyword('byteArray'),
|
|
18
|
-
).to.deep.equal(byteArray);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
describe('byteArray', () => {
|
|
22
|
-
beforeEach(() => {
|
|
23
|
-
addByteArrayKeyword(ajv);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
describe('compilation', () => {
|
|
27
|
-
it('should be used with array type', () => {
|
|
28
|
-
const schema = {
|
|
29
|
-
type: 'string',
|
|
30
|
-
byteArray: true,
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
ajv.validate(schema, Buffer.alloc(0));
|
|
34
|
-
|
|
35
|
-
expect(ajv.errors).to.have.lengthOf(1);
|
|
36
|
-
expect(ajv.errors[0].keyword).to.equal('type');
|
|
37
|
-
expect(ajv.errors[0].params.type).to.equal('string');
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('should not be used with `items` keyword', () => {
|
|
41
|
-
const schema = {
|
|
42
|
-
type: 'array',
|
|
43
|
-
byteArray: true,
|
|
44
|
-
items: {
|
|
45
|
-
type: 'string',
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
try {
|
|
50
|
-
ajv.validate(schema, Buffer.alloc(0));
|
|
51
|
-
|
|
52
|
-
expect.fail('should fail with keyword schema error');
|
|
53
|
-
} catch (e) {
|
|
54
|
-
expect(e.message).to.equal('\'byteArray\' should not be used with \'items\'');
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('should be boolean', () => {
|
|
59
|
-
const schema = {
|
|
60
|
-
type: 'array',
|
|
61
|
-
byteArray: 'something',
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
try {
|
|
65
|
-
ajv.validate(schema, Buffer.alloc(0));
|
|
66
|
-
|
|
67
|
-
expect.fail('should fail with keyword schema error');
|
|
68
|
-
} catch (e) {
|
|
69
|
-
expect(e.message).to.equal('keyword "byteArray" value is invalid at path "#": data must be boolean');
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('should have value of true', () => {
|
|
74
|
-
const schema = {
|
|
75
|
-
type: 'array',
|
|
76
|
-
byteArray: false,
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
try {
|
|
80
|
-
ajv.validate(schema, Buffer.alloc(0));
|
|
81
|
-
|
|
82
|
-
expect.fail('should fail with keyword schema error');
|
|
83
|
-
} catch (e) {
|
|
84
|
-
expect(e.message).to.equal('keyword "byteArray" value is invalid at path "#": data must be equal to constant');
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
describe('validation', () => {
|
|
90
|
-
it('should accept array of integers', () => {
|
|
91
|
-
const schema = {
|
|
92
|
-
type: 'array',
|
|
93
|
-
byteArray: true,
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
ajv.validate(schema, ['string']);
|
|
97
|
-
|
|
98
|
-
expect(ajv.errors).to.have.lengthOf(2);
|
|
99
|
-
|
|
100
|
-
const [error, byteArrayError] = ajv.errors;
|
|
101
|
-
|
|
102
|
-
expect(error.keyword).to.equal('type');
|
|
103
|
-
expect(error.schemaPath).to.equal('#/byteArray/items/type');
|
|
104
|
-
expect(error.message).to.equal('must be integer');
|
|
105
|
-
|
|
106
|
-
expect(byteArrayError.keyword).to.equal('byteArray');
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it('should accept array of integers not less than 0', () => {
|
|
110
|
-
const schema = {
|
|
111
|
-
type: 'array',
|
|
112
|
-
byteArray: true,
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
ajv.validate(schema, [-1]);
|
|
116
|
-
|
|
117
|
-
expect(ajv.errors).to.have.lengthOf(2);
|
|
118
|
-
|
|
119
|
-
const [error, byteArrayError] = ajv.errors;
|
|
120
|
-
|
|
121
|
-
expect(error.keyword).to.equal('minimum');
|
|
122
|
-
expect(error.schemaPath).to.equal('#/byteArray/items/minimum');
|
|
123
|
-
expect(error.message).to.equal('must be >= 0');
|
|
124
|
-
|
|
125
|
-
expect(byteArrayError.keyword).to.equal('byteArray');
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('should accept array of integers not greater than 255', () => {
|
|
129
|
-
const schema = {
|
|
130
|
-
type: 'array',
|
|
131
|
-
byteArray: true,
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
ajv.validate(schema, [0, 256]);
|
|
135
|
-
|
|
136
|
-
expect(ajv.errors).to.have.lengthOf(2);
|
|
137
|
-
|
|
138
|
-
const [error, byteArrayError] = ajv.errors;
|
|
139
|
-
|
|
140
|
-
expect(error.keyword).to.equal('maximum');
|
|
141
|
-
expect(error.schemaPath).to.equal('#/byteArray/items/maximum');
|
|
142
|
-
expect(error.message).to.equal('must be <= 255');
|
|
143
|
-
|
|
144
|
-
expect(byteArrayError.keyword).to.equal('byteArray');
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
});
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const { generate: generateEntropy } = require('@dashevo/dpp/lib/util/entropyGenerator');
|
|
2
|
-
|
|
3
|
-
describe('generateEntropy', () => {
|
|
4
|
-
it('should generate a byte array of length 32', () => {
|
|
5
|
-
const entropy = generateEntropy();
|
|
6
|
-
|
|
7
|
-
expect(Buffer.isBuffer(entropy)).to.be.true();
|
|
8
|
-
expect(entropy.byteLength).to.be.equal(32);
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
it('should generate random byte array', () => {
|
|
12
|
-
const randomBuffer = generateEntropy();
|
|
13
|
-
const secondRandomBuffer = generateEntropy();
|
|
14
|
-
|
|
15
|
-
expect(randomBuffer).to.not.deep.equal(secondRandomBuffer);
|
|
16
|
-
});
|
|
17
|
-
});
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const { encode } = require('@dashevo/dpp/lib/util/serializer');
|
|
2
|
-
|
|
3
|
-
const DataSerializationError = require('@dashevo/dpp/lib/util/errors/MaxEncodedBytesReachedError');
|
|
4
|
-
|
|
5
|
-
describe('serializer', function main() {
|
|
6
|
-
this.timeout(10000);
|
|
7
|
-
|
|
8
|
-
describe('#encode', () => {
|
|
9
|
-
it('should throw an error if payload is larger that 16 Kb', () => {
|
|
10
|
-
const payload = {};
|
|
11
|
-
for (let i = 0; i < 10000; i++) {
|
|
12
|
-
payload[i] = i;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
encode(payload);
|
|
17
|
-
expect.fail('Error was not thrown');
|
|
18
|
-
} catch (e) {
|
|
19
|
-
expect(e).to.be.an.instanceOf(DataSerializationError);
|
|
20
|
-
expect(e.getPayload()).to.deep.equal(payload);
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
});
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
const varint = require('varint');
|
|
2
|
-
const { encode } = require('@dashevo/dpp/lib/util/serializer');
|
|
3
|
-
|
|
4
|
-
let { decodeProtocolEntity, ProtocolVersionParsingError, SerializedObjectParsingError } = require('../..');
|
|
5
|
-
const { default: loadWasmDpp } = require('../..');
|
|
6
|
-
|
|
7
|
-
// TODO: decodeProtocolEntity was broken after serialization refactoring
|
|
8
|
-
// it was mostly used in js-drive and does not seem to be needed anymore
|
|
9
|
-
// can we remove it completely?
|
|
10
|
-
describe.skip('decodeProtocolEntityFactory', () => {
|
|
11
|
-
let parsedProtocolVersion;
|
|
12
|
-
let entityBuffer;
|
|
13
|
-
let protocolVersionBuffer;
|
|
14
|
-
let rawEntity;
|
|
15
|
-
let buffer;
|
|
16
|
-
|
|
17
|
-
beforeEach(async () => {
|
|
18
|
-
parsedProtocolVersion = 0;
|
|
19
|
-
|
|
20
|
-
protocolVersionBuffer = Buffer.from(varint.encode(parsedProtocolVersion));
|
|
21
|
-
|
|
22
|
-
rawEntity = { test: 'successful' };
|
|
23
|
-
entityBuffer = encode(rawEntity);
|
|
24
|
-
|
|
25
|
-
buffer = Buffer.concat([protocolVersionBuffer, entityBuffer]);
|
|
26
|
-
|
|
27
|
-
({
|
|
28
|
-
decodeProtocolEntity,
|
|
29
|
-
ProtocolVersionParsingError,
|
|
30
|
-
SerializedObjectParsingError,
|
|
31
|
-
} = await loadWasmDpp());
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('should throw ProtocolVersionParsingError if can\'t parse protocol version', () => {
|
|
35
|
-
buffer = Buffer.alloc(0);
|
|
36
|
-
|
|
37
|
-
try {
|
|
38
|
-
decodeProtocolEntity(buffer);
|
|
39
|
-
|
|
40
|
-
expect.fail('should throw ProtocolVersionParsingError');
|
|
41
|
-
} catch (e) {
|
|
42
|
-
expect(e).to.be.an.instanceOf(ProtocolVersionParsingError);
|
|
43
|
-
|
|
44
|
-
expect(e.getParsingError()).to.equals('protocol version could not be decoded as a varint');
|
|
45
|
-
expect(e.getCode()).to.equal(1000);
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('should throw SerializedObjectParsingError if entity decoding fails', () => {
|
|
50
|
-
entityBuffer = Buffer.from('invalid');
|
|
51
|
-
|
|
52
|
-
buffer = Buffer.concat([protocolVersionBuffer, entityBuffer]);
|
|
53
|
-
|
|
54
|
-
try {
|
|
55
|
-
decodeProtocolEntity(buffer);
|
|
56
|
-
|
|
57
|
-
expect.fail('should throw SerializedObjectParsingError');
|
|
58
|
-
} catch (e) {
|
|
59
|
-
expect(e).to.be.an.instanceOf(SerializedObjectParsingError);
|
|
60
|
-
|
|
61
|
-
expect(e.getParsingError()).to.equals('Io(Error { kind: UnexpectedEof, message: "failed to fill whole buffer" })');
|
|
62
|
-
expect(e.getCode()).to.equal(1001);
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('should decode protocol version and entity successfully', () => {
|
|
67
|
-
const [protocolVersion, actualRawEntity] = decodeProtocolEntity(buffer);
|
|
68
|
-
|
|
69
|
-
expect(protocolVersion).to.equal(parsedProtocolVersion);
|
|
70
|
-
expect(rawEntity).to.deep.equal(actualRawEntity);
|
|
71
|
-
});
|
|
72
|
-
});
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
const InvalidIdentityError = require('@dashevo/dpp/lib/identity/errors/InvalidIdentityError');
|
|
2
|
-
const getIdentityFixture = require('@dashevo/dpp/lib/test/fixtures/getIdentityFixture');
|
|
3
|
-
|
|
4
|
-
describe('InvalidIdentityError', () => {
|
|
5
|
-
let rawIdentity;
|
|
6
|
-
let error;
|
|
7
|
-
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
error = new Error('Some error');
|
|
10
|
-
|
|
11
|
-
const identity = getIdentityFixture();
|
|
12
|
-
rawIdentity = identity.toObject();
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('should return errors', () => {
|
|
16
|
-
const errors = [error];
|
|
17
|
-
|
|
18
|
-
const invalidIdentityError = new InvalidIdentityError(errors, rawIdentity);
|
|
19
|
-
|
|
20
|
-
expect(invalidIdentityError.getErrors()).to.deep.equal(errors);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('should return Identity', async () => {
|
|
24
|
-
const errors = [error];
|
|
25
|
-
|
|
26
|
-
const invalidIdentityError = new InvalidIdentityError(errors, rawIdentity);
|
|
27
|
-
|
|
28
|
-
expect(invalidIdentityError.getRawIdentity()).to.deep.equal(rawIdentity);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('should contain message for 1 error', async () => {
|
|
32
|
-
const errors = [error];
|
|
33
|
-
|
|
34
|
-
const invalidIdentityError = new InvalidIdentityError(errors, rawIdentity);
|
|
35
|
-
|
|
36
|
-
expect(invalidIdentityError.message).to.equal(`Invalid Identity: "${error.message}"`);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('should contain message for multiple errors', async () => {
|
|
40
|
-
const errors = [error, error];
|
|
41
|
-
|
|
42
|
-
const invalidIdentityError = new InvalidIdentityError(errors, rawIdentity);
|
|
43
|
-
|
|
44
|
-
expect(invalidIdentityError.message).to.equal(`Invalid Identity: "${error.message}" and 1 more`);
|
|
45
|
-
});
|
|
46
|
-
});
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
const InvalidStateTransitionError = require('@dashevo/dpp/lib/stateTransition/errors/InvalidStateTransitionError');
|
|
2
|
-
const DataContractCreateTransition = require('@dashevo/dpp/lib/dataContract/stateTransition/DataContractCreateTransition/DataContractCreateTransition');
|
|
3
|
-
const getDataContractFixture = require('@dashevo/dpp/lib/test/fixtures/getDataContractFixture');
|
|
4
|
-
|
|
5
|
-
describe('InvalidStateTransitionError', () => {
|
|
6
|
-
let rawStateTransition;
|
|
7
|
-
let error;
|
|
8
|
-
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
error = new Error('Some error');
|
|
11
|
-
|
|
12
|
-
const dataContract = getDataContractFixture();
|
|
13
|
-
const dataContractCreateTransition = new DataContractCreateTransition({
|
|
14
|
-
dataContract: dataContract.toObject(),
|
|
15
|
-
entropy: dataContract.getEntropy(),
|
|
16
|
-
});
|
|
17
|
-
rawStateTransition = dataContractCreateTransition.toObject();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('should return errors', () => {
|
|
21
|
-
const errors = [error];
|
|
22
|
-
|
|
23
|
-
const invalidStateTransitionError = new InvalidStateTransitionError(errors, rawStateTransition);
|
|
24
|
-
|
|
25
|
-
expect(invalidStateTransitionError.getErrors()).to.deep.equal(errors);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('should return State Transition', async () => {
|
|
29
|
-
const errors = [error];
|
|
30
|
-
|
|
31
|
-
const invalidStateTransitionError = new InvalidStateTransitionError(errors, rawStateTransition);
|
|
32
|
-
|
|
33
|
-
expect(invalidStateTransitionError.getRawStateTransition()).to.deep.equal(rawStateTransition);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('should contain message for 1 error', async () => {
|
|
37
|
-
const errors = [error];
|
|
38
|
-
|
|
39
|
-
const invalidStateTransitionError = new InvalidStateTransitionError(errors, rawStateTransition);
|
|
40
|
-
|
|
41
|
-
expect(invalidStateTransitionError.message).to.equal(`Invalid State Transition: "${error.message}"`);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('should contain message for multiple errors', async () => {
|
|
45
|
-
const errors = [error, error];
|
|
46
|
-
|
|
47
|
-
const invalidStateTransitionError = new InvalidStateTransitionError(errors, rawStateTransition);
|
|
48
|
-
|
|
49
|
-
expect(invalidStateTransitionError.message).to.equal(`Invalid State Transition: "${error.message}" and 1 more`);
|
|
50
|
-
});
|
|
51
|
-
});
|