@dashevo/dapi-grpc 5.0.2 → 5.1.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/Cargo.toml +1 -1
- package/build.rs +20 -4
- package/clients/drive/v0/nodejs/drive_pbjs.js +55257 -41542
- package/clients/platform/v0/nodejs/PlatformPromiseClient.js +276 -0
- package/clients/platform/v0/nodejs/platform_pbjs.js +55257 -41542
- package/clients/platform/v0/nodejs/platform_protoc.js +38896 -25250
- package/clients/platform/v0/web/PlatformPromiseClient.js +88 -0
- package/clients/platform/v0/web/platform_pb.d.ts +3093 -1296
- package/clients/platform/v0/web/platform_pb.js +38896 -25250
- package/clients/platform/v0/web/platform_pb_service.d.ts +114 -0
- package/clients/platform/v0/web/platform_pb_service.js +240 -0
- package/package.json +2 -2
- package/protos/platform/v0/platform.proto +455 -2
- package/test/unit/clients/platform/v0/nodejs/PlatformPromiseClient.spec.js +196 -0
- package/test/unit/clients/platform/v0/web/PlatformPromiseClient.spec.js +74 -0
- package/test/unit/documentHistoryWire.spec.js +94 -0
- package/tests/document_history_wire.rs +30 -0
|
@@ -23,6 +23,12 @@ describe('PlatformPromiseClient', () => {
|
|
|
23
23
|
getIdentityNonce: this.sinon.stub().resolves(response),
|
|
24
24
|
getIdentityKeys: this.sinon.stub().resolves(response),
|
|
25
25
|
getIdentityBalance: this.sinon.stub().resolves(response),
|
|
26
|
+
getYesNoVotePollState: this.sinon.stub().resolves(response),
|
|
27
|
+
getMasternodeYesNoVote: this.sinon.stub().resolves(response),
|
|
28
|
+
getPrivateDocumentEntries: this.sinon.stub().resolves(response),
|
|
29
|
+
getRecentStateTransitionStatus: this.sinon.stub().resolves(response),
|
|
30
|
+
getOwnerTransactionsInBlock: this.sinon.stub().resolves(response),
|
|
31
|
+
getBlocks: this.sinon.stub().resolves(response),
|
|
26
32
|
};
|
|
27
33
|
});
|
|
28
34
|
|
|
@@ -181,4 +187,194 @@ describe('PlatformPromiseClient', () => {
|
|
|
181
187
|
.to.be.calledOnceWith(request);
|
|
182
188
|
});
|
|
183
189
|
});
|
|
190
|
+
|
|
191
|
+
describe('#getYesNoVotePollState', () => {
|
|
192
|
+
it('should get yes/no vote poll state', async () => {
|
|
193
|
+
const result = await platformPromiseClient.getYesNoVotePollState(request);
|
|
194
|
+
|
|
195
|
+
expect(result).to.equal(response);
|
|
196
|
+
expect(platformPromiseClient.client.getYesNoVotePollState)
|
|
197
|
+
.to.be.calledOnceWith(request);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it('should throw an error when metadata is not an object', async () => {
|
|
201
|
+
try {
|
|
202
|
+
platformPromiseClient.getYesNoVotePollState({}, 'metadata');
|
|
203
|
+
|
|
204
|
+
expect.fail('Error was not thrown');
|
|
205
|
+
} catch (e) {
|
|
206
|
+
expect(e.message).to.equal('metadata must be an object');
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
describe('#getMasternodeYesNoVote', () => {
|
|
212
|
+
it('should get masternode yes/no vote', async () => {
|
|
213
|
+
const result = await platformPromiseClient.getMasternodeYesNoVote(request);
|
|
214
|
+
|
|
215
|
+
expect(result).to.equal(response);
|
|
216
|
+
expect(platformPromiseClient.client.getMasternodeYesNoVote)
|
|
217
|
+
.to.be.calledOnceWith(request);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it('should throw an error when metadata is not an object', async () => {
|
|
221
|
+
try {
|
|
222
|
+
platformPromiseClient.getMasternodeYesNoVote({}, 'metadata');
|
|
223
|
+
|
|
224
|
+
expect.fail('Error was not thrown');
|
|
225
|
+
} catch (e) {
|
|
226
|
+
expect(e.message).to.equal('metadata must be an object');
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
describe('#getPrivateDocumentEntries', () => {
|
|
232
|
+
it('should get private document entries', async () => {
|
|
233
|
+
const result = await platformPromiseClient.getPrivateDocumentEntries(request);
|
|
234
|
+
|
|
235
|
+
expect(result).to.equal(response);
|
|
236
|
+
expect(platformPromiseClient.client.getPrivateDocumentEntries)
|
|
237
|
+
.to.be.calledOnceWith(request);
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it('should keep the message conversion when the caller passes interceptors', async () => {
|
|
241
|
+
const passThrough = (options, nextCall) => nextCall(options);
|
|
242
|
+
|
|
243
|
+
await platformPromiseClient.getPrivateDocumentEntries(
|
|
244
|
+
request,
|
|
245
|
+
{},
|
|
246
|
+
{ interceptors: [passThrough], deadline: 5 },
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
const [, , callOptions] = platformPromiseClient.client.getPrivateDocumentEntries
|
|
250
|
+
.firstCall.args;
|
|
251
|
+
expect(callOptions.deadline).to.equal(5);
|
|
252
|
+
expect(callOptions.interceptors).to.have.lengthOf(2);
|
|
253
|
+
expect(callOptions.interceptors[0]).to.equal(passThrough);
|
|
254
|
+
expect(callOptions.interceptors[1]).to.be.a('function');
|
|
255
|
+
expect(callOptions.interceptors[1]).to.not.equal(passThrough);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it('should throw an error when metadata is not an object', async () => {
|
|
259
|
+
try {
|
|
260
|
+
platformPromiseClient.getPrivateDocumentEntries({}, 'metadata');
|
|
261
|
+
|
|
262
|
+
expect.fail('Error was not thrown');
|
|
263
|
+
} catch (e) {
|
|
264
|
+
expect(e.message).to.equal('metadata must be an object');
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
describe('#getOwnerTransactionsInBlock', () => {
|
|
270
|
+
it('should get the transactions of an owner in a block', async () => {
|
|
271
|
+
const result = await platformPromiseClient.getOwnerTransactionsInBlock(request);
|
|
272
|
+
|
|
273
|
+
expect(result).to.equal(response);
|
|
274
|
+
expect(platformPromiseClient.client.getOwnerTransactionsInBlock)
|
|
275
|
+
.to.be.calledOnceWith(request);
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
it('should keep the message conversion when the caller passes interceptors', async () => {
|
|
279
|
+
const passThrough = (options, nextCall) => nextCall(options);
|
|
280
|
+
|
|
281
|
+
await platformPromiseClient.getOwnerTransactionsInBlock(
|
|
282
|
+
request,
|
|
283
|
+
{},
|
|
284
|
+
{ interceptors: [passThrough], deadline: 5 },
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
const [, , callOptions] = platformPromiseClient.client.getOwnerTransactionsInBlock
|
|
288
|
+
.firstCall.args;
|
|
289
|
+
expect(callOptions.deadline).to.equal(5);
|
|
290
|
+
expect(callOptions.interceptors).to.have.lengthOf(2);
|
|
291
|
+
expect(callOptions.interceptors[0]).to.equal(passThrough);
|
|
292
|
+
expect(callOptions.interceptors[1]).to.be.a('function');
|
|
293
|
+
expect(callOptions.interceptors[1]).to.not.equal(passThrough);
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
it('should throw an error when metadata is not an object', async () => {
|
|
297
|
+
try {
|
|
298
|
+
platformPromiseClient.getOwnerTransactionsInBlock({}, 'metadata');
|
|
299
|
+
|
|
300
|
+
expect.fail('Error was not thrown');
|
|
301
|
+
} catch (e) {
|
|
302
|
+
expect(e.message).to.equal('metadata must be an object');
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
describe('#getBlocks', () => {
|
|
308
|
+
it('should get blocks', async () => {
|
|
309
|
+
const result = await platformPromiseClient.getBlocks(request);
|
|
310
|
+
|
|
311
|
+
expect(result).to.equal(response);
|
|
312
|
+
expect(platformPromiseClient.client.getBlocks)
|
|
313
|
+
.to.be.calledOnceWith(request);
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
it('should keep the message conversion when the caller passes interceptors', async () => {
|
|
317
|
+
const passThrough = (options, nextCall) => nextCall(options);
|
|
318
|
+
|
|
319
|
+
await platformPromiseClient.getBlocks(
|
|
320
|
+
request,
|
|
321
|
+
{},
|
|
322
|
+
{ interceptors: [passThrough], deadline: 5 },
|
|
323
|
+
);
|
|
324
|
+
|
|
325
|
+
const [, , callOptions] = platformPromiseClient.client.getBlocks.firstCall.args;
|
|
326
|
+
expect(callOptions.deadline).to.equal(5);
|
|
327
|
+
expect(callOptions.interceptors).to.have.lengthOf(2);
|
|
328
|
+
expect(callOptions.interceptors[0]).to.equal(passThrough);
|
|
329
|
+
expect(callOptions.interceptors[1]).to.be.a('function');
|
|
330
|
+
expect(callOptions.interceptors[1]).to.not.equal(passThrough);
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
it('should throw an error when metadata is not an object', async () => {
|
|
334
|
+
try {
|
|
335
|
+
platformPromiseClient.getBlocks({}, 'metadata');
|
|
336
|
+
|
|
337
|
+
expect.fail('Error was not thrown');
|
|
338
|
+
} catch (e) {
|
|
339
|
+
expect(e.message).to.equal('metadata must be an object');
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
describe('#getRecentStateTransitionStatus', () => {
|
|
345
|
+
it('should get the node\'s status of a state transition', async () => {
|
|
346
|
+
const result = await platformPromiseClient.getRecentStateTransitionStatus(request);
|
|
347
|
+
|
|
348
|
+
expect(result).to.equal(response);
|
|
349
|
+
expect(platformPromiseClient.client.getRecentStateTransitionStatus)
|
|
350
|
+
.to.be.calledOnceWith(request);
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
it('should keep the message conversion when the caller passes interceptors', async () => {
|
|
354
|
+
const passThrough = (options, nextCall) => nextCall(options);
|
|
355
|
+
|
|
356
|
+
await platformPromiseClient.getRecentStateTransitionStatus(
|
|
357
|
+
request,
|
|
358
|
+
{},
|
|
359
|
+
{ interceptors: [passThrough], deadline: 5 },
|
|
360
|
+
);
|
|
361
|
+
|
|
362
|
+
const [, , callOptions] = platformPromiseClient.client.getRecentStateTransitionStatus
|
|
363
|
+
.firstCall.args;
|
|
364
|
+
expect(callOptions.deadline).to.equal(5);
|
|
365
|
+
expect(callOptions.interceptors).to.have.lengthOf(2);
|
|
366
|
+
expect(callOptions.interceptors[0]).to.equal(passThrough);
|
|
367
|
+
expect(callOptions.interceptors[1]).to.be.a('function');
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
it('should throw an error when metadata is not an object', async () => {
|
|
371
|
+
try {
|
|
372
|
+
platformPromiseClient.getRecentStateTransitionStatus({}, 'metadata');
|
|
373
|
+
|
|
374
|
+
expect.fail('Error was not thrown');
|
|
375
|
+
} catch (e) {
|
|
376
|
+
expect(e.message).to.equal('metadata must be an object');
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
});
|
|
184
380
|
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const { v0: { PlatformPromiseClient } } = require('../../../../../../browser');
|
|
2
|
+
|
|
3
|
+
describe('PlatformPromiseClient (web)', () => {
|
|
4
|
+
let platformPromiseClient;
|
|
5
|
+
let request;
|
|
6
|
+
let response;
|
|
7
|
+
let metadata;
|
|
8
|
+
|
|
9
|
+
beforeEach(function main() {
|
|
10
|
+
request = 'test request';
|
|
11
|
+
response = 'test response';
|
|
12
|
+
metadata = { key: 'value' };
|
|
13
|
+
|
|
14
|
+
platformPromiseClient = new PlatformPromiseClient('https://localhost/');
|
|
15
|
+
platformPromiseClient.client = {
|
|
16
|
+
getOwnerTransactionsInBlock: this.sinon.stub().yields(null, response),
|
|
17
|
+
getBlocks: this.sinon.stub().yields(null, response),
|
|
18
|
+
getRecentStateTransitionStatus: this.sinon.stub().yields(null, response),
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe('#getOwnerTransactionsInBlock', () => {
|
|
23
|
+
it('should get the transactions of an owner in a block', async () => {
|
|
24
|
+
const result = await platformPromiseClient.getOwnerTransactionsInBlock(request, metadata);
|
|
25
|
+
|
|
26
|
+
expect(result).to.equal(response);
|
|
27
|
+
expect(platformPromiseClient.client.getOwnerTransactionsInBlock)
|
|
28
|
+
.to.be.calledOnceWith(request, metadata);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('should reject with the error the service answers', async () => {
|
|
32
|
+
const error = new Error('unavailable');
|
|
33
|
+
platformPromiseClient.client.getOwnerTransactionsInBlock.yields(error);
|
|
34
|
+
|
|
35
|
+
await expect(platformPromiseClient.getOwnerTransactionsInBlock(request))
|
|
36
|
+
.to.be.rejectedWith(error);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe('#getBlocks', () => {
|
|
41
|
+
it('should get blocks', async () => {
|
|
42
|
+
const result = await platformPromiseClient.getBlocks(request, metadata);
|
|
43
|
+
|
|
44
|
+
expect(result).to.equal(response);
|
|
45
|
+
expect(platformPromiseClient.client.getBlocks)
|
|
46
|
+
.to.be.calledOnceWith(request, metadata);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('should reject with the error the service answers', async () => {
|
|
50
|
+
const error = new Error('unavailable');
|
|
51
|
+
platformPromiseClient.client.getBlocks.yields(error);
|
|
52
|
+
|
|
53
|
+
await expect(platformPromiseClient.getBlocks(request)).to.be.rejectedWith(error);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('#getRecentStateTransitionStatus', () => {
|
|
58
|
+
it('should get the node\'s status of a state transition', async () => {
|
|
59
|
+
const result = await platformPromiseClient.getRecentStateTransitionStatus(request, metadata);
|
|
60
|
+
|
|
61
|
+
expect(result).to.equal(response);
|
|
62
|
+
expect(platformPromiseClient.client.getRecentStateTransitionStatus)
|
|
63
|
+
.to.be.calledOnceWith(request, metadata);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('should reject with the error the service answers', async () => {
|
|
67
|
+
const error = new Error('unavailable');
|
|
68
|
+
platformPromiseClient.client.getRecentStateTransitionStatus.yields(error);
|
|
69
|
+
|
|
70
|
+
await expect(platformPromiseClient.getRecentStateTransitionStatus(request))
|
|
71
|
+
.to.be.rejectedWith(error);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
const assert = require('node:assert/strict');
|
|
2
|
+
const nodeMessages = require('../../clients/platform/v0/nodejs/platform_protoc');
|
|
3
|
+
const webMessages = require('../../clients/platform/v0/web/platform_pb');
|
|
4
|
+
const protobufMessages = require('../../clients/platform/v0/nodejs/platform_pbjs');
|
|
5
|
+
const driveMessages = require('../../clients/drive/v0/nodejs/drive_pbjs');
|
|
6
|
+
|
|
7
|
+
describe('document history versioned wire format', () => {
|
|
8
|
+
const requestWire = Buffer.from([0x0a, 6, 0x2a, 2, 8, 1, 0x38, 1]);
|
|
9
|
+
const responseWire = Buffer.from([0x0a, 10, 0x0a, 8, 0x0a, 6, 8, 1, 0x12, 2, 255, 255]);
|
|
10
|
+
|
|
11
|
+
it('should preserve the offset wrapper and proof flag of a version 0 request', () => {
|
|
12
|
+
[nodeMessages, webMessages].forEach((messages) => {
|
|
13
|
+
const request = messages.GetDocumentHistoryRequest.deserializeBinary(requestWire);
|
|
14
|
+
assert.equal(request.getV0().getOffset().getValue(), 1);
|
|
15
|
+
assert.equal(request.getV0().getProve(), true);
|
|
16
|
+
assert.deepEqual(Buffer.from(request.serializeBinary()), requestWire);
|
|
17
|
+
});
|
|
18
|
+
[protobufMessages, driveMessages].forEach((messages) => {
|
|
19
|
+
const Request = messages.org.dash.platform.dapi.v0.GetDocumentHistoryRequest;
|
|
20
|
+
const request = Request.decode(requestWire);
|
|
21
|
+
assert.equal(request.v0.offset.value, 1);
|
|
22
|
+
assert.equal(request.v0.prove, true);
|
|
23
|
+
assert.deepEqual(Buffer.from(Request.encode(request).finish()), requestWire);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('should preserve document bytes at field 2 of a version 0 history entry', () => {
|
|
28
|
+
[nodeMessages, webMessages].forEach((messages) => {
|
|
29
|
+
const response = messages.GetDocumentHistoryResponse.deserializeBinary(responseWire);
|
|
30
|
+
const entry = response.getV0().getDocumentHistory().getDocumentEntriesList()[0];
|
|
31
|
+
assert.equal(entry.getDate(), '1');
|
|
32
|
+
assert.deepEqual(Buffer.from(entry.getValue_asU8()), Buffer.from([255, 255]));
|
|
33
|
+
assert.deepEqual(Buffer.from(response.serializeBinary()), responseWire);
|
|
34
|
+
});
|
|
35
|
+
[protobufMessages, driveMessages].forEach((messages) => {
|
|
36
|
+
const Response = messages.org.dash.platform.dapi.v0.GetDocumentHistoryResponse;
|
|
37
|
+
const response = Response.decode(responseWire);
|
|
38
|
+
const entry = response.v0.documentHistory.documentEntries[0];
|
|
39
|
+
assert.equal(entry.date.toString(), '1');
|
|
40
|
+
assert.deepEqual(Buffer.from(entry.value), Buffer.from([255, 255]));
|
|
41
|
+
assert.deepEqual(Buffer.from(Response.encode(response).finish()), responseWire);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
it('should carry composite selectors in version 1 at outer field 2', () => {
|
|
45
|
+
const bytes = Buffer.from([0x12, 4, 0x28, 1, 0x40, 2]);
|
|
46
|
+
[nodeMessages, webMessages].forEach((messages) => {
|
|
47
|
+
const request = messages.GetDocumentHistoryRequest.deserializeBinary(bytes);
|
|
48
|
+
assert.equal(request.getV1().getProve(), true);
|
|
49
|
+
assert.equal(request.getV1().getStartAtRevision(), '2');
|
|
50
|
+
assert.equal(request.hasV0(), false);
|
|
51
|
+
assert.deepEqual(Buffer.from(request.serializeBinary()), bytes);
|
|
52
|
+
});
|
|
53
|
+
[protobufMessages, driveMessages].forEach((messages) => {
|
|
54
|
+
const Request = messages.org.dash.platform.dapi.v0.GetDocumentHistoryRequest;
|
|
55
|
+
const request = Request.decode(bytes);
|
|
56
|
+
assert.equal(request.v1.prove, true);
|
|
57
|
+
assert.equal(request.v1.startAtRevision.toString(), '2');
|
|
58
|
+
assert.equal(request.v0, null);
|
|
59
|
+
assert.deepEqual(Buffer.from(Request.encode(request).finish()), bytes);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('should preserve deleted and erasing lifecycle metadata across published clients', () => {
|
|
64
|
+
[2, 3].forEach((state) => {
|
|
65
|
+
const bytes = Buffer.from([
|
|
66
|
+
0x12, 16, 0x0a, 14, 0x12, 12,
|
|
67
|
+
8, state, 16, 1, 24, 5, 32, 6, 40, 4, 48, 7,
|
|
68
|
+
]);
|
|
69
|
+
[nodeMessages, webMessages].forEach((messages) => {
|
|
70
|
+
const response = messages.GetDocumentHistoryResponse.deserializeBinary(bytes);
|
|
71
|
+
const lifecycle = response.getV1().getHistory().getLifecycle();
|
|
72
|
+
assert.equal(lifecycle.getState(), state);
|
|
73
|
+
assert.equal(lifecycle.getRemainingRevisions(), '1');
|
|
74
|
+
assert.equal(lifecycle.getDeletedAtMs(), '5');
|
|
75
|
+
assert.equal(lifecycle.getErasingStartedAtMs(), '6');
|
|
76
|
+
assert.equal(lifecycle.getErasingFromTimeMs(), '4');
|
|
77
|
+
assert.equal(lifecycle.getErasingFromRevision(), '7');
|
|
78
|
+
assert.deepEqual(Buffer.from(response.serializeBinary()), bytes);
|
|
79
|
+
});
|
|
80
|
+
[protobufMessages, driveMessages].forEach((messages) => {
|
|
81
|
+
const Response = messages.org.dash.platform.dapi.v0.GetDocumentHistoryResponse;
|
|
82
|
+
const response = Response.decode(bytes);
|
|
83
|
+
const { lifecycle } = response.v1.history;
|
|
84
|
+
assert.equal(lifecycle.state, state);
|
|
85
|
+
assert.equal(lifecycle.remainingRevisions.toString(), '1');
|
|
86
|
+
assert.equal(lifecycle.deletedAtMs.toString(), '5');
|
|
87
|
+
assert.equal(lifecycle.erasingStartedAtMs.toString(), '6');
|
|
88
|
+
assert.equal(lifecycle.erasingFromTimeMs.toString(), '4');
|
|
89
|
+
assert.equal(lifecycle.erasingFromRevision.toString(), '7');
|
|
90
|
+
assert.deepEqual(Buffer.from(Response.encode(response).finish()), bytes);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
use dapi_grpc::platform::v0::{GetDocumentHistoryRequest, GetDocumentHistoryResponse};
|
|
2
|
+
use dapi_grpc::Message;
|
|
3
|
+
|
|
4
|
+
#[test]
|
|
5
|
+
fn should_decode_released_document_history_offset_and_prove_fields() {
|
|
6
|
+
// The offset wrapper occupies field 5; the proof flag occupies field 7.
|
|
7
|
+
let bytes = [0x0a, 6, 0x2a, 2, 8, 1, 0x38, 1];
|
|
8
|
+
let request = GetDocumentHistoryRequest::decode(bytes.as_slice())
|
|
9
|
+
.expect("a document history request with an offset must remain decodable");
|
|
10
|
+
assert_eq!(request.encode_to_vec(), bytes);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
#[test]
|
|
14
|
+
fn should_decode_released_document_history_document_bytes() {
|
|
15
|
+
// Entry field 2 contains document bytes, including arbitrary non-varints.
|
|
16
|
+
let bytes = [0x0a, 10, 0x0a, 8, 0x0a, 6, 8, 1, 0x12, 2, 0xff, 0xff];
|
|
17
|
+
let response = GetDocumentHistoryResponse::decode(bytes.as_slice())
|
|
18
|
+
.expect("document history entries must preserve their document bytes");
|
|
19
|
+
assert_eq!(response.encode_to_vec(), bytes);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
#[test]
|
|
23
|
+
fn should_keep_composite_document_history_on_its_own_version_tag() {
|
|
24
|
+
let bytes = [0x12, 4, 0x28, 1, 0x40, 2];
|
|
25
|
+
let request = GetDocumentHistoryRequest::decode(bytes.as_slice()).unwrap();
|
|
26
|
+
assert!(
|
|
27
|
+
matches!(&request.version, Some(dapi_grpc::platform::v0::get_document_history_request::Version::V1(v1)) if v1.prove)
|
|
28
|
+
);
|
|
29
|
+
assert_eq!(request.encode_to_vec(), bytes);
|
|
30
|
+
}
|