@firmachain/firma-js 0.3.1 → 0.3.3
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 +47 -13
- package/dist/sdk/FirmaGovService.d.ts +9 -8
- package/dist/sdk/FirmaGovService.js +119 -32
- package/dist/sdk/FirmaStakingService.d.ts +4 -2
- package/dist/sdk/FirmaStakingService.js +37 -9
- package/dist/sdk/FirmaUtil.d.ts +28 -0
- package/dist/sdk/FirmaUtil.js +110 -0
- package/dist/sdk/firmachain/common/CommonTxClient.js +1 -0
- package/dist/sdk/firmachain/common/modules/gov/messages.js +1 -0
- package/dist/sdk/firmachain/gov/GovQueryClient.d.ts +22 -49
- package/dist/sdk/firmachain/gov/GovQueryClient.js +20 -28
- package/dist/sdk/firmachain/gov/GovTxClient.js +1 -0
- package/dist/sdk/firmachain/staking/StakingQueryClient.d.ts +2 -2
- package/dist/test/08.gas_estimate.test.js +10 -55
- package/dist/test/13.staking_query.test.js +12 -0
- package/dist/test/16.gov_tx.test.js +72 -58
- package/dist/test/17.gov_query.test.js +18 -18
- package/dist/test/18.util.test.js +65 -4
- package/dist/test/20.slashing_query.test.js +0 -1
- package/dist/test/config_test.d.ts +1 -1
- package/dist/test/config_test.js +17 -1
- package/package.json +3 -1
package/dist/sdk/FirmaUtil.js
CHANGED
|
@@ -84,6 +84,7 @@ var proto_signing_1 = require("@cosmjs/proto-signing");
|
|
|
84
84
|
var signingstargateclient_1 = require("./firmachain/common/signingstargateclient");
|
|
85
85
|
var any_1 = require("./firmachain/google/protobuf/any");
|
|
86
86
|
var long_1 = __importDefault(require("long"));
|
|
87
|
+
var bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
87
88
|
var CommonTxClient_1 = require("./firmachain/common/CommonTxClient");
|
|
88
89
|
var CryptoJS = require("crypto-js");
|
|
89
90
|
var sha1 = require("crypto-js/sha1");
|
|
@@ -456,6 +457,115 @@ var FirmaUtil = /** @class */ (function () {
|
|
|
456
457
|
FirmaUtil.getCommonTxClient = function (aliceWallet) {
|
|
457
458
|
return new CommonTxClient_1.CommonTxClient(aliceWallet, FirmaUtil.config.rpcAddress);
|
|
458
459
|
};
|
|
460
|
+
/**
|
|
461
|
+
* Parses a duration string to a Duration object.
|
|
462
|
+
* Supports formats like "336h0m0s", "21d", "1000ms", "1s", "1m", "1h", "1ns", "1µs"/"1us"
|
|
463
|
+
*
|
|
464
|
+
* @param durationStr - Duration string to parse (e.g., "336h0m0s", "21d")
|
|
465
|
+
* @returns Duration object with seconds and nanos fields
|
|
466
|
+
*/
|
|
467
|
+
FirmaUtil.parseDurationString = function (durationStr) {
|
|
468
|
+
if (!durationStr || durationStr.trim() === "") {
|
|
469
|
+
return { seconds: BigInt(0), nanos: 0 };
|
|
470
|
+
}
|
|
471
|
+
var input = durationStr.trim();
|
|
472
|
+
var totalSeconds = 0;
|
|
473
|
+
var totalNanos = 0;
|
|
474
|
+
// Handle negative durations
|
|
475
|
+
var isNegative = input.startsWith('-');
|
|
476
|
+
var cleanInput = isNegative ? input.substring(1) : input;
|
|
477
|
+
// Regular expression to match duration components
|
|
478
|
+
var regex = /(\d+(?:\.\d+)?)(d|h|m|s|ms|µs|us|ns)/g;
|
|
479
|
+
var match;
|
|
480
|
+
var hasMatches = false;
|
|
481
|
+
while ((match = regex.exec(cleanInput)) !== null) {
|
|
482
|
+
hasMatches = true;
|
|
483
|
+
var value = parseFloat(match[1]);
|
|
484
|
+
var unit = match[2];
|
|
485
|
+
switch (unit) {
|
|
486
|
+
case 'd': // days
|
|
487
|
+
totalSeconds += value * 24 * 60 * 60;
|
|
488
|
+
break;
|
|
489
|
+
case 'h': // hours
|
|
490
|
+
totalSeconds += value * 60 * 60;
|
|
491
|
+
break;
|
|
492
|
+
case 'm': // minutes
|
|
493
|
+
totalSeconds += value * 60;
|
|
494
|
+
break;
|
|
495
|
+
case 's': // seconds
|
|
496
|
+
totalSeconds += value;
|
|
497
|
+
break;
|
|
498
|
+
case 'ms': // milliseconds
|
|
499
|
+
totalNanos += value * 1000000;
|
|
500
|
+
break;
|
|
501
|
+
case 'µs':
|
|
502
|
+
case 'us': // microseconds
|
|
503
|
+
totalNanos += value * 1000;
|
|
504
|
+
break;
|
|
505
|
+
case 'ns': // nanoseconds
|
|
506
|
+
totalNanos += value;
|
|
507
|
+
break;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
if (!hasMatches) {
|
|
511
|
+
throw new Error("Invalid duration format: " + durationStr);
|
|
512
|
+
}
|
|
513
|
+
// Convert excess nanos to seconds
|
|
514
|
+
var extraSeconds = Math.floor(totalNanos / 1000000000);
|
|
515
|
+
totalSeconds += extraSeconds;
|
|
516
|
+
totalNanos = totalNanos % 1000000000;
|
|
517
|
+
// Apply negative sign
|
|
518
|
+
var finalSeconds = isNegative ? -totalSeconds : totalSeconds;
|
|
519
|
+
var finalNanos = isNegative ? -totalNanos : totalNanos;
|
|
520
|
+
return {
|
|
521
|
+
seconds: BigInt(Math.floor(finalSeconds)),
|
|
522
|
+
nanos: Math.floor(finalNanos)
|
|
523
|
+
};
|
|
524
|
+
};
|
|
525
|
+
/**
|
|
526
|
+
* Creates a Duration object from a duration string.
|
|
527
|
+
* This is a convenience method that combines parseDurationString with Duration.fromPartial.
|
|
528
|
+
*
|
|
529
|
+
* @param durationStr - Duration string to parse (e.g., "336h0m0s", "21d")
|
|
530
|
+
* @returns Duration object ready to use with protobuf
|
|
531
|
+
*/
|
|
532
|
+
FirmaUtil.createDurationFromString = function (durationStr) {
|
|
533
|
+
var _a = FirmaUtil.parseDurationString(durationStr), seconds = _a.seconds, nanos = _a.nanos;
|
|
534
|
+
// Import Duration if not already imported
|
|
535
|
+
var Duration = require("./firmachain/google/protobuf/duration").Duration;
|
|
536
|
+
return Duration.fromPartial({
|
|
537
|
+
seconds: seconds,
|
|
538
|
+
nanos: nanos
|
|
539
|
+
});
|
|
540
|
+
};
|
|
541
|
+
/**
|
|
542
|
+
* Safely processes commission rate strings to prevent big.Int conversion errors.
|
|
543
|
+
* Converts decimal commission rates to Cosmos SDK atomics format (integer representation).
|
|
544
|
+
*
|
|
545
|
+
* @param commissionRate - Commission rate string from staking params
|
|
546
|
+
* @returns Processed commission rate string safe for protobuf usage (atomics format or empty string)
|
|
547
|
+
*/
|
|
548
|
+
FirmaUtil.processCommissionRateAsDecimal = function (commissionRate) {
|
|
549
|
+
var trimmed = commissionRate.trim();
|
|
550
|
+
if (!commissionRate || trimmed === "") {
|
|
551
|
+
throw new Error("Invalid commission rate format: " + commissionRate);
|
|
552
|
+
}
|
|
553
|
+
if (!/^(\d+\.?\d*|\.\d+)$/.test(trimmed)) {
|
|
554
|
+
throw new Error("Invalid commission rate format: " + commissionRate);
|
|
555
|
+
}
|
|
556
|
+
// Validates input and creates BigNumber instance
|
|
557
|
+
var commissionRateBN = new bignumber_js_1.default(trimmed);
|
|
558
|
+
// Checks if it's a valid finite number
|
|
559
|
+
if (!commissionRateBN.isFinite())
|
|
560
|
+
throw new Error("Invalid commission rate format: " + commissionRate);
|
|
561
|
+
// Validates range (0 to 1 inclusive)
|
|
562
|
+
if (commissionRateBN.isNegative() || commissionRateBN.isGreaterThan(1))
|
|
563
|
+
throw new Error("Invalid commission rate range. Must be between 0 and 1 inclusive.");
|
|
564
|
+
// Converts to atomics format (multiply by 10^18)
|
|
565
|
+
var atomics = commissionRateBN.multipliedBy(new bignumber_js_1.default(10).pow(18));
|
|
566
|
+
// Returns integer string
|
|
567
|
+
return atomics.integerValue(bignumber_js_1.default.ROUND_DOWN).toString();
|
|
568
|
+
};
|
|
459
569
|
FirmaUtil.FctDecimal = 6;
|
|
460
570
|
return FirmaUtil;
|
|
461
571
|
}());
|
|
@@ -22,6 +22,7 @@ var tx_2 = require("cosmjs-types/cosmos/distribution/v1beta1/tx");
|
|
|
22
22
|
var tx_3 = require("cosmjs-types/cosmos/gov/v1beta1/tx");
|
|
23
23
|
var tx_4 = require("cosmjs-types/cosmos/staking/v1beta1/tx");
|
|
24
24
|
var tx_5 = require("cosmjs-types/cosmwasm/wasm/v1/tx");
|
|
25
|
+
// temporarly using kintsugi-tech/cosmjs-types - this will be returned to original cosmjs-types after the PR is merged
|
|
25
26
|
var tx_6 = require("@kintsugi-tech/cosmjs-types/cosmos/gov/v1/tx");
|
|
26
27
|
var AuthzTxTypes_1 = require("../authz/AuthzTxTypes");
|
|
27
28
|
var ContractTxTypes_1 = require("../contract/ContractTxTypes");
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.isMsgCancelProposalEncodeObject = exports.isMsgVoteWeightedEncodeObject = exports.isMsgVoteEncodeObject = exports.isMsgSubmitProposalEncodeObject = exports.isMsgDepositEncodeObject = exports.govTypes = void 0;
|
|
4
4
|
var tx_1 = require("cosmjs-types/cosmos/gov/v1/tx");
|
|
5
5
|
var tx_2 = require("cosmjs-types/cosmos/gov/v1beta1/tx");
|
|
6
|
+
// temporarly using kintsugi-tech/cosmjs-types - this will be returned to original cosmjs-types after the PR is merged
|
|
6
7
|
var tx_3 = require("@kintsugi-tech/cosmjs-types/cosmos/gov/v1/tx");
|
|
7
8
|
exports.govTypes = [
|
|
8
9
|
["/cosmos.gov.v1.MsgDeposit", tx_1.MsgDeposit],
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Proposal } from "@kintsugi-tech/cosmjs-types/cosmos/gov/v1/gov";
|
|
2
|
+
import { Coin } from "cosmjs-types/cosmos/base/v1beta1/coin";
|
|
1
3
|
export declare enum ProposalStatus {
|
|
2
4
|
PROPOSAL_STATUS_UNSPECIFIED = 0,
|
|
3
5
|
PROPOSAL_STATUS_DEPOSIT_PERIOD = 1,
|
|
@@ -6,32 +8,23 @@ export declare enum ProposalStatus {
|
|
|
6
8
|
PROPOSAL_STATUS_REJECTED = 4,
|
|
7
9
|
PROPOSAL_STATUS_FAILED = 5
|
|
8
10
|
}
|
|
9
|
-
export interface
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
amount: string;
|
|
17
|
-
}[];
|
|
18
|
-
max_deposit_period: string;
|
|
19
|
-
};
|
|
20
|
-
tally_params: {
|
|
21
|
-
quorum: string;
|
|
22
|
-
threshold: string;
|
|
23
|
-
veto_threshold: string;
|
|
24
|
-
};
|
|
11
|
+
export interface GovParamType {
|
|
12
|
+
min_deposit: Coin[];
|
|
13
|
+
max_deposit_period: string;
|
|
14
|
+
voting_period: string;
|
|
15
|
+
quorum: string;
|
|
16
|
+
threshold: string;
|
|
17
|
+
veto_threshold: string;
|
|
25
18
|
min_initial_deposit_ratio: string;
|
|
19
|
+
proposal_cancel_ratio: string;
|
|
20
|
+
proposal_cancel_dest: string;
|
|
21
|
+
expedited_voting_period: string;
|
|
22
|
+
expedited_threshold: string;
|
|
23
|
+
expedited_min_deposit: Coin[];
|
|
26
24
|
burn_vote_quorum: boolean;
|
|
27
25
|
burn_proposal_deposit_prevote: boolean;
|
|
28
26
|
burn_vote_veto: boolean;
|
|
29
|
-
|
|
30
|
-
expedited_threshold: string;
|
|
31
|
-
expedited_min_deposit: {
|
|
32
|
-
denom: string;
|
|
33
|
-
amount: string;
|
|
34
|
-
}[];
|
|
27
|
+
min_deposit_ratio: string;
|
|
35
28
|
}
|
|
36
29
|
export interface CurrentVoteInfo {
|
|
37
30
|
yes: string;
|
|
@@ -39,35 +32,15 @@ export interface CurrentVoteInfo {
|
|
|
39
32
|
no: string;
|
|
40
33
|
no_with_veto: string;
|
|
41
34
|
}
|
|
42
|
-
export interface ProposalInfo {
|
|
43
|
-
proposal_id: string;
|
|
44
|
-
content: {
|
|
45
|
-
"@type": string;
|
|
46
|
-
title: string;
|
|
47
|
-
description: string;
|
|
48
|
-
};
|
|
49
|
-
status: string;
|
|
50
|
-
final_tally_result: {
|
|
51
|
-
yes: string;
|
|
52
|
-
abstain: string;
|
|
53
|
-
no: string;
|
|
54
|
-
no_with_veto: string;
|
|
55
|
-
};
|
|
56
|
-
submit_time: string;
|
|
57
|
-
deposit_end_time: string;
|
|
58
|
-
total_deposit: {
|
|
59
|
-
denom: string;
|
|
60
|
-
amount: string;
|
|
61
|
-
}[];
|
|
62
|
-
voting_start_time: string;
|
|
63
|
-
voting_end_time: string;
|
|
64
|
-
}
|
|
65
35
|
export declare class GovQueryClient {
|
|
66
36
|
private readonly axios;
|
|
67
37
|
constructor(baseUrl: string);
|
|
68
38
|
queryGetCurrentVoteInfo(id: string): Promise<CurrentVoteInfo>;
|
|
69
|
-
queryGetParam(): Promise<
|
|
70
|
-
queryGetProposal(id: string): Promise<
|
|
71
|
-
queryGetProposalListByStatus(status: ProposalStatus): Promise<
|
|
72
|
-
queryGetProposalList(
|
|
39
|
+
queryGetParam(): Promise<GovParamType>;
|
|
40
|
+
queryGetProposal(id: string): Promise<Proposal>;
|
|
41
|
+
queryGetProposalListByStatus(status: ProposalStatus): Promise<Proposal[]>;
|
|
42
|
+
queryGetProposalList(pagination?: {
|
|
43
|
+
limit?: number;
|
|
44
|
+
key?: string;
|
|
45
|
+
}): Promise<Proposal[]>;
|
|
73
46
|
}
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
14
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
15
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -77,34 +88,15 @@ var GovQueryClient = /** @class */ (function () {
|
|
|
77
88
|
};
|
|
78
89
|
GovQueryClient.prototype.queryGetParam = function () {
|
|
79
90
|
return __awaiter(this, void 0, void 0, function () {
|
|
80
|
-
var path,
|
|
91
|
+
var path, result;
|
|
81
92
|
return __generator(this, function (_a) {
|
|
82
93
|
switch (_a.label) {
|
|
83
94
|
case 0:
|
|
84
|
-
path = "/cosmos/gov/
|
|
95
|
+
path = "/cosmos/gov/v1/params/deposit";
|
|
85
96
|
return [4 /*yield*/, this.axios.get(path)];
|
|
86
97
|
case 1:
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return [4 /*yield*/, this.axios.get(path)];
|
|
90
|
-
case 2:
|
|
91
|
-
depositResult = _a.sent();
|
|
92
|
-
path = "/cosmos/gov/v1beta1/params/tallying";
|
|
93
|
-
return [4 /*yield*/, this.axios.get(path)];
|
|
94
|
-
case 3:
|
|
95
|
-
tallyingResult = _a.sent();
|
|
96
|
-
return [2 /*return*/, {
|
|
97
|
-
voting_params: votingResult.data.voting_params,
|
|
98
|
-
deposit_params: depositResult.data.deposit_params,
|
|
99
|
-
tally_params: tallyingResult.data.tally_params,
|
|
100
|
-
min_initial_deposit_ratio: votingResult.data.min_initial_deposit_ratio,
|
|
101
|
-
burn_vote_quorum: votingResult.data.burn_vote_quorum,
|
|
102
|
-
burn_proposal_deposit_prevote: votingResult.data.burn_proposal_deposit_prevote,
|
|
103
|
-
burn_vote_veto: votingResult.data.burn_vote_veto,
|
|
104
|
-
expedited_voting_period: votingResult.data.expedited_voting_period,
|
|
105
|
-
expedited_threshold: votingResult.data.expedited_threshold,
|
|
106
|
-
expedited_min_deposit: votingResult.data.expedited_min_deposit
|
|
107
|
-
}];
|
|
98
|
+
result = _a.sent();
|
|
99
|
+
return [2 /*return*/, result.data.params];
|
|
108
100
|
}
|
|
109
101
|
});
|
|
110
102
|
});
|
|
@@ -115,7 +107,7 @@ var GovQueryClient = /** @class */ (function () {
|
|
|
115
107
|
return __generator(this, function (_a) {
|
|
116
108
|
switch (_a.label) {
|
|
117
109
|
case 0:
|
|
118
|
-
path = "/cosmos/gov/
|
|
110
|
+
path = "/cosmos/gov/v1/proposals/" + id;
|
|
119
111
|
return [4 /*yield*/, this.axios.get(path)];
|
|
120
112
|
case 1:
|
|
121
113
|
result = _a.sent();
|
|
@@ -130,7 +122,7 @@ var GovQueryClient = /** @class */ (function () {
|
|
|
130
122
|
return __generator(this, function (_a) {
|
|
131
123
|
switch (_a.label) {
|
|
132
124
|
case 0:
|
|
133
|
-
path = "/cosmos/gov/
|
|
125
|
+
path = "/cosmos/gov/v1/proposals";
|
|
134
126
|
return [4 /*yield*/, this.axios.get(path, { params: { proposalStatus: status } })];
|
|
135
127
|
case 1:
|
|
136
128
|
result = _a.sent();
|
|
@@ -139,14 +131,14 @@ var GovQueryClient = /** @class */ (function () {
|
|
|
139
131
|
});
|
|
140
132
|
});
|
|
141
133
|
};
|
|
142
|
-
GovQueryClient.prototype.queryGetProposalList = function () {
|
|
134
|
+
GovQueryClient.prototype.queryGetProposalList = function (pagination) {
|
|
143
135
|
return __awaiter(this, void 0, void 0, function () {
|
|
144
136
|
var path, result;
|
|
145
137
|
return __generator(this, function (_a) {
|
|
146
138
|
switch (_a.label) {
|
|
147
139
|
case 0:
|
|
148
|
-
path = "/cosmos/gov/
|
|
149
|
-
return [4 /*yield*/, this.axios.get(path)];
|
|
140
|
+
path = "/cosmos/gov/v1/proposals";
|
|
141
|
+
return [4 /*yield*/, this.axios.get(path, { params: __assign({}, pagination) })];
|
|
150
142
|
case 1:
|
|
151
143
|
result = _a.sent();
|
|
152
144
|
return [2 /*return*/, result.data.proposals];
|
|
@@ -19,6 +19,7 @@ exports.GovTxClient = void 0;
|
|
|
19
19
|
var proto_signing_1 = require("@cosmjs/proto-signing");
|
|
20
20
|
var tx_1 = require("cosmjs-types/cosmos/gov/v1beta1/tx");
|
|
21
21
|
var tx_2 = require("cosmjs-types/cosmos/gov/v1/tx");
|
|
22
|
+
// temporarly using kintsugi-tech/cosmjs-types - this will be returned to original cosmjs-types after the PR is merged
|
|
22
23
|
var tx_3 = require("@kintsugi-tech/cosmjs-types/cosmos/gov/v1/tx");
|
|
23
24
|
var ITxClient_1 = require("../common/ITxClient");
|
|
24
25
|
var types = [
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Pagination } from "../common";
|
|
2
|
-
export interface
|
|
2
|
+
export interface StakingParamType {
|
|
3
3
|
unbonding_time: string;
|
|
4
4
|
max_validators: number;
|
|
5
5
|
max_entries: number;
|
|
@@ -97,7 +97,7 @@ export declare class StakingQueryClient {
|
|
|
97
97
|
dataList: DelegationInfo[];
|
|
98
98
|
pagination: Pagination;
|
|
99
99
|
}>;
|
|
100
|
-
queryGetParams(): Promise<
|
|
100
|
+
queryGetParams(): Promise<StakingParamType>;
|
|
101
101
|
queryGetPool(): Promise<PoolDataType>;
|
|
102
102
|
queryValidator(valoperAddress: string): Promise<ValidatorDataType>;
|
|
103
103
|
queryValidators(status: string, paginationKey?: string): Promise<{
|
|
@@ -484,41 +484,19 @@ describe('[08. Gas Estimation Test]', function () {
|
|
|
484
484
|
});
|
|
485
485
|
}); });
|
|
486
486
|
it("7-3. Gov submitStakingParamsUpdateProposal gas estimation", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
487
|
-
|
|
488
|
-
return BigInt(parseFloat(decimal) * 1e18).toString();
|
|
489
|
-
}
|
|
490
|
-
function parseDuration(durationStr) {
|
|
491
|
-
var match = /^(\d+)(\.(\d+))?s$/.exec(durationStr);
|
|
492
|
-
if (!match)
|
|
493
|
-
throw new Error("Invalid duration string: " + durationStr);
|
|
494
|
-
var seconds = BigInt(match[1]);
|
|
495
|
-
var fractionalPart = match[3] || "";
|
|
496
|
-
var padded = (fractionalPart + "000000000").slice(0, 9);
|
|
497
|
-
var nanos = Number(padded);
|
|
498
|
-
return { seconds: seconds, nanos: nanos };
|
|
499
|
-
}
|
|
500
|
-
var initialDepositFCT, title, summary, stakingParmas, changeValue, unbondingData, changeStakingParams, metadata, gas;
|
|
487
|
+
var initialDepositFCT, title, summary, params, metadata, gas;
|
|
501
488
|
return __generator(this, function (_a) {
|
|
502
489
|
switch (_a.label) {
|
|
503
490
|
case 0:
|
|
504
491
|
initialDepositFCT = 5000;
|
|
505
492
|
title = "Staking parameter change proposal";
|
|
506
493
|
summary = "This is a Staking parameter change proposal";
|
|
507
|
-
return [4 /*yield*/, firma.Staking.
|
|
494
|
+
return [4 /*yield*/, firma.Staking.getParamsAsStakingParams()];
|
|
508
495
|
case 1:
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
unbondingData = parseDuration(stakingParmas.unbonding_time);
|
|
512
|
-
changeStakingParams = {
|
|
513
|
-
unbondingTime: { seconds: BigInt(unbondingData.seconds), nanos: unbondingData.nanos },
|
|
514
|
-
maxValidators: changeValue,
|
|
515
|
-
maxEntries: stakingParmas.max_entries,
|
|
516
|
-
historicalEntries: stakingParmas.historical_entries,
|
|
517
|
-
bondDenom: stakingParmas.bond_denom,
|
|
518
|
-
minCommissionRate: toDec18String(stakingParmas.min_commission_rate)
|
|
519
|
-
};
|
|
496
|
+
params = _a.sent();
|
|
497
|
+
params.maxValidators = 100;
|
|
520
498
|
metadata = "";
|
|
521
|
-
return [4 /*yield*/, firma.Gov.getGasEstimationSubmitStakingParamsUpdateProposal(aliceWallet, title, summary, initialDepositFCT,
|
|
499
|
+
return [4 /*yield*/, firma.Gov.getGasEstimationSubmitStakingParamsUpdateProposal(aliceWallet, title, summary, initialDepositFCT, params, metadata)];
|
|
522
500
|
case 2:
|
|
523
501
|
gas = _a.sent();
|
|
524
502
|
chai_1.expect(gas).to.not.equal(0);
|
|
@@ -527,42 +505,19 @@ describe('[08. Gas Estimation Test]', function () {
|
|
|
527
505
|
});
|
|
528
506
|
}); });
|
|
529
507
|
it("7-4, Gov submitGovParamsUpdateProposal gas estimation", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
530
|
-
|
|
531
|
-
var match = /^(\d+)(\.(\d+))?s$/.exec(durationStr);
|
|
532
|
-
if (!match)
|
|
533
|
-
throw new Error("Invalid duration string: " + durationStr);
|
|
534
|
-
var seconds = BigInt(match[1]);
|
|
535
|
-
var fractionalPart = match[3] || "";
|
|
536
|
-
var padded = (fractionalPart + "000000000").slice(0, 9);
|
|
537
|
-
var nanos = Number(padded);
|
|
538
|
-
return { seconds: seconds, nanos: nanos };
|
|
539
|
-
}
|
|
540
|
-
var initialDepositFCT, title, summary, govParams, convertMaxDepositPeriod, convertVotingPeriod, changeGovParams, metadata, gas;
|
|
508
|
+
var initialDepositFCT, title, summary, params, metadata, gas;
|
|
541
509
|
return __generator(this, function (_a) {
|
|
542
510
|
switch (_a.label) {
|
|
543
511
|
case 0:
|
|
544
512
|
initialDepositFCT = 5000;
|
|
545
513
|
title = "Gov parameter change proposal";
|
|
546
514
|
summary = "This is a Gov parameter change proposal";
|
|
547
|
-
return [4 /*yield*/, firma.Gov.
|
|
515
|
+
return [4 /*yield*/, firma.Gov.getParamAsGovParams()];
|
|
548
516
|
case 1:
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
convertVotingPeriod = parseDuration(govParams.voting_params.voting_period);
|
|
552
|
-
changeGovParams = {
|
|
553
|
-
minDeposit: govParams.deposit_params.min_deposit,
|
|
554
|
-
maxDepositPeriod: convertMaxDepositPeriod,
|
|
555
|
-
votingPeriod: convertVotingPeriod,
|
|
556
|
-
quorum: govParams.tally_params.quorum,
|
|
557
|
-
threshold: govParams.tally_params.threshold,
|
|
558
|
-
vetoThreshold: govParams.tally_params.veto_threshold,
|
|
559
|
-
minInitialDepositRatio: govParams.min_initial_deposit_ratio,
|
|
560
|
-
burnVoteQuorum: govParams.burn_vote_quorum,
|
|
561
|
-
burnProposalDepositPrevote: govParams.burn_proposal_deposit_prevote,
|
|
562
|
-
burnVoteVeto: govParams.burn_vote_veto
|
|
563
|
-
};
|
|
517
|
+
params = _a.sent();
|
|
518
|
+
params.burnProposalDepositPrevote = true;
|
|
564
519
|
metadata = "";
|
|
565
|
-
return [4 /*yield*/, firma.Gov.getGasEstimationSubmitGovParamsUpdateProposal(aliceWallet, title, summary, initialDepositFCT,
|
|
520
|
+
return [4 /*yield*/, firma.Gov.getGasEstimationSubmitGovParamsUpdateProposal(aliceWallet, title, summary, initialDepositFCT, params, metadata)];
|
|
566
521
|
case 2:
|
|
567
522
|
gas = _a.sent();
|
|
568
523
|
chai_1.expect(gas).to.not.equal(0);
|
|
@@ -137,6 +137,18 @@ describe('[13. Staking Query Test]', function () {
|
|
|
137
137
|
}
|
|
138
138
|
});
|
|
139
139
|
}); });
|
|
140
|
+
it('6-1.get getParamsAsStakingParams', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
141
|
+
var result;
|
|
142
|
+
return __generator(this, function (_a) {
|
|
143
|
+
switch (_a.label) {
|
|
144
|
+
case 0: return [4 /*yield*/, firma.Staking.getParamsAsStakingParams()];
|
|
145
|
+
case 1:
|
|
146
|
+
result = _a.sent();
|
|
147
|
+
chai_1.expect(result.maxValidators).to.not.equal(0);
|
|
148
|
+
return [2 /*return*/];
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}); });
|
|
140
152
|
// user side
|
|
141
153
|
it('7.get userside getTotalDelegationInfo', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
142
154
|
var wallet, result, _a, _b;
|
|
@@ -50,6 +50,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
50
50
|
var chai_1 = require("chai");
|
|
51
51
|
var common_1 = require("../sdk/firmachain/common");
|
|
52
52
|
var FirmaSDK_1 = require("../sdk/FirmaSDK");
|
|
53
|
+
var FirmaUtil_1 = require("../sdk/FirmaUtil");
|
|
53
54
|
var config_test_1 = require("./config_test");
|
|
54
55
|
// If test it, the properties of the chain change, so skip it.
|
|
55
56
|
describe('[16. Gov Tx Test]', function () {
|
|
@@ -153,41 +154,21 @@ describe('[16. Gov Tx Test]', function () {
|
|
|
153
154
|
});
|
|
154
155
|
}); });
|
|
155
156
|
it('SubmitStakingParamsUpdateProposal Test', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
156
|
-
|
|
157
|
-
return BigInt(parseFloat(decimal) * 1e18).toString();
|
|
158
|
-
}
|
|
159
|
-
function parseDuration(durationStr) {
|
|
160
|
-
var match = /^(\d+)(\.(\d+))?s$/.exec(durationStr);
|
|
161
|
-
if (!match)
|
|
162
|
-
throw new Error("Invalid duration string: " + durationStr);
|
|
163
|
-
var seconds = BigInt(match[1]);
|
|
164
|
-
var fractionalPart = match[3] || "";
|
|
165
|
-
var padded = (fractionalPart + "000000000").slice(0, 9);
|
|
166
|
-
var nanos = Number(padded);
|
|
167
|
-
return { seconds: seconds, nanos: nanos };
|
|
168
|
-
}
|
|
169
|
-
var title, summary, initialDepositFCT, stakingParmas, changeValue, unbondingData, changeStakingParams, metadata, result;
|
|
157
|
+
var title, summary, initialDepositFCT, params, metadata, result;
|
|
170
158
|
return __generator(this, function (_a) {
|
|
171
159
|
switch (_a.label) {
|
|
172
160
|
case 0:
|
|
173
161
|
title = "Staking Parameter Change proposal";
|
|
174
162
|
summary = "This is a Staking Parameter change proposal";
|
|
175
163
|
initialDepositFCT = 2500;
|
|
176
|
-
return [4 /*yield*/, firma.Staking.
|
|
164
|
+
return [4 /*yield*/, firma.Staking.getParamsAsStakingParams()];
|
|
177
165
|
case 1:
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
unbondingTime: { seconds: BigInt(unbondingData.seconds), nanos: unbondingData.nanos },
|
|
183
|
-
maxValidators: changeValue,
|
|
184
|
-
maxEntries: stakingParmas.max_entries,
|
|
185
|
-
historicalEntries: stakingParmas.historical_entries,
|
|
186
|
-
bondDenom: stakingParmas.bond_denom,
|
|
187
|
-
minCommissionRate: toDec18String(stakingParmas.min_commission_rate)
|
|
188
|
-
};
|
|
166
|
+
params = _a.sent();
|
|
167
|
+
params.maxValidators = 100;
|
|
168
|
+
params.historicalEntries = 10000;
|
|
169
|
+
params.minCommissionRate = FirmaUtil_1.FirmaUtil.processCommissionRateAsDecimal(params.minCommissionRate);
|
|
189
170
|
metadata = "";
|
|
190
|
-
return [4 /*yield*/, firma.Gov.submitStakingParamsUpdateProposal(aliceWallet, title, summary, initialDepositFCT,
|
|
171
|
+
return [4 /*yield*/, firma.Gov.submitStakingParamsUpdateProposal(aliceWallet, title, summary, initialDepositFCT, params, metadata)];
|
|
191
172
|
case 2:
|
|
192
173
|
result = _a.sent();
|
|
193
174
|
chai_1.expect(result.code).to.equal(0);
|
|
@@ -196,42 +177,19 @@ describe('[16. Gov Tx Test]', function () {
|
|
|
196
177
|
});
|
|
197
178
|
}); });
|
|
198
179
|
it('SubmitGovParamsUpdateProposal Test', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
199
|
-
|
|
200
|
-
var match = /^(\d+)(\.(\d+))?s$/.exec(durationStr);
|
|
201
|
-
if (!match)
|
|
202
|
-
throw new Error("Invalid duration string: " + durationStr);
|
|
203
|
-
var seconds = BigInt(match[1]);
|
|
204
|
-
var fractionalPart = match[3] || "";
|
|
205
|
-
var padded = (fractionalPart + "000000000").slice(0, 9);
|
|
206
|
-
var nanos = Number(padded);
|
|
207
|
-
return { seconds: seconds, nanos: nanos };
|
|
208
|
-
}
|
|
209
|
-
var title, summary, initialDepositFCT, govParams, convertMaxDepositPeriod, convertVotingPeriod, changeGovParams, metadata, result;
|
|
180
|
+
var title, summary, initialDepositFCT, params, metadata, result;
|
|
210
181
|
return __generator(this, function (_a) {
|
|
211
182
|
switch (_a.label) {
|
|
212
183
|
case 0:
|
|
213
|
-
title = "
|
|
214
|
-
summary = "This is a
|
|
184
|
+
title = "Gov Parameter Change proposal";
|
|
185
|
+
summary = "This is a Gov Parameter change proposal";
|
|
215
186
|
initialDepositFCT = 2500;
|
|
216
|
-
return [4 /*yield*/, firma.Gov.
|
|
187
|
+
return [4 /*yield*/, firma.Gov.getParamAsGovParams()];
|
|
217
188
|
case 1:
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
convertVotingPeriod = parseDuration(govParams.voting_params.voting_period);
|
|
221
|
-
changeGovParams = {
|
|
222
|
-
minDeposit: govParams.deposit_params.min_deposit,
|
|
223
|
-
maxDepositPeriod: convertMaxDepositPeriod,
|
|
224
|
-
votingPeriod: convertVotingPeriod,
|
|
225
|
-
quorum: govParams.tally_params.quorum,
|
|
226
|
-
threshold: govParams.tally_params.threshold,
|
|
227
|
-
vetoThreshold: govParams.tally_params.veto_threshold,
|
|
228
|
-
minInitialDepositRatio: govParams.min_initial_deposit_ratio,
|
|
229
|
-
burnVoteQuorum: govParams.burn_vote_quorum,
|
|
230
|
-
burnProposalDepositPrevote: govParams.burn_proposal_deposit_prevote,
|
|
231
|
-
burnVoteVeto: govParams.burn_vote_veto
|
|
232
|
-
};
|
|
189
|
+
params = _a.sent();
|
|
190
|
+
params.burnProposalDepositPrevote = true;
|
|
233
191
|
metadata = "";
|
|
234
|
-
return [4 /*yield*/, firma.Gov.submitGovParamsUpdateProposal(aliceWallet, title, summary, initialDepositFCT,
|
|
192
|
+
return [4 /*yield*/, firma.Gov.submitGovParamsUpdateProposal(aliceWallet, title, summary, initialDepositFCT, params, metadata)];
|
|
235
193
|
case 2:
|
|
236
194
|
result = _a.sent();
|
|
237
195
|
chai_1.expect(result.code).to.equal(0);
|
|
@@ -245,7 +203,7 @@ describe('[16. Gov Tx Test]', function () {
|
|
|
245
203
|
switch (_a.label) {
|
|
246
204
|
case 0:
|
|
247
205
|
initialDeposit = 5000;
|
|
248
|
-
title = "
|
|
206
|
+
title = "Software upgrade proposal";
|
|
249
207
|
summary = "This is a Text & CancelProposal";
|
|
250
208
|
plan = {
|
|
251
209
|
name: 'v0.5.1',
|
|
@@ -377,4 +335,60 @@ describe('[16. Gov Tx Test]', function () {
|
|
|
377
335
|
}
|
|
378
336
|
});
|
|
379
337
|
}); });
|
|
338
|
+
it('SubmitGovParamsUpdateProposal Test - failure case (missing parameter)', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
339
|
+
var title, summary, initialDeposit, proposalParams, metadata, errorMsg, error_1;
|
|
340
|
+
return __generator(this, function (_a) {
|
|
341
|
+
switch (_a.label) {
|
|
342
|
+
case 0:
|
|
343
|
+
title = "Gov Parameter Change fail proposal";
|
|
344
|
+
summary = "This is a Gov Parameter change proposal";
|
|
345
|
+
initialDeposit = 5000;
|
|
346
|
+
proposalParams = {
|
|
347
|
+
burnVoteQuorum: false
|
|
348
|
+
};
|
|
349
|
+
metadata = "";
|
|
350
|
+
errorMsg = "All governance parameters must be provided. Use getParamAsGovParams() to get current values and override only the parameters you want to change.";
|
|
351
|
+
_a.label = 1;
|
|
352
|
+
case 1:
|
|
353
|
+
_a.trys.push([1, 3, , 4]);
|
|
354
|
+
return [4 /*yield*/, firma.Gov.submitGovParamsUpdateProposal(aliceWallet, title, summary, initialDeposit, proposalParams, metadata)];
|
|
355
|
+
case 2:
|
|
356
|
+
_a.sent();
|
|
357
|
+
return [3 /*break*/, 4];
|
|
358
|
+
case 3:
|
|
359
|
+
error_1 = _a.sent();
|
|
360
|
+
chai_1.expect(error_1.message).to.equal(errorMsg);
|
|
361
|
+
return [3 /*break*/, 4];
|
|
362
|
+
case 4: return [2 /*return*/];
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
}); });
|
|
366
|
+
it('SubmitStakingParamsUpdateProposal Test - failure case (missing parameter)', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
367
|
+
var title, summary, initialDeposit, proposalParams, metadata, errorMsg, error_2;
|
|
368
|
+
return __generator(this, function (_a) {
|
|
369
|
+
switch (_a.label) {
|
|
370
|
+
case 0:
|
|
371
|
+
title = "Staking Parameter Change fail proposal";
|
|
372
|
+
summary = "This is a Staking Parameter change proposal";
|
|
373
|
+
initialDeposit = 5000;
|
|
374
|
+
proposalParams = {
|
|
375
|
+
maxValidators: 100
|
|
376
|
+
};
|
|
377
|
+
metadata = "";
|
|
378
|
+
errorMsg = "All staking parameters must be provided. Use Staking.getParamsAsStakingParams() to get current values and override only the parameters you want to change.";
|
|
379
|
+
_a.label = 1;
|
|
380
|
+
case 1:
|
|
381
|
+
_a.trys.push([1, 3, , 4]);
|
|
382
|
+
return [4 /*yield*/, firma.Gov.submitStakingParamsUpdateProposal(aliceWallet, title, summary, initialDeposit, proposalParams, metadata)];
|
|
383
|
+
case 2:
|
|
384
|
+
_a.sent();
|
|
385
|
+
return [3 /*break*/, 4];
|
|
386
|
+
case 3:
|
|
387
|
+
error_2 = _a.sent();
|
|
388
|
+
chai_1.expect(error_2.message).to.equal(errorMsg);
|
|
389
|
+
return [3 /*break*/, 4];
|
|
390
|
+
case 4: return [2 /*return*/];
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
}); });
|
|
380
394
|
});
|