Skip to content

Commit f1ea0eb

Browse files
chore: remove from aptos blockchain from families (#8897)
* chore: remove from aptos blockchain from families * chore: remove from aptos blockchain from families * chore: remove from aptos blockchain from families * chore: remove from aptos blockchain from families * chore: remove from aptos blockchain from families * chore: remove from aptos blockchain from families * chore: remove from aptos blockchain from families * chore: remove aptos blockchain from families * chore: remove aptos blockchain from families * chore: remove aptos blockchain from families * chore: remove aptos blockchain from families * chore: remove aptos blockchain from families * test: update tests * test: update bot test * test: api unit tests * test: broadcast unit tests * chore: save work * build: update packages * test: fix unit tests * test: fix unit tests * fix: update aptos bot test * test: fix unit tests * test: unit test for deviceTransactionConfig * test: unit test for signer * test: unit test for network * fix: remove script from package.json * fix: logic and logic tests * chore: disable sign operation tests temporarily * chore: remove commented code * chore: move tests to __tests__ * test: unit tests for sign operation * chore: add changeset * fix: remove duplicated changeset * fix: update changeset summary * fix: remove unused file * fix: remove comments * fix: remove comments * fix: remove catch argument * fix: remove comments * fix: remove random account address * fix: remove commented code * fix: bridge integration test * test: unit test for network * fix: wrong import path * fix: add unresolved and unused packages to ignore * build: remove unused package * chore: restore e2e send test * chore: restore apdus * fix: getAccountShape * test: fix unit tests for synchronization and network * test: update bridge integration tests snapshot * fix: remove unused dependency --------- Co-authored-by: Pedro Semeano <[email protected]>
1 parent d7aa57e commit f1ea0eb

File tree

79 files changed

+2395
-1229
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+2395
-1229
lines changed

.changeset/brave-sheep-accept.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"@ledgerhq/hw-app-aptos": minor
3+
"@ledgerhq/coin-aptos": minor
4+
"ledger-live-desktop": minor
5+
"live-mobile": minor
6+
"@ledgerhq/live-common": minor
7+
---
8+
9+
support: move aptos to its own coin module

apps/ledger-live-desktop/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"dependencies": {
5555
"@braze/web-sdk": "4.10.2",
5656
"@ledgerhq/coin-bitcoin": "workspace:^",
57+
"@ledgerhq/coin-aptos": "workspace:^",
5758
"@ledgerhq/coin-cosmos": "workspace:^",
5859
"@ledgerhq/coin-evm": "workspace:^",
5960
"@ledgerhq/coin-filecoin": "workspace:^",

apps/ledger-live-desktop/src/renderer/families/aptos/types.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
import {
2-
AptosAccount,
3-
Transaction,
4-
TransactionStatus,
5-
} from "@ledgerhq/live-common/families/aptos/types";
61
import { Operation } from "@ledgerhq/types-live";
72
import { FieldComponentProps, LLDCoinFamily } from "../types";
3+
import { AptosAccount, TransactionStatus } from "@ledgerhq/coin-aptos/lib/types/index";
84

95
export type AptosFamily = LLDCoinFamily<AptosAccount, Transaction, TransactionStatus, Operation>;
106
export type AptosFieldComponentProps = FieldComponentProps<
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"ignoreUnresolved": ["follow-redirects", "form-data", "proxy-from-env"],
3+
"ignoreUnused": ["@ledgerhq/devices", "invariant", "expect"],
4+
"ignoreUnimported": [
5+
"src/bridge/deviceTransactionConfig.ts",
6+
"src/bridge/transaction.ts",
7+
"src/bridge/bridge.fixture.ts",
8+
"src/errors.ts",
9+
"src/hw-signMessage.ts",
10+
"src/test/bot-specs.ts",
11+
"src/test/bridgeDatasetTest.ts",
12+
"src/test/cli.ts",
13+
"src/test/index.ts",
14+
"src/test/speculos-deviceActions.ts"
15+
]
16+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */
2+
module.exports = {
3+
collectCoverageFrom: ["src/**/*.ts"],
4+
coverageDirectory: "coverage",
5+
preset: "ts-jest",
6+
testEnvironment: "node",
7+
testPathIgnorePatterns: ["lib/", "lib-es/", ".integration.test.ts"],
8+
};
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
{
2+
"name": "@ledgerhq/coin-aptos",
3+
"version": "1.3.2",
4+
"description": "Ledger Aptos Coin integration",
5+
"keywords": [
6+
"Ledger",
7+
"LedgerWallet",
8+
"apt",
9+
"Aptos",
10+
"Hardware Wallet"
11+
],
12+
"repository": {
13+
"type": "git",
14+
"url": "https://github.com/LedgerHQ/ledger-live.git"
15+
},
16+
"bugs": {
17+
"url": "https://github.com/LedgerHQ/ledger-live/issues"
18+
},
19+
"homepage": "https://github.com/LedgerHQ/ledger-live/tree/develop/libs/coin-modules/coin-aptos",
20+
"publishConfig": {
21+
"access": "public"
22+
},
23+
"typesVersions": {
24+
"*": {
25+
"lib/*": [
26+
"lib/*"
27+
],
28+
"lib-es/*": [
29+
"lib-es/*"
30+
],
31+
"specs": [
32+
"lib/test/bot-specs"
33+
],
34+
"*": [
35+
"lib/*",
36+
"lib/api/*",
37+
"lib/bridge/*",
38+
"lib/common-logic/*",
39+
"lib/signer/*",
40+
"lib/test/*",
41+
"lib/types/*"
42+
]
43+
}
44+
},
45+
"exports": {
46+
"./lib/*": "./lib/*.js",
47+
"./lib-es/*": "./lib-es/*.js",
48+
"./api": {
49+
"require": "./lib/api/index.js",
50+
"default": "./lib-es/api/index.js"
51+
},
52+
"./deviceTransactionConfig": {
53+
"require": "./lib/bridge/deviceTransactionConfig.js",
54+
"default": "./lib-es/bridge/deviceTransactionConfig.js"
55+
},
56+
"./signer": {
57+
"require": "./lib/signer/index.js",
58+
"default": "./lib-es/signer/index.js"
59+
},
60+
"./specs": {
61+
"require": "./lib/test/bot-specs.js",
62+
"default": "./lib-es/test/bot-specs.js"
63+
},
64+
"./transaction": {
65+
"require": "./lib/bridge/transaction.js",
66+
"default": "./lib-es/bridge/transaction.js"
67+
},
68+
"./types": {
69+
"require": "./lib/types/index.js",
70+
"default": "./lib-es/types/index.js"
71+
},
72+
"./*": {
73+
"require": "./lib/*.js",
74+
"default": "./lib-es/*.js"
75+
},
76+
".": {
77+
"require": "./lib/index.js",
78+
"default": "./lib-es/index.js"
79+
},
80+
"./package.json": "./package.json"
81+
},
82+
"license": "Apache-2.0",
83+
"dependencies": {
84+
"@ledgerhq/coin-framework": "workspace:^",
85+
"@ledgerhq/cryptoassets": "workspace:^",
86+
"@ledgerhq/devices": "workspace:*",
87+
"@ledgerhq/errors": "workspace:^",
88+
"@ledgerhq/live-env": "workspace:^",
89+
"@ledgerhq/live-network": "workspace:^",
90+
"@ledgerhq/logs": "workspace:^",
91+
"@ledgerhq/types-live": "workspace:^",
92+
"@aptos-labs/ts-sdk": "^1.33.1",
93+
"@apollo/client": "^3.12.6",
94+
"@noble/hashes": "1.7.0",
95+
"bignumber.js": "^9.1.2",
96+
"graphql": "^16.10.0",
97+
"invariant": "^2.2.4",
98+
"lodash": "^4.17.21",
99+
"rxjs": "^7.8.1"
100+
},
101+
"devDependencies": {
102+
"@faker-js/faker": "^9.4.0",
103+
"@types/invariant": "^2.2.37",
104+
"@types/jest": "^29.5.14",
105+
"@types/lodash": "^4.17.14",
106+
"@types/semver": "^7.5.8",
107+
"jest": "^29.7.0",
108+
"ts-jest": "^29.2.5",
109+
"axios": "^1.7.9",
110+
"react": "^18.3.1"
111+
},
112+
"scripts": {
113+
"clean": "rimraf lib lib-es",
114+
"build": "tsc && tsc -m ES6 --outDir lib-es",
115+
"coverage": "jest --coverage --testPathIgnorePatterns='/bridge.integration.test.ts|node_modules|lib-es|lib/' --coveragePathIgnorePatterns='src/test|src/types|src/index.ts|src/bridge/bridge.fixture.ts' --passWithNoTests && mv coverage/coverage-final.json coverage/coverage-aptos.json",
116+
"prewatch": "pnpm build",
117+
"watch": "tsc --watch",
118+
"doc": "documentation readme src/** --section=API --pe ts --re ts --re d.ts",
119+
"lint": "eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx --cache",
120+
"lint:fix": "pnpm lint --fix",
121+
"test": "jest",
122+
"unimported": "unimported"
123+
}
124+
}

libs/ledger-live-common/src/families/aptos/api/index.test.ts renamed to libs/coin-modules/coin-aptos/src/__tests__/api/index.test.ts

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@ import {
99
Serializable,
1010
post,
1111
} from "@aptos-labs/ts-sdk";
12-
import network from "@ledgerhq/live-network/network";
12+
import network from "@ledgerhq/live-network";
1313
import BigNumber from "bignumber.js";
14-
import { AptosAPI } from ".";
15-
import { Account } from "../../../e2e/enum/Account";
14+
import { AptosAPI } from "../../api";
1615

1716
jest.mock("@aptos-labs/ts-sdk");
1817
jest.mock("@apollo/client");
19-
let mockedAptos;
20-
let mockedApolloClient;
21-
let mockedPost;
18+
let mockedAptos: jest.Mocked<any>;
19+
let mockedApolloClient: jest.Mocked<any>;
20+
let mockedPost = jest.fn();
2221

2322
jest.mock("@ledgerhq/live-network/network");
2423
const mockedNetwork = jest.mocked(network);
@@ -69,19 +68,17 @@ describe("Aptos API", () => {
6968
describe("getAccount", () => {
7069
it("calls getAccountInfo", async () => {
7170
const mockGetAccountInfo = jest.fn();
72-
mockedAptos.mockImplementation(() => {
73-
return {
74-
getAccountInfo: mockGetAccountInfo,
75-
};
76-
});
71+
mockedAptos.mockImplementation(() => ({
72+
getAccountInfo: mockGetAccountInfo,
73+
}));
7774

7875
const mockGetAccountSpy = jest.spyOn({ getAccount: mockGetAccountInfo }, "getAccount");
7976

8077
const api = new AptosAPI("aptos");
81-
await api.getAccount(Account.APTOS_1.address);
78+
await api.getAccount("address");
8279

8380
expect(mockGetAccountSpy).toHaveBeenCalledWith({
84-
accountAddress: Account.APTOS_1.address,
81+
accountAddress: "address",
8582
});
8683
});
8784
});
@@ -135,7 +132,7 @@ describe("Aptos API", () => {
135132
}));
136133

137134
const api = new AptosAPI("aptos");
138-
const accountInfo = await api.getAccountInfo(Account.APTOS_1.address, "1");
135+
const accountInfo = await api.getAccountInfo("APTOS_1_ADDRESS", "1");
139136

140137
expect(accountInfo.balance).toEqual(new BigNumber(123));
141138
expect(accountInfo.transactions).toEqual([
@@ -201,7 +198,7 @@ describe("Aptos API", () => {
201198
}));
202199

203200
const api = new AptosAPI("aptos");
204-
const accountInfo = await api.getAccountInfo(Account.APTOS_1.address, "1");
201+
const accountInfo = await api.getAccountInfo("APTOS_1_ADDRESS", "1");
205202

206203
expect(accountInfo.balance).toEqual(new BigNumber(0));
207204
expect(accountInfo.transactions).toEqual([
@@ -319,7 +316,7 @@ describe("Aptos API", () => {
319316
}));
320317

321318
const api = new AptosAPI("aptos");
322-
const accountInfo = await api.getAccountInfo(Account.APTOS_1.address, "1");
319+
const accountInfo = await api.getAccountInfo("APTOS_1_ADDRESS", "1");
323320

324321
expect(accountInfo.balance).toEqual(new BigNumber(123));
325322
expect(accountInfo.transactions).toEqual([null]);
@@ -367,15 +364,15 @@ describe("Aptos API", () => {
367364
const mockSimpleSpy = jest.spyOn({ simple: mockSimple }, "simple");
368365

369366
const api = new AptosAPI("aptos");
370-
await api.generateTransaction(Account.APTOS_1.address, payload, options);
367+
await api.generateTransaction("APTOS_1_ADDRESS", payload, options);
371368

372369
expect(mockSimpleSpy).toHaveBeenCalledWith({
373370
data: payload,
374371
options: {
375372
maxGasAmount: Number(options.maxGasAmount),
376373
gasUnitPrice: Number(options.gasUnitPrice),
377374
},
378-
sender: Account.APTOS_1.address,
375+
sender: "APTOS_1_ADDRESS",
379376
});
380377
});
381378

@@ -403,7 +400,7 @@ describe("Aptos API", () => {
403400
const mockSimpleSpy = jest.spyOn({ simple: mockSimple }, "simple");
404401

405402
const api = new AptosAPI("aptos");
406-
await api.generateTransaction(Account.APTOS_1.address, payload, options);
403+
await api.generateTransaction("APTOS_1_ADDRESS", payload, options);
407404

408405
expect(mockSimpleSpy).toHaveBeenCalledWith({
409406
data: payload,
@@ -412,7 +409,7 @@ describe("Aptos API", () => {
412409
gasUnitPrice: Number(options.gasUnitPrice),
413410
expireTimestamp: 120,
414411
},
415-
sender: Account.APTOS_1.address,
412+
sender: "APTOS_1_ADDRESS",
416413
});
417414
});
418415

@@ -433,7 +430,7 @@ describe("Aptos API", () => {
433430

434431
const api = new AptosAPI("aptos");
435432
expect(
436-
async () => await api.generateTransaction(Account.APTOS_1.address, payload, options),
433+
async () => await api.generateTransaction("APTOS_1_ADDRESS", payload, options),
437434
).rejects.toThrow();
438435
});
439436
});
@@ -454,9 +451,9 @@ describe("Aptos API", () => {
454451
const mockSimpleSpy = jest.spyOn({ simple: mockSimple }, "simple");
455452

456453
const api = new AptosAPI("aptos");
457-
const address = new Ed25519PublicKey(Account.APTOS_1.address);
454+
const address = new Ed25519PublicKey("APTOS_1_ADDRESS");
458455
const tx = new RawTransaction(
459-
new AccountAddress(Uint8Array.from(Buffer.from(Account.APTOS_2.address))),
456+
new AccountAddress(Uint8Array.from(Buffer.from("APTOS_2_ADDRESS"))),
460457
BigInt(1),
461458
"" as unknown as Serializable,
462459
BigInt(100),

libs/ledger-live-common/src/families/aptos/broadcast.test.ts renamed to libs/coin-modules/coin-aptos/src/__tests__/bridge/broadcast.test.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import broadcast from "./broadcast";
2-
import { AptosAPI } from "./api";
3-
import { patchOperationWithHash } from "./../../operation";
1+
import broadcast from "../../bridge/broadcast";
2+
import { AptosAPI } from "../../api";
3+
import { patchOperationWithHash } from "@ledgerhq/coin-framework/operation";
44
import type { Account, Operation, SignedOperation } from "@ledgerhq/types-live";
55
import BigNumber from "bignumber.js";
66

7-
jest.mock("./api");
8-
jest.mock("./../../operation");
9-
jest.mock("@ledgerhq/logs");
7+
jest.mock("../../api");
8+
jest.mock("@ledgerhq/coin-framework/operation");
109

1110
describe("broadcast", () => {
1211
const mockAccount: Account = {

libs/ledger-live-common/src/families/aptos/buildTransaction.test.ts renamed to libs/coin-modules/coin-aptos/src/__tests__/bridge/buildTransaction.test.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
import { createFixtureAccount } from "../../mock/fixtures/cryptoCurrencies";
2-
import createTransaction from "./createTransaction";
3-
import buildTransaction from "./buildTransaction";
4-
import { AptosAPI } from "./api";
5-
import { normalizeTransactionOptions } from "./logic";
1+
import { createFixtureAccount, createFixtureTransaction } from "../../bridge/bridge.fixture";
2+
import buildTransaction from "../../bridge/buildTransaction";
3+
import { AptosAPI } from "../../api";
4+
import { normalizeTransactionOptions } from "../../bridge/logic";
65
import { InputEntryFunctionData } from "@aptos-labs/ts-sdk";
7-
import { TransactionOptions } from "./types";
6+
import { TransactionOptions } from "../../types";
87

98
const generateTransaction = jest.fn(() => "tx");
109

11-
jest.mock("./logic", () => ({
10+
jest.mock("../../bridge/logic", () => ({
1211
normalizeTransactionOptions: jest.fn(() => ({
1312
maxGasAmount: "100",
1413
gasUnitPrice: "200",
@@ -17,7 +16,7 @@ jest.mock("./logic", () => ({
1716
DEFAULT_GAS_PRICE: 200,
1817
}));
1918

20-
jest.mock("./api", () => {
19+
jest.mock("../../api", () => {
2120
return {
2221
AptosAPI: function () {
2322
return {
@@ -30,7 +29,7 @@ jest.mock("./api", () => {
3029
describe("buildTransaction Test", () => {
3130
it("should return tx", async () => {
3231
const account = createFixtureAccount();
33-
const transaction = createTransaction();
32+
const transaction = createFixtureTransaction();
3433
const aptosClient = new AptosAPI(account.currency.id);
3534
const result = await buildTransaction(account, transaction, aptosClient);
3635

@@ -47,11 +46,11 @@ describe("buildTransaction Test", () => {
4746
generateTransaction.mock.calls[0];
4847

4948
expect(mockedNormalizeTransactionOptions.mock.calls[0][0]).toEqual({
50-
maxGasAmount: "100",
51-
gasUnitPrice: "200",
49+
maxGasAmount: "0",
50+
gasUnitPrice: "0",
5251
});
5352

54-
expect(generateTransactionArgs[0]).toBe("0x01");
53+
expect(generateTransactionArgs[0]).toBe("address");
5554
expect(generateTransactionArgs[1]).toEqual({
5655
function: "0x1::aptos_account::transfer_coins",
5756
typeArguments: ["0x1::aptos_coin::AptosCoin"],

libs/ledger-live-common/src/families/aptos/createTransaction.test.ts renamed to libs/coin-modules/coin-aptos/src/__tests__/bridge/createTransaction.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import BigNumber from "bignumber.js";
2-
import createTransaction from "./createTransaction";
2+
import createTransaction from "../../bridge/createTransaction";
33

4-
jest.mock("./logic", () => ({
4+
jest.mock("../../bridge/logic", () => ({
55
DEFAULT_GAS: 100,
66
DEFAULT_GAS_PRICE: 200,
77
}));

0 commit comments

Comments
 (0)