@dashevo/wasm-dpp 0.23.0-dev.10
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/.babelrc +5 -0
- package/.editorconfig +13 -0
- package/.eslintignore +1 -0
- package/.eslintrc +15 -0
- package/.mocharc.yml +4 -0
- package/CHANGELOG.md +397 -0
- package/LICENSE +20 -0
- package/README.md +37 -0
- package/karma.conf.js +53 -0
- package/package.json +107 -0
- package/test/.eslintrc +12 -0
- package/test/integration/DashPlatformProtocol.spec.js +53 -0
- package/test/integration/ajv/keywords/byteArray/addByteArrayKeyword.spec.js +148 -0
- package/test/integration/dataContract/DataContractFacade.spec.js +84 -0
- package/test/integration/dataContract/stateTransition/DataContractCreateTransition/validation/basic/validateDataContractCreateTransitionBasicFactory.spec.js +357 -0
- package/test/integration/dataContract/stateTransition/DataContractUpdateTransition/validation/basic/validateDataContractUpdateTransitionBasicFactory.spec.js +444 -0
- package/test/integration/dataContract/validation/validateDataContractFactory.spec.js +2191 -0
- package/test/integration/document/Document.spec.js +90 -0
- package/test/integration/document/DocumentFacade.spec.js +155 -0
- package/test/integration/document/stateTransition/DocumentsBatchTransition/DocumentBatchTransition.spec.js +83 -0
- package/test/integration/document/stateTransition/DocumentsBatchTransition/validation/basic/validateDocumentsBatchTransitionBasicFactory.spec.js +1146 -0
- package/test/integration/document/stateTransition/DocumentsBatchTransition/validation/state/executeDataTriggersFactory.spec.js +294 -0
- package/test/integration/document/validation/validateDocumentFactory.spec.js +447 -0
- package/test/integration/error/consensus/createConsensusError.spec.js +21 -0
- package/test/integration/identity/IdentityFacade.spec.js +187 -0
- package/test/integration/identity/stateTransition/IdentityCreateTransition/validation/basic/validateIdentityCreateTransitionBasicFactory.spec.js +422 -0
- package/test/integration/identity/stateTransition/IdentityTopUpTransition/validation/basic/validateIdentityTopUpTransitionBasicFactory.spec.js +361 -0
- package/test/integration/identity/stateTransition/IdentityUpdateTransition/validation/basic/validateIdentityUpdateTransitionBasicFactory.spec.js +595 -0
- package/test/integration/identity/stateTransition/IdentityUpdateTransition/validation/state/validateIdentityUpdateTransitionStateFactory.spec.js +299 -0
- package/test/integration/identity/stateTransition/IdentityUpdateTransition/validation/state/validatePublicKeysState.spec.js +66 -0
- package/test/integration/identity/stateTransition/assetLockProof/chain/validateChainAssetLockProofStructureFactory.spec.js +415 -0
- package/test/integration/identity/stateTransition/assetLockProof/fetchAssetLockTransactionOutputFactory.spec.js +134 -0
- package/test/integration/identity/stateTransition/assetLockProof/instant/validateInstantAssetLockProofStructureFactory.spec.js +401 -0
- package/test/integration/identity/stateTransition/assetLockProof/validateAssetLockTransactionFactory.spec.js +205 -0
- package/test/integration/identity/stateTransition/validatePublicKeySignaturesFactory.spec.js +127 -0
- package/test/integration/identity/validation/validateIdentityFactory.spec.js +370 -0
- package/test/integration/identity/validation/validatePublicKeysFactory.spec.js +497 -0
- package/test/integration/stateTransition/AbstractStateTransitionIdentitySigned.spec.js +507 -0
- package/test/integration/stateTransition/StateTransitionFacade.spec.js +418 -0
- package/test/integration/stateTransition/calculateStateTransitionFee.spec.js +35 -0
- package/test/integration/util/generateEntropy.spec.js +17 -0
- package/test/integration/util/serializer.spec.js +24 -0
- package/test/unit/DashPlatformProtocol.spec.js +79 -0
- package/test/unit/Identifier.spec.js +123 -0
- package/test/unit/Metadata.spec.js +37 -0
- package/test/unit/dataContract/DataContract.spec.js +407 -0
- package/test/unit/dataContract/DataContractFactory.spec.js +178 -0
- package/test/unit/dataContract/createDataContract.spec.js +57 -0
- package/test/unit/dataContract/errors/InvalidDataContractError.spec.js +46 -0
- package/test/unit/dataContract/generateDataContractId.spec.js +19 -0
- package/test/unit/dataContract/getBinaryPropertiesFromSchema.spec.js +103 -0
- package/test/unit/dataContract/getPropertyDefinitionByPath.spec.js +84 -0
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/DataContractCreateTransition.spec.js +160 -0
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/applyDataContractCreateTransitionFactory.spec.js +48 -0
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/validation/state/validateDataContractCreateTransitionStateFactory.spec.js +85 -0
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/DataContractUpdateTransition.spec.js +158 -0
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/applyDataContractUpdateTransitionFactory.spec.js +47 -0
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/validation/basic/validateIndicesAreBackwardCompatible.spec.js +121 -0
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/validation/state/validateDataContractUpdateTransitionStateFactory.spec.js +111 -0
- package/test/unit/dataContract/validation/validateDataContractMaxDepthFactory.spec.js +93 -0
- package/test/unit/dataContract/validation/validateDataContractPatternsFactory.spec.js +64 -0
- package/test/unit/dataTrigger/DataTrigger.spec.js +132 -0
- package/test/unit/dataTrigger/DataTriggerExecutionContext.spec.js +29 -0
- package/test/unit/dataTrigger/dashpayDataTriggers/createContactRequestDataTrigger.spec.js +109 -0
- package/test/unit/dataTrigger/dpnsTriggers/createDomainDataTrigger.spec.js +382 -0
- package/test/unit/dataTrigger/featureFlagDataTriggers/createFeatureFlagDataTrigger.spec.js +101 -0
- package/test/unit/dataTrigger/getDataTriggersFactory.spec.js +113 -0
- package/test/unit/dataTrigger/rejectDataTrigger.spec.js +51 -0
- package/test/unit/dataTrigger/rewardShareDataTriggers/createMasternodeRewardSharesDataTrigger.spec.js +200 -0
- package/test/unit/decodeProtocolEntityFactory.spec.js +75 -0
- package/test/unit/document/Document.spec.js +444 -0
- package/test/unit/document/DocumentFactory.spec.js +376 -0
- package/test/unit/document/errors/InvalidDocumentError.spec.js +46 -0
- package/test/unit/document/fetchAndValidateDataContractFactory.spec.js +66 -0
- package/test/unit/document/stateTransition/DocumetsBatchTransition/DocumentsBatchTransition.spec.js +168 -0
- package/test/unit/document/stateTransition/DocumetsBatchTransition/applyDocumentsBatchTransitionFactory.spec.js +171 -0
- package/test/unit/document/stateTransition/DocumetsBatchTransition/documentTransition/DocumentCreateTransition.spec.js +25 -0
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/basic/findDuplicatesById.spec.js +31 -0
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/basic/findDuplicatesByIndices.spec.js +122 -0
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/basic/validatePartialCompoundIndices.spec.js +75 -0
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/fetchDocumentsFactory.spec.js +128 -0
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/validateDocumentsBatchTransitionStateFactory.spec.js +811 -0
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/validateDocumentsUniquenessByIndicesFactory.spec.js +279 -0
- package/test/unit/errors/consensus/codes.spec.js +102 -0
- package/test/unit/identity/Identity.spec.js +243 -0
- package/test/unit/identity/IdentityFactory.spec.js +274 -0
- package/test/unit/identity/IdentityPublicKey.spec.js +273 -0
- package/test/unit/identity/creditsConverter.spec.js +34 -0
- package/test/unit/identity/errors/InvalidIdentityError.spec.js +46 -0
- package/test/unit/identity/stateTransition/IdentityCreateTransition/IdentityCreateTransition.spec.js +184 -0
- package/test/unit/identity/stateTransition/IdentityCreateTransition/applyIdentityCreateTransitionFactory.spec.js +90 -0
- package/test/unit/identity/stateTransition/IdentityCreateTransition/validation/state/validateIdentityCreateTransitionStateFactory.spec.js +71 -0
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/IdentityTopUpTransition.spec.js +137 -0
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/applyIdentityTopUpTransitionFactory.spec.js +108 -0
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/validation/state/validateIdentityTopUpTransitionStateFactory.spec.js +22 -0
- package/test/unit/identity/stateTransition/IdentityUpdateTransition/IdentityUpdateTransition.spec.js +219 -0
- package/test/unit/identity/stateTransition/IdentityUpdateTransition/applyIdentityUpdateTransitionFactory.spec.js +149 -0
- package/test/unit/identity/stateTransition/assetLockProof/createAssetLockProofInstance.spec.js +21 -0
- package/test/unit/identity/stateTransition/assetLockProof/fetchAssetLockPublicKeyHashFactory.spec.js +36 -0
- package/test/unit/identity/validation/validateRequiredPurposeAndSecurityLevelFactory.spec.js +47 -0
- package/test/unit/stateTransition/StateTransitionFactory.spec.js +160 -0
- package/test/unit/stateTransition/createStateTransitionFactory.spec.js +72 -0
- package/test/unit/stateTransition/errors/InvalidStateTransitionError.spec.js +51 -0
- package/test/unit/stateTransition/validation/validateStateTransitionBasicFactory.spec.js +138 -0
- package/test/unit/stateTransition/validation/validateStateTransitionFeeFactory.spec.js +372 -0
- package/test/unit/stateTransition/validation/validateStateTransitionIdentitySignatureFactory.spec.js +339 -0
- package/test/unit/stateTransition/validation/validateStateTransitionKeySignatureFactory.spec.js +86 -0
- package/test/unit/stateTransition/validation/validateStateTransitionStateFactory.spec.js +89 -0
- package/test/unit/version/validateProtocolVersionFactory.spec.js +80 -0
- package/webpack.config.js +49 -0
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
const DataContractFactory = require('../../../lib/dataContract/DataContractFactory');
|
|
2
|
+
|
|
3
|
+
const generateRandomIdentifier = require('../../../lib/test/utils/generateRandomIdentifier');
|
|
4
|
+
|
|
5
|
+
const DocumentCreateTransition = require(
|
|
6
|
+
'../../../lib/document/stateTransition/DocumentsBatchTransition/documentTransition/DocumentCreateTransition',
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
const Identifier = require('../../../lib/identifier/Identifier');
|
|
10
|
+
|
|
11
|
+
const protocolVersion = require('../../../lib/version/protocolVersion');
|
|
12
|
+
const createDPPMock = require('../../../lib/test/mocks/createDPPMock');
|
|
13
|
+
|
|
14
|
+
const Document = require('../../../lib/document/Document');
|
|
15
|
+
|
|
16
|
+
const hash = require('../../../lib/util/hash');
|
|
17
|
+
const serializer = require('../../../lib/util/serializer');
|
|
18
|
+
|
|
19
|
+
describe('Document', () => {
|
|
20
|
+
let hashMock;
|
|
21
|
+
let encodeMock;
|
|
22
|
+
let rawDocument;
|
|
23
|
+
let document;
|
|
24
|
+
let dataContract;
|
|
25
|
+
|
|
26
|
+
beforeEach(function beforeEach() {
|
|
27
|
+
const now = new Date().getTime();
|
|
28
|
+
|
|
29
|
+
const ownerId = generateRandomIdentifier().toBuffer();
|
|
30
|
+
|
|
31
|
+
const dataContractFactory = new DataContractFactory(createDPPMock(), () => {});
|
|
32
|
+
|
|
33
|
+
dataContract = dataContractFactory.create(ownerId, {
|
|
34
|
+
test: {
|
|
35
|
+
properties: {
|
|
36
|
+
name: {
|
|
37
|
+
type: 'string',
|
|
38
|
+
},
|
|
39
|
+
dataObject: {
|
|
40
|
+
type: 'object',
|
|
41
|
+
properties: {
|
|
42
|
+
binaryObject: {
|
|
43
|
+
type: 'object',
|
|
44
|
+
properties: {
|
|
45
|
+
identifier: {
|
|
46
|
+
type: 'array',
|
|
47
|
+
byteArray: true,
|
|
48
|
+
contentMediaType: Identifier.MEDIA_TYPE,
|
|
49
|
+
minItems: 32,
|
|
50
|
+
maxItems: 32,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
rawDocument = {
|
|
61
|
+
$protocolVersion: protocolVersion.latestVersion,
|
|
62
|
+
$id: generateRandomIdentifier(),
|
|
63
|
+
$type: 'test',
|
|
64
|
+
$dataContractId: dataContract.getId(),
|
|
65
|
+
$ownerId: ownerId,
|
|
66
|
+
$revision: DocumentCreateTransition.INITIAL_REVISION,
|
|
67
|
+
$createdAt: now,
|
|
68
|
+
$updatedAt: now,
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
document = new Document(rawDocument, dataContract);
|
|
72
|
+
|
|
73
|
+
encodeMock = this.sinonSandbox.stub(serializer, 'encode');
|
|
74
|
+
hashMock = this.sinonSandbox.stub(hash, 'hash');
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
afterEach(() => {
|
|
78
|
+
encodeMock.restore();
|
|
79
|
+
hashMock.restore();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe('constructor', () => {
|
|
83
|
+
it('should create Document with $id and data if present', () => {
|
|
84
|
+
const data = {
|
|
85
|
+
test: 1,
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
rawDocument = {
|
|
89
|
+
$id: Buffer.alloc(32),
|
|
90
|
+
$type: 'test',
|
|
91
|
+
...data,
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
document = new Document(rawDocument, dataContract);
|
|
95
|
+
|
|
96
|
+
expect(document.id).to.deep.equal(rawDocument.$id);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('should create Document with $type and data if present', () => {
|
|
100
|
+
const data = {
|
|
101
|
+
test: 1,
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
rawDocument = {
|
|
105
|
+
$type: 'test',
|
|
106
|
+
...data,
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
document = new Document(rawDocument, dataContract);
|
|
110
|
+
|
|
111
|
+
expect(document.type).to.equal(rawDocument.$type);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('should create Document with $dataContractId and data if present', () => {
|
|
115
|
+
const data = {
|
|
116
|
+
test: 1,
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
rawDocument = {
|
|
120
|
+
$dataContractId: generateRandomIdentifier().toBuffer(),
|
|
121
|
+
$type: 'test',
|
|
122
|
+
...data,
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
document = new Document(rawDocument, dataContract);
|
|
126
|
+
|
|
127
|
+
expect(document.dataContractId).to.deep.equal(rawDocument.$dataContractId);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('should create Document with $ownerId and data if present', () => {
|
|
131
|
+
const data = {
|
|
132
|
+
test: 1,
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
rawDocument = {
|
|
136
|
+
$ownerId: generateRandomIdentifier().toBuffer(),
|
|
137
|
+
$type: 'test',
|
|
138
|
+
...data,
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
document = new Document(rawDocument, dataContract);
|
|
142
|
+
|
|
143
|
+
expect(document.ownerId.toBuffer()).to.deep.equal(rawDocument.$ownerId);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('should create Document with undefined action and data if present', () => {
|
|
147
|
+
const data = {
|
|
148
|
+
test: 1,
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
rawDocument = {
|
|
152
|
+
$type: 'test',
|
|
153
|
+
...data,
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
document = new Document(rawDocument, dataContract);
|
|
157
|
+
|
|
158
|
+
expect(document.action).to.equal(undefined);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('should create Document with $revision and data if present', () => {
|
|
162
|
+
const data = {
|
|
163
|
+
test: 1,
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
rawDocument = {
|
|
167
|
+
$revision: 'test',
|
|
168
|
+
$type: 'test',
|
|
169
|
+
...data,
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
document = new Document(rawDocument, dataContract);
|
|
173
|
+
|
|
174
|
+
expect(document.revision).to.equal(rawDocument.$revision);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it('should create Document with $createdAt and data if present', async () => {
|
|
178
|
+
const data = {
|
|
179
|
+
test: 1,
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
const createdAt = new Date().getTime();
|
|
183
|
+
|
|
184
|
+
rawDocument = {
|
|
185
|
+
$createdAt: createdAt,
|
|
186
|
+
$type: 'test',
|
|
187
|
+
...data,
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
document = new Document(rawDocument, dataContract);
|
|
191
|
+
|
|
192
|
+
expect(document.getCreatedAt().getTime()).to.equal(rawDocument.$createdAt);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it('should create Document with $updatedAt and data if present', async () => {
|
|
196
|
+
const data = {
|
|
197
|
+
test: 1,
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
const updatedAt = new Date().getTime();
|
|
201
|
+
|
|
202
|
+
rawDocument = {
|
|
203
|
+
$updatedAt: updatedAt,
|
|
204
|
+
$type: 'test',
|
|
205
|
+
...data,
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
document = new Document(rawDocument, dataContract);
|
|
209
|
+
|
|
210
|
+
expect(document.getUpdatedAt().getTime()).to.equal(rawDocument.$updatedAt);
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
describe('#getId', () => {
|
|
215
|
+
it('should return ID', () => {
|
|
216
|
+
const id = '123';
|
|
217
|
+
|
|
218
|
+
document.id = id;
|
|
219
|
+
|
|
220
|
+
const actualId = document.getId();
|
|
221
|
+
|
|
222
|
+
expect(hashMock).to.have.not.been.called();
|
|
223
|
+
|
|
224
|
+
expect(id).to.equal(actualId);
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
describe('#getType', () => {
|
|
229
|
+
it('should return $type', () => {
|
|
230
|
+
expect(document.getType()).to.equal(rawDocument.$type);
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
describe('#getOwnerId', () => {
|
|
235
|
+
it('should return $ownerId', () => {
|
|
236
|
+
expect(document.getOwnerId()).to.deep.equal(rawDocument.$ownerId);
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
describe('#getDataContractId', () => {
|
|
241
|
+
it('should return $dataContractId', () => {
|
|
242
|
+
expect(document.getOwnerId()).to.deep.equal(rawDocument.$ownerId);
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
describe('#setRevision', () => {
|
|
247
|
+
it('should set $revision', () => {
|
|
248
|
+
const revision = 5;
|
|
249
|
+
|
|
250
|
+
const result = document.setRevision(revision);
|
|
251
|
+
|
|
252
|
+
expect(result).to.equal(document);
|
|
253
|
+
|
|
254
|
+
expect(document.revision).to.equal(revision);
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
describe('#getRevision', () => {
|
|
259
|
+
it('should return $revision', () => {
|
|
260
|
+
const revision = 5;
|
|
261
|
+
|
|
262
|
+
document.revision = revision;
|
|
263
|
+
|
|
264
|
+
expect(document.getRevision()).to.equal(revision);
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
describe('#setData', () => {
|
|
269
|
+
it('should call set for each document property', () => {
|
|
270
|
+
const data = {
|
|
271
|
+
test1: 1,
|
|
272
|
+
test2: 2,
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
const result = document.setData(data);
|
|
276
|
+
|
|
277
|
+
expect(result).to.equal(document);
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
describe('#getData', () => {
|
|
282
|
+
it('should return all data', () => {
|
|
283
|
+
const data = {
|
|
284
|
+
test1: 1,
|
|
285
|
+
test2: 2,
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
document.data = data;
|
|
289
|
+
|
|
290
|
+
expect(document.getData()).to.equal(data);
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
describe('#set', () => {
|
|
295
|
+
it('should set value for specified property name', () => {
|
|
296
|
+
const path = 'test[0].$my';
|
|
297
|
+
const value = 2;
|
|
298
|
+
|
|
299
|
+
const result = document.set(path, value);
|
|
300
|
+
|
|
301
|
+
expect(result).to.equal(document);
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
it('should set identifier', () => {
|
|
305
|
+
const path = 'dataObject.binaryObject.identifier';
|
|
306
|
+
const buffer = Buffer.alloc(32);
|
|
307
|
+
|
|
308
|
+
const result = document.set(path, buffer);
|
|
309
|
+
|
|
310
|
+
expect(result).to.equal(document);
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
it('should set identifier as part of object', () => {
|
|
314
|
+
const buffer = Buffer.alloc(32, 'a');
|
|
315
|
+
const path = 'dataObject.binaryObject';
|
|
316
|
+
const value = { identifier: buffer };
|
|
317
|
+
|
|
318
|
+
const result = document.set(path, value);
|
|
319
|
+
|
|
320
|
+
expect(result).to.equal(document);
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
describe('#get', () => {
|
|
325
|
+
it('should return value for specified property name', () => {
|
|
326
|
+
const path = 'dataObject.binaryObject.identifier';
|
|
327
|
+
const buffer = Buffer.alloc(32);
|
|
328
|
+
|
|
329
|
+
document.set(path, buffer);
|
|
330
|
+
|
|
331
|
+
const result = document.get(path);
|
|
332
|
+
|
|
333
|
+
expect(result).to.deep.equal(buffer);
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
describe('#toJSON', () => {
|
|
338
|
+
it('should return Document as plain JS object', () => {
|
|
339
|
+
const jsonDocument = {
|
|
340
|
+
...rawDocument,
|
|
341
|
+
$dataContractId: document.dataContractId.toString(),
|
|
342
|
+
$id: document.id.toString(),
|
|
343
|
+
$ownerId: document.ownerId.toString(),
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
expect(document.toJSON()).to.deep.equal(jsonDocument);
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
describe('#toBuffer', () => {
|
|
351
|
+
it('should return serialized Document', () => {
|
|
352
|
+
const serializedDocument = Buffer.from('123');
|
|
353
|
+
|
|
354
|
+
encodeMock.returns(serializedDocument);
|
|
355
|
+
|
|
356
|
+
const result = document.toBuffer();
|
|
357
|
+
|
|
358
|
+
const protocolVersionUInt32 = Buffer.alloc(4);
|
|
359
|
+
protocolVersionUInt32.writeUInt32LE(rawDocument.$protocolVersion, 0);
|
|
360
|
+
|
|
361
|
+
expect(result).to.deep.equal(Buffer.concat([protocolVersionUInt32, serializedDocument]));
|
|
362
|
+
|
|
363
|
+
const documentToEncode = { ...rawDocument };
|
|
364
|
+
delete documentToEncode.$protocolVersion;
|
|
365
|
+
|
|
366
|
+
expect(encodeMock.getCall(0).args).to.have.deep.members([
|
|
367
|
+
documentToEncode,
|
|
368
|
+
]);
|
|
369
|
+
});
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
describe('#hash', () => {
|
|
373
|
+
let toBufferMock;
|
|
374
|
+
|
|
375
|
+
beforeEach(function beforeEach() {
|
|
376
|
+
toBufferMock = this.sinonSandbox.stub(Document.prototype, 'toBuffer');
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
afterEach(() => {
|
|
380
|
+
toBufferMock.restore();
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
it('should return Document hash', () => {
|
|
384
|
+
const serializedDocument = '123';
|
|
385
|
+
const hashedDocument = '456';
|
|
386
|
+
|
|
387
|
+
toBufferMock.returns(serializedDocument);
|
|
388
|
+
|
|
389
|
+
hashMock.returns(hashedDocument);
|
|
390
|
+
|
|
391
|
+
const result = document.hash();
|
|
392
|
+
|
|
393
|
+
expect(result).to.equal(hashedDocument);
|
|
394
|
+
|
|
395
|
+
expect(toBufferMock).to.have.been.calledOnce();
|
|
396
|
+
|
|
397
|
+
expect(hashMock).to.have.been.calledOnceWith(serializedDocument);
|
|
398
|
+
});
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
describe('#setCreatedAt', () => {
|
|
402
|
+
it('should set $createdAt', () => {
|
|
403
|
+
const time = new Date();
|
|
404
|
+
|
|
405
|
+
const result = document.setCreatedAt(time);
|
|
406
|
+
|
|
407
|
+
expect(result).to.equal(document);
|
|
408
|
+
|
|
409
|
+
expect(document.createdAt).to.equal(time);
|
|
410
|
+
});
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
describe('#getCreatedAt', () => {
|
|
414
|
+
it('should return $createdAt', () => {
|
|
415
|
+
const time = new Date();
|
|
416
|
+
|
|
417
|
+
document.createdAt = time;
|
|
418
|
+
|
|
419
|
+
expect(document.getCreatedAt()).to.equal(time);
|
|
420
|
+
});
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
describe('#setUpdatedAt', () => {
|
|
424
|
+
it('should set $updatedAt', () => {
|
|
425
|
+
const time = new Date();
|
|
426
|
+
|
|
427
|
+
const result = document.setUpdatedAt(time);
|
|
428
|
+
|
|
429
|
+
expect(result).to.equal(document);
|
|
430
|
+
|
|
431
|
+
expect(document.updatedAt).to.equal(time);
|
|
432
|
+
});
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
describe('#getUpdatedAt', () => {
|
|
436
|
+
it('should return $updatedAt', () => {
|
|
437
|
+
const time = new Date();
|
|
438
|
+
|
|
439
|
+
document.updatedAt = time;
|
|
440
|
+
|
|
441
|
+
expect(document.getUpdatedAt()).to.equal(time);
|
|
442
|
+
});
|
|
443
|
+
});
|
|
444
|
+
});
|