@firmachain/firma-js 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +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 +36 -0
- package/dist/sdk/FirmaUtil.js +139 -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 +69 -57
- package/dist/test/17.gov_query.test.js +18 -18
- package/dist/test/18.util.test.js +74 -0
- package/dist/test/20.slashing_query.test.js +0 -1
- package/dist/test/config_test.js +8 -0
- package/package.json +1 -1
package/dist/sdk/FirmaUtil.js
CHANGED
|
@@ -456,6 +456,145 @@ var FirmaUtil = /** @class */ (function () {
|
|
|
456
456
|
FirmaUtil.getCommonTxClient = function (aliceWallet) {
|
|
457
457
|
return new CommonTxClient_1.CommonTxClient(aliceWallet, FirmaUtil.config.rpcAddress);
|
|
458
458
|
};
|
|
459
|
+
/**
|
|
460
|
+
* Parses a duration string to a Duration object.
|
|
461
|
+
* Supports formats like "336h0m0s", "21d", "1000ms", "1s", "1m", "1h", "1ns", "1µs"/"1us"
|
|
462
|
+
*
|
|
463
|
+
* @param durationStr - Duration string to parse (e.g., "336h0m0s", "21d")
|
|
464
|
+
* @returns Duration object with seconds and nanos fields
|
|
465
|
+
*/
|
|
466
|
+
FirmaUtil.parseDurationString = function (durationStr) {
|
|
467
|
+
if (!durationStr || durationStr.trim() === "") {
|
|
468
|
+
return { seconds: BigInt(0), nanos: 0 };
|
|
469
|
+
}
|
|
470
|
+
var input = durationStr.trim();
|
|
471
|
+
var totalSeconds = 0;
|
|
472
|
+
var totalNanos = 0;
|
|
473
|
+
// Handle negative durations
|
|
474
|
+
var isNegative = input.startsWith('-');
|
|
475
|
+
var cleanInput = isNegative ? input.substring(1) : input;
|
|
476
|
+
// Regular expression to match duration components
|
|
477
|
+
var regex = /(\d+(?:\.\d+)?)(d|h|m|s|ms|µs|us|ns)/g;
|
|
478
|
+
var match;
|
|
479
|
+
var hasMatches = false;
|
|
480
|
+
while ((match = regex.exec(cleanInput)) !== null) {
|
|
481
|
+
hasMatches = true;
|
|
482
|
+
var value = parseFloat(match[1]);
|
|
483
|
+
var unit = match[2];
|
|
484
|
+
switch (unit) {
|
|
485
|
+
case 'd': // days
|
|
486
|
+
totalSeconds += value * 24 * 60 * 60;
|
|
487
|
+
break;
|
|
488
|
+
case 'h': // hours
|
|
489
|
+
totalSeconds += value * 60 * 60;
|
|
490
|
+
break;
|
|
491
|
+
case 'm': // minutes
|
|
492
|
+
totalSeconds += value * 60;
|
|
493
|
+
break;
|
|
494
|
+
case 's': // seconds
|
|
495
|
+
totalSeconds += value;
|
|
496
|
+
break;
|
|
497
|
+
case 'ms': // milliseconds
|
|
498
|
+
totalNanos += value * 1000000;
|
|
499
|
+
break;
|
|
500
|
+
case 'µs':
|
|
501
|
+
case 'us': // microseconds
|
|
502
|
+
totalNanos += value * 1000;
|
|
503
|
+
break;
|
|
504
|
+
case 'ns': // nanoseconds
|
|
505
|
+
totalNanos += value;
|
|
506
|
+
break;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
if (!hasMatches) {
|
|
510
|
+
throw new Error("Invalid duration format: " + durationStr);
|
|
511
|
+
}
|
|
512
|
+
// Convert excess nanos to seconds
|
|
513
|
+
var extraSeconds = Math.floor(totalNanos / 1000000000);
|
|
514
|
+
totalSeconds += extraSeconds;
|
|
515
|
+
totalNanos = totalNanos % 1000000000;
|
|
516
|
+
// Apply negative sign
|
|
517
|
+
var finalSeconds = isNegative ? -totalSeconds : totalSeconds;
|
|
518
|
+
var finalNanos = isNegative ? -totalNanos : totalNanos;
|
|
519
|
+
return {
|
|
520
|
+
seconds: BigInt(Math.floor(finalSeconds)),
|
|
521
|
+
nanos: Math.floor(finalNanos)
|
|
522
|
+
};
|
|
523
|
+
};
|
|
524
|
+
/**
|
|
525
|
+
* Creates a Duration object from a duration string.
|
|
526
|
+
* This is a convenience method that combines parseDurationString with Duration.fromPartial.
|
|
527
|
+
*
|
|
528
|
+
* @param durationStr - Duration string to parse (e.g., "336h0m0s", "21d")
|
|
529
|
+
* @returns Duration object ready to use with protobuf
|
|
530
|
+
*/
|
|
531
|
+
FirmaUtil.createDurationFromString = function (durationStr) {
|
|
532
|
+
var _a = FirmaUtil.parseDurationString(durationStr), seconds = _a.seconds, nanos = _a.nanos;
|
|
533
|
+
// Import Duration if not already imported
|
|
534
|
+
var Duration = require("./firmachain/google/protobuf/duration").Duration;
|
|
535
|
+
return Duration.fromPartial({
|
|
536
|
+
seconds: seconds,
|
|
537
|
+
nanos: nanos
|
|
538
|
+
});
|
|
539
|
+
};
|
|
540
|
+
/**
|
|
541
|
+
* Normalizes decimal string for Cosmos SDK usage.
|
|
542
|
+
* Converts "0.000000000000000000" to empty string to avoid big.Int conversion errors.
|
|
543
|
+
*
|
|
544
|
+
* @param decimalStr - Decimal string that might cause big.Int conversion issues
|
|
545
|
+
* @returns Normalized string safe for Cosmos SDK usage
|
|
546
|
+
*/
|
|
547
|
+
FirmaUtil.normalizeDecimalString = function (decimalStr) {
|
|
548
|
+
if (!decimalStr || decimalStr.trim() === "") {
|
|
549
|
+
return "";
|
|
550
|
+
}
|
|
551
|
+
var trimmed = decimalStr.trim();
|
|
552
|
+
// Check if it's a valid decimal number
|
|
553
|
+
if (!/^-?\d*\.?\d*$/.test(trimmed)) {
|
|
554
|
+
return trimmed; // Return as-is if not a valid decimal
|
|
555
|
+
}
|
|
556
|
+
try {
|
|
557
|
+
var num = parseFloat(trimmed);
|
|
558
|
+
// If the number is 0 or very close to 0, return empty string
|
|
559
|
+
if (num === 0 || Math.abs(num) < 1e-18) {
|
|
560
|
+
return "";
|
|
561
|
+
}
|
|
562
|
+
// For non-zero values, return the original string
|
|
563
|
+
return trimmed;
|
|
564
|
+
}
|
|
565
|
+
catch (error) {
|
|
566
|
+
// If parsing fails, return the original string
|
|
567
|
+
return trimmed;
|
|
568
|
+
}
|
|
569
|
+
};
|
|
570
|
+
/**
|
|
571
|
+
* Safely processes commission rate strings to prevent big.Int conversion errors.
|
|
572
|
+
* This is specifically for handling commission rates that might be "0.000000000000000000".
|
|
573
|
+
*
|
|
574
|
+
* @param commissionRate - Commission rate string from staking params
|
|
575
|
+
* @returns Processed commission rate string safe for protobuf usage
|
|
576
|
+
*/
|
|
577
|
+
FirmaUtil.processCommissionRate = function (commissionRate) {
|
|
578
|
+
if (!commissionRate || commissionRate.trim() === "") {
|
|
579
|
+
return "";
|
|
580
|
+
}
|
|
581
|
+
var normalized = FirmaUtil.normalizeDecimalString(commissionRate);
|
|
582
|
+
// For commission rates, if it's effectively zero, return empty string
|
|
583
|
+
if (normalized === "") {
|
|
584
|
+
return "";
|
|
585
|
+
}
|
|
586
|
+
// Ensure the value is within valid commission rate range (0-1)
|
|
587
|
+
try {
|
|
588
|
+
var rate = parseFloat(normalized);
|
|
589
|
+
if (rate < 0 || rate > 1) {
|
|
590
|
+
throw new Error("Invalid commission rate: " + commissionRate + ". Must be between 0 and 1");
|
|
591
|
+
}
|
|
592
|
+
return normalized;
|
|
593
|
+
}
|
|
594
|
+
catch (error) {
|
|
595
|
+
throw new Error("Invalid commission rate format: " + commissionRate);
|
|
596
|
+
}
|
|
597
|
+
};
|
|
459
598
|
FirmaUtil.FctDecimal = 6;
|
|
460
599
|
return FirmaUtil;
|
|
461
600
|
}());
|
|
@@ -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;
|
|
@@ -153,41 +153,20 @@ describe('[16. Gov Tx Test]', function () {
|
|
|
153
153
|
});
|
|
154
154
|
}); });
|
|
155
155
|
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;
|
|
156
|
+
var title, summary, initialDepositFCT, params, metadata, result;
|
|
170
157
|
return __generator(this, function (_a) {
|
|
171
158
|
switch (_a.label) {
|
|
172
159
|
case 0:
|
|
173
160
|
title = "Staking Parameter Change proposal";
|
|
174
161
|
summary = "This is a Staking Parameter change proposal";
|
|
175
162
|
initialDepositFCT = 2500;
|
|
176
|
-
return [4 /*yield*/, firma.Staking.
|
|
163
|
+
return [4 /*yield*/, firma.Staking.getParamsAsStakingParams()];
|
|
177
164
|
case 1:
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
changeStakingParams = {
|
|
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
|
-
};
|
|
165
|
+
params = _a.sent();
|
|
166
|
+
params.maxValidators = 100;
|
|
167
|
+
params.historicalEntries = 10000;
|
|
189
168
|
metadata = "";
|
|
190
|
-
return [4 /*yield*/, firma.Gov.submitStakingParamsUpdateProposal(aliceWallet, title, summary, initialDepositFCT,
|
|
169
|
+
return [4 /*yield*/, firma.Gov.submitStakingParamsUpdateProposal(aliceWallet, title, summary, initialDepositFCT, params, metadata)];
|
|
191
170
|
case 2:
|
|
192
171
|
result = _a.sent();
|
|
193
172
|
chai_1.expect(result.code).to.equal(0);
|
|
@@ -196,42 +175,19 @@ describe('[16. Gov Tx Test]', function () {
|
|
|
196
175
|
});
|
|
197
176
|
}); });
|
|
198
177
|
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;
|
|
178
|
+
var title, summary, initialDepositFCT, params, metadata, result;
|
|
210
179
|
return __generator(this, function (_a) {
|
|
211
180
|
switch (_a.label) {
|
|
212
181
|
case 0:
|
|
213
|
-
title = "
|
|
214
|
-
summary = "This is a
|
|
182
|
+
title = "Gov Parameter Change proposal";
|
|
183
|
+
summary = "This is a Gov Parameter change proposal";
|
|
215
184
|
initialDepositFCT = 2500;
|
|
216
|
-
return [4 /*yield*/, firma.Gov.
|
|
185
|
+
return [4 /*yield*/, firma.Gov.getParamAsGovParams()];
|
|
217
186
|
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
|
-
};
|
|
187
|
+
params = _a.sent();
|
|
188
|
+
params.burnProposalDepositPrevote = true;
|
|
233
189
|
metadata = "";
|
|
234
|
-
return [4 /*yield*/, firma.Gov.submitGovParamsUpdateProposal(aliceWallet, title, summary, initialDepositFCT,
|
|
190
|
+
return [4 /*yield*/, firma.Gov.submitGovParamsUpdateProposal(aliceWallet, title, summary, initialDepositFCT, params, metadata)];
|
|
235
191
|
case 2:
|
|
236
192
|
result = _a.sent();
|
|
237
193
|
chai_1.expect(result.code).to.equal(0);
|
|
@@ -377,4 +333,60 @@ describe('[16. Gov Tx Test]', function () {
|
|
|
377
333
|
}
|
|
378
334
|
});
|
|
379
335
|
}); });
|
|
336
|
+
it('SubmitGovParamsUpdateProposal Test - failure case (missing parameter)', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
337
|
+
var title, summary, initialDeposit, proposalParams, metadata, errorMsg, error_1;
|
|
338
|
+
return __generator(this, function (_a) {
|
|
339
|
+
switch (_a.label) {
|
|
340
|
+
case 0:
|
|
341
|
+
title = "Gov Parameter Change fail proposal";
|
|
342
|
+
summary = "This is a Gov Parameter change proposal";
|
|
343
|
+
initialDeposit = 5000;
|
|
344
|
+
proposalParams = {
|
|
345
|
+
burnVoteQuorum: false
|
|
346
|
+
};
|
|
347
|
+
metadata = "";
|
|
348
|
+
errorMsg = "All governance parameters must be provided. Use getParamAsGovParams() to get current values and override only the parameters you want to change.";
|
|
349
|
+
_a.label = 1;
|
|
350
|
+
case 1:
|
|
351
|
+
_a.trys.push([1, 3, , 4]);
|
|
352
|
+
return [4 /*yield*/, firma.Gov.submitGovParamsUpdateProposal(aliceWallet, title, summary, initialDeposit, proposalParams, metadata)];
|
|
353
|
+
case 2:
|
|
354
|
+
_a.sent();
|
|
355
|
+
return [3 /*break*/, 4];
|
|
356
|
+
case 3:
|
|
357
|
+
error_1 = _a.sent();
|
|
358
|
+
chai_1.expect(error_1.message).to.equal(errorMsg);
|
|
359
|
+
return [3 /*break*/, 4];
|
|
360
|
+
case 4: return [2 /*return*/];
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
}); });
|
|
364
|
+
it('SubmitStakingParamsUpdateProposal Test - failure case (missing parameter)', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
365
|
+
var title, summary, initialDeposit, proposalParams, metadata, errorMsg, error_2;
|
|
366
|
+
return __generator(this, function (_a) {
|
|
367
|
+
switch (_a.label) {
|
|
368
|
+
case 0:
|
|
369
|
+
title = "Staking Parameter Change fail proposal";
|
|
370
|
+
summary = "This is a Staking Parameter change proposal";
|
|
371
|
+
initialDeposit = 5000;
|
|
372
|
+
proposalParams = {
|
|
373
|
+
maxValidators: 100
|
|
374
|
+
};
|
|
375
|
+
metadata = "";
|
|
376
|
+
errorMsg = "All staking parameters must be provided. Use Staking.getParamsAsStakingParams() to get current values and override only the parameters you want to change.";
|
|
377
|
+
_a.label = 1;
|
|
378
|
+
case 1:
|
|
379
|
+
_a.trys.push([1, 3, , 4]);
|
|
380
|
+
return [4 /*yield*/, firma.Gov.submitStakingParamsUpdateProposal(aliceWallet, title, summary, initialDeposit, proposalParams, metadata)];
|
|
381
|
+
case 2:
|
|
382
|
+
_a.sent();
|
|
383
|
+
return [3 /*break*/, 4];
|
|
384
|
+
case 3:
|
|
385
|
+
error_2 = _a.sent();
|
|
386
|
+
chai_1.expect(error_2.message).to.equal(errorMsg);
|
|
387
|
+
return [3 /*break*/, 4];
|
|
388
|
+
case 4: return [2 /*return*/];
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
}); });
|
|
380
392
|
});
|