@dashevo/dpns-contract 0.25.0-dev.9 → 0.25.0-pr.1545.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.toml +3 -1
- package/package.json +3 -3
- package/schema/dpns-contract-documents.json +13 -6
- package/src/lib.rs +22 -0
- package/test/bootstrap.js +5 -0
- package/test/unit/dpnsContract.spec.js +174 -431
package/Cargo.toml
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "dpns-contract"
|
|
3
3
|
description = "DPNS data contract schema and tools"
|
|
4
|
-
version = "0.
|
|
4
|
+
version = "0.25.0"
|
|
5
5
|
edition = "2021"
|
|
6
|
+
rust-version = "1.73"
|
|
6
7
|
license = "MIT"
|
|
7
8
|
|
|
8
9
|
[dependencies]
|
|
9
10
|
serde_json = { version = "1.0" }
|
|
11
|
+
platform-value = { path = "../rs-platform-value" }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dashevo/dpns-contract",
|
|
3
|
-
"version": "0.25.0-
|
|
3
|
+
"version": "0.25.0-pr.1545.2",
|
|
4
4
|
"description": "A contract and helper scripts for DPNS DApp",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"lint": "eslint .",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
],
|
|
32
32
|
"license": "MIT",
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@dashevo/dpp": "0.25.0-
|
|
35
|
-
"chai": "^4.3.
|
|
34
|
+
"@dashevo/wasm-dpp": "0.25.0-pr.1545.2",
|
|
35
|
+
"chai": "^4.3.9",
|
|
36
36
|
"dirty-chai": "^2.0.1",
|
|
37
37
|
"eslint": "^7.32.0",
|
|
38
38
|
"eslint-config-airbnb-base": "^14.2.1",
|
|
@@ -42,18 +42,25 @@
|
|
|
42
42
|
},
|
|
43
43
|
"normalizedLabel": {
|
|
44
44
|
"type": "string",
|
|
45
|
-
"pattern": "^[a-z0-9][a-z0-9-]{0,61}[a-z0-9]$",
|
|
45
|
+
"pattern": "^[a-hj-km-np-z0-9][a-hj-km-np-z0-9-]{0,61}[a-hj-km-np-z0-9]$",
|
|
46
46
|
"maxLength": 63,
|
|
47
|
-
"description": "Domain label
|
|
48
|
-
"$comment": "Must be equal to the label in lowercase.
|
|
47
|
+
"description": "Domain label converted to lowercase for case-insensitive uniqueness validation. \"o\", \"i\" and \"l\" replaced with \"0\" and \"1\" to mitigate homograph attack. e.g. 'b0b'",
|
|
48
|
+
"$comment": "Must be equal to the label in lowercase. \"o\", \"i\" and \"l\" must be replaced with \"0\" and \"1\"."
|
|
49
|
+
},
|
|
50
|
+
"parentDomainName": {
|
|
51
|
+
"type": "string",
|
|
52
|
+
"pattern": "^$|^[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9]$",
|
|
53
|
+
"minLength": 0,
|
|
54
|
+
"maxLength": 63,
|
|
55
|
+
"description": "A full parent domain name. e.g. 'dash'."
|
|
49
56
|
},
|
|
50
57
|
"normalizedParentDomainName": {
|
|
51
58
|
"type": "string",
|
|
52
|
-
"pattern": "^$|^[a-z0-9][a-z0-9-\\.]{0,61}[a-z0-9]$",
|
|
59
|
+
"pattern": "^$|^[a-hj-km-np-z0-9][a-hj-km-np-z0-9-\\.]{0,61}[a-hj-km-np-z0-9]$",
|
|
53
60
|
"minLength": 0,
|
|
54
61
|
"maxLength": 63,
|
|
55
|
-
"description": "A
|
|
56
|
-
"$comment": "Must either be equal to an existing domain or empty to create a top level domain. Only the data contract owner can create top level domains."
|
|
62
|
+
"description": "A parent domain name in lowercase for case-insensitive uniqueness validation. \"o\", \"i\" and \"l\" replaced with \"0\" and \"1\" to mitigate homograph attack. e.g. 'dash'",
|
|
63
|
+
"$comment": "Must either be equal to an existing domain or empty to create a top level domain. \"o\", \"i\" and \"l\" must be replaced with \"0\" and \"1\". Only the data contract owner can create top level domains."
|
|
57
64
|
},
|
|
58
65
|
"preorderSalt": {
|
|
59
66
|
"type": "array",
|
package/src/lib.rs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
use platform_value::{Identifier, IdentifierBytes32};
|
|
1
2
|
use serde_json::{Error, Value};
|
|
2
3
|
|
|
3
4
|
pub const ID_BYTES: [u8; 32] = [
|
|
@@ -10,6 +11,27 @@ pub const OWNER_ID_BYTES: [u8; 32] = [
|
|
|
10
11
|
67, 4, 181, 246, 153, 65, 68, 40, 110, 253, 172,
|
|
11
12
|
];
|
|
12
13
|
|
|
14
|
+
pub mod document_types {
|
|
15
|
+
pub mod domain {
|
|
16
|
+
pub const NAME: &str = "domain";
|
|
17
|
+
|
|
18
|
+
pub mod properties {
|
|
19
|
+
pub const LABEL: &str = "label";
|
|
20
|
+
pub const NORMALIZED_LABEL: &str = "normalizedLabel";
|
|
21
|
+
pub const PARENT_DOMAIN_NAME: &str = "parentDomainName";
|
|
22
|
+
pub const NORMALIZED_PARENT_DOMAIN_NAME: &str = "normalizedParentDomainName";
|
|
23
|
+
pub const PREORDER_SALT: &str = "preorderSalt";
|
|
24
|
+
pub const ALLOW_SUBDOMAINS: &str = "subdomainRules.allowSubdomains";
|
|
25
|
+
pub const RECORDS: &str = "records";
|
|
26
|
+
pub const DASH_UNIQUE_IDENTITY_ID: &str = "dashUniqueIdentityId";
|
|
27
|
+
pub const DASH_ALIAS_IDENTITY_ID: &str = "dashAliasIdentityId";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
pub const ID: Identifier = Identifier(IdentifierBytes32(ID_BYTES));
|
|
33
|
+
pub const OWNER_ID: Identifier = Identifier(IdentifierBytes32(OWNER_ID_BYTES));
|
|
34
|
+
|
|
13
35
|
pub fn load_documents_schemas() -> Result<Value, Error> {
|
|
14
36
|
serde_json::from_str(include_str!("../schema/dpns-contract-documents.json"))
|
|
15
37
|
}
|
package/test/bootstrap.js
CHANGED
|
@@ -4,9 +4,14 @@ const sinonChai = require('sinon-chai');
|
|
|
4
4
|
const { expect, use } = require('chai');
|
|
5
5
|
const dirtyChai = require('dirty-chai');
|
|
6
6
|
|
|
7
|
+
const {
|
|
8
|
+
default: loadWasmDpp,
|
|
9
|
+
} = require('@dashevo/wasm-dpp');
|
|
10
|
+
|
|
7
11
|
use(dirtyChai);
|
|
8
12
|
use(sinonChai);
|
|
9
13
|
|
|
14
|
+
before(loadWasmDpp);
|
|
10
15
|
beforeEach(function beforeEach() {
|
|
11
16
|
if (!this.sinon) {
|
|
12
17
|
this.sinon = sinon.createSandbox();
|
|
@@ -1,40 +1,40 @@
|
|
|
1
1
|
const crypto = require('crypto');
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
const {
|
|
4
|
+
DashPlatformProtocol, JsonSchemaError,
|
|
5
|
+
} = require('@dashevo/wasm-dpp');
|
|
6
|
+
const generateRandomIdentifier = require('@dashevo/wasm-dpp/lib/test/utils/generateRandomIdentifierAsync');
|
|
6
7
|
|
|
8
|
+
const { expect } = require('chai');
|
|
7
9
|
const dpnsContractDocumentsSchema = require('../../schema/dpns-contract-documents.json');
|
|
8
10
|
|
|
11
|
+
const expectJsonSchemaError = (validationResult, errorCount = 1) => {
|
|
12
|
+
const errors = validationResult.getErrors();
|
|
13
|
+
expect(errors).to.have.length(errorCount);
|
|
14
|
+
|
|
15
|
+
const error = validationResult.getErrors()[0];
|
|
16
|
+
expect(error).to.be.instanceof(JsonSchemaError);
|
|
17
|
+
|
|
18
|
+
return error;
|
|
19
|
+
};
|
|
20
|
+
|
|
9
21
|
describe('DPNS Contract', () => {
|
|
10
22
|
let dpp;
|
|
11
23
|
let dataContract;
|
|
12
24
|
let identityId;
|
|
13
25
|
|
|
14
|
-
beforeEach(async
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
stateRepository: {
|
|
19
|
-
fetchDataContract: fetchContractStub,
|
|
20
|
-
},
|
|
21
|
-
});
|
|
26
|
+
beforeEach(async () => {
|
|
27
|
+
dpp = new DashPlatformProtocol(
|
|
28
|
+
{ generate: () => crypto.randomBytes(32) },
|
|
29
|
+
);
|
|
22
30
|
|
|
23
|
-
await
|
|
24
|
-
|
|
25
|
-
identityId = generateRandomIdentifier();
|
|
31
|
+
identityId = await generateRandomIdentifier();
|
|
26
32
|
|
|
27
33
|
dataContract = dpp.dataContract.create(identityId, dpnsContractDocumentsSchema);
|
|
28
|
-
|
|
29
|
-
fetchContractStub.resolves(dataContract);
|
|
30
34
|
});
|
|
31
35
|
|
|
32
|
-
it('should have a valid contract definition', async
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const validationResult = await dpp.dataContract.validate(dataContract);
|
|
36
|
-
|
|
37
|
-
expect(validationResult.isValid()).to.be.true();
|
|
36
|
+
it('should have a valid contract definition', async () => {
|
|
37
|
+
expect(() => dpp.dataContract.create(identityId, dpnsContractDocumentsSchema)).to.not.throw();
|
|
38
38
|
});
|
|
39
39
|
|
|
40
40
|
describe('documents', () => {
|
|
@@ -51,103 +51,63 @@ describe('DPNS Contract', () => {
|
|
|
51
51
|
it('should be defined', async () => {
|
|
52
52
|
delete rawPreorderDocument.saltedDomainHash;
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
expect.fail('should throw error');
|
|
58
|
-
} catch (e) {
|
|
59
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
60
|
-
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
54
|
+
const document = dpp.document.create(dataContract, identityId, 'preorder', rawPreorderDocument);
|
|
55
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
56
|
+
const error = expectJsonSchemaError(validationResult);
|
|
61
57
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
65
|
-
expect(error.keyword).to.equal('required');
|
|
66
|
-
expect(error.params.missingProperty).to.equal('saltedDomainHash');
|
|
67
|
-
}
|
|
58
|
+
expect(error.keyword).to.equal('required');
|
|
59
|
+
expect(error.params.missingProperty).to.equal('saltedDomainHash');
|
|
68
60
|
});
|
|
69
61
|
|
|
70
62
|
it('should not be empty', async () => {
|
|
71
63
|
rawPreorderDocument.saltedDomainHash = Buffer.alloc(0);
|
|
72
64
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
expect.fail('should throw error');
|
|
77
|
-
} catch (e) {
|
|
78
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
79
|
-
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
80
|
-
|
|
81
|
-
const [error] = e.getErrors();
|
|
65
|
+
const document = dpp.document.create(dataContract, identityId, 'preorder', rawPreorderDocument);
|
|
66
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
67
|
+
const error = expectJsonSchemaError(validationResult);
|
|
82
68
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
expect(error.instancePath).to.equal('/saltedDomainHash');
|
|
86
|
-
}
|
|
69
|
+
expect(error.keyword).to.equal('minItems');
|
|
70
|
+
expect(error.instancePath).to.deep.equal('/saltedDomainHash');
|
|
87
71
|
});
|
|
88
72
|
|
|
89
73
|
it('should be not less than 32 bytes', async () => {
|
|
90
74
|
rawPreorderDocument.saltedDomainHash = crypto.randomBytes(10);
|
|
91
75
|
|
|
92
|
-
|
|
93
|
-
|
|
76
|
+
const document = dpp.document.create(dataContract, identityId, 'preorder', rawPreorderDocument);
|
|
77
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
78
|
+
const error = expectJsonSchemaError(validationResult);
|
|
94
79
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
98
|
-
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
99
|
-
|
|
100
|
-
const [error] = e.getErrors();
|
|
101
|
-
|
|
102
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
103
|
-
expect(error.keyword).to.equal('minItems');
|
|
104
|
-
expect(error.instancePath).to.equal('/saltedDomainHash');
|
|
105
|
-
}
|
|
80
|
+
expect(error.keyword).to.equal('minItems');
|
|
81
|
+
expect(error.instancePath).to.equal('/saltedDomainHash');
|
|
106
82
|
});
|
|
107
83
|
|
|
108
84
|
it('should be not longer than 32 bytes', async () => {
|
|
109
85
|
rawPreorderDocument.saltedDomainHash = crypto.randomBytes(40);
|
|
110
86
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
expect.fail('should throw error');
|
|
115
|
-
} catch (e) {
|
|
116
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
117
|
-
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
87
|
+
const document = dpp.document.create(dataContract, identityId, 'preorder', rawPreorderDocument);
|
|
88
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
89
|
+
const error = expectJsonSchemaError(validationResult);
|
|
118
90
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
122
|
-
expect(error.keyword).to.equal('maxItems');
|
|
123
|
-
expect(error.instancePath).to.equal('/saltedDomainHash');
|
|
124
|
-
}
|
|
91
|
+
expect(error.keyword).to.equal('maxItems');
|
|
92
|
+
expect(error.instancePath).to.equal('/saltedDomainHash');
|
|
125
93
|
});
|
|
126
94
|
});
|
|
127
95
|
|
|
128
96
|
it('should not have additional properties', async () => {
|
|
129
97
|
rawPreorderDocument.someOtherProperty = 42;
|
|
130
98
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
expect.fail('should throw error');
|
|
135
|
-
} catch (e) {
|
|
136
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
137
|
-
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
138
|
-
|
|
139
|
-
const [error] = e.getErrors();
|
|
99
|
+
const document = dpp.document.create(dataContract, identityId, 'preorder', rawPreorderDocument);
|
|
100
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
101
|
+
const error = expectJsonSchemaError(validationResult);
|
|
140
102
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
expect(error.params.additionalProperty).to.equal('someOtherProperty');
|
|
144
|
-
}
|
|
103
|
+
expect(error.keyword).to.equal('additionalProperties');
|
|
104
|
+
expect(error.params.additionalProperties).to.deep.equal(['someOtherProperty']);
|
|
145
105
|
});
|
|
146
106
|
|
|
147
107
|
it('should be valid', async () => {
|
|
148
108
|
const preorder = dpp.document.create(dataContract, identityId, 'preorder', rawPreorderDocument);
|
|
149
109
|
|
|
150
|
-
const result = await
|
|
110
|
+
const result = await preorder.validate(dpp.protocolVersion);
|
|
151
111
|
|
|
152
112
|
expect(result.isValid()).to.be.true();
|
|
153
113
|
});
|
|
@@ -156,14 +116,14 @@ describe('DPNS Contract', () => {
|
|
|
156
116
|
describe('domain', () => {
|
|
157
117
|
let rawDomainDocument;
|
|
158
118
|
|
|
159
|
-
beforeEach(() => {
|
|
119
|
+
beforeEach(async () => {
|
|
160
120
|
rawDomainDocument = {
|
|
161
121
|
label: 'Wallet',
|
|
162
|
-
normalizedLabel: '
|
|
122
|
+
normalizedLabel: 'wa11et', // lower case and base58 chars only
|
|
163
123
|
normalizedParentDomainName: 'dash',
|
|
164
124
|
preorderSalt: crypto.randomBytes(32),
|
|
165
125
|
records: {
|
|
166
|
-
dashUniqueIdentityId: generateRandomIdentifier(),
|
|
126
|
+
dashUniqueIdentityId: await generateRandomIdentifier(),
|
|
167
127
|
},
|
|
168
128
|
subdomainRules: {
|
|
169
129
|
allowSubdomains: false,
|
|
@@ -175,77 +135,45 @@ describe('DPNS Contract', () => {
|
|
|
175
135
|
it('should be present', async () => {
|
|
176
136
|
delete rawDomainDocument.label;
|
|
177
137
|
|
|
178
|
-
|
|
179
|
-
|
|
138
|
+
const document = dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
139
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
140
|
+
const error = expectJsonSchemaError(validationResult);
|
|
180
141
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
184
|
-
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
185
|
-
|
|
186
|
-
const [error] = e.getErrors();
|
|
187
|
-
|
|
188
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
189
|
-
expect(error.keyword).to.equal('required');
|
|
190
|
-
expect(error.params.missingProperty).to.equal('label');
|
|
191
|
-
}
|
|
142
|
+
expect(error.keyword).to.equal('required');
|
|
143
|
+
expect(error.params.missingProperty).to.equal('label');
|
|
192
144
|
});
|
|
193
145
|
|
|
194
146
|
it('should follow pattern', async () => {
|
|
195
147
|
rawDomainDocument.label = 'invalid label';
|
|
196
148
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
expect.fail('should throw error');
|
|
201
|
-
} catch (e) {
|
|
202
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
203
|
-
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
149
|
+
const document = dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
150
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
151
|
+
const error = expectJsonSchemaError(validationResult);
|
|
204
152
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
208
|
-
expect(error.keyword).to.equal('pattern');
|
|
209
|
-
expect(error.instancePath).to.equal('/label');
|
|
210
|
-
}
|
|
153
|
+
expect(error.keyword).to.equal('pattern');
|
|
154
|
+
expect(error.instancePath).to.equal('/label');
|
|
211
155
|
});
|
|
212
156
|
|
|
213
157
|
it('should be longer than 3 chars', async () => {
|
|
214
158
|
rawDomainDocument.label = 'ab';
|
|
215
159
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
expect.fail('should throw error');
|
|
220
|
-
} catch (e) {
|
|
221
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
222
|
-
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
223
|
-
|
|
224
|
-
const [error] = e.getErrors();
|
|
160
|
+
const document = dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
161
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
162
|
+
const error = expectJsonSchemaError(validationResult);
|
|
225
163
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
expect(error.instancePath).to.equal('/label');
|
|
229
|
-
}
|
|
164
|
+
expect(error.keyword).to.equal('minLength');
|
|
165
|
+
expect(error.instancePath).to.equal('/label');
|
|
230
166
|
});
|
|
231
167
|
|
|
232
168
|
it('should be less than 63 chars', async () => {
|
|
233
169
|
rawDomainDocument.label = 'a'.repeat(64);
|
|
234
170
|
|
|
235
|
-
|
|
236
|
-
|
|
171
|
+
const document = dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
172
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
173
|
+
const error = expectJsonSchemaError(validationResult, 2);
|
|
237
174
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
241
|
-
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
242
|
-
|
|
243
|
-
const [error] = e.getErrors();
|
|
244
|
-
|
|
245
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
246
|
-
expect(error.keyword).to.equal('maxLength');
|
|
247
|
-
expect(error.instancePath).to.equal('/label');
|
|
248
|
-
}
|
|
175
|
+
expect(error.keyword).to.equal('pattern');
|
|
176
|
+
expect(error.instancePath).to.equal('/label');
|
|
249
177
|
});
|
|
250
178
|
});
|
|
251
179
|
|
|
@@ -253,58 +181,34 @@ describe('DPNS Contract', () => {
|
|
|
253
181
|
it('should be defined', async () => {
|
|
254
182
|
delete rawDomainDocument.normalizedLabel;
|
|
255
183
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
expect.fail('should throw error');
|
|
260
|
-
} catch (e) {
|
|
261
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
262
|
-
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
184
|
+
const document = dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
185
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
186
|
+
const error = expectJsonSchemaError(validationResult);
|
|
263
187
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
267
|
-
expect(error.keyword).to.equal('required');
|
|
268
|
-
expect(error.params.missingProperty).to.equal('normalizedLabel');
|
|
269
|
-
}
|
|
188
|
+
expect(error.keyword).to.equal('required');
|
|
189
|
+
expect(error.params.missingProperty).to.equal('normalizedLabel');
|
|
270
190
|
});
|
|
271
191
|
|
|
272
192
|
it('should follow pattern', async () => {
|
|
273
193
|
rawDomainDocument.normalizedLabel = 'InValiD label';
|
|
274
194
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
expect.fail('should throw error');
|
|
279
|
-
} catch (e) {
|
|
280
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
281
|
-
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
195
|
+
const document = dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
196
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
197
|
+
const error = expectJsonSchemaError(validationResult);
|
|
282
198
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
286
|
-
expect(error.keyword).to.equal('pattern');
|
|
287
|
-
expect(error.instancePath).to.equal('/normalizedLabel');
|
|
288
|
-
}
|
|
199
|
+
expect(error.keyword).to.equal('pattern');
|
|
200
|
+
expect(error.instancePath).to.equal('/normalizedLabel');
|
|
289
201
|
});
|
|
290
202
|
|
|
291
203
|
it('should be less than 63 chars', async () => {
|
|
292
204
|
rawDomainDocument.normalizedLabel = 'a'.repeat(64);
|
|
293
205
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
expect.fail('should throw error');
|
|
298
|
-
} catch (e) {
|
|
299
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
300
|
-
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
301
|
-
|
|
302
|
-
const [error] = e.getErrors();
|
|
206
|
+
const document = dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
207
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
208
|
+
const error = expectJsonSchemaError(validationResult, 2);
|
|
303
209
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
expect(error.instancePath).to.equal('/normalizedLabel');
|
|
307
|
-
}
|
|
210
|
+
expect(error.keyword).to.equal('pattern');
|
|
211
|
+
expect(error.instancePath).to.equal('/normalizedLabel');
|
|
308
212
|
});
|
|
309
213
|
});
|
|
310
214
|
|
|
@@ -312,58 +216,34 @@ describe('DPNS Contract', () => {
|
|
|
312
216
|
it('should be defined', async () => {
|
|
313
217
|
delete rawDomainDocument.normalizedParentDomainName;
|
|
314
218
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
expect.fail('should throw error');
|
|
319
|
-
} catch (e) {
|
|
320
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
321
|
-
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
322
|
-
|
|
323
|
-
const [error] = e.getErrors();
|
|
219
|
+
const document = dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
220
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
221
|
+
const error = expectJsonSchemaError(validationResult);
|
|
324
222
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
expect(error.params.missingProperty).to.equal('normalizedParentDomainName');
|
|
328
|
-
}
|
|
223
|
+
expect(error.keyword).to.equal('required');
|
|
224
|
+
expect(error.params.missingProperty).to.equal('normalizedParentDomainName');
|
|
329
225
|
});
|
|
330
226
|
|
|
331
227
|
it('should be less than 190 chars', async () => {
|
|
332
228
|
rawDomainDocument.normalizedParentDomainName = 'a'.repeat(191);
|
|
333
229
|
|
|
334
|
-
|
|
335
|
-
|
|
230
|
+
const document = dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
231
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
232
|
+
const error = expectJsonSchemaError(validationResult, 2);
|
|
336
233
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
340
|
-
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
341
|
-
|
|
342
|
-
const [error] = e.getErrors();
|
|
343
|
-
|
|
344
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
345
|
-
expect(error.keyword).to.equal('maxLength');
|
|
346
|
-
expect(error.instancePath).to.equal('/normalizedParentDomainName');
|
|
347
|
-
}
|
|
234
|
+
expect(error.keyword).to.equal('pattern');
|
|
235
|
+
expect(error.instancePath).to.equal('/normalizedParentDomainName');
|
|
348
236
|
});
|
|
349
237
|
|
|
350
238
|
it('should follow pattern', async () => {
|
|
351
239
|
rawDomainDocument.normalizedParentDomainName = '&'.repeat(50);
|
|
352
240
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
expect.fail('should throw error');
|
|
357
|
-
} catch (e) {
|
|
358
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
359
|
-
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
241
|
+
const document = dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
242
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
243
|
+
const error = expectJsonSchemaError(validationResult);
|
|
360
244
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
364
|
-
expect(error.keyword).to.equal('pattern');
|
|
365
|
-
expect(error.instancePath).to.equal('/normalizedParentDomainName');
|
|
366
|
-
}
|
|
245
|
+
expect(error.keyword).to.equal('pattern');
|
|
246
|
+
expect(error.instancePath).to.equal('/normalizedParentDomainName');
|
|
367
247
|
});
|
|
368
248
|
});
|
|
369
249
|
|
|
@@ -371,103 +251,65 @@ describe('DPNS Contract', () => {
|
|
|
371
251
|
it('should be defined', async () => {
|
|
372
252
|
delete rawDomainDocument.preorderSalt;
|
|
373
253
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
expect.fail('should throw error');
|
|
378
|
-
} catch (e) {
|
|
379
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
380
|
-
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
254
|
+
const document = dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
255
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
256
|
+
const error = expectJsonSchemaError(validationResult);
|
|
381
257
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
385
|
-
expect(error.keyword).to.equal('required');
|
|
386
|
-
expect(error.params.missingProperty).to.equal('preorderSalt');
|
|
387
|
-
}
|
|
258
|
+
expect(error.keyword).to.equal('required');
|
|
259
|
+
expect(error.params.missingProperty).to.equal('preorderSalt');
|
|
388
260
|
});
|
|
389
261
|
|
|
390
262
|
it('should not be empty', async () => {
|
|
391
263
|
rawDomainDocument.preorderSalt = Buffer.alloc(0);
|
|
392
264
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
} catch (e) {
|
|
398
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
399
|
-
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
400
|
-
|
|
401
|
-
const [error] = e.getErrors();
|
|
265
|
+
dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
266
|
+
const document = dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
267
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
268
|
+
const error = expectJsonSchemaError(validationResult);
|
|
402
269
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
expect(error.instancePath).to.equal('/preorderSalt');
|
|
406
|
-
}
|
|
270
|
+
expect(error.keyword).to.equal('minItems');
|
|
271
|
+
expect(error.instancePath).to.deep.equal('/preorderSalt');
|
|
407
272
|
});
|
|
408
273
|
|
|
409
274
|
it('should be not less than 32 bytes', async () => {
|
|
410
275
|
rawDomainDocument.preorderSalt = crypto.randomBytes(10);
|
|
411
276
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
expect.fail('should throw error');
|
|
416
|
-
} catch (e) {
|
|
417
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
418
|
-
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
419
|
-
|
|
420
|
-
const [error] = e.getErrors();
|
|
277
|
+
const document = dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
278
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
279
|
+
const error = expectJsonSchemaError(validationResult);
|
|
421
280
|
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
expect(error.instancePath).to.equal('/preorderSalt');
|
|
425
|
-
}
|
|
281
|
+
expect(error.keyword).to.equal('minItems');
|
|
282
|
+
expect(error.instancePath).to.equal('/preorderSalt');
|
|
426
283
|
});
|
|
427
284
|
|
|
428
285
|
it('should be not longer than 32 bytes', async () => {
|
|
429
286
|
rawDomainDocument.preorderSalt = crypto.randomBytes(40);
|
|
430
287
|
|
|
431
|
-
|
|
432
|
-
|
|
288
|
+
const document = dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
289
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
290
|
+
const error = expectJsonSchemaError(validationResult);
|
|
433
291
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
437
|
-
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
438
|
-
|
|
439
|
-
const [error] = e.getErrors();
|
|
440
|
-
|
|
441
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
442
|
-
expect(error.keyword).to.equal('maxItems');
|
|
443
|
-
expect(error.instancePath).to.equal('/preorderSalt');
|
|
444
|
-
}
|
|
292
|
+
expect(error.keyword).to.equal('maxItems');
|
|
293
|
+
expect(error.instancePath).to.equal('/preorderSalt');
|
|
445
294
|
});
|
|
446
295
|
});
|
|
447
296
|
|
|
448
297
|
it('should not have additional properties', async () => {
|
|
449
|
-
rawDomainDocument.someOtherProperty =
|
|
298
|
+
rawDomainDocument.someOtherProperty = [];
|
|
450
299
|
|
|
451
|
-
|
|
452
|
-
dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
300
|
+
const document = dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
453
301
|
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
457
|
-
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
302
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
303
|
+
const error = expectJsonSchemaError(validationResult);
|
|
458
304
|
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
462
|
-
expect(error.keyword).to.equal('additionalProperties');
|
|
463
|
-
expect(error.params.additionalProperty).to.equal('someOtherProperty');
|
|
464
|
-
}
|
|
305
|
+
expect(error.keyword).to.equal('additionalProperties');
|
|
306
|
+
expect(error.params.additionalProperties).to.deep.equal(['someOtherProperty']);
|
|
465
307
|
});
|
|
466
308
|
|
|
467
309
|
it('should be valid', async () => {
|
|
468
310
|
const domain = dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
469
311
|
|
|
470
|
-
const result = await
|
|
312
|
+
const result = await domain.validate(dpp.protocolVersion);
|
|
471
313
|
|
|
472
314
|
expect(result.isValid()).to.be.true();
|
|
473
315
|
});
|
|
@@ -476,39 +318,23 @@ describe('DPNS Contract', () => {
|
|
|
476
318
|
it('should be defined', async () => {
|
|
477
319
|
delete rawDomainDocument.records;
|
|
478
320
|
|
|
479
|
-
|
|
480
|
-
|
|
321
|
+
const document = dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
322
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
323
|
+
const error = expectJsonSchemaError(validationResult);
|
|
481
324
|
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
485
|
-
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
486
|
-
|
|
487
|
-
const [error] = e.getErrors();
|
|
488
|
-
|
|
489
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
490
|
-
expect(error.keyword).to.equal('required');
|
|
491
|
-
expect(error.params.missingProperty).to.equal('records');
|
|
492
|
-
}
|
|
325
|
+
expect(error.keyword).to.equal('required');
|
|
326
|
+
expect(error.params.missingProperty).to.equal('records');
|
|
493
327
|
});
|
|
494
328
|
|
|
495
329
|
it('should not be empty', async () => {
|
|
496
330
|
rawDomainDocument.records = {};
|
|
497
331
|
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
expect.fail('should throw error');
|
|
502
|
-
} catch (e) {
|
|
503
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
504
|
-
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
332
|
+
const document = dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
333
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
334
|
+
const error = expectJsonSchemaError(validationResult);
|
|
505
335
|
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
509
|
-
expect(error.keyword).to.equal('minProperties');
|
|
510
|
-
expect(error.instancePath).to.equal('/records');
|
|
511
|
-
}
|
|
336
|
+
expect(error.keyword).to.equal('minProperties');
|
|
337
|
+
expect(error.instancePath).to.deep.equal('/records');
|
|
512
338
|
});
|
|
513
339
|
|
|
514
340
|
it('should not have additional properties', async () => {
|
|
@@ -516,21 +342,13 @@ describe('DPNS Contract', () => {
|
|
|
516
342
|
someOtherProperty: 42,
|
|
517
343
|
};
|
|
518
344
|
|
|
519
|
-
|
|
520
|
-
|
|
345
|
+
const document = dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
346
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
347
|
+
const error = expectJsonSchemaError(validationResult);
|
|
521
348
|
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
526
|
-
|
|
527
|
-
const [error] = e.getErrors();
|
|
528
|
-
|
|
529
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
530
|
-
expect(error.keyword).to.equal('additionalProperties');
|
|
531
|
-
expect(error.instancePath).to.equal('/records');
|
|
532
|
-
expect(error.params.additionalProperty).to.equal('someOtherProperty');
|
|
533
|
-
}
|
|
349
|
+
expect(error.keyword).to.equal('additionalProperties');
|
|
350
|
+
expect(error.instancePath).to.equal('/records');
|
|
351
|
+
expect(error.params.additionalProperties).to.deep.equal(['someOtherProperty']);
|
|
534
352
|
});
|
|
535
353
|
|
|
536
354
|
describe('Dash Identity', () => {
|
|
@@ -540,20 +358,12 @@ describe('DPNS Contract', () => {
|
|
|
540
358
|
dashAliasIdentityId: identityId,
|
|
541
359
|
};
|
|
542
360
|
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
expect.fail('should throw error');
|
|
547
|
-
} catch (e) {
|
|
548
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
549
|
-
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
361
|
+
const document = dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
362
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
363
|
+
const error = expectJsonSchemaError(validationResult);
|
|
550
364
|
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
554
|
-
expect(error.keyword).to.equal('maxProperties');
|
|
555
|
-
expect(error.instancePath).to.equal('/records');
|
|
556
|
-
}
|
|
365
|
+
expect(error.keyword).to.equal('maxProperties');
|
|
366
|
+
expect(error.instancePath).to.equal('/records');
|
|
557
367
|
});
|
|
558
368
|
|
|
559
369
|
describe('dashUniqueIdentityId', () => {
|
|
@@ -562,20 +372,9 @@ describe('DPNS Contract', () => {
|
|
|
562
372
|
dashUniqueIdentityId: crypto.randomBytes(30),
|
|
563
373
|
};
|
|
564
374
|
|
|
565
|
-
|
|
375
|
+
expect(() => {
|
|
566
376
|
dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
567
|
-
|
|
568
|
-
expect.fail('should throw error');
|
|
569
|
-
} catch (e) {
|
|
570
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
571
|
-
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
572
|
-
|
|
573
|
-
const [error] = e.getErrors();
|
|
574
|
-
|
|
575
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
576
|
-
expect(error.keyword).to.equal('minItems');
|
|
577
|
-
expect(error.instancePath).to.equal('/records/dashUniqueIdentityId');
|
|
578
|
-
}
|
|
377
|
+
}).to.throw();
|
|
579
378
|
});
|
|
580
379
|
|
|
581
380
|
it('should no more than 32 bytes', async () => {
|
|
@@ -583,20 +382,9 @@ describe('DPNS Contract', () => {
|
|
|
583
382
|
dashUniqueIdentityId: crypto.randomBytes(64),
|
|
584
383
|
};
|
|
585
384
|
|
|
586
|
-
|
|
385
|
+
expect(() => {
|
|
587
386
|
dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
588
|
-
|
|
589
|
-
expect.fail('should throw error');
|
|
590
|
-
} catch (e) {
|
|
591
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
592
|
-
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
593
|
-
|
|
594
|
-
const [error] = e.getErrors();
|
|
595
|
-
|
|
596
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
597
|
-
expect(error.keyword).to.equal('maxItems');
|
|
598
|
-
expect(error.instancePath).to.equal('/records/dashUniqueIdentityId');
|
|
599
|
-
}
|
|
387
|
+
}).to.throw();
|
|
600
388
|
});
|
|
601
389
|
});
|
|
602
390
|
|
|
@@ -606,20 +394,9 @@ describe('DPNS Contract', () => {
|
|
|
606
394
|
dashAliasIdentityId: crypto.randomBytes(30),
|
|
607
395
|
};
|
|
608
396
|
|
|
609
|
-
|
|
397
|
+
expect(() => {
|
|
610
398
|
dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
611
|
-
|
|
612
|
-
expect.fail('should throw error');
|
|
613
|
-
} catch (e) {
|
|
614
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
615
|
-
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
616
|
-
|
|
617
|
-
const [error] = e.getErrors();
|
|
618
|
-
|
|
619
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
620
|
-
expect(error.keyword).to.equal('minItems');
|
|
621
|
-
expect(error.instancePath).to.equal('/records/dashAliasIdentityId');
|
|
622
|
-
}
|
|
399
|
+
}).to.throw();
|
|
623
400
|
});
|
|
624
401
|
|
|
625
402
|
it('should no more than 32 bytes', async () => {
|
|
@@ -627,20 +404,9 @@ describe('DPNS Contract', () => {
|
|
|
627
404
|
dashAliasIdentityId: crypto.randomBytes(64),
|
|
628
405
|
};
|
|
629
406
|
|
|
630
|
-
|
|
407
|
+
expect(() => {
|
|
631
408
|
dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
632
|
-
|
|
633
|
-
expect.fail('should throw error');
|
|
634
|
-
} catch (e) {
|
|
635
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
636
|
-
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
637
|
-
|
|
638
|
-
const [error] = e.getErrors();
|
|
639
|
-
|
|
640
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
641
|
-
expect(error.keyword).to.equal('maxItems');
|
|
642
|
-
expect(error.instancePath).to.equal('/records/dashAliasIdentityId');
|
|
643
|
-
}
|
|
409
|
+
}).to.throw();
|
|
644
410
|
});
|
|
645
411
|
});
|
|
646
412
|
});
|
|
@@ -650,59 +416,36 @@ describe('DPNS Contract', () => {
|
|
|
650
416
|
it('should be defined', async () => {
|
|
651
417
|
delete rawDomainDocument.subdomainRules;
|
|
652
418
|
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
expect.fail('should throw error');
|
|
657
|
-
} catch (e) {
|
|
658
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
659
|
-
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
660
|
-
|
|
661
|
-
const [error] = e.getErrors();
|
|
419
|
+
const document = dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
420
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
421
|
+
const error = expectJsonSchemaError(validationResult);
|
|
662
422
|
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
expect(error.params.missingProperty).to.equal('subdomainRules');
|
|
666
|
-
}
|
|
423
|
+
expect(error.keyword).to.equal('required');
|
|
424
|
+
expect(error.params.missingProperty).to.equal('subdomainRules');
|
|
667
425
|
});
|
|
668
426
|
|
|
669
427
|
it('should not have additional properties', async () => {
|
|
670
428
|
rawDomainDocument.subdomainRules.someOtherProperty = 42;
|
|
671
429
|
|
|
672
|
-
|
|
673
|
-
|
|
430
|
+
const document = dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
431
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
432
|
+
const error = expectJsonSchemaError(validationResult);
|
|
674
433
|
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
679
|
-
|
|
680
|
-
const [error] = e.getErrors();
|
|
681
|
-
|
|
682
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
683
|
-
expect(error.keyword).to.equal('additionalProperties');
|
|
684
|
-
expect(error.instancePath).to.equal('/subdomainRules');
|
|
685
|
-
}
|
|
434
|
+
expect(error.keyword).to.equal('additionalProperties');
|
|
435
|
+
expect(error.instancePath).to.equal('/subdomainRules');
|
|
436
|
+
expect(error.params.additionalProperties).to.deep.equal(['someOtherProperty']);
|
|
686
437
|
});
|
|
687
438
|
|
|
688
439
|
describe('allowSubdomains', () => {
|
|
689
440
|
it('should be boolean', async () => {
|
|
690
441
|
rawDomainDocument.subdomainRules.allowSubdomains = 'data';
|
|
691
442
|
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
expect.fail('should throw error');
|
|
696
|
-
} catch (e) {
|
|
697
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
698
|
-
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
699
|
-
|
|
700
|
-
const [error] = e.getErrors();
|
|
443
|
+
const document = dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
444
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
445
|
+
const error = expectJsonSchemaError(validationResult);
|
|
701
446
|
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
expect(error.instancePath).to.equal('/subdomainRules/allowSubdomains');
|
|
705
|
-
}
|
|
447
|
+
expect(error.keyword).to.equal('type');
|
|
448
|
+
expect(error.instancePath).to.deep.equal('/subdomainRules/allowSubdomains');
|
|
706
449
|
});
|
|
707
450
|
});
|
|
708
451
|
});
|