dash-platform-sdk 1.3.2-dev.4 → 1.3.2-dev.5
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/bundle.min.js +1 -1
- package/package.json +1 -1
- package/src/documents/query.js +4 -3
- package/test/unit/Document.spec.js +29 -0
package/package.json
CHANGED
package/src/documents/query.js
CHANGED
|
@@ -11,13 +11,13 @@ export default async function query(grpcPool, dataContractId, documentTypeName,
|
|
|
11
11
|
if (startAt != null) {
|
|
12
12
|
start = {
|
|
13
13
|
oneofKind: 'startAt',
|
|
14
|
-
startAt: startAt.
|
|
14
|
+
startAt: startAt.bytes()
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
17
|
if (startAfter != null) {
|
|
18
18
|
start = {
|
|
19
19
|
oneofKind: 'startAfter',
|
|
20
|
-
|
|
20
|
+
startAfter: startAfter.bytes()
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
const getDocumentsRequest = GetDocumentsRequest.create({
|
|
@@ -49,7 +49,8 @@ export default async function query(grpcPool, dataContractId, documentTypeName,
|
|
|
49
49
|
throw new Error('Metadata not found');
|
|
50
50
|
}
|
|
51
51
|
const startAtIncluded = startAt != null;
|
|
52
|
-
const
|
|
52
|
+
const startIdentifier = startAt ?? startAfter;
|
|
53
|
+
const { rootHash, documents } = verifyDocumentsProof(proof.grovedbProof, dataContract, documentTypeName, where, orderBy, limit, startIdentifier?.bytes(), startAtIncluded, BigInt(metadata?.timeMs), LATEST_PLATFORM_VERSION);
|
|
53
54
|
const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
|
|
54
55
|
const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
|
|
55
56
|
if (!verify) {
|
|
@@ -42,6 +42,35 @@ describe('Document', () => {
|
|
|
42
42
|
expect(document.dataContractId.base58()).toEqual(dataContract);
|
|
43
43
|
expect(document).toEqual(expect.any(DocumentWASM));
|
|
44
44
|
});
|
|
45
|
+
test('should be able to get document with startAt', async () => {
|
|
46
|
+
const dataContract = '6hVQW16jyvZyGSQk2YVty4ND6bgFXozizYWnPt753uW5';
|
|
47
|
+
const documentType = 'torrent';
|
|
48
|
+
const limit = 5;
|
|
49
|
+
// @ts-expect-error
|
|
50
|
+
const [firstQueriedDoc] = (await sdk.documents.query(dataContract, documentType, null, null, limit)).toReversed();
|
|
51
|
+
// @ts-expect-error
|
|
52
|
+
const [secondQueriedDoc] = await sdk.documents.query(dataContract, documentType, null, null, limit, firstQueriedDoc.id);
|
|
53
|
+
expect(secondQueriedDoc.id.base58()).toEqual(firstQueriedDoc.id.base58());
|
|
54
|
+
expect(secondQueriedDoc.createdAtBlockHeight).toEqual(undefined);
|
|
55
|
+
expect(secondQueriedDoc.dataContractId.base58()).toEqual(dataContract);
|
|
56
|
+
expect(secondQueriedDoc).toEqual(expect.any(DocumentWASM));
|
|
57
|
+
});
|
|
58
|
+
test('should be able to get document with startAfter', async () => {
|
|
59
|
+
const dataContract = '6hVQW16jyvZyGSQk2YVty4ND6bgFXozizYWnPt753uW5';
|
|
60
|
+
const documentType = 'torrent';
|
|
61
|
+
const limit = 5;
|
|
62
|
+
const masterQueryLimit = limit * 2;
|
|
63
|
+
// @ts-expect-error
|
|
64
|
+
const masterQuery = await sdk.documents.query(dataContract, documentType, null, null, masterQueryLimit);
|
|
65
|
+
// @ts-expect-error
|
|
66
|
+
const [firstQueriedDoc] = (await sdk.documents.query(dataContract, documentType, null, null, limit)).toReversed();
|
|
67
|
+
// @ts-expect-error
|
|
68
|
+
const [secondQueriedDoc] = await sdk.documents.query(dataContract, documentType, null, null, limit, undefined, firstQueriedDoc.id);
|
|
69
|
+
expect(masterQuery[5].id.base58()).toEqual(secondQueriedDoc.id.base58());
|
|
70
|
+
expect(secondQueriedDoc.createdAtBlockHeight).toEqual(undefined);
|
|
71
|
+
expect(secondQueriedDoc.dataContractId.base58()).toEqual(dataContract);
|
|
72
|
+
expect(secondQueriedDoc).toEqual(expect.any(DocumentWASM));
|
|
73
|
+
});
|
|
45
74
|
describe('should be able to create state transition', () => {
|
|
46
75
|
test('should be able to create a create transition', async () => {
|
|
47
76
|
const document = sdk.documents.create(dataContract, documentType, data, identity);
|