dash-platform-sdk 1.3.2-dev.3 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dash-platform-sdk",
3
- "version": "1.3.2-dev.3",
3
+ "version": "1.3.2-dev.5",
4
4
  "main": "index.js",
5
5
  "description": "Lightweight SDK for accessing Dash Platform blockchain",
6
6
  "ts-standard": {
@@ -39,7 +39,7 @@ export class DocumentsController {
39
39
  * @param startAfter {IdentifierLike=} Same as previous, but with exclusion. Cannot be set if startAt already provided
40
40
  */
41
41
  async query(dataContractId, documentType, where, orderBy, limit, startAt, startAfter) {
42
- if (startAfter != null && startAt !== null) {
42
+ if (startAfter != null && startAt != null) {
43
43
  throw new Error('You may only set either startAfter or startAt at once');
44
44
  }
45
45
  return await query(this.grpcPool, new IdentifierWASM(dataContractId), documentType, where, orderBy, limit ?? 100, startAt, startAfter);
@@ -7,20 +7,17 @@ import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
7
7
  import { encode } from 'cbor-x';
8
8
  import getDataContractByIdentifier from '../dataContracts/getDataContractByIdentifier.js';
9
9
  export default async function query(grpcPool, dataContractId, documentTypeName, where, orderBy, limit = 100, startAt, startAfter) {
10
- if ([startAt, startAfter].filter(e => e != null).length === 2) {
11
- throw new Error('Only startAt or startAfter could be specified at one time');
12
- }
13
10
  let start;
14
11
  if (startAt != null) {
15
12
  start = {
16
13
  oneofKind: 'startAt',
17
- startAt: startAt.base58()
14
+ startAt: startAt.bytes()
18
15
  };
19
16
  }
20
17
  if (startAfter != null) {
21
18
  start = {
22
19
  oneofKind: 'startAfter',
23
- startAt: startAfter.base58()
20
+ startAfter: startAfter.bytes()
24
21
  };
25
22
  }
26
23
  const getDocumentsRequest = GetDocumentsRequest.create({
@@ -52,7 +49,8 @@ export default async function query(grpcPool, dataContractId, documentTypeName,
52
49
  throw new Error('Metadata not found');
53
50
  }
54
51
  const startAtIncluded = startAt != null;
55
- const { rootHash, documents } = verifyDocumentsProof(proof.grovedbProof, dataContract, documentTypeName, where, orderBy, limit, startAt?.bytes(), startAtIncluded, BigInt(metadata?.timeMs), LATEST_PLATFORM_VERSION);
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);
56
54
  const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
57
55
  const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
58
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);