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
|
@@ -1,149 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
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 DashPlatformSDK_1 = require("../../src/DashPlatformSDK");
|
|
40
|
-
var sdk;
|
|
41
|
-
var mnemonic;
|
|
42
|
-
describe('KeyPair', function () {
|
|
43
|
-
beforeAll(function () {
|
|
44
|
-
sdk = new DashPlatformSDK_1.DashPlatformSDK();
|
|
1
|
+
import { DashPlatformSDK } from '../../src/DashPlatformSDK';
|
|
2
|
+
let sdk;
|
|
3
|
+
let mnemonic;
|
|
4
|
+
describe('KeyPair', () => {
|
|
5
|
+
beforeAll(() => {
|
|
6
|
+
sdk = new DashPlatformSDK({ network: 'testnet' });
|
|
45
7
|
mnemonic = 'deliver frame tomato ring tool second dream mutual fade sponsor visa teach';
|
|
46
8
|
});
|
|
47
|
-
describe('mnemonic',
|
|
48
|
-
test('should be able to get seed from mnemonic',
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
wallet = _a.sent();
|
|
72
|
-
expect(wallet.privateKey).toEqual(new Uint8Array([105, 213, 35, 36, 214, 9, 104, 32, 148, 57, 157, 10, 134, 251, 79, 152, 252, 58, 194, 48, 145, 102, 7, 252, 191, 69, 164, 97, 195, 136, 182, 93]));
|
|
73
|
-
return [2 /*return*/];
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}); });
|
|
77
|
-
test('should be able to get wallet from mnemonic', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
78
|
-
var wallet;
|
|
79
|
-
return __generator(this, function (_a) {
|
|
80
|
-
switch (_a.label) {
|
|
81
|
-
case 0: return [4 /*yield*/, sdk.keyPair.mnemonicToWallet(mnemonic, '', true, { versions: 'testnet' })];
|
|
82
|
-
case 1:
|
|
83
|
-
wallet = _a.sent();
|
|
84
|
-
expect(wallet.privateKey).toEqual(new Uint8Array([105, 213, 35, 36, 214, 9, 104, 32, 148, 57, 157, 10, 134, 251, 79, 152, 252, 58, 194, 48, 145, 102, 7, 252, 191, 69, 164, 97, 195, 136, 182, 93]));
|
|
85
|
-
return [2 /*return*/];
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
}); });
|
|
89
|
-
test('should be able to get wallet for testnet from mnemonic without options', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
90
|
-
var wallet;
|
|
91
|
-
return __generator(this, function (_a) {
|
|
92
|
-
switch (_a.label) {
|
|
93
|
-
case 0: return [4 /*yield*/, sdk.keyPair.mnemonicToWallet(mnemonic)];
|
|
94
|
-
case 1:
|
|
95
|
-
wallet = _a.sent();
|
|
96
|
-
expect(wallet.privateKey).toEqual(new Uint8Array([105, 213, 35, 36, 214, 9, 104, 32, 148, 57, 157, 10, 134, 251, 79, 152, 252, 58, 194, 48, 145, 102, 7, 252, 191, 69, 164, 97, 195, 136, 182, 93]));
|
|
97
|
-
return [2 /*return*/];
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
}); });
|
|
101
|
-
});
|
|
102
|
-
describe('wallet', function () {
|
|
103
|
-
test('should be able to derive address from wallet via derive path', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
104
|
-
var wallet, key, address;
|
|
105
|
-
return __generator(this, function (_a) {
|
|
106
|
-
switch (_a.label) {
|
|
107
|
-
case 0: return [4 /*yield*/, sdk.keyPair.mnemonicToWallet(mnemonic, '', true, { versions: 'testnet' })];
|
|
108
|
-
case 1:
|
|
109
|
-
wallet = _a.sent();
|
|
110
|
-
return [4 /*yield*/, sdk.keyPair.derivePath(wallet, "m/44'/1'/0'/0/0")];
|
|
111
|
-
case 2:
|
|
112
|
-
key = _a.sent();
|
|
113
|
-
return [4 /*yield*/, sdk.keyPair.publicKeyToAddress(key.publicKey, { version: 'testnet' })];
|
|
114
|
-
case 3:
|
|
115
|
-
address = _a.sent();
|
|
116
|
-
expect(address).toEqual('yRGEqFgmuqJct4jzH48sFrvBCc3WuPKDTp');
|
|
117
|
-
return [2 /*return*/];
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
}); });
|
|
121
|
-
test('should be able to derive identity from wallet', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
122
|
-
var wallet, key;
|
|
123
|
-
return __generator(this, function (_a) {
|
|
124
|
-
switch (_a.label) {
|
|
125
|
-
case 0: return [4 /*yield*/, sdk.keyPair.mnemonicToWallet(mnemonic, '', true, { versions: 'testnet' })];
|
|
126
|
-
case 1:
|
|
127
|
-
wallet = _a.sent();
|
|
128
|
-
return [4 /*yield*/, sdk.keyPair.walletToIdentityKey(wallet, 0, 0)];
|
|
129
|
-
case 2:
|
|
130
|
-
key = _a.sent();
|
|
131
|
-
expect(key.privateKey).toEqual(Uint8Array.from([89, 255, 64, 41, 202, 170, 83, 68, 135, 58, 161, 107, 130, 20, 3, 50, 69, 16, 108, 104, 32, 68, 13, 100, 225, 24, 79, 20, 193, 184, 238, 55]));
|
|
132
|
-
return [2 /*return*/];
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
}); });
|
|
136
|
-
test('should be able to derive identity from mnemonic', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
137
|
-
var key;
|
|
138
|
-
return __generator(this, function (_a) {
|
|
139
|
-
switch (_a.label) {
|
|
140
|
-
case 0: return [4 /*yield*/, sdk.keyPair.mnemonicToIdentityKey(mnemonic, 0, 0)];
|
|
141
|
-
case 1:
|
|
142
|
-
key = _a.sent();
|
|
143
|
-
expect(key.privateKey).toEqual(Uint8Array.from([89, 255, 64, 41, 202, 170, 83, 68, 135, 58, 161, 107, 130, 20, 3, 50, 69, 16, 108, 104, 32, 68, 13, 100, 225, 24, 79, 20, 193, 184, 238, 55]));
|
|
144
|
-
return [2 /*return*/];
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
}); });
|
|
9
|
+
describe('mnemonic', () => {
|
|
10
|
+
test('should be able to get seed from mnemonic', async () => {
|
|
11
|
+
const seed = sdk.keyPair.mnemonicToSeed(mnemonic);
|
|
12
|
+
// TODO: Get mock data from sdk
|
|
13
|
+
expect(seed).toEqual(Uint8Array.from([170, 120, 192, 223, 47, 43, 142, 250, 243, 136, 44, 236, 84, 170, 156, 154, 126, 231, 185, 130, 242, 40, 134, 27, 36, 33, 187, 102, 29, 177, 119, 141, 61, 157, 81, 35, 85, 33, 43, 28, 108, 24, 108, 159, 119, 233, 104, 100, 2, 206, 18, 245, 142, 99, 19, 143, 141, 0, 207, 31, 143, 58, 245, 107]));
|
|
14
|
+
});
|
|
15
|
+
test('should be able to derive hd wallet from seed', async () => {
|
|
16
|
+
const seed = sdk.keyPair.mnemonicToSeed(mnemonic);
|
|
17
|
+
const hdKey = sdk.keyPair.seedToHdKey(seed);
|
|
18
|
+
expect(hdKey.privateKey).toEqual(new Uint8Array([105, 213, 35, 36, 214, 9, 104, 32, 148, 57, 157, 10, 134, 251, 79, 152, 252, 58, 194, 48, 145, 102, 7, 252, 191, 69, 164, 97, 195, 136, 182, 93]));
|
|
19
|
+
});
|
|
20
|
+
test('should be able to derive address from wallet via derive path', async () => {
|
|
21
|
+
const seed = sdk.keyPair.mnemonicToSeed(mnemonic);
|
|
22
|
+
const seedHdKey = sdk.keyPair.seedToHdKey(seed, 'testnet');
|
|
23
|
+
const derivedHdKey = await sdk.keyPair.derivePath(seedHdKey, "m/44'/1'/0'/0/0");
|
|
24
|
+
const address = sdk.keyPair.p2pkhAddress(derivedHdKey.publicKey, 'testnet');
|
|
25
|
+
expect(address).toEqual('yRGEqFgmuqJct4jzH48sFrvBCc3WuPKDTp');
|
|
26
|
+
});
|
|
27
|
+
test('should be able to derive identity hd key from wallet', async () => {
|
|
28
|
+
const seed = sdk.keyPair.mnemonicToSeed(mnemonic);
|
|
29
|
+
const seedHdKey = sdk.keyPair.seedToHdKey(seed);
|
|
30
|
+
const key = sdk.keyPair.deriveIdentityPrivateKey(seedHdKey, 0, 0, 'testnet');
|
|
31
|
+
expect(key.privateKey).toEqual(Uint8Array.from([89, 255, 64, 41, 202, 170, 83, 68, 135, 58, 161, 107, 130, 20, 3, 50, 69, 16, 108, 104, 32, 68, 13, 100, 225, 24, 79, 20, 193, 184, 238, 55]));
|
|
32
|
+
});
|
|
148
33
|
});
|
|
149
34
|
});
|
package/test/unit/Names.spec.js
CHANGED
|
@@ -1,96 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
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 broadcast_1 = require("../../src/stateTransitions/broadcast");
|
|
40
|
-
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
41
|
-
var DashPlatformSDK_1 = require("../../src/DashPlatformSDK");
|
|
42
|
-
var sleep_1 = require("../../src/utils/sleep");
|
|
1
|
+
import broadcast from '../../src/stateTransitions/broadcast';
|
|
2
|
+
import { DocumentWASM, PrivateKeyWASM } from 'pshenmic-dpp';
|
|
3
|
+
import { DashPlatformSDK } from '../../src/DashPlatformSDK';
|
|
4
|
+
import sleep from '../../src/utils/sleep';
|
|
43
5
|
jest.mock('../../src/stateTransitions/broadcast');
|
|
44
6
|
jest.mock('../../src/utils/sleep');
|
|
45
|
-
|
|
46
|
-
describe('DPNS names',
|
|
47
|
-
beforeAll(
|
|
48
|
-
sdk = new
|
|
7
|
+
let sdk;
|
|
8
|
+
describe('DPNS names', () => {
|
|
9
|
+
beforeAll(() => {
|
|
10
|
+
sdk = new DashPlatformSDK({ network: 'testnet' });
|
|
49
11
|
// @ts-expect-error
|
|
50
|
-
|
|
12
|
+
sleep.mockReturnValue(Promise.resolve());
|
|
51
13
|
sdk.stateTransitions.broadcast = jest.fn();
|
|
52
14
|
});
|
|
53
|
-
test('should be able to search names by
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
case 1:
|
|
72
|
-
documents = _a.sent();
|
|
73
|
-
expect(documents === null || documents === void 0 ? void 0 : documents.length).toEqual(3);
|
|
74
|
-
xyzDocument = documents[0];
|
|
75
|
-
expect(xyzDocument.ownerId.base58()).toEqual('36LGwPSXef8q8wpdnx4EdDeVNuqCYNAE9boDu5bxytsm');
|
|
76
|
-
return [2 /*return*/];
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
}); });
|
|
80
|
-
test('should be able to register a name', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
81
|
-
var fullName, identityId, privateKey;
|
|
82
|
-
return __generator(this, function (_a) {
|
|
83
|
-
switch (_a.label) {
|
|
84
|
-
case 0:
|
|
85
|
-
fullName = 'test-identity-050.dash';
|
|
86
|
-
identityId = 'CKKYnVeKoxCbvuEhiT6MDoQaRyXgDECwtxoKL5cqucZE';
|
|
87
|
-
privateKey = pshenmic_dpp_1.PrivateKeyWASM.fromWIF('XERm528aQWJ3hzEcb79KMQKewbSSJQtni3fWHbu75wDxg6xg6AA3');
|
|
88
|
-
return [4 /*yield*/, sdk.names.registerName(fullName, identityId, privateKey)];
|
|
89
|
-
case 1:
|
|
90
|
-
_a.sent();
|
|
91
|
-
expect(broadcast_1.default).toHaveBeenCalledTimes(2);
|
|
92
|
-
return [2 /*return*/];
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
}); });
|
|
15
|
+
test('should be able to search names by DPNS name', async () => {
|
|
16
|
+
const documents = await sdk.names.searchByName('xyz.dash');
|
|
17
|
+
expect(documents?.length).toEqual(1);
|
|
18
|
+
expect(documents[0]).toEqual(expect.any(DocumentWASM));
|
|
19
|
+
});
|
|
20
|
+
test('should be able to search names by identity', async () => {
|
|
21
|
+
const documents = await sdk.names.searchByIdentity('36LGwPSXef8q8wpdnx4EdDeVNuqCYNAE9boDu5bxytsm');
|
|
22
|
+
expect(documents?.length).toEqual(3);
|
|
23
|
+
const [xyzDocument] = documents;
|
|
24
|
+
expect(xyzDocument.ownerId.base58()).toEqual('36LGwPSXef8q8wpdnx4EdDeVNuqCYNAE9boDu5bxytsm');
|
|
25
|
+
});
|
|
26
|
+
test('should be able to register a name', async () => {
|
|
27
|
+
const fullName = 'test-identity-050.dash';
|
|
28
|
+
const identityId = 'CKKYnVeKoxCbvuEhiT6MDoQaRyXgDECwtxoKL5cqucZE';
|
|
29
|
+
const privateKey = PrivateKeyWASM.fromWIF('XERm528aQWJ3hzEcb79KMQKewbSSJQtni3fWHbu75wDxg6xg6AA3');
|
|
30
|
+
await sdk.names.registerName(fullName, identityId, privateKey);
|
|
31
|
+
expect(broadcast).toHaveBeenCalledTimes(2);
|
|
32
|
+
});
|
|
96
33
|
});
|
package/test/unit/Node.spec.js
CHANGED
|
@@ -1,129 +1,58 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1
|
+
import { DashPlatformSDK } from '../../src/DashPlatformSDK';
|
|
2
|
+
let sdk;
|
|
3
|
+
describe('Node', () => {
|
|
4
|
+
beforeAll(() => {
|
|
5
|
+
sdk = new DashPlatformSDK({ network: 'testnet' });
|
|
9
6
|
});
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
7
|
+
test('should be able to call getStatus', async () => {
|
|
8
|
+
const status = await sdk.node.status();
|
|
9
|
+
expect(status.version?.software?.dapi).toEqual(expect.any(String));
|
|
10
|
+
expect(status.version?.software?.drive).toEqual(expect.any(String));
|
|
11
|
+
expect(status.version?.software?.tenderdash).toEqual(expect.any(String));
|
|
12
|
+
expect(status.version?.protocol?.tenderdash?.p2P).toEqual(expect.any(Number));
|
|
13
|
+
expect(status.version?.protocol?.tenderdash?.block).toEqual(expect.any(Number));
|
|
14
|
+
expect(status.version?.protocol?.drive?.latest).toEqual(expect.any(Number));
|
|
15
|
+
expect(status.version?.protocol?.drive?.current).toEqual(expect.any(Number));
|
|
16
|
+
expect(status.node?.id).toEqual(expect.any(String));
|
|
17
|
+
expect(status.chain?.catchingUp).toEqual(expect.any(Boolean));
|
|
18
|
+
expect(status.chain?.latestBlockHash).toEqual(expect.any(String));
|
|
19
|
+
expect(status.chain?.latestAppHash).toEqual(expect.any(String));
|
|
20
|
+
expect(status.chain?.latestBlockHeight).toEqual(expect.any(String));
|
|
21
|
+
expect(status.chain?.earliestBlockHash).toEqual(expect.any(String));
|
|
22
|
+
expect(status.chain?.earliestAppHash).toEqual(expect.any(String));
|
|
23
|
+
expect(status.chain?.earliestBlockHeight).toEqual(expect.any(String));
|
|
24
|
+
expect(status.chain?.maxPeerBlockHeight).toEqual(expect.any(String));
|
|
25
|
+
expect(status.chain?.coreChainLockedHeight).toEqual(expect.any(Number));
|
|
26
|
+
expect(status.network?.chainId).toEqual(expect.any(String));
|
|
27
|
+
expect(status.network?.peersCount).toEqual(expect.any(Number));
|
|
28
|
+
expect(status.network?.listening).toEqual(expect.any(Boolean));
|
|
29
|
+
expect(status.stateSync?.totalSyncedTime).toEqual(expect.any(String));
|
|
30
|
+
expect(status.stateSync?.remainingTime).toEqual(expect.any(String));
|
|
31
|
+
expect(status.stateSync?.totalSnapshots).toEqual(expect.any(Number));
|
|
32
|
+
expect(status.stateSync?.chunkProcessAvgTime).toEqual(expect.any(String));
|
|
33
|
+
expect(status.stateSync?.snapshotHeight).toEqual(expect.any(String));
|
|
34
|
+
expect(status.stateSync?.snapshotChunksCount).toEqual(expect.any(String));
|
|
35
|
+
expect(status.stateSync?.backfilledBlocks).toEqual(expect.any(String));
|
|
36
|
+
expect(status.stateSync?.backfillBlocksTotal).toEqual(expect.any(String));
|
|
37
|
+
expect(status.time?.local).toEqual(expect.any(String));
|
|
38
|
+
expect(status.time?.block).toEqual(expect.any(String));
|
|
39
|
+
expect(status.time?.genesis).toEqual(expect.any(String));
|
|
40
|
+
expect(status.time?.epoch).toEqual(expect.any(Number));
|
|
41
|
+
});
|
|
42
|
+
test('should be able to call getEpochsInfo in desc', async () => {
|
|
43
|
+
const epochsInfo = await sdk.node.getEpochsInfo(10, false, 8607);
|
|
44
|
+
const expectedEpochsNumbers = Array.from({ length: 10 }, (_val, index) => 8598 + index);
|
|
45
|
+
expect(epochsInfo.length).toEqual(10);
|
|
46
|
+
expect(epochsInfo.map(epochInfo => epochInfo.number)).toEqual(expectedEpochsNumbers);
|
|
47
|
+
});
|
|
48
|
+
test('should be able to call getEpochsInfo in asc', async () => {
|
|
49
|
+
const epochsInfo = await sdk.node.getEpochsInfo(10, true, 8596);
|
|
50
|
+
const expectedEpochsNumbers = Array.from({ length: 10 }, (_val, index) => 8596 + index);
|
|
51
|
+
expect(epochsInfo.length).toEqual(10);
|
|
52
|
+
expect(epochsInfo.map(epochInfo => epochInfo.number)).toEqual(expectedEpochsNumbers);
|
|
53
|
+
});
|
|
54
|
+
test('should be able to call getTotalCreditsInPlatform', async () => {
|
|
55
|
+
const totalCredits = await sdk.node.totalCredits();
|
|
56
|
+
expect(Number(totalCredits)).toBeGreaterThan(0);
|
|
44
57
|
});
|
|
45
|
-
test('should be able to call getStatus', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
46
|
-
var status;
|
|
47
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18;
|
|
48
|
-
return __generator(this, function (_19) {
|
|
49
|
-
switch (_19.label) {
|
|
50
|
-
case 0: return [4 /*yield*/, sdk.node.status()];
|
|
51
|
-
case 1:
|
|
52
|
-
status = _19.sent();
|
|
53
|
-
expect((_b = (_a = status.version) === null || _a === void 0 ? void 0 : _a.software) === null || _b === void 0 ? void 0 : _b.dapi).toEqual(expect.any(String));
|
|
54
|
-
expect((_d = (_c = status.version) === null || _c === void 0 ? void 0 : _c.software) === null || _d === void 0 ? void 0 : _d.drive).toEqual(expect.any(String));
|
|
55
|
-
expect((_f = (_e = status.version) === null || _e === void 0 ? void 0 : _e.software) === null || _f === void 0 ? void 0 : _f.tenderdash).toEqual(expect.any(String));
|
|
56
|
-
expect((_j = (_h = (_g = status.version) === null || _g === void 0 ? void 0 : _g.protocol) === null || _h === void 0 ? void 0 : _h.tenderdash) === null || _j === void 0 ? void 0 : _j.p2p).toEqual(expect.any(Number));
|
|
57
|
-
expect((_m = (_l = (_k = status.version) === null || _k === void 0 ? void 0 : _k.protocol) === null || _l === void 0 ? void 0 : _l.tenderdash) === null || _m === void 0 ? void 0 : _m.block).toEqual(expect.any(Number));
|
|
58
|
-
expect((_q = (_p = (_o = status.version) === null || _o === void 0 ? void 0 : _o.protocol) === null || _p === void 0 ? void 0 : _p.drive) === null || _q === void 0 ? void 0 : _q.latest).toEqual(expect.any(Number));
|
|
59
|
-
expect((_t = (_s = (_r = status.version) === null || _r === void 0 ? void 0 : _r.protocol) === null || _s === void 0 ? void 0 : _s.drive) === null || _t === void 0 ? void 0 : _t.current).toEqual(expect.any(Number));
|
|
60
|
-
expect((_u = status.node) === null || _u === void 0 ? void 0 : _u.id).toEqual(expect.any(String));
|
|
61
|
-
expect((_v = status.chain) === null || _v === void 0 ? void 0 : _v.catchingUp).toEqual(expect.any(Boolean));
|
|
62
|
-
expect((_w = status.chain) === null || _w === void 0 ? void 0 : _w.latestBlockHash).toEqual(expect.any(String));
|
|
63
|
-
expect((_x = status.chain) === null || _x === void 0 ? void 0 : _x.latestAppHash).toEqual(expect.any(String));
|
|
64
|
-
expect((_y = status.chain) === null || _y === void 0 ? void 0 : _y.latestBlockHeight).toEqual(expect.any(String));
|
|
65
|
-
expect((_z = status.chain) === null || _z === void 0 ? void 0 : _z.earliestBlockHash).toEqual(expect.any(String));
|
|
66
|
-
expect((_0 = status.chain) === null || _0 === void 0 ? void 0 : _0.earliestAppHash).toEqual(expect.any(String));
|
|
67
|
-
expect((_1 = status.chain) === null || _1 === void 0 ? void 0 : _1.earliestBlockHeight).toEqual(expect.any(String));
|
|
68
|
-
expect((_2 = status.chain) === null || _2 === void 0 ? void 0 : _2.maxPeerBlockHeight).toEqual(expect.any(String));
|
|
69
|
-
expect((_3 = status.chain) === null || _3 === void 0 ? void 0 : _3.coreChainLockedHeight).toEqual(expect.any(Number));
|
|
70
|
-
expect((_4 = status.network) === null || _4 === void 0 ? void 0 : _4.chainId).toEqual(expect.any(String));
|
|
71
|
-
expect((_5 = status.network) === null || _5 === void 0 ? void 0 : _5.peersCount).toEqual(expect.any(Number));
|
|
72
|
-
expect((_6 = status.network) === null || _6 === void 0 ? void 0 : _6.listening).toEqual(expect.any(Boolean));
|
|
73
|
-
expect((_7 = status.stateSync) === null || _7 === void 0 ? void 0 : _7.totalSyncedTime).toEqual(expect.any(String));
|
|
74
|
-
expect((_8 = status.stateSync) === null || _8 === void 0 ? void 0 : _8.remainingTime).toEqual(expect.any(String));
|
|
75
|
-
expect((_9 = status.stateSync) === null || _9 === void 0 ? void 0 : _9.totalSnapshots).toEqual(expect.any(Number));
|
|
76
|
-
expect((_10 = status.stateSync) === null || _10 === void 0 ? void 0 : _10.chunkProcessAvgTime).toEqual(expect.any(String));
|
|
77
|
-
expect((_11 = status.stateSync) === null || _11 === void 0 ? void 0 : _11.snapshotHeight).toEqual(expect.any(String));
|
|
78
|
-
expect((_12 = status.stateSync) === null || _12 === void 0 ? void 0 : _12.snapshotChunksCount).toEqual(expect.any(String));
|
|
79
|
-
expect((_13 = status.stateSync) === null || _13 === void 0 ? void 0 : _13.backfilledBlocks).toEqual(expect.any(String));
|
|
80
|
-
expect((_14 = status.stateSync) === null || _14 === void 0 ? void 0 : _14.backfillBlocksTotal).toEqual(expect.any(String));
|
|
81
|
-
expect((_15 = status.time) === null || _15 === void 0 ? void 0 : _15.local).toEqual(expect.any(String));
|
|
82
|
-
expect((_16 = status.time) === null || _16 === void 0 ? void 0 : _16.block).toEqual(expect.any(String));
|
|
83
|
-
expect((_17 = status.time) === null || _17 === void 0 ? void 0 : _17.genesis).toEqual(expect.any(String));
|
|
84
|
-
expect((_18 = status.time) === null || _18 === void 0 ? void 0 : _18.epoch).toEqual(expect.any(Number));
|
|
85
|
-
return [2 /*return*/];
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
}); });
|
|
89
|
-
test('should be able to call getEpochsInfo in desc', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
90
|
-
var epochsInfo, expectedEpochsNumbers;
|
|
91
|
-
return __generator(this, function (_a) {
|
|
92
|
-
switch (_a.label) {
|
|
93
|
-
case 0: return [4 /*yield*/, sdk.node.getEpochsInfo(10, false, 8607)];
|
|
94
|
-
case 1:
|
|
95
|
-
epochsInfo = _a.sent();
|
|
96
|
-
expectedEpochsNumbers = Array.from({ length: 10 }, function (_val, index) { return 8598 + index; });
|
|
97
|
-
expect(epochsInfo.length).toEqual(10);
|
|
98
|
-
expect(epochsInfo.map(function (epochInfo) { return epochInfo.number; })).toEqual(expectedEpochsNumbers);
|
|
99
|
-
return [2 /*return*/];
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
}); });
|
|
103
|
-
test('should be able to call getEpochsInfo in asc', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
104
|
-
var epochsInfo, expectedEpochsNumbers;
|
|
105
|
-
return __generator(this, function (_a) {
|
|
106
|
-
switch (_a.label) {
|
|
107
|
-
case 0: return [4 /*yield*/, sdk.node.getEpochsInfo(10, true, 8596)];
|
|
108
|
-
case 1:
|
|
109
|
-
epochsInfo = _a.sent();
|
|
110
|
-
expectedEpochsNumbers = Array.from({ length: 10 }, function (_val, index) { return 8596 + index; });
|
|
111
|
-
expect(epochsInfo.length).toEqual(10);
|
|
112
|
-
expect(epochsInfo.map(function (epochInfo) { return epochInfo.number; })).toEqual(expectedEpochsNumbers);
|
|
113
|
-
return [2 /*return*/];
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
}); });
|
|
117
|
-
test('should be able to call getTotalCreditsInPlatform', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
118
|
-
var totalCredits;
|
|
119
|
-
return __generator(this, function (_a) {
|
|
120
|
-
switch (_a.label) {
|
|
121
|
-
case 0: return [4 /*yield*/, sdk.node.totalCredits()];
|
|
122
|
-
case 1:
|
|
123
|
-
totalCredits = _a.sent();
|
|
124
|
-
expect(Number(totalCredits)).toBeGreaterThan(0);
|
|
125
|
-
return [2 /*return*/];
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
}); });
|
|
129
58
|
});
|
package/test/unit/SDK.spec.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
beforeAll(function () {
|
|
7
|
-
sdk = new DashPlatformSDK_1.DashPlatformSDK();
|
|
1
|
+
import { DashPlatformSDK } from '../../src/DashPlatformSDK';
|
|
2
|
+
let sdk;
|
|
3
|
+
describe('DashPlatformSDK', () => {
|
|
4
|
+
beforeAll(() => {
|
|
5
|
+
sdk = new DashPlatformSDK({ network: 'testnet' });
|
|
8
6
|
});
|
|
9
|
-
test('should be constructable throw `new`',
|
|
10
|
-
expect(sdk).toEqual(expect.any(
|
|
7
|
+
test('should be constructable throw `new`', () => {
|
|
8
|
+
expect(sdk).toEqual(expect.any(DashPlatformSDK));
|
|
11
9
|
});
|
|
12
10
|
});
|