@firmachain/firma-js 0.3.7 → 0.4.0-beta1

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.
Files changed (128) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +1 -0
  3. package/dist/sdk/FirmaAuthzService.js +20 -15
  4. package/dist/sdk/FirmaBankService.d.ts +1 -1
  5. package/dist/sdk/FirmaBankService.js +5 -4
  6. package/dist/sdk/FirmaConfig.js +4 -4
  7. package/dist/sdk/FirmaContractService.js +10 -8
  8. package/dist/sdk/FirmaDistributionService.js +37 -22
  9. package/dist/sdk/FirmaFeeGrantService.d.ts +0 -1
  10. package/dist/sdk/FirmaFeeGrantService.js +12 -14
  11. package/dist/sdk/FirmaGovService.d.ts +14 -0
  12. package/dist/sdk/FirmaGovService.js +74 -47
  13. package/dist/sdk/FirmaIbcService.js +4 -3
  14. package/dist/sdk/FirmaNftService.d.ts +3 -3
  15. package/dist/sdk/FirmaNftService.js +13 -10
  16. package/dist/sdk/FirmaStakingService.js +12 -9
  17. package/dist/sdk/FirmaTokenService.js +17 -14
  18. package/dist/sdk/FirmaUtil.js +1 -1
  19. package/dist/sdk/FirmaWalletService.d.ts +1 -1
  20. package/dist/sdk/FirmaWalletService.js +11 -23
  21. package/dist/sdk/firmachain/authz/AuthzTxClient.js +2 -0
  22. package/dist/sdk/firmachain/bank/BankTxClient.js +1 -1
  23. package/dist/sdk/firmachain/common/CommonTxClient.js +3 -1
  24. package/dist/sdk/firmachain/common/FirmaLedger.d.ts +49 -0
  25. package/dist/sdk/firmachain/common/FirmaLedger.js +301 -0
  26. package/dist/sdk/firmachain/common/ITxClient.d.ts +1 -1
  27. package/dist/sdk/firmachain/common/ITxClient.js +6 -4
  28. package/dist/sdk/firmachain/common/LedgerWallet.d.ts +5 -13
  29. package/dist/sdk/firmachain/common/LedgerWallet.js +1266 -124
  30. package/dist/sdk/firmachain/common/SigningProtobufStargateClient.js +3 -4
  31. package/dist/sdk/firmachain/common/SigningStargateClient.d.ts +2 -3
  32. package/dist/sdk/firmachain/common/SigningStargateClient.js +7 -10
  33. package/dist/sdk/firmachain/common/index.d.ts +1 -0
  34. package/dist/sdk/firmachain/common/index.js +1 -0
  35. package/dist/sdk/firmachain/common/signing.d.ts +4 -10
  36. package/dist/sdk/firmachain/common/signing.js +13 -60
  37. package/dist/sdk/firmachain/contract/ContractTxClient.js +1 -1
  38. package/dist/sdk/firmachain/contract/ContractTxTypes.js +54 -8
  39. package/dist/sdk/firmachain/distribution/DistributionTxClient.js +1 -1
  40. package/dist/sdk/firmachain/feegrant/FeeGrantTxClient.js +3 -1
  41. package/dist/sdk/firmachain/feegrant/FeeGrantTxTypes.d.ts +1 -2
  42. package/dist/sdk/firmachain/google/protobuf/any.js +0 -12
  43. package/dist/sdk/firmachain/gov/GovTxClient.js +3 -0
  44. package/dist/sdk/firmachain/nft/NftTxClient.js +1 -1
  45. package/dist/sdk/firmachain/token/TokenTxClient.js +1 -1
  46. package/package.json +16 -8
  47. package/dist/test/00.wallet.test.d.ts +0 -1
  48. package/dist/test/00.wallet.test.js +0 -96
  49. package/dist/test/01.contract_tx.test.d.ts +0 -1
  50. package/dist/test/01.contract_tx.test.js +0 -157
  51. package/dist/test/02.contract_query.test.d.ts +0 -1
  52. package/dist/test/02.contract_query.test.js +0 -245
  53. package/dist/test/03.contract_scenario.test.d.ts +0 -1
  54. package/dist/test/03.contract_scenario.test.js +0 -406
  55. package/dist/test/04.bank_tx.test.d.ts +0 -1
  56. package/dist/test/04.bank_tx.test.js +0 -126
  57. package/dist/test/05.bank_query.test.d.ts +0 -1
  58. package/dist/test/05.bank_query.test.js +0 -162
  59. package/dist/test/06.feegrant_tx.test.d.ts +0 -1
  60. package/dist/test/06.feegrant_tx.test.js +0 -185
  61. package/dist/test/07.feegrant_query.test.d.ts +0 -1
  62. package/dist/test/07.feegrant_query.test.js +0 -129
  63. package/dist/test/08.gas_estimate.test.d.ts +0 -1
  64. package/dist/test/08.gas_estimate.test.js +0 -728
  65. package/dist/test/09.ipfs.test.d.ts +0 -1
  66. package/dist/test/09.ipfs.test.js +0 -72
  67. package/dist/test/10.nft_tx.test.d.ts +0 -1
  68. package/dist/test/10.nft_tx.test.js +0 -209
  69. package/dist/test/11.nft_query.test.d.ts +0 -1
  70. package/dist/test/11.nft_query.test.js +0 -165
  71. package/dist/test/12.staking_tx.test.d.ts +0 -1
  72. package/dist/test/12.staking_tx.test.js +0 -211
  73. package/dist/test/13.staking_query.test.d.ts +0 -1
  74. package/dist/test/13.staking_query.test.js +0 -275
  75. package/dist/test/14.distribution_tx.test.d.ts +0 -1
  76. package/dist/test/14.distribution_tx.test.js +0 -170
  77. package/dist/test/15.distribution_query.test.d.ts +0 -1
  78. package/dist/test/15.distribution_query.test.js +0 -243
  79. package/dist/test/16.gov_tx.test.d.ts +0 -1
  80. package/dist/test/16.gov_tx.test.js +0 -396
  81. package/dist/test/17.gov_query.test.d.ts +0 -1
  82. package/dist/test/17.gov_query.test.js +0 -181
  83. package/dist/test/18.util.test.d.ts +0 -1
  84. package/dist/test/18.util.test.js +0 -354
  85. package/dist/test/19.chain.test.d.ts +0 -1
  86. package/dist/test/19.chain.test.js +0 -127
  87. package/dist/test/20.slashing_query.test.d.ts +0 -1
  88. package/dist/test/20.slashing_query.test.js +0 -111
  89. package/dist/test/21.token_tx.test.d.ts +0 -1
  90. package/dist/test/21.token_tx.test.js +0 -149
  91. package/dist/test/22.token_query.test.d.ts +0 -1
  92. package/dist/test/22.token_query.test.js +0 -103
  93. package/dist/test/23.authz_tx.test.d.ts +0 -1
  94. package/dist/test/23.authz_tx.test.js +0 -380
  95. package/dist/test/24.authz_query.test.d.ts +0 -1
  96. package/dist/test/24.authz_query.test.js +0 -202
  97. package/dist/test/25.cosmwasm_tx.test.d.ts +0 -1
  98. package/dist/test/25.cosmwasm_tx.test.js +0 -229
  99. package/dist/test/26.cosmwasm_query.test.d.ts +0 -1
  100. package/dist/test/26.cosmwasm_query.test.js +0 -275
  101. package/dist/test/27.arbitrary_sign.test.d.ts +0 -1
  102. package/dist/test/27.arbitrary_sign.test.js +0 -162
  103. package/dist/test/28.ibc_tx.test.d.ts +0 -1
  104. package/dist/test/28.ibc_tx.test.js +0 -98
  105. package/dist/test/29.mint_query.test.d.ts +0 -1
  106. package/dist/test/29.mint_query.test.js +0 -59
  107. package/dist/test/30.cw20_tx.test.d.ts +0 -1
  108. package/dist/test/30.cw20_tx.test.js +0 -450
  109. package/dist/test/31.cw20_query.test.d.ts +0 -1
  110. package/dist/test/31.cw20_query.test.js +0 -333
  111. package/dist/test/32.cw721_tx.test.d.ts +0 -1
  112. package/dist/test/32.cw721_tx.test.js +0 -431
  113. package/dist/test/33.cw721_query.test.d.ts +0 -1
  114. package/dist/test/33.cw721_query.test.js +0 -371
  115. package/dist/test/34.cw_bridge_tx.test.d.ts +0 -1
  116. package/dist/test/34.cw_bridge_tx.test.js +0 -476
  117. package/dist/test/35.cw_bridge_tx_low.test.d.ts +0 -1
  118. package/dist/test/35.cw_bridge_tx_low.test.js +0 -398
  119. package/dist/test/36.cw_bridge_query.test.d.ts +0 -1
  120. package/dist/test/36.cw_bridge_query.test.js +0 -318
  121. package/dist/test/37.cw_marketplace_tx.test.d.ts +0 -1
  122. package/dist/test/37.cw_marketplace_tx.test.js +0 -794
  123. package/dist/test/38.cw_marketplace_query.test.d.ts +0 -1
  124. package/dist/test/38.cw_marketplace_query.test.js +0 -128
  125. package/dist/test/config_test.d.ts +0 -11
  126. package/dist/test/config_test.js +0 -14
  127. package/dist/test/config_test.sample.d.ts +0 -11
  128. package/dist/test/config_test.sample.js +0 -14
@@ -1,380 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
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;
13
- return g = { next: verb(0), "throw": verb(1), "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 chai_1 = require("chai");
40
- var authz_1 = require("../sdk/firmachain/authz");
41
- var bank_1 = require("../sdk/firmachain/bank");
42
- var distribution_1 = require("../sdk/firmachain/distribution");
43
- var staking_1 = require("../sdk/firmachain/staking");
44
- var FirmaSDK_1 = require("../sdk/FirmaSDK");
45
- var FirmaUtil_1 = require("../sdk/FirmaUtil");
46
- var config_test_1 = require("./config_test");
47
- describe('[23. Authz Tx Test]', function () {
48
- var firma;
49
- var aliceWallet;
50
- var aliceAddress;
51
- var bobWallet;
52
- var bobAddress;
53
- beforeEach(function () {
54
- return __awaiter(this, void 0, void 0, function () {
55
- return __generator(this, function (_a) {
56
- switch (_a.label) {
57
- case 0:
58
- firma = new FirmaSDK_1.FirmaSDK(config_test_1.TestChainConfig);
59
- return [4 /*yield*/, firma.Wallet.fromMnemonic(config_test_1.aliceMnemonic)];
60
- case 1:
61
- aliceWallet = _a.sent();
62
- return [4 /*yield*/, aliceWallet.getAddress()];
63
- case 2:
64
- aliceAddress = _a.sent();
65
- return [4 /*yield*/, firma.Wallet.fromMnemonic(config_test_1.bobMnemonic)];
66
- case 3:
67
- bobWallet = _a.sent();
68
- return [4 /*yield*/, bobWallet.getAddress()];
69
- case 4:
70
- bobAddress = _a.sent();
71
- return [2 /*return*/];
72
- }
73
- });
74
- });
75
- });
76
- // grant type check
77
- // authorization_type="send"|"generic"|"delegate"|"unbond"|"redelegate"
78
- it('Authz Grant Send', function () { return __awaiter(void 0, void 0, void 0, function () {
79
- var date, expirationDate, maxFCT, result;
80
- return __generator(this, function (_a) {
81
- switch (_a.label) {
82
- case 0:
83
- date = new Date();
84
- date.setDate(date.getDate() + 1);
85
- expirationDate = {
86
- seconds: BigInt(Math.floor(date.getTime() / 1000)),
87
- nanos: (date.getTime() % 1000) * 1000000
88
- };
89
- maxFCT = 10;
90
- return [4 /*yield*/, firma.Authz.grantSendAuthorization(aliceWallet, bobAddress, expirationDate, maxFCT)];
91
- case 1:
92
- result = _a.sent();
93
- (0, chai_1.expect)(result.code).to.be.equal(0);
94
- return [2 /*return*/];
95
- }
96
- });
97
- }); });
98
- it('Authz ExecuteAllowance-Send', function () { return __awaiter(void 0, void 0, void 0, function () {
99
- var amountFCT, address, toAddress, sendAmount, msgSend, anyData, result;
100
- return __generator(this, function (_a) {
101
- switch (_a.label) {
102
- case 0:
103
- amountFCT = 9;
104
- address = aliceAddress;
105
- toAddress = bobAddress;
106
- sendAmount = { denom: firma.Config.denom, amount: FirmaUtil_1.FirmaUtil.getUFCTStringFromFCT(amountFCT) };
107
- msgSend = bank_1.BankTxClient.msgSend({
108
- fromAddress: address,
109
- toAddress: toAddress,
110
- amount: [sendAmount]
111
- });
112
- anyData = FirmaUtil_1.FirmaUtil.getAnyData(bank_1.BankTxClient.getRegistry(), msgSend);
113
- return [4 /*yield*/, firma.Authz.executeAllowance(bobWallet, [anyData])];
114
- case 1:
115
- result = _a.sent();
116
- (0, chai_1.expect)(result.code).to.be.equal(0);
117
- return [2 /*return*/];
118
- }
119
- });
120
- }); });
121
- it('Authz Revoke Send', function () { return __awaiter(void 0, void 0, void 0, function () {
122
- var result;
123
- return __generator(this, function (_a) {
124
- switch (_a.label) {
125
- case 0: return [4 /*yield*/, firma.Authz.revokeSendAuthorization(aliceWallet, bobAddress)];
126
- case 1:
127
- result = _a.sent();
128
- (0, chai_1.expect)(result.code).to.be.equal(0);
129
- return [2 /*return*/];
130
- }
131
- });
132
- }); });
133
- it('Authz Grant Delegate', function () { return __awaiter(void 0, void 0, void 0, function () {
134
- var delegationInfo, validatorAddress, date, expirationDate, maxFCT, result;
135
- return __generator(this, function (_a) {
136
- switch (_a.label) {
137
- case 0: return [4 /*yield*/, firma.Staking.getTotalDelegationInfo(aliceAddress)];
138
- case 1:
139
- delegationInfo = (_a.sent()).dataList;
140
- validatorAddress = delegationInfo[0].delegation.validator_address;
141
- date = new Date();
142
- date.setDate(date.getDate() + 1);
143
- expirationDate = {
144
- seconds: BigInt(Math.floor(date.getTime() / 1000)),
145
- nanos: (date.getTime() % 1000) * 1000000
146
- };
147
- maxFCT = 100;
148
- return [4 /*yield*/, firma.Authz.grantStakeAuthorization(aliceWallet, bobAddress, [validatorAddress], authz_1.AuthorizationType.AUTHORIZATION_TYPE_DELEGATE, expirationDate, maxFCT)];
149
- case 2:
150
- result = _a.sent();
151
- (0, chai_1.expect)(result.code).to.be.equal(0);
152
- return [2 /*return*/];
153
- }
154
- });
155
- }); });
156
- it('Authz ExecuteAllowance-Delegate', function () { return __awaiter(void 0, void 0, void 0, function () {
157
- var delegationInfo, validatorAddress, amountFCT, address, sendAmount, msgDelegate, anyData, result;
158
- return __generator(this, function (_a) {
159
- switch (_a.label) {
160
- case 0: return [4 /*yield*/, firma.Staking.getTotalDelegationInfo(aliceAddress)];
161
- case 1:
162
- delegationInfo = (_a.sent()).dataList;
163
- validatorAddress = delegationInfo[0].delegation.validator_address;
164
- amountFCT = 9;
165
- address = aliceAddress;
166
- sendAmount = { denom: firma.Config.denom, amount: FirmaUtil_1.FirmaUtil.getUFCTStringFromFCT(amountFCT) };
167
- msgDelegate = staking_1.StakingTxClient.msgDelegate({
168
- delegatorAddress: address,
169
- validatorAddress: validatorAddress,
170
- amount: sendAmount
171
- });
172
- anyData = FirmaUtil_1.FirmaUtil.getAnyData(staking_1.StakingTxClient.getRegistry(), msgDelegate);
173
- return [4 /*yield*/, firma.Authz.executeAllowance(bobWallet, [anyData])];
174
- case 2:
175
- result = _a.sent();
176
- (0, chai_1.expect)(result.code).to.be.equal(0);
177
- return [2 /*return*/];
178
- }
179
- });
180
- }); });
181
- it('Authz Revoke Delegate', function () { return __awaiter(void 0, void 0, void 0, function () {
182
- var result;
183
- return __generator(this, function (_a) {
184
- switch (_a.label) {
185
- case 0: return [4 /*yield*/, firma.Authz.revokeStakeAuthorization(aliceWallet, bobAddress, authz_1.AuthorizationType.AUTHORIZATION_TYPE_DELEGATE)];
186
- case 1:
187
- result = _a.sent();
188
- (0, chai_1.expect)(result.code).to.be.equal(0);
189
- return [2 /*return*/];
190
- }
191
- });
192
- }); });
193
- it('Authz Grant UnDelegate', function () { return __awaiter(void 0, void 0, void 0, function () {
194
- var delegationInfo, validatorAddress, date, expirationDate, maxFCT, result;
195
- return __generator(this, function (_a) {
196
- switch (_a.label) {
197
- case 0: return [4 /*yield*/, firma.Staking.getTotalDelegationInfo(aliceAddress)];
198
- case 1:
199
- delegationInfo = (_a.sent()).dataList;
200
- validatorAddress = delegationInfo[0].delegation.validator_address;
201
- date = new Date();
202
- date.setDate(date.getDate() + 1);
203
- expirationDate = {
204
- seconds: BigInt(Math.floor(date.getTime() / 1000)),
205
- nanos: (date.getTime() % 1000) * 1000000
206
- };
207
- maxFCT = 10;
208
- return [4 /*yield*/, firma.Authz.grantStakeAuthorization(aliceWallet, bobAddress, [validatorAddress], authz_1.AuthorizationType.AUTHORIZATION_TYPE_UNDELEGATE, expirationDate, maxFCT)];
209
- case 2:
210
- result = _a.sent();
211
- (0, chai_1.expect)(result.code).to.be.equal(0);
212
- return [2 /*return*/];
213
- }
214
- });
215
- }); });
216
- it('Authz ExecuteAllowance-Undelegate', function () { return __awaiter(void 0, void 0, void 0, function () {
217
- var delegationInfo, validatorAddress, amountFCT, address, sendAmount, msgUndelegate, anyData, gas, fee, result;
218
- return __generator(this, function (_a) {
219
- switch (_a.label) {
220
- case 0: return [4 /*yield*/, firma.Staking.getTotalDelegationInfo(aliceAddress)];
221
- case 1:
222
- delegationInfo = (_a.sent()).dataList;
223
- validatorAddress = delegationInfo[0].delegation.validator_address;
224
- amountFCT = 9;
225
- address = aliceAddress;
226
- sendAmount = { denom: firma.Config.denom, amount: FirmaUtil_1.FirmaUtil.getUFCTStringFromFCT(amountFCT) };
227
- msgUndelegate = staking_1.StakingTxClient.msgUndelegate({
228
- delegatorAddress: address,
229
- validatorAddress: validatorAddress,
230
- amount: sendAmount
231
- });
232
- anyData = FirmaUtil_1.FirmaUtil.getAnyData(staking_1.StakingTxClient.getRegistry(), msgUndelegate);
233
- return [4 /*yield*/, firma.Authz.getGasEstimationExecuteAllowance(bobWallet, [anyData])];
234
- case 2:
235
- gas = _a.sent();
236
- fee = Math.ceil(gas * 0.1);
237
- return [4 /*yield*/, firma.Authz.executeAllowance(bobWallet, [anyData], { gas: gas, fee: fee })];
238
- case 3:
239
- result = _a.sent();
240
- (0, chai_1.expect)(result.code).to.be.equal(0);
241
- return [2 /*return*/];
242
- }
243
- });
244
- }); });
245
- it('Authz Grant ReDelegate', function () { return __awaiter(void 0, void 0, void 0, function () {
246
- var delegationInfo, validatorAddress1, validatorAddress2, date, expirationDate, maxFCT, result;
247
- return __generator(this, function (_a) {
248
- switch (_a.label) {
249
- case 0: return [4 /*yield*/, firma.Staking.getTotalDelegationInfo(aliceAddress)];
250
- case 1:
251
- delegationInfo = (_a.sent()).dataList;
252
- validatorAddress1 = delegationInfo[0].delegation.validator_address;
253
- validatorAddress2 = delegationInfo[1].delegation.validator_address;
254
- date = new Date();
255
- date.setDate(date.getDate() + 1);
256
- expirationDate = {
257
- seconds: BigInt(Math.floor(date.getTime() / 1000)),
258
- nanos: (date.getTime() % 1000) * 1000000
259
- };
260
- maxFCT = 10;
261
- return [4 /*yield*/, firma.Authz.grantStakeAuthorization(aliceWallet, bobAddress, [validatorAddress1, validatorAddress2], authz_1.AuthorizationType.AUTHORIZATION_TYPE_REDELEGATE, expirationDate, maxFCT)];
262
- case 2:
263
- result = _a.sent();
264
- (0, chai_1.expect)(result.code).to.be.equal(0);
265
- return [2 /*return*/];
266
- }
267
- });
268
- }); });
269
- it('Authz Revoke UnDelegate', function () { return __awaiter(void 0, void 0, void 0, function () {
270
- var result;
271
- return __generator(this, function (_a) {
272
- switch (_a.label) {
273
- case 0: return [4 /*yield*/, firma.Authz.revokeStakeAuthorization(aliceWallet, bobAddress, authz_1.AuthorizationType.AUTHORIZATION_TYPE_UNDELEGATE)];
274
- case 1:
275
- result = _a.sent();
276
- (0, chai_1.expect)(result.code).to.be.equal(0);
277
- return [2 /*return*/];
278
- }
279
- });
280
- }); });
281
- it('Authz ExecuteAllowance-ReDelegate', function () { return __awaiter(void 0, void 0, void 0, function () {
282
- var delegationInfo, validatorAddress1, validatorAddress2, amountFCT, sendAmount, msgUndelegate, anyData, gas, fee, result;
283
- return __generator(this, function (_a) {
284
- switch (_a.label) {
285
- case 0: return [4 /*yield*/, firma.Staking.getTotalDelegationInfo(aliceAddress)];
286
- case 1:
287
- delegationInfo = (_a.sent()).dataList;
288
- validatorAddress1 = delegationInfo[0].delegation.validator_address;
289
- validatorAddress2 = delegationInfo[1].delegation.validator_address;
290
- amountFCT = 1;
291
- sendAmount = { denom: firma.Config.denom, amount: FirmaUtil_1.FirmaUtil.getUFCTStringFromFCT(amountFCT) };
292
- msgUndelegate = staking_1.StakingTxClient.msgRedelegate({
293
- delegatorAddress: aliceAddress,
294
- validatorSrcAddress: validatorAddress1,
295
- validatorDstAddress: validatorAddress2,
296
- amount: sendAmount
297
- });
298
- anyData = FirmaUtil_1.FirmaUtil.getAnyData(staking_1.StakingTxClient.getRegistry(), msgUndelegate);
299
- return [4 /*yield*/, firma.Authz.getGasEstimationExecuteAllowance(bobWallet, [anyData])];
300
- case 2:
301
- gas = _a.sent();
302
- fee = Math.ceil(gas * 0.1);
303
- return [4 /*yield*/, firma.Authz.executeAllowance(bobWallet, [anyData], { gas: gas, fee: fee })];
304
- case 3:
305
- result = _a.sent();
306
- (0, chai_1.expect)(result.code).to.be.equal(0);
307
- return [2 /*return*/];
308
- }
309
- });
310
- }); });
311
- it('Authz Revoke ReDelegate', function () { return __awaiter(void 0, void 0, void 0, function () {
312
- var result;
313
- return __generator(this, function (_a) {
314
- switch (_a.label) {
315
- case 0: return [4 /*yield*/, firma.Authz.revokeStakeAuthorization(aliceWallet, bobAddress, authz_1.AuthorizationType.AUTHORIZATION_TYPE_REDELEGATE)];
316
- case 1:
317
- result = _a.sent();
318
- (0, chai_1.expect)(result.code).to.be.equal(0);
319
- return [2 /*return*/];
320
- }
321
- });
322
- }); });
323
- // GenericAuthorization: MsgWithdrawDelegatorReward case
324
- it('Authz Grant-GenericAuthorization MsgWithdrawDelegatorReward', function () { return __awaiter(void 0, void 0, void 0, function () {
325
- var msg, date, expirationDate, result;
326
- return __generator(this, function (_a) {
327
- switch (_a.label) {
328
- case 0:
329
- msg = "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward";
330
- date = new Date();
331
- date.setDate(date.getDate() + 1);
332
- expirationDate = {
333
- seconds: BigInt(Math.floor(date.getTime() / 1000)),
334
- nanos: (date.getTime() % 1000) * 1000000
335
- };
336
- return [4 /*yield*/, firma.Authz.grantGenericAuthorization(aliceWallet, bobAddress, msg, expirationDate)];
337
- case 1:
338
- result = _a.sent();
339
- (0, chai_1.expect)(result.code).to.be.equal(0);
340
- return [2 /*return*/];
341
- }
342
- });
343
- }); });
344
- it('Authz GenericAuthorization ExecuteAllowance-MsgWithdrawDelegatorReward', function () { return __awaiter(void 0, void 0, void 0, function () {
345
- var delegationInfo, validatorAddress, address, msgWithdrawDelegatorReward, anyData, result;
346
- return __generator(this, function (_a) {
347
- switch (_a.label) {
348
- case 0: return [4 /*yield*/, firma.Staking.getTotalDelegationInfo(aliceAddress)];
349
- case 1:
350
- delegationInfo = (_a.sent()).dataList;
351
- validatorAddress = delegationInfo[0].delegation.validator_address;
352
- address = aliceAddress;
353
- msgWithdrawDelegatorReward = distribution_1.DistributionTxClient.msgWithdrawDelegatorReward({
354
- delegatorAddress: address,
355
- validatorAddress: validatorAddress,
356
- });
357
- anyData = FirmaUtil_1.FirmaUtil.getAnyData(distribution_1.DistributionTxClient.getRegistry(), msgWithdrawDelegatorReward);
358
- return [4 /*yield*/, firma.Authz.executeAllowance(bobWallet, [anyData])];
359
- case 2:
360
- result = _a.sent();
361
- (0, chai_1.expect)(result.code).to.be.equal(0);
362
- return [2 /*return*/];
363
- }
364
- });
365
- }); });
366
- it('Authz Revoke-GenericAuthorization MsgWithdrawDelegatorReward', function () { return __awaiter(void 0, void 0, void 0, function () {
367
- var msgType, result;
368
- return __generator(this, function (_a) {
369
- switch (_a.label) {
370
- case 0:
371
- msgType = "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward";
372
- return [4 /*yield*/, firma.Authz.revokeGenericAuthorization(aliceWallet, bobAddress, msgType)];
373
- case 1:
374
- result = _a.sent();
375
- (0, chai_1.expect)(result.code).to.be.equal(0);
376
- return [2 /*return*/];
377
- }
378
- });
379
- }); });
380
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,202 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
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;
13
- return g = { next: verb(0), "throw": verb(1), "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 chai_1 = require("chai");
40
- var AuthzTxTypes_1 = require("../sdk/firmachain/authz/AuthzTxTypes");
41
- var FirmaSDK_1 = require("../sdk/FirmaSDK");
42
- var config_test_1 = require("./config_test");
43
- describe('[24. Authz query Test]', function () {
44
- var firma;
45
- var aliceWallet;
46
- var aliceAddress;
47
- var bobWallet;
48
- var bobAddress;
49
- var date;
50
- var expirationDate;
51
- var validatorAddress;
52
- var maxFCT;
53
- beforeEach(function () {
54
- return __awaiter(this, void 0, void 0, function () {
55
- var delegationInfo;
56
- return __generator(this, function (_a) {
57
- switch (_a.label) {
58
- case 0:
59
- firma = new FirmaSDK_1.FirmaSDK(config_test_1.TestChainConfig);
60
- return [4 /*yield*/, firma.Wallet.fromMnemonic(config_test_1.aliceMnemonic)];
61
- case 1:
62
- aliceWallet = _a.sent();
63
- return [4 /*yield*/, aliceWallet.getAddress()];
64
- case 2:
65
- aliceAddress = _a.sent();
66
- return [4 /*yield*/, firma.Wallet.fromMnemonic(config_test_1.bobMnemonic)];
67
- case 3:
68
- bobWallet = _a.sent();
69
- return [4 /*yield*/, bobWallet.getAddress()];
70
- case 4:
71
- bobAddress = _a.sent();
72
- date = new Date();
73
- date.setDate(date.getDate() + 1);
74
- expirationDate = {
75
- seconds: BigInt(Math.floor(date.getTime() / 1000)),
76
- nanos: (date.getTime() % 1000) * 1000000
77
- };
78
- return [4 /*yield*/, firma.Staking.getTotalDelegationInfo(aliceAddress)];
79
- case 5:
80
- delegationInfo = (_a.sent()).dataList;
81
- validatorAddress = delegationInfo[0].delegation.validator_address;
82
- maxFCT = 100;
83
- return [2 /*return*/];
84
- }
85
- });
86
- });
87
- });
88
- var initializeGrant = function () {
89
- return __awaiter(this, void 0, void 0, function () {
90
- return __generator(this, function (_a) {
91
- return [2 /*return*/];
92
- });
93
- });
94
- };
95
- it('Authz getSendGrantData', function () { return __awaiter(void 0, void 0, void 0, function () {
96
- var amountFCT, grantResult, result, grant, revokeResult;
97
- return __generator(this, function (_a) {
98
- switch (_a.label) {
99
- case 0:
100
- amountFCT = 9;
101
- return [4 /*yield*/, firma.Authz.grantSendAuthorization(aliceWallet, bobAddress, expirationDate, amountFCT)];
102
- case 1:
103
- grantResult = _a.sent();
104
- (0, chai_1.expect)(grantResult.code).to.equal(0);
105
- return [4 /*yield*/, firma.Authz.getSendGrantData(aliceAddress, bobAddress)];
106
- case 2:
107
- result = (_a.sent()).dataList;
108
- (0, chai_1.expect)(result.length).to.be.greaterThan(0);
109
- grant = result[0];
110
- (0, chai_1.expect)(grant).to.have.property('authorization');
111
- (0, chai_1.expect)(grant).to.have.property('expiration');
112
- return [4 /*yield*/, firma.Authz.revokeSendAuthorization(aliceWallet, bobAddress)];
113
- case 3:
114
- revokeResult = _a.sent();
115
- (0, chai_1.expect)(revokeResult.code).to.equal(0);
116
- return [2 /*return*/];
117
- }
118
- });
119
- }); });
120
- it('Authz getGenericGrantData', function () { return __awaiter(void 0, void 0, void 0, function () {
121
- var msg, genericResult, result, grant;
122
- return __generator(this, function (_a) {
123
- switch (_a.label) {
124
- case 0:
125
- msg = "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward";
126
- return [4 /*yield*/, firma.Authz.grantGenericAuthorization(aliceWallet, bobAddress, msg, expirationDate)];
127
- case 1:
128
- genericResult = _a.sent();
129
- (0, chai_1.expect)(genericResult.code).to.be.equal(0);
130
- return [4 /*yield*/, firma.Authz.getGenericGrantData(aliceAddress, bobAddress, msg)];
131
- case 2:
132
- result = (_a.sent()).dataList;
133
- // This test may fail if the grant does not exist.
134
- (0, chai_1.expect)(result.length).to.be.greaterThan(0);
135
- grant = result[0];
136
- (0, chai_1.expect)(grant).to.have.property('authorization');
137
- (0, chai_1.expect)(grant).to.have.property('expiration');
138
- return [2 /*return*/];
139
- }
140
- });
141
- }); });
142
- it('Authz getStakingGrantData - delegate', function () { return __awaiter(void 0, void 0, void 0, function () {
143
- var delegateResult, result, grant;
144
- return __generator(this, function (_a) {
145
- switch (_a.label) {
146
- case 0: return [4 /*yield*/, firma.Authz.grantStakeAuthorization(aliceWallet, bobAddress, [validatorAddress], AuthzTxTypes_1.AuthorizationType.AUTHORIZATION_TYPE_DELEGATE, expirationDate, maxFCT)];
147
- case 1:
148
- delegateResult = _a.sent();
149
- (0, chai_1.expect)(delegateResult.code).to.be.equal(0);
150
- return [4 /*yield*/, firma.Authz.getStakingGrantData(aliceAddress, bobAddress, AuthzTxTypes_1.AuthorizationType.AUTHORIZATION_TYPE_DELEGATE)];
151
- case 2:
152
- result = (_a.sent()).dataList;
153
- // This test may fail if the grant does not exist.
154
- (0, chai_1.expect)(result.length).to.be.greaterThan(0);
155
- grant = result[0];
156
- (0, chai_1.expect)(grant).to.have.property('authorization');
157
- (0, chai_1.expect)(grant).to.have.property('expiration');
158
- return [2 /*return*/];
159
- }
160
- });
161
- }); });
162
- it('Authz getStakingGrantData - redelegate', function () { return __awaiter(void 0, void 0, void 0, function () {
163
- var redelegateResult, result, grant;
164
- return __generator(this, function (_a) {
165
- switch (_a.label) {
166
- case 0: return [4 /*yield*/, firma.Authz.grantStakeAuthorization(aliceWallet, bobAddress, [validatorAddress], AuthzTxTypes_1.AuthorizationType.AUTHORIZATION_TYPE_REDELEGATE, expirationDate, maxFCT)];
167
- case 1:
168
- redelegateResult = _a.sent();
169
- (0, chai_1.expect)(redelegateResult.code).to.be.equal(0);
170
- return [4 /*yield*/, firma.Authz.getStakingGrantData(aliceAddress, bobAddress, AuthzTxTypes_1.AuthorizationType.AUTHORIZATION_TYPE_REDELEGATE)];
171
- case 2:
172
- result = (_a.sent()).dataList;
173
- // This test may fail if the grant does not exist.
174
- (0, chai_1.expect)(result.length).to.be.greaterThan(0);
175
- grant = result[0];
176
- (0, chai_1.expect)(grant).to.have.property('authorization');
177
- (0, chai_1.expect)(grant).to.have.property('expiration');
178
- return [2 /*return*/];
179
- }
180
- });
181
- }); });
182
- it('Authz getStakingGrantData - undelegate', function () { return __awaiter(void 0, void 0, void 0, function () {
183
- var undelegateResult, result, grant;
184
- return __generator(this, function (_a) {
185
- switch (_a.label) {
186
- case 0: return [4 /*yield*/, firma.Authz.grantStakeAuthorization(aliceWallet, bobAddress, [validatorAddress], AuthzTxTypes_1.AuthorizationType.AUTHORIZATION_TYPE_UNDELEGATE, expirationDate, maxFCT)];
187
- case 1:
188
- undelegateResult = _a.sent();
189
- (0, chai_1.expect)(undelegateResult.code).to.be.equal(0);
190
- return [4 /*yield*/, firma.Authz.getStakingGrantData(aliceAddress, bobAddress, AuthzTxTypes_1.AuthorizationType.AUTHORIZATION_TYPE_UNDELEGATE)];
191
- case 2:
192
- result = (_a.sent()).dataList;
193
- // This test may fail if the grant does not exist.
194
- (0, chai_1.expect)(result.length).to.be.greaterThan(0);
195
- grant = result[0];
196
- (0, chai_1.expect)(grant).to.have.property('authorization');
197
- (0, chai_1.expect)(grant).to.have.property('expiration');
198
- return [2 /*return*/];
199
- }
200
- });
201
- }); });
202
- });
@@ -1 +0,0 @@
1
- export {};