@ledgerhq/coin-aptos 2.0.0-nightly.4 → 2.0.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 +18 -6
- package/CHANGELOG.md +156 -29
- package/jest.config.js +2 -1
- 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 +52 -0
- package/lib/__tests__/api/index.integ.test.js.map +1 -0
- package/lib/__tests__/api/index.test.js +48 -460
- 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 +6 -6
- package/lib/__tests__/bridge/buildTransaction.test.js.map +1 -1
- package/lib/__tests__/bridge/createTransaction.test.js +1 -1
- package/lib/__tests__/bridge/createTransaction.test.js.map +1 -1
- package/lib/__tests__/bridge/getFeesForTransaction.test.js +9 -9
- package/lib/__tests__/bridge/getFeesForTransaction.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 +3 -2
- package/lib/__tests__/bridge/signOperation.test.js.map +1 -1
- package/lib/__tests__/bridge/synchronisation.test.js +6 -6
- 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 +520 -0
- package/lib/__tests__/network/client.test.js.map +1 -0
- package/lib/api/index.d.ts +4 -33
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +24 -196
- package/lib/api/index.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.map +1 -1
- package/lib/bridge/createTransaction.js +3 -3
- package/lib/bridge/createTransaction.js.map +1 -1
- package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib/bridge/estimateMaxSpendable.js +5 -4
- 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 +7 -6
- package/lib/bridge/getFeesForTransaction.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 +0 -3
- package/lib/bridge/logic.d.ts.map +1 -1
- package/lib/bridge/logic.js +1 -4
- package/lib/bridge/logic.js.map +1 -1
- package/lib/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib/bridge/prepareTransaction.js +4 -3
- package/lib/bridge/prepareTransaction.js.map +1 -1
- package/lib/bridge/signOperation.js +3 -3
- package/lib/bridge/signOperation.js.map +1 -1
- package/lib/bridge/synchronisation.js +3 -3
- 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 +4 -0
- package/lib/constants.d.ts.map +1 -1
- package/lib/constants.js +8 -1
- package/lib/constants.js.map +1 -1
- package/lib/network/client.d.ts +36 -0
- package/lib/network/client.d.ts.map +1 -0
- package/lib/network/client.js +247 -0
- package/lib/network/client.js.map +1 -0
- package/lib/network/graphql/queries.d.ts.map +1 -0
- package/lib/network/graphql/queries.js.map +1 -0
- 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/bridgeDatasetTest.d.ts.map +1 -1
- package/lib/test/bridgeDatasetTest.js +1 -0
- package/lib/test/bridgeDatasetTest.js.map +1 -1
- package/lib/types/assets.d.ts +12 -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-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 +50 -0
- package/lib-es/__tests__/api/index.integ.test.js.map +1 -0
- package/lib-es/__tests__/api/index.test.js +52 -464
- 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 +2 -2
- package/lib-es/__tests__/bridge/buildTransaction.test.js.map +1 -1
- package/lib-es/__tests__/bridge/createTransaction.test.js +1 -1
- package/lib-es/__tests__/bridge/createTransaction.test.js.map +1 -1
- package/lib-es/__tests__/bridge/getFeesForTransaction.test.js +2 -2
- package/lib-es/__tests__/bridge/getFeesForTransaction.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 +3 -2
- package/lib-es/__tests__/bridge/signOperation.test.js.map +1 -1
- package/lib-es/__tests__/bridge/synchronisation.test.js +3 -3
- 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 +515 -0
- package/lib-es/__tests__/network/client.test.js.map +1 -0
- package/lib-es/api/index.d.ts +4 -33
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +22 -194
- package/lib-es/api/index.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.map +1 -1
- package/lib-es/bridge/createTransaction.js +1 -1
- package/lib-es/bridge/createTransaction.js.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.js +3 -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 +2 -1
- package/lib-es/bridge/getFeesForTransaction.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 +0 -3
- package/lib-es/bridge/logic.d.ts.map +1 -1
- package/lib-es/bridge/logic.js +0 -3
- 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 -2
- package/lib-es/bridge/prepareTransaction.js.map +1 -1
- package/lib-es/bridge/signOperation.js +1 -1
- package/lib-es/bridge/signOperation.js.map +1 -1
- package/lib-es/bridge/synchronisation.js +1 -1
- 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 +4 -0
- package/lib-es/constants.d.ts.map +1 -1
- package/lib-es/constants.js +4 -0
- package/lib-es/constants.js.map +1 -1
- package/lib-es/network/client.d.ts +36 -0
- package/lib-es/network/client.d.ts.map +1 -0
- package/lib-es/network/client.js +240 -0
- package/lib-es/network/client.js.map +1 -0
- package/lib-es/network/graphql/queries.d.ts.map +1 -0
- package/lib-es/network/graphql/queries.js.map +1 -0
- 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/bridgeDatasetTest.d.ts.map +1 -1
- package/lib-es/test/bridgeDatasetTest.js +1 -0
- package/lib-es/test/bridgeDatasetTest.js.map +1 -1
- package/lib-es/types/assets.d.ts +12 -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/package.json +12 -10
- package/src/__tests__/api/index.integ.test.ts +58 -0
- package/src/__tests__/api/index.test.ts +60 -547
- package/src/__tests__/bridge/broadcast.test.ts +2 -2
- package/src/__tests__/bridge/buildTransaction.test.ts +2 -2
- package/src/__tests__/bridge/createTransaction.test.ts +1 -1
- package/src/__tests__/bridge/getFeesForTransaction.test.ts +2 -2
- package/src/__tests__/bridge/prepareTransaction.test.ts +2 -2
- package/src/__tests__/bridge/signOperation.test.ts +6 -3
- package/src/__tests__/bridge/synchronisation.test.ts +4 -4
- package/src/__tests__/network/client.test.ts +618 -0
- package/src/api/index.ts +31 -250
- package/src/bridge/broadcast.ts +7 -7
- package/src/bridge/buildTransaction.ts +1 -1
- package/src/bridge/createTransaction.ts +1 -1
- package/src/bridge/estimateMaxSpendable.ts +3 -2
- package/src/bridge/getFeesForTransaction.ts +3 -2
- package/src/bridge/index.ts +1 -1
- package/src/bridge/logic.ts +0 -4
- package/src/bridge/prepareTransaction.ts +4 -2
- package/src/bridge/signOperation.ts +1 -1
- package/src/bridge/synchronisation.ts +1 -1
- package/src/config.ts +19 -0
- package/src/constants.ts +5 -0
- package/src/network/client.ts +315 -0
- package/src/network/index.ts +2 -1
- package/src/test/bridgeDatasetTest.ts +1 -0
- package/src/types/assets.ts +15 -0
- 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/queries.js +0 -0
- /package/lib/{api → network}/graphql/types.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/queries.js +0 -0
- /package/lib-es/{api → network}/graphql/types.d.ts +0 -0
- /package/lib-es/{api → network}/graphql/types.js +0 -0
- /package/src/{api → network}/graphql/queries.ts +0 -0
- /package/src/{api → network}/graphql/types.ts +0 -0
|
@@ -1,569 +1,82 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
InputEntryFunctionData,
|
|
8
|
-
RawTransaction,
|
|
9
|
-
Serializable,
|
|
10
|
-
post,
|
|
11
|
-
} from "@aptos-labs/ts-sdk";
|
|
12
|
-
import network from "@ledgerhq/live-network";
|
|
13
|
-
import BigNumber from "bignumber.js";
|
|
14
|
-
import { AptosAPI } from "../../api";
|
|
15
|
-
import { TokenCurrency } from "@ledgerhq/types-cryptoassets";
|
|
1
|
+
import { Aptos } from "@aptos-labs/ts-sdk";
|
|
2
|
+
import type { Api } from "@ledgerhq/coin-framework/api/types";
|
|
3
|
+
import type { AptosAsset, AptosExtra, AptosFeeParameters, AptosSender } from "../../types/assets";
|
|
4
|
+
import type { AptosConfig } from "../../config";
|
|
5
|
+
import { createApi } from "../../api";
|
|
6
|
+
import coinConfig from "../../config";
|
|
16
7
|
|
|
17
8
|
jest.mock("@aptos-labs/ts-sdk");
|
|
18
|
-
jest.mock("@apollo/client");
|
|
19
9
|
let mockedAptos: jest.Mocked<any>;
|
|
20
|
-
let mockedApolloClient: jest.Mocked<any>;
|
|
21
|
-
let mockedPost = jest.fn();
|
|
22
10
|
|
|
23
|
-
jest.mock("
|
|
24
|
-
|
|
11
|
+
jest.mock("../../config", () => ({
|
|
12
|
+
setCoinConfig: jest.fn(),
|
|
13
|
+
}));
|
|
25
14
|
|
|
26
|
-
|
|
27
|
-
beforeEach(() => {
|
|
28
|
-
mockedAptos = jest.mocked(Aptos);
|
|
29
|
-
mockedApolloClient = jest.mocked(ApolloClient);
|
|
30
|
-
mockedPost = jest.mocked(post);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
afterEach(() => jest.clearAllMocks());
|
|
34
|
-
|
|
35
|
-
it("builds the client properly for mainnet", () => {
|
|
36
|
-
const api = new AptosAPI("aptos");
|
|
37
|
-
|
|
38
|
-
expect(api.broadcast).toBeDefined();
|
|
39
|
-
expect(typeof api.broadcast).toBe("function");
|
|
40
|
-
expect(api.estimateGasPrice).toBeDefined();
|
|
41
|
-
expect(typeof api.estimateGasPrice).toBe("function");
|
|
42
|
-
expect(api.generateTransaction).toBeDefined();
|
|
43
|
-
expect(typeof api.generateTransaction).toBe("function");
|
|
44
|
-
expect(api.getAccount).toBeDefined();
|
|
45
|
-
expect(typeof api.getAccount).toBe("function");
|
|
46
|
-
expect(api.getAccountInfo).toBeDefined();
|
|
47
|
-
expect(typeof api.getAccountInfo).toBe("function");
|
|
48
|
-
expect(api.simulateTransaction).toBeDefined();
|
|
49
|
-
expect(typeof api.simulateTransaction).toBe("function");
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it("builds the client properly for testnet", () => {
|
|
53
|
-
const api = new AptosAPI("aptos_testnet");
|
|
54
|
-
|
|
55
|
-
expect(api.broadcast).toBeDefined();
|
|
56
|
-
expect(typeof api.broadcast).toBe("function");
|
|
57
|
-
expect(api.estimateGasPrice).toBeDefined();
|
|
58
|
-
expect(typeof api.estimateGasPrice).toBe("function");
|
|
59
|
-
expect(api.generateTransaction).toBeDefined();
|
|
60
|
-
expect(typeof api.generateTransaction).toBe("function");
|
|
61
|
-
expect(api.getAccount).toBeDefined();
|
|
62
|
-
expect(typeof api.getAccount).toBe("function");
|
|
63
|
-
expect(api.getAccountInfo).toBeDefined();
|
|
64
|
-
expect(typeof api.getAccountInfo).toBe("function");
|
|
65
|
-
expect(api.simulateTransaction).toBeDefined();
|
|
66
|
-
expect(typeof api.simulateTransaction).toBe("function");
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
describe("getAccount", () => {
|
|
70
|
-
it("calls getAccountInfo", async () => {
|
|
71
|
-
const mockGetAccountInfo = jest.fn();
|
|
72
|
-
mockedAptos.mockImplementation(() => ({
|
|
73
|
-
getAccountInfo: mockGetAccountInfo,
|
|
74
|
-
}));
|
|
75
|
-
|
|
76
|
-
const mockGetAccountSpy = jest.spyOn({ getAccount: mockGetAccountInfo }, "getAccount");
|
|
77
|
-
|
|
78
|
-
const api = new AptosAPI("aptos");
|
|
79
|
-
await api.getAccount("address");
|
|
80
|
-
|
|
81
|
-
expect(mockGetAccountSpy).toHaveBeenCalledWith({
|
|
82
|
-
accountAddress: "address",
|
|
83
|
-
});
|
|
84
|
-
});
|
|
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
|
-
});
|
|
15
|
+
const mockAptosConfig: AptosConfig = {} as AptosConfig;
|
|
114
16
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}));
|
|
17
|
+
describe("createApi", () => {
|
|
18
|
+
it("should set the coin config value", () => {
|
|
19
|
+
const setCoinConfigSpy = jest.spyOn(coinConfig, "setCoinConfig");
|
|
119
20
|
|
|
120
|
-
|
|
121
|
-
const api = new AptosAPI("aptos");
|
|
122
|
-
const balance = await api.getBalance("address", token);
|
|
21
|
+
createApi(mockAptosConfig);
|
|
123
22
|
|
|
124
|
-
|
|
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
|
-
});
|
|
23
|
+
const config = setCoinConfigSpy.mock.calls[0][0]();
|
|
139
24
|
|
|
140
|
-
|
|
141
|
-
mockedAptos.mockImplementation(() => ({
|
|
142
|
-
view: jest.fn().mockImplementation(() => {
|
|
143
|
-
throw new Error("error");
|
|
144
|
-
}),
|
|
145
|
-
}));
|
|
25
|
+
expect(setCoinConfigSpy).toHaveBeenCalled();
|
|
146
26
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
});
|
|
27
|
+
expect(config).toEqual(
|
|
28
|
+
expect.objectContaining({
|
|
29
|
+
...mockAptosConfig,
|
|
30
|
+
status: { type: "active" },
|
|
31
|
+
}),
|
|
32
|
+
);
|
|
154
33
|
});
|
|
155
34
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
view: jest.fn().mockReturnValue(["123"]),
|
|
160
|
-
getTransactionByVersion: jest.fn().mockReturnValue({
|
|
161
|
-
type: "user_transaction",
|
|
162
|
-
version: "v1",
|
|
163
|
-
}),
|
|
164
|
-
getBlockByVersion: jest.fn().mockReturnValue({
|
|
165
|
-
block_height: "1",
|
|
166
|
-
block_hash: "83ca6d",
|
|
167
|
-
}),
|
|
168
|
-
}));
|
|
169
|
-
|
|
170
|
-
mockedNetwork.mockResolvedValue(
|
|
171
|
-
Promise.resolve({
|
|
172
|
-
data: {
|
|
173
|
-
account: {
|
|
174
|
-
account_number: 1,
|
|
175
|
-
sequence: 0,
|
|
176
|
-
pub_key: { key: "k", "@type": "type" },
|
|
177
|
-
base_account: {
|
|
178
|
-
account_number: 2,
|
|
179
|
-
sequence: 42,
|
|
180
|
-
pub_key: { key: "k2", "@type": "type2" },
|
|
181
|
-
},
|
|
182
|
-
},
|
|
183
|
-
block_height: "999",
|
|
184
|
-
},
|
|
185
|
-
status: 200,
|
|
186
|
-
headers: {} as any,
|
|
187
|
-
statusText: "",
|
|
188
|
-
config: {
|
|
189
|
-
headers: {} as any,
|
|
190
|
-
},
|
|
191
|
-
}),
|
|
192
|
-
);
|
|
193
|
-
|
|
194
|
-
mockedApolloClient.mockImplementation(() => ({
|
|
195
|
-
query: async () => ({
|
|
196
|
-
data: {
|
|
197
|
-
account_transactions: [{ transaction_version: 1 }],
|
|
198
|
-
},
|
|
199
|
-
loading: false,
|
|
200
|
-
networkStatus: 7,
|
|
201
|
-
}),
|
|
202
|
-
}));
|
|
203
|
-
|
|
204
|
-
const api = new AptosAPI("aptos");
|
|
205
|
-
const accountInfo = await api.getAccountInfo("APTOS_1_ADDRESS", "1");
|
|
206
|
-
|
|
207
|
-
expect(accountInfo.balance).toEqual(new BigNumber(123));
|
|
208
|
-
expect(accountInfo.transactions).toEqual([
|
|
209
|
-
{
|
|
210
|
-
type: "user_transaction",
|
|
211
|
-
version: "v1",
|
|
212
|
-
block: {
|
|
213
|
-
height: 1,
|
|
214
|
-
hash: "83ca6d",
|
|
215
|
-
},
|
|
216
|
-
},
|
|
217
|
-
]);
|
|
218
|
-
expect(accountInfo.blockHeight).toEqual(999);
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
it("return balance = 0 if it fails to fetch balance", async () => {
|
|
222
|
-
mockedAptos.mockImplementation(() => ({
|
|
223
|
-
view: jest.fn().mockImplementation(() => {
|
|
224
|
-
throw new Error("error");
|
|
225
|
-
}),
|
|
226
|
-
getTransactionByVersion: jest.fn().mockReturnValue({
|
|
227
|
-
type: "user_transaction",
|
|
228
|
-
version: "v1",
|
|
229
|
-
}),
|
|
230
|
-
getBlockByVersion: jest.fn().mockReturnValue({
|
|
231
|
-
block_height: "1",
|
|
232
|
-
block_hash: "83ca6d",
|
|
233
|
-
}),
|
|
234
|
-
}));
|
|
235
|
-
|
|
236
|
-
mockedNetwork.mockResolvedValue(
|
|
237
|
-
Promise.resolve({
|
|
238
|
-
data: {
|
|
239
|
-
account: {
|
|
240
|
-
account_number: 1,
|
|
241
|
-
sequence: 0,
|
|
242
|
-
pub_key: { key: "k", "@type": "type" },
|
|
243
|
-
base_account: {
|
|
244
|
-
account_number: 2,
|
|
245
|
-
sequence: 42,
|
|
246
|
-
pub_key: { key: "k2", "@type": "type2" },
|
|
247
|
-
},
|
|
248
|
-
},
|
|
249
|
-
block_height: "999",
|
|
250
|
-
},
|
|
251
|
-
status: 200,
|
|
252
|
-
headers: {} as any,
|
|
253
|
-
statusText: "",
|
|
254
|
-
config: {
|
|
255
|
-
headers: {} as any,
|
|
256
|
-
},
|
|
257
|
-
}),
|
|
258
|
-
);
|
|
259
|
-
|
|
260
|
-
mockedApolloClient.mockImplementation(() => ({
|
|
261
|
-
query: async () => ({
|
|
262
|
-
data: {
|
|
263
|
-
account_transactions: [{ transaction_version: 1 }],
|
|
264
|
-
},
|
|
265
|
-
loading: false,
|
|
266
|
-
networkStatus: 7,
|
|
267
|
-
}),
|
|
268
|
-
}));
|
|
269
|
-
|
|
270
|
-
const api = new AptosAPI("aptos");
|
|
271
|
-
const accountInfo = await api.getAccountInfo("APTOS_1_ADDRESS", "1");
|
|
272
|
-
|
|
273
|
-
expect(accountInfo.balance).toEqual(new BigNumber(0));
|
|
274
|
-
expect(accountInfo.transactions).toEqual([
|
|
275
|
-
{
|
|
276
|
-
type: "user_transaction",
|
|
277
|
-
version: "v1",
|
|
278
|
-
block: {
|
|
279
|
-
height: 1,
|
|
280
|
-
hash: "83ca6d",
|
|
281
|
-
},
|
|
282
|
-
},
|
|
283
|
-
]);
|
|
284
|
-
expect(accountInfo.blockHeight).toEqual(999);
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
it("returns no transactions if it the address is empty", async () => {
|
|
288
|
-
mockedAptos.mockImplementation(() => ({
|
|
289
|
-
view: jest.fn().mockReturnValue(["123"]),
|
|
290
|
-
getTransactionByVersion: jest.fn().mockReturnValue({
|
|
291
|
-
type: "user_transaction",
|
|
292
|
-
version: "v1",
|
|
293
|
-
}),
|
|
294
|
-
getBlockByVersion: jest.fn().mockReturnValue({
|
|
295
|
-
block_height: "1",
|
|
296
|
-
block_hash: "83ca6d",
|
|
297
|
-
}),
|
|
298
|
-
}));
|
|
35
|
+
it("should return an API object with alpaca api methods", () => {
|
|
36
|
+
const api: Api<AptosAsset, AptosExtra, AptosSender, AptosFeeParameters> =
|
|
37
|
+
createApi(mockAptosConfig);
|
|
299
38
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
account_number: 2,
|
|
309
|
-
sequence: 42,
|
|
310
|
-
pub_key: { key: "k2", "@type": "type2" },
|
|
311
|
-
},
|
|
312
|
-
},
|
|
313
|
-
block_height: "999",
|
|
314
|
-
},
|
|
315
|
-
status: 200,
|
|
316
|
-
headers: {} as any,
|
|
317
|
-
statusText: "",
|
|
318
|
-
config: {
|
|
319
|
-
headers: {} as any,
|
|
320
|
-
},
|
|
321
|
-
}),
|
|
322
|
-
);
|
|
323
|
-
|
|
324
|
-
mockedApolloClient.mockImplementation(() => ({
|
|
325
|
-
query: async () => ({
|
|
326
|
-
data: {
|
|
327
|
-
account_transactions: [{ transaction_version: 1 }],
|
|
328
|
-
},
|
|
329
|
-
loading: false,
|
|
330
|
-
networkStatus: 7,
|
|
331
|
-
}),
|
|
332
|
-
}));
|
|
333
|
-
|
|
334
|
-
const api = new AptosAPI("aptos");
|
|
335
|
-
const accountInfo = await api.getAccountInfo("", "1");
|
|
336
|
-
|
|
337
|
-
expect(accountInfo.balance).toEqual(new BigNumber(123));
|
|
338
|
-
expect(accountInfo.transactions).toEqual([]);
|
|
339
|
-
expect(accountInfo.blockHeight).toEqual(999);
|
|
340
|
-
});
|
|
341
|
-
|
|
342
|
-
it("returns a null transaction if it fails to getTransactionByVersion", async () => {
|
|
343
|
-
mockedAptos.mockImplementation(() => ({
|
|
344
|
-
view: jest.fn().mockReturnValue(["123"]),
|
|
345
|
-
getTransactionByVersion: jest.fn().mockImplementation(() => {
|
|
346
|
-
throw new Error("error");
|
|
347
|
-
}),
|
|
348
|
-
getBlockByVersion: jest.fn().mockReturnValue({
|
|
349
|
-
block_height: "1",
|
|
350
|
-
block_hash: "83ca6d",
|
|
351
|
-
}),
|
|
352
|
-
}));
|
|
353
|
-
|
|
354
|
-
mockedNetwork.mockResolvedValue(
|
|
355
|
-
Promise.resolve({
|
|
356
|
-
data: {
|
|
357
|
-
account: {
|
|
358
|
-
account_number: 1,
|
|
359
|
-
sequence: 0,
|
|
360
|
-
pub_key: { key: "k", "@type": "type" },
|
|
361
|
-
base_account: {
|
|
362
|
-
account_number: 2,
|
|
363
|
-
sequence: 42,
|
|
364
|
-
pub_key: { key: "k2", "@type": "type2" },
|
|
365
|
-
},
|
|
366
|
-
},
|
|
367
|
-
block_height: "999",
|
|
368
|
-
},
|
|
369
|
-
status: 200,
|
|
370
|
-
headers: {} as any,
|
|
371
|
-
statusText: "",
|
|
372
|
-
config: {
|
|
373
|
-
headers: {} as any,
|
|
374
|
-
},
|
|
375
|
-
}),
|
|
376
|
-
);
|
|
377
|
-
|
|
378
|
-
mockedApolloClient.mockImplementation(() => ({
|
|
379
|
-
query: async () => ({
|
|
380
|
-
data: {
|
|
381
|
-
account_transactions: [{ transaction_version: 1 }],
|
|
382
|
-
},
|
|
383
|
-
loading: false,
|
|
384
|
-
networkStatus: 7,
|
|
385
|
-
}),
|
|
386
|
-
}));
|
|
387
|
-
|
|
388
|
-
const api = new AptosAPI("aptos");
|
|
389
|
-
const accountInfo = await api.getAccountInfo("APTOS_1_ADDRESS", "1");
|
|
390
|
-
|
|
391
|
-
expect(accountInfo.balance).toEqual(new BigNumber(123));
|
|
392
|
-
expect(accountInfo.transactions).toEqual([null]);
|
|
393
|
-
expect(accountInfo.blockHeight).toEqual(999);
|
|
394
|
-
});
|
|
395
|
-
});
|
|
396
|
-
|
|
397
|
-
describe("estimateGasPrice", () => {
|
|
398
|
-
it("estimates the gas price", async () => {
|
|
399
|
-
const gasEstimation = { gas_estimate: 100 };
|
|
400
|
-
mockedAptos.mockImplementation(() => ({
|
|
401
|
-
getGasPriceEstimation: jest.fn().mockReturnValue(gasEstimation),
|
|
402
|
-
}));
|
|
403
|
-
|
|
404
|
-
const api = new AptosAPI("aptos");
|
|
405
|
-
const gasPrice = await api.estimateGasPrice();
|
|
406
|
-
|
|
407
|
-
expect(gasPrice.gas_estimate).toEqual(100);
|
|
408
|
-
});
|
|
39
|
+
// Check that methods are set with what we expect
|
|
40
|
+
expect(api.broadcast).toBeDefined();
|
|
41
|
+
expect(api.combine).toBeDefined();
|
|
42
|
+
expect(api.craftTransaction).toBeDefined();
|
|
43
|
+
expect(api.estimateFees).toBeDefined();
|
|
44
|
+
expect(api.getBalance).toBeDefined();
|
|
45
|
+
expect(api.lastBlock).toBeDefined();
|
|
46
|
+
expect(api.listOperations).toBeDefined();
|
|
409
47
|
});
|
|
48
|
+
});
|
|
410
49
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
functionArguments: ["0x13", 1],
|
|
415
|
-
};
|
|
416
|
-
|
|
417
|
-
it("generates a transaction without expireTimestamp", async () => {
|
|
418
|
-
const options = {
|
|
419
|
-
maxGasAmount: "100",
|
|
420
|
-
gasUnitPrice: "50",
|
|
421
|
-
};
|
|
422
|
-
|
|
423
|
-
const mockSimple = jest.fn().mockImplementation(async () => ({
|
|
424
|
-
rawTransaction: null,
|
|
425
|
-
}));
|
|
426
|
-
mockedAptos.mockImplementation(() => ({
|
|
427
|
-
transaction: {
|
|
428
|
-
build: {
|
|
429
|
-
simple: mockSimple,
|
|
430
|
-
},
|
|
431
|
-
},
|
|
432
|
-
}));
|
|
433
|
-
|
|
434
|
-
const mockSimpleSpy = jest.spyOn({ simple: mockSimple }, "simple");
|
|
435
|
-
|
|
436
|
-
const api = new AptosAPI("aptos");
|
|
437
|
-
await api.generateTransaction("APTOS_1_ADDRESS", payload, options);
|
|
438
|
-
|
|
439
|
-
expect(mockSimpleSpy).toHaveBeenCalledWith({
|
|
440
|
-
data: payload,
|
|
441
|
-
options: {
|
|
442
|
-
maxGasAmount: Number(options.maxGasAmount),
|
|
443
|
-
gasUnitPrice: Number(options.gasUnitPrice),
|
|
444
|
-
},
|
|
445
|
-
sender: "APTOS_1_ADDRESS",
|
|
446
|
-
});
|
|
447
|
-
});
|
|
448
|
-
|
|
449
|
-
it("generates a transaction with default expireTimestamp", async () => {
|
|
450
|
-
const options = {
|
|
451
|
-
maxGasAmount: "100",
|
|
452
|
-
gasUnitPrice: "50",
|
|
453
|
-
};
|
|
454
|
-
|
|
455
|
-
const mockSimple = jest.fn().mockImplementation(async () => ({
|
|
456
|
-
rawTransaction: null,
|
|
457
|
-
}));
|
|
458
|
-
const mockGetLedgerInfo = jest.fn().mockImplementation(async () => ({
|
|
459
|
-
ledger_timestamp: "0",
|
|
460
|
-
}));
|
|
461
|
-
mockedAptos.mockImplementation(() => ({
|
|
462
|
-
transaction: {
|
|
463
|
-
build: {
|
|
464
|
-
simple: mockSimple,
|
|
465
|
-
},
|
|
466
|
-
},
|
|
467
|
-
getLedgerInfo: mockGetLedgerInfo,
|
|
468
|
-
}));
|
|
469
|
-
|
|
470
|
-
const mockSimpleSpy = jest.spyOn({ simple: mockSimple }, "simple");
|
|
471
|
-
|
|
472
|
-
const api = new AptosAPI("aptos");
|
|
473
|
-
await api.generateTransaction("APTOS_1_ADDRESS", payload, options);
|
|
474
|
-
|
|
475
|
-
expect(mockSimpleSpy).toHaveBeenCalledWith({
|
|
476
|
-
data: payload,
|
|
477
|
-
options: {
|
|
478
|
-
maxGasAmount: Number(options.maxGasAmount),
|
|
479
|
-
gasUnitPrice: Number(options.gasUnitPrice),
|
|
480
|
-
expireTimestamp: 120,
|
|
481
|
-
},
|
|
482
|
-
sender: "APTOS_1_ADDRESS",
|
|
483
|
-
});
|
|
484
|
-
});
|
|
485
|
-
|
|
486
|
-
it("throws an error when failing to build a transaction", async () => {
|
|
487
|
-
const options = {
|
|
488
|
-
maxGasAmount: "100",
|
|
489
|
-
gasUnitPrice: "50",
|
|
490
|
-
};
|
|
491
|
-
|
|
492
|
-
const mockSimple = jest.fn().mockImplementation(async () => null);
|
|
493
|
-
mockedAptos.mockImplementation(() => ({
|
|
494
|
-
transaction: {
|
|
495
|
-
build: {
|
|
496
|
-
simple: mockSimple,
|
|
497
|
-
},
|
|
498
|
-
},
|
|
499
|
-
}));
|
|
500
|
-
|
|
501
|
-
const api = new AptosAPI("aptos");
|
|
502
|
-
expect(
|
|
503
|
-
async () => await api.generateTransaction("APTOS_1_ADDRESS", payload, options),
|
|
504
|
-
).rejects.toThrow();
|
|
505
|
-
});
|
|
50
|
+
describe("lastBlock", () => {
|
|
51
|
+
beforeEach(() => {
|
|
52
|
+
mockedAptos = jest.mocked(Aptos);
|
|
506
53
|
});
|
|
507
54
|
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
const mockSimple = jest.fn().mockImplementation(async () => ({
|
|
511
|
-
rawTransaction: null,
|
|
512
|
-
}));
|
|
513
|
-
mockedAptos.mockImplementation(() => ({
|
|
514
|
-
transaction: {
|
|
515
|
-
simulate: {
|
|
516
|
-
simple: mockSimple,
|
|
517
|
-
},
|
|
518
|
-
},
|
|
519
|
-
}));
|
|
520
|
-
|
|
521
|
-
const mockSimpleSpy = jest.spyOn({ simple: mockSimple }, "simple");
|
|
522
|
-
|
|
523
|
-
const api = new AptosAPI("aptos");
|
|
524
|
-
const address = new Ed25519PublicKey("APTOS_1_ADDRESS");
|
|
525
|
-
const tx = new RawTransaction(
|
|
526
|
-
new AccountAddress(Uint8Array.from(Buffer.from("APTOS_2_ADDRESS"))),
|
|
527
|
-
BigInt(1),
|
|
528
|
-
"" as unknown as Serializable,
|
|
529
|
-
BigInt(100),
|
|
530
|
-
BigInt(50),
|
|
531
|
-
BigInt(1),
|
|
532
|
-
{ chainId: 1 } as ChainId,
|
|
533
|
-
);
|
|
534
|
-
await api.simulateTransaction(address, tx);
|
|
535
|
-
|
|
536
|
-
expect(mockSimpleSpy).toHaveBeenCalledWith({
|
|
537
|
-
signerPublicKey: address,
|
|
538
|
-
transaction: { rawTransaction: tx },
|
|
539
|
-
options: {
|
|
540
|
-
estimateGasUnitPrice: true,
|
|
541
|
-
estimateMaxGasAmount: true,
|
|
542
|
-
estimatePrioritizedGasUnitPrice: false,
|
|
543
|
-
},
|
|
544
|
-
});
|
|
545
|
-
});
|
|
55
|
+
afterEach(() => {
|
|
56
|
+
jest.resetAllMocks();
|
|
546
57
|
});
|
|
547
|
-
describe("broadcast", () => {
|
|
548
|
-
it("broadcasts the transaction", async () => {
|
|
549
|
-
mockedPost.mockImplementation(async () => ({ data: { hash: "ok" } }));
|
|
550
|
-
const mockedPostSpy = jest.spyOn({ post: mockedPost }, "post");
|
|
551
|
-
|
|
552
|
-
mockedAptos.mockImplementation(() => ({
|
|
553
|
-
config: "config",
|
|
554
|
-
}));
|
|
555
|
-
|
|
556
|
-
const api = new AptosAPI("aptos");
|
|
557
|
-
await api.broadcast("signature");
|
|
558
58
|
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
59
|
+
it("returns the last block information", async () => {
|
|
60
|
+
mockedAptos.mockImplementation(() => ({
|
|
61
|
+
getLedgerInfo: jest.fn().mockReturnValue({
|
|
62
|
+
block_height: "123",
|
|
63
|
+
}),
|
|
64
|
+
getBlockByHeight: jest.fn().mockReturnValue({
|
|
65
|
+
block_height: "123",
|
|
66
|
+
block_hash: "123hash",
|
|
67
|
+
block_timestamp: "1746021098623892",
|
|
68
|
+
first_version: "1",
|
|
69
|
+
last_version: "1",
|
|
70
|
+
}),
|
|
71
|
+
}));
|
|
72
|
+
|
|
73
|
+
const api: Api<AptosAsset, AptosExtra, AptosSender, AptosFeeParameters> =
|
|
74
|
+
createApi(mockAptosConfig);
|
|
75
|
+
|
|
76
|
+
expect(await api.lastBlock()).toStrictEqual({
|
|
77
|
+
height: 123,
|
|
78
|
+
hash: "123hash",
|
|
79
|
+
time: new Date(1746021098623892),
|
|
567
80
|
});
|
|
568
81
|
});
|
|
569
82
|
});
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import broadcast from "../../bridge/broadcast";
|
|
2
|
-
import { AptosAPI } from "../../
|
|
2
|
+
import { AptosAPI } from "../../network";
|
|
3
3
|
import { patchOperationWithHash } from "@ledgerhq/coin-framework/operation";
|
|
4
4
|
import type { Account, Operation, SignedOperation } from "@ledgerhq/types-live";
|
|
5
5
|
import BigNumber from "bignumber.js";
|
|
6
6
|
|
|
7
|
-
jest.mock("../../
|
|
7
|
+
jest.mock("../../network");
|
|
8
8
|
jest.mock("@ledgerhq/coin-framework/operation");
|
|
9
9
|
|
|
10
10
|
describe("broadcast", () => {
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
createFixtureTransactionWithSubAccount,
|
|
6
6
|
} from "../../bridge/bridge.fixture";
|
|
7
7
|
import buildTransaction from "../../bridge/buildTransaction";
|
|
8
|
-
import { AptosAPI } from "../../
|
|
8
|
+
import { AptosAPI } from "../../network";
|
|
9
9
|
import { normalizeTransactionOptions } from "../../bridge/logic";
|
|
10
10
|
import { InputEntryFunctionData } from "@aptos-labs/ts-sdk";
|
|
11
11
|
import { TransactionOptions } from "../../types";
|
|
@@ -21,7 +21,7 @@ jest.mock("../../bridge/logic", () => ({
|
|
|
21
21
|
DEFAULT_GAS_PRICE: 200,
|
|
22
22
|
}));
|
|
23
23
|
|
|
24
|
-
jest.mock("../../
|
|
24
|
+
jest.mock("../../network", () => {
|
|
25
25
|
return {
|
|
26
26
|
AptosAPI: function () {
|
|
27
27
|
return {
|
|
@@ -6,11 +6,11 @@ import {
|
|
|
6
6
|
createFixtureTransactionWithSubAccount,
|
|
7
7
|
} from "../../bridge/bridge.fixture";
|
|
8
8
|
import * as getFeesForTransaction from "../../bridge/getFeesForTransaction";
|
|
9
|
-
import { AptosAPI } from "../../
|
|
9
|
+
import { AptosAPI } from "../../network";
|
|
10
10
|
|
|
11
11
|
let simulateTransaction = jest.fn();
|
|
12
12
|
|
|
13
|
-
jest.mock("../../
|
|
13
|
+
jest.mock("../../network", () => {
|
|
14
14
|
return {
|
|
15
15
|
AptosAPI: function () {
|
|
16
16
|
return {
|