dash-platform-sdk 1.5.3 → 1.6.0-dev.2
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/README.md +15 -15
- package/bundle.min.js +1 -1
- package/package.json +3 -4
- package/proto/generated/platform.client.d.ts +20 -60
- package/proto/generated/platform.client.js +41 -69
- package/proto/generated/platform.d.ts +2330 -1650
- package/proto/generated/platform.js +4992 -3467
- package/src/constants.d.ts +1 -1
- package/src/constants.js +1 -1
- package/src/documents/create.d.ts +1 -1
- package/src/documents/create.js +2 -2
- package/src/documents/createStateTransition.d.ts +2 -2
- package/src/documents/createStateTransition.js +6 -6
- package/src/documents/getActionFeeAgreement.d.ts +4 -0
- package/src/documents/getActionFeeAgreement.js +21 -0
- package/src/documents/index.d.ts +99 -4
- package/src/documents/index.js +117 -3
- package/src/documents/query.js +13 -52
- package/src/documents/queryAggregate.d.ts +4 -0
- package/src/documents/queryAggregate.js +32 -0
- package/src/documents/queryJoined.d.ts +16 -0
- package/src/documents/queryJoined.js +44 -0
- package/src/documents/queryRanked.d.ts +12 -0
- package/src/documents/queryRanked.js +37 -0
- package/src/documents/v1.d.ts +33 -0
- package/src/documents/v1.js +233 -0
- package/src/identities/getIdentityByNonUniquePublicKeyHash.js +6 -10
- package/src/names/index.d.ts +4 -1
- package/src/names/index.js +5 -2
- package/src/names/registerName.d.ts +1 -1
- package/src/names/registerName.js +55 -35
- package/src/shielded/getMostRecentShieldedAnchor.d.ts +2 -1
- package/src/shielded/getMostRecentShieldedAnchor.js +6 -4
- package/src/shielded/getShieldedAnchors.d.ts +2 -1
- package/src/shielded/getShieldedAnchors.js +6 -4
- package/src/shielded/getShieldedEncryptedNotes.d.ts +2 -1
- package/src/shielded/getShieldedEncryptedNotes.js +6 -4
- package/src/shielded/getShieldedNotesCount.d.ts +2 -1
- package/src/shielded/getShieldedNotesCount.js +6 -4
- package/src/shielded/getShieldedNullifiers.d.ts +2 -1
- package/src/shielded/getShieldedNullifiers.js +6 -4
- package/src/shielded/getShieldedPoolState.d.ts +2 -1
- package/src/shielded/getShieldedPoolState.js +6 -4
- package/src/shielded/index.d.ts +17 -7
- package/src/shielded/index.js +22 -12
- package/src/stateTransitions/index.d.ts +6 -2
- package/src/stateTransitions/index.js +5 -1
- package/src/stateTransitions/waitForStateTransitionResult.d.ts +1 -1
- package/src/stateTransitions/waitForStateTransitionResult.js +4 -2
- package/test/unit/DataContract.spec.js +2 -1
- package/test/unit/Document.spec.js +9 -9
- package/test/unit/DocumentActionFees.spec.d.ts +1 -0
- package/test/unit/DocumentActionFees.spec.js +99 -0
- package/test/unit/DocumentQueries.spec.d.ts +1 -0
- package/test/unit/DocumentQueries.spec.js +178 -0
- package/test/unit/DocumentsV1.spec.d.ts +1 -0
- package/test/unit/DocumentsV1.spec.js +75 -0
- package/test/unit/Names.spec.js +30 -0
- package/test/unit/Node.spec.js +11 -8
- package/types.d.ts +20 -1
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { DocumentWASM, IdentifierWASM } from 'pshenmic-dpp';
|
|
2
|
+
import { DashPlatformSDK } from '../../src/DashPlatformSDK.js';
|
|
3
|
+
const DOCUMENT_HISTORY = '6voHRaoiPcfmMhbqCA9dixH98xcgPQ9UEcuaXjpVu3LD';
|
|
4
|
+
const DPNS = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec';
|
|
5
|
+
function decodeTimestampKey(key) {
|
|
6
|
+
return new DataView(key.buffer, key.byteOffset, key.byteLength).getBigUint64(0) ^ (1n << 63n);
|
|
7
|
+
}
|
|
8
|
+
let sdk;
|
|
9
|
+
describe('Document queries', () => {
|
|
10
|
+
beforeAll(async () => {
|
|
11
|
+
sdk = new DashPlatformSDK({ network: 'testnet' });
|
|
12
|
+
});
|
|
13
|
+
describe('where operators', () => {
|
|
14
|
+
test('should be able to query with `in`', async () => {
|
|
15
|
+
const documents = await sdk.documents.query(DPNS, 'domain', [['normalizedParentDomainName', '==', 'dash'], ['normalizedLabel', 'in', ['dash', 'pshenmic']]], [['normalizedLabel', 'asc']], 5);
|
|
16
|
+
expect(documents.length).toBeGreaterThan(0);
|
|
17
|
+
expect(documents[0]).toEqual(expect.any(DocumentWASM));
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
describe('count', () => {
|
|
21
|
+
test('should be able to count all documents of a type', async () => {
|
|
22
|
+
// without a where clause the count comes from the document type's primary key tree
|
|
23
|
+
const { mode, entries: [total] } = await sdk.documents.count(DOCUMENT_HISTORY, { documentTypeName: 'transfer' });
|
|
24
|
+
expect(mode).toEqual('primaryKeyTree');
|
|
25
|
+
expect(total.count).toEqual(expect.any(BigInt));
|
|
26
|
+
expect(total.key).toEqual(new Uint8Array());
|
|
27
|
+
});
|
|
28
|
+
test('should be able to count documents matching an equality', async () => {
|
|
29
|
+
// how many DPNS names were ever transferred
|
|
30
|
+
const { entries: [total] } = await sdk.documents.count(DOCUMENT_HISTORY, {
|
|
31
|
+
documentTypeName: 'transfer',
|
|
32
|
+
where: [['dataContractId', '==', DPNS]]
|
|
33
|
+
});
|
|
34
|
+
expect(total.count).toEqual(expect.any(BigInt));
|
|
35
|
+
});
|
|
36
|
+
test('should be able to count documents in a range', async () => {
|
|
37
|
+
// DPNS names transferred in the last 30 days: a range on the last property of a `rangeCountable` index
|
|
38
|
+
const monthAgo = Date.now() - 30 * 24 * 60 * 60 * 1000;
|
|
39
|
+
const { mode, entries: [total] } = await sdk.documents.count(DOCUMENT_HISTORY, {
|
|
40
|
+
documentTypeName: 'transfer',
|
|
41
|
+
where: [['dataContractId', '==', DPNS], ['$createdAt', '>', monthAgo]]
|
|
42
|
+
});
|
|
43
|
+
expect(mode).toEqual('aggregate');
|
|
44
|
+
expect(total.count).toEqual(expect.any(BigInt));
|
|
45
|
+
});
|
|
46
|
+
test('should be able to count grouped by an `in` clause', async () => {
|
|
47
|
+
// one entry per contract of the `in` list that has transfers, the contract id is the entry key
|
|
48
|
+
const { entries } = await sdk.documents.count(DOCUMENT_HISTORY, {
|
|
49
|
+
documentTypeName: 'transfer',
|
|
50
|
+
where: [['dataContractId', 'in', [DPNS, DOCUMENT_HISTORY]]],
|
|
51
|
+
groupBy: ['dataContractId']
|
|
52
|
+
});
|
|
53
|
+
const [dpns] = entries;
|
|
54
|
+
expect(new IdentifierWASM(dpns.key).base58()).toEqual(DPNS);
|
|
55
|
+
expect(dpns.count).toEqual(expect.any(BigInt));
|
|
56
|
+
});
|
|
57
|
+
test('should be able to count grouped by a range', async () => {
|
|
58
|
+
// one entry per distinct `$createdAt`, `limit` caps the amount of groups
|
|
59
|
+
const { mode, entries } = await sdk.documents.count(DOCUMENT_HISTORY, {
|
|
60
|
+
documentTypeName: 'transfer',
|
|
61
|
+
where: [['dataContractId', '==', DPNS], ['$createdAt', '>', 0]],
|
|
62
|
+
groupBy: ['$createdAt'],
|
|
63
|
+
limit: 3
|
|
64
|
+
});
|
|
65
|
+
expect(mode).toEqual('distinct');
|
|
66
|
+
expect(entries.length).toBeLessThanOrEqual(3);
|
|
67
|
+
expect(decodeTimestampKey(entries[0].key)).toBeGreaterThan(0n);
|
|
68
|
+
expect(entries[0].count).toEqual(expect.any(BigInt));
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
describe('sum and average', () => {
|
|
72
|
+
test('should be able to sum a field', async () => {
|
|
73
|
+
// total credits asked for DPNS names in all price updates
|
|
74
|
+
const { entries: [total] } = await sdk.documents.sum(DOCUMENT_HISTORY, {
|
|
75
|
+
documentTypeName: 'priceUpdate',
|
|
76
|
+
where: [['dataContractId', '==', DPNS], ['$createdAt', '>', 0]]
|
|
77
|
+
}, 'price');
|
|
78
|
+
expect(total.sum).toEqual(expect.any(BigInt));
|
|
79
|
+
});
|
|
80
|
+
test('should be able to average a field', async () => {
|
|
81
|
+
// the proof carries the count and the sum, the average is computed by the caller
|
|
82
|
+
const { entries: [total] } = await sdk.documents.average(DOCUMENT_HISTORY, {
|
|
83
|
+
documentTypeName: 'purchase',
|
|
84
|
+
where: [['dataContractId', '==', DPNS], ['$createdAt', '>', 0]]
|
|
85
|
+
}, 'price');
|
|
86
|
+
const { count, sum } = total;
|
|
87
|
+
expect(count).toBeGreaterThan(0n);
|
|
88
|
+
expect(sum / count).toEqual(expect.any(BigInt));
|
|
89
|
+
});
|
|
90
|
+
test('should be able to average grouped by an `in` clause', async () => {
|
|
91
|
+
// the `in` value of each group is returned in `inKey`
|
|
92
|
+
const { entries } = await sdk.documents.average(DOCUMENT_HISTORY, {
|
|
93
|
+
documentTypeName: 'priceUpdate',
|
|
94
|
+
where: [['dataContractId', 'in', [DPNS, DOCUMENT_HISTORY]], ['$createdAt', '>', 0]],
|
|
95
|
+
groupBy: ['dataContractId']
|
|
96
|
+
}, 'price');
|
|
97
|
+
const [dpns] = entries;
|
|
98
|
+
expect(new IdentifierWASM(dpns.inKey).base58()).toEqual(DPNS);
|
|
99
|
+
expect(dpns.count).toEqual(expect.any(BigInt));
|
|
100
|
+
expect(dpns.sum).toEqual(expect.any(BigInt));
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
describe('composite', () => {
|
|
104
|
+
test('should be able to query a page with a bound sub-query', async () => {
|
|
105
|
+
// page: three DPNS name transfers. Sub-query: purchases of the same names, the page's
|
|
106
|
+
// `documentId` values become an `in` clause on the sub-query's `documentId`
|
|
107
|
+
const { pageDocuments, subResults: [purchases] } = await sdk.documents.composite(DOCUMENT_HISTORY, {
|
|
108
|
+
documentTypeName: 'transfer',
|
|
109
|
+
where: [['dataContractId', '==', DPNS]],
|
|
110
|
+
orderBy: [['$createdAt', 'asc']],
|
|
111
|
+
limit: 3
|
|
112
|
+
}, [{
|
|
113
|
+
documentTypeName: 'purchase',
|
|
114
|
+
where: [['dataContractId', '==', DPNS]],
|
|
115
|
+
// a sub-query on a non-unique index needs a limit per bound value
|
|
116
|
+
limit: 2,
|
|
117
|
+
binding: { source: 'page', sourceProperty: 'documentId', field: 'documentId' }
|
|
118
|
+
}]);
|
|
119
|
+
expect(pageDocuments.length).toEqual(3);
|
|
120
|
+
expect(pageDocuments[0]).toEqual(expect.any(DocumentWASM));
|
|
121
|
+
expect(Array.isArray(purchases.documents)).toEqual(true);
|
|
122
|
+
expect(Array.isArray(purchases.missingIds)).toEqual(true);
|
|
123
|
+
});
|
|
124
|
+
test('should be able to bind a sub-query of another contract', async () => {
|
|
125
|
+
// page: DPNS domains. Sub-query: their transfers in `document-history`, a contract
|
|
126
|
+
// other than the page's one is passed as `dataContract`
|
|
127
|
+
const history = await sdk.dataContracts.getDataContractByIdentifier(DOCUMENT_HISTORY);
|
|
128
|
+
const { pageDocuments, subResults: [transfers] } = await sdk.documents.composite(DPNS, {
|
|
129
|
+
documentTypeName: 'domain',
|
|
130
|
+
where: [['normalizedParentDomainName', '==', 'dash']],
|
|
131
|
+
orderBy: [['normalizedLabel', 'asc']],
|
|
132
|
+
limit: 3
|
|
133
|
+
}, [{
|
|
134
|
+
dataContract: history,
|
|
135
|
+
documentTypeName: 'transfer',
|
|
136
|
+
where: [['dataContractId', '==', DPNS]],
|
|
137
|
+
limit: 2,
|
|
138
|
+
binding: { source: 'page', sourceProperty: '$id', field: 'documentId' }
|
|
139
|
+
}]);
|
|
140
|
+
expect(pageDocuments.length).toEqual(3);
|
|
141
|
+
expect(Array.isArray(transfers.documents)).toEqual(true);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
/**
|
|
145
|
+
* No contract on testnet declares the indexes these queries need yet, so the examples below
|
|
146
|
+
* show the call and check that the node accepts the request shape and only refuses the missing index
|
|
147
|
+
*/
|
|
148
|
+
describe('ranked, having and chained', () => {
|
|
149
|
+
test('ranked: top groups by count', async () => {
|
|
150
|
+
// needs a single-property index on the `groupBy` field
|
|
151
|
+
await expect(sdk.documents.ranked(DOCUMENT_HISTORY, {
|
|
152
|
+
documentTypeName: 'transfer',
|
|
153
|
+
select: { function: 'count' },
|
|
154
|
+
groupBy: ['dataContractId'],
|
|
155
|
+
where: [['dataContractId', 'in', [DPNS, DOCUMENT_HISTORY]]],
|
|
156
|
+
// order by `$count` for count, by the aggregated field for sum and avg
|
|
157
|
+
orderBy: [['$count', 'desc']],
|
|
158
|
+
limit: 2,
|
|
159
|
+
offset: 0
|
|
160
|
+
})).rejects.toThrow(/ranked%20index|ranked index/);
|
|
161
|
+
});
|
|
162
|
+
test('having: groups whose aggregate is within bounds', async () => {
|
|
163
|
+
// needs the same index as ranked, `limit` is required (1 ..= 100)
|
|
164
|
+
await expect(sdk.documents.having(DOCUMENT_HISTORY, {
|
|
165
|
+
documentTypeName: 'transfer',
|
|
166
|
+
select: { function: 'count' },
|
|
167
|
+
groupBy: ['dataContractId'],
|
|
168
|
+
where: [['dataContractId', 'in', [DPNS, DOCUMENT_HISTORY]]],
|
|
169
|
+
having: [{ function: 'count', operator: '>=', value: 10 }],
|
|
170
|
+
limit: 10
|
|
171
|
+
})).rejects.toThrow(/ranked%20index|ranked index/);
|
|
172
|
+
});
|
|
173
|
+
test('chained: documents and the documents they refer to', async () => {
|
|
174
|
+
// the inner document type must be `indexOnly`
|
|
175
|
+
await expect(sdk.documents.chained(DPNS, { documentTypeName: 'domain', where: [['normalizedParentDomainName', '==', 'dash']], limit: 2 }, 'records.identity', 'domain')).rejects.toThrow(/indexOnly/);
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { IdentifierWASM } from 'pshenmic-dpp';
|
|
2
|
+
import { GetDocumentsRequest_GetDocumentsRequestV1_Select_Function, GetDocumentsRequest_GetDocumentsRequestV1_SubQuery_Kind, GetDocumentsRequest_HavingClause_Operator, GetDocumentsRequest_TimeRangeSelection_Selector, GetDocumentsRequest_WhereOperator } from '../../proto/generated/platform.js';
|
|
3
|
+
import { toFieldValue, toHavingClauses, toOrderClauses, toSelect, toStart, toSubQueries, toWhereClauses } from '../../src/documents/v1.js';
|
|
4
|
+
describe('Documents V1 request conversion', () => {
|
|
5
|
+
test('should convert field values', () => {
|
|
6
|
+
expect(toFieldValue(true).variant).toEqual({ oneofKind: 'boolValue', boolValue: true });
|
|
7
|
+
expect(toFieldValue(5).variant).toEqual({ oneofKind: 'uint64Value', uint64Value: '5' });
|
|
8
|
+
expect(toFieldValue(-5n).variant).toEqual({ oneofKind: 'int64Value', int64Value: '-5' });
|
|
9
|
+
expect(toFieldValue(1.5).variant).toEqual({ oneofKind: 'doubleValue', doubleValue: 1.5 });
|
|
10
|
+
expect(toFieldValue('dash').variant).toEqual({ oneofKind: 'text', text: 'dash' });
|
|
11
|
+
expect(toFieldValue(new Uint8Array([1])).variant).toEqual({ oneofKind: 'bytesValue', bytesValue: new Uint8Array([1]) });
|
|
12
|
+
expect(toFieldValue(null).variant).toEqual({ oneofKind: 'nullValue', nullValue: true });
|
|
13
|
+
expect(toFieldValue(['a', 1]).variant).toEqual({
|
|
14
|
+
oneofKind: 'list',
|
|
15
|
+
list: { values: [toFieldValue('a'), toFieldValue(1)] }
|
|
16
|
+
});
|
|
17
|
+
expect(() => toFieldValue({})).toThrow();
|
|
18
|
+
});
|
|
19
|
+
test('should convert where clauses', () => {
|
|
20
|
+
const [equal, startsWith, containsAny] = toWhereClauses([
|
|
21
|
+
['normalizedParentDomainName', '==', 'dash'],
|
|
22
|
+
['normalizedLabel', 'startsWith', 'a'],
|
|
23
|
+
['tags', 'contains_any', ['x', 'y']]
|
|
24
|
+
]);
|
|
25
|
+
expect(equal).toEqual({ field: 'normalizedParentDomainName', operator: GetDocumentsRequest_WhereOperator.EQUAL, value: toFieldValue('dash') });
|
|
26
|
+
expect(startsWith.operator).toEqual(GetDocumentsRequest_WhereOperator.STARTS_WITH);
|
|
27
|
+
expect(containsAny.operator).toEqual(GetDocumentsRequest_WhereOperator.CONTAINS_ANY);
|
|
28
|
+
expect(toWhereClauses(undefined)).toEqual([]);
|
|
29
|
+
// @ts-expect-error
|
|
30
|
+
expect(() => toWhereClauses([['a', 'like', 'b']])).toThrow();
|
|
31
|
+
});
|
|
32
|
+
test('should convert time and integer range where clauses', () => {
|
|
33
|
+
const [newest, byStart, grid, integer] = toWhereClauses([
|
|
34
|
+
['$createdAt', 'inTimeRange', 'newest'],
|
|
35
|
+
['$createdAt', 'IN_TIME_RANGE', 1700000000000n],
|
|
36
|
+
['$createdAt', 'in_time_range', { selector: 'oldest', grid: { rangeSeconds: 3600, stepSeconds: 60 } }],
|
|
37
|
+
['height', 'inIntegerRange', { start: 100, grid: { range: 10, step: 10 } }]
|
|
38
|
+
]);
|
|
39
|
+
expect(newest.operator).toEqual(GetDocumentsRequest_WhereOperator.IN_TIME_RANGE);
|
|
40
|
+
expect(newest.value).toEqual(undefined);
|
|
41
|
+
expect(newest.timeRange?.selector).toEqual(GetDocumentsRequest_TimeRangeSelection_Selector.NEWEST);
|
|
42
|
+
expect(byStart.timeRange).toEqual(expect.objectContaining({ selector: GetDocumentsRequest_TimeRangeSelection_Selector.BY_START, startMs: '1700000000000' }));
|
|
43
|
+
expect(grid.timeRange?.grid).toEqual({ range: '3600', step: '60', phase: '0' });
|
|
44
|
+
expect(integer.operator).toEqual(GetDocumentsRequest_WhereOperator.IN_INTEGER_RANGE);
|
|
45
|
+
expect(integer.integerRange).toEqual({ start: toFieldValue(100), grid: { range: '10', step: '10', phase: '0' } });
|
|
46
|
+
});
|
|
47
|
+
test('should convert order, select and having clauses', () => {
|
|
48
|
+
expect(toOrderClauses([['$count', 'desc'], ['name', 'asc']])).toEqual([
|
|
49
|
+
{ target: { oneofKind: 'field', field: '$count' }, ascending: false },
|
|
50
|
+
{ target: { oneofKind: 'field', field: 'name' }, ascending: true }
|
|
51
|
+
]);
|
|
52
|
+
expect(toSelect({ function: 'sum', field: 'amount' })).toEqual([
|
|
53
|
+
{ function: GetDocumentsRequest_GetDocumentsRequestV1_Select_Function.SUM, field: 'amount' }
|
|
54
|
+
]);
|
|
55
|
+
expect(toSelect({ function: 'count' })[0].field).toEqual('');
|
|
56
|
+
const [having] = toHavingClauses([{ function: 'count', operator: '>=', value: 10 }]);
|
|
57
|
+
expect(having.operator).toEqual(GetDocumentsRequest_HavingClause_Operator.GREATER_THAN_OR_EQUALS);
|
|
58
|
+
expect(having.right).toEqual({ oneofKind: 'value', value: toFieldValue(10) });
|
|
59
|
+
});
|
|
60
|
+
test('should convert start and sub-queries', () => {
|
|
61
|
+
const id = new IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec');
|
|
62
|
+
expect(toStart(undefined)).toEqual({ oneofKind: undefined });
|
|
63
|
+
expect(toStart(id, true)).toEqual({ oneofKind: 'startAt', startAt: id.bytes() });
|
|
64
|
+
expect(toStart(id, false)).toEqual({ oneofKind: 'startAfter', startAfter: id.bytes() });
|
|
65
|
+
const [fromPage, fromSubQuery] = toSubQueries([
|
|
66
|
+
{ documentTypeName: 'domain', binding: { source: 'page', sourceProperty: '$ownerId', field: '$ownerId' } },
|
|
67
|
+
{ documentTypeName: 'preorder', kind: 'count', binding: { source: 0, sourceProperty: '$id', field: '$id' } }
|
|
68
|
+
], id);
|
|
69
|
+
expect(fromPage.dataContractId).toEqual(id.bytes());
|
|
70
|
+
expect(fromPage.kind).toEqual(GetDocumentsRequest_GetDocumentsRequestV1_SubQuery_Kind.DOCUMENTS);
|
|
71
|
+
expect(fromPage.bind?.source).toEqual(0);
|
|
72
|
+
expect(fromSubQuery.kind).toEqual(GetDocumentsRequest_GetDocumentsRequestV1_SubQuery_Kind.COUNT);
|
|
73
|
+
expect(fromSubQuery.bind?.source).toEqual(1);
|
|
74
|
+
});
|
|
75
|
+
});
|
package/test/unit/Names.spec.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import broadcast from '../../src/stateTransitions/broadcast.js';
|
|
2
|
+
import waitForStateTransitionResult from '../../src/stateTransitions/waitForStateTransitionResult.js';
|
|
2
3
|
import { DocumentWASM, PrivateKeyWASM } from 'pshenmic-dpp';
|
|
3
4
|
import { DashPlatformSDK } from '../../src/DashPlatformSDK.js';
|
|
4
5
|
import sleep from '../../src/utils/sleep.js';
|
|
@@ -32,4 +33,33 @@ describe('DPNS names', () => {
|
|
|
32
33
|
await sdk.names.registerName(fullName, identityId, privateKey);
|
|
33
34
|
expect(broadcast).toHaveBeenCalledTimes(2);
|
|
34
35
|
});
|
|
36
|
+
test('should be able to register a name with existing preorder salt', async () => {
|
|
37
|
+
const fullName = 'test-identity-050.dash';
|
|
38
|
+
const identityId = 'CKKYnVeKoxCbvuEhiT6MDoQaRyXgDECwtxoKL5cqucZE';
|
|
39
|
+
const privateKey = PrivateKeyWASM.fromWIF('XERm528aQWJ3hzEcb79KMQKewbSSJQtni3fWHbu75wDxg6xg6AA3');
|
|
40
|
+
const preorderSalt = new Uint8Array(32).fill(1);
|
|
41
|
+
jest.mocked(broadcast).mockClear();
|
|
42
|
+
const salt = await sdk.names.registerName(fullName, identityId, privateKey, preorderSalt);
|
|
43
|
+
expect(salt).toEqual(preorderSalt);
|
|
44
|
+
expect(broadcast).toHaveBeenCalledTimes(1);
|
|
45
|
+
});
|
|
46
|
+
test('should expose preorder salt in error if preorder confirmation fails', async () => {
|
|
47
|
+
const fullName = 'test-identity-050.dash';
|
|
48
|
+
const identityId = 'CKKYnVeKoxCbvuEhiT6MDoQaRyXgDECwtxoKL5cqucZE';
|
|
49
|
+
const privateKey = PrivateKeyWASM.fromWIF('XERm528aQWJ3hzEcb79KMQKewbSSJQtni3fWHbu75wDxg6xg6AA3');
|
|
50
|
+
jest.mocked(waitForStateTransitionResult).mockRejectedValueOnce(new Error('Timeout'));
|
|
51
|
+
const error = await sdk.names.registerName(fullName, identityId, privateKey).catch(e => e);
|
|
52
|
+
expect(error.message).toEqual('Timeout');
|
|
53
|
+
expect(error.preorderSalt).toBeInstanceOf(Uint8Array);
|
|
54
|
+
expect(error.preorderSalt.length).toEqual(32);
|
|
55
|
+
});
|
|
56
|
+
test('should not expose preorder salt in error if preorder broadcast is refused', async () => {
|
|
57
|
+
const fullName = 'test-identity-050.dash';
|
|
58
|
+
const identityId = 'CKKYnVeKoxCbvuEhiT6MDoQaRyXgDECwtxoKL5cqucZE';
|
|
59
|
+
const privateKey = PrivateKeyWASM.fromWIF('XERm528aQWJ3hzEcb79KMQKewbSSJQtni3fWHbu75wDxg6xg6AA3');
|
|
60
|
+
jest.mocked(broadcast).mockRejectedValueOnce(new Error('Refused'));
|
|
61
|
+
const error = await sdk.names.registerName(fullName, identityId, privateKey).catch(e => e);
|
|
62
|
+
expect(error.message).toEqual('Refused');
|
|
63
|
+
expect(error.preorderSalt).toBeUndefined();
|
|
64
|
+
});
|
|
35
65
|
});
|
package/test/unit/Node.spec.js
CHANGED
|
@@ -26,14 +26,17 @@ describe('Node', () => {
|
|
|
26
26
|
expect(status.network?.chainId).toEqual(expect.any(String));
|
|
27
27
|
expect(status.network?.peersCount).toEqual(expect.any(Number));
|
|
28
28
|
expect(status.network?.listening).toEqual(expect.any(Boolean));
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
// rs-dapi (v5) returns state sync info only if tenderdash reports non-zero state sync counters
|
|
30
|
+
if (status.stateSync != null) {
|
|
31
|
+
expect(status.stateSync.totalSyncedTime).toEqual(expect.any(String));
|
|
32
|
+
expect(status.stateSync.remainingTime).toEqual(expect.any(String));
|
|
33
|
+
expect(status.stateSync.totalSnapshots).toEqual(expect.any(Number));
|
|
34
|
+
expect(status.stateSync.chunkProcessAvgTime).toEqual(expect.any(String));
|
|
35
|
+
expect(status.stateSync.snapshotHeight).toEqual(expect.any(String));
|
|
36
|
+
expect(status.stateSync.snapshotChunksCount).toEqual(expect.any(String));
|
|
37
|
+
expect(status.stateSync.backfilledBlocks).toEqual(expect.any(String));
|
|
38
|
+
expect(status.stateSync.backfillBlocksTotal).toEqual(expect.any(String));
|
|
39
|
+
}
|
|
37
40
|
expect(status.time?.local).toEqual(expect.any(String));
|
|
38
41
|
expect(status.time?.block).toEqual(expect.any(String));
|
|
39
42
|
expect(status.time?.genesis).toEqual(expect.any(String));
|
package/types.d.ts
CHANGED
|
@@ -1,9 +1,27 @@
|
|
|
1
|
-
import { AddressFundsFeeStrategyStepWASM, AssetLockProofWASM, CoreScriptWASM, DocumentWASM, GasFeesPaidByWASM, IdentifierLike, IdentifierWASM, InputAddressWASM, KeyType, OrchardAddressWASM, PlatformAddressLike, PlatformAddressWASM, PlatformVersionWASM, PoolingLike, PrivateKeyWASM, Purpose, SecurityLevel, ShieldedOutputWASM, SpendableNoteWASM, TokenEmergencyActionWASM, TokenPricingScheduleWASM, AddressWitnessWASM, IdentityPublicKeyInCreationWASM, OutputAddressWASM, OutputAddressNullableCreditsWASM, VerifiedAddressesTrunkState } from 'pshenmic-dpp';
|
|
1
|
+
import { AddressFundsFeeStrategyStepWASM, AssetLockProofWASM, CoreScriptWASM, DocumentActionFeeAgreementWASM, DocumentWASM, GasFeesPaidByWASM, IdentifierLike, IdentifierWASM, InputAddressWASM, KeyType, OrchardAddressWASM, PlatformAddressLike, PlatformAddressWASM, PlatformVersionWASM, PoolingLike, PrivateKeyWASM, Purpose, SecurityLevel, ShieldedOutputWASM, SpendableNoteWASM, TokenEmergencyActionWASM, TokenPricingScheduleWASM, AddressWitnessWASM, IdentityPublicKeyInCreationWASM, OutputAddressWASM, OutputAddressNullableCreditsWASM, VerifiedAddressesTrunkState } from 'pshenmic-dpp';
|
|
2
2
|
import { ResponseMetadata } from './proto/generated/platform.js';
|
|
3
3
|
export { CoreScriptWASM, DocumentWASM, GasFeesPaidByWASM, IdentifierWASM, KeyType, Purpose, SecurityLevel, TokenEmergencyActionWASM, TokenPricingScheduleWASM, StateTransitionWASM, BatchTransitionWASM, IdentityPublicKeyWASM, PrivateKeyWASM, DataContractUpdateTransitionWASM, IdentityWASM, IdentityUpdateTransitionWASM, IdentityCreditTransferWASM, MasternodeVoteTransitionWASM, IdentifierLike, PlatformAddressLike, InputAddressWASM, OutputAddressWASM, OutputAddressNullableCreditsWASM, AddressFundsFeeStrategyStepWASM, AddressWitnessWASM, IdentityPublicKeyInCreationWASM, AssetLockProofWASM, IdentityCreditTransferToAddressesTransitionWASM, IdentityCreateFromAddressesTransitionWASM, IdentityTopUpFromAddressesTransitionWASM, AddressFundsTransferTransitionWASM, AddressFundingFromAssetLockTransitionWASM, AddressCreditWithdrawalTransitionWASM } from 'pshenmic-dpp';
|
|
4
4
|
export type Network = 'mainnet' | 'testnet';
|
|
5
5
|
export { DashPlatformSDK } from './src/DashPlatformSDK.js';
|
|
6
6
|
export type MasternodeList = Record<string, MasternodeInfo>;
|
|
7
|
+
export type DocumentTransitionType = 'create' | 'replace' | 'delete' | 'updatePrice' | 'transfer' | 'purchase';
|
|
8
|
+
/**
|
|
9
|
+
* The action fee a document transition agrees to pay to the contract fee pots (protocol v14).
|
|
10
|
+
* Required when the document type declares `actionFees` for the action, ignored otherwise
|
|
11
|
+
*/
|
|
12
|
+
export interface DocumentActionFeeAgreement {
|
|
13
|
+
/** owner part the document type declares for the action, in credits */
|
|
14
|
+
owner: bigint;
|
|
15
|
+
/** moderators part the document type declares for the action, in credits */
|
|
16
|
+
moderators: bigint;
|
|
17
|
+
/** set when the fee is priced by the epoch fee multiplier, omit for a fixed fee */
|
|
18
|
+
feeMultiplier?: {
|
|
19
|
+
/** fee multiplier of the current epoch, in permille */
|
|
20
|
+
knownPermille: bigint;
|
|
21
|
+
/** how far above the known multiplier the executing epoch's one may be, in percent */
|
|
22
|
+
increaseTolerancePercent: number;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
7
25
|
export interface DocumentTransitionParams {
|
|
8
26
|
identityContractNonce: bigint;
|
|
9
27
|
amount?: bigint;
|
|
@@ -20,6 +38,7 @@ export interface DocumentTransitionParams {
|
|
|
20
38
|
maximumTokenCost?: bigint;
|
|
21
39
|
gasFeesPaidBy: GasFeesPaidByWASM;
|
|
22
40
|
};
|
|
41
|
+
actionFeeAgreement?: DocumentActionFeeAgreement | DocumentActionFeeAgreementWASM;
|
|
23
42
|
}
|
|
24
43
|
export interface ShieldedTransitionBaseParams {
|
|
25
44
|
/** version of the platform (defaults to the latest supported version) */
|