@ledgerhq/live-common 34.1.0-next.0 → 34.1.0-next.1

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 (102) hide show
  1. package/lib/families/cosmos/api/Cosmos.d.ts +56 -1
  2. package/lib/families/cosmos/api/Cosmos.d.ts.map +1 -1
  3. package/lib/families/cosmos/api/Cosmos.js +120 -75
  4. package/lib/families/cosmos/api/Cosmos.js.map +1 -1
  5. package/lib/families/cosmos/api/Cosmos.unit.test.d.ts +2 -0
  6. package/lib/families/cosmos/api/Cosmos.unit.test.d.ts.map +1 -0
  7. package/lib/families/cosmos/api/Cosmos.unit.test.js +755 -0
  8. package/lib/families/cosmos/api/Cosmos.unit.test.js.map +1 -0
  9. package/lib/families/cosmos/api/types.d.ts +321 -0
  10. package/lib/families/cosmos/api/types.d.ts.map +1 -0
  11. package/lib/families/cosmos/api/types.js +3 -0
  12. package/lib/families/cosmos/api/types.js.map +1 -0
  13. package/lib/families/cosmos/js-buildTransaction.d.ts +3 -3
  14. package/lib/families/cosmos/js-buildTransaction.d.ts.map +1 -1
  15. package/lib/families/cosmos/js-buildTransaction.js +1 -5
  16. package/lib/families/cosmos/js-buildTransaction.js.map +1 -1
  17. package/lib/families/cosmos/js-buildTransaction.unit.test.d.ts +2 -0
  18. package/lib/families/cosmos/js-buildTransaction.unit.test.d.ts.map +1 -0
  19. package/lib/families/cosmos/{js-buildTransaction.test.js → js-buildTransaction.unit.test.js} +1 -1
  20. package/lib/families/cosmos/js-buildTransaction.unit.test.js.map +1 -0
  21. package/lib/families/cosmos/js-prepareTransaction.d.ts.map +1 -1
  22. package/lib/families/cosmos/js-prepareTransaction.js +15 -10
  23. package/lib/families/cosmos/js-prepareTransaction.js.map +1 -1
  24. package/lib/families/cosmos/js-prepareTransaction.unit.test.d.ts +2 -0
  25. package/lib/families/cosmos/js-prepareTransaction.unit.test.d.ts.map +1 -0
  26. package/lib/families/cosmos/{js-prepareTransaction.test.js → js-prepareTransaction.unit.test.js} +1 -1
  27. package/lib/families/cosmos/js-prepareTransaction.unit.test.js.map +1 -0
  28. package/lib/families/cosmos/js-signOperation.d.ts.map +1 -1
  29. package/lib/families/cosmos/js-signOperation.js +5 -5
  30. package/lib/families/cosmos/js-signOperation.js.map +1 -1
  31. package/lib/families/cosmos/js-synchronisation.d.ts.map +1 -1
  32. package/lib/families/cosmos/js-synchronisation.js +7 -1
  33. package/lib/families/cosmos/js-synchronisation.js.map +1 -1
  34. package/lib/families/cosmos/js-synchronisation.unit.test.js +114 -1
  35. package/lib/families/cosmos/js-synchronisation.unit.test.js.map +1 -1
  36. package/lib-es/families/cosmos/api/Cosmos.d.ts +56 -1
  37. package/lib-es/families/cosmos/api/Cosmos.d.ts.map +1 -1
  38. package/lib-es/families/cosmos/api/Cosmos.js +120 -75
  39. package/lib-es/families/cosmos/api/Cosmos.js.map +1 -1
  40. package/lib-es/families/cosmos/api/Cosmos.unit.test.d.ts +2 -0
  41. package/lib-es/families/cosmos/api/Cosmos.unit.test.d.ts.map +1 -0
  42. package/lib-es/families/cosmos/api/Cosmos.unit.test.js +750 -0
  43. package/lib-es/families/cosmos/api/Cosmos.unit.test.js.map +1 -0
  44. package/lib-es/families/cosmos/api/types.d.ts +321 -0
  45. package/lib-es/families/cosmos/api/types.d.ts.map +1 -0
  46. package/lib-es/families/cosmos/api/types.js +2 -0
  47. package/lib-es/families/cosmos/api/types.js.map +1 -0
  48. package/lib-es/families/cosmos/js-buildTransaction.d.ts +3 -3
  49. package/lib-es/families/cosmos/js-buildTransaction.d.ts.map +1 -1
  50. package/lib-es/families/cosmos/js-buildTransaction.js +1 -2
  51. package/lib-es/families/cosmos/js-buildTransaction.js.map +1 -1
  52. package/lib-es/families/cosmos/js-buildTransaction.unit.test.d.ts +2 -0
  53. package/lib-es/families/cosmos/js-buildTransaction.unit.test.d.ts.map +1 -0
  54. package/lib-es/families/cosmos/{js-buildTransaction.test.js → js-buildTransaction.unit.test.js} +1 -1
  55. package/lib-es/families/cosmos/js-buildTransaction.unit.test.js.map +1 -0
  56. package/lib-es/families/cosmos/js-prepareTransaction.d.ts.map +1 -1
  57. package/lib-es/families/cosmos/js-prepareTransaction.js +15 -10
  58. package/lib-es/families/cosmos/js-prepareTransaction.js.map +1 -1
  59. package/lib-es/families/cosmos/js-prepareTransaction.unit.test.d.ts +2 -0
  60. package/lib-es/families/cosmos/js-prepareTransaction.unit.test.d.ts.map +1 -0
  61. package/lib-es/families/cosmos/{js-prepareTransaction.test.js → js-prepareTransaction.unit.test.js} +1 -1
  62. package/lib-es/families/cosmos/js-prepareTransaction.unit.test.js.map +1 -0
  63. package/lib-es/families/cosmos/js-signOperation.d.ts.map +1 -1
  64. package/lib-es/families/cosmos/js-signOperation.js +5 -5
  65. package/lib-es/families/cosmos/js-signOperation.js.map +1 -1
  66. package/lib-es/families/cosmos/js-synchronisation.d.ts.map +1 -1
  67. package/lib-es/families/cosmos/js-synchronisation.js +7 -1
  68. package/lib-es/families/cosmos/js-synchronisation.js.map +1 -1
  69. package/lib-es/families/cosmos/js-synchronisation.unit.test.js +114 -1
  70. package/lib-es/families/cosmos/js-synchronisation.unit.test.js.map +1 -1
  71. package/package.json +24 -24
  72. package/src/families/cosmos/api/Cosmos.ts +162 -95
  73. package/src/families/cosmos/api/Cosmos.unit.test.ts +771 -0
  74. package/src/families/cosmos/api/types.ts +329 -0
  75. package/src/families/cosmos/js-buildTransaction.ts +5 -6
  76. package/src/families/cosmos/js-prepareTransaction.ts +15 -11
  77. package/src/families/cosmos/js-signOperation.ts +8 -7
  78. package/src/families/cosmos/js-synchronisation.ts +9 -1
  79. package/src/families/cosmos/js-synchronisation.unit.test.ts +117 -0
  80. package/lib/families/cosmos/api/Cosmos.test.d.ts +0 -2
  81. package/lib/families/cosmos/api/Cosmos.test.d.ts.map +0 -1
  82. package/lib/families/cosmos/api/Cosmos.test.js +0 -203
  83. package/lib/families/cosmos/api/Cosmos.test.js.map +0 -1
  84. package/lib/families/cosmos/js-buildTransaction.test.d.ts +0 -2
  85. package/lib/families/cosmos/js-buildTransaction.test.d.ts.map +0 -1
  86. package/lib/families/cosmos/js-buildTransaction.test.js.map +0 -1
  87. package/lib/families/cosmos/js-prepareTransaction.test.d.ts +0 -2
  88. package/lib/families/cosmos/js-prepareTransaction.test.d.ts.map +0 -1
  89. package/lib/families/cosmos/js-prepareTransaction.test.js.map +0 -1
  90. package/lib-es/families/cosmos/api/Cosmos.test.d.ts +0 -2
  91. package/lib-es/families/cosmos/api/Cosmos.test.d.ts.map +0 -1
  92. package/lib-es/families/cosmos/api/Cosmos.test.js +0 -198
  93. package/lib-es/families/cosmos/api/Cosmos.test.js.map +0 -1
  94. package/lib-es/families/cosmos/js-buildTransaction.test.d.ts +0 -2
  95. package/lib-es/families/cosmos/js-buildTransaction.test.d.ts.map +0 -1
  96. package/lib-es/families/cosmos/js-buildTransaction.test.js.map +0 -1
  97. package/lib-es/families/cosmos/js-prepareTransaction.test.d.ts +0 -2
  98. package/lib-es/families/cosmos/js-prepareTransaction.test.d.ts.map +0 -1
  99. package/lib-es/families/cosmos/js-prepareTransaction.test.js.map +0 -1
  100. package/src/families/cosmos/api/Cosmos.test.ts +0 -210
  101. /package/src/families/cosmos/{js-buildTransaction.test.ts → js-buildTransaction.unit.test.ts} +0 -0
  102. /package/src/families/cosmos/{js-prepareTransaction.test.ts → js-prepareTransaction.unit.test.ts} +0 -0
@@ -0,0 +1,755 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const network_1 = __importDefault(require("@ledgerhq/live-network/network"));
16
+ const bignumber_js_1 = __importDefault(require("bignumber.js"));
17
+ const chain_1 = __importDefault(require("../chain/chain"));
18
+ const Cosmos_1 = require("./Cosmos");
19
+ const LiveConfig_1 = require("@ledgerhq/live-config/LiveConfig");
20
+ const sharedConfig_1 = require("../../../config/sharedConfig");
21
+ jest.mock("@ledgerhq/live-network/network");
22
+ const mockedNetwork = jest.mocked(network_1.default);
23
+ LiveConfig_1.LiveConfig.setConfig(sharedConfig_1.liveConfig);
24
+ describe("CosmosApi", () => {
25
+ let cosmosApi;
26
+ beforeEach(() => {
27
+ cosmosApi = new Cosmos_1.CosmosAPI("cosmos");
28
+ });
29
+ afterEach(() => {
30
+ jest.resetAllMocks();
31
+ });
32
+ describe("getAccount", () => {
33
+ it("should return base_account if available", () => __awaiter(void 0, void 0, void 0, function* () {
34
+ mockedNetwork.mockResolvedValue({
35
+ data: {
36
+ account: {
37
+ account_number: 1,
38
+ sequence: 0,
39
+ pub_key: { key: "k", "@type": "type" },
40
+ base_account: {
41
+ account_number: 2,
42
+ sequence: 42,
43
+ pub_key: { key: "k2", "@type": "type2" },
44
+ },
45
+ },
46
+ },
47
+ });
48
+ const account = yield cosmosApi.getAccount("addr");
49
+ expect(account.accountNumber).toEqual(2);
50
+ expect(account.sequence).toEqual(42);
51
+ expect(account.pubKey).toEqual("k2");
52
+ expect(account.pubKeyType).toEqual("type2");
53
+ }));
54
+ it("should return the correct account based on type", () => __awaiter(void 0, void 0, void 0, function* () {
55
+ mockedNetwork.mockResolvedValue({
56
+ data: {
57
+ account: {
58
+ "@type": "/cosmos.auth.v1beta1.BaseAccount",
59
+ account_number: 1,
60
+ sequence: 0,
61
+ pub_key: { key: "k", "@type": "type" },
62
+ },
63
+ },
64
+ });
65
+ const account = yield cosmosApi.getAccount("addr");
66
+ expect(account).toEqual({
67
+ accountNumber: 1,
68
+ sequence: 0,
69
+ pubKey: "k",
70
+ pubKeyType: "type",
71
+ });
72
+ mockedNetwork.mockResolvedValue({
73
+ data: {
74
+ account: {
75
+ "@type": "/ethermint.types.v1.EthAccount",
76
+ account_number: 1,
77
+ sequence: 0,
78
+ pub_key: { key: "k", "@type": "type" },
79
+ base_account: {
80
+ address: "address",
81
+ pub_key: { key: "k2", "@type": "type2" },
82
+ account_number: 2,
83
+ sequence: 3,
84
+ },
85
+ code_hash: "codeHash",
86
+ },
87
+ },
88
+ });
89
+ const ethermintAccount = yield cosmosApi.getAccount("addr");
90
+ expect(ethermintAccount).toEqual({
91
+ accountNumber: 2,
92
+ sequence: 3,
93
+ pubKey: "k2",
94
+ pubKeyType: "type2",
95
+ });
96
+ }));
97
+ it("should return default sequence value if network fails", () => __awaiter(void 0, void 0, void 0, function* () {
98
+ mockedNetwork.mockImplementation(() => {
99
+ throw new Error();
100
+ });
101
+ const account = yield cosmosApi.getAccount("addr");
102
+ expect(account.sequence).toEqual(0);
103
+ }));
104
+ it("should return default pubkeytype value if network fails", () => __awaiter(void 0, void 0, void 0, function* () {
105
+ mockedNetwork.mockImplementation(() => {
106
+ throw new Error();
107
+ });
108
+ const account = yield cosmosApi.getAccount("addr");
109
+ expect(account.pubKeyType).toEqual((0, chain_1.default)("cosmos").defaultPubKeyType);
110
+ }));
111
+ });
112
+ describe("simulate", () => {
113
+ it("should return gas used when the network call returns gas used", () => __awaiter(void 0, void 0, void 0, function* () {
114
+ mockedNetwork.mockResolvedValue({
115
+ data: {
116
+ gas_info: {
117
+ gas_used: 42000,
118
+ },
119
+ },
120
+ });
121
+ const gas = yield cosmosApi.simulate([]);
122
+ expect(gas).toEqual(new bignumber_js_1.default(42000));
123
+ }));
124
+ it("should throw an error when the network call does not return gas used", () => __awaiter(void 0, void 0, void 0, function* () {
125
+ mockedNetwork.mockResolvedValue({
126
+ data: { gas_info: {} },
127
+ });
128
+ yield expect(cosmosApi.simulate([])).rejects.toThrowError();
129
+ }));
130
+ it("should throw an error when the network call fails", () => __awaiter(void 0, void 0, void 0, function* () {
131
+ mockedNetwork.mockImplementation(() => {
132
+ throw new Error();
133
+ });
134
+ yield expect(cosmosApi.simulate([])).rejects.toThrowError();
135
+ }));
136
+ });
137
+ describe("getTransactions", () => {
138
+ it("should return both recipient and sender tx", () => __awaiter(void 0, void 0, void 0, function* () {
139
+ // @ts-expect-error method is mocked
140
+ network_1.default.mockImplementation((networkOptions) => {
141
+ if (networkOptions.url.includes("recipient")) {
142
+ return Promise.resolve({
143
+ data: {
144
+ pagination: { total: 1 },
145
+ tx_responses: [
146
+ {
147
+ txhash: "recipienthash",
148
+ },
149
+ ],
150
+ },
151
+ });
152
+ }
153
+ else if (networkOptions.url.includes("sender")) {
154
+ return Promise.resolve({
155
+ data: {
156
+ pagination: { total: 1 },
157
+ tx_responses: [
158
+ {
159
+ txhash: "senderhash",
160
+ },
161
+ ],
162
+ },
163
+ });
164
+ }
165
+ else {
166
+ return Promise.resolve({
167
+ data: {
168
+ pagination: { total: 0 },
169
+ tx_responses: [],
170
+ },
171
+ });
172
+ }
173
+ });
174
+ const txs = yield cosmosApi.getTransactions("address", 50);
175
+ expect(txs.find(tx => tx.txhash === "senderhash")).toBeDefined();
176
+ expect(txs.find(tx => tx.txhash === "recipienthash")).toBeDefined();
177
+ expect(txs.length).toEqual(2);
178
+ }));
179
+ it("should return every pages of transactions", () => __awaiter(void 0, void 0, void 0, function* () {
180
+ const simulatedTotal = 500;
181
+ // @ts-expect-error method is mocked
182
+ network_1.default.mockImplementation((networkOptions) => {
183
+ const pageOffset = networkOptions.url.split("pagination.offset=")[1].split("&")[0];
184
+ const pageSize = Number(networkOptions.url.split("pagination.limit=")[1].split("&")[0]);
185
+ return Promise.resolve({
186
+ data: {
187
+ pagination: { total: simulatedTotal },
188
+ tx_responses: Array(pageSize)
189
+ .fill({})
190
+ .map((_, i) => ({
191
+ txhash: `${pageOffset}_${i}`,
192
+ })),
193
+ },
194
+ });
195
+ });
196
+ const txs = yield cosmosApi.getTransactions("address", 10);
197
+ // sender + recipient
198
+ expect(txs.length).toEqual(simulatedTotal * 2);
199
+ }));
200
+ });
201
+ describe("fetchTransactions", () => {
202
+ it("should fetch a pre v0.47 payload", () => __awaiter(void 0, void 0, void 0, function* () {
203
+ const nodeUrl = "nodeURL";
204
+ const sender = "cosmos1mzuuwf9djp25vkcjwc08g3tjsv64d94zj3txfp";
205
+ const pagination = {
206
+ limit: 100,
207
+ offset: 0,
208
+ reverse: true,
209
+ };
210
+ // @ts-expect-error method is mocked
211
+ network_1.default.mockImplementationOnce(({ url }) => {
212
+ if (url ===
213
+ `${nodeUrl}/cosmos/tx/v1beta1/txs?events=message.sender='${sender}'&pagination.limit=${pagination.limit}&pagination.offset=${pagination.offset}&pagination.reverse=${pagination.reverse}`) {
214
+ return {
215
+ data: {
216
+ txs: [],
217
+ tx_responses: [
218
+ {
219
+ height: "19827195",
220
+ txhash: "C4D4ED8F0E77DA1BB9CDA148F3500384AE6D2B14E3CBD338B866B79492AD3351",
221
+ codespace: "",
222
+ code: 0,
223
+ data: "12260A242F636F736D6F732E62616E6B2E763162657461312E4D736753656E64526573706F6E7365",
224
+ raw_log: '[{"msg_index":0,"events":[{"type":"message","attributes":[{"key":"action","value":"/cosmos.bank.v1beta1.MsgSend"},{"key":"sender","value":"cosmos1mzuuwf9djp25vkcjwc08g3tjsv64d94zj3txfp"},{"key":"module","value":"bank"}]},{"type":"coin_spent","attributes":[{"key":"spender","value":"cosmos1mzuuwf9djp25vkcjwc08g3tjsv64d94zj3txfp"},{"key":"amount","value":"100uatom"}]},{"type":"coin_received","attributes":[{"key":"receiver","value":"cosmos1qzjgrqjy894jx3luxfamrt2nz4rwx7nl8djyw3"},{"key":"amount","value":"100uatom"}]},{"type":"transfer","attributes":[{"key":"recipient","value":"cosmos1qzjgrqjy894jx3luxfamrt2nz4rwx7nl8djyw3"},{"key":"sender","value":"cosmos1mzuuwf9djp25vkcjwc08g3tjsv64d94zj3txfp"},{"key":"amount","value":"100uatom"}]},{"type":"message","attributes":[{"key":"sender","value":"cosmos1mzuuwf9djp25vkcjwc08g3tjsv64d94zj3txfp"}]}]}]',
225
+ logs: [
226
+ {
227
+ msg_index: 0,
228
+ log: "",
229
+ events: [
230
+ {
231
+ type: "message",
232
+ attributes: [
233
+ { key: "action", value: "/cosmos.bank.v1beta1.MsgSend" },
234
+ {
235
+ key: "sender",
236
+ value: "cosmos1mzuuwf9djp25vkcjwc08g3tjsv64d94zj3txfp",
237
+ },
238
+ { key: "module", value: "bank" },
239
+ ],
240
+ },
241
+ {
242
+ type: "coin_spent",
243
+ attributes: [
244
+ {
245
+ key: "spender",
246
+ value: "cosmos1mzuuwf9djp25vkcjwc08g3tjsv64d94zj3txfp",
247
+ },
248
+ { key: "amount", value: "100uatom" },
249
+ ],
250
+ },
251
+ {
252
+ type: "coin_received",
253
+ attributes: [
254
+ {
255
+ key: "receiver",
256
+ value: "cosmos1qzjgrqjy894jx3luxfamrt2nz4rwx7nl8djyw3",
257
+ },
258
+ { key: "amount", value: "100uatom" },
259
+ ],
260
+ },
261
+ {
262
+ type: "transfer",
263
+ attributes: [
264
+ {
265
+ key: "recipient",
266
+ value: "cosmos1qzjgrqjy894jx3luxfamrt2nz4rwx7nl8djyw3",
267
+ },
268
+ {
269
+ key: "sender",
270
+ value: "cosmos1mzuuwf9djp25vkcjwc08g3tjsv64d94zj3txfp",
271
+ },
272
+ { key: "amount", value: "100uatom" },
273
+ ],
274
+ },
275
+ {
276
+ type: "message",
277
+ attributes: [
278
+ {
279
+ key: "sender",
280
+ value: "cosmos1mzuuwf9djp25vkcjwc08g3tjsv64d94zj3txfp",
281
+ },
282
+ ],
283
+ },
284
+ ],
285
+ },
286
+ ],
287
+ info: "",
288
+ gas_wanted: "79806",
289
+ gas_used: "70948",
290
+ tx: {
291
+ "@type": "/cosmos.tx.v1beta1.Tx",
292
+ body: {
293
+ messages: [
294
+ {
295
+ "@type": "/cosmos.bank.v1beta1.MsgSend",
296
+ from_address: "cosmos1mzuuwf9djp25vkcjwc08g3tjsv64d94zj3txfp",
297
+ to_address: "cosmos1qzjgrqjy894jx3luxfamrt2nz4rwx7nl8djyw3",
298
+ amount: [{ denom: "uatom", amount: "100" }],
299
+ },
300
+ ],
301
+ memo: "",
302
+ timeout_height: "0",
303
+ extension_options: [],
304
+ non_critical_extension_options: [],
305
+ },
306
+ auth_info: {
307
+ signer_infos: [
308
+ {
309
+ public_key: {
310
+ "@type": "/cosmos.crypto.secp256k1.PubKey",
311
+ key: "AnvfR65YxO3gfGPcTY9Qc0EbJdwaqmC7W2oILWHpU+wp",
312
+ },
313
+ mode_info: { single: { mode: "SIGN_MODE_LEGACY_AMINO_JSON" } },
314
+ sequence: "0",
315
+ },
316
+ ],
317
+ fee: {
318
+ amount: [{ denom: "uatom", amount: "1996" }],
319
+ gas_limit: "79806",
320
+ payer: "",
321
+ granter: "",
322
+ },
323
+ tip: null,
324
+ },
325
+ signatures: [
326
+ "uAtttiPzG+VgDFTU1uZQ7Q7ijThbt/mhFegMHXsYvjh4WR9SFZ/iLWdvZrp+nX0LcJuflZ7ZGZwHO9ZH7yKMTg==",
327
+ ],
328
+ },
329
+ timestamp: "2024-04-02T17:03:53Z",
330
+ events: [
331
+ {
332
+ type: "coin_spent",
333
+ attributes: [
334
+ {
335
+ key: "spender",
336
+ value: "cosmos1mzuuwf9djp25vkcjwc08g3tjsv64d94zj3txfp",
337
+ index: true,
338
+ },
339
+ { key: "amount", value: "1996uatom", index: true },
340
+ ],
341
+ },
342
+ {
343
+ type: "coin_received",
344
+ attributes: [
345
+ {
346
+ key: "receiver",
347
+ value: "cosmos17xpfvakm2amg962yls6f84z3kell8c5lserqta",
348
+ index: true,
349
+ },
350
+ { key: "amount", value: "1996uatom", index: true },
351
+ ],
352
+ },
353
+ {
354
+ type: "transfer",
355
+ attributes: [
356
+ {
357
+ key: "recipient",
358
+ value: "cosmos17xpfvakm2amg962yls6f84z3kell8c5lserqta",
359
+ index: true,
360
+ },
361
+ {
362
+ key: "sender",
363
+ value: "cosmos1mzuuwf9djp25vkcjwc08g3tjsv64d94zj3txfp",
364
+ index: true,
365
+ },
366
+ { key: "amount", value: "1996uatom", index: true },
367
+ ],
368
+ },
369
+ {
370
+ type: "message",
371
+ attributes: [
372
+ {
373
+ key: "sender",
374
+ value: "cosmos1mzuuwf9djp25vkcjwc08g3tjsv64d94zj3txfp",
375
+ index: true,
376
+ },
377
+ ],
378
+ },
379
+ {
380
+ type: "tx",
381
+ attributes: [
382
+ { key: "fee", value: "1996uatom", index: true },
383
+ {
384
+ key: "fee_payer",
385
+ value: "cosmos1mzuuwf9djp25vkcjwc08g3tjsv64d94zj3txfp",
386
+ index: true,
387
+ },
388
+ ],
389
+ },
390
+ {
391
+ type: "tx",
392
+ attributes: [
393
+ {
394
+ key: "acc_seq",
395
+ value: "cosmos1mzuuwf9djp25vkcjwc08g3tjsv64d94zj3txfp/0",
396
+ index: true,
397
+ },
398
+ ],
399
+ },
400
+ {
401
+ type: "tx",
402
+ attributes: [
403
+ {
404
+ key: "signature",
405
+ value: "uAtttiPzG+VgDFTU1uZQ7Q7ijThbt/mhFegMHXsYvjh4WR9SFZ/iLWdvZrp+nX0LcJuflZ7ZGZwHO9ZH7yKMTg==",
406
+ index: true,
407
+ },
408
+ ],
409
+ },
410
+ {
411
+ type: "message",
412
+ attributes: [
413
+ { key: "action", value: "/cosmos.bank.v1beta1.MsgSend", index: true },
414
+ {
415
+ key: "sender",
416
+ value: "cosmos1mzuuwf9djp25vkcjwc08g3tjsv64d94zj3txfp",
417
+ index: true,
418
+ },
419
+ { key: "module", value: "bank", index: true },
420
+ ],
421
+ },
422
+ {
423
+ type: "coin_spent",
424
+ attributes: [
425
+ {
426
+ key: "spender",
427
+ value: "cosmos1mzuuwf9djp25vkcjwc08g3tjsv64d94zj3txfp",
428
+ index: true,
429
+ },
430
+ { key: "amount", value: "100uatom", index: true },
431
+ ],
432
+ },
433
+ {
434
+ type: "coin_received",
435
+ attributes: [
436
+ {
437
+ key: "receiver",
438
+ value: "cosmos1qzjgrqjy894jx3luxfamrt2nz4rwx7nl8djyw3",
439
+ index: true,
440
+ },
441
+ { key: "amount", value: "100uatom", index: true },
442
+ ],
443
+ },
444
+ {
445
+ type: "transfer",
446
+ attributes: [
447
+ {
448
+ key: "recipient",
449
+ value: "cosmos1qzjgrqjy894jx3luxfamrt2nz4rwx7nl8djyw3",
450
+ index: true,
451
+ },
452
+ {
453
+ key: "sender",
454
+ value: "cosmos1mzuuwf9djp25vkcjwc08g3tjsv64d94zj3txfp",
455
+ index: true,
456
+ },
457
+ { key: "amount", value: "100uatom", index: true },
458
+ ],
459
+ },
460
+ {
461
+ type: "message",
462
+ attributes: [
463
+ {
464
+ key: "sender",
465
+ value: "cosmos1mzuuwf9djp25vkcjwc08g3tjsv64d94zj3txfp",
466
+ index: true,
467
+ },
468
+ ],
469
+ },
470
+ ],
471
+ },
472
+ ],
473
+ pagination: null,
474
+ total: "1",
475
+ },
476
+ };
477
+ }
478
+ });
479
+ // using as object to access private method
480
+ const result = yield cosmosApi["fetchTransactions"](nodeUrl, "message.sender", sender, {
481
+ "pagination.limit": pagination.limit,
482
+ "pagination.offset": pagination.offset,
483
+ "pagination.reverse": pagination.reverse,
484
+ });
485
+ expect(result).toEqual({
486
+ txs: [
487
+ {
488
+ height: "19827195",
489
+ txhash: "C4D4ED8F0E77DA1BB9CDA148F3500384AE6D2B14E3CBD338B866B79492AD3351",
490
+ codespace: "",
491
+ code: 0,
492
+ data: "12260A242F636F736D6F732E62616E6B2E763162657461312E4D736753656E64526573706F6E7365",
493
+ raw_log: '[{"msg_index":0,"events":[{"type":"message","attributes":[{"key":"action","value":"/cosmos.bank.v1beta1.MsgSend"},{"key":"sender","value":"cosmos1mzuuwf9djp25vkcjwc08g3tjsv64d94zj3txfp"},{"key":"module","value":"bank"}]},{"type":"coin_spent","attributes":[{"key":"spender","value":"cosmos1mzuuwf9djp25vkcjwc08g3tjsv64d94zj3txfp"},{"key":"amount","value":"100uatom"}]},{"type":"coin_received","attributes":[{"key":"receiver","value":"cosmos1qzjgrqjy894jx3luxfamrt2nz4rwx7nl8djyw3"},{"key":"amount","value":"100uatom"}]},{"type":"transfer","attributes":[{"key":"recipient","value":"cosmos1qzjgrqjy894jx3luxfamrt2nz4rwx7nl8djyw3"},{"key":"sender","value":"cosmos1mzuuwf9djp25vkcjwc08g3tjsv64d94zj3txfp"},{"key":"amount","value":"100uatom"}]},{"type":"message","attributes":[{"key":"sender","value":"cosmos1mzuuwf9djp25vkcjwc08g3tjsv64d94zj3txfp"}]}]}]',
494
+ logs: [
495
+ {
496
+ msg_index: 0,
497
+ log: "",
498
+ events: [
499
+ {
500
+ type: "message",
501
+ attributes: [
502
+ { key: "action", value: "/cosmos.bank.v1beta1.MsgSend" },
503
+ {
504
+ key: "sender",
505
+ value: "cosmos1mzuuwf9djp25vkcjwc08g3tjsv64d94zj3txfp",
506
+ },
507
+ { key: "module", value: "bank" },
508
+ ],
509
+ },
510
+ {
511
+ type: "coin_spent",
512
+ attributes: [
513
+ {
514
+ key: "spender",
515
+ value: "cosmos1mzuuwf9djp25vkcjwc08g3tjsv64d94zj3txfp",
516
+ },
517
+ { key: "amount", value: "100uatom" },
518
+ ],
519
+ },
520
+ {
521
+ type: "coin_received",
522
+ attributes: [
523
+ {
524
+ key: "receiver",
525
+ value: "cosmos1qzjgrqjy894jx3luxfamrt2nz4rwx7nl8djyw3",
526
+ },
527
+ { key: "amount", value: "100uatom" },
528
+ ],
529
+ },
530
+ {
531
+ type: "transfer",
532
+ attributes: [
533
+ {
534
+ key: "recipient",
535
+ value: "cosmos1qzjgrqjy894jx3luxfamrt2nz4rwx7nl8djyw3",
536
+ },
537
+ {
538
+ key: "sender",
539
+ value: "cosmos1mzuuwf9djp25vkcjwc08g3tjsv64d94zj3txfp",
540
+ },
541
+ { key: "amount", value: "100uatom" },
542
+ ],
543
+ },
544
+ {
545
+ type: "message",
546
+ attributes: [
547
+ {
548
+ key: "sender",
549
+ value: "cosmos1mzuuwf9djp25vkcjwc08g3tjsv64d94zj3txfp",
550
+ },
551
+ ],
552
+ },
553
+ ],
554
+ },
555
+ ],
556
+ info: "",
557
+ gas_wanted: "79806",
558
+ gas_used: "70948",
559
+ tx: {
560
+ "@type": "/cosmos.tx.v1beta1.Tx",
561
+ body: {
562
+ messages: [
563
+ {
564
+ "@type": "/cosmos.bank.v1beta1.MsgSend",
565
+ from_address: "cosmos1mzuuwf9djp25vkcjwc08g3tjsv64d94zj3txfp",
566
+ to_address: "cosmos1qzjgrqjy894jx3luxfamrt2nz4rwx7nl8djyw3",
567
+ amount: [{ denom: "uatom", amount: "100" }],
568
+ },
569
+ ],
570
+ memo: "",
571
+ timeout_height: "0",
572
+ extension_options: [],
573
+ non_critical_extension_options: [],
574
+ },
575
+ auth_info: {
576
+ signer_infos: [
577
+ {
578
+ public_key: {
579
+ "@type": "/cosmos.crypto.secp256k1.PubKey",
580
+ key: "AnvfR65YxO3gfGPcTY9Qc0EbJdwaqmC7W2oILWHpU+wp",
581
+ },
582
+ mode_info: { single: { mode: "SIGN_MODE_LEGACY_AMINO_JSON" } },
583
+ sequence: "0",
584
+ },
585
+ ],
586
+ fee: {
587
+ amount: [{ denom: "uatom", amount: "1996" }],
588
+ gas_limit: "79806",
589
+ payer: "",
590
+ granter: "",
591
+ },
592
+ tip: null,
593
+ },
594
+ signatures: [
595
+ "uAtttiPzG+VgDFTU1uZQ7Q7ijThbt/mhFegMHXsYvjh4WR9SFZ/iLWdvZrp+nX0LcJuflZ7ZGZwHO9ZH7yKMTg==",
596
+ ],
597
+ },
598
+ timestamp: "2024-04-02T17:03:53Z",
599
+ events: [
600
+ {
601
+ type: "coin_spent",
602
+ attributes: [
603
+ {
604
+ key: "spender",
605
+ value: "cosmos1mzuuwf9djp25vkcjwc08g3tjsv64d94zj3txfp",
606
+ index: true,
607
+ },
608
+ { key: "amount", value: "1996uatom", index: true },
609
+ ],
610
+ },
611
+ {
612
+ type: "coin_received",
613
+ attributes: [
614
+ {
615
+ key: "receiver",
616
+ value: "cosmos17xpfvakm2amg962yls6f84z3kell8c5lserqta",
617
+ index: true,
618
+ },
619
+ { key: "amount", value: "1996uatom", index: true },
620
+ ],
621
+ },
622
+ {
623
+ type: "transfer",
624
+ attributes: [
625
+ {
626
+ key: "recipient",
627
+ value: "cosmos17xpfvakm2amg962yls6f84z3kell8c5lserqta",
628
+ index: true,
629
+ },
630
+ {
631
+ key: "sender",
632
+ value: "cosmos1mzuuwf9djp25vkcjwc08g3tjsv64d94zj3txfp",
633
+ index: true,
634
+ },
635
+ { key: "amount", value: "1996uatom", index: true },
636
+ ],
637
+ },
638
+ {
639
+ type: "message",
640
+ attributes: [
641
+ {
642
+ key: "sender",
643
+ value: "cosmos1mzuuwf9djp25vkcjwc08g3tjsv64d94zj3txfp",
644
+ index: true,
645
+ },
646
+ ],
647
+ },
648
+ {
649
+ type: "tx",
650
+ attributes: [
651
+ { key: "fee", value: "1996uatom", index: true },
652
+ {
653
+ key: "fee_payer",
654
+ value: "cosmos1mzuuwf9djp25vkcjwc08g3tjsv64d94zj3txfp",
655
+ index: true,
656
+ },
657
+ ],
658
+ },
659
+ {
660
+ type: "tx",
661
+ attributes: [
662
+ {
663
+ key: "acc_seq",
664
+ value: "cosmos1mzuuwf9djp25vkcjwc08g3tjsv64d94zj3txfp/0",
665
+ index: true,
666
+ },
667
+ ],
668
+ },
669
+ {
670
+ type: "tx",
671
+ attributes: [
672
+ {
673
+ key: "signature",
674
+ value: "uAtttiPzG+VgDFTU1uZQ7Q7ijThbt/mhFegMHXsYvjh4WR9SFZ/iLWdvZrp+nX0LcJuflZ7ZGZwHO9ZH7yKMTg==",
675
+ index: true,
676
+ },
677
+ ],
678
+ },
679
+ {
680
+ type: "message",
681
+ attributes: [
682
+ { key: "action", value: "/cosmos.bank.v1beta1.MsgSend", index: true },
683
+ {
684
+ key: "sender",
685
+ value: "cosmos1mzuuwf9djp25vkcjwc08g3tjsv64d94zj3txfp",
686
+ index: true,
687
+ },
688
+ { key: "module", value: "bank", index: true },
689
+ ],
690
+ },
691
+ {
692
+ type: "coin_spent",
693
+ attributes: [
694
+ {
695
+ key: "spender",
696
+ value: "cosmos1mzuuwf9djp25vkcjwc08g3tjsv64d94zj3txfp",
697
+ index: true,
698
+ },
699
+ { key: "amount", value: "100uatom", index: true },
700
+ ],
701
+ },
702
+ {
703
+ type: "coin_received",
704
+ attributes: [
705
+ {
706
+ key: "receiver",
707
+ value: "cosmos1qzjgrqjy894jx3luxfamrt2nz4rwx7nl8djyw3",
708
+ index: true,
709
+ },
710
+ { key: "amount", value: "100uatom", index: true },
711
+ ],
712
+ },
713
+ {
714
+ type: "transfer",
715
+ attributes: [
716
+ {
717
+ key: "recipient",
718
+ value: "cosmos1qzjgrqjy894jx3luxfamrt2nz4rwx7nl8djyw3",
719
+ index: true,
720
+ },
721
+ {
722
+ key: "sender",
723
+ value: "cosmos1mzuuwf9djp25vkcjwc08g3tjsv64d94zj3txfp",
724
+ index: true,
725
+ },
726
+ { key: "amount", value: "100uatom", index: true },
727
+ ],
728
+ },
729
+ {
730
+ type: "message",
731
+ attributes: [
732
+ {
733
+ key: "sender",
734
+ value: "cosmos1mzuuwf9djp25vkcjwc08g3tjsv64d94zj3txfp",
735
+ index: true,
736
+ },
737
+ ],
738
+ },
739
+ ],
740
+ },
741
+ ],
742
+ total: "1",
743
+ });
744
+ }));
745
+ });
746
+ describe("broadcastTransaction", () => {
747
+ it("should throw a SequenceNumberError exception in case of sequence number error", () => __awaiter(void 0, void 0, void 0, function* () {
748
+ mockedNetwork.mockResolvedValue({
749
+ data: { tx_response: { code: 32 } },
750
+ });
751
+ yield expect(cosmosApi.broadcast({ signedOperation: { operation: null, signature: "signedOperation" } })).rejects.toThrow("SequenceNumberError");
752
+ }));
753
+ });
754
+ });
755
+ //# sourceMappingURL=Cosmos.unit.test.js.map