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