@ledgerhq/coin-cosmos 0.18.0-nightly.6 → 0.18.0-nightly.8
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 +18 -0
- package/package.json +8 -8
- 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,667 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
30
|
-
const jsHelpers = __importStar(require("@ledgerhq/coin-framework/bridge/jsHelpers"));
|
|
31
|
-
const Cosmos_1 = require("./network/Cosmos");
|
|
32
|
-
const synchronisation_1 = require("./synchronisation");
|
|
33
|
-
jest.mock("./network/Cosmos");
|
|
34
|
-
jest.mock("@ledgerhq/coin-framework/account");
|
|
35
|
-
jest.mock("@ledgerhq/coin-framework/bridge/jsHelpers");
|
|
36
|
-
const infoMock = {
|
|
37
|
-
currency: {
|
|
38
|
-
units: [{}, { code: "uatom" }],
|
|
39
|
-
},
|
|
40
|
-
address: "address",
|
|
41
|
-
index: 0,
|
|
42
|
-
};
|
|
43
|
-
const baseAccountInfoMock = {
|
|
44
|
-
txs: [],
|
|
45
|
-
delegations: [],
|
|
46
|
-
unbondings: [],
|
|
47
|
-
balances: new bignumber_js_1.default(0),
|
|
48
|
-
accountInfo: { sequence: 0, accountNumber: 0 },
|
|
49
|
-
};
|
|
50
|
-
const baseTxMock = {
|
|
51
|
-
logs: [],
|
|
52
|
-
txhash: "2",
|
|
53
|
-
tx: {
|
|
54
|
-
auth_info: {
|
|
55
|
-
signer_infos: [{ sequence: "seq" }],
|
|
56
|
-
fee: { amount: [{ denom: "uatom", amount: new bignumber_js_1.default(1) }] },
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
|
-
const syncConfig = {};
|
|
61
|
-
function mockAccountInfo(partialMock) {
|
|
62
|
-
// @ts-expect-error mocked
|
|
63
|
-
Cosmos_1.CosmosAPI.mockReturnValueOnce({
|
|
64
|
-
getAccountInfo: jest.fn().mockResolvedValue({ ...baseAccountInfoMock, ...partialMock }),
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
function mockCosmosTx(tx) {
|
|
68
|
-
return {
|
|
69
|
-
events: [
|
|
70
|
-
{
|
|
71
|
-
type: "withdraw_rewards",
|
|
72
|
-
attributes: [
|
|
73
|
-
{
|
|
74
|
-
key: "amount",
|
|
75
|
-
value: "10uatom",
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
key: "validator",
|
|
79
|
-
value: "validatorAddressHehe",
|
|
80
|
-
},
|
|
81
|
-
],
|
|
82
|
-
},
|
|
83
|
-
],
|
|
84
|
-
logs: [],
|
|
85
|
-
txhash: "2",
|
|
86
|
-
tx: {
|
|
87
|
-
"@type": "/cosmos.tx.v1beta1.Tx",
|
|
88
|
-
body: {
|
|
89
|
-
messages: [
|
|
90
|
-
{
|
|
91
|
-
"@type": "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward",
|
|
92
|
-
delegator_address: "address",
|
|
93
|
-
validator_address: "validatorAddressHehe",
|
|
94
|
-
},
|
|
95
|
-
],
|
|
96
|
-
memo: "Ledger Live",
|
|
97
|
-
timeout_height: "0",
|
|
98
|
-
extension_options: [],
|
|
99
|
-
non_critical_extension_options: [],
|
|
100
|
-
},
|
|
101
|
-
auth_info: {
|
|
102
|
-
signer_infos: [{ sequence: "seq" }],
|
|
103
|
-
fee: { amount: [{ denom: "uatom", amount: new bignumber_js_1.default(0) }] },
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
code: 0,
|
|
107
|
-
...tx,
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
describe("getAccountShape", () => {
|
|
111
|
-
let mergeOpsSpy;
|
|
112
|
-
beforeEach(() => {
|
|
113
|
-
// @ts-expect-error mocked
|
|
114
|
-
Cosmos_1.CosmosAPI.mockClear();
|
|
115
|
-
mergeOpsSpy = jest
|
|
116
|
-
.spyOn(jsHelpers, "mergeOps")
|
|
117
|
-
.mockImplementation((existing, newlyFetched) => [
|
|
118
|
-
...existing,
|
|
119
|
-
...newlyFetched,
|
|
120
|
-
]);
|
|
121
|
-
});
|
|
122
|
-
afterEach(() => {
|
|
123
|
-
mergeOpsSpy.mockReset();
|
|
124
|
-
});
|
|
125
|
-
it("should sum up delegations to balance", async () => {
|
|
126
|
-
mockAccountInfo({
|
|
127
|
-
balances: new bignumber_js_1.default(1),
|
|
128
|
-
delegations: [{ amount: new bignumber_js_1.default(2) }],
|
|
129
|
-
});
|
|
130
|
-
const account = await (0, synchronisation_1.getAccountShape)(infoMock, syncConfig);
|
|
131
|
-
expect(account.balance).toEqual(new bignumber_js_1.default(3));
|
|
132
|
-
});
|
|
133
|
-
it("should sum up delegation balances and assign it in cosmosResources delegatedBalances", async () => {
|
|
134
|
-
mockAccountInfo({
|
|
135
|
-
delegations: [{ amount: new bignumber_js_1.default(1) }, { amount: new bignumber_js_1.default(2) }],
|
|
136
|
-
});
|
|
137
|
-
const account = await (0, synchronisation_1.getAccountShape)(infoMock, syncConfig);
|
|
138
|
-
expect(account.cosmosResources.delegatedBalance).toEqual(new bignumber_js_1.default(3));
|
|
139
|
-
});
|
|
140
|
-
it("should sum up unbondings to balance", async () => {
|
|
141
|
-
mockAccountInfo({
|
|
142
|
-
balances: new bignumber_js_1.default(2),
|
|
143
|
-
unbondings: [{ amount: new bignumber_js_1.default(3) }],
|
|
144
|
-
});
|
|
145
|
-
const account = await (0, synchronisation_1.getAccountShape)(infoMock, syncConfig);
|
|
146
|
-
expect(account.balance).toEqual(new bignumber_js_1.default(5));
|
|
147
|
-
});
|
|
148
|
-
it("estimate spendable balance correctly", async () => {
|
|
149
|
-
// Shouldn't it be 97 ?
|
|
150
|
-
mockAccountInfo({
|
|
151
|
-
balances: new bignumber_js_1.default(100),
|
|
152
|
-
unbondings: [{ amount: new bignumber_js_1.default(1) }],
|
|
153
|
-
delegations: [{ amount: new bignumber_js_1.default(2) }],
|
|
154
|
-
});
|
|
155
|
-
const account = await (0, synchronisation_1.getAccountShape)(infoMock, syncConfig);
|
|
156
|
-
expect(account.spendableBalance).toEqual(new bignumber_js_1.default(100));
|
|
157
|
-
});
|
|
158
|
-
it("should reduce balance to 0 if spendable balance is negative", async () => {
|
|
159
|
-
mockAccountInfo({
|
|
160
|
-
balances: new bignumber_js_1.default(-10),
|
|
161
|
-
});
|
|
162
|
-
const account = await (0, synchronisation_1.getAccountShape)(infoMock, syncConfig);
|
|
163
|
-
expect(account.spendableBalance).toEqual(new bignumber_js_1.default(0));
|
|
164
|
-
});
|
|
165
|
-
it("should sum up pendingRewards and insert it in cosmosResources", async () => {
|
|
166
|
-
mockAccountInfo({
|
|
167
|
-
delegations: [
|
|
168
|
-
{
|
|
169
|
-
pendingRewards: new bignumber_js_1.default(1),
|
|
170
|
-
},
|
|
171
|
-
{
|
|
172
|
-
pendingRewards: new bignumber_js_1.default(2),
|
|
173
|
-
},
|
|
174
|
-
],
|
|
175
|
-
});
|
|
176
|
-
const account = await (0, synchronisation_1.getAccountShape)(infoMock, syncConfig);
|
|
177
|
-
expect(account.cosmosResources.pendingRewardsBalance).toEqual(new bignumber_js_1.default(3));
|
|
178
|
-
});
|
|
179
|
-
it("set spendable balance to 0 if spendable balance is negative in initial account", async () => {
|
|
180
|
-
mockAccountInfo({});
|
|
181
|
-
const account = await (0, synchronisation_1.getAccountShape)({
|
|
182
|
-
...infoMock,
|
|
183
|
-
initialAccount: {
|
|
184
|
-
spendableBalance: new bignumber_js_1.default(-10),
|
|
185
|
-
},
|
|
186
|
-
}, syncConfig);
|
|
187
|
-
expect(account.spendableBalance).toEqual(new bignumber_js_1.default(0));
|
|
188
|
-
});
|
|
189
|
-
it("should estimate operations count correctly", async () => {
|
|
190
|
-
mockAccountInfo({});
|
|
191
|
-
const account = await (0, synchronisation_1.getAccountShape)({
|
|
192
|
-
...infoMock,
|
|
193
|
-
initialAccount: {
|
|
194
|
-
operations: [{}, {}],
|
|
195
|
-
},
|
|
196
|
-
}, syncConfig);
|
|
197
|
-
expect(account.operationsCount).toEqual(2);
|
|
198
|
-
});
|
|
199
|
-
it("should merge old operations with newly fetched ones", async () => {
|
|
200
|
-
const existingOperations = [{ hash: "3", id: "3" }];
|
|
201
|
-
mockAccountInfo({});
|
|
202
|
-
await (0, synchronisation_1.getAccountShape)({
|
|
203
|
-
...infoMock,
|
|
204
|
-
initialAccount: {
|
|
205
|
-
operations: existingOperations,
|
|
206
|
-
},
|
|
207
|
-
}, syncConfig);
|
|
208
|
-
expect(mergeOpsSpy.mock.calls[0][0]).toEqual(existingOperations);
|
|
209
|
-
});
|
|
210
|
-
it("should add newly fetched operations", async () => {
|
|
211
|
-
mockAccountInfo({ txs: [mockCosmosTx({})] });
|
|
212
|
-
await (0, synchronisation_1.getAccountShape)(infoMock, syncConfig);
|
|
213
|
-
expect(mergeOpsSpy.mock.calls[0][1]).toBeTruthy();
|
|
214
|
-
});
|
|
215
|
-
it("should get the memo correctly", async () => {
|
|
216
|
-
mockAccountInfo({ txs: [mockCosmosTx({})] });
|
|
217
|
-
const account = await (0, synchronisation_1.getAccountShape)(infoMock, syncConfig);
|
|
218
|
-
expect(account.operations[0].extra.memo).toEqual("Ledger Live");
|
|
219
|
-
});
|
|
220
|
-
it("should list claim reward operations correctly with one delegation", async () => {
|
|
221
|
-
mockAccountInfo({
|
|
222
|
-
txs: [
|
|
223
|
-
mockCosmosTx({
|
|
224
|
-
events: [
|
|
225
|
-
{
|
|
226
|
-
type: "withdraw_rewards",
|
|
227
|
-
attributes: [
|
|
228
|
-
{
|
|
229
|
-
key: "amount",
|
|
230
|
-
value: "3uatom",
|
|
231
|
-
},
|
|
232
|
-
{
|
|
233
|
-
key: "validator",
|
|
234
|
-
value: "validatorAddressNumeroUno",
|
|
235
|
-
},
|
|
236
|
-
],
|
|
237
|
-
},
|
|
238
|
-
],
|
|
239
|
-
logs: [],
|
|
240
|
-
tx: {
|
|
241
|
-
"@type": "/cosmos.tx.v1beta1.Tx",
|
|
242
|
-
body: {
|
|
243
|
-
messages: [
|
|
244
|
-
{
|
|
245
|
-
"@type": "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward",
|
|
246
|
-
delegator_address: "address",
|
|
247
|
-
validator_address: "cosmosvaloper1crqm3598z6qmyn2kkcl9dz7uqs4qdqnr6s8jdn",
|
|
248
|
-
},
|
|
249
|
-
],
|
|
250
|
-
memo: "Ledger Live",
|
|
251
|
-
timeout_height: "0",
|
|
252
|
-
extension_options: [],
|
|
253
|
-
non_critical_extension_options: [],
|
|
254
|
-
},
|
|
255
|
-
auth_info: {
|
|
256
|
-
signer_infos: [{ sequence: "seq" }],
|
|
257
|
-
fee: { amount: [{ denom: "uatom", amount: new bignumber_js_1.default(0) }] },
|
|
258
|
-
},
|
|
259
|
-
signatures: [],
|
|
260
|
-
},
|
|
261
|
-
}),
|
|
262
|
-
],
|
|
263
|
-
});
|
|
264
|
-
const account = await (0, synchronisation_1.getAccountShape)(infoMock, syncConfig);
|
|
265
|
-
expect(account.operations[0].value).toEqual(new bignumber_js_1.default(3));
|
|
266
|
-
expect(account.operations[0].extra.validators).toEqual([
|
|
267
|
-
{
|
|
268
|
-
address: "validatorAddressNumeroUno",
|
|
269
|
-
amount: new bignumber_js_1.default(3),
|
|
270
|
-
},
|
|
271
|
-
]);
|
|
272
|
-
});
|
|
273
|
-
it("should list claim reward operations correctly with multiple delegations", async () => {
|
|
274
|
-
mockAccountInfo({
|
|
275
|
-
txs: [
|
|
276
|
-
mockCosmosTx({
|
|
277
|
-
events: [
|
|
278
|
-
{
|
|
279
|
-
type: "withdraw_rewards",
|
|
280
|
-
attributes: [
|
|
281
|
-
{
|
|
282
|
-
key: "amount",
|
|
283
|
-
value: "10uatom",
|
|
284
|
-
},
|
|
285
|
-
{
|
|
286
|
-
key: "validator",
|
|
287
|
-
value: "validatorAddressHehe",
|
|
288
|
-
},
|
|
289
|
-
],
|
|
290
|
-
},
|
|
291
|
-
{
|
|
292
|
-
type: "withdraw_rewards",
|
|
293
|
-
attributes: [
|
|
294
|
-
{
|
|
295
|
-
key: "amount",
|
|
296
|
-
value: "5uatom",
|
|
297
|
-
},
|
|
298
|
-
{
|
|
299
|
-
key: "validator",
|
|
300
|
-
value: "validatorAddressTwo",
|
|
301
|
-
},
|
|
302
|
-
],
|
|
303
|
-
},
|
|
304
|
-
{
|
|
305
|
-
type: "withdraw_rewards",
|
|
306
|
-
attributes: [
|
|
307
|
-
{
|
|
308
|
-
key: "amount",
|
|
309
|
-
value: "56ibc/0025F8A87464A471E66B234C4F93AEC5B4DA3D42D7986451A059273426290DD5,512ibc/6B8A3F5C2AD51CD6171FA41A7E8C35AD594AB69226438DB94450436EA57B3A89,7uatom",
|
|
310
|
-
},
|
|
311
|
-
{
|
|
312
|
-
key: "validator",
|
|
313
|
-
value: "validatorAddressThree",
|
|
314
|
-
},
|
|
315
|
-
],
|
|
316
|
-
},
|
|
317
|
-
],
|
|
318
|
-
tx: {
|
|
319
|
-
"@type": "/cosmos.tx.v1beta1.Tx",
|
|
320
|
-
body: {
|
|
321
|
-
messages: [
|
|
322
|
-
{
|
|
323
|
-
"@type": "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward",
|
|
324
|
-
delegator_address: "address",
|
|
325
|
-
validator_address: "validatorAddressHehe",
|
|
326
|
-
},
|
|
327
|
-
{
|
|
328
|
-
"@type": "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward",
|
|
329
|
-
delegator_address: "address",
|
|
330
|
-
validator_address: "validatorAddressTwo",
|
|
331
|
-
},
|
|
332
|
-
{
|
|
333
|
-
"@type": "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward",
|
|
334
|
-
delegator_address: "address",
|
|
335
|
-
validator_address: "validatorAddressThree",
|
|
336
|
-
},
|
|
337
|
-
],
|
|
338
|
-
memo: "Ledger Live",
|
|
339
|
-
timeout_height: "0",
|
|
340
|
-
extension_options: [],
|
|
341
|
-
non_critical_extension_options: [],
|
|
342
|
-
},
|
|
343
|
-
auth_info: {
|
|
344
|
-
signer_infos: [{ sequence: "seq" }],
|
|
345
|
-
fee: { amount: [{ denom: "uatom", amount: new bignumber_js_1.default(0) }] },
|
|
346
|
-
},
|
|
347
|
-
signatures: [],
|
|
348
|
-
},
|
|
349
|
-
}),
|
|
350
|
-
],
|
|
351
|
-
});
|
|
352
|
-
const account = await (0, synchronisation_1.getAccountShape)(infoMock, syncConfig);
|
|
353
|
-
expect(account.operations[0].value).toEqual(new bignumber_js_1.default(22));
|
|
354
|
-
expect(account.operations[0].extra.validators).toEqual([
|
|
355
|
-
{
|
|
356
|
-
address: "validatorAddressHehe",
|
|
357
|
-
amount: new bignumber_js_1.default(10),
|
|
358
|
-
},
|
|
359
|
-
{
|
|
360
|
-
address: "validatorAddressTwo",
|
|
361
|
-
amount: new bignumber_js_1.default(5),
|
|
362
|
-
},
|
|
363
|
-
{
|
|
364
|
-
address: "validatorAddressThree",
|
|
365
|
-
amount: new bignumber_js_1.default(7),
|
|
366
|
-
},
|
|
367
|
-
]);
|
|
368
|
-
});
|
|
369
|
-
it("should parse an operation correctly when the operation failed)", async () => {
|
|
370
|
-
const failedOperation = mockCosmosTx({
|
|
371
|
-
tx: {
|
|
372
|
-
"@type": "/cosmos.tx.v1beta1.Tx",
|
|
373
|
-
body: {
|
|
374
|
-
messages: [
|
|
375
|
-
{
|
|
376
|
-
"@type": "/cosmos.bank.v1beta1.MsgSend",
|
|
377
|
-
from_address: "address",
|
|
378
|
-
to_address: "cosmos1lptvx486j7630632q3ah0dwq20ghdrpxgl8xzg",
|
|
379
|
-
amount: [
|
|
380
|
-
{
|
|
381
|
-
denom: "uatom",
|
|
382
|
-
amount: "10000",
|
|
383
|
-
},
|
|
384
|
-
],
|
|
385
|
-
},
|
|
386
|
-
],
|
|
387
|
-
memo: "",
|
|
388
|
-
timeout_height: "0",
|
|
389
|
-
extension_options: [],
|
|
390
|
-
non_critical_extension_options: [],
|
|
391
|
-
},
|
|
392
|
-
auth_info: baseTxMock.tx.auth_info,
|
|
393
|
-
},
|
|
394
|
-
code: 11,
|
|
395
|
-
});
|
|
396
|
-
mockAccountInfo({
|
|
397
|
-
txs: [failedOperation],
|
|
398
|
-
});
|
|
399
|
-
const account = await (0, synchronisation_1.getAccountShape)(infoMock, syncConfig);
|
|
400
|
-
expect(account.operations[0].value).toEqual(new bignumber_js_1.default(10001)); // 10000(amount) + 1(fees)
|
|
401
|
-
expect(account.operations[0].type).toEqual("OUT");
|
|
402
|
-
expect(account.operations[0].hasFailed).toEqual(true);
|
|
403
|
-
});
|
|
404
|
-
it("should parse an operation correctly with multiple transfers(received operations)", async () => {
|
|
405
|
-
mockAccountInfo({
|
|
406
|
-
txs: [
|
|
407
|
-
mockCosmosTx({
|
|
408
|
-
tx: {
|
|
409
|
-
"@type": "/cosmos.tx.v1beta1.Tx",
|
|
410
|
-
body: {
|
|
411
|
-
messages: [
|
|
412
|
-
{
|
|
413
|
-
"@type": "/cosmos.bank.v1beta1.MsgSend",
|
|
414
|
-
from_address: "cosmos1lptvx486j7630632q3ah0dwq20ghdrpxgl8xzg",
|
|
415
|
-
to_address: "address",
|
|
416
|
-
amount: [
|
|
417
|
-
{
|
|
418
|
-
denom: "uatom",
|
|
419
|
-
amount: "5",
|
|
420
|
-
},
|
|
421
|
-
],
|
|
422
|
-
},
|
|
423
|
-
{
|
|
424
|
-
"@type": "/cosmos.bank.v1beta1.MsgSend",
|
|
425
|
-
from_address: "cosmos1lptvx486j7630632q3ah0dwq20ghdrpxgl8xzg",
|
|
426
|
-
to_address: "address",
|
|
427
|
-
amount: [
|
|
428
|
-
{
|
|
429
|
-
denom: "uatom",
|
|
430
|
-
amount: "6",
|
|
431
|
-
},
|
|
432
|
-
],
|
|
433
|
-
},
|
|
434
|
-
],
|
|
435
|
-
memo: "",
|
|
436
|
-
timeout_height: "0",
|
|
437
|
-
extension_options: [],
|
|
438
|
-
non_critical_extension_options: [],
|
|
439
|
-
},
|
|
440
|
-
auth_info: baseTxMock.tx.auth_info,
|
|
441
|
-
},
|
|
442
|
-
}),
|
|
443
|
-
],
|
|
444
|
-
});
|
|
445
|
-
const account = await (0, synchronisation_1.getAccountShape)(infoMock, syncConfig);
|
|
446
|
-
expect(account.operations[0].value).toEqual(new bignumber_js_1.default(11)); // 5 + 6
|
|
447
|
-
expect(account.operations[0].type).toEqual("IN");
|
|
448
|
-
});
|
|
449
|
-
it("should parse an operation correctly with multiple transfers(sent operations)", async () => {
|
|
450
|
-
mockAccountInfo({
|
|
451
|
-
txs: [
|
|
452
|
-
mockCosmosTx({
|
|
453
|
-
tx: {
|
|
454
|
-
"@type": "/cosmos.tx.v1beta1.Tx",
|
|
455
|
-
body: {
|
|
456
|
-
messages: [
|
|
457
|
-
{
|
|
458
|
-
"@type": "/cosmos.bank.v1beta1.MsgSend",
|
|
459
|
-
from_address: "address",
|
|
460
|
-
to_address: "cosmos1lptvx486j7630632q3ah0dwq20ghdrpxgl8xzg",
|
|
461
|
-
amount: [
|
|
462
|
-
{
|
|
463
|
-
denom: "uatom",
|
|
464
|
-
amount: "5",
|
|
465
|
-
},
|
|
466
|
-
],
|
|
467
|
-
},
|
|
468
|
-
{
|
|
469
|
-
"@type": "/cosmos.bank.v1beta1.MsgSend",
|
|
470
|
-
from_address: "address",
|
|
471
|
-
to_address: "cosmos1lptvx486j7630632q3ah0dwq20ghdrpxgl8xzg",
|
|
472
|
-
amount: [
|
|
473
|
-
{
|
|
474
|
-
denom: "uatom",
|
|
475
|
-
amount: "6",
|
|
476
|
-
},
|
|
477
|
-
],
|
|
478
|
-
},
|
|
479
|
-
],
|
|
480
|
-
memo: "",
|
|
481
|
-
timeout_height: "0",
|
|
482
|
-
extension_options: [],
|
|
483
|
-
non_critical_extension_options: [],
|
|
484
|
-
},
|
|
485
|
-
auth_info: baseTxMock.tx.auth_info,
|
|
486
|
-
},
|
|
487
|
-
}),
|
|
488
|
-
],
|
|
489
|
-
});
|
|
490
|
-
const account = await (0, synchronisation_1.getAccountShape)(infoMock, syncConfig);
|
|
491
|
-
expect(account.operations[0].value).toEqual(new bignumber_js_1.default(12)); // 5 + 6 + 1(fees)
|
|
492
|
-
expect(account.operations[0].type).toEqual("OUT");
|
|
493
|
-
});
|
|
494
|
-
it("should parse an operation correctly with multiple delegations", async () => {
|
|
495
|
-
mockAccountInfo({
|
|
496
|
-
txs: [
|
|
497
|
-
mockCosmosTx({
|
|
498
|
-
tx: {
|
|
499
|
-
body: {
|
|
500
|
-
memo: "memo",
|
|
501
|
-
messages: [
|
|
502
|
-
{
|
|
503
|
-
"@type": "/cosmos.staking.v1beta1.MsgDelegate",
|
|
504
|
-
delegator_address: "address",
|
|
505
|
-
validator_address: "address1",
|
|
506
|
-
amount: {
|
|
507
|
-
denom: "uatom",
|
|
508
|
-
amount: "5",
|
|
509
|
-
},
|
|
510
|
-
},
|
|
511
|
-
{
|
|
512
|
-
"@type": "/cosmos.staking.v1beta1.MsgDelegate",
|
|
513
|
-
delegator_address: "address",
|
|
514
|
-
validator_address: "address2",
|
|
515
|
-
amount: {
|
|
516
|
-
denom: "uatom",
|
|
517
|
-
amount: "6",
|
|
518
|
-
},
|
|
519
|
-
},
|
|
520
|
-
],
|
|
521
|
-
},
|
|
522
|
-
auth_info: baseTxMock.tx.auth_info,
|
|
523
|
-
},
|
|
524
|
-
}),
|
|
525
|
-
],
|
|
526
|
-
});
|
|
527
|
-
const account = await (0, synchronisation_1.getAccountShape)(infoMock, syncConfig);
|
|
528
|
-
expect(account.operations[0].value).toEqual(new bignumber_js_1.default(1)); // fees
|
|
529
|
-
expect(account.operations[0].type).toEqual("DELEGATE");
|
|
530
|
-
expect(account.operations[0].extra.validators).toEqual([
|
|
531
|
-
{
|
|
532
|
-
address: "address1",
|
|
533
|
-
amount: new bignumber_js_1.default(5),
|
|
534
|
-
},
|
|
535
|
-
{
|
|
536
|
-
address: "address2",
|
|
537
|
-
amount: new bignumber_js_1.default(6),
|
|
538
|
-
},
|
|
539
|
-
]);
|
|
540
|
-
});
|
|
541
|
-
it("should parse an operation correctly with multiple redelegate", async () => {
|
|
542
|
-
mockAccountInfo({
|
|
543
|
-
txs: [
|
|
544
|
-
mockCosmosTx({
|
|
545
|
-
tx: {
|
|
546
|
-
body: {
|
|
547
|
-
memo: "memo",
|
|
548
|
-
messages: [
|
|
549
|
-
{
|
|
550
|
-
"@type": "/cosmos.staking.v1beta1.MsgBeginRedelegate",
|
|
551
|
-
delegator_address: "address",
|
|
552
|
-
validator_src_address: "address_src",
|
|
553
|
-
validator_dst_address: "address1",
|
|
554
|
-
amount: {
|
|
555
|
-
denom: "uatom",
|
|
556
|
-
amount: "5",
|
|
557
|
-
},
|
|
558
|
-
},
|
|
559
|
-
{
|
|
560
|
-
"@type": "/cosmos.staking.v1beta1.MsgBeginRedelegate",
|
|
561
|
-
delegator_address: "address",
|
|
562
|
-
validator_src_address: "address_src",
|
|
563
|
-
validator_dst_address: "address2",
|
|
564
|
-
amount: {
|
|
565
|
-
denom: "uatom",
|
|
566
|
-
amount: "6",
|
|
567
|
-
},
|
|
568
|
-
},
|
|
569
|
-
],
|
|
570
|
-
},
|
|
571
|
-
auth_info: baseTxMock.tx.auth_info,
|
|
572
|
-
},
|
|
573
|
-
}),
|
|
574
|
-
],
|
|
575
|
-
});
|
|
576
|
-
const account = await (0, synchronisation_1.getAccountShape)(infoMock, syncConfig);
|
|
577
|
-
expect(account.operations[0].value).toEqual(new bignumber_js_1.default(1)); // fees
|
|
578
|
-
expect(account.operations[0].type).toEqual("REDELEGATE");
|
|
579
|
-
expect(account.operations[0].extra.sourceValidator).toEqual("address_src");
|
|
580
|
-
expect(account.operations[0].extra.validators).toEqual([
|
|
581
|
-
{
|
|
582
|
-
address: "address1",
|
|
583
|
-
amount: new bignumber_js_1.default(5),
|
|
584
|
-
},
|
|
585
|
-
{
|
|
586
|
-
address: "address2",
|
|
587
|
-
amount: new bignumber_js_1.default(6),
|
|
588
|
-
},
|
|
589
|
-
]);
|
|
590
|
-
});
|
|
591
|
-
it("should parse an operation correctly with multiple unredelegate", async () => {
|
|
592
|
-
mockAccountInfo({
|
|
593
|
-
txs: [
|
|
594
|
-
mockCosmosTx({
|
|
595
|
-
tx: {
|
|
596
|
-
body: {
|
|
597
|
-
memo: "memo",
|
|
598
|
-
messages: [
|
|
599
|
-
{
|
|
600
|
-
"@type": "/cosmos.staking.v1beta1.MsgUndelegate",
|
|
601
|
-
delegator_address: "address",
|
|
602
|
-
validator_address: "address1",
|
|
603
|
-
amount: {
|
|
604
|
-
denom: "uatom",
|
|
605
|
-
amount: "5",
|
|
606
|
-
},
|
|
607
|
-
},
|
|
608
|
-
{
|
|
609
|
-
"@type": "/cosmos.staking.v1beta1.MsgUndelegate",
|
|
610
|
-
delegator_address: "address",
|
|
611
|
-
validator_address: "address2",
|
|
612
|
-
amount: {
|
|
613
|
-
denom: "uatom",
|
|
614
|
-
amount: "6",
|
|
615
|
-
},
|
|
616
|
-
},
|
|
617
|
-
],
|
|
618
|
-
},
|
|
619
|
-
auth_info: baseTxMock.tx.auth_info,
|
|
620
|
-
},
|
|
621
|
-
}),
|
|
622
|
-
],
|
|
623
|
-
});
|
|
624
|
-
const account = await (0, synchronisation_1.getAccountShape)(infoMock, syncConfig);
|
|
625
|
-
expect(account.operations[0].value).toEqual(new bignumber_js_1.default(1)); // fees
|
|
626
|
-
expect(account.operations[0].type).toEqual("UNDELEGATE");
|
|
627
|
-
expect(account.operations[0].extra.validators).toEqual([
|
|
628
|
-
{
|
|
629
|
-
address: "address1",
|
|
630
|
-
amount: new bignumber_js_1.default(5),
|
|
631
|
-
},
|
|
632
|
-
{
|
|
633
|
-
address: "address2",
|
|
634
|
-
amount: new bignumber_js_1.default(6),
|
|
635
|
-
},
|
|
636
|
-
]);
|
|
637
|
-
});
|
|
638
|
-
it("should parse an operation correctly with missing auth_info", async () => {
|
|
639
|
-
mockAccountInfo({
|
|
640
|
-
txs: [
|
|
641
|
-
mockCosmosTx({
|
|
642
|
-
tx: {
|
|
643
|
-
body: {
|
|
644
|
-
memo: "memo",
|
|
645
|
-
messages: [
|
|
646
|
-
{
|
|
647
|
-
"@type": "/cosmos.bank.v1beta1.MsgSend",
|
|
648
|
-
from_address: "address",
|
|
649
|
-
to_address: "cosmos1lptvx486j7630632q3ah0dwq20ghdrpxgl8xzg",
|
|
650
|
-
amount: [
|
|
651
|
-
{
|
|
652
|
-
denom: "uatom",
|
|
653
|
-
amount: "5",
|
|
654
|
-
},
|
|
655
|
-
],
|
|
656
|
-
},
|
|
657
|
-
],
|
|
658
|
-
},
|
|
659
|
-
},
|
|
660
|
-
}),
|
|
661
|
-
],
|
|
662
|
-
});
|
|
663
|
-
const account = await (0, synchronisation_1.getAccountShape)(infoMock, syncConfig);
|
|
664
|
-
expect(account.operations[0].value).toBeDefined();
|
|
665
|
-
});
|
|
666
|
-
});
|
|
667
|
-
//# sourceMappingURL=synchronisation.unit.test.js.map
|