dash-platform-sdk 1.3.0-dev.4 → 1.3.0-dev.6
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 +21 -2
- package/index.js +2 -5
- package/package.json +30 -31
- package/proto/generated/google/protobuf/wrappers.d.ts +260 -29
- package/proto/generated/google/protobuf/wrappers.js +562 -345
- package/proto/generated/platform.client.d.ts +251 -0
- package/proto/generated/platform.client.js +175 -0
- package/proto/generated/platform.d.ts +3682 -1939
- package/proto/generated/platform.js +8119 -18366
- package/src/DashPlatformSDK.d.ts +5 -4
- package/src/DashPlatformSDK.js +56 -46
- package/src/constants.js +7 -10
- package/src/contestedResources/createStateTransition.d.ts +1 -2
- package/src/contestedResources/createStateTransition.js +4 -7
- package/src/contestedResources/getContestedResourceVoteState.js +67 -118
- package/src/contestedResources/index.js +9 -55
- package/src/dataContracts/create.js +5 -8
- package/src/dataContracts/createStateTransition.js +10 -14
- package/src/dataContracts/getDataContractByIdentifier.js +40 -83
- package/src/dataContracts/index.js +17 -63
- package/src/documents/create.js +3 -6
- package/src/documents/createStateTransition.js +19 -31
- package/src/documents/index.js +25 -72
- package/src/documents/query.js +58 -90
- package/src/grpcConnectionPool.d.ts +30 -8
- package/src/grpcConnectionPool.js +63 -121
- package/src/identities/createStateTransition.js +14 -26
- package/src/identities/getIdentityBalance.js +37 -80
- package/src/identities/getIdentityByIdentifier.js +37 -80
- package/src/identities/getIdentityByNonUniquePublicKeyHash.js +41 -82
- package/src/identities/getIdentityByPublicKeyHash.js +37 -80
- package/src/identities/getIdentityContractNonce.js +40 -83
- package/src/identities/getIdentityNonce.js +38 -81
- package/src/identities/getIdentityPublicKeys.js +43 -81
- package/src/identities/index.js +57 -153
- package/src/keyPair/deriveChild.d.ts +2 -2
- package/src/keyPair/deriveChild.js +2 -49
- package/src/keyPair/derivePath.d.ts +2 -2
- package/src/keyPair/derivePath.js +2 -49
- package/src/keyPair/index.d.ts +39 -114
- package/src/keyPair/index.js +62 -296
- package/src/keyPair/mnemonicToSeed.d.ts +1 -1
- package/src/keyPair/mnemonicToSeed.js +3 -46
- package/src/names/index.js +43 -111
- package/src/names/registerName.js +60 -127
- package/src/names/searchByIdentity.d.ts +1 -1
- package/src/names/searchByIdentity.js +4 -50
- package/src/names/searchByName.js +15 -63
- package/src/names/testNameContested.js +1 -4
- package/src/names/validateName.js +3 -6
- package/src/node/epochs.js +43 -85
- package/src/node/index.d.ts +3 -3
- package/src/node/index.js +18 -77
- package/src/node/status.js +37 -81
- package/src/node/totalCredits.d.ts +2 -1
- package/src/node/totalCredits.js +32 -73
- package/src/signer/AbstractSigner.js +1 -2
- package/src/signer/setSigner.js +1 -4
- package/src/stateTransitions/broadcast.js +7 -57
- package/src/stateTransitions/index.js +13 -66
- package/src/stateTransitions/waitForStateTransitionResult.js +6 -58
- package/src/tokens/createStateTransition.js +23 -35
- package/src/tokens/getIdentitiesTokenBalances.js +40 -83
- package/src/tokens/getIdentityTokensBalances.js +40 -83
- package/src/tokens/getTokenContractInfo.js +40 -83
- package/src/tokens/getTokenDirectPurchasePrices.js +37 -80
- package/src/tokens/getTokenTotalSupply.js +38 -81
- package/src/tokens/index.js +39 -124
- package/src/types.d.ts +6 -12
- package/src/types.js +6 -16
- package/src/utils/base58ToBytes.js +3 -6
- package/src/utils/bytesToHex.js +2 -5
- package/src/utils/bytesToTypedArray.d.ts +1 -0
- package/src/utils/bytesToTypedArray.js +3 -0
- package/src/utils/calculateMsgHash.d.ts +1 -1
- package/src/utils/calculateMsgHash.js +10 -13
- package/src/utils/calculateSignHash.d.ts +1 -1
- package/src/utils/calculateSignHash.js +7 -10
- package/src/utils/calculateStateIdHash.d.ts +1 -1
- package/src/utils/calculateStateIdHash.js +8 -10
- package/src/utils/convertToHomographSafeChars.js +2 -5
- package/src/utils/createVoterIdentityId.d.ts +1 -1
- package/src/utils/createVoterIdentityId.js +12 -11
- package/src/utils/getEvonodeList.d.ts +2 -2
- package/src/utils/getEvonodeList.js +10 -61
- package/src/utils/getQuorumPublicKey.js +15 -66
- package/src/utils/getRandomArrayItem.js +1 -4
- package/src/utils/getRandomBytes.js +2 -5
- package/src/utils/hexToBytes.js +2 -6
- package/src/utils/index.js +21 -28
- package/src/utils/indexBytesToString.js +2 -5
- package/src/utils/sha256.d.ts +1 -1
- package/src/utils/sha256.js +10 -8
- package/src/utils/signHash.d.ts +1 -1
- package/src/utils/signHash.js +9 -12
- package/src/utils/signRequestId.d.ts +1 -1
- package/src/utils/signRequestId.js +9 -12
- package/src/utils/sleep.js +2 -50
- package/src/utils/stringToIndexValueBytes.js +4 -7
- package/src/utils/verifyTenderdashProof.d.ts +1 -1
- package/src/utils/verifyTenderdashProof.js +13 -17
- package/src/voting/createStateTransition.d.ts +1 -2
- package/src/voting/createStateTransition.js +4 -7
- package/src/voting/createVote.js +4 -7
- package/src/voting/index.d.ts +3 -4
- package/src/voting/index.js +19 -26
- package/test/unit/ContestedResources.spec.js +92 -177
- package/test/unit/DataContract.spec.js +44 -111
- package/test/unit/Document.spec.js +93 -183
- package/test/unit/Identity.spec.js +221 -346
- package/test/unit/KeyPair.spec.js +30 -145
- package/test/unit/Names.spec.js +27 -90
- package/test/unit/Node.spec.js +55 -126
- package/test/unit/SDK.spec.js +7 -9
- package/test/unit/Tokens.spec.js +111 -278
- package/bundle.min.js.LICENSE.txt +0 -1
- package/src/keyPair/keyToPublicKey.d.ts +0 -2
- package/src/keyPair/keyToPublicKey.js +0 -47
- package/src/keyPair/keyToWalletId.d.ts +0 -2
- package/src/keyPair/keyToWalletId.js +0 -50
- package/src/keyPair/keyToXPrivateKey.d.ts +0 -3
- package/src/keyPair/keyToXPrivateKey.js +0 -50
- package/src/keyPair/keyToXPublicKey.d.ts +0 -3
- package/src/keyPair/keyToXPublicKey.js +0 -50
- package/src/keyPair/mnemonicToIdentityKey.d.ts +0 -3
- package/src/keyPair/mnemonicToIdentityKey.js +0 -57
- package/src/keyPair/mnemonicToWallet.d.ts +0 -2
- package/src/keyPair/mnemonicToWallet.js +0 -55
- package/src/keyPair/privateKeyToWif.d.ts +0 -2
- package/src/keyPair/privateKeyToWif.js +0 -50
- package/src/keyPair/publicKeyToAddress.d.ts +0 -2
- package/src/keyPair/publicKeyToAddress.js +0 -50
- package/src/keyPair/seedToWallet.d.ts +0 -2
- package/src/keyPair/seedToWallet.js +0 -50
- package/src/keyPair/walletToIdentityKey.d.ts +0 -3
- package/src/keyPair/walletToIdentityKey.js +0 -56
- package/src/keyPair/xkeyToHDXKey.d.ts +0 -2
- package/src/keyPair/xkeyToHDXKey.js +0 -50
package/src/voting/index.js
CHANGED
|
@@ -1,28 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var createVote_1 = require("./createVote");
|
|
5
|
-
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
6
|
-
var createVoterIdentityId_1 = require("../utils/createVoterIdentityId");
|
|
1
|
+
import createVote from './createVote';
|
|
2
|
+
import { IdentifierWASM, MasternodeVoteTransitionWASM, ResourceVoteChoiceWASM } from 'pshenmic-dpp';
|
|
3
|
+
import { createVoterIdentityId } from '../utils/createVoterIdentityId';
|
|
7
4
|
/**
|
|
8
5
|
* Voting controller for performing masternode votes
|
|
9
6
|
*
|
|
10
7
|
* @hideconstructor
|
|
11
8
|
*/
|
|
12
|
-
|
|
13
|
-
function VotingController() {
|
|
14
|
-
}
|
|
9
|
+
export class VotingController {
|
|
15
10
|
/**
|
|
16
11
|
* Creates an {IdentifierWASM} from masternode pro tx hash and voting address (public key hash)
|
|
17
12
|
*
|
|
18
13
|
* @param proTxHash {string} voter's masternode pro tx hash
|
|
19
14
|
* @param publicKeyHash {string} voter address's public key hash
|
|
20
15
|
*
|
|
21
|
-
* @return {IdentifierWASM}
|
|
16
|
+
* @return {Promise<IdentifierWASM>}
|
|
22
17
|
*/
|
|
23
|
-
|
|
24
|
-
return
|
|
25
|
-
}
|
|
18
|
+
async createVoterIdentityId(proTxHash, publicKeyHash) {
|
|
19
|
+
return await createVoterIdentityId(proTxHash, publicKeyHash);
|
|
20
|
+
}
|
|
26
21
|
/**
|
|
27
22
|
* Creates a {VoteWASM} with all information about the vote, such as data contract id, choice, and target index
|
|
28
23
|
*
|
|
@@ -32,19 +27,19 @@ var VotingController = /** @class */ (function () {
|
|
|
32
27
|
* @param indexValues {string[]}
|
|
33
28
|
* @param choice {ResourceVoteChoice}
|
|
34
29
|
*/
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
createVote(dataContractId, documentTypeName, indexName, indexValues, choice) {
|
|
31
|
+
let resourceVoteChoice;
|
|
37
32
|
if (choice === 'lock') {
|
|
38
|
-
resourceVoteChoice =
|
|
33
|
+
resourceVoteChoice = ResourceVoteChoiceWASM.Lock();
|
|
39
34
|
}
|
|
40
35
|
else if (choice === 'abstain') {
|
|
41
|
-
resourceVoteChoice =
|
|
36
|
+
resourceVoteChoice = ResourceVoteChoiceWASM.Abstain();
|
|
42
37
|
}
|
|
43
38
|
else {
|
|
44
|
-
resourceVoteChoice =
|
|
39
|
+
resourceVoteChoice = ResourceVoteChoiceWASM.TowardsIdentity(new IdentifierWASM(choice));
|
|
45
40
|
}
|
|
46
|
-
return (
|
|
47
|
-
}
|
|
41
|
+
return createVote(new IdentifierWASM(dataContractId), documentTypeName, indexName, indexValues, resourceVoteChoice);
|
|
42
|
+
}
|
|
48
43
|
/**
|
|
49
44
|
* Creates a {StateTransitionWASM} from masternoe protxhash and voter identity
|
|
50
45
|
*
|
|
@@ -53,10 +48,8 @@ var VotingController = /** @class */ (function () {
|
|
|
53
48
|
* @param voterIdentity {IdentifierWASM} voter identity identifier
|
|
54
49
|
* @param identityNonce {BigInt} identity nonce
|
|
55
50
|
*/
|
|
56
|
-
|
|
57
|
-
|
|
51
|
+
createStateTransition(voteWASM, proTxHash, voterIdentity, identityNonce) {
|
|
52
|
+
const transition = new MasternodeVoteTransitionWASM(IdentifierWASM.fromHex(proTxHash), new IdentifierWASM(voterIdentity), voteWASM, identityNonce);
|
|
58
53
|
return transition.toStateTransition();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
}());
|
|
62
|
-
exports.VotingController = VotingController;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -1,50 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
40
|
-
var types_1 = require("../../src/types");
|
|
41
|
-
var stringToIndexValueBytes_1 = require("../../src/utils/stringToIndexValueBytes");
|
|
42
|
-
var sdk;
|
|
43
|
-
var contract;
|
|
44
|
-
describe('Contested Resources', function () {
|
|
45
|
-
beforeAll(function () {
|
|
46
|
-
sdk = new types_1.DashPlatformSDK({ network: 'testnet' });
|
|
47
|
-
contract = new pshenmic_dpp_1.DataContractWASM('11111111111111111111111111111111', BigInt(1), {
|
|
1
|
+
import { DataContractWASM, PlatformVersionWASM, PrivateKeyWASM } from 'pshenmic-dpp';
|
|
2
|
+
import stringToIndexValueBytes from '../../src/utils/stringToIndexValueBytes';
|
|
3
|
+
import { DashPlatformSDK } from '../../src/DashPlatformSDK';
|
|
4
|
+
import { ContestedStateResultType } from '../../src/types';
|
|
5
|
+
let sdk;
|
|
6
|
+
let contract;
|
|
7
|
+
describe('Contested Resources', () => {
|
|
8
|
+
beforeAll(() => {
|
|
9
|
+
sdk = new DashPlatformSDK({ network: 'testnet' });
|
|
10
|
+
contract = new DataContractWASM('11111111111111111111111111111111', BigInt(1), {
|
|
48
11
|
domain: {
|
|
49
12
|
type: 'object',
|
|
50
13
|
indices: [
|
|
@@ -209,136 +172,88 @@ describe('Contested Resources', function () {
|
|
|
209
172
|
documentsMutable: false,
|
|
210
173
|
additionalProperties: false
|
|
211
174
|
}
|
|
212
|
-
}, undefined, undefined, true,
|
|
175
|
+
}, undefined, undefined, true, PlatformVersionWASM.PLATFORM_V9);
|
|
213
176
|
contract.id = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec';
|
|
214
177
|
});
|
|
215
|
-
test('should be able to get contested resource vote state with finishedVoteInfo',
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
choice = 'abstain';
|
|
297
|
-
privateKey = pshenmic_dpp_1.PrivateKeyWASM.fromHex('bf175afa03d3b3647e3480bb1feffb9d4a76c1e40eb2c2b0f8b5884b42dbe955', 'testnet');
|
|
298
|
-
voterIdentifier = sdk.voting.createVoterIdentityId(proTxHash, privateKey.getPublicKeyHash());
|
|
299
|
-
return [4 /*yield*/, sdk.identities.getIdentityByIdentifier(voterIdentifier)];
|
|
300
|
-
case 1:
|
|
301
|
-
voterIdentity = _a.sent();
|
|
302
|
-
identityPublicKey = voterIdentity.getPublicKeys().filter(function (identityPublicKey) { return privateKey.getPublicKeyHash() === identityPublicKey.getPublicKeyHash(); })[0];
|
|
303
|
-
return [4 /*yield*/, sdk.identities.getIdentityNonce(voterIdentity.id)];
|
|
304
|
-
case 2:
|
|
305
|
-
identityNonce = _a.sent();
|
|
306
|
-
vote = sdk.voting.createVote(dataContactId, documentTypeName, indexName, indexValues, choice);
|
|
307
|
-
stateTransition = sdk.voting.createStateTransition(vote, proTxHash, voterIdentity.id, identityNonce + BigInt(1));
|
|
308
|
-
// test key disabled
|
|
309
|
-
identityPublicKey.removeDisabledAt();
|
|
310
|
-
stateTransition.sign(privateKey, identityPublicKey);
|
|
311
|
-
return [2 /*return*/];
|
|
312
|
-
}
|
|
313
|
-
});
|
|
314
|
-
}); });
|
|
315
|
-
test('should be able to create Lock vote', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
316
|
-
var dataContactId, documentTypeName, indexName, indexValues, proTxHash, choice, privateKey, voterIdentifier, voterIdentity, identityPublicKey, identityNonce, vote, stateTransition;
|
|
317
|
-
return __generator(this, function (_a) {
|
|
318
|
-
switch (_a.label) {
|
|
319
|
-
case 0:
|
|
320
|
-
dataContactId = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec';
|
|
321
|
-
documentTypeName = 'domain';
|
|
322
|
-
indexName = 'parentNameAndLabel';
|
|
323
|
-
indexValues = ['dash', sdk.names.normalizeLabel('testidentity')];
|
|
324
|
-
proTxHash = '559db949f305ae7ca1f2c3fafbde707a5adcb9ef7d53f99df4600d72b6bab965';
|
|
325
|
-
choice = 'lock';
|
|
326
|
-
privateKey = pshenmic_dpp_1.PrivateKeyWASM.fromHex('bf175afa03d3b3647e3480bb1feffb9d4a76c1e40eb2c2b0f8b5884b42dbe955', 'testnet');
|
|
327
|
-
voterIdentifier = sdk.voting.createVoterIdentityId(proTxHash, privateKey.getPublicKeyHash());
|
|
328
|
-
return [4 /*yield*/, sdk.identities.getIdentityByIdentifier(voterIdentifier)];
|
|
329
|
-
case 1:
|
|
330
|
-
voterIdentity = _a.sent();
|
|
331
|
-
identityPublicKey = voterIdentity.getPublicKeys().filter(function (identityPublicKey) { return privateKey.getPublicKeyHash() === identityPublicKey.getPublicKeyHash(); })[0];
|
|
332
|
-
return [4 /*yield*/, sdk.identities.getIdentityNonce(voterIdentity.id)];
|
|
333
|
-
case 2:
|
|
334
|
-
identityNonce = _a.sent();
|
|
335
|
-
vote = sdk.voting.createVote(dataContactId, documentTypeName, indexName, indexValues, choice);
|
|
336
|
-
stateTransition = sdk.voting.createStateTransition(vote, proTxHash, voterIdentity.id, identityNonce + BigInt(1));
|
|
337
|
-
// test key disabled
|
|
338
|
-
identityPublicKey.removeDisabledAt();
|
|
339
|
-
stateTransition.sign(privateKey, identityPublicKey);
|
|
340
|
-
return [2 /*return*/];
|
|
341
|
-
}
|
|
342
|
-
});
|
|
343
|
-
}); });
|
|
178
|
+
test('should be able to get contested resource vote state with finishedVoteInfo', async () => {
|
|
179
|
+
const voteState = await sdk.contestedResources.getContestedResourceVoteState(contract, 'domain', 'parentNameAndLabel', [
|
|
180
|
+
'dash',
|
|
181
|
+
'asdmaye1ght'
|
|
182
|
+
].map(stringToIndexValueBytes), ContestedStateResultType.DOCUMENTS_AND_VOTE_TALLY, true);
|
|
183
|
+
expect(voteState.finishedVoteInfo).toBeTruthy();
|
|
184
|
+
expect(voteState.contenders).toBeTruthy();
|
|
185
|
+
expect(voteState.contenders.length).toBeGreaterThan(0);
|
|
186
|
+
expect(voteState.abstainVoteTally).toBeDefined();
|
|
187
|
+
expect(voteState.lockVoteTally).toBeDefined();
|
|
188
|
+
});
|
|
189
|
+
test('should be able to get contested resource vote state for incorrect values', async () => {
|
|
190
|
+
try {
|
|
191
|
+
await sdk.contestedResources.getContestedResourceVoteState(contract, 'domain', 'parentNameAndLabel', [
|
|
192
|
+
'dash',
|
|
193
|
+
'agreatma1n'
|
|
194
|
+
].map(stringToIndexValueBytes), ContestedStateResultType.DOCUMENTS_AND_VOTE_TALLY, false);
|
|
195
|
+
}
|
|
196
|
+
catch (e) {
|
|
197
|
+
expect(true).toBeTruthy();
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
expect(false).toBeTruthy();
|
|
201
|
+
});
|
|
202
|
+
test('should be able to create TowardsIdentity vote', async () => {
|
|
203
|
+
const dataContactId = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec';
|
|
204
|
+
const documentTypeName = 'domain';
|
|
205
|
+
const indexName = 'parentNameAndLabel';
|
|
206
|
+
const indexValues = ['dash', sdk.names.normalizeLabel('testidentity')];
|
|
207
|
+
const proTxHash = 'd9b090cfc19caf2e27d512e69c43812a274bdf29c081d0ade4fd272ad56a5f89';
|
|
208
|
+
const choice = 'CKKYnVeKoxCbvuEhiT6MDoQaRyXgDECwtxoKL5cqucZE';
|
|
209
|
+
const privateKey = PrivateKeyWASM.fromWIF('cPGCETHtoevguQoyTSdsowCEF91yqhrcikcvBNK2CuTwpSLV7m9Z');
|
|
210
|
+
const voterIdentifier = await sdk.voting.createVoterIdentityId(proTxHash, privateKey.getPublicKeyHash());
|
|
211
|
+
expect(voterIdentifier.base58()).toEqual('HqfLeB9PLg3t9CL25tRNkEDPjAnDaHAMmthRNe8ucn8q');
|
|
212
|
+
const voterIdentity = await sdk.identities.getIdentityByIdentifier(voterIdentifier);
|
|
213
|
+
const [identityPublicKey] = voterIdentity.getPublicKeys().filter(identityPublicKey => privateKey.getPublicKeyHash() === identityPublicKey.getPublicKeyHash());
|
|
214
|
+
const identityNonce = await sdk.identities.getIdentityNonce(voterIdentity.id);
|
|
215
|
+
const vote = sdk.voting.createVote(dataContactId, documentTypeName, indexName, indexValues, choice);
|
|
216
|
+
const stateTransition = sdk.voting.createStateTransition(vote, proTxHash, voterIdentity.id, identityNonce + BigInt(1));
|
|
217
|
+
// test key disabled
|
|
218
|
+
identityPublicKey.removeDisabledAt();
|
|
219
|
+
stateTransition.sign(privateKey, identityPublicKey);
|
|
220
|
+
});
|
|
221
|
+
test('should be able to create Abstain vote', async () => {
|
|
222
|
+
const dataContactId = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec';
|
|
223
|
+
const documentTypeName = 'domain';
|
|
224
|
+
const indexName = 'parentNameAndLabel';
|
|
225
|
+
const indexValues = ['dash', sdk.names.normalizeLabel('testidentity')];
|
|
226
|
+
const proTxHash = 'd9b090cfc19caf2e27d512e69c43812a274bdf29c081d0ade4fd272ad56a5f89';
|
|
227
|
+
const choice = 'abstain';
|
|
228
|
+
const privateKey = PrivateKeyWASM.fromWIF('cPGCETHtoevguQoyTSdsowCEF91yqhrcikcvBNK2CuTwpSLV7m9Z');
|
|
229
|
+
const voterIdentifier = await sdk.voting.createVoterIdentityId(proTxHash, privateKey.getPublicKeyHash());
|
|
230
|
+
expect(voterIdentifier.base58()).toEqual('HqfLeB9PLg3t9CL25tRNkEDPjAnDaHAMmthRNe8ucn8q');
|
|
231
|
+
const voterIdentity = await sdk.identities.getIdentityByIdentifier(voterIdentifier);
|
|
232
|
+
const [identityPublicKey] = voterIdentity.getPublicKeys().filter(identityPublicKey => privateKey.getPublicKeyHash() === identityPublicKey.getPublicKeyHash());
|
|
233
|
+
const identityNonce = await sdk.identities.getIdentityNonce(voterIdentity.id);
|
|
234
|
+
const vote = sdk.voting.createVote(dataContactId, documentTypeName, indexName, indexValues, choice);
|
|
235
|
+
const stateTransition = sdk.voting.createStateTransition(vote, proTxHash, voterIdentity.id, identityNonce + BigInt(1));
|
|
236
|
+
// test key disabled
|
|
237
|
+
identityPublicKey.removeDisabledAt();
|
|
238
|
+
stateTransition.sign(privateKey, identityPublicKey);
|
|
239
|
+
});
|
|
240
|
+
test('should be able to create Lock vote', async () => {
|
|
241
|
+
const dataContactId = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec';
|
|
242
|
+
const documentTypeName = 'domain';
|
|
243
|
+
const indexName = 'parentNameAndLabel';
|
|
244
|
+
const indexValues = ['dash', sdk.names.normalizeLabel('testidentity')];
|
|
245
|
+
const proTxHash = 'd9b090cfc19caf2e27d512e69c43812a274bdf29c081d0ade4fd272ad56a5f89';
|
|
246
|
+
const choice = 'lock';
|
|
247
|
+
const privateKey = PrivateKeyWASM.fromWIF('cPGCETHtoevguQoyTSdsowCEF91yqhrcikcvBNK2CuTwpSLV7m9Z');
|
|
248
|
+
const voterIdentifier = await sdk.voting.createVoterIdentityId(proTxHash, privateKey.getPublicKeyHash());
|
|
249
|
+
expect(voterIdentifier.base58()).toEqual('HqfLeB9PLg3t9CL25tRNkEDPjAnDaHAMmthRNe8ucn8q');
|
|
250
|
+
const voterIdentity = await sdk.identities.getIdentityByIdentifier(voterIdentifier);
|
|
251
|
+
const [identityPublicKey] = voterIdentity.getPublicKeys().filter(identityPublicKey => privateKey.getPublicKeyHash() === identityPublicKey.getPublicKeyHash());
|
|
252
|
+
const identityNonce = await sdk.identities.getIdentityNonce(voterIdentity.id);
|
|
253
|
+
const vote = sdk.voting.createVote(dataContactId, documentTypeName, indexName, indexValues, choice);
|
|
254
|
+
const stateTransition = sdk.voting.createStateTransition(vote, proTxHash, voterIdentity.id, identityNonce + BigInt(1));
|
|
255
|
+
// test key disabled
|
|
256
|
+
identityPublicKey.removeDisabledAt();
|
|
257
|
+
stateTransition.sign(privateKey, identityPublicKey);
|
|
258
|
+
});
|
|
344
259
|
});
|
|
@@ -1,51 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
40
|
-
var types_1 = require("../../src/types");
|
|
41
|
-
var sdk;
|
|
42
|
-
var ownerIdentifier;
|
|
43
|
-
var identityNonce;
|
|
44
|
-
var config;
|
|
45
|
-
var schema;
|
|
46
|
-
describe('DataContract', function () {
|
|
47
|
-
beforeAll(function () {
|
|
48
|
-
sdk = new types_1.DashPlatformSDK();
|
|
1
|
+
import { DataContractWASM, StateTransitionWASM } from 'pshenmic-dpp';
|
|
2
|
+
import { DashPlatformSDK } from '../../src/types';
|
|
3
|
+
let sdk;
|
|
4
|
+
let ownerIdentifier;
|
|
5
|
+
let identityNonce;
|
|
6
|
+
let config;
|
|
7
|
+
let schema;
|
|
8
|
+
describe('DataContract', () => {
|
|
9
|
+
beforeAll(() => {
|
|
10
|
+
sdk = new DashPlatformSDK({ network: 'testnet' });
|
|
49
11
|
ownerIdentifier = 'GARSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec';
|
|
50
12
|
identityNonce = BigInt(11);
|
|
51
13
|
config = {
|
|
@@ -76,67 +38,38 @@ describe('DataContract', function () {
|
|
|
76
38
|
}
|
|
77
39
|
};
|
|
78
40
|
});
|
|
79
|
-
test('should be able to get data contract',
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
});
|
|
114
|
-
}); });
|
|
115
|
-
test('should be able to create data contract with optional params', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
116
|
-
var dataContract;
|
|
117
|
-
return __generator(this, function (_a) {
|
|
118
|
-
dataContract = sdk.dataContracts.create(ownerIdentifier, identityNonce, schema, true, undefined, config);
|
|
119
|
-
expect(dataContract).toEqual(expect.any(pshenmic_dpp_1.DataContractWASM));
|
|
120
|
-
expect(dataContract.getConfig()).toEqual(config);
|
|
121
|
-
return [2 /*return*/];
|
|
122
|
-
});
|
|
123
|
-
}); });
|
|
124
|
-
test('should be able to create data contract create transition', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
125
|
-
var dataContract, transition;
|
|
126
|
-
return __generator(this, function (_a) {
|
|
127
|
-
dataContract = sdk.dataContracts.create(ownerIdentifier, identityNonce, schema);
|
|
128
|
-
transition = sdk.dataContracts.createStateTransition(dataContract, 'create', identityNonce);
|
|
129
|
-
expect(transition).toEqual(expect.any(pshenmic_dpp_1.StateTransitionWASM));
|
|
130
|
-
return [2 /*return*/];
|
|
131
|
-
});
|
|
132
|
-
}); });
|
|
133
|
-
test('should be able to create data contract update transition', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
134
|
-
var dataContract, transition;
|
|
135
|
-
return __generator(this, function (_a) {
|
|
136
|
-
dataContract = sdk.dataContracts.create(ownerIdentifier, identityNonce, schema);
|
|
137
|
-
transition = sdk.dataContracts.createStateTransition(dataContract, 'update', identityNonce);
|
|
138
|
-
expect(transition).toEqual(expect.any(pshenmic_dpp_1.StateTransitionWASM));
|
|
139
|
-
return [2 /*return*/];
|
|
140
|
-
});
|
|
141
|
-
}); });
|
|
41
|
+
test('should be able to get data contract', async () => {
|
|
42
|
+
let dataContract;
|
|
43
|
+
// System Data Contract
|
|
44
|
+
dataContract = await sdk.dataContracts.getDataContractByIdentifier('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec');
|
|
45
|
+
expect(dataContract).toEqual(expect.any(DataContractWASM));
|
|
46
|
+
// User Data Contract
|
|
47
|
+
dataContract = await sdk.dataContracts.getDataContractByIdentifier('Aukz296s36am6wKStoMbxm4YhC6kTpu3mERVrC7vHokP');
|
|
48
|
+
expect(dataContract).toEqual(expect.any(DataContractWASM));
|
|
49
|
+
// User Data Contract with keep history
|
|
50
|
+
dataContract = await sdk.dataContracts.getDataContractByIdentifier('DrEhmVJz56ukHbaFt8xLVRasnNWsrx3x8dGtcu9xg6rV');
|
|
51
|
+
expect(dataContract).toEqual(expect.any(DataContractWASM));
|
|
52
|
+
// Token Data Contract
|
|
53
|
+
dataContract = await sdk.dataContracts.getDataContractByIdentifier('3XtMFe9UPf75DAcLmLsX9CLTrLPNysNPMcnWCE1C39vm');
|
|
54
|
+
expect(dataContract).toEqual(expect.any(DataContractWASM));
|
|
55
|
+
});
|
|
56
|
+
test('should be able to create data contract', async () => {
|
|
57
|
+
const dataContract = sdk.dataContracts.create(ownerIdentifier, identityNonce, schema);
|
|
58
|
+
expect(dataContract).toEqual(expect.any(DataContractWASM));
|
|
59
|
+
});
|
|
60
|
+
test('should be able to create data contract with optional params', async () => {
|
|
61
|
+
const dataContract = sdk.dataContracts.create(ownerIdentifier, identityNonce, schema, true, undefined, config);
|
|
62
|
+
expect(dataContract).toEqual(expect.any(DataContractWASM));
|
|
63
|
+
expect(dataContract.getConfig()).toEqual(config);
|
|
64
|
+
});
|
|
65
|
+
test('should be able to create data contract create transition', async () => {
|
|
66
|
+
const dataContract = sdk.dataContracts.create(ownerIdentifier, identityNonce, schema);
|
|
67
|
+
const transition = sdk.dataContracts.createStateTransition(dataContract, 'create', identityNonce);
|
|
68
|
+
expect(transition).toEqual(expect.any(StateTransitionWASM));
|
|
69
|
+
});
|
|
70
|
+
test('should be able to create data contract update transition', async () => {
|
|
71
|
+
const dataContract = sdk.dataContracts.create(ownerIdentifier, identityNonce, schema);
|
|
72
|
+
const transition = sdk.dataContracts.createStateTransition(dataContract, 'update', identityNonce);
|
|
73
|
+
expect(transition).toEqual(expect.any(StateTransitionWASM));
|
|
74
|
+
});
|
|
142
75
|
});
|