@ledgerhq/coin-aptos 1.9.5 → 1.10.0-nightly.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/CHANGELOG.md +17 -0
- package/lib/__tests__/api/index.test.js +61 -5
- package/lib/__tests__/api/index.test.js.map +1 -1
- package/lib/__tests__/bridge/buildTransaction.test.js +57 -2
- package/lib/__tests__/bridge/buildTransaction.test.js.map +1 -1
- package/lib/__tests__/bridge/getFeesForTransaction.test.js +109 -8
- 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/signOperation.test.js +128 -2
- package/lib/__tests__/bridge/signOperation.test.js.map +1 -1
- package/lib/__tests__/bridge/synchronisation.test.js +1214 -67
- package/lib/__tests__/bridge/synchronisation.test.js.map +1 -1
- package/lib/api/graphql/queries.js +6 -6
- package/lib/api/graphql/types.d.ts +9 -9
- package/lib/api/graphql/types.d.ts.map +1 -1
- package/lib/api/index.d.ts +5 -2
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +30 -4
- 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/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 +1 -1
- package/lib/bridge/estimateMaxSpendable.js.map +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/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 +2 -2
- package/lib/bridge/prepareTransaction.js.map +1 -1
- package/lib/bridge/signOperation.d.ts.map +1 -1
- package/lib/bridge/signOperation.js +17 -3
- 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 +127 -4
- package/lib/bridge/synchronisation.js.map +1 -1
- 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/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/index.d.ts +18 -7
- package/lib/types/index.d.ts.map +1 -1
- package/lib-es/__tests__/api/index.test.js +61 -5
- package/lib-es/__tests__/api/index.test.js.map +1 -1
- package/lib-es/__tests__/bridge/buildTransaction.test.js +58 -3
- package/lib-es/__tests__/bridge/buildTransaction.test.js.map +1 -1
- package/lib-es/__tests__/bridge/getFeesForTransaction.test.js +110 -9
- 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/signOperation.test.js +128 -2
- 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/api/graphql/queries.js +6 -6
- package/lib-es/api/graphql/types.d.ts +9 -9
- package/lib-es/api/graphql/types.d.ts.map +1 -1
- package/lib-es/api/index.d.ts +5 -2
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +30 -4
- 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/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 +1 -1
- 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 +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/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 +2 -2
- 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 +17 -3
- 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 +123 -3
- package/lib-es/bridge/synchronisation.js.map +1 -1
- 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/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/index.d.ts +18 -7
- package/lib-es/types/index.d.ts.map +1 -1
- package/package.json +9 -8
- package/src/__tests__/api/index.test.ts +75 -5
- package/src/__tests__/bridge/buildTransaction.test.ts +85 -3
- package/src/__tests__/bridge/getFeesForTransaction.test.ts +144 -9
- package/src/__tests__/bridge/getTransactionStatus.test.ts +217 -38
- package/src/__tests__/bridge/logic.test.ts +922 -118
- package/src/__tests__/bridge/signOperation.test.ts +141 -2
- package/src/__tests__/bridge/synchronisation.test.ts +1265 -71
- package/src/api/graphql/queries.ts +6 -6
- package/src/api/graphql/types.ts +9 -9
- package/src/api/index.ts +32 -5
- package/src/bridge/bridge.fixture.ts +91 -12
- package/src/bridge/buildTransaction.ts +39 -6
- package/src/bridge/estimateMaxSpendable.ts +1 -1
- package/src/bridge/getFeesForTransaction.ts +14 -9
- package/src/bridge/getTransactionStatus.ts +35 -13
- package/src/bridge/logic.ts +202 -63
- package/src/bridge/prepareTransaction.ts +4 -3
- package/src/bridge/signOperation.ts +19 -3
- package/src/bridge/synchronisation.ts +170 -3
- package/src/constants.ts +12 -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/index.ts +15 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,KAAK,EACV,OAAO,EACP,SAAS,EACT,iBAAiB,EACjB,oBAAoB,EACpB,uBAAuB,EACvB,0BAA0B,EAC3B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AAEzB,MAAM,MAAM,gBAAgB,GAAG,uBAAuB,GAAG;IACvD,KAAK,EAAE;QACL,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,SAAS,CAAC;AAEvC,MAAM,MAAM,YAAY,GAAG,OAAO,CAAC;AAEnC,MAAM,MAAM,iBAAiB,GAAG,uBAAuB,CAAC;AAExD,MAAM,MAAM,oBAAoB,GAAG,0BAA0B,CAAC;AAE9D,MAAM,MAAM,sBAAsB,GAAG;IACnC,IAAI,EAAE;QACJ,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,IAAI;IAC/D,IAAI,EAAE,CAAC,CAAC;IACR,IAAI,EAAE,MAAM,CA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AI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,8BAA8B,GAAG;IAC3C,OAAO,EAAE,SAAS,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,oCAAoC,GAAG;IACjD,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,IAAI,EAAE;QAAE,EAAE,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,YAAY,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC;CACtD,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,CAAC,GAAG,EAAE,MAAM,GAAG,qBAAqB,CAAC;CACtC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/coin-aptos",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0-nightly.0",
|
|
4
4
|
"description": "Ledger Aptos Coin integration",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ledger",
|
|
@@ -90,14 +90,15 @@
|
|
|
90
90
|
"expect": "^27.4.6",
|
|
91
91
|
"lodash": "^4.17.21",
|
|
92
92
|
"rxjs": "^7.8.1",
|
|
93
|
-
"@ledgerhq/coin-framework": "^5.0.
|
|
94
|
-
"@ledgerhq/cryptoassets": "^13.
|
|
95
|
-
"@ledgerhq/
|
|
96
|
-
"@ledgerhq/
|
|
97
|
-
"@ledgerhq/
|
|
98
|
-
"@ledgerhq/live-
|
|
93
|
+
"@ledgerhq/coin-framework": "^5.1.0-nightly.0",
|
|
94
|
+
"@ledgerhq/cryptoassets": "^13.17.0-nightly.1",
|
|
95
|
+
"@ledgerhq/types-cryptoassets": "^7.23.0",
|
|
96
|
+
"@ledgerhq/devices": "8.4.5-nightly.1",
|
|
97
|
+
"@ledgerhq/errors": "^6.20.0-nightly.1",
|
|
98
|
+
"@ledgerhq/live-env": "^2.9.0-nightly.0",
|
|
99
|
+
"@ledgerhq/live-network": "^2.0.8-nightly.0",
|
|
99
100
|
"@ledgerhq/logs": "^6.12.0",
|
|
100
|
-
"@ledgerhq/types-live": "^6.
|
|
101
|
+
"@ledgerhq/types-live": "^6.71.0-nightly.0"
|
|
101
102
|
},
|
|
102
103
|
"devDependencies": {
|
|
103
104
|
"@faker-js/faker": "^9.4.0",
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
import network from "@ledgerhq/live-network";
|
|
13
13
|
import BigNumber from "bignumber.js";
|
|
14
14
|
import { AptosAPI } from "../../api";
|
|
15
|
+
import { TokenCurrency } from "@ledgerhq/types-cryptoassets";
|
|
15
16
|
|
|
16
17
|
jest.mock("@aptos-labs/ts-sdk");
|
|
17
18
|
jest.mock("@apollo/client");
|
|
@@ -83,8 +84,77 @@ describe("Aptos API", () => {
|
|
|
83
84
|
});
|
|
84
85
|
});
|
|
85
86
|
|
|
87
|
+
describe("getBalance", () => {
|
|
88
|
+
let token: TokenCurrency;
|
|
89
|
+
|
|
90
|
+
beforeEach(() => {
|
|
91
|
+
token = {
|
|
92
|
+
type: "TokenCurrency",
|
|
93
|
+
id: "aptos_token",
|
|
94
|
+
name: "Aptos Token",
|
|
95
|
+
ticker: "APT",
|
|
96
|
+
units: [{ name: "APT", code: "APT", magnitude: 6 }],
|
|
97
|
+
contractAddress: "APTOS_1_ADDRESS",
|
|
98
|
+
tokenType: "fungible_asset",
|
|
99
|
+
parentCurrency: {
|
|
100
|
+
type: "CryptoCurrency",
|
|
101
|
+
id: "aptos",
|
|
102
|
+
name: "Aptos",
|
|
103
|
+
ticker: "APT",
|
|
104
|
+
units: [{ name: "APT", code: "APT", magnitude: 6 }],
|
|
105
|
+
color: "#000000",
|
|
106
|
+
family: "aptos",
|
|
107
|
+
scheme: "aptos",
|
|
108
|
+
explorerViews: [],
|
|
109
|
+
managerAppName: "Aptos",
|
|
110
|
+
coinType: 637,
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("get coin balance", async () => {
|
|
116
|
+
mockedAptos.mockImplementation(() => ({
|
|
117
|
+
view: jest.fn().mockReturnValue(["1234"]),
|
|
118
|
+
}));
|
|
119
|
+
|
|
120
|
+
token.tokenType = "coin";
|
|
121
|
+
const api = new AptosAPI("aptos");
|
|
122
|
+
const balance = await api.getBalance("address", token);
|
|
123
|
+
|
|
124
|
+
expect(balance).toEqual(new BigNumber(1234));
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("get fungible assets balance", async () => {
|
|
128
|
+
mockedAptos.mockImplementation(() => ({
|
|
129
|
+
view: jest.fn().mockReturnValue(["12345"]),
|
|
130
|
+
}));
|
|
131
|
+
|
|
132
|
+
token.tokenType = "fungible_asset";
|
|
133
|
+
|
|
134
|
+
const api = new AptosAPI("aptos");
|
|
135
|
+
const balance = await api.getBalance("address", token);
|
|
136
|
+
|
|
137
|
+
expect(balance).toEqual(new BigNumber(12345));
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it("return 0 balace if could not retrieve proper balance of fungible assets", async () => {
|
|
141
|
+
mockedAptos.mockImplementation(() => ({
|
|
142
|
+
view: jest.fn().mockImplementation(() => {
|
|
143
|
+
throw new Error("error");
|
|
144
|
+
}),
|
|
145
|
+
}));
|
|
146
|
+
|
|
147
|
+
token.tokenType = "fungible_asset";
|
|
148
|
+
|
|
149
|
+
const api = new AptosAPI("aptos");
|
|
150
|
+
const balance = await api.getBalance("address", token);
|
|
151
|
+
|
|
152
|
+
expect(balance).toEqual(new BigNumber(0));
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
|
|
86
156
|
describe("getAccountInfo", () => {
|
|
87
|
-
it("calls
|
|
157
|
+
it("calls getCoinBalance, fetchTransactions and getHeight", async () => {
|
|
88
158
|
mockedAptos.mockImplementation(() => ({
|
|
89
159
|
view: jest.fn().mockReturnValue(["123"]),
|
|
90
160
|
getTransactionByVersion: jest.fn().mockReturnValue({
|
|
@@ -124,7 +194,7 @@ describe("Aptos API", () => {
|
|
|
124
194
|
mockedApolloClient.mockImplementation(() => ({
|
|
125
195
|
query: async () => ({
|
|
126
196
|
data: {
|
|
127
|
-
|
|
197
|
+
account_transactions: [{ transaction_version: 1 }],
|
|
128
198
|
},
|
|
129
199
|
loading: false,
|
|
130
200
|
networkStatus: 7,
|
|
@@ -190,7 +260,7 @@ describe("Aptos API", () => {
|
|
|
190
260
|
mockedApolloClient.mockImplementation(() => ({
|
|
191
261
|
query: async () => ({
|
|
192
262
|
data: {
|
|
193
|
-
|
|
263
|
+
account_transactions: [{ transaction_version: 1 }],
|
|
194
264
|
},
|
|
195
265
|
loading: false,
|
|
196
266
|
networkStatus: 7,
|
|
@@ -254,7 +324,7 @@ describe("Aptos API", () => {
|
|
|
254
324
|
mockedApolloClient.mockImplementation(() => ({
|
|
255
325
|
query: async () => ({
|
|
256
326
|
data: {
|
|
257
|
-
|
|
327
|
+
account_transactions: [{ transaction_version: 1 }],
|
|
258
328
|
},
|
|
259
329
|
loading: false,
|
|
260
330
|
networkStatus: 7,
|
|
@@ -308,7 +378,7 @@ describe("Aptos API", () => {
|
|
|
308
378
|
mockedApolloClient.mockImplementation(() => ({
|
|
309
379
|
query: async () => ({
|
|
310
380
|
data: {
|
|
311
|
-
|
|
381
|
+
account_transactions: [{ transaction_version: 1 }],
|
|
312
382
|
},
|
|
313
383
|
loading: false,
|
|
314
384
|
networkStatus: 7,
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
createFixtureAccount,
|
|
3
|
+
createFixtureAccountWithSubAccount,
|
|
4
|
+
createFixtureTransaction,
|
|
5
|
+
createFixtureTransactionWithSubAccount,
|
|
6
|
+
} from "../../bridge/bridge.fixture";
|
|
2
7
|
import buildTransaction from "../../bridge/buildTransaction";
|
|
3
8
|
import { AptosAPI } from "../../api";
|
|
4
9
|
import { normalizeTransactionOptions } from "../../bridge/logic";
|
|
@@ -26,8 +31,12 @@ jest.mock("../../api", () => {
|
|
|
26
31
|
};
|
|
27
32
|
});
|
|
28
33
|
|
|
34
|
+
afterEach(() => {
|
|
35
|
+
jest.clearAllMocks();
|
|
36
|
+
});
|
|
37
|
+
|
|
29
38
|
describe("buildTransaction Test", () => {
|
|
30
|
-
it("should return
|
|
39
|
+
it("should return transaction for main account", async () => {
|
|
31
40
|
const account = createFixtureAccount();
|
|
32
41
|
const transaction = createFixtureTransaction();
|
|
33
42
|
const aptosClient = new AptosAPI(account.currency.id);
|
|
@@ -54,8 +63,81 @@ describe("buildTransaction Test", () => {
|
|
|
54
63
|
expect(generateTransactionArgs[1]).toEqual({
|
|
55
64
|
function: "0x1::aptos_account::transfer_coins",
|
|
56
65
|
typeArguments: ["0x1::aptos_coin::AptosCoin"],
|
|
57
|
-
functionArguments: ["", "0"],
|
|
66
|
+
functionArguments: ["recipient", "0"],
|
|
67
|
+
});
|
|
68
|
+
expect(generateTransactionArgs[2]).toEqual({ maxGasAmount: "100", gasUnitPrice: "200" });
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("should return transaction for token account of type fungible asset", async () => {
|
|
72
|
+
const account = createFixtureAccountWithSubAccount("fungible_asset");
|
|
73
|
+
const transaction = createFixtureTransactionWithSubAccount();
|
|
74
|
+
const aptosClient = new AptosAPI(account.currency.id);
|
|
75
|
+
const result = await buildTransaction(account, transaction, aptosClient);
|
|
76
|
+
|
|
77
|
+
const expected = "tx";
|
|
78
|
+
|
|
79
|
+
expect(result).toBe(expected);
|
|
80
|
+
|
|
81
|
+
const mockedNormalizeTransactionOptions = jest.mocked(normalizeTransactionOptions);
|
|
82
|
+
|
|
83
|
+
expect(mockedNormalizeTransactionOptions).toHaveBeenCalledTimes(1);
|
|
84
|
+
expect(generateTransaction).toHaveBeenCalledTimes(1);
|
|
85
|
+
|
|
86
|
+
const generateTransactionArgs: [string, InputEntryFunctionData, TransactionOptions][] =
|
|
87
|
+
generateTransaction.mock.calls[0];
|
|
88
|
+
|
|
89
|
+
expect(mockedNormalizeTransactionOptions.mock.calls[0][0]).toEqual({
|
|
90
|
+
maxGasAmount: "0",
|
|
91
|
+
gasUnitPrice: "0",
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
expect(generateTransactionArgs[0]).toBe("address");
|
|
95
|
+
expect(generateTransactionArgs[1]).toEqual({
|
|
96
|
+
function: "0x1::primary_fungible_store::transfer",
|
|
97
|
+
typeArguments: ["0x1::fungible_asset::Metadata"],
|
|
98
|
+
functionArguments: ["contract_address", "recipient", "0"],
|
|
99
|
+
});
|
|
100
|
+
expect(generateTransactionArgs[2]).toEqual({ maxGasAmount: "100", gasUnitPrice: "200" });
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("should return transaction for token account of type coin", async () => {
|
|
104
|
+
const account = createFixtureAccountWithSubAccount("coin");
|
|
105
|
+
const transaction = createFixtureTransactionWithSubAccount();
|
|
106
|
+
const aptosClient = new AptosAPI(account.currency.id);
|
|
107
|
+
const result = await buildTransaction(account, transaction, aptosClient);
|
|
108
|
+
|
|
109
|
+
const expected = "tx";
|
|
110
|
+
|
|
111
|
+
expect(result).toBe(expected);
|
|
112
|
+
|
|
113
|
+
const mockedNormalizeTransactionOptions = jest.mocked(normalizeTransactionOptions);
|
|
114
|
+
|
|
115
|
+
expect(mockedNormalizeTransactionOptions).toHaveBeenCalledTimes(1);
|
|
116
|
+
expect(generateTransaction).toHaveBeenCalledTimes(1);
|
|
117
|
+
|
|
118
|
+
const generateTransactionArgs: [string, InputEntryFunctionData, TransactionOptions][] =
|
|
119
|
+
generateTransaction.mock.calls[0];
|
|
120
|
+
|
|
121
|
+
expect(mockedNormalizeTransactionOptions.mock.calls[0][0]).toEqual({
|
|
122
|
+
maxGasAmount: "0",
|
|
123
|
+
gasUnitPrice: "0",
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
expect(generateTransactionArgs[0]).toBe("address");
|
|
127
|
+
expect(generateTransactionArgs[1]).toEqual({
|
|
128
|
+
function: "0x1::aptos_account::transfer_coins",
|
|
129
|
+
typeArguments: ["contract_address"],
|
|
130
|
+
functionArguments: ["recipient", "0"],
|
|
58
131
|
});
|
|
59
132
|
expect(generateTransactionArgs[2]).toEqual({ maxGasAmount: "100", gasUnitPrice: "200" });
|
|
60
133
|
});
|
|
134
|
+
|
|
135
|
+
it("should throw error if token is not supported", async () => {
|
|
136
|
+
const account = createFixtureAccountWithSubAccount("not_supported_token_type");
|
|
137
|
+
const transaction = createFixtureTransactionWithSubAccount();
|
|
138
|
+
const aptosClient = new AptosAPI(account.currency.id);
|
|
139
|
+
expect(async () => await buildTransaction(account, transaction, aptosClient)).rejects.toThrow(
|
|
140
|
+
"Token type not_supported_token_type not supported",
|
|
141
|
+
);
|
|
142
|
+
});
|
|
61
143
|
});
|
|
@@ -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 * as getFeesForTransaction from "../../bridge/getFeesForTransaction";
|
|
4
9
|
import { AptosAPI } from "../../api";
|
|
5
10
|
|
|
@@ -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
|
});
|