@dashevo/token-history-contract 2.0.0-dev.1
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/.eslintrc +18 -0
- package/.mocharc.yml +2 -0
- package/Cargo.toml +13 -0
- package/LICENSE +20 -0
- package/README.md +26 -0
- package/lib/systemIds.js +4 -0
- package/package.json +29 -0
- package/schema/v1/token-history-contract-documents.json +760 -0
- package/src/error.rs +17 -0
- package/src/lib.rs +37 -0
- package/src/v1/mod.rs +21 -0
- package/test/.eslintrc +12 -0
- package/test/bootstrap.js +30 -0
- package/test/unit/tokenHistoryContract.spec.js +412 -0
package/src/error.rs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
use platform_version::version::FeatureVersion;
|
|
2
|
+
|
|
3
|
+
#[derive(thiserror::Error, Debug)]
|
|
4
|
+
pub enum Error {
|
|
5
|
+
/// Platform expected some specific versions
|
|
6
|
+
#[error("platform unknown version on {method}, received: {received}")]
|
|
7
|
+
UnknownVersionMismatch {
|
|
8
|
+
/// method
|
|
9
|
+
method: String,
|
|
10
|
+
/// the allowed versions for this method
|
|
11
|
+
known_versions: Vec<FeatureVersion>,
|
|
12
|
+
/// requested core height
|
|
13
|
+
received: FeatureVersion,
|
|
14
|
+
},
|
|
15
|
+
#[error("schema deserialize error: {0}")]
|
|
16
|
+
InvalidSchemaJson(#[from] serde_json::Error),
|
|
17
|
+
}
|
package/src/lib.rs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
mod error;
|
|
2
|
+
pub mod v1;
|
|
3
|
+
|
|
4
|
+
pub use crate::error::Error;
|
|
5
|
+
use platform_value::{Identifier, IdentifierBytes32};
|
|
6
|
+
use platform_version::version::PlatformVersion;
|
|
7
|
+
use serde_json::Value;
|
|
8
|
+
|
|
9
|
+
pub const ID_BYTES: [u8; 32] = [
|
|
10
|
+
45, 67, 89, 21, 34, 216, 145, 78, 156, 243, 17, 58, 202, 190, 13, 92, 61, 40, 122, 201, 84, 99,
|
|
11
|
+
187, 110, 233, 128, 63, 48, 172, 29, 210, 108,
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
pub const OWNER_ID_BYTES: [u8; 32] = [0; 32];
|
|
15
|
+
|
|
16
|
+
pub const ID: Identifier = Identifier(IdentifierBytes32(ID_BYTES));
|
|
17
|
+
pub const OWNER_ID: Identifier = Identifier(IdentifierBytes32(OWNER_ID_BYTES));
|
|
18
|
+
pub fn load_definitions(platform_version: &PlatformVersion) -> Result<Option<Value>, Error> {
|
|
19
|
+
match platform_version.system_data_contracts.withdrawals {
|
|
20
|
+
1 => Ok(None),
|
|
21
|
+
version => Err(Error::UnknownVersionMismatch {
|
|
22
|
+
method: "wallet_contract::load_definitions".to_string(),
|
|
23
|
+
known_versions: vec![1],
|
|
24
|
+
received: version,
|
|
25
|
+
}),
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
pub fn load_documents_schemas(platform_version: &PlatformVersion) -> Result<Value, Error> {
|
|
29
|
+
match platform_version.system_data_contracts.withdrawals {
|
|
30
|
+
1 => v1::load_documents_schemas(),
|
|
31
|
+
version => Err(Error::UnknownVersionMismatch {
|
|
32
|
+
method: "wallet_contract::load_documents_schemas".to_string(),
|
|
33
|
+
known_versions: vec![1],
|
|
34
|
+
received: version,
|
|
35
|
+
}),
|
|
36
|
+
}
|
|
37
|
+
}
|
package/src/v1/mod.rs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
use crate::Error;
|
|
2
|
+
use serde_json::Value;
|
|
3
|
+
|
|
4
|
+
pub mod document_types {
|
|
5
|
+
pub mod tx_metadata {
|
|
6
|
+
pub const NAME: &str = "tx_metadata";
|
|
7
|
+
|
|
8
|
+
pub mod properties {
|
|
9
|
+
pub const KEY_INDEX: &str = "keyIndex";
|
|
10
|
+
pub const ENCRYPTION_KEY_INDEX: &str = "encryptionKeyIndex";
|
|
11
|
+
pub const ENCRYPTED_METADATA: &str = "encryptedMetadata";
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
pub fn load_documents_schemas() -> Result<Value, Error> {
|
|
17
|
+
serde_json::from_str(include_str!(
|
|
18
|
+
"../../schema/v1/token-history-contract-documents.json"
|
|
19
|
+
))
|
|
20
|
+
.map_err(Error::InvalidSchemaJson)
|
|
21
|
+
}
|
package/test/.eslintrc
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const sinon = require('sinon');
|
|
2
|
+
const sinonChai = require('sinon-chai');
|
|
3
|
+
|
|
4
|
+
const { expect, use } = require('chai');
|
|
5
|
+
const dirtyChai = require('dirty-chai');
|
|
6
|
+
|
|
7
|
+
const {
|
|
8
|
+
default: loadWasmDpp,
|
|
9
|
+
} = require('@dashevo/wasm-dpp');
|
|
10
|
+
|
|
11
|
+
use(dirtyChai);
|
|
12
|
+
use(sinonChai);
|
|
13
|
+
|
|
14
|
+
exports.mochaHooks = {
|
|
15
|
+
beforeAll: loadWasmDpp,
|
|
16
|
+
|
|
17
|
+
beforeEach() {
|
|
18
|
+
if (!this.sinon) {
|
|
19
|
+
this.sinon = sinon.createSandbox();
|
|
20
|
+
} else {
|
|
21
|
+
this.sinon.restore();
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
afterEach() {
|
|
26
|
+
this.sinon.restore();
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
global.expect = expect;
|
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
const crypto = require('crypto');
|
|
2
|
+
const {
|
|
3
|
+
DashPlatformProtocol,
|
|
4
|
+
JsonSchemaError,
|
|
5
|
+
} = require('@dashevo/wasm-dpp');
|
|
6
|
+
const generateRandomIdentifier = require('@dashevo/wasm-dpp/lib/test/utils/generateRandomIdentifierAsync');
|
|
7
|
+
const { expect } = require('chai');
|
|
8
|
+
const tokenHistoryContractDocumentsSchema = require('../../schema/v1/token-history-contract-documents.json');
|
|
9
|
+
|
|
10
|
+
const expectJsonSchemaError = (validationResult, errorCount = 1) => {
|
|
11
|
+
const errors = validationResult.getErrors();
|
|
12
|
+
expect(errors).to.have.length(errorCount);
|
|
13
|
+
|
|
14
|
+
const error = validationResult.getErrors()[0];
|
|
15
|
+
expect(error).to.be.instanceof(JsonSchemaError);
|
|
16
|
+
|
|
17
|
+
return error;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
describe('Token History Contract', () => {
|
|
21
|
+
let dpp;
|
|
22
|
+
let dataContract;
|
|
23
|
+
let identityId;
|
|
24
|
+
|
|
25
|
+
beforeEach(async () => {
|
|
26
|
+
dpp = new DashPlatformProtocol({ generate: () => crypto.randomBytes(32) });
|
|
27
|
+
identityId = await generateRandomIdentifier();
|
|
28
|
+
dataContract = dpp.dataContract.create(
|
|
29
|
+
identityId,
|
|
30
|
+
BigInt(1),
|
|
31
|
+
tokenHistoryContractDocumentsSchema,
|
|
32
|
+
);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('should have a valid contract definition', async () => {
|
|
36
|
+
const createContract = () => dpp.dataContract.create(
|
|
37
|
+
identityId,
|
|
38
|
+
BigInt(1),
|
|
39
|
+
tokenHistoryContractDocumentsSchema,
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
expect(createContract).to.not.throw();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe('documents', () => {
|
|
46
|
+
describe('burn', () => {
|
|
47
|
+
let rawBurnDocument;
|
|
48
|
+
|
|
49
|
+
beforeEach(() => {
|
|
50
|
+
rawBurnDocument = {
|
|
51
|
+
tokenId: crypto.randomBytes(32),
|
|
52
|
+
amount: 100,
|
|
53
|
+
note: 'Burning tokens',
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('tokenId', () => {
|
|
58
|
+
it('should be defined', async () => {
|
|
59
|
+
delete rawBurnDocument.tokenId;
|
|
60
|
+
const document = dpp.document.create(dataContract, identityId, 'burn', rawBurnDocument);
|
|
61
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
62
|
+
const error = expectJsonSchemaError(validationResult);
|
|
63
|
+
expect(error.keyword).to.equal('required');
|
|
64
|
+
expect(error.params.missingProperty).to.equal('tokenId');
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe('amount', () => {
|
|
69
|
+
it('should be defined', async () => {
|
|
70
|
+
delete rawBurnDocument.amount;
|
|
71
|
+
const document = dpp.document.create(dataContract, identityId, 'burn', rawBurnDocument);
|
|
72
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
73
|
+
const error = expectJsonSchemaError(validationResult);
|
|
74
|
+
expect(error.keyword).to.equal('required');
|
|
75
|
+
expect(error.params.missingProperty).to.equal('amount');
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('should be a non-negative integer', async () => {
|
|
79
|
+
rawBurnDocument.amount = -1;
|
|
80
|
+
const document = dpp.document.create(dataContract, identityId, 'burn', rawBurnDocument);
|
|
81
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
82
|
+
const error = expectJsonSchemaError(validationResult);
|
|
83
|
+
expect(error.keyword).to.equal('minimum');
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('should not have additional properties', async () => {
|
|
88
|
+
rawBurnDocument.extraProp = 123;
|
|
89
|
+
const document = dpp.document.create(dataContract, identityId, 'burn', rawBurnDocument);
|
|
90
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
91
|
+
const error = expectJsonSchemaError(validationResult);
|
|
92
|
+
|
|
93
|
+
expect(error.keyword).to.equal('additionalProperties');
|
|
94
|
+
expect(error.params.additionalProperties).to.deep.equal([
|
|
95
|
+
'extraProp',
|
|
96
|
+
]);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('should be valid', async () => {
|
|
100
|
+
const document = dpp.document.create(dataContract, identityId, 'burn', rawBurnDocument);
|
|
101
|
+
const validationResult = await document.validate(dpp.protocolVersion);
|
|
102
|
+
expect(validationResult.isValid()).to.be.true();
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
describe('mint', () => {
|
|
107
|
+
let rawMintDocument;
|
|
108
|
+
|
|
109
|
+
beforeEach(() => {
|
|
110
|
+
rawMintDocument = {
|
|
111
|
+
tokenId: crypto.randomBytes(32),
|
|
112
|
+
recipientId: crypto.randomBytes(32),
|
|
113
|
+
amount: 1000,
|
|
114
|
+
note: 'Minting tokens',
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
describe('tokenId', () => {
|
|
119
|
+
it('should be defined', async () => {
|
|
120
|
+
delete rawMintDocument.tokenId;
|
|
121
|
+
const document = dpp.document.create(dataContract, identityId, 'mint', rawMintDocument);
|
|
122
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
123
|
+
const error = expectJsonSchemaError(validationResult);
|
|
124
|
+
expect(error.keyword).to.equal('required');
|
|
125
|
+
expect(error.params.missingProperty).to.equal('tokenId');
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
describe('recipientId', () => {
|
|
130
|
+
it('should be defined', async () => {
|
|
131
|
+
delete rawMintDocument.recipientId;
|
|
132
|
+
const document = dpp.document.create(dataContract, identityId, 'mint', rawMintDocument);
|
|
133
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
134
|
+
const error = expectJsonSchemaError(validationResult);
|
|
135
|
+
expect(error.keyword).to.equal('required');
|
|
136
|
+
expect(error.params.missingProperty).to.equal('recipientId');
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
describe('amount', () => {
|
|
141
|
+
it('should be a non-negative integer', async () => {
|
|
142
|
+
rawMintDocument.amount = -1;
|
|
143
|
+
const document = dpp.document.create(dataContract, identityId, 'mint', rawMintDocument);
|
|
144
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
145
|
+
const error = expectJsonSchemaError(validationResult);
|
|
146
|
+
expect(error.keyword).to.equal('minimum');
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('should not have additional properties', async () => {
|
|
151
|
+
rawMintDocument.extraField = 'foo';
|
|
152
|
+
const document = dpp.document.create(dataContract, identityId, 'mint', rawMintDocument);
|
|
153
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
154
|
+
const error = expectJsonSchemaError(validationResult);
|
|
155
|
+
expect(error.keyword).to.equal('additionalProperties');
|
|
156
|
+
expect(error.params.additionalProperties).to.deep.equal(['extraField']);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('should be valid', async () => {
|
|
160
|
+
const document = dpp.document.create(dataContract, identityId, 'mint', rawMintDocument);
|
|
161
|
+
const validationResult = await document.validate(dpp.protocolVersion);
|
|
162
|
+
expect(validationResult.isValid()).to.be.true();
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
describe('transfer', () => {
|
|
167
|
+
let rawTransferDocument;
|
|
168
|
+
|
|
169
|
+
beforeEach(() => {
|
|
170
|
+
rawTransferDocument = {
|
|
171
|
+
tokenId: crypto.randomBytes(32),
|
|
172
|
+
amount: 10,
|
|
173
|
+
toIdentityId: crypto.randomBytes(32),
|
|
174
|
+
publicNote: 'Transfer tokens',
|
|
175
|
+
encryptedPersonalNote: crypto.randomBytes(32),
|
|
176
|
+
encryptedSharedNote: crypto.randomBytes(32),
|
|
177
|
+
senderKeyIndex: 0,
|
|
178
|
+
recipientKeyIndex: 1,
|
|
179
|
+
rootEncryptionKeyIndex: 2,
|
|
180
|
+
derivationEncryptionKeyIndex: 3,
|
|
181
|
+
};
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
describe('tokenId', () => {
|
|
185
|
+
it('should be defined', async () => {
|
|
186
|
+
delete rawTransferDocument.tokenId;
|
|
187
|
+
const document = dpp.document.create(dataContract, identityId, 'transfer', rawTransferDocument);
|
|
188
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
189
|
+
const error = expectJsonSchemaError(validationResult);
|
|
190
|
+
expect(error.keyword).to.equal('required');
|
|
191
|
+
expect(error.params.missingProperty).to.equal('tokenId');
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
describe('amount', () => {
|
|
196
|
+
it('should be a non-negative integer', async () => {
|
|
197
|
+
rawTransferDocument.amount = -1;
|
|
198
|
+
const document = dpp.document.create(dataContract, identityId, 'transfer', rawTransferDocument);
|
|
199
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
200
|
+
const error = expectJsonSchemaError(validationResult);
|
|
201
|
+
expect(error.keyword).to.equal('minimum');
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
describe('toIdentityId', () => {
|
|
206
|
+
it('should be defined', async () => {
|
|
207
|
+
delete rawTransferDocument.toIdentityId;
|
|
208
|
+
const document = dpp.document.create(dataContract, identityId, 'transfer', rawTransferDocument);
|
|
209
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
210
|
+
const error = expectJsonSchemaError(validationResult);
|
|
211
|
+
expect(error.keyword).to.equal('required');
|
|
212
|
+
expect(error.params.missingProperty).to.equal('toIdentityId');
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it('should not have additional properties', async () => {
|
|
217
|
+
rawTransferDocument.foo = 'bar';
|
|
218
|
+
const document = dpp.document.create(dataContract, identityId, 'transfer', rawTransferDocument);
|
|
219
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
220
|
+
const error = expectJsonSchemaError(validationResult);
|
|
221
|
+
expect(error.keyword).to.equal('additionalProperties');
|
|
222
|
+
expect(error.params.additionalProperties).to.deep.equal(['foo']);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it('should be valid', async () => {
|
|
226
|
+
const document = dpp.document.create(dataContract, identityId, 'transfer', rawTransferDocument);
|
|
227
|
+
const validationResult = await document.validate(dpp.protocolVersion);
|
|
228
|
+
expect(validationResult.isValid()).to.be.true();
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
describe('freeze', () => {
|
|
233
|
+
let rawFreezeDocument;
|
|
234
|
+
|
|
235
|
+
beforeEach(() => {
|
|
236
|
+
rawFreezeDocument = {
|
|
237
|
+
tokenId: crypto.randomBytes(32),
|
|
238
|
+
frozenIdentityId: crypto.randomBytes(32),
|
|
239
|
+
};
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
describe('tokenId', () => {
|
|
243
|
+
it('should be defined', async () => {
|
|
244
|
+
delete rawFreezeDocument.tokenId;
|
|
245
|
+
const document = dpp.document.create(dataContract, identityId, 'freeze', rawFreezeDocument);
|
|
246
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
247
|
+
const error = expectJsonSchemaError(validationResult);
|
|
248
|
+
expect(error.keyword).to.equal('required');
|
|
249
|
+
expect(error.params.missingProperty).to.equal('tokenId');
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
describe('frozenIdentityId', () => {
|
|
254
|
+
it('should be defined', async () => {
|
|
255
|
+
delete rawFreezeDocument.frozenIdentityId;
|
|
256
|
+
const document = dpp.document.create(dataContract, identityId, 'freeze', rawFreezeDocument);
|
|
257
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
258
|
+
const error = expectJsonSchemaError(validationResult);
|
|
259
|
+
expect(error.keyword).to.equal('required');
|
|
260
|
+
expect(error.params.missingProperty).to.equal('frozenIdentityId');
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it('should not have additional properties', async () => {
|
|
265
|
+
rawFreezeDocument.something = true;
|
|
266
|
+
const document = dpp.document.create(dataContract, identityId, 'freeze', rawFreezeDocument);
|
|
267
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
268
|
+
const error = expectJsonSchemaError(validationResult);
|
|
269
|
+
expect(error.keyword).to.equal('additionalProperties');
|
|
270
|
+
expect(error.params.additionalProperties).to.deep.equal(['something']);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it('should be valid', async () => {
|
|
274
|
+
const document = dpp.document.create(dataContract, identityId, 'freeze', rawFreezeDocument);
|
|
275
|
+
const validationResult = await document.validate(dpp.protocolVersion);
|
|
276
|
+
expect(validationResult.isValid()).to.be.true();
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
describe('unfreeze', () => {
|
|
281
|
+
let rawUnfreezeDocument;
|
|
282
|
+
|
|
283
|
+
beforeEach(() => {
|
|
284
|
+
rawUnfreezeDocument = {
|
|
285
|
+
tokenId: crypto.randomBytes(32),
|
|
286
|
+
frozenIdentityId: crypto.randomBytes(32),
|
|
287
|
+
};
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
describe('tokenId', () => {
|
|
291
|
+
it('should be defined', async () => {
|
|
292
|
+
delete rawUnfreezeDocument.tokenId;
|
|
293
|
+
const document = dpp.document.create(dataContract, identityId, 'unfreeze', rawUnfreezeDocument);
|
|
294
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
295
|
+
const error = expectJsonSchemaError(validationResult);
|
|
296
|
+
expect(error.keyword).to.equal('required');
|
|
297
|
+
expect(error.params.missingProperty).to.equal('tokenId');
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
it('should not have additional properties', async () => {
|
|
302
|
+
rawUnfreezeDocument.foo = 'bar';
|
|
303
|
+
const document = dpp.document.create(dataContract, identityId, 'unfreeze', rawUnfreezeDocument);
|
|
304
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
305
|
+
const error = expectJsonSchemaError(validationResult);
|
|
306
|
+
expect(error.keyword).to.equal('additionalProperties');
|
|
307
|
+
expect(error.params.additionalProperties).to.deep.equal(['foo']);
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
it('should be valid', async () => {
|
|
311
|
+
const document = dpp.document.create(dataContract, identityId, 'unfreeze', rawUnfreezeDocument);
|
|
312
|
+
const validationResult = await document.validate(dpp.protocolVersion);
|
|
313
|
+
expect(validationResult.isValid()).to.be.true();
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
describe('destroyFrozenFunds', () => {
|
|
318
|
+
let rawDestroyFrozenFundsDocument;
|
|
319
|
+
|
|
320
|
+
beforeEach(() => {
|
|
321
|
+
rawDestroyFrozenFundsDocument = {
|
|
322
|
+
tokenId: crypto.randomBytes(32),
|
|
323
|
+
frozenIdentityId: crypto.randomBytes(32),
|
|
324
|
+
destroyedAmount: 500,
|
|
325
|
+
};
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
describe('frozenIdentityId', () => {
|
|
329
|
+
it('should be defined', async () => {
|
|
330
|
+
delete rawDestroyFrozenFundsDocument.frozenIdentityId;
|
|
331
|
+
const document = dpp.document.create(dataContract, identityId, 'destroyFrozenFunds', rawDestroyFrozenFundsDocument);
|
|
332
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
333
|
+
const error = expectJsonSchemaError(validationResult);
|
|
334
|
+
expect(error.keyword).to.equal('required');
|
|
335
|
+
expect(error.params.missingProperty).to.equal('frozenIdentityId');
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
describe('destroyedAmount', () => {
|
|
340
|
+
it('should be non-negative', async () => {
|
|
341
|
+
rawDestroyFrozenFundsDocument.destroyedAmount = -1;
|
|
342
|
+
const document = dpp.document.create(dataContract, identityId, 'destroyFrozenFunds', rawDestroyFrozenFundsDocument);
|
|
343
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
344
|
+
const error = expectJsonSchemaError(validationResult);
|
|
345
|
+
expect(error.keyword).to.equal('minimum');
|
|
346
|
+
});
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
it('should not have additional properties', async () => {
|
|
350
|
+
rawDestroyFrozenFundsDocument.bar = 123;
|
|
351
|
+
const document = dpp.document.create(dataContract, identityId, 'destroyFrozenFunds', rawDestroyFrozenFundsDocument);
|
|
352
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
353
|
+
const error = expectJsonSchemaError(validationResult);
|
|
354
|
+
expect(error.keyword).to.equal('additionalProperties');
|
|
355
|
+
expect(error.params.additionalProperties).to.deep.equal(['bar']);
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
it('should be valid', async () => {
|
|
359
|
+
const document = dpp.document.create(dataContract, identityId, 'destroyFrozenFunds', rawDestroyFrozenFundsDocument);
|
|
360
|
+
const validationResult = await document.validate(dpp.protocolVersion);
|
|
361
|
+
expect(validationResult.isValid()).to.be.true();
|
|
362
|
+
});
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
describe('emergencyAction', () => {
|
|
366
|
+
let rawEmergencyActionDocument;
|
|
367
|
+
|
|
368
|
+
beforeEach(() => {
|
|
369
|
+
rawEmergencyActionDocument = {
|
|
370
|
+
tokenId: crypto.randomBytes(32),
|
|
371
|
+
action: 1,
|
|
372
|
+
};
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
describe('tokenId', () => {
|
|
376
|
+
it('should be defined', async () => {
|
|
377
|
+
delete rawEmergencyActionDocument.tokenId;
|
|
378
|
+
const document = dpp.document.create(dataContract, identityId, 'emergencyAction', rawEmergencyActionDocument);
|
|
379
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
380
|
+
const error = expectJsonSchemaError(validationResult);
|
|
381
|
+
expect(error.keyword).to.equal('required');
|
|
382
|
+
expect(error.params.missingProperty).to.equal('tokenId');
|
|
383
|
+
});
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
describe('action', () => {
|
|
387
|
+
it('should be non-negative', async () => {
|
|
388
|
+
rawEmergencyActionDocument.action = -5;
|
|
389
|
+
const document = dpp.document.create(dataContract, identityId, 'emergencyAction', rawEmergencyActionDocument);
|
|
390
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
391
|
+
const error = expectJsonSchemaError(validationResult);
|
|
392
|
+
expect(error.keyword).to.equal('enum');
|
|
393
|
+
});
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
it('should not have additional properties', async () => {
|
|
397
|
+
rawEmergencyActionDocument.xyz = 999;
|
|
398
|
+
const document = dpp.document.create(dataContract, identityId, 'emergencyAction', rawEmergencyActionDocument);
|
|
399
|
+
const validationResult = document.validate(dpp.protocolVersion);
|
|
400
|
+
const error = expectJsonSchemaError(validationResult);
|
|
401
|
+
expect(error.keyword).to.equal('additionalProperties');
|
|
402
|
+
expect(error.params.additionalProperties).to.deep.equal(['xyz']);
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
it('should be valid', async () => {
|
|
406
|
+
const document = dpp.document.create(dataContract, identityId, 'emergencyAction', rawEmergencyActionDocument);
|
|
407
|
+
const validationResult = await document.validate(dpp.protocolVersion);
|
|
408
|
+
expect(validationResult.isValid()).to.be.true();
|
|
409
|
+
});
|
|
410
|
+
});
|
|
411
|
+
});
|
|
412
|
+
});
|