@dashevo/dashpay-contract 0.25.0-dev.8 → 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/lib/test/bootstrap.js +5 -0
- package/package.json +3 -3
- package/schema/dashpay.schema.json +2 -0
- package/src/lib.rs +16 -0
- package/test/unit/schema.spec.js +198 -449
package/Cargo.toml
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "dashpay-contract"
|
|
3
3
|
description = "DashPay 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
|
lazy_static = "1.4.0"
|
|
10
11
|
serde_json = { version = "1.0" }
|
|
12
|
+
platform-value = { path = "../rs-platform-value" }
|
package/lib/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();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dashevo/dashpay-contract",
|
|
3
|
-
"version": "0.25.0-
|
|
3
|
+
"version": "0.25.0-pr.1545.2",
|
|
4
4
|
"description": "Reference contract of the DashPay DPA on Dash Evolution",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"lint": "eslint .",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
},
|
|
26
26
|
"homepage": "https://github.com/dashevo/dashpay-contract#readme",
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@dashevo/dpp": "0.25.0-
|
|
29
|
-
"chai": "^4.3.
|
|
28
|
+
"@dashevo/wasm-dpp": "0.25.0-pr.1545.2",
|
|
29
|
+
"chai": "^4.3.9",
|
|
30
30
|
"dirty-chai": "^2.0.1",
|
|
31
31
|
"eslint": "^7.32.0",
|
|
32
32
|
"eslint-config-airbnb-base": "^14.2.1",
|
package/src/lib.rs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
use platform_value::{Identifier, IdentifierBytes32};
|
|
1
2
|
use serde_json::Error;
|
|
2
3
|
use serde_json::Value;
|
|
3
4
|
|
|
@@ -11,6 +12,21 @@ pub const OWNER_ID_BYTES: [u8; 32] = [
|
|
|
11
12
|
215, 90, 101, 229, 15, 115, 5, 44, 117, 182, 217,
|
|
12
13
|
];
|
|
13
14
|
|
|
15
|
+
pub mod document_types {
|
|
16
|
+
pub mod contact_request {
|
|
17
|
+
pub const NAME: &str = "contactRequest";
|
|
18
|
+
|
|
19
|
+
pub mod properties {
|
|
20
|
+
pub const TO_USER_ID: &str = "toUserId";
|
|
21
|
+
pub const CORE_HEIGHT_CREATED_AT: &str = "coreHeightCreatedAt";
|
|
22
|
+
pub const CORE_CHAIN_LOCKED_HEIGHT: &str = "coreChainLockedHeight";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
pub const ID: Identifier = Identifier(IdentifierBytes32(ID_BYTES));
|
|
28
|
+
pub const OWNER_ID: Identifier = Identifier(IdentifierBytes32(OWNER_ID_BYTES));
|
|
29
|
+
|
|
14
30
|
pub fn load_documents_schemas() -> Result<Value, Error> {
|
|
15
31
|
serde_json::from_str(include_str!("../schema/dashpay.schema.json"))
|
|
16
32
|
}
|
package/test/unit/schema.spec.js
CHANGED
|
@@ -1,41 +1,39 @@
|
|
|
1
1
|
const { expect } = require('chai');
|
|
2
|
-
const
|
|
3
|
-
const
|
|
2
|
+
const crypto = require('crypto');
|
|
3
|
+
const { DashPlatformProtocol, JsonSchemaError } = require('@dashevo/wasm-dpp');
|
|
4
|
+
const generateRandomIdentifier = require('@dashevo/wasm-dpp/lib/test/utils/generateRandomIdentifierAsync');
|
|
4
5
|
const schema = require('../../schema/dashpay.schema.json');
|
|
5
6
|
|
|
6
7
|
const whitepaperMasternodeText = 'Full nodes are servers running on a P2P network that allow peers to use them to receive updates about the events on the network. These nodes utilize significant amounts of traffic and other resources that incur a substantial cost. As a result, a steady decrease in the amount of these nodes has been observed for some time on the Bitcoin network and as a result, block propagation times have been upwards of 40 seconds. Many solutions have been proposed such as a new reward scheme by Microsoft Research and the Bitnodes incentive program';
|
|
7
8
|
const encoded32Chars = '4fafc98bbfe597f7ba2c9f767d52036d';
|
|
8
9
|
const encoded64Chars = '4fafc98bbfe597f7ba2c9f767d52036d2226175960a908e355e5c575711eb166';
|
|
9
10
|
|
|
11
|
+
const expectJsonSchemaError = (validationResult) => {
|
|
12
|
+
const errors = validationResult.getErrors();
|
|
13
|
+
expect(errors).to.have.length(1);
|
|
14
|
+
|
|
15
|
+
const error = validationResult.getErrors()[0];
|
|
16
|
+
expect(error).to.be.instanceof(JsonSchemaError);
|
|
17
|
+
|
|
18
|
+
return error;
|
|
19
|
+
};
|
|
20
|
+
|
|
10
21
|
describe('Dashpay Contract', () => {
|
|
11
22
|
let dpp;
|
|
12
23
|
let contract;
|
|
13
24
|
let identityId;
|
|
14
25
|
|
|
15
|
-
beforeEach(async
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
stateRepository: {
|
|
20
|
-
fetchDataContract: fetchContractStub,
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
await dpp.initialize();
|
|
25
|
-
|
|
26
|
-
identityId = generateRandomIdentifier();
|
|
26
|
+
beforeEach(async () => {
|
|
27
|
+
dpp = new DashPlatformProtocol(
|
|
28
|
+
{ generate: () => crypto.randomBytes(32) },
|
|
29
|
+
);
|
|
27
30
|
|
|
31
|
+
identityId = await generateRandomIdentifier();
|
|
28
32
|
contract = dpp.dataContract.create(identityId, schema);
|
|
29
|
-
|
|
30
|
-
fetchContractStub.resolves(contract);
|
|
31
33
|
});
|
|
32
34
|
|
|
33
|
-
it('should have a valid contract definition', async
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const validationResult = await dpp.dataContract.validate(contract);
|
|
37
|
-
|
|
38
|
-
expect(validationResult.isValid()).to.be.true();
|
|
35
|
+
it('should have a valid contract definition', async () => {
|
|
36
|
+
expect(() => dpp.dataContract.create(identityId, schema)).to.not.throw();
|
|
39
37
|
});
|
|
40
38
|
|
|
41
39
|
describe('Documents', () => {
|
|
@@ -53,20 +51,12 @@ describe('Dashpay Contract', () => {
|
|
|
53
51
|
it('should have less than 25 chars length', async () => {
|
|
54
52
|
profileData.displayName = 'AliceAndBobAndCarolAndDanAndEveAndFrankAndIvanAndMikeAndWalterAndWendy';
|
|
55
53
|
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
const document = dpp.document.create(contract, identityId, 'profile', profileData);
|
|
55
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
56
|
+
const error = expectJsonSchemaError(validationResult);
|
|
58
57
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
62
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
63
|
-
|
|
64
|
-
const [error] = e.errors;
|
|
65
|
-
|
|
66
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
67
|
-
expect(error.keyword).to.equal('maxLength');
|
|
68
|
-
expect(error.instancePath).to.equal('/displayName');
|
|
69
|
-
}
|
|
58
|
+
expect(error.keyword).to.equal('maxLength');
|
|
59
|
+
expect(error.instancePath).to.deep.equal('/displayName');
|
|
70
60
|
});
|
|
71
61
|
});
|
|
72
62
|
|
|
@@ -74,20 +64,12 @@ describe('Dashpay Contract', () => {
|
|
|
74
64
|
it('should have less than 256 chars length', async () => {
|
|
75
65
|
profileData.publicMessage = whitepaperMasternodeText;
|
|
76
66
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
expect.fail('should throw error');
|
|
81
|
-
} catch (e) {
|
|
82
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
83
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
67
|
+
const document = dpp.document.create(contract, identityId, 'profile', profileData);
|
|
68
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
69
|
+
const error = expectJsonSchemaError(validationResult);
|
|
84
70
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
88
|
-
expect(error.keyword).to.equal('maxLength');
|
|
89
|
-
expect(error.instancePath).to.equal('/publicMessage');
|
|
90
|
-
}
|
|
71
|
+
expect(error.keyword).to.equal('maxLength');
|
|
72
|
+
expect(error.instancePath).to.deep.equal('/publicMessage');
|
|
91
73
|
});
|
|
92
74
|
});
|
|
93
75
|
|
|
@@ -95,58 +77,34 @@ describe('Dashpay Contract', () => {
|
|
|
95
77
|
it('should not be empty', async () => {
|
|
96
78
|
profileData.avatarUrl = '';
|
|
97
79
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
expect.fail('should throw error');
|
|
102
|
-
} catch (e) {
|
|
103
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
104
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
80
|
+
const document = dpp.document.create(contract, identityId, 'profile', profileData);
|
|
81
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
82
|
+
const error = expectJsonSchemaError(validationResult);
|
|
105
83
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
109
|
-
expect(error.keyword).to.equal('format');
|
|
110
|
-
expect(error.instancePath).to.equal('/avatarUrl');
|
|
111
|
-
}
|
|
84
|
+
expect(error.keyword).to.equal('format');
|
|
85
|
+
expect(error.instancePath).to.deep.equal('/avatarUrl');
|
|
112
86
|
});
|
|
113
87
|
|
|
114
88
|
it('should have less than 2048 chars length', async () => {
|
|
115
89
|
profileData.avatarUrl = `https://github.com/dashpay/dash/wiki/Whitepaper?text=${encodeURI(whitepaperMasternodeText)}${encodeURI(whitepaperMasternodeText)}${encodeURI(whitepaperMasternodeText)}${encodeURI(whitepaperMasternodeText)}${encodeURI(whitepaperMasternodeText)}`;
|
|
116
90
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
expect.fail('should throw error');
|
|
121
|
-
} catch (e) {
|
|
122
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
123
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
91
|
+
const document = dpp.document.create(contract, identityId, 'profile', profileData);
|
|
92
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
93
|
+
const error = expectJsonSchemaError(validationResult);
|
|
124
94
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
128
|
-
expect(error.keyword).to.equal('maxLength');
|
|
129
|
-
expect(error.instancePath).to.equal('/avatarUrl');
|
|
130
|
-
}
|
|
95
|
+
expect(error.keyword).to.equal('maxLength');
|
|
96
|
+
expect(error.instancePath).to.deep.equal('/avatarUrl');
|
|
131
97
|
});
|
|
132
98
|
|
|
133
99
|
it('should be of type URL', async () => {
|
|
134
100
|
profileData.avatarUrl = 'notAUrl';
|
|
135
101
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
expect.fail('should throw error');
|
|
140
|
-
} catch (e) {
|
|
141
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
142
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
143
|
-
|
|
144
|
-
const [error] = e.errors;
|
|
102
|
+
const document = dpp.document.create(contract, identityId, 'profile', profileData);
|
|
103
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
104
|
+
const error = expectJsonSchemaError(validationResult);
|
|
145
105
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
expect(error.instancePath).to.equal('/avatarUrl');
|
|
149
|
-
}
|
|
106
|
+
expect(error.keyword).to.equal('format');
|
|
107
|
+
expect(error.instancePath).to.deep.equal('/avatarUrl');
|
|
150
108
|
});
|
|
151
109
|
});
|
|
152
110
|
|
|
@@ -154,52 +112,34 @@ describe('Dashpay Contract', () => {
|
|
|
154
112
|
it('should have minimum length of 32', async () => {
|
|
155
113
|
profileData.avatarHash = Buffer.alloc(0);
|
|
156
114
|
|
|
157
|
-
|
|
158
|
-
|
|
115
|
+
const document = dpp.document.create(contract, identityId, 'profile', profileData);
|
|
116
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
117
|
+
const error = expectJsonSchemaError(validationResult);
|
|
159
118
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
163
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
164
|
-
const [error] = e.errors;
|
|
165
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
166
|
-
expect(error.keyword).to.equal('minItems');
|
|
167
|
-
expect(error.instancePath).to.equal('/avatarHash');
|
|
168
|
-
}
|
|
119
|
+
expect(error.keyword).to.equal('minItems');
|
|
120
|
+
expect(error.instancePath).to.deep.equal('/avatarHash');
|
|
169
121
|
});
|
|
170
122
|
|
|
171
123
|
it('should have maximum length of 32', async () => {
|
|
172
124
|
profileData.avatarHash = Buffer.alloc(33);
|
|
173
125
|
|
|
174
|
-
|
|
175
|
-
|
|
126
|
+
const document = dpp.document.create(contract, identityId, 'profile', profileData);
|
|
127
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
128
|
+
const error = expectJsonSchemaError(validationResult);
|
|
176
129
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
180
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
181
|
-
const [error] = e.errors;
|
|
182
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
183
|
-
expect(error.keyword).to.equal('maxItems');
|
|
184
|
-
expect(error.instancePath).to.equal('/avatarHash');
|
|
185
|
-
}
|
|
130
|
+
expect(error.keyword).to.equal('maxItems');
|
|
131
|
+
expect(error.instancePath).to.deep.equal('/avatarHash');
|
|
186
132
|
});
|
|
187
133
|
|
|
188
134
|
it('should be of type array', async () => {
|
|
189
135
|
profileData.avatarHash = 'notAnArray';
|
|
190
136
|
|
|
191
|
-
|
|
192
|
-
|
|
137
|
+
const document = dpp.document.create(contract, identityId, 'profile', profileData);
|
|
138
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
139
|
+
const error = expectJsonSchemaError(validationResult);
|
|
193
140
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
197
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
198
|
-
const [error] = e.errors;
|
|
199
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
200
|
-
expect(error.keyword).to.equal('type');
|
|
201
|
-
expect(error.instancePath).to.equal('/avatarHash');
|
|
202
|
-
}
|
|
141
|
+
expect(error.keyword).to.equal('type');
|
|
142
|
+
expect(error.instancePath).to.deep.equal('/avatarHash');
|
|
203
143
|
});
|
|
204
144
|
});
|
|
205
145
|
|
|
@@ -207,78 +147,52 @@ describe('Dashpay Contract', () => {
|
|
|
207
147
|
it('should have minimum length of 8', async () => {
|
|
208
148
|
profileData.avatarFingerprint = Buffer.alloc(0);
|
|
209
149
|
|
|
210
|
-
|
|
211
|
-
|
|
150
|
+
const document = dpp.document.create(contract, identityId, 'profile', profileData);
|
|
151
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
152
|
+
const error = expectJsonSchemaError(validationResult);
|
|
212
153
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
216
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
217
|
-
const [error] = e.errors;
|
|
218
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
219
|
-
expect(error.keyword).to.equal('minItems');
|
|
220
|
-
expect(error.instancePath).to.equal('/avatarFingerprint');
|
|
221
|
-
}
|
|
154
|
+
expect(error.keyword).to.equal('minItems');
|
|
155
|
+
expect(error.instancePath).to.deep.equal('/avatarFingerprint');
|
|
222
156
|
});
|
|
223
157
|
|
|
224
158
|
it('should have maximum length of 8', async () => {
|
|
225
159
|
profileData.avatarFingerprint = Buffer.alloc(33);
|
|
226
160
|
|
|
227
|
-
|
|
228
|
-
|
|
161
|
+
const document = dpp.document.create(contract, identityId, 'profile', profileData);
|
|
162
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
163
|
+
const error = expectJsonSchemaError(validationResult);
|
|
229
164
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
233
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
234
|
-
const [error] = e.errors;
|
|
235
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
236
|
-
expect(error.keyword).to.equal('maxItems');
|
|
237
|
-
expect(error.instancePath).to.equal('/avatarFingerprint');
|
|
238
|
-
}
|
|
165
|
+
expect(error.keyword).to.equal('maxItems');
|
|
166
|
+
expect(error.instancePath).to.deep.equal('/avatarFingerprint');
|
|
239
167
|
});
|
|
240
168
|
|
|
241
169
|
it('should be of type array', async () => {
|
|
242
170
|
profileData.avatarFingerprint = 'notAnArray';
|
|
243
171
|
|
|
244
|
-
|
|
245
|
-
|
|
172
|
+
const document = dpp.document.create(contract, identityId, 'profile', profileData);
|
|
173
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
174
|
+
const error = expectJsonSchemaError(validationResult);
|
|
246
175
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
250
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
251
|
-
const [error] = e.errors;
|
|
252
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
253
|
-
expect(error.keyword).to.equal('type');
|
|
254
|
-
expect(error.instancePath).to.equal('/avatarFingerprint');
|
|
255
|
-
}
|
|
176
|
+
expect(error.keyword).to.equal('type');
|
|
177
|
+
expect(error.instancePath).to.deep.equal('/avatarFingerprint');
|
|
256
178
|
});
|
|
257
179
|
});
|
|
258
180
|
|
|
259
181
|
it('should not have additional properties', async () => {
|
|
260
182
|
profileData.someOtherProperty = 42;
|
|
261
183
|
|
|
262
|
-
|
|
263
|
-
|
|
184
|
+
const document = dpp.document.create(contract, identityId, 'profile', profileData);
|
|
185
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
186
|
+
const error = expectJsonSchemaError(validationResult);
|
|
264
187
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
268
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
269
|
-
|
|
270
|
-
const [error] = e.errors;
|
|
271
|
-
|
|
272
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
273
|
-
expect(error.keyword).to.equal('additionalProperties');
|
|
274
|
-
expect(error.params.additionalProperty).to.equal('someOtherProperty');
|
|
275
|
-
}
|
|
188
|
+
expect(error.keyword).to.equal('additionalProperties');
|
|
189
|
+
expect(error.params.additionalProperties).to.deep.equal(['someOtherProperty']);
|
|
276
190
|
});
|
|
277
191
|
|
|
278
192
|
it('should be valid', async () => {
|
|
279
193
|
const profile = dpp.document.create(contract, identityId, 'profile', profileData);
|
|
280
194
|
|
|
281
|
-
const result =
|
|
195
|
+
const result = profile.validate(dpp.protocolVersion);
|
|
282
196
|
|
|
283
197
|
expect(result.isValid()).to.be.true();
|
|
284
198
|
});
|
|
@@ -300,58 +214,34 @@ describe('Dashpay Contract', () => {
|
|
|
300
214
|
it('should be defined', async () => {
|
|
301
215
|
delete contactInfoData.encToUserId;
|
|
302
216
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
expect.fail('should throw error');
|
|
307
|
-
} catch (e) {
|
|
308
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
309
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
217
|
+
const document = dpp.document.create(contract, identityId, 'contactInfo', contactInfoData);
|
|
218
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
219
|
+
const error = expectJsonSchemaError(validationResult);
|
|
310
220
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
314
|
-
expect(error.keyword).to.equal('required');
|
|
315
|
-
expect(error.params.missingProperty).to.equal('encToUserId');
|
|
316
|
-
}
|
|
221
|
+
expect(error.keyword).to.equal('required');
|
|
222
|
+
expect(error.params.missingProperty).to.equal('encToUserId');
|
|
317
223
|
});
|
|
318
224
|
|
|
319
225
|
it('should have exactly 32 chars length', async () => {
|
|
320
226
|
contactInfoData.encToUserId = Buffer.from(`${encoded64Chars}11`, 'hex');
|
|
321
227
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
expect.fail('should throw error');
|
|
326
|
-
} catch (e) {
|
|
327
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
328
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
329
|
-
|
|
330
|
-
const [error] = e.errors;
|
|
228
|
+
const document = dpp.document.create(contract, identityId, 'contactInfo', contactInfoData);
|
|
229
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
230
|
+
const error = expectJsonSchemaError(validationResult);
|
|
331
231
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
expect(error.instancePath).to.equal('/encToUserId');
|
|
335
|
-
}
|
|
232
|
+
expect(error.keyword).to.equal('maxItems');
|
|
233
|
+
expect(error.instancePath).to.equal('/encToUserId');
|
|
336
234
|
});
|
|
337
235
|
|
|
338
236
|
it('should have more or 32 chars length', async () => {
|
|
339
237
|
contactInfoData.encToUserId = Buffer.from(encoded32Chars, 'hex');
|
|
340
238
|
|
|
341
|
-
|
|
342
|
-
|
|
239
|
+
const document = dpp.document.create(contract, identityId, 'contactInfo', contactInfoData);
|
|
240
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
241
|
+
const error = expectJsonSchemaError(validationResult);
|
|
343
242
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
347
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
348
|
-
|
|
349
|
-
const [error] = e.errors;
|
|
350
|
-
|
|
351
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
352
|
-
expect(error.keyword).to.equal('minItems');
|
|
353
|
-
expect(error.instancePath).to.equal('/encToUserId');
|
|
354
|
-
}
|
|
243
|
+
expect(error.keyword).to.equal('minItems');
|
|
244
|
+
expect(error.instancePath).to.equal('/encToUserId');
|
|
355
245
|
});
|
|
356
246
|
});
|
|
357
247
|
|
|
@@ -359,39 +249,23 @@ describe('Dashpay Contract', () => {
|
|
|
359
249
|
it('should be defined', async () => {
|
|
360
250
|
delete contactInfoData.rootEncryptionKeyIndex;
|
|
361
251
|
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
expect.fail('should throw error');
|
|
366
|
-
} catch (e) {
|
|
367
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
368
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
369
|
-
|
|
370
|
-
const [error] = e.errors;
|
|
252
|
+
const document = dpp.document.create(contract, identityId, 'contactInfo', contactInfoData);
|
|
253
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
254
|
+
const error = expectJsonSchemaError(validationResult);
|
|
371
255
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
expect(error.params.missingProperty).to.equal('rootEncryptionKeyIndex');
|
|
375
|
-
}
|
|
256
|
+
expect(error.keyword).to.equal('required');
|
|
257
|
+
expect(error.params.missingProperty).to.equal('rootEncryptionKeyIndex');
|
|
376
258
|
});
|
|
377
259
|
|
|
378
260
|
it('should not be less than 0', async () => {
|
|
379
261
|
contactInfoData.rootEncryptionKeyIndex = -1;
|
|
380
262
|
|
|
381
|
-
|
|
382
|
-
|
|
263
|
+
const document = dpp.document.create(contract, identityId, 'contactInfo', contactInfoData);
|
|
264
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
265
|
+
const error = expectJsonSchemaError(validationResult);
|
|
383
266
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
387
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
388
|
-
|
|
389
|
-
const [error] = e.errors;
|
|
390
|
-
|
|
391
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
392
|
-
expect(error.keyword).to.equal('minimum');
|
|
393
|
-
expect(error.instancePath).to.equal('/rootEncryptionKeyIndex');
|
|
394
|
-
}
|
|
267
|
+
expect(error.keyword).to.equal('minimum');
|
|
268
|
+
expect(error.instancePath).to.equal('/rootEncryptionKeyIndex');
|
|
395
269
|
});
|
|
396
270
|
});
|
|
397
271
|
|
|
@@ -399,40 +273,24 @@ describe('Dashpay Contract', () => {
|
|
|
399
273
|
it('should be defined', async () => {
|
|
400
274
|
delete contactInfoData.privateData;
|
|
401
275
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
expect.fail('should throw error');
|
|
406
|
-
} catch (e) {
|
|
407
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
408
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
276
|
+
const document = dpp.document.create(contract, identityId, 'contactInfo', contactInfoData);
|
|
277
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
278
|
+
const error = expectJsonSchemaError(validationResult);
|
|
409
279
|
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
413
|
-
expect(error.keyword).to.equal('required');
|
|
414
|
-
expect(error.params.missingProperty).to.equal('privateData');
|
|
415
|
-
}
|
|
280
|
+
expect(error.keyword).to.equal('required');
|
|
281
|
+
expect(error.params.missingProperty).to.equal('privateData');
|
|
416
282
|
});
|
|
417
283
|
});
|
|
418
284
|
|
|
419
285
|
it('should not have additional properties', async () => {
|
|
420
286
|
contactInfoData.someOtherProperty = 42;
|
|
421
287
|
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
expect.fail('should throw error');
|
|
426
|
-
} catch (e) {
|
|
427
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
428
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
429
|
-
|
|
430
|
-
const [error] = e.errors;
|
|
288
|
+
const document = dpp.document.create(contract, identityId, 'contactInfo', contactInfoData);
|
|
289
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
290
|
+
const error = expectJsonSchemaError(validationResult);
|
|
431
291
|
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
expect(error.params.additionalProperty).to.equal('someOtherProperty');
|
|
435
|
-
}
|
|
292
|
+
expect(error.keyword).to.equal('additionalProperties');
|
|
293
|
+
expect(error.params.additionalProperties).to.deep.equal(['someOtherProperty']);
|
|
436
294
|
});
|
|
437
295
|
});
|
|
438
296
|
|
|
@@ -453,20 +311,12 @@ describe('Dashpay Contract', () => {
|
|
|
453
311
|
it('should be defined', async () => {
|
|
454
312
|
delete contactRequestData.toUserId;
|
|
455
313
|
|
|
456
|
-
|
|
457
|
-
|
|
314
|
+
const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
|
|
315
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
316
|
+
const error = expectJsonSchemaError(validationResult);
|
|
458
317
|
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
462
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
463
|
-
|
|
464
|
-
const [error] = e.errors;
|
|
465
|
-
|
|
466
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
467
|
-
expect(error.keyword).to.equal('required');
|
|
468
|
-
expect(error.params.missingProperty).to.equal('toUserId');
|
|
469
|
-
}
|
|
318
|
+
expect(error.keyword).to.equal('required');
|
|
319
|
+
expect(error.params.missingProperty).to.equal('toUserId');
|
|
470
320
|
});
|
|
471
321
|
});
|
|
472
322
|
|
|
@@ -474,20 +324,12 @@ describe('Dashpay Contract', () => {
|
|
|
474
324
|
it('should be defined', async () => {
|
|
475
325
|
delete contactRequestData.encryptedPublicKey;
|
|
476
326
|
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
expect.fail('should throw error');
|
|
481
|
-
} catch (e) {
|
|
482
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
483
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
327
|
+
const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
|
|
328
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
329
|
+
const error = expectJsonSchemaError(validationResult);
|
|
484
330
|
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
488
|
-
expect(error.keyword).to.equal('required');
|
|
489
|
-
expect(error.params.missingProperty).to.equal('encryptedPublicKey');
|
|
490
|
-
}
|
|
331
|
+
expect(error.keyword).to.equal('required');
|
|
332
|
+
expect(error.params.missingProperty).to.equal('encryptedPublicKey');
|
|
491
333
|
});
|
|
492
334
|
});
|
|
493
335
|
|
|
@@ -495,39 +337,23 @@ describe('Dashpay Contract', () => {
|
|
|
495
337
|
it('should be defined', async () => {
|
|
496
338
|
delete contactRequestData.senderKeyIndex;
|
|
497
339
|
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
expect.fail('should throw error');
|
|
502
|
-
} catch (e) {
|
|
503
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
504
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
340
|
+
const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
|
|
341
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
342
|
+
const error = expectJsonSchemaError(validationResult);
|
|
505
343
|
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
509
|
-
expect(error.keyword).to.equal('required');
|
|
510
|
-
expect(error.params.missingProperty).to.equal('senderKeyIndex');
|
|
511
|
-
}
|
|
344
|
+
expect(error.keyword).to.equal('required');
|
|
345
|
+
expect(error.params.missingProperty).to.equal('senderKeyIndex');
|
|
512
346
|
});
|
|
513
347
|
|
|
514
348
|
it('should not be less than 0', async () => {
|
|
515
349
|
contactRequestData.senderKeyIndex = -1;
|
|
516
350
|
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
expect.fail('should throw error');
|
|
521
|
-
} catch (e) {
|
|
522
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
523
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
351
|
+
const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
|
|
352
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
353
|
+
const error = expectJsonSchemaError(validationResult);
|
|
524
354
|
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
528
|
-
expect(error.keyword).to.equal('minimum');
|
|
529
|
-
expect(error.instancePath).to.equal('/senderKeyIndex');
|
|
530
|
-
}
|
|
355
|
+
expect(error.keyword).to.equal('minimum');
|
|
356
|
+
expect(error.instancePath).to.equal('/senderKeyIndex');
|
|
531
357
|
});
|
|
532
358
|
});
|
|
533
359
|
|
|
@@ -535,39 +361,23 @@ describe('Dashpay Contract', () => {
|
|
|
535
361
|
it('should be defined', async () => {
|
|
536
362
|
delete contactRequestData.recipientKeyIndex;
|
|
537
363
|
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
expect.fail('should throw error');
|
|
542
|
-
} catch (e) {
|
|
543
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
544
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
545
|
-
|
|
546
|
-
const [error] = e.errors;
|
|
364
|
+
const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
|
|
365
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
366
|
+
const error = expectJsonSchemaError(validationResult);
|
|
547
367
|
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
expect(error.params.missingProperty).to.equal('recipientKeyIndex');
|
|
551
|
-
}
|
|
368
|
+
expect(error.keyword).to.equal('required');
|
|
369
|
+
expect(error.params.missingProperty).to.equal('recipientKeyIndex');
|
|
552
370
|
});
|
|
553
371
|
|
|
554
372
|
it('should not be less than 0', async () => {
|
|
555
373
|
contactRequestData.recipientKeyIndex = -1;
|
|
556
374
|
|
|
557
|
-
|
|
558
|
-
|
|
375
|
+
const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
|
|
376
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
377
|
+
const error = expectJsonSchemaError(validationResult);
|
|
559
378
|
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
563
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
564
|
-
|
|
565
|
-
const [error] = e.errors;
|
|
566
|
-
|
|
567
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
568
|
-
expect(error.keyword).to.equal('minimum');
|
|
569
|
-
expect(error.instancePath).to.equal('/recipientKeyIndex');
|
|
570
|
-
}
|
|
379
|
+
expect(error.keyword).to.equal('minimum');
|
|
380
|
+
expect(error.instancePath).to.equal('/recipientKeyIndex');
|
|
571
381
|
});
|
|
572
382
|
});
|
|
573
383
|
|
|
@@ -575,51 +385,34 @@ describe('Dashpay Contract', () => {
|
|
|
575
385
|
it('should have minimum length of 48', async () => {
|
|
576
386
|
contactRequestData.encryptedAccountLabel = Buffer.alloc(0);
|
|
577
387
|
|
|
578
|
-
|
|
579
|
-
|
|
388
|
+
const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
|
|
389
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
390
|
+
const error = expectJsonSchemaError(validationResult);
|
|
580
391
|
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
584
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
585
|
-
const [error] = e.errors;
|
|
586
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
587
|
-
expect(error.keyword).to.equal('minItems');
|
|
588
|
-
expect(error.instancePath).to.equal('/encryptedAccountLabel');
|
|
589
|
-
}
|
|
392
|
+
expect(error.keyword).to.equal('minItems');
|
|
393
|
+
expect(error.instancePath).to.deep.equal('/encryptedAccountLabel');
|
|
590
394
|
});
|
|
591
395
|
|
|
592
396
|
it('should have maximum length of 80', async () => {
|
|
593
397
|
contactRequestData.encryptedAccountLabel = Buffer.alloc(82);
|
|
594
398
|
|
|
595
|
-
|
|
596
|
-
|
|
399
|
+
const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
|
|
400
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
401
|
+
const error = expectJsonSchemaError(validationResult);
|
|
597
402
|
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
601
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
602
|
-
const [error] = e.errors;
|
|
603
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
604
|
-
expect(error.keyword).to.equal('maxItems');
|
|
605
|
-
expect(error.instancePath).to.equal('/encryptedAccountLabel');
|
|
606
|
-
}
|
|
403
|
+
expect(error.keyword).to.equal('maxItems');
|
|
404
|
+
expect(error.instancePath).to.deep.equal('/encryptedAccountLabel');
|
|
607
405
|
});
|
|
608
406
|
|
|
609
407
|
it('should be of type array', async () => {
|
|
610
408
|
contactRequestData.encryptedAccountLabel = 'notAnArray';
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
const [error] = e.errors;
|
|
619
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
620
|
-
expect(error.keyword).to.equal('type');
|
|
621
|
-
expect(error.instancePath).to.equal('/encryptedAccountLabel');
|
|
622
|
-
}
|
|
409
|
+
|
|
410
|
+
const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
|
|
411
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
412
|
+
const error = expectJsonSchemaError(validationResult);
|
|
413
|
+
|
|
414
|
+
expect(error.keyword).to.equal('type');
|
|
415
|
+
expect(error.instancePath).to.deep.equal('/encryptedAccountLabel');
|
|
623
416
|
});
|
|
624
417
|
});
|
|
625
418
|
|
|
@@ -627,52 +420,34 @@ describe('Dashpay Contract', () => {
|
|
|
627
420
|
it('should have minimum length of 38', async () => {
|
|
628
421
|
contactRequestData.autoAcceptProof = Buffer.alloc(0);
|
|
629
422
|
|
|
630
|
-
|
|
631
|
-
|
|
423
|
+
const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
|
|
424
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
425
|
+
const error = expectJsonSchemaError(validationResult);
|
|
632
426
|
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
636
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
637
|
-
const [error] = e.errors;
|
|
638
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
639
|
-
expect(error.keyword).to.equal('minItems');
|
|
640
|
-
expect(error.instancePath).to.equal('/autoAcceptProof');
|
|
641
|
-
}
|
|
427
|
+
expect(error.keyword).to.equal('minItems');
|
|
428
|
+
expect(error.instancePath).to.deep.equal('/autoAcceptProof');
|
|
642
429
|
});
|
|
643
430
|
|
|
644
431
|
it('should have maximum length of 102', async () => {
|
|
645
432
|
contactRequestData.autoAcceptProof = Buffer.alloc(104);
|
|
646
433
|
|
|
647
|
-
|
|
648
|
-
|
|
434
|
+
const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
|
|
435
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
436
|
+
const error = expectJsonSchemaError(validationResult);
|
|
649
437
|
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
653
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
654
|
-
const [error] = e.errors;
|
|
655
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
656
|
-
expect(error.keyword).to.equal('maxItems');
|
|
657
|
-
expect(error.instancePath).to.equal('/autoAcceptProof');
|
|
658
|
-
}
|
|
438
|
+
expect(error.keyword).to.equal('maxItems');
|
|
439
|
+
expect(error.instancePath).to.deep.equal('/autoAcceptProof');
|
|
659
440
|
});
|
|
660
441
|
|
|
661
442
|
it('should be of type array', async () => {
|
|
662
443
|
contactRequestData.autoAcceptProof = 'notAnArray';
|
|
663
444
|
|
|
664
|
-
|
|
665
|
-
|
|
445
|
+
const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
|
|
446
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
447
|
+
const error = expectJsonSchemaError(validationResult);
|
|
666
448
|
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
670
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
671
|
-
const [error] = e.errors;
|
|
672
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
673
|
-
expect(error.keyword).to.equal('type');
|
|
674
|
-
expect(error.instancePath).to.equal('/autoAcceptProof');
|
|
675
|
-
}
|
|
449
|
+
expect(error.keyword).to.equal('type');
|
|
450
|
+
expect(error.instancePath).to.deep.equal('/autoAcceptProof');
|
|
676
451
|
});
|
|
677
452
|
});
|
|
678
453
|
|
|
@@ -680,35 +455,23 @@ describe('Dashpay Contract', () => {
|
|
|
680
455
|
it('should be defined', async () => {
|
|
681
456
|
delete contactRequestData.accountReference;
|
|
682
457
|
|
|
683
|
-
|
|
684
|
-
|
|
458
|
+
const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
|
|
459
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
460
|
+
const error = expectJsonSchemaError(validationResult);
|
|
685
461
|
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
689
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
690
|
-
const [error] = e.errors;
|
|
691
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
692
|
-
expect(error.keyword).to.equal('required');
|
|
693
|
-
expect(error.params.missingProperty).to.equal('accountReference');
|
|
694
|
-
}
|
|
462
|
+
expect(error.keyword).to.equal('required');
|
|
463
|
+
expect(error.params.missingProperty).to.equal('accountReference');
|
|
695
464
|
});
|
|
696
465
|
|
|
697
466
|
it('should not be less than 0', async () => {
|
|
698
467
|
contactRequestData.accountReference = -1;
|
|
699
468
|
|
|
700
|
-
|
|
701
|
-
|
|
469
|
+
const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
|
|
470
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
471
|
+
const error = expectJsonSchemaError(validationResult);
|
|
702
472
|
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
706
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
707
|
-
const [error] = e.errors;
|
|
708
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
709
|
-
expect(error.keyword).to.equal('minimum');
|
|
710
|
-
expect(error.instancePath).to.equal('/accountReference');
|
|
711
|
-
}
|
|
473
|
+
expect(error.keyword).to.equal('minimum');
|
|
474
|
+
expect(error.instancePath).to.equal('/accountReference');
|
|
712
475
|
});
|
|
713
476
|
});
|
|
714
477
|
|
|
@@ -716,38 +479,24 @@ describe('Dashpay Contract', () => {
|
|
|
716
479
|
it('should not be less than 1', async () => {
|
|
717
480
|
contactRequestData.coreHeightCreatedAt = -1;
|
|
718
481
|
|
|
719
|
-
|
|
720
|
-
|
|
482
|
+
const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
|
|
483
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
484
|
+
const error = expectJsonSchemaError(validationResult);
|
|
721
485
|
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
725
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
726
|
-
const [error] = e.errors;
|
|
727
|
-
expect(error.name).to.equal('JsonSchemaError');
|
|
728
|
-
expect(error.keyword).to.equal('minimum');
|
|
729
|
-
expect(error.instancePath).to.equal('/coreHeightCreatedAt');
|
|
730
|
-
}
|
|
486
|
+
expect(error.keyword).to.equal('minimum');
|
|
487
|
+
expect(error.instancePath).to.equal('/coreHeightCreatedAt');
|
|
731
488
|
});
|
|
732
489
|
});
|
|
733
490
|
|
|
734
491
|
it('should not have additional properties', async () => {
|
|
735
492
|
contactRequestData.someOtherProperty = 42;
|
|
736
493
|
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
expect.fail('should throw error');
|
|
741
|
-
} catch (e) {
|
|
742
|
-
expect(e.name).to.equal('InvalidDocumentError');
|
|
743
|
-
expect(e.errors).to.have.a.lengthOf(1);
|
|
744
|
-
|
|
745
|
-
const [error] = e.errors;
|
|
494
|
+
const document = dpp.document.create(contract, identityId, 'contactRequest', contactRequestData);
|
|
495
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
496
|
+
const error = expectJsonSchemaError(validationResult);
|
|
746
497
|
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
expect(error.params.additionalProperty).to.equal('someOtherProperty');
|
|
750
|
-
}
|
|
498
|
+
expect(error.keyword).to.equal('additionalProperties');
|
|
499
|
+
expect(error.params.additionalProperties).to.deep.equal(['someOtherProperty']);
|
|
751
500
|
});
|
|
752
501
|
});
|
|
753
502
|
});
|