@ledgerhq/coin-cosmos 0.18.0-nightly.6 → 0.18.0-nightly.7

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 (75) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +11 -0
  3. package/package.json +8 -8
  4. package/lib/bridge/index.test.d.ts +0 -2
  5. package/lib/bridge/index.test.d.ts.map +0 -1
  6. package/lib/bridge/index.test.js +0 -68
  7. package/lib/bridge/index.test.js.map +0 -1
  8. package/lib/buildTransaction.unit.test.d.ts +0 -2
  9. package/lib/buildTransaction.unit.test.d.ts.map +0 -1
  10. package/lib/buildTransaction.unit.test.js +0 -736
  11. package/lib/buildTransaction.unit.test.js.map +0 -1
  12. package/lib/chain/chain.unit.test.d.ts +0 -2
  13. package/lib/chain/chain.unit.test.d.ts.map +0 -1
  14. package/lib/chain/chain.unit.test.js +0 -41
  15. package/lib/chain/chain.unit.test.js.map +0 -1
  16. package/lib/helpers.unit.test.d.ts +0 -2
  17. package/lib/helpers.unit.test.d.ts.map +0 -1
  18. package/lib/helpers.unit.test.js +0 -65
  19. package/lib/helpers.unit.test.js.map +0 -1
  20. package/lib/network/Cosmos.unit.test.d.ts +0 -2
  21. package/lib/network/Cosmos.unit.test.d.ts.map +0 -1
  22. package/lib/network/Cosmos.unit.test.js +0 -580
  23. package/lib/network/Cosmos.unit.test.js.map +0 -1
  24. package/lib/prepareTransaction.unit.test.d.ts +0 -2
  25. package/lib/prepareTransaction.unit.test.d.ts.map +0 -1
  26. package/lib/prepareTransaction.unit.test.js +0 -159
  27. package/lib/prepareTransaction.unit.test.js.map +0 -1
  28. package/lib/synchronisation.integ.test.d.ts +0 -2
  29. package/lib/synchronisation.integ.test.d.ts.map +0 -1
  30. package/lib/synchronisation.integ.test.js +0 -233
  31. package/lib/synchronisation.integ.test.js.map +0 -1
  32. package/lib/synchronisation.test.d.ts +0 -2
  33. package/lib/synchronisation.test.d.ts.map +0 -1
  34. package/lib/synchronisation.test.js +0 -65
  35. package/lib/synchronisation.test.js.map +0 -1
  36. package/lib/synchronisation.unit.test.d.ts +0 -2
  37. package/lib/synchronisation.unit.test.d.ts.map +0 -1
  38. package/lib/synchronisation.unit.test.js +0 -667
  39. package/lib/synchronisation.unit.test.js.map +0 -1
  40. package/lib-es/bridge/index.test.d.ts +0 -2
  41. package/lib-es/bridge/index.test.d.ts.map +0 -1
  42. package/lib-es/bridge/index.test.js +0 -66
  43. package/lib-es/bridge/index.test.js.map +0 -1
  44. package/lib-es/buildTransaction.unit.test.d.ts +0 -2
  45. package/lib-es/buildTransaction.unit.test.d.ts.map +0 -1
  46. package/lib-es/buildTransaction.unit.test.js +0 -731
  47. package/lib-es/buildTransaction.unit.test.js.map +0 -1
  48. package/lib-es/chain/chain.unit.test.d.ts +0 -2
  49. package/lib-es/chain/chain.unit.test.d.ts.map +0 -1
  50. package/lib-es/chain/chain.unit.test.js +0 -36
  51. package/lib-es/chain/chain.unit.test.js.map +0 -1
  52. package/lib-es/helpers.unit.test.d.ts +0 -2
  53. package/lib-es/helpers.unit.test.d.ts.map +0 -1
  54. package/lib-es/helpers.unit.test.js +0 -63
  55. package/lib-es/helpers.unit.test.js.map +0 -1
  56. package/lib-es/network/Cosmos.unit.test.d.ts +0 -2
  57. package/lib-es/network/Cosmos.unit.test.d.ts.map +0 -1
  58. package/lib-es/network/Cosmos.unit.test.js +0 -575
  59. package/lib-es/network/Cosmos.unit.test.js.map +0 -1
  60. package/lib-es/prepareTransaction.unit.test.d.ts +0 -2
  61. package/lib-es/prepareTransaction.unit.test.d.ts.map +0 -1
  62. package/lib-es/prepareTransaction.unit.test.js +0 -131
  63. package/lib-es/prepareTransaction.unit.test.js.map +0 -1
  64. package/lib-es/synchronisation.integ.test.d.ts +0 -2
  65. package/lib-es/synchronisation.integ.test.d.ts.map +0 -1
  66. package/lib-es/synchronisation.integ.test.js +0 -205
  67. package/lib-es/synchronisation.integ.test.js.map +0 -1
  68. package/lib-es/synchronisation.test.d.ts +0 -2
  69. package/lib-es/synchronisation.test.d.ts.map +0 -1
  70. package/lib-es/synchronisation.test.js +0 -60
  71. package/lib-es/synchronisation.test.js.map +0 -1
  72. package/lib-es/synchronisation.unit.test.d.ts +0 -2
  73. package/lib-es/synchronisation.unit.test.d.ts.map +0 -1
  74. package/lib-es/synchronisation.unit.test.js +0 -639
  75. package/lib-es/synchronisation.unit.test.js.map +0 -1
@@ -1,736 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const bignumber_js_1 = __importDefault(require("bignumber.js"));
7
- const tx_1 = require("cosmjs-types/cosmos/staking/v1beta1/tx");
8
- const tx_2 = require("cosmjs-types/cosmos/distribution/v1beta1/tx");
9
- const tx_3 = require("cosmjs-types/cosmos/tx/v1beta1/tx");
10
- const cosmos_1 = require("@keplr-wallet/cosmos");
11
- const tx_4 = require("@keplr-wallet/proto-types/cosmos/tx/v1beta1/tx");
12
- const buildTransaction_1 = require("./buildTransaction");
13
- const veryBigNumber = new bignumber_js_1.default(3333300000000000000000);
14
- describe("txToMessages", () => {
15
- const transaction = {};
16
- const account = {
17
- freshAddress: "accAddress",
18
- currency: { units: [{ code: "atom" }, { code: "uatom" }] },
19
- };
20
- describe("When transaction mode is send", () => {
21
- beforeEach(() => {
22
- transaction.mode = "send";
23
- });
24
- describe("Amino", () => {
25
- it("should return a MsgSend message if transaction is complete", () => {
26
- transaction.recipient = "address";
27
- transaction.amount = new bignumber_js_1.default(1000);
28
- const { aminoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
29
- const [aminoMsg] = aminoMsgs;
30
- expect(aminoMsg).toBeTruthy();
31
- expect(aminoMsg.type).toContain("MsgSend");
32
- expect(aminoMsg.value.to_address).toEqual(transaction.recipient);
33
- expect(aminoMsg.value.from_address).toEqual(account.freshAddress);
34
- expect(aminoMsg.value.amount[0].amount).toEqual(transaction.amount.toFixed());
35
- expect(aminoMsg.value.amount[0].denom).toEqual(account.currency.units[1].code);
36
- });
37
- it("should not include exponential part on big numbers", () => {
38
- transaction.recipient = "address";
39
- transaction.amount = veryBigNumber;
40
- const { aminoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
41
- const [aminoMsg] = aminoMsgs;
42
- expect(aminoMsg.value.amount[0].amount.includes("e")).toEqual(false);
43
- });
44
- it("should return no message if recipient isn't defined", () => {
45
- transaction.amount = new bignumber_js_1.default(10);
46
- transaction.recipient = "";
47
- const { aminoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
48
- expect(aminoMsgs.length).toEqual(0);
49
- });
50
- it("should return no message if amount is zero", () => {
51
- transaction.amount = new bignumber_js_1.default(0);
52
- const { aminoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
53
- expect(aminoMsgs.length).toEqual(0);
54
- });
55
- it("should return no message if amount is negative", () => {
56
- transaction.amount = new bignumber_js_1.default(-10);
57
- const { aminoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
58
- expect(aminoMsgs.length).toEqual(0);
59
- });
60
- it("should return no message if amount is negative", () => {
61
- transaction.amount = new bignumber_js_1.default(-10);
62
- const { aminoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
63
- expect(aminoMsgs.length).toEqual(0);
64
- });
65
- });
66
- describe("Proto", () => {
67
- it("should return a MsgSend message if transaction is complete", () => {
68
- transaction.recipient = "address";
69
- transaction.amount = new bignumber_js_1.default(1000);
70
- const { protoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
71
- const [protoMsg] = protoMsgs;
72
- const value = cosmos_1.cosmos.bank.v1beta1.MsgSend.decode(protoMsg.value);
73
- expect(protoMsg).toBeTruthy();
74
- expect(protoMsg.typeUrl).toContain("MsgSend");
75
- expect(value.toAddress).toEqual(transaction.recipient);
76
- expect(value.fromAddress).toEqual(account.freshAddress);
77
- expect(value.amount[0].amount).toEqual(transaction.amount.toFixed());
78
- expect(value.amount[0].denom).toEqual(account.currency.units[1].code);
79
- });
80
- it("should not include exponential part on big numbers", () => {
81
- transaction.recipient = "address";
82
- transaction.amount = veryBigNumber;
83
- const { protoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
84
- const [protoMsg] = protoMsgs;
85
- const value = cosmos_1.cosmos.bank.v1beta1.MsgSend.decode(protoMsg.value);
86
- expect(value.amount[0].amount?.includes("e")).toEqual(false);
87
- });
88
- it("should return no message if recipient isn't defined", () => {
89
- transaction.amount = new bignumber_js_1.default(10);
90
- transaction.recipient = "";
91
- const { protoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
92
- expect(protoMsgs.length).toEqual(0);
93
- });
94
- it("should return no message if amount is zero", () => {
95
- transaction.amount = new bignumber_js_1.default(0);
96
- const { protoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
97
- expect(protoMsgs.length).toEqual(0);
98
- });
99
- it("should return no message if amount is negative", () => {
100
- transaction.amount = new bignumber_js_1.default(-10);
101
- const { protoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
102
- expect(protoMsgs.length).toEqual(0);
103
- });
104
- });
105
- });
106
- describe("When transaction mode is delegate", () => {
107
- beforeEach(() => {
108
- transaction.mode = "delegate";
109
- });
110
- describe("Amino", () => {
111
- it("should return a MsgDelegate message if transaction is complete", () => {
112
- transaction.amount = new bignumber_js_1.default(1000);
113
- transaction.validators = [
114
- {
115
- address: "realAddressTrustMe",
116
- amount: new bignumber_js_1.default(100),
117
- },
118
- ];
119
- const { aminoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
120
- const [message] = aminoMsgs;
121
- expect(message).toBeTruthy();
122
- expect(message.type).toContain("MsgDelegate");
123
- expect(message.value.validator_address).toEqual(transaction.validators[0].address);
124
- expect(message.value.delegator_address).toEqual(account.freshAddress);
125
- expect(message.value.amount?.amount).toEqual(transaction.amount.toFixed());
126
- expect(message.value.amount?.denom).toEqual(account.currency.units[1].code);
127
- });
128
- it("should not include exponential part on big numbers", () => {
129
- transaction.recipient = "address";
130
- transaction.amount = veryBigNumber;
131
- transaction.validators = [
132
- {
133
- address: "realAddressTrustMe",
134
- amount: veryBigNumber,
135
- },
136
- ];
137
- const { aminoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
138
- const [message] = aminoMsgs;
139
- expect(message.value.amount?.amount.includes("e")).toEqual(false);
140
- });
141
- it("should return no message if tx has a 0 amount", () => {
142
- transaction.amount = new bignumber_js_1.default(0);
143
- transaction.validators = [{ address: "realAddressTrustMe" }];
144
- const { aminoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
145
- expect(aminoMsgs.length).toEqual(0);
146
- });
147
- it("should return no message if tx has a negative amount", () => {
148
- transaction.amount = new bignumber_js_1.default(-1);
149
- transaction.validators = [{ address: "realAddressTrustMe" }];
150
- const { aminoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
151
- expect(aminoMsgs.length).toEqual(0);
152
- });
153
- it("should return no message if validators has no address", () => {
154
- transaction.validators = [{}];
155
- const { aminoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
156
- expect(aminoMsgs.length).toEqual(0);
157
- });
158
- it("should return no message if validators aren't defined", () => {
159
- transaction.validators = [];
160
- const { aminoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
161
- expect(aminoMsgs.length).toEqual(0);
162
- });
163
- });
164
- describe("Proto", () => {
165
- it("should return a MsgDelegate message if transaction is complete", () => {
166
- transaction.amount = new bignumber_js_1.default(1000);
167
- transaction.validators = [
168
- {
169
- address: "realAddressTrustMe",
170
- amount: new bignumber_js_1.default(100),
171
- },
172
- ];
173
- const { protoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
174
- const [message] = protoMsgs;
175
- expect(message).toBeTruthy();
176
- expect(message.typeUrl).toContain("MsgDelegate");
177
- const value = tx_1.MsgDelegate.decode(message.value);
178
- expect(value.validatorAddress).toEqual(transaction.validators[0].address);
179
- expect(value.delegatorAddress).toEqual(account.freshAddress);
180
- expect(value.amount?.amount).toEqual(transaction.amount.toFixed());
181
- expect(value.amount?.denom).toEqual(account.currency.units[1].code);
182
- });
183
- it("should not include exponential part on big numbers", () => {
184
- transaction.amount = veryBigNumber;
185
- transaction.validators = [
186
- {
187
- address: "realAddressTrustMe",
188
- amount: veryBigNumber,
189
- },
190
- ];
191
- const { protoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
192
- const [message] = protoMsgs;
193
- const value = tx_1.MsgDelegate.decode(message.value);
194
- expect(value.amount?.amount.includes("e")).toEqual(false);
195
- });
196
- it("should return no message if tx has a 0 amount", () => {
197
- transaction.amount = new bignumber_js_1.default(0);
198
- transaction.validators = [{ address: "realAddressTrustMe" }];
199
- const { protoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
200
- expect(protoMsgs.length).toEqual(0);
201
- });
202
- it("should return no message if tx has a negative amount", () => {
203
- transaction.amount = new bignumber_js_1.default(-1);
204
- transaction.validators = [{ address: "realAddressTrustMe" }];
205
- const { protoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
206
- expect(protoMsgs.length).toEqual(0);
207
- });
208
- it("should return no message if validators has no address", () => {
209
- transaction.validators = [{}];
210
- const { protoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
211
- expect(protoMsgs.length).toEqual(0);
212
- });
213
- it("should return no message if validators aren't defined", () => {
214
- transaction.validators = [];
215
- const { protoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
216
- expect(protoMsgs.length).toEqual(0);
217
- });
218
- });
219
- });
220
- describe("When transaction mode is undelegate", () => {
221
- beforeEach(() => {
222
- transaction.mode = "undelegate";
223
- });
224
- describe("Amino", () => {
225
- it("should return a MsgUndelegate message if transaction is complete", () => {
226
- transaction.amount = new bignumber_js_1.default(1000);
227
- transaction.validators = [
228
- {
229
- address: "realAddressTrustMe",
230
- amount: new bignumber_js_1.default(100),
231
- },
232
- ];
233
- const { aminoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
234
- const [message] = aminoMsgs;
235
- expect(message).toBeTruthy();
236
- expect(message.type).toContain("MsgUndelegate");
237
- expect(message.value.validator_address).toEqual(transaction.validators[0].address);
238
- expect(message.value.delegator_address).toEqual(account.freshAddress);
239
- expect(message.value.amount?.amount).toEqual(transaction.validators[0].amount.toFixed());
240
- expect(message.value.amount?.denom).toEqual(account.currency.units[1].code);
241
- });
242
- it("should not include exponential part on big numbers", () => {
243
- transaction.amount = veryBigNumber;
244
- transaction.validators = [
245
- {
246
- address: "realAddressTrustMe",
247
- amount: veryBigNumber,
248
- },
249
- ];
250
- const { aminoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
251
- const [message] = aminoMsgs;
252
- expect(message.value.amount?.amount.includes("e")).toEqual(false);
253
- });
254
- it("should return no message if validators aren't defined", () => {
255
- transaction.validators = [];
256
- const { aminoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
257
- expect(aminoMsgs.length).toEqual(0);
258
- });
259
- it("should return no message if validator address isn't defined", () => {
260
- transaction.validators = [
261
- {
262
- address: "",
263
- amount: new bignumber_js_1.default(100),
264
- },
265
- ];
266
- const { aminoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
267
- expect(aminoMsgs.length).toEqual(0);
268
- });
269
- it("should return no message if validator amount is 0", () => {
270
- transaction.validators = [
271
- {
272
- address: "address",
273
- amount: new bignumber_js_1.default(0),
274
- },
275
- ];
276
- const { aminoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
277
- expect(aminoMsgs.length).toEqual(0);
278
- });
279
- it("should return no message if validator amount is negative", () => {
280
- transaction.validators = [
281
- {
282
- address: "address",
283
- amount: new bignumber_js_1.default(-10),
284
- },
285
- ];
286
- const { aminoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
287
- expect(aminoMsgs.length).toEqual(0);
288
- });
289
- });
290
- describe("Proto", () => {
291
- it("should return a MsgUndelegate message if transaction is complete", () => {
292
- transaction.amount = new bignumber_js_1.default(1000);
293
- transaction.validators = [
294
- {
295
- address: "realAddressTrustMe",
296
- amount: new bignumber_js_1.default(100),
297
- },
298
- ];
299
- const { protoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
300
- const [message] = protoMsgs;
301
- expect(message).toBeTruthy();
302
- expect(message.typeUrl).toContain("MsgUndelegate");
303
- const value = tx_1.MsgUndelegate.decode(message.value);
304
- expect(value.validatorAddress).toEqual(transaction.validators[0].address);
305
- expect(value.delegatorAddress).toEqual(account.freshAddress);
306
- expect(value.amount?.amount).toEqual(transaction.validators[0].amount.toFixed());
307
- expect(value.amount?.denom).toEqual(account.currency.units[1].code);
308
- });
309
- it("should not include exponential part on big numbers", () => {
310
- transaction.amount = veryBigNumber;
311
- transaction.validators = [
312
- {
313
- address: "realAddressTrustMe",
314
- amount: veryBigNumber,
315
- },
316
- ];
317
- const { protoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
318
- const [message] = protoMsgs;
319
- const value = tx_1.MsgUndelegate.decode(message.value);
320
- expect(value.amount?.amount.includes("e")).toEqual(false);
321
- });
322
- it("should return no message if validators aren't defined", () => {
323
- transaction.validators = [];
324
- const { protoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
325
- expect(protoMsgs.length).toEqual(0);
326
- });
327
- it("should return no message if validator address isn't defined", () => {
328
- transaction.validators = [
329
- {
330
- address: "",
331
- amount: new bignumber_js_1.default(100),
332
- },
333
- ];
334
- const { protoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
335
- expect(protoMsgs.length).toEqual(0);
336
- });
337
- it("should return no message if validator amount is 0", () => {
338
- transaction.validators = [
339
- {
340
- address: "address",
341
- amount: new bignumber_js_1.default(0),
342
- },
343
- ];
344
- const { protoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
345
- expect(protoMsgs.length).toEqual(0);
346
- });
347
- it("should return no message if validator amount is negative", () => {
348
- transaction.validators = [
349
- {
350
- address: "address",
351
- amount: new bignumber_js_1.default(-10),
352
- },
353
- ];
354
- const { protoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
355
- expect(protoMsgs.length).toEqual(0);
356
- });
357
- });
358
- });
359
- describe("When transaction mode is redelegate", () => {
360
- beforeEach(() => {
361
- transaction.mode = "redelegate";
362
- });
363
- describe("Amino", () => {
364
- it("should return a MsgBeginRedelegate message if transaction is complete", () => {
365
- transaction.sourceValidator = "source";
366
- transaction.validators = [
367
- {
368
- address: "realAddressTrustMe",
369
- amount: new bignumber_js_1.default(100),
370
- },
371
- ];
372
- const { aminoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
373
- const [message] = aminoMsgs;
374
- expect(message).toBeTruthy();
375
- expect(message.type).toContain("MsgBeginRedelegate");
376
- expect(message.value.validator_src_address).toEqual(transaction.sourceValidator);
377
- expect(message.value.validator_dst_address).toEqual(transaction.validators[0].address);
378
- expect(message.value.delegator_address).toEqual(account.freshAddress);
379
- expect(message.value.amount.amount).toEqual(transaction.validators[0].amount.toFixed());
380
- expect(message.value.amount.denom).toEqual(account.currency.units[1].code);
381
- });
382
- it("should not include exponential part on big numbers", () => {
383
- transaction.sourceValidator = "source";
384
- transaction.validators = [
385
- {
386
- address: "realAddressTrustMe",
387
- amount: veryBigNumber,
388
- },
389
- ];
390
- const { aminoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
391
- const [message] = aminoMsgs;
392
- expect(message.value.amount.amount.includes("e")).toEqual(false);
393
- });
394
- it("should return no message if sourceValidator isn't defined", () => {
395
- transaction.sourceValidator = "";
396
- transaction.validators = [
397
- {
398
- address: "address",
399
- amount: new bignumber_js_1.default(100),
400
- },
401
- ];
402
- const { aminoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
403
- expect(aminoMsgs.length).toEqual(0);
404
- });
405
- it("should return no message if validator address isn't defined", () => {
406
- transaction.validators = [
407
- {
408
- address: "",
409
- amount: new bignumber_js_1.default(100),
410
- },
411
- ];
412
- const { aminoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
413
- expect(aminoMsgs.length).toEqual(0);
414
- });
415
- it("should return no message if validator amount is 0", () => {
416
- transaction.validators = [
417
- {
418
- address: "address",
419
- amount: new bignumber_js_1.default(0),
420
- },
421
- ];
422
- const { aminoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
423
- expect(aminoMsgs.length).toEqual(0);
424
- });
425
- it("should return no message if validator amount is negative", () => {
426
- transaction.validators = [
427
- {
428
- address: "address",
429
- amount: new bignumber_js_1.default(-10),
430
- },
431
- ];
432
- const { aminoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
433
- expect(aminoMsgs.length).toEqual(0);
434
- });
435
- });
436
- describe("Proto", () => {
437
- it("should return a MsgBeginRedelegate message if transaction is complete", () => {
438
- transaction.sourceValidator = "source";
439
- transaction.validators = [
440
- {
441
- address: "realAddressTrustMe",
442
- amount: new bignumber_js_1.default(100),
443
- },
444
- ];
445
- const { protoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
446
- const [message] = protoMsgs;
447
- expect(message).toBeTruthy();
448
- expect(message.typeUrl).toContain("MsgBeginRedelegate");
449
- const value = tx_1.MsgBeginRedelegate.decode(message.value);
450
- expect(value.validatorSrcAddress).toEqual(transaction.sourceValidator);
451
- expect(value.validatorDstAddress).toEqual(transaction.validators[0].address);
452
- expect(value.delegatorAddress).toEqual(account.freshAddress);
453
- expect(value.amount?.amount).toEqual(transaction.validators[0].amount.toFixed());
454
- expect(value.amount?.denom).toEqual(account.currency.units[1].code);
455
- });
456
- it("should not include exponential part on big numbers", () => {
457
- transaction.sourceValidator = "source";
458
- transaction.validators = [
459
- {
460
- address: "realAddressTrustMe",
461
- amount: veryBigNumber,
462
- },
463
- ];
464
- const { protoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
465
- const [message] = protoMsgs;
466
- expect(message).toBeTruthy();
467
- const value = tx_1.MsgBeginRedelegate.decode(message.value);
468
- expect(value.amount?.amount.includes("e")).toEqual(false);
469
- });
470
- it("should return no message if sourceValidator isn't defined", () => {
471
- transaction.sourceValidator = "";
472
- transaction.validators = [
473
- {
474
- address: "address",
475
- amount: new bignumber_js_1.default(100),
476
- },
477
- ];
478
- const { protoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
479
- expect(protoMsgs.length).toEqual(0);
480
- });
481
- it("should return no message if validator address isn't defined", () => {
482
- transaction.validators = [
483
- {
484
- address: "",
485
- amount: new bignumber_js_1.default(100),
486
- },
487
- ];
488
- const { protoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
489
- expect(protoMsgs.length).toEqual(0);
490
- });
491
- it("should return no message if validator amount is 0", () => {
492
- transaction.validators = [
493
- {
494
- address: "address",
495
- amount: new bignumber_js_1.default(0),
496
- },
497
- ];
498
- const { protoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
499
- expect(protoMsgs.length).toEqual(0);
500
- });
501
- it("should return no message if validator amount is negative", () => {
502
- transaction.validators = [
503
- {
504
- address: "address",
505
- amount: new bignumber_js_1.default(-10),
506
- },
507
- ];
508
- const { protoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
509
- expect(protoMsgs.length).toEqual(0);
510
- });
511
- });
512
- });
513
- describe("When transaction mode is claimReward", () => {
514
- beforeEach(() => {
515
- transaction.mode = "claimReward";
516
- });
517
- describe("Amino", () => {
518
- it("should return a MsgWithdrawDelegationReward message if transaction is complete", () => {
519
- transaction.validators = [
520
- {
521
- address: "iAmAValidatorAddress",
522
- amount: new bignumber_js_1.default(1000),
523
- },
524
- ];
525
- const { aminoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
526
- const [message] = aminoMsgs;
527
- expect(message).toBeTruthy();
528
- expect(message.type).toContain("MsgWithdrawDelegationReward");
529
- expect(message.value.validator_address).toEqual(transaction.validators[0].address);
530
- expect(message.value.delegator_address).toEqual(account.freshAddress);
531
- });
532
- it("should return no message if validator isn't defined", () => {
533
- transaction.validators = [];
534
- const { aminoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
535
- expect(aminoMsgs.length).toEqual(0);
536
- });
537
- it("should return no message if validator address isn't defined", () => {
538
- transaction.validators = [
539
- {
540
- address: "",
541
- amount: new bignumber_js_1.default(1000),
542
- },
543
- ];
544
- const { aminoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
545
- expect(aminoMsgs.length).toEqual(0);
546
- });
547
- });
548
- describe("Proto", () => {
549
- it("should return a MsgWithdrawDelegatorReward message if transaction is complete", () => {
550
- transaction.validators = [
551
- {
552
- address: "iAmAValidatorAddress",
553
- amount: new bignumber_js_1.default(1000),
554
- },
555
- ];
556
- const { protoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
557
- const [message] = protoMsgs;
558
- expect(message).toBeTruthy();
559
- expect(message.typeUrl).toContain("MsgWithdrawDelegatorReward");
560
- const value = tx_2.MsgWithdrawDelegatorReward.decode(message.value);
561
- expect(value.validatorAddress).toEqual(transaction.validators[0].address);
562
- expect(value.delegatorAddress).toEqual(account.freshAddress);
563
- });
564
- it("should return no message if validator isn't defined", () => {
565
- transaction.validators = [];
566
- const { protoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
567
- expect(protoMsgs.length).toEqual(0);
568
- });
569
- it("should return no message if validator address isn't defined", () => {
570
- transaction.validators = [
571
- {
572
- address: "",
573
- amount: new bignumber_js_1.default(1000),
574
- },
575
- ];
576
- const { protoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
577
- expect(protoMsgs.length).toEqual(0);
578
- });
579
- });
580
- });
581
- describe("When transaction mode is claimRewardCompound", () => {
582
- beforeEach(() => {
583
- transaction.mode = "claimRewardCompound";
584
- });
585
- describe("Amino", () => {
586
- it("should return a MsgWithdrawDelegationReward message and a MsgDelegate if transaction is complete", () => {
587
- transaction.validators = [
588
- {
589
- address: "iAmAValidatorAddress",
590
- amount: new bignumber_js_1.default(1000),
591
- },
592
- ];
593
- const { aminoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
594
- const [withDrawMessage, delegateMessage] = aminoMsgs;
595
- expect(withDrawMessage).toBeTruthy();
596
- expect(withDrawMessage.type).toContain("MsgWithdrawDelegationReward");
597
- expect(withDrawMessage.value.validator_address).toEqual(transaction.validators[0].address);
598
- expect(withDrawMessage.value.delegator_address).toEqual(account.freshAddress);
599
- expect(delegateMessage).toBeTruthy();
600
- expect(delegateMessage.type).toContain("MsgDelegate");
601
- expect(delegateMessage.value.validator_address).toEqual(transaction.validators[0].address);
602
- expect(delegateMessage.value.delegator_address).toEqual(account.freshAddress);
603
- expect(delegateMessage.value.amount.amount).toEqual(transaction.validators[0].amount.toFixed());
604
- expect(delegateMessage.value.amount.denom).toEqual(account.currency.units[1].code);
605
- });
606
- it("should not include exponential part on big numbers", () => {
607
- transaction.validators = [
608
- {
609
- address: "iAmAValidatorAddress",
610
- amount: veryBigNumber,
611
- },
612
- ];
613
- const { aminoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
614
- const [, delegateMessage] = aminoMsgs;
615
- expect(delegateMessage.value.amount.amount.includes("e")).toEqual(false);
616
- });
617
- });
618
- describe("Proto", () => {
619
- it("should return a MsgWithdrawDelegatorReward message and a MsgDelegate if transaction is complete", () => {
620
- transaction.validators = [
621
- {
622
- address: "iAmAValidatorAddress",
623
- amount: new bignumber_js_1.default(1000),
624
- },
625
- ];
626
- const { protoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
627
- const [withDrawMessage, delegateMessage] = protoMsgs;
628
- expect(withDrawMessage).toBeTruthy();
629
- expect(withDrawMessage.typeUrl).toContain("MsgWithdrawDelegatorReward");
630
- const withDrawMessageValue = tx_2.MsgWithdrawDelegatorReward.decode(withDrawMessage.value);
631
- expect(withDrawMessageValue.validatorAddress).toEqual(transaction.validators[0].address);
632
- expect(withDrawMessageValue.delegatorAddress).toEqual(account.freshAddress);
633
- expect(delegateMessage).toBeTruthy();
634
- expect(delegateMessage.typeUrl).toContain("MsgDelegate");
635
- const delegateMessageValue = tx_1.MsgDelegate.decode(delegateMessage.value);
636
- expect(delegateMessageValue.validatorAddress).toEqual(transaction.validators[0].address);
637
- expect(delegateMessageValue.delegatorAddress).toEqual(account.freshAddress);
638
- expect(delegateMessageValue.amount?.amount).toEqual(transaction.validators[0].amount.toFixed());
639
- expect(delegateMessageValue.amount?.denom).toEqual(account.currency.units[1].code);
640
- });
641
- it("should return a MsgWithdrawDelegatorReward message and a MsgDelegate if transaction is complete", () => {
642
- transaction.validators = [
643
- {
644
- address: "iAmAValidatorAddress",
645
- amount: veryBigNumber,
646
- },
647
- ];
648
- const { protoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
649
- const [, delegateMessage] = protoMsgs;
650
- const delegateMessageValue = tx_1.MsgDelegate.decode(delegateMessage.value);
651
- expect(delegateMessageValue.amount?.amount.includes("e")).toEqual(false);
652
- });
653
- });
654
- });
655
- describe("When transaction mode isn't known", () => {
656
- describe("Amino", () => {
657
- it("should return no message", () => {
658
- // @ts-expect-error Random mode that isn't listed in typescript type
659
- transaction.mode = "RandomModeThatICreatedMyself";
660
- const { aminoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
661
- expect(aminoMsgs.length).toEqual(0);
662
- });
663
- });
664
- describe("Proto", () => {
665
- it("should return no message", () => {
666
- // @ts-expect-error Random mode that isn't listed in typescript type
667
- transaction.mode = "RandomModeThatICreatedMyself";
668
- const { protoMsgs } = (0, buildTransaction_1.txToMessages)(account, transaction);
669
- expect(protoMsgs.length).toEqual(0);
670
- });
671
- });
672
- });
673
- });
674
- describe("buildTransaction", () => {
675
- let bodyFromPartialSpy;
676
- let feeFromPartialSpy;
677
- let txRawEncodeSpy;
678
- const defaultInfos = {
679
- memo: "test",
680
- pubKey: "pubkey",
681
- sequence: "1",
682
- protoMsgs: [],
683
- pubKeyType: "type",
684
- signature: new Uint8Array(),
685
- feeAmount: undefined,
686
- gasLimit: undefined,
687
- };
688
- beforeEach(() => {
689
- bodyFromPartialSpy = jest.spyOn(tx_3.TxBody, "fromPartial");
690
- feeFromPartialSpy = jest.spyOn(tx_4.Fee, "fromPartial");
691
- txRawEncodeSpy = jest.spyOn(tx_3.TxRaw, "encode");
692
- });
693
- afterEach(() => {
694
- jest.clearAllMocks();
695
- });
696
- it("should set memo", () => {
697
- (0, buildTransaction_1.buildTransaction)({ ...defaultInfos, memo: "toto" });
698
- expect(bodyFromPartialSpy).toHaveBeenCalledWith(expect.objectContaining({
699
- memo: "toto",
700
- }));
701
- });
702
- it("should set gasLimit", () => {
703
- (0, buildTransaction_1.buildTransaction)({ ...defaultInfos, gasLimit: "10" });
704
- expect(feeFromPartialSpy).toHaveBeenCalledWith(expect.objectContaining({
705
- gasLimit: "10",
706
- }));
707
- });
708
- it("should set messages", () => {
709
- (0, buildTransaction_1.buildTransaction)({
710
- ...defaultInfos,
711
- protoMsgs: [
712
- {
713
- typeUrl: "typeUrl",
714
- value: new Uint8Array(),
715
- },
716
- ],
717
- });
718
- expect(bodyFromPartialSpy).toHaveBeenCalledWith(expect.objectContaining({
719
- messages: [
720
- {
721
- typeUrl: "typeUrl",
722
- value: new Uint8Array(),
723
- },
724
- ],
725
- }));
726
- });
727
- it("should set signature", () => {
728
- const signature = new Uint8Array([8]);
729
- (0, buildTransaction_1.buildTransaction)({
730
- ...defaultInfos,
731
- signature,
732
- });
733
- expect(txRawEncodeSpy).toHaveBeenCalledWith(expect.objectContaining({ signatures: [signature] }));
734
- });
735
- });
736
- //# sourceMappingURL=buildTransaction.unit.test.js.map