@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.
- package/.turbo/turbo-build.log +1 -1
- package/.unimportedrc.json +6 -3
- package/CHANGELOG.md +27 -35
- package/lib/bridge/buildOptimisticOperation.d.ts.map +1 -1
- package/lib/bridge/buildOptimisticOperation.js +2 -5
- package/lib/bridge/buildOptimisticOperation.js.map +1 -1
- package/lib/bridge/buildTransaction.d.ts.map +1 -1
- package/lib/bridge/buildTransaction.js +6 -29
- package/lib/bridge/buildTransaction.js.map +1 -1
- package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib/bridge/estimateMaxSpendable.js +1 -9
- package/lib/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib/bridge/getFeesForTransaction.d.ts.map +1 -1
- package/lib/bridge/getFeesForTransaction.js +5 -32
- package/lib/bridge/getFeesForTransaction.js.map +1 -1
- package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib/bridge/getTransactionStatus.js +4 -18
- package/lib/bridge/getTransactionStatus.js.map +1 -1
- package/lib/bridge/index.d.ts.map +1 -1
- package/lib/bridge/index.js.map +1 -1
- package/lib/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib/bridge/prepareTransaction.js +4 -33
- package/lib/bridge/prepareTransaction.js.map +1 -1
- package/lib/bridge/signOperation.d.ts.map +1 -1
- package/lib/bridge/signOperation.js +3 -11
- package/lib/bridge/signOperation.js.map +1 -1
- package/lib/bridge/synchronisation.d.ts.map +1 -1
- package/lib/bridge/synchronisation.js +3 -7
- package/lib/bridge/synchronisation.js.map +1 -1
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +0 -8
- package/lib/config.js.map +1 -1
- package/lib/test/please-add-coverage.test.d.ts +2 -0
- package/lib/test/please-add-coverage.test.d.ts.map +1 -0
- package/lib/test/please-add-coverage.test.js +6 -0
- package/lib/test/please-add-coverage.test.js.map +1 -0
- package/lib/types/types.d.ts +0 -1
- package/lib/types/types.d.ts.map +1 -1
- package/lib/types/types.js.map +1 -1
- package/lib-es/bridge/buildOptimisticOperation.d.ts.map +1 -1
- package/lib-es/bridge/buildOptimisticOperation.js +2 -5
- package/lib-es/bridge/buildOptimisticOperation.js.map +1 -1
- package/lib-es/bridge/buildTransaction.d.ts.map +1 -1
- package/lib-es/bridge/buildTransaction.js +6 -29
- package/lib-es/bridge/buildTransaction.js.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.js +2 -10
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -1
- package/lib-es/bridge/getFeesForTransaction.js +5 -29
- package/lib-es/bridge/getFeesForTransaction.js.map +1 -1
- package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib-es/bridge/getTransactionStatus.js +4 -18
- package/lib-es/bridge/getTransactionStatus.js.map +1 -1
- package/lib-es/bridge/index.d.ts.map +1 -1
- package/lib-es/bridge/index.js.map +1 -1
- package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib-es/bridge/prepareTransaction.js +4 -33
- package/lib-es/bridge/prepareTransaction.js.map +1 -1
- package/lib-es/bridge/signOperation.d.ts.map +1 -1
- package/lib-es/bridge/signOperation.js +3 -11
- package/lib-es/bridge/signOperation.js.map +1 -1
- package/lib-es/bridge/synchronisation.d.ts.map +1 -1
- package/lib-es/bridge/synchronisation.js +3 -7
- package/lib-es/bridge/synchronisation.js.map +1 -1
- package/lib-es/config.d.ts.map +1 -1
- package/lib-es/config.js +0 -8
- package/lib-es/config.js.map +1 -1
- package/lib-es/test/please-add-coverage.test.d.ts +1 -0
- package/lib-es/test/please-add-coverage.test.d.ts.map +1 -0
- package/lib-es/test/please-add-coverage.test.js +5 -0
- package/lib-es/test/please-add-coverage.test.js.map +1 -0
- package/lib-es/types/types.d.ts +0 -1
- package/lib-es/types/types.d.ts.map +1 -1
- package/lib-es/types/types.js.map +1 -1
- package/package.json +17 -18
- package/src/bridge/buildOptimisticOperation.ts +2 -6
- package/src/bridge/buildTransaction.ts +7 -38
- package/src/bridge/estimateMaxSpendable.ts +2 -18
- package/src/bridge/getFeesForTransaction.ts +5 -39
- package/src/bridge/getTransactionStatus.ts +4 -21
- package/src/bridge/index.ts +1 -0
- package/src/bridge/prepareTransaction.ts +6 -39
- package/src/bridge/signOperation.ts +4 -19
- package/src/bridge/synchronisation.ts +4 -10
- package/src/config.ts +0 -8
- package/src/logic.ts +1 -1
- package/src/test/please-add-coverage.test.ts +3 -0
- package/src/types/types.ts +0 -1
- package/lib/__tests__/bridge/buildOptimisticOperation.test.d.ts +0 -2
- package/lib/__tests__/bridge/buildOptimisticOperation.test.d.ts.map +0 -1
- package/lib/__tests__/bridge/buildOptimisticOperation.test.js +0 -23
- package/lib/__tests__/bridge/buildOptimisticOperation.test.js.map +0 -1
- package/lib/__tests__/bridge/buildTransaction.test.d.ts +0 -2
- package/lib/__tests__/bridge/buildTransaction.test.d.ts.map +0 -1
- package/lib/__tests__/bridge/buildTransaction.test.js +0 -412
- package/lib/__tests__/bridge/buildTransaction.test.js.map +0 -1
- package/lib/__tests__/bridge/createTransaction.test.d.ts +0 -2
- package/lib/__tests__/bridge/createTransaction.test.d.ts.map +0 -1
- package/lib/__tests__/bridge/createTransaction.test.js +0 -22
- package/lib/__tests__/bridge/createTransaction.test.js.map +0 -1
- package/lib/__tests__/bridge/deviceTransactionConfig.test.d.ts +0 -2
- package/lib/__tests__/bridge/deviceTransactionConfig.test.d.ts.map +0 -1
- package/lib/__tests__/bridge/deviceTransactionConfig.test.js +0 -21
- package/lib/__tests__/bridge/deviceTransactionConfig.test.js.map +0 -1
- package/lib/__tests__/bridge/estimateMaxSpendable.test.d.ts +0 -2
- package/lib/__tests__/bridge/estimateMaxSpendable.test.d.ts.map +0 -1
- package/lib/__tests__/bridge/estimateMaxSpendable.test.js +0 -108
- package/lib/__tests__/bridge/estimateMaxSpendable.test.js.map +0 -1
- package/lib/__tests__/bridge/getFeesForTransaction.test.d.ts +0 -2
- package/lib/__tests__/bridge/getFeesForTransaction.test.d.ts.map +0 -1
- package/lib/__tests__/bridge/getFeesForTransaction.test.js +0 -211
- package/lib/__tests__/bridge/getFeesForTransaction.test.js.map +0 -1
- package/lib/__tests__/bridge/getTransactionStatus.test.d.ts +0 -2
- package/lib/__tests__/bridge/getTransactionStatus.test.d.ts.map +0 -1
- package/lib/__tests__/bridge/getTransactionStatus.test.js +0 -214
- package/lib/__tests__/bridge/getTransactionStatus.test.js.map +0 -1
- package/lib/__tests__/bridge/logic.test.d.ts +0 -2
- package/lib/__tests__/bridge/logic.test.d.ts.map +0 -1
- package/lib/__tests__/bridge/logic.test.js +0 -490
- package/lib/__tests__/bridge/logic.test.js.map +0 -1
- package/lib/__tests__/bridge/prepareTransaction.test.d.ts +0 -2
- package/lib/__tests__/bridge/prepareTransaction.test.d.ts.map +0 -1
- package/lib/__tests__/bridge/prepareTransaction.test.js +0 -239
- package/lib/__tests__/bridge/prepareTransaction.test.js.map +0 -1
- package/lib/bridge/fixtures.d.ts +0 -36
- package/lib/bridge/fixtures.d.ts.map +0 -1
- package/lib/bridge/fixtures.js +0 -98
- package/lib/bridge/fixtures.js.map +0 -1
- package/lib/constants.d.ts +0 -6
- package/lib/constants.d.ts.map +0 -1
- package/lib/constants.js +0 -15
- package/lib/constants.js.map +0 -1
- package/lib-es/__tests__/bridge/buildOptimisticOperation.test.d.ts +0 -2
- package/lib-es/__tests__/bridge/buildOptimisticOperation.test.d.ts.map +0 -1
- package/lib-es/__tests__/bridge/buildOptimisticOperation.test.js +0 -18
- package/lib-es/__tests__/bridge/buildOptimisticOperation.test.js.map +0 -1
- package/lib-es/__tests__/bridge/buildTransaction.test.d.ts +0 -2
- package/lib-es/__tests__/bridge/buildTransaction.test.d.ts.map +0 -1
- package/lib-es/__tests__/bridge/buildTransaction.test.js +0 -407
- package/lib-es/__tests__/bridge/buildTransaction.test.js.map +0 -1
- package/lib-es/__tests__/bridge/createTransaction.test.d.ts +0 -2
- package/lib-es/__tests__/bridge/createTransaction.test.d.ts.map +0 -1
- package/lib-es/__tests__/bridge/createTransaction.test.js +0 -17
- package/lib-es/__tests__/bridge/createTransaction.test.js.map +0 -1
- package/lib-es/__tests__/bridge/deviceTransactionConfig.test.d.ts +0 -2
- package/lib-es/__tests__/bridge/deviceTransactionConfig.test.d.ts.map +0 -1
- package/lib-es/__tests__/bridge/deviceTransactionConfig.test.js +0 -16
- package/lib-es/__tests__/bridge/deviceTransactionConfig.test.js.map +0 -1
- package/lib-es/__tests__/bridge/estimateMaxSpendable.test.d.ts +0 -2
- package/lib-es/__tests__/bridge/estimateMaxSpendable.test.d.ts.map +0 -1
- package/lib-es/__tests__/bridge/estimateMaxSpendable.test.js +0 -103
- package/lib-es/__tests__/bridge/estimateMaxSpendable.test.js.map +0 -1
- package/lib-es/__tests__/bridge/getFeesForTransaction.test.d.ts +0 -2
- package/lib-es/__tests__/bridge/getFeesForTransaction.test.d.ts.map +0 -1
- package/lib-es/__tests__/bridge/getFeesForTransaction.test.js +0 -206
- package/lib-es/__tests__/bridge/getFeesForTransaction.test.js.map +0 -1
- package/lib-es/__tests__/bridge/getTransactionStatus.test.d.ts +0 -2
- package/lib-es/__tests__/bridge/getTransactionStatus.test.d.ts.map +0 -1
- package/lib-es/__tests__/bridge/getTransactionStatus.test.js +0 -209
- package/lib-es/__tests__/bridge/getTransactionStatus.test.js.map +0 -1
- package/lib-es/__tests__/bridge/logic.test.d.ts +0 -2
- package/lib-es/__tests__/bridge/logic.test.d.ts.map +0 -1
- package/lib-es/__tests__/bridge/logic.test.js +0 -485
- package/lib-es/__tests__/bridge/logic.test.js.map +0 -1
- package/lib-es/__tests__/bridge/prepareTransaction.test.d.ts +0 -2
- package/lib-es/__tests__/bridge/prepareTransaction.test.d.ts.map +0 -1
- package/lib-es/__tests__/bridge/prepareTransaction.test.js +0 -234
- package/lib-es/__tests__/bridge/prepareTransaction.test.js.map +0 -1
- package/lib-es/bridge/fixtures.d.ts +0 -36
- package/lib-es/bridge/fixtures.d.ts.map +0 -1
- package/lib-es/bridge/fixtures.js +0 -89
- package/lib-es/bridge/fixtures.js.map +0 -1
- package/lib-es/constants.d.ts +0 -6
- package/lib-es/constants.d.ts.map +0 -1
- package/lib-es/constants.js +0 -11
- package/lib-es/constants.js.map +0 -1
- package/src/__tests__/bridge/buildOptimisticOperation.test.ts +0 -29
- package/src/__tests__/bridge/buildTransaction.test.ts +0 -502
- package/src/__tests__/bridge/createTransaction.test.ts +0 -17
- package/src/__tests__/bridge/deviceTransactionConfig.test.ts +0 -16
- package/src/__tests__/bridge/estimateMaxSpendable.test.ts +0 -112
- package/src/__tests__/bridge/getFeesForTransaction.test.ts +0 -233
- package/src/__tests__/bridge/getTransactionStatus.test.ts +0 -261
- package/src/__tests__/bridge/logic.test.ts +0 -538
- package/src/__tests__/bridge/prepareTransaction.test.ts +0 -261
- package/src/bridge/fixtures.ts +0 -103
- 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
|
-
});
|