@ledgerhq/coin-celo 1.3.0 → 1.3.1-nightly.0

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 (187) hide show
  1. package/.unimportedrc.json +3 -6
  2. package/CHANGELOG.md +8 -0
  3. package/lib/__tests__/bridge/buildOptimisticOperation.test.d.ts +2 -0
  4. package/lib/__tests__/bridge/buildOptimisticOperation.test.d.ts.map +1 -0
  5. package/lib/__tests__/bridge/buildOptimisticOperation.test.js +23 -0
  6. package/lib/__tests__/bridge/buildOptimisticOperation.test.js.map +1 -0
  7. package/lib/__tests__/bridge/buildTransaction.test.d.ts +2 -0
  8. package/lib/__tests__/bridge/buildTransaction.test.d.ts.map +1 -0
  9. package/lib/__tests__/bridge/buildTransaction.test.js +412 -0
  10. package/lib/__tests__/bridge/buildTransaction.test.js.map +1 -0
  11. package/lib/__tests__/bridge/createTransaction.test.d.ts +2 -0
  12. package/lib/__tests__/bridge/createTransaction.test.d.ts.map +1 -0
  13. package/lib/__tests__/bridge/createTransaction.test.js +22 -0
  14. package/lib/__tests__/bridge/createTransaction.test.js.map +1 -0
  15. package/lib/__tests__/bridge/deviceTransactionConfig.test.d.ts +2 -0
  16. package/lib/__tests__/bridge/deviceTransactionConfig.test.d.ts.map +1 -0
  17. package/lib/__tests__/bridge/deviceTransactionConfig.test.js +21 -0
  18. package/lib/__tests__/bridge/deviceTransactionConfig.test.js.map +1 -0
  19. package/lib/__tests__/bridge/estimateMaxSpendable.test.d.ts +2 -0
  20. package/lib/__tests__/bridge/estimateMaxSpendable.test.d.ts.map +1 -0
  21. package/lib/__tests__/bridge/estimateMaxSpendable.test.js +108 -0
  22. package/lib/__tests__/bridge/estimateMaxSpendable.test.js.map +1 -0
  23. package/lib/__tests__/bridge/getFeesForTransaction.test.d.ts +2 -0
  24. package/lib/__tests__/bridge/getFeesForTransaction.test.d.ts.map +1 -0
  25. package/lib/__tests__/bridge/getFeesForTransaction.test.js +211 -0
  26. package/lib/__tests__/bridge/getFeesForTransaction.test.js.map +1 -0
  27. package/lib/__tests__/bridge/getTransactionStatus.test.d.ts +2 -0
  28. package/lib/__tests__/bridge/getTransactionStatus.test.d.ts.map +1 -0
  29. package/lib/__tests__/bridge/getTransactionStatus.test.js +214 -0
  30. package/lib/__tests__/bridge/getTransactionStatus.test.js.map +1 -0
  31. package/lib/__tests__/bridge/logic.test.d.ts +2 -0
  32. package/lib/__tests__/bridge/logic.test.d.ts.map +1 -0
  33. package/lib/__tests__/bridge/logic.test.js +490 -0
  34. package/lib/__tests__/bridge/logic.test.js.map +1 -0
  35. package/lib/__tests__/bridge/prepareTransaction.test.d.ts +2 -0
  36. package/lib/__tests__/bridge/prepareTransaction.test.d.ts.map +1 -0
  37. package/lib/__tests__/bridge/prepareTransaction.test.js +239 -0
  38. package/lib/__tests__/bridge/prepareTransaction.test.js.map +1 -0
  39. package/lib/bridge/buildOptimisticOperation.d.ts.map +1 -1
  40. package/lib/bridge/buildOptimisticOperation.js +5 -2
  41. package/lib/bridge/buildOptimisticOperation.js.map +1 -1
  42. package/lib/bridge/buildTransaction.d.ts.map +1 -1
  43. package/lib/bridge/buildTransaction.js +29 -6
  44. package/lib/bridge/buildTransaction.js.map +1 -1
  45. package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -1
  46. package/lib/bridge/estimateMaxSpendable.js +9 -1
  47. package/lib/bridge/estimateMaxSpendable.js.map +1 -1
  48. package/lib/bridge/fixtures.d.ts +36 -0
  49. package/lib/bridge/fixtures.d.ts.map +1 -0
  50. package/lib/bridge/fixtures.js +98 -0
  51. package/lib/bridge/fixtures.js.map +1 -0
  52. package/lib/bridge/getFeesForTransaction.d.ts.map +1 -1
  53. package/lib/bridge/getFeesForTransaction.js +32 -5
  54. package/lib/bridge/getFeesForTransaction.js.map +1 -1
  55. package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
  56. package/lib/bridge/getTransactionStatus.js +18 -4
  57. package/lib/bridge/getTransactionStatus.js.map +1 -1
  58. package/lib/bridge/index.d.ts.map +1 -1
  59. package/lib/bridge/index.js.map +1 -1
  60. package/lib/bridge/prepareTransaction.d.ts.map +1 -1
  61. package/lib/bridge/prepareTransaction.js +33 -4
  62. package/lib/bridge/prepareTransaction.js.map +1 -1
  63. package/lib/bridge/signOperation.d.ts.map +1 -1
  64. package/lib/bridge/signOperation.js +11 -3
  65. package/lib/bridge/signOperation.js.map +1 -1
  66. package/lib/bridge/synchronisation.d.ts.map +1 -1
  67. package/lib/bridge/synchronisation.js +7 -3
  68. package/lib/bridge/synchronisation.js.map +1 -1
  69. package/lib/config.d.ts.map +1 -1
  70. package/lib/config.js +8 -0
  71. package/lib/config.js.map +1 -1
  72. package/lib/constants.d.ts +6 -0
  73. package/lib/constants.d.ts.map +1 -0
  74. package/lib/constants.js +15 -0
  75. package/lib/constants.js.map +1 -0
  76. package/lib/types/types.d.ts +1 -0
  77. package/lib/types/types.d.ts.map +1 -1
  78. package/lib/types/types.js.map +1 -1
  79. package/lib-es/__tests__/bridge/buildOptimisticOperation.test.d.ts +2 -0
  80. package/lib-es/__tests__/bridge/buildOptimisticOperation.test.d.ts.map +1 -0
  81. package/lib-es/__tests__/bridge/buildOptimisticOperation.test.js +18 -0
  82. package/lib-es/__tests__/bridge/buildOptimisticOperation.test.js.map +1 -0
  83. package/lib-es/__tests__/bridge/buildTransaction.test.d.ts +2 -0
  84. package/lib-es/__tests__/bridge/buildTransaction.test.d.ts.map +1 -0
  85. package/lib-es/__tests__/bridge/buildTransaction.test.js +407 -0
  86. package/lib-es/__tests__/bridge/buildTransaction.test.js.map +1 -0
  87. package/lib-es/__tests__/bridge/createTransaction.test.d.ts +2 -0
  88. package/lib-es/__tests__/bridge/createTransaction.test.d.ts.map +1 -0
  89. package/lib-es/__tests__/bridge/createTransaction.test.js +17 -0
  90. package/lib-es/__tests__/bridge/createTransaction.test.js.map +1 -0
  91. package/lib-es/__tests__/bridge/deviceTransactionConfig.test.d.ts +2 -0
  92. package/lib-es/__tests__/bridge/deviceTransactionConfig.test.d.ts.map +1 -0
  93. package/lib-es/__tests__/bridge/deviceTransactionConfig.test.js +16 -0
  94. package/lib-es/__tests__/bridge/deviceTransactionConfig.test.js.map +1 -0
  95. package/lib-es/__tests__/bridge/estimateMaxSpendable.test.d.ts +2 -0
  96. package/lib-es/__tests__/bridge/estimateMaxSpendable.test.d.ts.map +1 -0
  97. package/lib-es/__tests__/bridge/estimateMaxSpendable.test.js +103 -0
  98. package/lib-es/__tests__/bridge/estimateMaxSpendable.test.js.map +1 -0
  99. package/lib-es/__tests__/bridge/getFeesForTransaction.test.d.ts +2 -0
  100. package/lib-es/__tests__/bridge/getFeesForTransaction.test.d.ts.map +1 -0
  101. package/lib-es/__tests__/bridge/getFeesForTransaction.test.js +206 -0
  102. package/lib-es/__tests__/bridge/getFeesForTransaction.test.js.map +1 -0
  103. package/lib-es/__tests__/bridge/getTransactionStatus.test.d.ts +2 -0
  104. package/lib-es/__tests__/bridge/getTransactionStatus.test.d.ts.map +1 -0
  105. package/lib-es/__tests__/bridge/getTransactionStatus.test.js +209 -0
  106. package/lib-es/__tests__/bridge/getTransactionStatus.test.js.map +1 -0
  107. package/lib-es/__tests__/bridge/logic.test.d.ts +2 -0
  108. package/lib-es/__tests__/bridge/logic.test.d.ts.map +1 -0
  109. package/lib-es/__tests__/bridge/logic.test.js +485 -0
  110. package/lib-es/__tests__/bridge/logic.test.js.map +1 -0
  111. package/lib-es/__tests__/bridge/prepareTransaction.test.d.ts +2 -0
  112. package/lib-es/__tests__/bridge/prepareTransaction.test.d.ts.map +1 -0
  113. package/lib-es/__tests__/bridge/prepareTransaction.test.js +234 -0
  114. package/lib-es/__tests__/bridge/prepareTransaction.test.js.map +1 -0
  115. package/lib-es/bridge/buildOptimisticOperation.d.ts.map +1 -1
  116. package/lib-es/bridge/buildOptimisticOperation.js +5 -2
  117. package/lib-es/bridge/buildOptimisticOperation.js.map +1 -1
  118. package/lib-es/bridge/buildTransaction.d.ts.map +1 -1
  119. package/lib-es/bridge/buildTransaction.js +29 -6
  120. package/lib-es/bridge/buildTransaction.js.map +1 -1
  121. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
  122. package/lib-es/bridge/estimateMaxSpendable.js +10 -2
  123. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
  124. package/lib-es/bridge/fixtures.d.ts +36 -0
  125. package/lib-es/bridge/fixtures.d.ts.map +1 -0
  126. package/lib-es/bridge/fixtures.js +89 -0
  127. package/lib-es/bridge/fixtures.js.map +1 -0
  128. package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -1
  129. package/lib-es/bridge/getFeesForTransaction.js +29 -5
  130. package/lib-es/bridge/getFeesForTransaction.js.map +1 -1
  131. package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
  132. package/lib-es/bridge/getTransactionStatus.js +18 -4
  133. package/lib-es/bridge/getTransactionStatus.js.map +1 -1
  134. package/lib-es/bridge/index.d.ts.map +1 -1
  135. package/lib-es/bridge/index.js.map +1 -1
  136. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
  137. package/lib-es/bridge/prepareTransaction.js +33 -4
  138. package/lib-es/bridge/prepareTransaction.js.map +1 -1
  139. package/lib-es/bridge/signOperation.d.ts.map +1 -1
  140. package/lib-es/bridge/signOperation.js +11 -3
  141. package/lib-es/bridge/signOperation.js.map +1 -1
  142. package/lib-es/bridge/synchronisation.d.ts.map +1 -1
  143. package/lib-es/bridge/synchronisation.js +7 -3
  144. package/lib-es/bridge/synchronisation.js.map +1 -1
  145. package/lib-es/config.d.ts.map +1 -1
  146. package/lib-es/config.js +8 -0
  147. package/lib-es/config.js.map +1 -1
  148. package/lib-es/constants.d.ts +6 -0
  149. package/lib-es/constants.d.ts.map +1 -0
  150. package/lib-es/constants.js +11 -0
  151. package/lib-es/constants.js.map +1 -0
  152. package/lib-es/types/types.d.ts +1 -0
  153. package/lib-es/types/types.d.ts.map +1 -1
  154. package/lib-es/types/types.js.map +1 -1
  155. package/package.json +9 -8
  156. package/src/__tests__/bridge/buildOptimisticOperation.test.ts +29 -0
  157. package/src/__tests__/bridge/buildTransaction.test.ts +502 -0
  158. package/src/__tests__/bridge/createTransaction.test.ts +17 -0
  159. package/src/__tests__/bridge/deviceTransactionConfig.test.ts +16 -0
  160. package/src/__tests__/bridge/estimateMaxSpendable.test.ts +112 -0
  161. package/src/__tests__/bridge/getFeesForTransaction.test.ts +233 -0
  162. package/src/__tests__/bridge/getTransactionStatus.test.ts +261 -0
  163. package/src/__tests__/bridge/logic.test.ts +538 -0
  164. package/src/__tests__/bridge/prepareTransaction.test.ts +261 -0
  165. package/src/bridge/buildOptimisticOperation.ts +6 -2
  166. package/src/bridge/buildTransaction.ts +38 -7
  167. package/src/bridge/estimateMaxSpendable.ts +18 -2
  168. package/src/bridge/fixtures.ts +103 -0
  169. package/src/bridge/getFeesForTransaction.ts +39 -5
  170. package/src/bridge/getTransactionStatus.ts +21 -4
  171. package/src/bridge/index.ts +0 -1
  172. package/src/bridge/prepareTransaction.ts +39 -6
  173. package/src/bridge/signOperation.ts +19 -4
  174. package/src/bridge/synchronisation.ts +10 -4
  175. package/src/config.ts +8 -0
  176. package/src/constants.ts +15 -0
  177. package/src/logic.ts +1 -1
  178. package/src/types/types.ts +1 -0
  179. package/lib/test/please-add-coverage.test.d.ts +0 -2
  180. package/lib/test/please-add-coverage.test.d.ts.map +0 -1
  181. package/lib/test/please-add-coverage.test.js +0 -6
  182. package/lib/test/please-add-coverage.test.js.map +0 -1
  183. package/lib-es/test/please-add-coverage.test.d.ts +0 -1
  184. package/lib-es/test/please-add-coverage.test.d.ts.map +0 -1
  185. package/lib-es/test/please-add-coverage.test.js +0 -5
  186. package/lib-es/test/please-add-coverage.test.js.map +0 -1
  187. package/src/test/please-add-coverage.test.ts +0 -3
@@ -0,0 +1,538 @@
1
+ import BigNumber from "bignumber.js";
2
+ import { accountFixture } from "../../bridge/fixtures";
3
+ import {
4
+ activatableVotes,
5
+ availablePendingWithdrawals,
6
+ defaultValidatorGroupAddress,
7
+ fallbackValidatorGroup,
8
+ getPendingStakingOperationAmounts,
9
+ getValidatorGroupsWithoutVotes,
10
+ getValidatorGroupsWithVotes,
11
+ getVote,
12
+ hasActivatableVotes,
13
+ hasRevokableVotes,
14
+ hasWithdrawableBalance,
15
+ isAccountRegistrationPending,
16
+ isDefaultValidatorGroup,
17
+ isDefaultValidatorGroupAddress,
18
+ revokableVotes,
19
+ voteStatus,
20
+ withdrawableBalance,
21
+ } from "../../logic";
22
+ import { CeloAccount } from "../../types";
23
+ import { Operation } from "@ledgerhq/types-live";
24
+
25
+ jest.useFakeTimers().setSystemTime(new Date("2020-01-01"));
26
+
27
+ describe("logic", () => {
28
+ it("availablePendingWithdrawals", () => {
29
+ const result = availablePendingWithdrawals({
30
+ ...accountFixture,
31
+ celoResources: {
32
+ ...accountFixture.celoResources,
33
+ pendingWithdrawals: [
34
+ {
35
+ value: BigNumber(123123123),
36
+ time: BigNumber(31231),
37
+ index: 0,
38
+ },
39
+ {
40
+ value: BigNumber(123123123),
41
+ time: BigNumber(23214451),
42
+ index: 0,
43
+ },
44
+ {
45
+ value: BigNumber(123123123),
46
+ time: BigNumber(1577836900000),
47
+ index: 0,
48
+ },
49
+ ],
50
+ },
51
+ });
52
+
53
+ expect(result).toHaveLength(2);
54
+ });
55
+
56
+ it("withdrawableBalance", () => {
57
+ const account = {
58
+ ...accountFixture,
59
+ celoResources: {
60
+ ...accountFixture.celoResources,
61
+ pendingWithdrawals: [
62
+ {
63
+ value: BigNumber(123123123),
64
+ time: BigNumber(31231),
65
+ index: 0,
66
+ },
67
+ {
68
+ value: BigNumber(123123123),
69
+ time: BigNumber(23214451),
70
+ index: 0,
71
+ },
72
+ {
73
+ value: BigNumber(123123123),
74
+ time: BigNumber(1577836900000),
75
+ index: 0,
76
+ },
77
+ ],
78
+ },
79
+ };
80
+
81
+ expect(withdrawableBalance(account)).toEqual(BigNumber(246246246));
82
+ expect(hasWithdrawableBalance(account)).toBeTruthy();
83
+ });
84
+
85
+ it("isDefaultValidatorGroupAddress", () => {
86
+ expect(isDefaultValidatorGroupAddress("other_address")).toBeFalsy();
87
+ expect(isDefaultValidatorGroupAddress(defaultValidatorGroupAddress())).toBeTruthy();
88
+ expect(
89
+ isDefaultValidatorGroup({
90
+ address: "validator_address",
91
+ name: "validator1",
92
+ votes: BigNumber(8484848),
93
+ }),
94
+ ).toBeFalsy();
95
+ expect(
96
+ isDefaultValidatorGroup({
97
+ address: defaultValidatorGroupAddress(),
98
+ name: "validator1",
99
+ votes: BigNumber(8484848),
100
+ }),
101
+ ).toBeTruthy();
102
+ });
103
+
104
+ it("activatableVotes", () => {
105
+ const account = {
106
+ ...accountFixture,
107
+ celoResources: {
108
+ ...accountFixture.celoResources,
109
+ votes: [
110
+ {
111
+ validatorGroup: "1",
112
+ amount: BigNumber(123),
113
+ activatable: true,
114
+ revokable: false,
115
+ type: "active",
116
+ index: 0,
117
+ },
118
+ {
119
+ validatorGroup: "2",
120
+ amount: BigNumber(123213),
121
+ activatable: false,
122
+ revokable: true,
123
+ type: "pending",
124
+ index: 0,
125
+ },
126
+ {
127
+ validatorGroup: "3",
128
+ amount: BigNumber(1232223),
129
+ activatable: true,
130
+ revokable: false,
131
+ type: "active",
132
+ index: 0,
133
+ },
134
+ ],
135
+ },
136
+ } as CeloAccount;
137
+ const result = activatableVotes(account);
138
+
139
+ expect(result).toMatchObject([
140
+ {
141
+ validatorGroup: "1",
142
+ amount: BigNumber(123),
143
+ activatable: true,
144
+ revokable: false,
145
+ type: "active",
146
+ index: 0,
147
+ },
148
+ {
149
+ validatorGroup: "3",
150
+ amount: BigNumber(1232223),
151
+ activatable: true,
152
+ revokable: false,
153
+ type: "active",
154
+ index: 0,
155
+ },
156
+ ]);
157
+ expect(hasActivatableVotes(account)).toBeTruthy();
158
+ expect(revokableVotes(account)).toMatchObject([
159
+ {
160
+ validatorGroup: "2",
161
+ amount: BigNumber(123213),
162
+ activatable: false,
163
+ revokable: true,
164
+ type: "pending",
165
+ index: 0,
166
+ },
167
+ ]);
168
+ expect(hasRevokableVotes(account)).toBeTruthy();
169
+ });
170
+
171
+ it("getVote", () => {
172
+ const account = {
173
+ ...accountFixture,
174
+ celoResources: {
175
+ ...accountFixture.celoResources,
176
+ votes: [
177
+ {
178
+ validatorGroup: "1",
179
+ amount: BigNumber(123),
180
+ activatable: true,
181
+ revokable: false,
182
+ type: "active",
183
+ index: 0,
184
+ },
185
+ {
186
+ validatorGroup: "2",
187
+ amount: BigNumber(123213),
188
+ activatable: false,
189
+ revokable: true,
190
+ type: "pending",
191
+ index: 0,
192
+ },
193
+ {
194
+ validatorGroup: "3",
195
+ amount: BigNumber(1232223),
196
+ activatable: true,
197
+ revokable: false,
198
+ type: "active",
199
+ index: 0,
200
+ },
201
+ ],
202
+ },
203
+ } as CeloAccount;
204
+ const result = getVote(account, "2", 0);
205
+
206
+ expect(result).toMatchObject({
207
+ validatorGroup: "2",
208
+ amount: BigNumber(123213),
209
+ activatable: false,
210
+ revokable: true,
211
+ type: "pending",
212
+ index: 0,
213
+ });
214
+ });
215
+
216
+ it("voteStatus", () => {
217
+ expect(
218
+ voteStatus({
219
+ validatorGroup: "2",
220
+ amount: BigNumber(123213),
221
+ activatable: true,
222
+ revokable: true,
223
+ type: "pending",
224
+ index: 0,
225
+ }),
226
+ ).toEqual("awaitingActivation");
227
+ expect(
228
+ voteStatus({
229
+ validatorGroup: "2",
230
+ amount: BigNumber(123213),
231
+ activatable: false,
232
+ revokable: true,
233
+ type: "pending",
234
+ index: 0,
235
+ }),
236
+ ).toEqual("pending");
237
+ });
238
+
239
+ it("fallbackValidatorGroup", () => {
240
+ expect(fallbackValidatorGroup("address")).toMatchObject({
241
+ address: "address",
242
+ name: "address",
243
+ votes: BigNumber(0),
244
+ });
245
+ });
246
+
247
+ it("isAccountRegistrationPending", () => {
248
+ const account = {
249
+ ...accountFixture,
250
+ pendingOperations: [
251
+ {
252
+ id: "pendingOperation1",
253
+ accountId: accountFixture.id,
254
+ blockHash: "block_hash",
255
+ blockHeight: 1,
256
+ date: new Date(),
257
+ type: "REGISTER",
258
+ senders: [],
259
+ recipients: [],
260
+ fee: BigNumber(0),
261
+ value: BigNumber(1),
262
+ hash: "hash",
263
+ extra: "extra",
264
+ } as Operation,
265
+ ],
266
+ celoResources: {
267
+ ...accountFixture.celoResources,
268
+ registrationStatus: false,
269
+ },
270
+ } as CeloAccount;
271
+
272
+ expect(isAccountRegistrationPending(account)).toBeTruthy();
273
+ });
274
+
275
+ it("getPendingStakingOperationAmounts", () => {
276
+ const account = {
277
+ ...accountFixture,
278
+ pendingOperations: [
279
+ {
280
+ id: "pendingOperation1",
281
+ accountId: accountFixture.id,
282
+ blockHash: "block_hash",
283
+ blockHeight: 1,
284
+ date: new Date(),
285
+ type: "VOTE",
286
+ senders: [],
287
+ recipients: [],
288
+ fee: BigNumber(0),
289
+ value: BigNumber(2),
290
+ hash: "hash",
291
+ extra: "extra",
292
+ } as Operation,
293
+ {
294
+ id: "pendingOperation1",
295
+ accountId: accountFixture.id,
296
+ blockHash: "block_hash",
297
+ blockHeight: 1,
298
+ date: new Date(),
299
+ type: "VOTE",
300
+ senders: [],
301
+ recipients: [],
302
+ fee: BigNumber(0),
303
+ value: BigNumber(10),
304
+ hash: "hash",
305
+ extra: "extra",
306
+ } as Operation,
307
+ {
308
+ id: "pendingOperation1",
309
+ accountId: accountFixture.id,
310
+ blockHash: "block_hash",
311
+ blockHeight: 1,
312
+ date: new Date(),
313
+ type: "LOCK",
314
+ senders: [],
315
+ recipients: [],
316
+ fee: BigNumber(0),
317
+ value: BigNumber(30),
318
+ hash: "hash",
319
+ extra: "extra",
320
+ } as Operation,
321
+ {
322
+ id: "pendingOperation1",
323
+ accountId: accountFixture.id,
324
+ blockHash: "block_hash",
325
+ blockHeight: 1,
326
+ date: new Date(),
327
+ type: "REGISTER",
328
+ senders: [],
329
+ recipients: [],
330
+ fee: BigNumber(0),
331
+ value: BigNumber(30),
332
+ hash: "hash",
333
+ extra: "extra",
334
+ } as Operation,
335
+ ],
336
+ celoResources: {
337
+ ...accountFixture.celoResources,
338
+ registrationStatus: false,
339
+ },
340
+ } as CeloAccount;
341
+ const result = getPendingStakingOperationAmounts(account);
342
+ expect(result).toMatchObject({
343
+ vote: BigNumber(12),
344
+ lock: BigNumber(30),
345
+ });
346
+ });
347
+
348
+ it("getPendingStakingOperationAmounts", () => {
349
+ const account = {
350
+ ...accountFixture,
351
+ pendingOperations: [
352
+ {
353
+ id: "pendingOperation1",
354
+ accountId: accountFixture.id,
355
+ blockHash: "block_hash",
356
+ blockHeight: 1,
357
+ date: new Date(),
358
+ type: "VOTE",
359
+ senders: [],
360
+ recipients: [],
361
+ fee: BigNumber(0),
362
+ value: BigNumber(2),
363
+ hash: "hash",
364
+ extra: "extra",
365
+ } as Operation,
366
+ {
367
+ id: "pendingOperation1",
368
+ accountId: accountFixture.id,
369
+ blockHash: "block_hash",
370
+ blockHeight: 1,
371
+ date: new Date(),
372
+ type: "VOTE",
373
+ senders: [],
374
+ recipients: [],
375
+ fee: BigNumber(0),
376
+ value: BigNumber(10),
377
+ hash: "hash",
378
+ extra: "extra",
379
+ } as Operation,
380
+ {
381
+ id: "pendingOperation1",
382
+ accountId: accountFixture.id,
383
+ blockHash: "block_hash",
384
+ blockHeight: 1,
385
+ date: new Date(),
386
+ type: "LOCK",
387
+ senders: [],
388
+ recipients: [],
389
+ fee: BigNumber(0),
390
+ value: BigNumber(30),
391
+ hash: "hash",
392
+ extra: "extra",
393
+ } as Operation,
394
+ {
395
+ id: "pendingOperation1",
396
+ accountId: accountFixture.id,
397
+ blockHash: "block_hash",
398
+ blockHeight: 1,
399
+ date: new Date(),
400
+ type: "REGISTER",
401
+ senders: [],
402
+ recipients: [],
403
+ fee: BigNumber(0),
404
+ value: BigNumber(30),
405
+ hash: "hash",
406
+ extra: "extra",
407
+ } as Operation,
408
+ ],
409
+ celoResources: {
410
+ ...accountFixture.celoResources,
411
+ registrationStatus: false,
412
+ },
413
+ operations: [
414
+ {
415
+ id: "operation1",
416
+ accountId: accountFixture.id,
417
+ blockHash: "block_hash",
418
+ blockHeight: 1,
419
+ date: new Date(),
420
+ type: "LOCK",
421
+ senders: [],
422
+ recipients: [],
423
+ fee: BigNumber(0),
424
+ value: BigNumber(1),
425
+ hash: "hash",
426
+ extra: "extra",
427
+ } as Operation,
428
+ ],
429
+ operationsCount: 1,
430
+ } as CeloAccount;
431
+ const result = getPendingStakingOperationAmounts(account);
432
+ expect(result).toMatchObject({
433
+ vote: BigNumber(0),
434
+ lock: BigNumber(0),
435
+ });
436
+ });
437
+
438
+ it("getValidatorGroupsWithVotes", () => {
439
+ const result = getValidatorGroupsWithVotes(
440
+ [
441
+ {
442
+ address: "validator1",
443
+ name: "validator1",
444
+ votes: BigNumber(3),
445
+ },
446
+ {
447
+ address: "validator2",
448
+ name: "validator2",
449
+ votes: BigNumber(4),
450
+ },
451
+ {
452
+ address: "validator3",
453
+ name: "validator3",
454
+ votes: BigNumber(0),
455
+ },
456
+ ],
457
+ [
458
+ {
459
+ validatorGroup: "validator1",
460
+ amount: BigNumber(1),
461
+ activatable: true,
462
+ revokable: true,
463
+ type: "active",
464
+ index: 0,
465
+ },
466
+ {
467
+ validatorGroup: "validator2",
468
+ amount: BigNumber(2),
469
+ activatable: true,
470
+ revokable: true,
471
+ type: "active",
472
+ index: 0,
473
+ },
474
+ ],
475
+ );
476
+
477
+ expect(result).toMatchObject([
478
+ {
479
+ address: "validator1",
480
+ name: "validator1",
481
+ votes: BigNumber(3),
482
+ },
483
+ {
484
+ address: "validator2",
485
+ name: "validator2",
486
+ votes: BigNumber(4),
487
+ },
488
+ ]);
489
+ });
490
+
491
+ it("getValidatorGroupsWithoutVotes", () => {
492
+ const result = getValidatorGroupsWithoutVotes(
493
+ [
494
+ {
495
+ address: "validator1",
496
+ name: "validator1",
497
+ votes: BigNumber(3),
498
+ },
499
+ {
500
+ address: "validator2",
501
+ name: "validator2",
502
+ votes: BigNumber(4),
503
+ },
504
+ {
505
+ address: "validator3",
506
+ name: "validator3",
507
+ votes: BigNumber(0),
508
+ },
509
+ ],
510
+ [
511
+ {
512
+ validatorGroup: "validator1",
513
+ amount: BigNumber(1),
514
+ activatable: true,
515
+ revokable: true,
516
+ type: "active",
517
+ index: 0,
518
+ },
519
+ {
520
+ validatorGroup: "validator2",
521
+ amount: BigNumber(2),
522
+ activatable: true,
523
+ revokable: true,
524
+ type: "active",
525
+ index: 0,
526
+ },
527
+ ],
528
+ );
529
+
530
+ expect(result).toMatchObject([
531
+ {
532
+ address: "validator3",
533
+ name: "validator3",
534
+ votes: BigNumber(0),
535
+ },
536
+ ]);
537
+ });
538
+ });