@ledgerhq/coin-celo 1.2.2-nightly.3 → 1.3.0-nightly.5

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 +3 -6
  3. package/CHANGELOG.md +26 -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 +5 -2
  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/signOperation.d.ts.map +1 -1
  65. package/lib/bridge/signOperation.js +11 -3
  66. package/lib/bridge/signOperation.js.map +1 -1
  67. package/lib/bridge/synchronisation.d.ts.map +1 -1
  68. package/lib/bridge/synchronisation.js +7 -3
  69. package/lib/bridge/synchronisation.js.map +1 -1
  70. package/lib/config.d.ts.map +1 -1
  71. package/lib/config.js +8 -0
  72. package/lib/config.js.map +1 -1
  73. package/lib/constants.d.ts +6 -0
  74. package/lib/constants.d.ts.map +1 -0
  75. package/lib/constants.js +15 -0
  76. package/lib/constants.js.map +1 -0
  77. package/lib/types/types.d.ts +1 -0
  78. package/lib/types/types.d.ts.map +1 -1
  79. package/lib/types/types.js.map +1 -1
  80. package/lib-es/__tests__/bridge/buildOptimisticOperation.test.d.ts +2 -0
  81. package/lib-es/__tests__/bridge/buildOptimisticOperation.test.d.ts.map +1 -0
  82. package/lib-es/__tests__/bridge/buildOptimisticOperation.test.js +18 -0
  83. package/lib-es/__tests__/bridge/buildOptimisticOperation.test.js.map +1 -0
  84. package/lib-es/__tests__/bridge/buildTransaction.test.d.ts +2 -0
  85. package/lib-es/__tests__/bridge/buildTransaction.test.d.ts.map +1 -0
  86. package/lib-es/__tests__/bridge/buildTransaction.test.js +407 -0
  87. package/lib-es/__tests__/bridge/buildTransaction.test.js.map +1 -0
  88. package/lib-es/__tests__/bridge/createTransaction.test.d.ts +2 -0
  89. package/lib-es/__tests__/bridge/createTransaction.test.d.ts.map +1 -0
  90. package/lib-es/__tests__/bridge/createTransaction.test.js +17 -0
  91. package/lib-es/__tests__/bridge/createTransaction.test.js.map +1 -0
  92. package/lib-es/__tests__/bridge/deviceTransactionConfig.test.d.ts +2 -0
  93. package/lib-es/__tests__/bridge/deviceTransactionConfig.test.d.ts.map +1 -0
  94. package/lib-es/__tests__/bridge/deviceTransactionConfig.test.js +16 -0
  95. package/lib-es/__tests__/bridge/deviceTransactionConfig.test.js.map +1 -0
  96. package/lib-es/__tests__/bridge/estimateMaxSpendable.test.d.ts +2 -0
  97. package/lib-es/__tests__/bridge/estimateMaxSpendable.test.d.ts.map +1 -0
  98. package/lib-es/__tests__/bridge/estimateMaxSpendable.test.js +103 -0
  99. package/lib-es/__tests__/bridge/estimateMaxSpendable.test.js.map +1 -0
  100. package/lib-es/__tests__/bridge/getFeesForTransaction.test.d.ts +2 -0
  101. package/lib-es/__tests__/bridge/getFeesForTransaction.test.d.ts.map +1 -0
  102. package/lib-es/__tests__/bridge/getFeesForTransaction.test.js +206 -0
  103. package/lib-es/__tests__/bridge/getFeesForTransaction.test.js.map +1 -0
  104. package/lib-es/__tests__/bridge/getTransactionStatus.test.d.ts +2 -0
  105. package/lib-es/__tests__/bridge/getTransactionStatus.test.d.ts.map +1 -0
  106. package/lib-es/__tests__/bridge/getTransactionStatus.test.js +209 -0
  107. package/lib-es/__tests__/bridge/getTransactionStatus.test.js.map +1 -0
  108. package/lib-es/__tests__/bridge/logic.test.d.ts +2 -0
  109. package/lib-es/__tests__/bridge/logic.test.d.ts.map +1 -0
  110. package/lib-es/__tests__/bridge/logic.test.js +485 -0
  111. package/lib-es/__tests__/bridge/logic.test.js.map +1 -0
  112. package/lib-es/__tests__/bridge/prepareTransaction.test.d.ts +2 -0
  113. package/lib-es/__tests__/bridge/prepareTransaction.test.d.ts.map +1 -0
  114. package/lib-es/__tests__/bridge/prepareTransaction.test.js +234 -0
  115. package/lib-es/__tests__/bridge/prepareTransaction.test.js.map +1 -0
  116. package/lib-es/bridge/buildOptimisticOperation.d.ts.map +1 -1
  117. package/lib-es/bridge/buildOptimisticOperation.js +5 -2
  118. package/lib-es/bridge/buildOptimisticOperation.js.map +1 -1
  119. package/lib-es/bridge/buildTransaction.d.ts.map +1 -1
  120. package/lib-es/bridge/buildTransaction.js +29 -6
  121. package/lib-es/bridge/buildTransaction.js.map +1 -1
  122. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
  123. package/lib-es/bridge/estimateMaxSpendable.js +10 -2
  124. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
  125. package/lib-es/bridge/fixtures.d.ts +36 -0
  126. package/lib-es/bridge/fixtures.d.ts.map +1 -0
  127. package/lib-es/bridge/fixtures.js +89 -0
  128. package/lib-es/bridge/fixtures.js.map +1 -0
  129. package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -1
  130. package/lib-es/bridge/getFeesForTransaction.js +29 -5
  131. package/lib-es/bridge/getFeesForTransaction.js.map +1 -1
  132. package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
  133. package/lib-es/bridge/getTransactionStatus.js +18 -4
  134. package/lib-es/bridge/getTransactionStatus.js.map +1 -1
  135. package/lib-es/bridge/index.d.ts.map +1 -1
  136. package/lib-es/bridge/index.js.map +1 -1
  137. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
  138. package/lib-es/bridge/prepareTransaction.js +33 -4
  139. package/lib-es/bridge/prepareTransaction.js.map +1 -1
  140. package/lib-es/bridge/signOperation.d.ts.map +1 -1
  141. package/lib-es/bridge/signOperation.js +11 -3
  142. package/lib-es/bridge/signOperation.js.map +1 -1
  143. package/lib-es/bridge/synchronisation.d.ts.map +1 -1
  144. package/lib-es/bridge/synchronisation.js +7 -3
  145. package/lib-es/bridge/synchronisation.js.map +1 -1
  146. package/lib-es/config.d.ts.map +1 -1
  147. package/lib-es/config.js +8 -0
  148. package/lib-es/config.js.map +1 -1
  149. package/lib-es/constants.d.ts +6 -0
  150. package/lib-es/constants.d.ts.map +1 -0
  151. package/lib-es/constants.js +11 -0
  152. package/lib-es/constants.js.map +1 -0
  153. package/lib-es/types/types.d.ts +1 -0
  154. package/lib-es/types/types.d.ts.map +1 -1
  155. package/lib-es/types/types.js.map +1 -1
  156. package/package.json +14 -13
  157. package/src/__tests__/bridge/buildOptimisticOperation.test.ts +29 -0
  158. package/src/__tests__/bridge/buildTransaction.test.ts +502 -0
  159. package/src/__tests__/bridge/createTransaction.test.ts +17 -0
  160. package/src/__tests__/bridge/deviceTransactionConfig.test.ts +16 -0
  161. package/src/__tests__/bridge/estimateMaxSpendable.test.ts +112 -0
  162. package/src/__tests__/bridge/getFeesForTransaction.test.ts +233 -0
  163. package/src/__tests__/bridge/getTransactionStatus.test.ts +261 -0
  164. package/src/__tests__/bridge/logic.test.ts +538 -0
  165. package/src/__tests__/bridge/prepareTransaction.test.ts +261 -0
  166. package/src/bridge/buildOptimisticOperation.ts +6 -2
  167. package/src/bridge/buildTransaction.ts +38 -7
  168. package/src/bridge/estimateMaxSpendable.ts +18 -2
  169. package/src/bridge/fixtures.ts +103 -0
  170. package/src/bridge/getFeesForTransaction.ts +39 -5
  171. package/src/bridge/getTransactionStatus.ts +21 -4
  172. package/src/bridge/index.ts +0 -1
  173. package/src/bridge/prepareTransaction.ts +39 -6
  174. package/src/bridge/signOperation.ts +19 -4
  175. package/src/bridge/synchronisation.ts +10 -4
  176. package/src/config.ts +8 -0
  177. package/src/constants.ts +15 -0
  178. package/src/logic.ts +1 -1
  179. package/src/types/types.ts +1 -0
  180. package/lib/test/please-add-coverage.test.d.ts +0 -2
  181. package/lib/test/please-add-coverage.test.d.ts.map +0 -1
  182. package/lib/test/please-add-coverage.test.js +0 -6
  183. package/lib/test/please-add-coverage.test.js.map +0 -1
  184. package/lib-es/test/please-add-coverage.test.d.ts +0 -1
  185. package/lib-es/test/please-add-coverage.test.d.ts.map +0 -1
  186. package/lib-es/test/please-add-coverage.test.js +0 -5
  187. package/lib-es/test/please-add-coverage.test.js.map +0 -1
  188. package/src/test/please-add-coverage.test.ts +0 -3
@@ -0,0 +1,233 @@
1
+ import BigNumber from "bignumber.js";
2
+ import getFeesForTransaction from "../../bridge/getFeesForTransaction";
3
+ import { accountFixture, transactionFixture } from "../../bridge/fixtures";
4
+
5
+ const chainIdMock = jest.fn();
6
+ const nonceMock = jest.fn();
7
+ const voteMock = jest.fn(() => ({
8
+ txo: {
9
+ encodeABI: jest.fn(() => ({ data: "vote_data" })),
10
+ estimateGas: jest.fn(async () => 1),
11
+ },
12
+ }));
13
+ const revokeMock = jest.fn();
14
+ const voteSignerToAccountMock = jest.fn();
15
+
16
+ jest.mock("../../network/sdk", () => {
17
+ return {
18
+ celoKit: jest.fn(() => ({
19
+ contracts: {
20
+ getLockedGold: jest.fn(async () => ({
21
+ address: "address",
22
+ lock: jest.fn(() => ({
23
+ txo: {
24
+ encodeABI: jest.fn(() => ({ data: "lock_data" })),
25
+ estimateGas: jest.fn(async () => 2),
26
+ },
27
+ })),
28
+ unlock: jest.fn(() => ({
29
+ txo: {
30
+ encodeABI: jest.fn(() => ({ data: "unlock_data" })),
31
+ estimateGas: jest.fn(async () => 3),
32
+ },
33
+ })),
34
+ withdraw: jest.fn(() => ({
35
+ txo: {
36
+ encodeABI: jest.fn(() => ({ data: "withdraw_data" })),
37
+ estimateGas: jest.fn(async () => 3),
38
+ },
39
+ })),
40
+ vote: jest.fn(() => ({
41
+ txo: {
42
+ encodeABI: jest.fn(() => ({ data: "vote_data" })),
43
+ estimateGas: jest.fn(async () => 3),
44
+ },
45
+ })),
46
+ getAccountNonvotingLockedGold: jest.fn(() => BigNumber(0)),
47
+ })),
48
+ getElection: jest.fn(async () => ({
49
+ vote: voteMock,
50
+ revoke: revokeMock,
51
+ activate: jest.fn(() => ({
52
+ find: jest.fn(() => ({
53
+ txo: {
54
+ encodeABI: jest.fn(() => ({ data: "vote_data" })),
55
+ estimateGas: jest.fn(async () => 3),
56
+ },
57
+ })),
58
+ })),
59
+ address: "vote_address",
60
+ })),
61
+ getAccounts: jest.fn(async () => ({
62
+ voteSignerToAccount: voteSignerToAccountMock,
63
+ createAccount: jest.fn(() => ({
64
+ txo: {
65
+ encodeABI: jest.fn(() => ({ data: "register_data" })),
66
+ estimateGas: jest.fn(async () => 3),
67
+ },
68
+ })),
69
+ address: "register_address",
70
+ })),
71
+ getStableToken: jest.fn(async () => ({
72
+ address: "stable_token_address",
73
+ transfer: jest.fn(() => ({
74
+ txo: {
75
+ encodeABI: jest.fn(() => ({ data: "send_token_data" })),
76
+ },
77
+ })),
78
+ })),
79
+ getErc20: jest.fn(async () => ({
80
+ address: "erc20_token_address",
81
+ transfer: jest.fn(() => ({
82
+ txo: {
83
+ encodeABI: jest.fn(() => ({ data: "send_token_data" })),
84
+ },
85
+ })),
86
+ })),
87
+ },
88
+ connection: {
89
+ chainId: chainIdMock,
90
+ nonce: nonceMock,
91
+ estimateGasWithInflationFactor: jest.fn().mockReturnValue(3),
92
+ gasPrice: jest.fn(async () => BigNumber(2)),
93
+ },
94
+ })),
95
+ };
96
+ });
97
+
98
+ describe("getFeesForTransaction", () => {
99
+ it("should return the correct fees for a send transaction", async () => {
100
+ const fees = await getFeesForTransaction({
101
+ account: { ...accountFixture, balance: BigNumber(123), spendableBalance: BigNumber(123) },
102
+ transaction: transactionFixture,
103
+ });
104
+
105
+ expect(fees).toEqual(BigNumber(24));
106
+ });
107
+
108
+ it("should return the correct fees for a revoke transaction without revoked transactions", async () => {
109
+ revokeMock.mockClear();
110
+
111
+ revokeMock.mockReturnValue({
112
+ find: jest.fn(() => false),
113
+ });
114
+
115
+ const fees = await getFeesForTransaction({
116
+ account: { ...accountFixture, balance: BigNumber(123), spendableBalance: BigNumber(123) },
117
+ transaction: { ...transactionFixture, mode: "revoke" },
118
+ });
119
+
120
+ expect(fees).toEqual(BigNumber(0));
121
+ });
122
+
123
+ it("should return the correct fees for a revoke transaction with revoked transactions", async () => {
124
+ revokeMock.mockClear();
125
+
126
+ revokeMock.mockReturnValue({
127
+ find: jest.fn(() => ({
128
+ txo: {
129
+ encodeABI: jest.fn(() => ({ data: "revoke_data" })),
130
+ estimateGas: jest.fn(async () => 2),
131
+ },
132
+ })),
133
+ });
134
+
135
+ const fees = await getFeesForTransaction({
136
+ account: { ...accountFixture, balance: BigNumber(123), spendableBalance: BigNumber(123) },
137
+ transaction: { ...transactionFixture, mode: "revoke" },
138
+ });
139
+
140
+ expect(fees).toEqual(BigNumber(4));
141
+ });
142
+
143
+ it("should return the correct fees for a revoke transaction with revoked transactions and useAllAmount set to true", async () => {
144
+ revokeMock.mockClear();
145
+
146
+ revokeMock.mockReturnValue({
147
+ find: jest.fn(() => ({
148
+ txo: {
149
+ encodeABI: jest.fn(() => ({ data: "revoke_data" })),
150
+ estimateGas: jest.fn(async () => 2),
151
+ },
152
+ })),
153
+ });
154
+
155
+ const fees = await getFeesForTransaction({
156
+ account: {
157
+ ...accountFixture,
158
+ balance: BigNumber(123),
159
+ spendableBalance: BigNumber(123),
160
+ celoResources: {
161
+ ...accountFixture.celoResources,
162
+ votes: [
163
+ {
164
+ activatable: true,
165
+ amount: BigNumber(10),
166
+ index: 0,
167
+ revokable: true,
168
+ type: "active",
169
+ validatorGroup: transactionFixture.recipient,
170
+ },
171
+ ],
172
+ },
173
+ },
174
+ transaction: { ...transactionFixture, mode: "revoke", useAllAmount: true },
175
+ });
176
+
177
+ expect(fees).toEqual(BigNumber(4));
178
+ });
179
+
180
+ it("should return the correct fees for a withdraw transaction", async () => {
181
+ const fees = await getFeesForTransaction({
182
+ account: { ...accountFixture, balance: BigNumber(123), spendableBalance: BigNumber(123) },
183
+ transaction: { ...transactionFixture, mode: "withdraw" },
184
+ });
185
+
186
+ expect(fees).toEqual(BigNumber(6));
187
+ });
188
+
189
+ it("should return the correct fees for a vote transaction", async () => {
190
+ const fees = await getFeesForTransaction({
191
+ account: { ...accountFixture, balance: BigNumber(123), spendableBalance: BigNumber(123) },
192
+ transaction: { ...transactionFixture, mode: "vote" },
193
+ });
194
+
195
+ expect(fees).toEqual(BigNumber(2));
196
+ });
197
+
198
+ it("should return the correct fees for a lock transaction", async () => {
199
+ const fees = await getFeesForTransaction({
200
+ account: { ...accountFixture, balance: BigNumber(123), spendableBalance: BigNumber(123) },
201
+ transaction: { ...transactionFixture, mode: "lock" },
202
+ });
203
+
204
+ expect(fees).toEqual(BigNumber(4));
205
+ });
206
+
207
+ it("should return the correct fees for a unlock transaction", async () => {
208
+ const fees = await getFeesForTransaction({
209
+ account: { ...accountFixture, balance: BigNumber(123), spendableBalance: BigNumber(123) },
210
+ transaction: { ...transactionFixture, mode: "unlock" },
211
+ });
212
+
213
+ expect(fees).toEqual(BigNumber(6));
214
+ });
215
+
216
+ it("should return the correct fees for an activate transaction", async () => {
217
+ const fees = await getFeesForTransaction({
218
+ account: { ...accountFixture, balance: BigNumber(123), spendableBalance: BigNumber(123) },
219
+ transaction: { ...transactionFixture, mode: "activate" },
220
+ });
221
+
222
+ expect(fees).toEqual(BigNumber(6));
223
+ });
224
+
225
+ it("should return the correct fees for a register transaction", async () => {
226
+ const fees = await getFeesForTransaction({
227
+ account: { ...accountFixture, balance: BigNumber(123), spendableBalance: BigNumber(123) },
228
+ transaction: { ...transactionFixture, mode: "register" },
229
+ });
230
+
231
+ expect(fees).toEqual(BigNumber(6));
232
+ });
233
+ });
@@ -0,0 +1,261 @@
1
+ import { accountFixture, transactionFixture } from "../../bridge/fixtures";
2
+ import getTransactionStatus from "../../bridge/getTransactionStatus";
3
+ import BigNumber from "bignumber.js";
4
+
5
+ jest.mock("../../network/sdk", () => {
6
+ return {
7
+ celoKit: jest.fn(() => ({
8
+ contracts: {
9
+ getLockedGold: jest.fn(async () => ({
10
+ address: "address",
11
+ lock: jest.fn(() => ({
12
+ txo: {
13
+ encodeABI: jest.fn(() => ({ data: "lock_data" })),
14
+ estimateGas: jest.fn(async () => 2),
15
+ },
16
+ })),
17
+ unlock: jest.fn(() => ({
18
+ txo: {
19
+ encodeABI: jest.fn(() => ({ data: "unlock_data" })),
20
+ estimateGas: jest.fn(async () => 3),
21
+ },
22
+ })),
23
+ withdraw: jest.fn(() => ({
24
+ txo: {
25
+ encodeABI: jest.fn(() => ({ data: "withdraw_data" })),
26
+ estimateGas: jest.fn(async () => 3),
27
+ },
28
+ })),
29
+ vote: jest.fn(() => ({
30
+ txo: {
31
+ encodeABI: jest.fn(() => ({ data: "vote_data" })),
32
+ estimateGas: jest.fn(async () => 3),
33
+ },
34
+ })),
35
+ getAccountNonvotingLockedGold: jest.fn(() => BigNumber(100)),
36
+ })),
37
+ },
38
+ })),
39
+ };
40
+ });
41
+
42
+ describe("getTransactionStatus", () => {
43
+ it("should return an InvalidAddressBecauseDestinationIsAlsoSource error in case the recipient is also the sender", async () => {
44
+ const transactionStatus = await getTransactionStatus(
45
+ { ...accountFixture, balance: BigNumber(123), spendableBalance: BigNumber(123) },
46
+ {
47
+ ...transactionFixture,
48
+ recipient: accountFixture.freshAddress,
49
+ fees: BigNumber(2),
50
+ },
51
+ );
52
+
53
+ expect(transactionStatus.errors["recipient"].name).toEqual(
54
+ "InvalidAddressBecauseDestinationIsAlsoSource",
55
+ );
56
+ expect(transactionStatus.errors).not.toHaveProperty("fees");
57
+ expect(transactionStatus.errors).not.toHaveProperty("amount");
58
+ expect(Object.keys(transactionStatus.warnings).length).toEqual(0);
59
+ });
60
+
61
+ it("should return an FeeNotLoaded error in case the transaction is missing fees", async () => {
62
+ const transactionStatus = await getTransactionStatus(
63
+ { ...accountFixture, balance: BigNumber(123), spendableBalance: BigNumber(123) },
64
+ {
65
+ ...transactionFixture,
66
+ recipient: "0x79D5A290D7ba4b99322d91b577589e8d0BF87072",
67
+ },
68
+ );
69
+
70
+ expect(transactionStatus.errors["fees"].name).toEqual("FeeNotLoaded");
71
+ expect(transactionStatus.errors).not.toHaveProperty("recipient");
72
+ expect(transactionStatus.errors).not.toHaveProperty("amount");
73
+ expect(Object.keys(transactionStatus.warnings).length).toEqual(0);
74
+ });
75
+
76
+ it("should return an NotEnoughBalance error in case the transaction is more than the account balance", async () => {
77
+ const transactionStatus = await getTransactionStatus(
78
+ { ...accountFixture, balance: BigNumber(123), spendableBalance: BigNumber(123) },
79
+ {
80
+ ...transactionFixture,
81
+ recipient: "0x79D5A290D7ba4b99322d91b577589e8d0BF87072",
82
+ fees: BigNumber(2),
83
+ amount: BigNumber(88888),
84
+ },
85
+ );
86
+
87
+ expect(transactionStatus.errors["amount"].name).toEqual("NotEnoughBalance");
88
+ expect(transactionStatus.errors).not.toHaveProperty("recipient");
89
+ expect(transactionStatus.errors).not.toHaveProperty("fees");
90
+ expect(Object.keys(transactionStatus.warnings).length).toEqual(0);
91
+ });
92
+
93
+ it("should return an RecipientRequired error in case the transaction does not have a recipient address", async () => {
94
+ const transactionStatus = await getTransactionStatus(
95
+ { ...accountFixture, balance: BigNumber(123), spendableBalance: BigNumber(123) },
96
+ {
97
+ ...transactionFixture,
98
+ recipient: "",
99
+ fees: BigNumber(2),
100
+ },
101
+ );
102
+
103
+ expect(transactionStatus.errors["recipient"].name).toEqual("RecipientRequired");
104
+ expect(transactionStatus.errors).not.toHaveProperty("amount");
105
+ expect(transactionStatus.errors).not.toHaveProperty("fees");
106
+ expect(Object.keys(transactionStatus.warnings).length).toEqual(0);
107
+ });
108
+
109
+ it("should return an InvalidAddress error in case the transaction does not have a valid recipient address", async () => {
110
+ const transactionStatus = await getTransactionStatus(
111
+ { ...accountFixture, balance: BigNumber(123), spendableBalance: BigNumber(123) },
112
+ {
113
+ ...transactionFixture,
114
+ fees: BigNumber(2),
115
+ },
116
+ );
117
+
118
+ expect(transactionStatus.errors["recipient"].name).toEqual("InvalidAddress");
119
+ expect(transactionStatus.errors).not.toHaveProperty("amount");
120
+ expect(transactionStatus.errors).not.toHaveProperty("fees");
121
+ expect(Object.keys(transactionStatus.warnings).length).toEqual(0);
122
+ });
123
+
124
+ it("should return a CeloAllFundsWarning warning in case of a send or lock transaction is using all the balance above the safety buffer", async () => {
125
+ const transactionStatus = await getTransactionStatus(
126
+ {
127
+ ...accountFixture,
128
+ balance: BigNumber(10000000000000000),
129
+ spendableBalance: BigNumber(10000000000000000),
130
+ celoResources: {
131
+ ...accountFixture.celoResources,
132
+ lockedBalance: BigNumber(44444),
133
+ },
134
+ },
135
+ {
136
+ ...transactionFixture,
137
+ recipient: "0x79D5A290D7ba4b99322d91b577589e8d0BF87072",
138
+ amount: BigNumber(9000000000000000),
139
+ fees: BigNumber(2),
140
+ },
141
+ );
142
+
143
+ expect(transactionStatus.warnings["amount"].name).toEqual("CeloAllFundsWarning");
144
+ expect(transactionStatus.errors).not.toHaveProperty("amount");
145
+ expect(transactionStatus.errors).not.toHaveProperty("fees");
146
+ expect(transactionStatus.errors).not.toHaveProperty("recipient");
147
+ });
148
+
149
+ it("should not return any error or warning", async () => {
150
+ const transactionStatus = await getTransactionStatus(
151
+ {
152
+ ...accountFixture,
153
+ balance: BigNumber(10000000000000000),
154
+ spendableBalance: BigNumber(10000000000000000),
155
+ celoResources: {
156
+ ...accountFixture.celoResources,
157
+ lockedBalance: BigNumber(44444),
158
+ },
159
+ },
160
+ {
161
+ ...transactionFixture,
162
+ recipient: "0x79D5A290D7ba4b99322d91b577589e8d0BF87072",
163
+ fees: BigNumber(2),
164
+ useAllAmount: true,
165
+ mode: "vote",
166
+ },
167
+ );
168
+
169
+ expect(transactionStatus.errors).not.toHaveProperty("amount");
170
+ expect(transactionStatus.errors).not.toHaveProperty("fees");
171
+ expect(transactionStatus.errors).not.toHaveProperty("recipient");
172
+ expect(Object.keys(transactionStatus.warnings).length).toEqual(0);
173
+ });
174
+
175
+ it("should return an AmountRequired error", async () => {
176
+ const transactionStatus = await getTransactionStatus(
177
+ {
178
+ ...accountFixture,
179
+ balance: BigNumber(10000000000000000),
180
+ spendableBalance: BigNumber(10000000000000000),
181
+ celoResources: {
182
+ ...accountFixture.celoResources,
183
+ lockedBalance: BigNumber(44444),
184
+ },
185
+ },
186
+ {
187
+ ...transactionFixture,
188
+ recipient: "0x79D5A290D7ba4b99322d91b577589e8d0BF87072",
189
+ fees: BigNumber(2),
190
+ amount: BigNumber(0),
191
+ },
192
+ );
193
+
194
+ expect(transactionStatus.errors["amount"].name).toEqual("AmountRequired");
195
+ expect(transactionStatus.errors).not.toHaveProperty("fees");
196
+ expect(transactionStatus.errors).not.toHaveProperty("recipient");
197
+ expect(Object.keys(transactionStatus.warnings).length).toEqual(0);
198
+ });
199
+
200
+ it("should return an NotEnoughBalance error for a vote transaction where the amount is higher than the total non-voting locked balance", async () => {
201
+ const transactionStatus = await getTransactionStatus(
202
+ {
203
+ ...accountFixture,
204
+ balance: BigNumber(10000000000000000),
205
+ spendableBalance: BigNumber(10000000000000000),
206
+ celoResources: {
207
+ ...accountFixture.celoResources,
208
+ lockedBalance: BigNumber(44444),
209
+ },
210
+ },
211
+ {
212
+ ...transactionFixture,
213
+ recipient: "0x79D5A290D7ba4b99322d91b577589e8d0BF87072",
214
+ fees: BigNumber(2),
215
+ amount: BigNumber(200),
216
+ mode: "vote",
217
+ },
218
+ );
219
+
220
+ expect(transactionStatus.errors["amount"].name).toEqual("NotEnoughBalance");
221
+ expect(transactionStatus.errors).not.toHaveProperty("fees");
222
+ expect(transactionStatus.errors).not.toHaveProperty("recipient");
223
+ expect(Object.keys(transactionStatus.warnings).length).toEqual(0);
224
+ });
225
+
226
+ it("should return an NotEnoughBalance error for a revoke transaction where the amount is higher than the total non-voting locked balance", async () => {
227
+ const transactionStatus = await getTransactionStatus(
228
+ {
229
+ ...accountFixture,
230
+ balance: BigNumber(10000000000000000),
231
+ spendableBalance: BigNumber(10000000000000000),
232
+ celoResources: {
233
+ ...accountFixture.celoResources,
234
+ lockedBalance: BigNumber(44444),
235
+ votes: [
236
+ {
237
+ activatable: true,
238
+ amount: BigNumber(109),
239
+ index: 0,
240
+ revokable: true,
241
+ type: "active",
242
+ validatorGroup: transactionFixture.recipient,
243
+ },
244
+ ],
245
+ },
246
+ },
247
+ {
248
+ ...transactionFixture,
249
+ recipient: "0x79D5A290D7ba4b99322d91b577589e8d0BF87072",
250
+ useAllAmount: true,
251
+ fees: BigNumber(2),
252
+ mode: "revoke",
253
+ },
254
+ );
255
+
256
+ expect(transactionStatus.errors).not.toHaveProperty("amount");
257
+ expect(transactionStatus.errors).not.toHaveProperty("fees");
258
+ expect(transactionStatus.errors).not.toHaveProperty("recipient");
259
+ expect(Object.keys(transactionStatus.warnings).length).toEqual(0);
260
+ });
261
+ });