@ledgerhq/coin-celo 1.3.0-nightly.4 → 1.3.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 (188) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.unimportedrc.json +6 -3
  3. package/CHANGELOG.md +27 -35
  4. package/lib/bridge/buildOptimisticOperation.d.ts.map +1 -1
  5. package/lib/bridge/buildOptimisticOperation.js +2 -5
  6. package/lib/bridge/buildOptimisticOperation.js.map +1 -1
  7. package/lib/bridge/buildTransaction.d.ts.map +1 -1
  8. package/lib/bridge/buildTransaction.js +6 -29
  9. package/lib/bridge/buildTransaction.js.map +1 -1
  10. package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -1
  11. package/lib/bridge/estimateMaxSpendable.js +1 -9
  12. package/lib/bridge/estimateMaxSpendable.js.map +1 -1
  13. package/lib/bridge/getFeesForTransaction.d.ts.map +1 -1
  14. package/lib/bridge/getFeesForTransaction.js +5 -32
  15. package/lib/bridge/getFeesForTransaction.js.map +1 -1
  16. package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
  17. package/lib/bridge/getTransactionStatus.js +4 -18
  18. package/lib/bridge/getTransactionStatus.js.map +1 -1
  19. package/lib/bridge/index.d.ts.map +1 -1
  20. package/lib/bridge/index.js.map +1 -1
  21. package/lib/bridge/prepareTransaction.d.ts.map +1 -1
  22. package/lib/bridge/prepareTransaction.js +4 -33
  23. package/lib/bridge/prepareTransaction.js.map +1 -1
  24. package/lib/bridge/signOperation.d.ts.map +1 -1
  25. package/lib/bridge/signOperation.js +3 -11
  26. package/lib/bridge/signOperation.js.map +1 -1
  27. package/lib/bridge/synchronisation.d.ts.map +1 -1
  28. package/lib/bridge/synchronisation.js +3 -7
  29. package/lib/bridge/synchronisation.js.map +1 -1
  30. package/lib/config.d.ts.map +1 -1
  31. package/lib/config.js +0 -8
  32. package/lib/config.js.map +1 -1
  33. package/lib/test/please-add-coverage.test.d.ts +2 -0
  34. package/lib/test/please-add-coverage.test.d.ts.map +1 -0
  35. package/lib/test/please-add-coverage.test.js +6 -0
  36. package/lib/test/please-add-coverage.test.js.map +1 -0
  37. package/lib/types/types.d.ts +0 -1
  38. package/lib/types/types.d.ts.map +1 -1
  39. package/lib/types/types.js.map +1 -1
  40. package/lib-es/bridge/buildOptimisticOperation.d.ts.map +1 -1
  41. package/lib-es/bridge/buildOptimisticOperation.js +2 -5
  42. package/lib-es/bridge/buildOptimisticOperation.js.map +1 -1
  43. package/lib-es/bridge/buildTransaction.d.ts.map +1 -1
  44. package/lib-es/bridge/buildTransaction.js +6 -29
  45. package/lib-es/bridge/buildTransaction.js.map +1 -1
  46. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
  47. package/lib-es/bridge/estimateMaxSpendable.js +2 -10
  48. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
  49. package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -1
  50. package/lib-es/bridge/getFeesForTransaction.js +5 -29
  51. package/lib-es/bridge/getFeesForTransaction.js.map +1 -1
  52. package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
  53. package/lib-es/bridge/getTransactionStatus.js +4 -18
  54. package/lib-es/bridge/getTransactionStatus.js.map +1 -1
  55. package/lib-es/bridge/index.d.ts.map +1 -1
  56. package/lib-es/bridge/index.js.map +1 -1
  57. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
  58. package/lib-es/bridge/prepareTransaction.js +4 -33
  59. package/lib-es/bridge/prepareTransaction.js.map +1 -1
  60. package/lib-es/bridge/signOperation.d.ts.map +1 -1
  61. package/lib-es/bridge/signOperation.js +3 -11
  62. package/lib-es/bridge/signOperation.js.map +1 -1
  63. package/lib-es/bridge/synchronisation.d.ts.map +1 -1
  64. package/lib-es/bridge/synchronisation.js +3 -7
  65. package/lib-es/bridge/synchronisation.js.map +1 -1
  66. package/lib-es/config.d.ts.map +1 -1
  67. package/lib-es/config.js +0 -8
  68. package/lib-es/config.js.map +1 -1
  69. package/lib-es/test/please-add-coverage.test.d.ts +1 -0
  70. package/lib-es/test/please-add-coverage.test.d.ts.map +1 -0
  71. package/lib-es/test/please-add-coverage.test.js +5 -0
  72. package/lib-es/test/please-add-coverage.test.js.map +1 -0
  73. package/lib-es/types/types.d.ts +0 -1
  74. package/lib-es/types/types.d.ts.map +1 -1
  75. package/lib-es/types/types.js.map +1 -1
  76. package/package.json +17 -18
  77. package/src/bridge/buildOptimisticOperation.ts +2 -6
  78. package/src/bridge/buildTransaction.ts +7 -38
  79. package/src/bridge/estimateMaxSpendable.ts +2 -18
  80. package/src/bridge/getFeesForTransaction.ts +5 -39
  81. package/src/bridge/getTransactionStatus.ts +4 -21
  82. package/src/bridge/index.ts +1 -0
  83. package/src/bridge/prepareTransaction.ts +6 -39
  84. package/src/bridge/signOperation.ts +4 -19
  85. package/src/bridge/synchronisation.ts +4 -10
  86. package/src/config.ts +0 -8
  87. package/src/logic.ts +1 -1
  88. package/src/test/please-add-coverage.test.ts +3 -0
  89. package/src/types/types.ts +0 -1
  90. package/lib/__tests__/bridge/buildOptimisticOperation.test.d.ts +0 -2
  91. package/lib/__tests__/bridge/buildOptimisticOperation.test.d.ts.map +0 -1
  92. package/lib/__tests__/bridge/buildOptimisticOperation.test.js +0 -23
  93. package/lib/__tests__/bridge/buildOptimisticOperation.test.js.map +0 -1
  94. package/lib/__tests__/bridge/buildTransaction.test.d.ts +0 -2
  95. package/lib/__tests__/bridge/buildTransaction.test.d.ts.map +0 -1
  96. package/lib/__tests__/bridge/buildTransaction.test.js +0 -412
  97. package/lib/__tests__/bridge/buildTransaction.test.js.map +0 -1
  98. package/lib/__tests__/bridge/createTransaction.test.d.ts +0 -2
  99. package/lib/__tests__/bridge/createTransaction.test.d.ts.map +0 -1
  100. package/lib/__tests__/bridge/createTransaction.test.js +0 -22
  101. package/lib/__tests__/bridge/createTransaction.test.js.map +0 -1
  102. package/lib/__tests__/bridge/deviceTransactionConfig.test.d.ts +0 -2
  103. package/lib/__tests__/bridge/deviceTransactionConfig.test.d.ts.map +0 -1
  104. package/lib/__tests__/bridge/deviceTransactionConfig.test.js +0 -21
  105. package/lib/__tests__/bridge/deviceTransactionConfig.test.js.map +0 -1
  106. package/lib/__tests__/bridge/estimateMaxSpendable.test.d.ts +0 -2
  107. package/lib/__tests__/bridge/estimateMaxSpendable.test.d.ts.map +0 -1
  108. package/lib/__tests__/bridge/estimateMaxSpendable.test.js +0 -108
  109. package/lib/__tests__/bridge/estimateMaxSpendable.test.js.map +0 -1
  110. package/lib/__tests__/bridge/getFeesForTransaction.test.d.ts +0 -2
  111. package/lib/__tests__/bridge/getFeesForTransaction.test.d.ts.map +0 -1
  112. package/lib/__tests__/bridge/getFeesForTransaction.test.js +0 -211
  113. package/lib/__tests__/bridge/getFeesForTransaction.test.js.map +0 -1
  114. package/lib/__tests__/bridge/getTransactionStatus.test.d.ts +0 -2
  115. package/lib/__tests__/bridge/getTransactionStatus.test.d.ts.map +0 -1
  116. package/lib/__tests__/bridge/getTransactionStatus.test.js +0 -214
  117. package/lib/__tests__/bridge/getTransactionStatus.test.js.map +0 -1
  118. package/lib/__tests__/bridge/logic.test.d.ts +0 -2
  119. package/lib/__tests__/bridge/logic.test.d.ts.map +0 -1
  120. package/lib/__tests__/bridge/logic.test.js +0 -490
  121. package/lib/__tests__/bridge/logic.test.js.map +0 -1
  122. package/lib/__tests__/bridge/prepareTransaction.test.d.ts +0 -2
  123. package/lib/__tests__/bridge/prepareTransaction.test.d.ts.map +0 -1
  124. package/lib/__tests__/bridge/prepareTransaction.test.js +0 -239
  125. package/lib/__tests__/bridge/prepareTransaction.test.js.map +0 -1
  126. package/lib/bridge/fixtures.d.ts +0 -36
  127. package/lib/bridge/fixtures.d.ts.map +0 -1
  128. package/lib/bridge/fixtures.js +0 -98
  129. package/lib/bridge/fixtures.js.map +0 -1
  130. package/lib/constants.d.ts +0 -6
  131. package/lib/constants.d.ts.map +0 -1
  132. package/lib/constants.js +0 -15
  133. package/lib/constants.js.map +0 -1
  134. package/lib-es/__tests__/bridge/buildOptimisticOperation.test.d.ts +0 -2
  135. package/lib-es/__tests__/bridge/buildOptimisticOperation.test.d.ts.map +0 -1
  136. package/lib-es/__tests__/bridge/buildOptimisticOperation.test.js +0 -18
  137. package/lib-es/__tests__/bridge/buildOptimisticOperation.test.js.map +0 -1
  138. package/lib-es/__tests__/bridge/buildTransaction.test.d.ts +0 -2
  139. package/lib-es/__tests__/bridge/buildTransaction.test.d.ts.map +0 -1
  140. package/lib-es/__tests__/bridge/buildTransaction.test.js +0 -407
  141. package/lib-es/__tests__/bridge/buildTransaction.test.js.map +0 -1
  142. package/lib-es/__tests__/bridge/createTransaction.test.d.ts +0 -2
  143. package/lib-es/__tests__/bridge/createTransaction.test.d.ts.map +0 -1
  144. package/lib-es/__tests__/bridge/createTransaction.test.js +0 -17
  145. package/lib-es/__tests__/bridge/createTransaction.test.js.map +0 -1
  146. package/lib-es/__tests__/bridge/deviceTransactionConfig.test.d.ts +0 -2
  147. package/lib-es/__tests__/bridge/deviceTransactionConfig.test.d.ts.map +0 -1
  148. package/lib-es/__tests__/bridge/deviceTransactionConfig.test.js +0 -16
  149. package/lib-es/__tests__/bridge/deviceTransactionConfig.test.js.map +0 -1
  150. package/lib-es/__tests__/bridge/estimateMaxSpendable.test.d.ts +0 -2
  151. package/lib-es/__tests__/bridge/estimateMaxSpendable.test.d.ts.map +0 -1
  152. package/lib-es/__tests__/bridge/estimateMaxSpendable.test.js +0 -103
  153. package/lib-es/__tests__/bridge/estimateMaxSpendable.test.js.map +0 -1
  154. package/lib-es/__tests__/bridge/getFeesForTransaction.test.d.ts +0 -2
  155. package/lib-es/__tests__/bridge/getFeesForTransaction.test.d.ts.map +0 -1
  156. package/lib-es/__tests__/bridge/getFeesForTransaction.test.js +0 -206
  157. package/lib-es/__tests__/bridge/getFeesForTransaction.test.js.map +0 -1
  158. package/lib-es/__tests__/bridge/getTransactionStatus.test.d.ts +0 -2
  159. package/lib-es/__tests__/bridge/getTransactionStatus.test.d.ts.map +0 -1
  160. package/lib-es/__tests__/bridge/getTransactionStatus.test.js +0 -209
  161. package/lib-es/__tests__/bridge/getTransactionStatus.test.js.map +0 -1
  162. package/lib-es/__tests__/bridge/logic.test.d.ts +0 -2
  163. package/lib-es/__tests__/bridge/logic.test.d.ts.map +0 -1
  164. package/lib-es/__tests__/bridge/logic.test.js +0 -485
  165. package/lib-es/__tests__/bridge/logic.test.js.map +0 -1
  166. package/lib-es/__tests__/bridge/prepareTransaction.test.d.ts +0 -2
  167. package/lib-es/__tests__/bridge/prepareTransaction.test.d.ts.map +0 -1
  168. package/lib-es/__tests__/bridge/prepareTransaction.test.js +0 -234
  169. package/lib-es/__tests__/bridge/prepareTransaction.test.js.map +0 -1
  170. package/lib-es/bridge/fixtures.d.ts +0 -36
  171. package/lib-es/bridge/fixtures.d.ts.map +0 -1
  172. package/lib-es/bridge/fixtures.js +0 -89
  173. package/lib-es/bridge/fixtures.js.map +0 -1
  174. package/lib-es/constants.d.ts +0 -6
  175. package/lib-es/constants.d.ts.map +0 -1
  176. package/lib-es/constants.js +0 -11
  177. package/lib-es/constants.js.map +0 -1
  178. package/src/__tests__/bridge/buildOptimisticOperation.test.ts +0 -29
  179. package/src/__tests__/bridge/buildTransaction.test.ts +0 -502
  180. package/src/__tests__/bridge/createTransaction.test.ts +0 -17
  181. package/src/__tests__/bridge/deviceTransactionConfig.test.ts +0 -16
  182. package/src/__tests__/bridge/estimateMaxSpendable.test.ts +0 -112
  183. package/src/__tests__/bridge/getFeesForTransaction.test.ts +0 -233
  184. package/src/__tests__/bridge/getTransactionStatus.test.ts +0 -261
  185. package/src/__tests__/bridge/logic.test.ts +0 -538
  186. package/src/__tests__/bridge/prepareTransaction.test.ts +0 -261
  187. package/src/bridge/fixtures.ts +0 -103
  188. package/src/constants.ts +0 -15
@@ -1,502 +0,0 @@
1
- import BigNumber from "bignumber.js";
2
- import buildTransaction from "../../bridge/buildTransaction";
3
- import {
4
- accountFixture,
5
- accountWithTokenAccountFixture,
6
- transactionFixture,
7
- } from "../../bridge/fixtures";
8
-
9
- const chainIdMock = jest.fn();
10
- const nonceMock = jest.fn();
11
- const voteMock = jest.fn(() => ({
12
- txo: {
13
- encodeABI: jest.fn(() => ({ data: "vote_data" })),
14
- estimateGas: jest.fn(async () => 1),
15
- },
16
- }));
17
- const revokeMock = jest.fn();
18
- const voteSignerToAccountMock = jest.fn();
19
-
20
- jest.mock("../../network/sdk", () => {
21
- return {
22
- celoKit: jest.fn(() => ({
23
- contracts: {
24
- getLockedGold: jest.fn(async () => ({
25
- address: "address",
26
- lock: jest.fn(() => ({
27
- txo: {
28
- encodeABI: jest.fn(() => ({ data: "lock_data" })),
29
- estimateGas: jest.fn(async () => 2),
30
- },
31
- })),
32
- unlock: jest.fn(() => ({
33
- txo: {
34
- encodeABI: jest.fn(() => ({ data: "unlock_data" })),
35
- estimateGas: jest.fn(async () => 3),
36
- },
37
- })),
38
- withdraw: jest.fn(() => ({
39
- txo: {
40
- encodeABI: jest.fn(() => ({ data: "withdraw_data" })),
41
- estimateGas: jest.fn(async () => 3),
42
- },
43
- })),
44
- vote: jest.fn(() => ({
45
- txo: {
46
- encodeABI: jest.fn(() => ({ data: "vote_data" })),
47
- estimateGas: jest.fn(async () => 3),
48
- },
49
- })),
50
- })),
51
- getElection: jest.fn(async () => ({
52
- vote: voteMock,
53
- revoke: revokeMock,
54
- activate: jest.fn(() => ({
55
- find: jest.fn(() => ({
56
- txo: {
57
- encodeABI: jest.fn(() => ({ data: "vote_data" })),
58
- estimateGas: jest.fn(async () => 3),
59
- },
60
- })),
61
- })),
62
- address: "vote_address",
63
- })),
64
- getAccounts: jest.fn(async () => ({
65
- voteSignerToAccount: voteSignerToAccountMock,
66
- createAccount: jest.fn(() => ({
67
- txo: {
68
- encodeABI: jest.fn(() => ({ data: "register_data" })),
69
- estimateGas: jest.fn(async () => 3),
70
- },
71
- })),
72
- address: "register_address",
73
- })),
74
- getStableToken: jest.fn(async () => ({
75
- address: "stable_token_address",
76
- transfer: jest.fn(() => ({
77
- txo: {
78
- encodeABI: jest.fn(() => ({ data: "send_token_data" })),
79
- },
80
- })),
81
- })),
82
- getErc20: jest.fn(async () => ({
83
- address: "erc20_token_address",
84
- transfer: jest.fn(() => ({
85
- txo: {
86
- encodeABI: jest.fn(() => ({ data: "send_token_data" })),
87
- },
88
- })),
89
- })),
90
- },
91
- connection: {
92
- chainId: chainIdMock,
93
- nonce: nonceMock,
94
- estimateGasWithInflationFactor: jest.fn().mockReturnValue(3),
95
- web3: { eth: { getBlock: jest.fn().mockResolvedValue({ baseFeePerGas: 10 }) } },
96
- getMaxPriorityFeePerGas: jest.fn().mockResolvedValue(1),
97
- },
98
- })),
99
- };
100
- });
101
-
102
- describe("buildTransaction", () => {
103
- it("should build a lock transaction", async () => {
104
- const transaction = await buildTransaction(
105
- { ...accountFixture, spendableBalance: BigNumber(123) },
106
- {
107
- ...transactionFixture,
108
- mode: "lock",
109
- },
110
- );
111
-
112
- expect(transaction).toMatchObject({
113
- from: accountFixture.freshAddress,
114
- to: "address",
115
- value: "10",
116
- data: { data: "lock_data" },
117
- gas: "12",
118
- });
119
-
120
- expect(chainIdMock).toHaveBeenCalledTimes(1);
121
- expect(nonceMock).toHaveBeenCalledWith(accountFixture.freshAddress);
122
- });
123
-
124
- it("should build a lock transaction with useAllAmount", async () => {
125
- const transaction = await buildTransaction(
126
- { ...accountFixture, spendableBalance: BigNumber(123) },
127
- {
128
- ...transactionFixture,
129
- mode: "lock",
130
- useAllAmount: true,
131
- fees: BigNumber(2),
132
- },
133
- );
134
-
135
- expect(transaction).toMatchObject({
136
- from: accountFixture.freshAddress,
137
- to: "address",
138
- value: "121",
139
- data: { data: "lock_data" },
140
- gas: "12",
141
- });
142
- });
143
-
144
- it("should build an unlock transaction", async () => {
145
- const transaction = await buildTransaction(
146
- {
147
- ...accountFixture,
148
- spendableBalance: BigNumber(123),
149
- celoResources: {
150
- registrationStatus: false,
151
- lockedBalance: BigNumber(0),
152
- nonvotingLockedBalance: BigNumber(40),
153
- pendingWithdrawals: null,
154
- votes: null,
155
- electionAddress: null,
156
- lockedGoldAddress: null,
157
- maxNumGroupsVotedFor: BigNumber(0),
158
- },
159
- },
160
- {
161
- ...transactionFixture,
162
- mode: "unlock",
163
- },
164
- );
165
-
166
- expect(transaction).toMatchObject({
167
- from: accountFixture.freshAddress,
168
- to: "address",
169
- data: { data: "unlock_data" },
170
- gas: "12",
171
- });
172
- });
173
-
174
- it("should build an unlock transaction with useAllAmount", async () => {
175
- const transaction = await buildTransaction(
176
- {
177
- ...accountFixture,
178
- spendableBalance: BigNumber(123),
179
- celoResources: {
180
- registrationStatus: false,
181
- lockedBalance: BigNumber(0),
182
- nonvotingLockedBalance: BigNumber(40),
183
- pendingWithdrawals: null,
184
- votes: null,
185
- electionAddress: null,
186
- lockedGoldAddress: null,
187
- maxNumGroupsVotedFor: BigNumber(0),
188
- },
189
- },
190
- {
191
- ...transactionFixture,
192
- useAllAmount: true,
193
- mode: "unlock",
194
- },
195
- );
196
-
197
- expect(transaction).toMatchObject({
198
- from: accountFixture.freshAddress,
199
- to: "address",
200
- data: { data: "unlock_data" },
201
- gas: "12",
202
- });
203
- });
204
-
205
- it("should build a withdraw transaction", async () => {
206
- const transaction = await buildTransaction(
207
- {
208
- ...accountFixture,
209
- spendableBalance: BigNumber(123),
210
- celoResources: {
211
- registrationStatus: false,
212
- lockedBalance: BigNumber(0),
213
- nonvotingLockedBalance: BigNumber(40),
214
- pendingWithdrawals: null,
215
- votes: null,
216
- electionAddress: null,
217
- lockedGoldAddress: null,
218
- maxNumGroupsVotedFor: BigNumber(0),
219
- },
220
- },
221
- {
222
- ...transactionFixture,
223
- mode: "withdraw",
224
- },
225
- );
226
-
227
- expect(transaction).toMatchObject({
228
- from: accountFixture.freshAddress,
229
- to: "address",
230
- data: { data: "withdraw_data" },
231
- gas: "12",
232
- });
233
- });
234
-
235
- it("should build a vote transaction", async () => {
236
- const transaction = await buildTransaction(
237
- {
238
- ...accountFixture,
239
- spendableBalance: BigNumber(123),
240
- celoResources: {
241
- registrationStatus: false,
242
- lockedBalance: BigNumber(0),
243
- nonvotingLockedBalance: BigNumber(40),
244
- pendingWithdrawals: null,
245
- votes: null,
246
- electionAddress: null,
247
- lockedGoldAddress: null,
248
- maxNumGroupsVotedFor: BigNumber(0),
249
- },
250
- },
251
- {
252
- ...transactionFixture,
253
- mode: "vote",
254
- },
255
- );
256
-
257
- expect(transaction).toMatchObject({
258
- from: accountFixture.freshAddress,
259
- to: "vote_address",
260
- data: { data: "vote_data" },
261
- gas: "12",
262
- });
263
-
264
- expect(voteMock).toHaveBeenCalledTimes(1);
265
- expect(voteMock).toHaveBeenCalledWith(transactionFixture.recipient, new BigNumber(10));
266
- });
267
-
268
- it("should build a revoke transaction but fail without revokes", async () => {
269
- revokeMock.mockClear();
270
-
271
- revokeMock.mockReturnValue({
272
- find: jest.fn(() => false),
273
- });
274
-
275
- expect(
276
- async () =>
277
- await buildTransaction(
278
- {
279
- ...accountFixture,
280
- spendableBalance: BigNumber(123),
281
- celoResources: {
282
- registrationStatus: false,
283
- lockedBalance: BigNumber(0),
284
- nonvotingLockedBalance: BigNumber(40),
285
- pendingWithdrawals: null,
286
- votes: null,
287
- electionAddress: null,
288
- lockedGoldAddress: null,
289
- maxNumGroupsVotedFor: BigNumber(0),
290
- },
291
- },
292
- {
293
- ...transactionFixture,
294
- mode: "revoke",
295
- },
296
- ),
297
- ).rejects.toThrow("No votes to revoke");
298
- });
299
-
300
- it("should build a revoke transaction", async () => {
301
- revokeMock.mockClear();
302
-
303
- voteSignerToAccountMock.mockReturnValue("signer_account");
304
- revokeMock.mockReturnValue({
305
- find: jest.fn(() => ({
306
- txo: {
307
- encodeABI: jest.fn(() => ({ data: "revoke_data" })),
308
- estimateGas: jest.fn(async () => 2),
309
- },
310
- })),
311
- });
312
-
313
- const transaction = await buildTransaction(
314
- {
315
- ...accountFixture,
316
- spendableBalance: BigNumber(123),
317
- celoResources: {
318
- registrationStatus: false,
319
- lockedBalance: BigNumber(0),
320
- nonvotingLockedBalance: BigNumber(40),
321
- pendingWithdrawals: null,
322
- votes: null,
323
- electionAddress: null,
324
- lockedGoldAddress: null,
325
- maxNumGroupsVotedFor: BigNumber(0),
326
- },
327
- },
328
- {
329
- ...transactionFixture,
330
- mode: "revoke",
331
- },
332
- );
333
-
334
- expect(transaction).toMatchObject({
335
- from: accountFixture.freshAddress,
336
- to: "vote_address",
337
- data: { data: "revoke_data" },
338
- gas: "12",
339
- });
340
-
341
- expect(revokeMock).toHaveBeenCalledTimes(1);
342
- expect(revokeMock).toHaveBeenCalledWith(
343
- "signer_account",
344
- transactionFixture.recipient,
345
- new BigNumber(10),
346
- );
347
- expect(voteSignerToAccountMock).toHaveBeenCalledWith(accountFixture.freshAddress);
348
- });
349
-
350
- it("should build a revoke transaction with useAllAmount", async () => {
351
- revokeMock.mockClear();
352
-
353
- voteSignerToAccountMock.mockReturnValue("signer_account");
354
- revokeMock.mockReturnValue({
355
- find: jest.fn(() => ({
356
- txo: {
357
- encodeABI: jest.fn(() => ({ data: "revoke_data" })),
358
- estimateGas: jest.fn(async () => 2),
359
- },
360
- })),
361
- });
362
-
363
- const transaction = await buildTransaction(
364
- {
365
- ...accountFixture,
366
- spendableBalance: BigNumber(123),
367
- celoResources: {
368
- registrationStatus: false,
369
- lockedBalance: BigNumber(0),
370
- nonvotingLockedBalance: BigNumber(40),
371
- pendingWithdrawals: null,
372
- votes: null,
373
- electionAddress: null,
374
- lockedGoldAddress: null,
375
- maxNumGroupsVotedFor: BigNumber(0),
376
- },
377
- },
378
- {
379
- ...transactionFixture,
380
- useAllAmount: true,
381
- mode: "revoke",
382
- },
383
- );
384
-
385
- expect(transaction).toMatchObject({
386
- from: accountFixture.freshAddress,
387
- to: "vote_address",
388
- data: { data: "revoke_data" },
389
- gas: "12",
390
- });
391
-
392
- expect(revokeMock).toHaveBeenCalledTimes(1);
393
- expect(revokeMock).toHaveBeenCalledWith(
394
- "signer_account",
395
- transactionFixture.recipient,
396
- new BigNumber(10),
397
- );
398
- expect(voteSignerToAccountMock).toHaveBeenCalledWith(accountFixture.freshAddress);
399
- });
400
-
401
- it("should build an activate transaction", async () => {
402
- const transaction = await buildTransaction(
403
- { ...accountFixture, spendableBalance: BigNumber(123) },
404
- {
405
- ...transactionFixture,
406
- mode: "activate",
407
- },
408
- );
409
-
410
- expect(transaction).toMatchObject({
411
- from: accountFixture.freshAddress,
412
- to: "vote_address",
413
- data: { data: "vote_data" },
414
- gas: "12",
415
- });
416
- });
417
-
418
- it("should build a register transaction", async () => {
419
- const transaction = await buildTransaction(
420
- { ...accountFixture, spendableBalance: BigNumber(123) },
421
- {
422
- ...transactionFixture,
423
- mode: "register",
424
- },
425
- );
426
-
427
- expect(transaction).toMatchObject({
428
- from: accountFixture.freshAddress,
429
- to: "register_address",
430
- data: { data: "register_data" },
431
- gas: "12",
432
- });
433
- });
434
-
435
- it("should build a send transaction", async () => {
436
- const transaction = await buildTransaction(
437
- { ...accountFixture, spendableBalance: BigNumber(123) },
438
- {
439
- ...transactionFixture,
440
- mode: "send",
441
- },
442
- );
443
-
444
- expect(transaction).toMatchObject({
445
- from: accountFixture.freshAddress,
446
- to: transactionFixture.recipient,
447
- value: "10",
448
- gas: "12",
449
- });
450
- });
451
-
452
- it("should build a token transaction", async () => {
453
- const transaction = await buildTransaction(
454
- {
455
- ...accountWithTokenAccountFixture,
456
- spendableBalance: BigNumber(123),
457
- },
458
- {
459
- ...transactionFixture,
460
- subAccountId: accountWithTokenAccountFixture.subAccounts[0].id,
461
- mode: "send",
462
- },
463
- );
464
-
465
- expect(transaction).toMatchObject({
466
- from: accountFixture.freshAddress,
467
- to: "recipient",
468
- value: "10",
469
- gas: "12",
470
- });
471
- });
472
-
473
- it("should build a stable token transaction", async () => {
474
- const transaction = await buildTransaction(
475
- {
476
- ...accountWithTokenAccountFixture,
477
- spendableBalance: BigNumber(123),
478
- subAccounts: [
479
- {
480
- ...accountWithTokenAccountFixture.subAccounts[0],
481
- token: {
482
- ...accountWithTokenAccountFixture.subAccounts[0].token,
483
- id: "cEUR",
484
- },
485
- },
486
- ],
487
- },
488
- {
489
- ...transactionFixture,
490
- subAccountId: accountWithTokenAccountFixture.subAccounts[0].id,
491
- mode: "send",
492
- },
493
- );
494
-
495
- expect(transaction).toMatchObject({
496
- from: accountFixture.freshAddress,
497
- to: "recipient",
498
- value: "10",
499
- gas: "12",
500
- });
501
- });
502
- });
@@ -1,17 +0,0 @@
1
- import BigNumber from "bignumber.js";
2
- import createTransaction from "../../bridge/createTransaction";
3
- import { accountFixture } from "../../bridge/fixtures";
4
-
5
- describe("createTransaction", () => {
6
- it("returns a dummy transaction", () => {
7
- expect(createTransaction(accountFixture)).toMatchObject({
8
- family: "celo",
9
- amount: new BigNumber(0),
10
- recipient: "",
11
- useAllAmount: false,
12
- fees: null,
13
- mode: "send",
14
- index: null,
15
- });
16
- });
17
- });
@@ -1,16 +0,0 @@
1
- import getDeviceTransactionConfig from "../../bridge/deviceTransactionConfig";
2
-
3
- describe("deviceTransactionConfig", () => {
4
- it("returns the expected config", () => {
5
- expect(getDeviceTransactionConfig()).toEqual([
6
- {
7
- type: "amount",
8
- label: "Amount",
9
- },
10
- {
11
- type: "fees",
12
- label: "Fees",
13
- },
14
- ]);
15
- });
16
- });
@@ -1,112 +0,0 @@
1
- import BigNumber from "bignumber.js";
2
- import estimateMaxSpendable from "../../bridge/estimateMaxSpendable";
3
- import {
4
- accountFixture,
5
- accountWithTokenAccountFixture,
6
- tokenTransactionFixture,
7
- transactionFixture,
8
- } from "../../bridge/fixtures";
9
-
10
- jest.mock("../../bridge/getFeesForTransaction", async () => 12);
11
-
12
- const voteMock = jest.fn(() => ({
13
- txo: {
14
- encodeABI: jest.fn(() => ({ data: "vote_data" })),
15
- estimateGas: jest.fn(async () => 1),
16
- },
17
- }));
18
-
19
- jest.mock("../../network/sdk", () => {
20
- return {
21
- celoKit: jest.fn(() => ({
22
- contracts: {
23
- getLockedGold: jest.fn(async () => ({
24
- address: "address",
25
- getAccountNonvotingLockedGold: jest.fn(async () => BigNumber(22)),
26
- lock: jest.fn(() => ({
27
- txo: {
28
- encodeABI: jest.fn(() => ({ data: "lock_data" })),
29
- estimateGas: jest.fn(async () => 2),
30
- },
31
- })),
32
- unlock: jest.fn(() => ({
33
- txo: {
34
- encodeABI: jest.fn(() => ({ data: "unlock_data" })),
35
- estimateGas: jest.fn(async () => 3),
36
- },
37
- })),
38
- withdraw: jest.fn(() => ({
39
- txo: {
40
- encodeABI: jest.fn(() => ({ data: "withdraw_data" })),
41
- estimateGas: jest.fn(async () => 3),
42
- },
43
- })),
44
- vote: jest.fn(() => ({
45
- txo: {
46
- encodeABI: jest.fn(() => ({ data: "vote_data" })),
47
- estimateGas: jest.fn(async () => 3),
48
- },
49
- })),
50
- })),
51
- getElection: jest.fn(async () => ({
52
- vote: voteMock,
53
- revoke: jest.fn(),
54
- address: "vote_address",
55
- })),
56
- getAccounts: jest.fn(async () => ({
57
- voteSignerToAccount: jest.fn(),
58
- createAccount: jest.fn(() => ({
59
- txo: {
60
- encodeABI: jest.fn(() => ({ data: "register_data" })),
61
- estimateGas: jest.fn(async () => 3),
62
- },
63
- })),
64
- address: "register_address",
65
- })),
66
- getStableToken: jest.fn(async () => ({
67
- address: "stable_token_address",
68
- transfer: jest.fn(() => ({
69
- txo: {
70
- encodeABI: jest.fn(() => ({ data: "send_token_data" })),
71
- },
72
- })),
73
- })),
74
- getErc20: jest.fn(async () => ({
75
- address: "erc20_token_address",
76
- transfer: jest.fn(() => ({
77
- txo: {
78
- encodeABI: jest.fn(() => ({ data: "send_token_data" })),
79
- },
80
- })),
81
- })),
82
- },
83
- connection: {
84
- chainId: jest.fn(),
85
- nonce: jest.fn(),
86
- estimateGasWithInflationFactor: jest.fn().mockReturnValue(3),
87
- },
88
- })),
89
- };
90
- });
91
-
92
- describe("estimateMaxSpendable", () => {
93
- it("returns the maximum spendable for a celo account", async () => {
94
- const maximumAmount = await estimateMaxSpendable({
95
- account: { ...accountFixture, balance: BigNumber(100), spendableBalance: BigNumber(100) },
96
- transaction: transactionFixture,
97
- });
98
- expect(maximumAmount).toEqual(BigNumber(100));
99
- });
100
-
101
- it("returns the maximum spendable for a celo account", async () => {
102
- const maximumAmount = await estimateMaxSpendable({
103
- account: {
104
- ...accountWithTokenAccountFixture,
105
- balance: BigNumber(100),
106
- spendableBalance: BigNumber(100),
107
- },
108
- transaction: tokenTransactionFixture,
109
- });
110
- expect(maximumAmount).toEqual(BigNumber(212));
111
- });
112
- });