@ledgerhq/coin-celo 1.3.0 → 1.4.0-nightly.1

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 (200) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.unimportedrc.json +3 -6
  3. package/CHANGELOG.md +24 -0
  4. package/lib/__tests__/bridge/buildOptimisticOperation.test.d.ts +2 -0
  5. package/lib/__tests__/bridge/buildOptimisticOperation.test.d.ts.map +1 -0
  6. package/lib/__tests__/bridge/buildOptimisticOperation.test.js +23 -0
  7. package/lib/__tests__/bridge/buildOptimisticOperation.test.js.map +1 -0
  8. package/lib/__tests__/bridge/buildTransaction.test.d.ts +2 -0
  9. package/lib/__tests__/bridge/buildTransaction.test.d.ts.map +1 -0
  10. package/lib/__tests__/bridge/buildTransaction.test.js +412 -0
  11. package/lib/__tests__/bridge/buildTransaction.test.js.map +1 -0
  12. package/lib/__tests__/bridge/createTransaction.test.d.ts +2 -0
  13. package/lib/__tests__/bridge/createTransaction.test.d.ts.map +1 -0
  14. package/lib/__tests__/bridge/createTransaction.test.js +22 -0
  15. package/lib/__tests__/bridge/createTransaction.test.js.map +1 -0
  16. package/lib/__tests__/bridge/deviceTransactionConfig.test.d.ts +2 -0
  17. package/lib/__tests__/bridge/deviceTransactionConfig.test.d.ts.map +1 -0
  18. package/lib/__tests__/bridge/deviceTransactionConfig.test.js +21 -0
  19. package/lib/__tests__/bridge/deviceTransactionConfig.test.js.map +1 -0
  20. package/lib/__tests__/bridge/estimateMaxSpendable.test.d.ts +2 -0
  21. package/lib/__tests__/bridge/estimateMaxSpendable.test.d.ts.map +1 -0
  22. package/lib/__tests__/bridge/estimateMaxSpendable.test.js +108 -0
  23. package/lib/__tests__/bridge/estimateMaxSpendable.test.js.map +1 -0
  24. package/lib/__tests__/bridge/getFeesForTransaction.test.d.ts +2 -0
  25. package/lib/__tests__/bridge/getFeesForTransaction.test.d.ts.map +1 -0
  26. package/lib/__tests__/bridge/getFeesForTransaction.test.js +211 -0
  27. package/lib/__tests__/bridge/getFeesForTransaction.test.js.map +1 -0
  28. package/lib/__tests__/bridge/getTransactionStatus.test.d.ts +2 -0
  29. package/lib/__tests__/bridge/getTransactionStatus.test.d.ts.map +1 -0
  30. package/lib/__tests__/bridge/getTransactionStatus.test.js +214 -0
  31. package/lib/__tests__/bridge/getTransactionStatus.test.js.map +1 -0
  32. package/lib/__tests__/bridge/logic.test.d.ts +2 -0
  33. package/lib/__tests__/bridge/logic.test.d.ts.map +1 -0
  34. package/lib/__tests__/bridge/logic.test.js +490 -0
  35. package/lib/__tests__/bridge/logic.test.js.map +1 -0
  36. package/lib/__tests__/bridge/prepareTransaction.test.d.ts +2 -0
  37. package/lib/__tests__/bridge/prepareTransaction.test.d.ts.map +1 -0
  38. package/lib/__tests__/bridge/prepareTransaction.test.js +239 -0
  39. package/lib/__tests__/bridge/prepareTransaction.test.js.map +1 -0
  40. package/lib/bridge/buildOptimisticOperation.d.ts.map +1 -1
  41. package/lib/bridge/buildOptimisticOperation.js +6 -3
  42. package/lib/bridge/buildOptimisticOperation.js.map +1 -1
  43. package/lib/bridge/buildTransaction.d.ts.map +1 -1
  44. package/lib/bridge/buildTransaction.js +29 -6
  45. package/lib/bridge/buildTransaction.js.map +1 -1
  46. package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -1
  47. package/lib/bridge/estimateMaxSpendable.js +9 -1
  48. package/lib/bridge/estimateMaxSpendable.js.map +1 -1
  49. package/lib/bridge/fixtures.d.ts +36 -0
  50. package/lib/bridge/fixtures.d.ts.map +1 -0
  51. package/lib/bridge/fixtures.js +98 -0
  52. package/lib/bridge/fixtures.js.map +1 -0
  53. package/lib/bridge/getFeesForTransaction.d.ts.map +1 -1
  54. package/lib/bridge/getFeesForTransaction.js +32 -5
  55. package/lib/bridge/getFeesForTransaction.js.map +1 -1
  56. package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
  57. package/lib/bridge/getTransactionStatus.js +18 -4
  58. package/lib/bridge/getTransactionStatus.js.map +1 -1
  59. package/lib/bridge/index.d.ts.map +1 -1
  60. package/lib/bridge/index.js.map +1 -1
  61. package/lib/bridge/prepareTransaction.d.ts.map +1 -1
  62. package/lib/bridge/prepareTransaction.js +33 -4
  63. package/lib/bridge/prepareTransaction.js.map +1 -1
  64. package/lib/bridge/serialization.d.ts.map +1 -1
  65. package/lib/bridge/serialization.js +10 -8
  66. package/lib/bridge/serialization.js.map +1 -1
  67. package/lib/bridge/signOperation.d.ts.map +1 -1
  68. package/lib/bridge/signOperation.js +11 -3
  69. package/lib/bridge/signOperation.js.map +1 -1
  70. package/lib/bridge/synchronisation.d.ts.map +1 -1
  71. package/lib/bridge/synchronisation.js +8 -3
  72. package/lib/bridge/synchronisation.js.map +1 -1
  73. package/lib/config.d.ts.map +1 -1
  74. package/lib/config.js +8 -0
  75. package/lib/config.js.map +1 -1
  76. package/lib/constants.d.ts +6 -0
  77. package/lib/constants.d.ts.map +1 -0
  78. package/lib/constants.js +15 -0
  79. package/lib/constants.js.map +1 -0
  80. package/lib/network/hubble.js +1 -1
  81. package/lib/network/hubble.js.map +1 -1
  82. package/lib/types/types.d.ts +3 -2
  83. package/lib/types/types.d.ts.map +1 -1
  84. package/lib/types/types.js.map +1 -1
  85. package/lib-es/__tests__/bridge/buildOptimisticOperation.test.d.ts +2 -0
  86. package/lib-es/__tests__/bridge/buildOptimisticOperation.test.d.ts.map +1 -0
  87. package/lib-es/__tests__/bridge/buildOptimisticOperation.test.js +18 -0
  88. package/lib-es/__tests__/bridge/buildOptimisticOperation.test.js.map +1 -0
  89. package/lib-es/__tests__/bridge/buildTransaction.test.d.ts +2 -0
  90. package/lib-es/__tests__/bridge/buildTransaction.test.d.ts.map +1 -0
  91. package/lib-es/__tests__/bridge/buildTransaction.test.js +407 -0
  92. package/lib-es/__tests__/bridge/buildTransaction.test.js.map +1 -0
  93. package/lib-es/__tests__/bridge/createTransaction.test.d.ts +2 -0
  94. package/lib-es/__tests__/bridge/createTransaction.test.d.ts.map +1 -0
  95. package/lib-es/__tests__/bridge/createTransaction.test.js +17 -0
  96. package/lib-es/__tests__/bridge/createTransaction.test.js.map +1 -0
  97. package/lib-es/__tests__/bridge/deviceTransactionConfig.test.d.ts +2 -0
  98. package/lib-es/__tests__/bridge/deviceTransactionConfig.test.d.ts.map +1 -0
  99. package/lib-es/__tests__/bridge/deviceTransactionConfig.test.js +16 -0
  100. package/lib-es/__tests__/bridge/deviceTransactionConfig.test.js.map +1 -0
  101. package/lib-es/__tests__/bridge/estimateMaxSpendable.test.d.ts +2 -0
  102. package/lib-es/__tests__/bridge/estimateMaxSpendable.test.d.ts.map +1 -0
  103. package/lib-es/__tests__/bridge/estimateMaxSpendable.test.js +103 -0
  104. package/lib-es/__tests__/bridge/estimateMaxSpendable.test.js.map +1 -0
  105. package/lib-es/__tests__/bridge/getFeesForTransaction.test.d.ts +2 -0
  106. package/lib-es/__tests__/bridge/getFeesForTransaction.test.d.ts.map +1 -0
  107. package/lib-es/__tests__/bridge/getFeesForTransaction.test.js +206 -0
  108. package/lib-es/__tests__/bridge/getFeesForTransaction.test.js.map +1 -0
  109. package/lib-es/__tests__/bridge/getTransactionStatus.test.d.ts +2 -0
  110. package/lib-es/__tests__/bridge/getTransactionStatus.test.d.ts.map +1 -0
  111. package/lib-es/__tests__/bridge/getTransactionStatus.test.js +209 -0
  112. package/lib-es/__tests__/bridge/getTransactionStatus.test.js.map +1 -0
  113. package/lib-es/__tests__/bridge/logic.test.d.ts +2 -0
  114. package/lib-es/__tests__/bridge/logic.test.d.ts.map +1 -0
  115. package/lib-es/__tests__/bridge/logic.test.js +485 -0
  116. package/lib-es/__tests__/bridge/logic.test.js.map +1 -0
  117. package/lib-es/__tests__/bridge/prepareTransaction.test.d.ts +2 -0
  118. package/lib-es/__tests__/bridge/prepareTransaction.test.d.ts.map +1 -0
  119. package/lib-es/__tests__/bridge/prepareTransaction.test.js +234 -0
  120. package/lib-es/__tests__/bridge/prepareTransaction.test.js.map +1 -0
  121. package/lib-es/bridge/buildOptimisticOperation.d.ts.map +1 -1
  122. package/lib-es/bridge/buildOptimisticOperation.js +6 -3
  123. package/lib-es/bridge/buildOptimisticOperation.js.map +1 -1
  124. package/lib-es/bridge/buildTransaction.d.ts.map +1 -1
  125. package/lib-es/bridge/buildTransaction.js +29 -6
  126. package/lib-es/bridge/buildTransaction.js.map +1 -1
  127. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
  128. package/lib-es/bridge/estimateMaxSpendable.js +10 -2
  129. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
  130. package/lib-es/bridge/fixtures.d.ts +36 -0
  131. package/lib-es/bridge/fixtures.d.ts.map +1 -0
  132. package/lib-es/bridge/fixtures.js +89 -0
  133. package/lib-es/bridge/fixtures.js.map +1 -0
  134. package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -1
  135. package/lib-es/bridge/getFeesForTransaction.js +29 -5
  136. package/lib-es/bridge/getFeesForTransaction.js.map +1 -1
  137. package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
  138. package/lib-es/bridge/getTransactionStatus.js +18 -4
  139. package/lib-es/bridge/getTransactionStatus.js.map +1 -1
  140. package/lib-es/bridge/index.d.ts.map +1 -1
  141. package/lib-es/bridge/index.js.map +1 -1
  142. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
  143. package/lib-es/bridge/prepareTransaction.js +33 -4
  144. package/lib-es/bridge/prepareTransaction.js.map +1 -1
  145. package/lib-es/bridge/serialization.d.ts.map +1 -1
  146. package/lib-es/bridge/serialization.js +10 -8
  147. package/lib-es/bridge/serialization.js.map +1 -1
  148. package/lib-es/bridge/signOperation.d.ts.map +1 -1
  149. package/lib-es/bridge/signOperation.js +11 -3
  150. package/lib-es/bridge/signOperation.js.map +1 -1
  151. package/lib-es/bridge/synchronisation.d.ts.map +1 -1
  152. package/lib-es/bridge/synchronisation.js +8 -3
  153. package/lib-es/bridge/synchronisation.js.map +1 -1
  154. package/lib-es/config.d.ts.map +1 -1
  155. package/lib-es/config.js +8 -0
  156. package/lib-es/config.js.map +1 -1
  157. package/lib-es/constants.d.ts +6 -0
  158. package/lib-es/constants.d.ts.map +1 -0
  159. package/lib-es/constants.js +11 -0
  160. package/lib-es/constants.js.map +1 -0
  161. package/lib-es/network/hubble.js +1 -1
  162. package/lib-es/network/hubble.js.map +1 -1
  163. package/lib-es/types/types.d.ts +3 -2
  164. package/lib-es/types/types.d.ts.map +1 -1
  165. package/lib-es/types/types.js.map +1 -1
  166. package/package.json +13 -12
  167. package/src/__tests__/bridge/buildOptimisticOperation.test.ts +29 -0
  168. package/src/__tests__/bridge/buildTransaction.test.ts +502 -0
  169. package/src/__tests__/bridge/createTransaction.test.ts +17 -0
  170. package/src/__tests__/bridge/deviceTransactionConfig.test.ts +16 -0
  171. package/src/__tests__/bridge/estimateMaxSpendable.test.ts +112 -0
  172. package/src/__tests__/bridge/getFeesForTransaction.test.ts +233 -0
  173. package/src/__tests__/bridge/getTransactionStatus.test.ts +261 -0
  174. package/src/__tests__/bridge/logic.test.ts +538 -0
  175. package/src/__tests__/bridge/prepareTransaction.test.ts +261 -0
  176. package/src/bridge/buildOptimisticOperation.ts +7 -3
  177. package/src/bridge/buildTransaction.ts +38 -7
  178. package/src/bridge/estimateMaxSpendable.ts +18 -2
  179. package/src/bridge/fixtures.ts +103 -0
  180. package/src/bridge/getFeesForTransaction.ts +39 -5
  181. package/src/bridge/getTransactionStatus.ts +21 -4
  182. package/src/bridge/index.ts +0 -1
  183. package/src/bridge/prepareTransaction.ts +39 -6
  184. package/src/bridge/serialization.ts +12 -8
  185. package/src/bridge/signOperation.ts +19 -4
  186. package/src/bridge/synchronisation.ts +11 -4
  187. package/src/config.ts +8 -0
  188. package/src/constants.ts +15 -0
  189. package/src/logic.ts +1 -1
  190. package/src/network/hubble.ts +1 -1
  191. package/src/types/types.ts +3 -2
  192. package/lib/test/please-add-coverage.test.d.ts +0 -2
  193. package/lib/test/please-add-coverage.test.d.ts.map +0 -1
  194. package/lib/test/please-add-coverage.test.js +0 -6
  195. package/lib/test/please-add-coverage.test.js.map +0 -1
  196. package/lib-es/test/please-add-coverage.test.d.ts +0 -1
  197. package/lib-es/test/please-add-coverage.test.d.ts.map +0 -1
  198. package/lib-es/test/please-add-coverage.test.js +0 -5
  199. package/lib-es/test/please-add-coverage.test.js.map +0 -1
  200. package/src/test/please-add-coverage.test.ts +0 -3
@@ -0,0 +1,502 @@
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
+ });
@@ -0,0 +1,17 @@
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
+ });
@@ -0,0 +1,16 @@
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
+ });
@@ -0,0 +1,112 @@
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
+ });