@ledgerhq/coin-aptos 1.9.6-next.0 → 2.0.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.
- package/.turbo/turbo-build.log +1 -1
- package/.unimportedrc.json +18 -6
- package/CHANGELOG.md +19 -4
- package/jest.integ.config.js +8 -0
- package/lib/__tests__/api/index.integ.test.d.ts +2 -0
- package/lib/__tests__/api/index.integ.test.d.ts.map +1 -0
- package/lib/__tests__/api/index.integ.test.js +22 -0
- package/lib/__tests__/api/index.integ.test.js.map +1 -0
- package/lib/__tests__/api/index.test.js +48 -404
- package/lib/__tests__/api/index.test.js.map +1 -1
- package/lib/__tests__/bridge/broadcast.test.js +5 -5
- package/lib/__tests__/bridge/broadcast.test.js.map +1 -1
- package/lib/__tests__/bridge/buildTransaction.test.js +60 -5
- package/lib/__tests__/bridge/buildTransaction.test.js.map +1 -1
- package/lib/__tests__/bridge/getFeesForTransaction.test.js +115 -14
- package/lib/__tests__/bridge/getFeesForTransaction.test.js.map +1 -1
- package/lib/__tests__/bridge/getTransactionStatus.test.js +175 -37
- package/lib/__tests__/bridge/getTransactionStatus.test.js.map +1 -1
- package/lib/__tests__/bridge/logic.test.js +889 -115
- package/lib/__tests__/bridge/logic.test.js.map +1 -1
- package/lib/__tests__/bridge/prepareTransaction.test.js +3 -3
- package/lib/__tests__/bridge/prepareTransaction.test.js.map +1 -1
- package/lib/__tests__/bridge/signOperation.test.js +131 -4
- package/lib/__tests__/bridge/signOperation.test.js.map +1 -1
- package/lib/__tests__/bridge/synchronisation.test.js +1215 -68
- package/lib/__tests__/bridge/synchronisation.test.js.map +1 -1
- package/lib/__tests__/network/client.test.d.ts +2 -0
- package/lib/__tests__/network/client.test.d.ts.map +1 -0
- package/lib/__tests__/network/client.test.js +478 -0
- package/lib/__tests__/network/client.test.js.map +1 -0
- package/lib/api/index.d.ts +4 -30
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +26 -170
- package/lib/api/index.js.map +1 -1
- package/lib/bridge/bridge.fixture.d.ts +2 -0
- package/lib/bridge/bridge.fixture.d.ts.map +1 -1
- package/lib/bridge/bridge.fixture.js +85 -13
- package/lib/bridge/bridge.fixture.js.map +1 -1
- package/lib/bridge/broadcast.d.ts +3 -2
- package/lib/bridge/broadcast.d.ts.map +1 -1
- package/lib/bridge/broadcast.js +4 -3
- package/lib/bridge/broadcast.js.map +1 -1
- package/lib/bridge/buildTransaction.d.ts +1 -1
- package/lib/bridge/buildTransaction.d.ts.map +1 -1
- package/lib/bridge/buildTransaction.js +29 -3
- package/lib/bridge/buildTransaction.js.map +1 -1
- package/lib/bridge/estimateMaxSpendable.js +3 -3
- package/lib/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib/bridge/getFeesForTransaction.d.ts +1 -1
- package/lib/bridge/getFeesForTransaction.d.ts.map +1 -1
- package/lib/bridge/getFeesForTransaction.js +12 -7
- package/lib/bridge/getFeesForTransaction.js.map +1 -1
- package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib/bridge/getTransactionStatus.js +28 -14
- package/lib/bridge/getTransactionStatus.js.map +1 -1
- package/lib/bridge/index.d.ts +1 -1
- package/lib/bridge/index.d.ts.map +1 -1
- package/lib/bridge/logic.d.ts +13 -8
- package/lib/bridge/logic.d.ts.map +1 -1
- package/lib/bridge/logic.js +152 -54
- package/lib/bridge/logic.js.map +1 -1
- package/lib/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib/bridge/prepareTransaction.js +4 -4
- package/lib/bridge/prepareTransaction.js.map +1 -1
- package/lib/bridge/signOperation.d.ts.map +1 -1
- package/lib/bridge/signOperation.js +20 -6
- package/lib/bridge/signOperation.js.map +1 -1
- package/lib/bridge/synchronisation.d.ts +15 -0
- package/lib/bridge/synchronisation.d.ts.map +1 -1
- package/lib/bridge/synchronisation.js +129 -6
- package/lib/bridge/synchronisation.js.map +1 -1
- package/lib/config.d.ts +13 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +9 -0
- package/lib/config.js.map +1 -0
- package/lib/constants.d.ts +5 -1
- package/lib/constants.d.ts.map +1 -1
- package/lib/constants.js +6 -2
- package/lib/constants.js.map +1 -1
- package/lib/network/client.d.ts +34 -0
- package/lib/network/client.d.ts.map +1 -0
- package/lib/network/client.js +213 -0
- package/lib/network/client.js.map +1 -0
- package/lib/network/graphql/queries.d.ts.map +1 -0
- package/lib/{api → network}/graphql/queries.js +6 -6
- package/lib/network/graphql/queries.js.map +1 -0
- package/lib/{api → network}/graphql/types.d.ts +9 -9
- package/lib/network/graphql/types.d.ts.map +1 -0
- package/lib/{api → network}/graphql/types.js.map +1 -1
- package/lib/network/index.d.ts +2 -1
- package/lib/network/index.d.ts.map +1 -1
- package/lib/network/index.js +15 -0
- package/lib/network/index.js.map +1 -1
- package/lib/test/bot-specs.d.ts.map +1 -1
- package/lib/test/bot-specs.js +40 -1
- package/lib/test/bot-specs.js.map +1 -1
- package/lib/test/bridgeDatasetTest.d.ts.map +1 -1
- package/lib/test/bridgeDatasetTest.js +44 -62
- package/lib/test/bridgeDatasetTest.js.map +1 -1
- package/lib/test/speculos-deviceActions.d.ts +1 -0
- package/lib/test/speculos-deviceActions.d.ts.map +1 -1
- package/lib/test/speculos-deviceActions.js +37 -5
- package/lib/test/speculos-deviceActions.js.map +1 -1
- package/lib/types/assets.d.ts +3 -0
- package/lib/types/assets.d.ts.map +1 -0
- package/lib/types/assets.js +3 -0
- package/lib/types/assets.js.map +1 -0
- package/lib/types/index.d.ts +18 -7
- package/lib/types/index.d.ts.map +1 -1
- package/lib-es/__tests__/api/index.integ.test.d.ts +2 -0
- package/lib-es/__tests__/api/index.integ.test.d.ts.map +1 -0
- package/lib-es/__tests__/api/index.integ.test.js +20 -0
- package/lib-es/__tests__/api/index.integ.test.js.map +1 -0
- package/lib-es/__tests__/api/index.test.js +52 -408
- package/lib-es/__tests__/api/index.test.js.map +1 -1
- package/lib-es/__tests__/bridge/broadcast.test.js +2 -2
- package/lib-es/__tests__/bridge/broadcast.test.js.map +1 -1
- package/lib-es/__tests__/bridge/buildTransaction.test.js +60 -5
- package/lib-es/__tests__/bridge/buildTransaction.test.js.map +1 -1
- package/lib-es/__tests__/bridge/getFeesForTransaction.test.js +112 -11
- package/lib-es/__tests__/bridge/getFeesForTransaction.test.js.map +1 -1
- package/lib-es/__tests__/bridge/getTransactionStatus.test.js +177 -39
- package/lib-es/__tests__/bridge/getTransactionStatus.test.js.map +1 -1
- package/lib-es/__tests__/bridge/logic.test.js +891 -117
- package/lib-es/__tests__/bridge/logic.test.js.map +1 -1
- package/lib-es/__tests__/bridge/prepareTransaction.test.js +2 -2
- package/lib-es/__tests__/bridge/prepareTransaction.test.js.map +1 -1
- package/lib-es/__tests__/bridge/signOperation.test.js +131 -4
- package/lib-es/__tests__/bridge/signOperation.test.js.map +1 -1
- package/lib-es/__tests__/bridge/synchronisation.test.js +1213 -69
- package/lib-es/__tests__/bridge/synchronisation.test.js.map +1 -1
- package/lib-es/__tests__/network/client.test.d.ts +2 -0
- package/lib-es/__tests__/network/client.test.d.ts.map +1 -0
- package/lib-es/__tests__/network/client.test.js +473 -0
- package/lib-es/__tests__/network/client.test.js.map +1 -0
- package/lib-es/api/index.d.ts +4 -30
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +24 -168
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/bridge/bridge.fixture.d.ts +2 -0
- package/lib-es/bridge/bridge.fixture.d.ts.map +1 -1
- package/lib-es/bridge/bridge.fixture.js +82 -12
- package/lib-es/bridge/bridge.fixture.js.map +1 -1
- package/lib-es/bridge/broadcast.d.ts +3 -2
- package/lib-es/bridge/broadcast.d.ts.map +1 -1
- package/lib-es/bridge/broadcast.js +4 -3
- package/lib-es/bridge/broadcast.js.map +1 -1
- package/lib-es/bridge/buildTransaction.d.ts +1 -1
- package/lib-es/bridge/buildTransaction.d.ts.map +1 -1
- package/lib-es/bridge/buildTransaction.js +30 -4
- package/lib-es/bridge/buildTransaction.js.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.js +2 -2
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib-es/bridge/getFeesForTransaction.d.ts +1 -1
- package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -1
- package/lib-es/bridge/getFeesForTransaction.js +13 -8
- 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 +28 -14
- package/lib-es/bridge/getTransactionStatus.js.map +1 -1
- package/lib-es/bridge/index.d.ts +1 -1
- package/lib-es/bridge/index.d.ts.map +1 -1
- package/lib-es/bridge/logic.d.ts +13 -8
- package/lib-es/bridge/logic.d.ts.map +1 -1
- package/lib-es/bridge/logic.js +146 -52
- package/lib-es/bridge/logic.js.map +1 -1
- package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib-es/bridge/prepareTransaction.js +3 -3
- 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 +18 -4
- package/lib-es/bridge/signOperation.js.map +1 -1
- package/lib-es/bridge/synchronisation.d.ts +15 -0
- package/lib-es/bridge/synchronisation.d.ts.map +1 -1
- package/lib-es/bridge/synchronisation.js +124 -4
- package/lib-es/bridge/synchronisation.js.map +1 -1
- package/lib-es/config.d.ts +13 -0
- package/lib-es/config.d.ts.map +1 -0
- package/lib-es/config.js +4 -0
- package/lib-es/config.js.map +1 -0
- package/lib-es/constants.d.ts +5 -1
- package/lib-es/constants.d.ts.map +1 -1
- package/lib-es/constants.js +5 -1
- package/lib-es/constants.js.map +1 -1
- package/lib-es/network/client.d.ts +34 -0
- package/lib-es/network/client.d.ts.map +1 -0
- package/lib-es/network/client.js +206 -0
- package/lib-es/network/client.js.map +1 -0
- package/lib-es/network/graphql/queries.d.ts.map +1 -0
- package/lib-es/{api → network}/graphql/queries.js +6 -6
- package/lib-es/network/graphql/queries.js.map +1 -0
- package/lib-es/{api → network}/graphql/types.d.ts +9 -9
- package/lib-es/network/graphql/types.d.ts.map +1 -0
- package/lib-es/{api → network}/graphql/types.js.map +1 -1
- package/lib-es/network/index.d.ts +2 -1
- package/lib-es/network/index.d.ts.map +1 -1
- package/lib-es/network/index.js +1 -0
- package/lib-es/network/index.js.map +1 -1
- package/lib-es/test/bot-specs.d.ts.map +1 -1
- package/lib-es/test/bot-specs.js +41 -2
- package/lib-es/test/bot-specs.js.map +1 -1
- package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -1
- package/lib-es/test/bridgeDatasetTest.js +44 -59
- package/lib-es/test/bridgeDatasetTest.js.map +1 -1
- package/lib-es/test/speculos-deviceActions.d.ts +1 -0
- package/lib-es/test/speculos-deviceActions.d.ts.map +1 -1
- package/lib-es/test/speculos-deviceActions.js +36 -4
- package/lib-es/test/speculos-deviceActions.js.map +1 -1
- package/lib-es/types/assets.d.ts +3 -0
- package/lib-es/types/assets.d.ts.map +1 -0
- package/lib-es/types/assets.js +2 -0
- package/lib-es/types/assets.js.map +1 -0
- package/lib-es/types/index.d.ts +18 -7
- package/lib-es/types/index.d.ts.map +1 -1
- package/package.json +10 -8
- package/src/__tests__/api/index.integ.test.ts +24 -0
- package/src/__tests__/api/index.test.ts +58 -477
- package/src/__tests__/bridge/broadcast.test.ts +2 -2
- package/src/__tests__/bridge/buildTransaction.test.ts +87 -5
- package/src/__tests__/bridge/getFeesForTransaction.test.ts +146 -11
- package/src/__tests__/bridge/getTransactionStatus.test.ts +217 -38
- package/src/__tests__/bridge/logic.test.ts +922 -118
- package/src/__tests__/bridge/prepareTransaction.test.ts +2 -2
- package/src/__tests__/bridge/signOperation.test.ts +147 -5
- package/src/__tests__/bridge/synchronisation.test.ts +1265 -71
- package/src/__tests__/network/client.test.ts +569 -0
- package/src/api/index.ts +30 -223
- package/src/bridge/bridge.fixture.ts +91 -12
- package/src/bridge/broadcast.ts +7 -7
- package/src/bridge/buildTransaction.ts +40 -7
- package/src/bridge/estimateMaxSpendable.ts +2 -2
- package/src/bridge/getFeesForTransaction.ts +15 -10
- package/src/bridge/getTransactionStatus.ts +35 -13
- package/src/bridge/index.ts +1 -1
- package/src/bridge/logic.ts +202 -63
- package/src/bridge/prepareTransaction.ts +5 -3
- package/src/bridge/signOperation.ts +20 -4
- package/src/bridge/synchronisation.ts +171 -4
- package/src/config.ts +19 -0
- package/src/constants.ts +12 -1
- package/src/network/client.ts +265 -0
- package/src/{api → network}/graphql/queries.ts +6 -6
- package/src/{api → network}/graphql/types.ts +9 -9
- package/src/network/index.ts +2 -1
- package/src/test/bot-specs.ts +63 -3
- package/src/test/bridgeDatasetTest.ts +46 -59
- package/src/test/speculos-deviceActions.ts +40 -4
- package/src/types/assets.ts +3 -0
- package/src/types/index.ts +15 -1
- package/lib/api/graphql/queries.d.ts.map +0 -1
- package/lib/api/graphql/queries.js.map +0 -1
- package/lib/api/graphql/types.d.ts.map +0 -1
- package/lib-es/api/graphql/queries.d.ts.map +0 -1
- package/lib-es/api/graphql/queries.js.map +0 -1
- package/lib-es/api/graphql/types.d.ts.map +0 -1
- /package/lib/{api → network}/graphql/queries.d.ts +0 -0
- /package/lib/{api → network}/graphql/types.js +0 -0
- /package/lib-es/{api → network}/graphql/queries.d.ts +0 -0
- /package/lib-es/{api → network}/graphql/types.js +0 -0
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import BigNumber from "bignumber.js";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
createFixtureAccount,
|
|
4
|
+
createFixtureAccountWithSubAccount,
|
|
5
|
+
createFixtureTransaction,
|
|
6
|
+
createFixtureTransactionWithSubAccount,
|
|
7
|
+
} from "../../bridge/bridge.fixture";
|
|
3
8
|
import * as getFeesForTransaction from "../../bridge/getFeesForTransaction";
|
|
4
|
-
import { AptosAPI } from "../../
|
|
9
|
+
import { AptosAPI } from "../../network";
|
|
5
10
|
|
|
6
11
|
let simulateTransaction = jest.fn();
|
|
7
12
|
|
|
8
|
-
jest.mock("../../
|
|
13
|
+
jest.mock("../../network", () => {
|
|
9
14
|
return {
|
|
10
15
|
AptosAPI: function () {
|
|
11
16
|
return {
|
|
@@ -24,16 +29,18 @@ jest.mock("@aptos-labs/ts-sdk", () => {
|
|
|
24
29
|
};
|
|
25
30
|
});
|
|
26
31
|
|
|
27
|
-
jest.
|
|
28
|
-
return {
|
|
29
|
-
DEFAULT_GAS: 201,
|
|
30
|
-
DEFAULT_GAS_PRICE: 101,
|
|
31
|
-
ESTIMATE_GAS_MUL: 1,
|
|
32
|
-
normalizeTransactionOptions: jest.fn(),
|
|
33
|
-
};
|
|
34
|
-
});
|
|
32
|
+
const mockedGetTokenAccount = jest.fn();
|
|
35
33
|
|
|
36
34
|
describe("getFeesForTransaction Test", () => {
|
|
35
|
+
beforeEach(() => {
|
|
36
|
+
jest.mock("../../bridge/logic", () => ({
|
|
37
|
+
DEFAULT_GAS: 201,
|
|
38
|
+
DEFAULT_GAS_PRICE: 101,
|
|
39
|
+
ESTIMATE_GAS_MUL: 1,
|
|
40
|
+
normalizeTransactionOptions: jest.fn(),
|
|
41
|
+
getTokenAccount: mockedGetTokenAccount,
|
|
42
|
+
}));
|
|
43
|
+
});
|
|
37
44
|
describe("when using getFee", () => {
|
|
38
45
|
describe("with vm_status as INSUFFICIENT_BALANCE", () => {
|
|
39
46
|
it("should return a fee estimation object", async () => {
|
|
@@ -46,6 +53,7 @@ describe("getFeesForTransaction Test", () => {
|
|
|
46
53
|
gas_unit_price: "102",
|
|
47
54
|
},
|
|
48
55
|
]);
|
|
56
|
+
mockedGetTokenAccount.mockReturnValue(undefined);
|
|
49
57
|
|
|
50
58
|
const account = createFixtureAccount();
|
|
51
59
|
const transaction = createFixtureTransaction();
|
|
@@ -68,6 +76,40 @@ describe("getFeesForTransaction Test", () => {
|
|
|
68
76
|
|
|
69
77
|
expect(result).toEqual(expected);
|
|
70
78
|
});
|
|
79
|
+
|
|
80
|
+
it("should return a fee estimation object for the token transaction", async () => {
|
|
81
|
+
simulateTransaction = jest.fn(() => [
|
|
82
|
+
{
|
|
83
|
+
success: true,
|
|
84
|
+
vm_status: [],
|
|
85
|
+
expiration_timestamp_secs: 5,
|
|
86
|
+
gas_used: "202",
|
|
87
|
+
gas_unit_price: "102",
|
|
88
|
+
},
|
|
89
|
+
]);
|
|
90
|
+
mockedGetTokenAccount.mockReturnValue(undefined);
|
|
91
|
+
|
|
92
|
+
const account = createFixtureAccountWithSubAccount("coin");
|
|
93
|
+
const transaction = createFixtureTransactionWithSubAccount();
|
|
94
|
+
const aptosClient = new AptosAPI(account.currency.id);
|
|
95
|
+
|
|
96
|
+
transaction.amount = new BigNumber(1);
|
|
97
|
+
account.xpub = "xpub";
|
|
98
|
+
account.spendableBalance = new BigNumber(100000000);
|
|
99
|
+
|
|
100
|
+
const result = await getFeesForTransaction.getFee(account, transaction, aptosClient);
|
|
101
|
+
|
|
102
|
+
const expected = {
|
|
103
|
+
fees: new BigNumber(20604),
|
|
104
|
+
estimate: {
|
|
105
|
+
maxGasAmount: "202",
|
|
106
|
+
gasUnitPrice: "102",
|
|
107
|
+
},
|
|
108
|
+
errors: {},
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
expect(result).toEqual(expected);
|
|
112
|
+
});
|
|
71
113
|
});
|
|
72
114
|
|
|
73
115
|
describe("with vm_status as DUMMY_STATE", () => {
|
|
@@ -81,6 +123,7 @@ describe("getFeesForTransaction Test", () => {
|
|
|
81
123
|
gas_unit_price: "100",
|
|
82
124
|
},
|
|
83
125
|
]);
|
|
126
|
+
mockedGetTokenAccount.mockReturnValue(undefined);
|
|
84
127
|
|
|
85
128
|
const account = createFixtureAccount();
|
|
86
129
|
const transaction = createFixtureTransaction();
|
|
@@ -95,6 +138,44 @@ describe("getFeesForTransaction Test", () => {
|
|
|
95
138
|
}).rejects.toThrow("Simulation failed with following error: DUMMY_STATE");
|
|
96
139
|
});
|
|
97
140
|
});
|
|
141
|
+
|
|
142
|
+
describe("with vm_status as MAX_GAS_UNITS_BELOW_MIN_TRANSACTION_GAS_UNITS", () => {
|
|
143
|
+
it("should return a fee estimation object with GasInsuficeinetBalance error", async () => {
|
|
144
|
+
simulateTransaction = jest.fn(() => [
|
|
145
|
+
{
|
|
146
|
+
success: false,
|
|
147
|
+
vm_status: ["MAX_GAS_UNITS_BELOW_MIN_TRANSACTION_GAS_UNITS"],
|
|
148
|
+
expiration_timestamp_secs: 5,
|
|
149
|
+
gas_used: "0",
|
|
150
|
+
gas_unit_price: "100",
|
|
151
|
+
},
|
|
152
|
+
]);
|
|
153
|
+
mockedGetTokenAccount.mockReturnValue(undefined);
|
|
154
|
+
|
|
155
|
+
const account = createFixtureAccountWithSubAccount("coin");
|
|
156
|
+
const transaction = createFixtureTransactionWithSubAccount();
|
|
157
|
+
const aptosClient = new AptosAPI(account.currency.id);
|
|
158
|
+
|
|
159
|
+
transaction.amount = new BigNumber(1);
|
|
160
|
+
account.xpub = "xpub";
|
|
161
|
+
account.spendableBalance = new BigNumber(100000000);
|
|
162
|
+
|
|
163
|
+
const result = await getFeesForTransaction.getFee(account, transaction, aptosClient);
|
|
164
|
+
|
|
165
|
+
const expected = {
|
|
166
|
+
fees: new BigNumber(0),
|
|
167
|
+
estimate: {
|
|
168
|
+
maxGasAmount: "0",
|
|
169
|
+
gasUnitPrice: "100",
|
|
170
|
+
},
|
|
171
|
+
errors: {
|
|
172
|
+
maxGasAmount: "GasInsufficientBalance",
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
expect(result).toEqual(expected);
|
|
177
|
+
});
|
|
178
|
+
});
|
|
98
179
|
});
|
|
99
180
|
|
|
100
181
|
describe("when using getEstimatedGas", () => {
|
|
@@ -109,6 +190,7 @@ describe("getFeesForTransaction Test", () => {
|
|
|
109
190
|
gas_unit_price: "102",
|
|
110
191
|
},
|
|
111
192
|
]);
|
|
193
|
+
mockedGetTokenAccount.mockReturnValue(undefined);
|
|
112
194
|
|
|
113
195
|
const account = createFixtureAccount();
|
|
114
196
|
const transaction = createFixtureTransaction();
|
|
@@ -152,6 +234,8 @@ describe("getFeesForTransaction Test", () => {
|
|
|
152
234
|
gas_unit_price: "102",
|
|
153
235
|
},
|
|
154
236
|
]);
|
|
237
|
+
mockedGetTokenAccount.mockReturnValue(undefined);
|
|
238
|
+
|
|
155
239
|
const account = createFixtureAccount();
|
|
156
240
|
account.xpub = "xpub";
|
|
157
241
|
const transaction = createFixtureTransaction();
|
|
@@ -186,4 +270,55 @@ describe("getFeesForTransaction Test", () => {
|
|
|
186
270
|
});
|
|
187
271
|
});
|
|
188
272
|
});
|
|
273
|
+
|
|
274
|
+
describe("when key is in cache from a token account", () => {
|
|
275
|
+
beforeEach(() => {
|
|
276
|
+
jest.clearAllMocks();
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it("should return cached fee", async () => {
|
|
280
|
+
simulateTransaction = jest.fn(() => [
|
|
281
|
+
{
|
|
282
|
+
success: true,
|
|
283
|
+
vm_status: [],
|
|
284
|
+
expiration_timestamp_secs: 5,
|
|
285
|
+
gas_used: "202",
|
|
286
|
+
gas_unit_price: "102",
|
|
287
|
+
},
|
|
288
|
+
]);
|
|
289
|
+
mockedGetTokenAccount.mockReturnValue(undefined);
|
|
290
|
+
|
|
291
|
+
const account = createFixtureAccountWithSubAccount("coin");
|
|
292
|
+
account.xpub = "xpub";
|
|
293
|
+
const transaction = createFixtureTransactionWithSubAccount();
|
|
294
|
+
const aptosClient = new AptosAPI(account.currency.id);
|
|
295
|
+
|
|
296
|
+
transaction.amount = new BigNumber(10);
|
|
297
|
+
|
|
298
|
+
const result1 = await getFeesForTransaction.getEstimatedGas(
|
|
299
|
+
account,
|
|
300
|
+
transaction,
|
|
301
|
+
aptosClient,
|
|
302
|
+
);
|
|
303
|
+
const result2 = await getFeesForTransaction.getEstimatedGas(
|
|
304
|
+
account,
|
|
305
|
+
transaction,
|
|
306
|
+
aptosClient,
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
expect(simulateTransaction.mock.calls).toHaveLength(1);
|
|
310
|
+
|
|
311
|
+
const expected = {
|
|
312
|
+
errors: {},
|
|
313
|
+
estimate: {
|
|
314
|
+
gasUnitPrice: "102",
|
|
315
|
+
maxGasAmount: "202",
|
|
316
|
+
},
|
|
317
|
+
fees: new BigNumber("20604"),
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
expect(result1).toEqual(expected);
|
|
321
|
+
expect(result2).toEqual(expected);
|
|
322
|
+
});
|
|
323
|
+
});
|
|
189
324
|
});
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import BigNumber from "bignumber.js";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
createFixtureAccount,
|
|
4
|
+
createFixtureAccountWithSubAccount,
|
|
5
|
+
createFixtureTransaction,
|
|
6
|
+
createFixtureTransactionWithSubAccount,
|
|
7
|
+
} from "../../bridge/bridge.fixture";
|
|
3
8
|
import getTransactionStatus from "../../bridge/getTransactionStatus";
|
|
4
9
|
import {
|
|
5
10
|
AmountRequired,
|
|
@@ -7,15 +12,16 @@ import {
|
|
|
7
12
|
InvalidAddress,
|
|
8
13
|
InvalidAddressBecauseDestinationIsAlsoSource,
|
|
9
14
|
NotEnoughBalance,
|
|
15
|
+
NotEnoughBalanceFees,
|
|
10
16
|
RecipientRequired,
|
|
11
17
|
} from "@ledgerhq/errors";
|
|
12
18
|
|
|
13
19
|
describe("getTransactionStatus Test", () => {
|
|
14
|
-
it("should return
|
|
20
|
+
it("should return error for AmountRequired", async () => {
|
|
15
21
|
const account = createFixtureAccount();
|
|
16
22
|
const transaction = createFixtureTransaction();
|
|
17
23
|
|
|
18
|
-
transaction.fees =
|
|
24
|
+
transaction.fees = BigNumber(2);
|
|
19
25
|
transaction.recipient = "0x" + "0".repeat(64);
|
|
20
26
|
|
|
21
27
|
const result = await getTransactionStatus(account, transaction);
|
|
@@ -25,21 +31,21 @@ describe("getTransactionStatus Test", () => {
|
|
|
25
31
|
amount: new AmountRequired(),
|
|
26
32
|
},
|
|
27
33
|
warnings: {},
|
|
28
|
-
estimatedFees:
|
|
29
|
-
amount:
|
|
30
|
-
totalSpent:
|
|
34
|
+
estimatedFees: BigNumber(2),
|
|
35
|
+
amount: BigNumber(0),
|
|
36
|
+
totalSpent: BigNumber(2),
|
|
31
37
|
};
|
|
32
38
|
|
|
33
39
|
expect(result).toEqual(expected);
|
|
34
40
|
});
|
|
35
41
|
|
|
36
|
-
it("should return
|
|
42
|
+
it("should return error for FeeNotLoaded", async () => {
|
|
37
43
|
const account = createFixtureAccount();
|
|
38
|
-
account.
|
|
44
|
+
account.spendableBalance = BigNumber(10);
|
|
39
45
|
|
|
40
46
|
const transaction = createFixtureTransaction();
|
|
41
47
|
transaction.fees = null;
|
|
42
|
-
transaction.amount =
|
|
48
|
+
transaction.amount = BigNumber(2);
|
|
43
49
|
transaction.recipient = "0x" + "0".repeat(64);
|
|
44
50
|
|
|
45
51
|
const result = await getTransactionStatus(account, transaction);
|
|
@@ -49,22 +55,71 @@ describe("getTransactionStatus Test", () => {
|
|
|
49
55
|
fees: new FeeNotLoaded(),
|
|
50
56
|
},
|
|
51
57
|
warnings: {},
|
|
52
|
-
estimatedFees:
|
|
53
|
-
amount:
|
|
54
|
-
totalSpent:
|
|
58
|
+
estimatedFees: BigNumber(0),
|
|
59
|
+
amount: BigNumber(2),
|
|
60
|
+
totalSpent: BigNumber(2),
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
expect(result).toEqual(expected);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("should return error for NotEnoughBalance", async () => {
|
|
67
|
+
const account = createFixtureAccount();
|
|
68
|
+
account.spendableBalance = BigNumber(1);
|
|
69
|
+
|
|
70
|
+
const transaction = createFixtureTransaction();
|
|
71
|
+
transaction.recipient = "0x" + "0".repeat(64);
|
|
72
|
+
transaction.amount = BigNumber(2);
|
|
73
|
+
transaction.fees = BigNumber(2);
|
|
74
|
+
|
|
75
|
+
const result = await getTransactionStatus(account, transaction);
|
|
76
|
+
|
|
77
|
+
const expected = {
|
|
78
|
+
errors: {
|
|
79
|
+
amount: new NotEnoughBalance(),
|
|
80
|
+
},
|
|
81
|
+
warnings: {},
|
|
82
|
+
estimatedFees: BigNumber(2),
|
|
83
|
+
amount: BigNumber(2),
|
|
84
|
+
totalSpent: BigNumber(4),
|
|
55
85
|
};
|
|
56
86
|
|
|
57
87
|
expect(result).toEqual(expected);
|
|
58
88
|
});
|
|
59
89
|
|
|
60
|
-
it("should return
|
|
90
|
+
it("should return error for NotEnoughBalance and amount equal to zero with use all amount option", async () => {
|
|
61
91
|
const account = createFixtureAccount();
|
|
62
|
-
account.
|
|
92
|
+
account.spendableBalance = BigNumber(1);
|
|
63
93
|
|
|
64
94
|
const transaction = createFixtureTransaction();
|
|
65
95
|
transaction.recipient = "0x" + "0".repeat(64);
|
|
66
|
-
transaction.amount =
|
|
67
|
-
transaction.fees =
|
|
96
|
+
transaction.amount = BigNumber(2);
|
|
97
|
+
transaction.fees = BigNumber(2);
|
|
98
|
+
transaction.useAllAmount = true;
|
|
99
|
+
|
|
100
|
+
const result = await getTransactionStatus(account, transaction);
|
|
101
|
+
|
|
102
|
+
const expected = {
|
|
103
|
+
errors: {
|
|
104
|
+
amount: new NotEnoughBalance(),
|
|
105
|
+
},
|
|
106
|
+
warnings: {},
|
|
107
|
+
estimatedFees: BigNumber(2),
|
|
108
|
+
amount: BigNumber(0),
|
|
109
|
+
totalSpent: BigNumber(2),
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
expect(result).toEqual(expected);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("should return error for NotEnoughBalance for token account when not enough tokens", async () => {
|
|
116
|
+
const account = createFixtureAccountWithSubAccount("coin");
|
|
117
|
+
account.spendableBalance = BigNumber(300);
|
|
118
|
+
|
|
119
|
+
const transaction = createFixtureTransactionWithSubAccount();
|
|
120
|
+
transaction.recipient = "0x" + "0".repeat(64);
|
|
121
|
+
transaction.amount = BigNumber(2000);
|
|
122
|
+
transaction.fees = BigNumber(200);
|
|
68
123
|
|
|
69
124
|
const result = await getTransactionStatus(account, transaction);
|
|
70
125
|
|
|
@@ -73,21 +128,97 @@ describe("getTransactionStatus Test", () => {
|
|
|
73
128
|
amount: new NotEnoughBalance(),
|
|
74
129
|
},
|
|
75
130
|
warnings: {},
|
|
76
|
-
estimatedFees:
|
|
77
|
-
amount:
|
|
78
|
-
totalSpent:
|
|
131
|
+
estimatedFees: BigNumber(200),
|
|
132
|
+
amount: BigNumber(2000),
|
|
133
|
+
totalSpent: BigNumber(2000),
|
|
79
134
|
};
|
|
80
135
|
|
|
81
136
|
expect(result).toEqual(expected);
|
|
82
137
|
});
|
|
83
138
|
|
|
84
|
-
it("should return
|
|
139
|
+
it("should return error for NotEnoughBalance with use all amount option", async () => {
|
|
85
140
|
const account = createFixtureAccount();
|
|
86
|
-
account.
|
|
141
|
+
account.spendableBalance = BigNumber(1);
|
|
87
142
|
|
|
88
143
|
const transaction = createFixtureTransaction();
|
|
89
|
-
transaction.
|
|
90
|
-
transaction.
|
|
144
|
+
transaction.recipient = "0x" + "0".repeat(64);
|
|
145
|
+
transaction.amount = BigNumber(2);
|
|
146
|
+
transaction.fees = BigNumber(2);
|
|
147
|
+
transaction.useAllAmount = true;
|
|
148
|
+
|
|
149
|
+
const result = await getTransactionStatus(account, transaction);
|
|
150
|
+
|
|
151
|
+
const expected = {
|
|
152
|
+
errors: {
|
|
153
|
+
amount: new NotEnoughBalance(),
|
|
154
|
+
},
|
|
155
|
+
warnings: {},
|
|
156
|
+
estimatedFees: BigNumber(2),
|
|
157
|
+
amount: BigNumber(0),
|
|
158
|
+
totalSpent: BigNumber(2),
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
expect(result).toEqual(expected);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("should return error for NotEnoughBalance for token account with use all amount option when not enough fees", async () => {
|
|
165
|
+
const account = createFixtureAccountWithSubAccount("coin");
|
|
166
|
+
account.spendableBalance = BigNumber(10);
|
|
167
|
+
|
|
168
|
+
const transaction = createFixtureTransactionWithSubAccount();
|
|
169
|
+
transaction.recipient = "0x" + "0".repeat(64);
|
|
170
|
+
transaction.amount = BigNumber(2000);
|
|
171
|
+
transaction.fees = BigNumber(200);
|
|
172
|
+
transaction.useAllAmount = true;
|
|
173
|
+
|
|
174
|
+
const result = await getTransactionStatus(account, transaction);
|
|
175
|
+
|
|
176
|
+
const expected = {
|
|
177
|
+
errors: {
|
|
178
|
+
amount: new NotEnoughBalance(),
|
|
179
|
+
},
|
|
180
|
+
warnings: {},
|
|
181
|
+
estimatedFees: BigNumber(200),
|
|
182
|
+
amount: BigNumber(1000),
|
|
183
|
+
totalSpent: BigNumber(1000),
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
expect(result).toEqual(expected);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("should return error for NotEnoughBalanceFees", async () => {
|
|
190
|
+
const account = createFixtureAccountWithSubAccount("coin");
|
|
191
|
+
account.spendableBalance = BigNumber(1);
|
|
192
|
+
|
|
193
|
+
const transaction = createFixtureTransactionWithSubAccount();
|
|
194
|
+
transaction.recipient = "0x" + "0".repeat(64);
|
|
195
|
+
transaction.amount = BigNumber(2);
|
|
196
|
+
transaction.fees = BigNumber(0);
|
|
197
|
+
transaction.errors = { maxGasAmount: "GasInsufficientBalance" };
|
|
198
|
+
|
|
199
|
+
const result = await getTransactionStatus(account, transaction);
|
|
200
|
+
|
|
201
|
+
const expected = {
|
|
202
|
+
errors: {
|
|
203
|
+
amount: new NotEnoughBalanceFees(),
|
|
204
|
+
},
|
|
205
|
+
warnings: {},
|
|
206
|
+
estimatedFees: BigNumber(0),
|
|
207
|
+
amount: BigNumber(2),
|
|
208
|
+
totalSpent: BigNumber(2),
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
expect(result).toEqual(expected);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it("should return error for RecipientRequired", async () => {
|
|
215
|
+
const account = createFixtureAccount();
|
|
216
|
+
account.spendableBalance = BigNumber(10);
|
|
217
|
+
|
|
218
|
+
const transaction = createFixtureTransaction();
|
|
219
|
+
transaction.amount = BigNumber(2);
|
|
220
|
+
transaction.fees = BigNumber(2);
|
|
221
|
+
transaction.recipient = "";
|
|
91
222
|
|
|
92
223
|
const result = await getTransactionStatus(account, transaction);
|
|
93
224
|
|
|
@@ -96,20 +227,20 @@ describe("getTransactionStatus Test", () => {
|
|
|
96
227
|
recipient: new RecipientRequired(),
|
|
97
228
|
},
|
|
98
229
|
warnings: {},
|
|
99
|
-
estimatedFees:
|
|
100
|
-
amount:
|
|
101
|
-
totalSpent:
|
|
230
|
+
estimatedFees: BigNumber(2),
|
|
231
|
+
amount: BigNumber(2),
|
|
232
|
+
totalSpent: BigNumber(4),
|
|
102
233
|
};
|
|
103
234
|
|
|
104
235
|
expect(result).toEqual(expected);
|
|
105
236
|
});
|
|
106
237
|
|
|
107
|
-
it("should return
|
|
238
|
+
it("should return error for InvalidAddress", async () => {
|
|
108
239
|
const account = createFixtureAccount();
|
|
109
240
|
const transaction = createFixtureTransaction();
|
|
110
241
|
|
|
111
|
-
transaction.amount =
|
|
112
|
-
transaction.fees =
|
|
242
|
+
transaction.amount = BigNumber(2);
|
|
243
|
+
transaction.fees = BigNumber(2);
|
|
113
244
|
transaction.recipient = "0x";
|
|
114
245
|
|
|
115
246
|
const result = await getTransactionStatus(account, transaction);
|
|
@@ -120,20 +251,20 @@ describe("getTransactionStatus Test", () => {
|
|
|
120
251
|
amount: new NotEnoughBalance(),
|
|
121
252
|
},
|
|
122
253
|
warnings: {},
|
|
123
|
-
estimatedFees:
|
|
124
|
-
amount:
|
|
125
|
-
totalSpent:
|
|
254
|
+
estimatedFees: BigNumber(2),
|
|
255
|
+
amount: BigNumber(2),
|
|
256
|
+
totalSpent: BigNumber(4),
|
|
126
257
|
};
|
|
127
258
|
|
|
128
259
|
expect(result).toEqual(expected);
|
|
129
260
|
});
|
|
130
261
|
|
|
131
|
-
it("should return
|
|
262
|
+
it("should return error for InvalidAddressBecauseDestinationIsAlsoSource", async () => {
|
|
132
263
|
const account = createFixtureAccount();
|
|
133
264
|
const transaction = createFixtureTransaction();
|
|
134
265
|
|
|
135
|
-
transaction.amount =
|
|
136
|
-
transaction.fees =
|
|
266
|
+
transaction.amount = BigNumber(2);
|
|
267
|
+
transaction.fees = BigNumber(2);
|
|
137
268
|
transaction.recipient = "0x" + "0".repeat(64);
|
|
138
269
|
account.freshAddress = transaction.recipient;
|
|
139
270
|
|
|
@@ -145,9 +276,57 @@ describe("getTransactionStatus Test", () => {
|
|
|
145
276
|
amount: new NotEnoughBalance(),
|
|
146
277
|
},
|
|
147
278
|
warnings: {},
|
|
148
|
-
estimatedFees:
|
|
149
|
-
amount:
|
|
150
|
-
totalSpent:
|
|
279
|
+
estimatedFees: BigNumber(2),
|
|
280
|
+
amount: BigNumber(2),
|
|
281
|
+
totalSpent: BigNumber(4),
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
expect(result).toEqual(expected);
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
it("should return error for RecipientRequired", async () => {
|
|
288
|
+
const account = createFixtureAccount();
|
|
289
|
+
const transaction = createFixtureTransaction();
|
|
290
|
+
|
|
291
|
+
transaction.amount = BigNumber(2);
|
|
292
|
+
transaction.fees = BigNumber(2);
|
|
293
|
+
transaction.recipient = "";
|
|
294
|
+
account.freshAddress = transaction.recipient;
|
|
295
|
+
|
|
296
|
+
const result = await getTransactionStatus(account, transaction);
|
|
297
|
+
|
|
298
|
+
const expected = {
|
|
299
|
+
errors: {
|
|
300
|
+
recipient: new RecipientRequired(),
|
|
301
|
+
amount: new NotEnoughBalance(),
|
|
302
|
+
},
|
|
303
|
+
warnings: {},
|
|
304
|
+
estimatedFees: BigNumber(2),
|
|
305
|
+
amount: BigNumber(2),
|
|
306
|
+
totalSpent: BigNumber(4),
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
expect(result).toEqual(expected);
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
it("should return right amount and total spent with use all amount option", async () => {
|
|
313
|
+
const account = createFixtureAccount();
|
|
314
|
+
account.spendableBalance = BigNumber(10);
|
|
315
|
+
|
|
316
|
+
const transaction = createFixtureTransaction();
|
|
317
|
+
transaction.recipient = "0x" + "0".repeat(64);
|
|
318
|
+
transaction.amount = BigNumber(2);
|
|
319
|
+
transaction.fees = BigNumber(2);
|
|
320
|
+
transaction.useAllAmount = true;
|
|
321
|
+
|
|
322
|
+
const result = await getTransactionStatus(account, transaction);
|
|
323
|
+
|
|
324
|
+
const expected = {
|
|
325
|
+
errors: {},
|
|
326
|
+
warnings: {},
|
|
327
|
+
estimatedFees: BigNumber(2),
|
|
328
|
+
amount: BigNumber(8),
|
|
329
|
+
totalSpent: BigNumber(10),
|
|
151
330
|
};
|
|
152
331
|
|
|
153
332
|
expect(result).toEqual(expected);
|