@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,233 +0,0 @@
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
- });
@@ -1,261 +0,0 @@
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
- });