Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove from aptos blockchain from families #8897

Open
wants to merge 58 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
4f3b88c
chore: remove from aptos blockchain from families
jccguimaraes Jan 14, 2025
8f6e936
chore: remove from aptos blockchain from families
jccguimaraes Jan 14, 2025
a065bcf
Merge branch 'develop' into feat/coin-aptos
jccguimaraes Jan 15, 2025
3b96235
chore: remove from aptos blockchain from families
jccguimaraes Jan 15, 2025
3923584
chore: remove from aptos blockchain from families
jccguimaraes Jan 15, 2025
ccc7059
chore: remove from aptos blockchain from families
jccguimaraes Jan 15, 2025
0c416cb
chore: remove from aptos blockchain from families
jccguimaraes Jan 15, 2025
df8ca58
Merge branch 'develop' into feat/coin-aptos
jccguimaraes Jan 15, 2025
6fa7b65
chore: remove from aptos blockchain from families
jccguimaraes Jan 15, 2025
08a5621
chore: remove aptos blockchain from families
jccguimaraes Jan 15, 2025
7b80570
chore: remove aptos blockchain from families
jccguimaraes Jan 16, 2025
b60b41f
chore: remove aptos blockchain from families
jccguimaraes Jan 16, 2025
3dab3c8
chore: remove aptos blockchain from families
jccguimaraes Jan 16, 2025
abfa132
Merge branch 'develop' into feat/coin-aptos
jccguimaraes Jan 16, 2025
f58983f
chore: remove aptos blockchain from families
jccguimaraes Jan 16, 2025
5a0e380
test: update tests
jccguimaraes Jan 16, 2025
b6e5c2d
test: update bot test
jccguimaraes Jan 16, 2025
21e7ac4
test: api unit tests
semeano Jan 17, 2025
ab4fc2f
test: broadcast unit tests
semeano Jan 17, 2025
d1cc7df
Merge branch 'develop' into feat/coin-aptos
semeano Jan 17, 2025
c8deb53
chore: save work
semeano Jan 17, 2025
1b4a8b9
build: update packages
semeano Jan 17, 2025
cf9e952
test: fix unit tests
semeano Jan 17, 2025
cac2ac8
test: fix unit tests
semeano Jan 17, 2025
a4aacc3
fix: update aptos bot test
jccguimaraes Jan 17, 2025
12ea13c
test: fix unit tests
semeano Jan 17, 2025
cfcbd63
test: unit test for deviceTransactionConfig
semeano Jan 17, 2025
6f14cee
test: unit test for signer
semeano Jan 17, 2025
28a8720
test: unit test for network
semeano Jan 17, 2025
72f22ca
fix: remove script from package.json
semeano Jan 17, 2025
a91f967
fix: logic and logic tests
semeano Jan 20, 2025
c9d2649
chore: disable sign operation tests temporarily
semeano Jan 20, 2025
d36bc27
chore: remove commented code
semeano Jan 20, 2025
fdf6ba4
chore: move tests to __tests__
semeano Jan 20, 2025
4b33419
test: unit tests for sign operation
semeano Jan 21, 2025
60b232c
Merge branch 'develop' into feat/coin-aptos
semeano Jan 21, 2025
e318d46
chore: add changeset
semeano Jan 21, 2025
21d3326
fix: remove duplicated changeset
semeano Jan 21, 2025
3575f39
fix: update changeset summary
semeano Jan 21, 2025
1960697
fix: remove unused file
semeano Jan 21, 2025
ae3fe41
fix: remove comments
semeano Jan 21, 2025
89be594
fix: remove comments
semeano Jan 21, 2025
8b19cde
fix: remove catch argument
semeano Jan 21, 2025
3f8e06f
fix: remove comments
semeano Jan 21, 2025
b6a5784
fix: remove random account address
semeano Jan 21, 2025
a5c27d5
fix: remove commented code
semeano Jan 21, 2025
a733d70
fix: bridge integration test
semeano Jan 22, 2025
898d854
test: unit test for network
semeano Jan 23, 2025
01e1fcf
fix: wrong import path
semeano Jan 23, 2025
5e31781
fix: add unresolved and unused packages to ignore
semeano Jan 23, 2025
a45213b
build: remove unused package
semeano Jan 23, 2025
815ecfc
chore: restore e2e send test
semeano Jan 23, 2025
b31387c
chore: restore apdus
semeano Jan 23, 2025
afd204e
fix: getAccountShape
semeano Jan 23, 2025
05da067
test: fix unit tests for synchronization and network
semeano Jan 23, 2025
142ad95
test: update bridge integration tests snapshot
semeano Jan 23, 2025
6df7dd4
Merge branch 'develop' into feat/coin-aptos
semeano Jan 23, 2025
587ccac
fix: remove unused dependency
semeano Jan 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/brave-sheep-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@ledgerhq/hw-app-aptos": minor
"@ledgerhq/coin-aptos": minor
"ledger-live-desktop": minor
"live-mobile": minor
"@ledgerhq/live-common": minor
---

support: move aptos to its own coin module
1 change: 1 addition & 0 deletions apps/ledger-live-desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"dependencies": {
"@braze/web-sdk": "4.10.2",
"@ledgerhq/coin-bitcoin": "workspace:^",
"@ledgerhq/coin-aptos": "workspace:^",
"@ledgerhq/coin-cosmos": "workspace:^",
"@ledgerhq/coin-evm": "workspace:^",
"@ledgerhq/coin-filecoin": "workspace:^",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import {
AptosAccount,
Transaction,
TransactionStatus,
} from "@ledgerhq/live-common/families/aptos/types";
import { Operation } from "@ledgerhq/types-live";
import { FieldComponentProps, LLDCoinFamily } from "../types";
import { AptosAccount, TransactionStatus } from "@ledgerhq/coin-aptos/lib/types/index";

export type AptosFamily = LLDCoinFamily<AptosAccount, Transaction, TransactionStatus, Operation>;
export type AptosFieldComponentProps = FieldComponentProps<
Expand Down
16 changes: 16 additions & 0 deletions libs/coin-modules/coin-aptos/.unimportedrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"ignoreUnresolved": ["follow-redirects", "form-data", "proxy-from-env"],
"ignoreUnused": ["@ledgerhq/devices", "invariant", "expect"],
"ignoreUnimported": [
"src/bridge/deviceTransactionConfig.ts",
"src/bridge/transaction.ts",
"src/bridge/bridge.fixture.ts",
"src/errors.ts",
"src/hw-signMessage.ts",
"src/test/bot-specs.ts",
"src/test/bridgeDatasetTest.ts",
"src/test/cli.ts",
"src/test/index.ts",
"src/test/speculos-deviceActions.ts"
]
}
8 changes: 8 additions & 0 deletions libs/coin-modules/coin-aptos/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */
module.exports = {
collectCoverageFrom: ["src/**/*.ts"],
coverageDirectory: "coverage",
preset: "ts-jest",
testEnvironment: "node",
testPathIgnorePatterns: ["lib/", "lib-es/", ".integration.test.ts"],
};
124 changes: 124 additions & 0 deletions libs/coin-modules/coin-aptos/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
{
"name": "@ledgerhq/coin-aptos",
"version": "1.3.2",
"description": "Ledger Aptos Coin integration",
"keywords": [
"Ledger",
"LedgerWallet",
"apt",
"Aptos",
"Hardware Wallet"
],
"repository": {
"type": "git",
"url": "https://github.com/LedgerHQ/ledger-live.git"
},
"bugs": {
"url": "https://github.com/LedgerHQ/ledger-live/issues"
},
"homepage": "https://github.com/LedgerHQ/ledger-live/tree/develop/libs/coin-modules/coin-aptos",
"publishConfig": {
"access": "public"
},
"typesVersions": {
"*": {
"lib/*": [
"lib/*"
],
"lib-es/*": [
"lib-es/*"
],
"specs": [
"lib/test/bot-specs"
],
"*": [
"lib/*",
"lib/api/*",
"lib/bridge/*",
"lib/common-logic/*",
"lib/signer/*",
"lib/test/*",
"lib/types/*"
]
}
},
"exports": {
"./lib/*": "./lib/*.js",
"./lib-es/*": "./lib-es/*.js",
"./api": {
"require": "./lib/api/index.js",
"default": "./lib-es/api/index.js"
},
"./deviceTransactionConfig": {
"require": "./lib/bridge/deviceTransactionConfig.js",
"default": "./lib-es/bridge/deviceTransactionConfig.js"
},
"./signer": {
"require": "./lib/signer/index.js",
"default": "./lib-es/signer/index.js"
},
"./specs": {
"require": "./lib/test/bot-specs.js",
"default": "./lib-es/test/bot-specs.js"
},
"./transaction": {
"require": "./lib/bridge/transaction.js",
"default": "./lib-es/bridge/transaction.js"
},
"./types": {
"require": "./lib/types/index.js",
"default": "./lib-es/types/index.js"
},
"./*": {
"require": "./lib/*.js",
"default": "./lib-es/*.js"
},
".": {
"require": "./lib/index.js",
"default": "./lib-es/index.js"
},
"./package.json": "./package.json"
},
"license": "Apache-2.0",
"dependencies": {
"@ledgerhq/coin-framework": "workspace:^",
"@ledgerhq/cryptoassets": "workspace:^",
"@ledgerhq/devices": "workspace:*",
"@ledgerhq/errors": "workspace:^",
"@ledgerhq/live-env": "workspace:^",
"@ledgerhq/live-network": "workspace:^",
"@ledgerhq/logs": "workspace:^",
"@ledgerhq/types-live": "workspace:^",
"@aptos-labs/ts-sdk": "^1.33.1",
"@apollo/client": "^3.12.6",
"@noble/hashes": "1.7.0",
"bignumber.js": "^9.1.2",
"graphql": "^16.10.0",
"invariant": "^2.2.4",
"lodash": "^4.17.21",
"rxjs": "^7.8.1"
},
"devDependencies": {
"@faker-js/faker": "^9.4.0",
"@types/invariant": "^2.2.37",
"@types/jest": "^29.5.14",
"@types/lodash": "^4.17.14",
"@types/semver": "^7.5.8",
"jest": "^29.7.0",
"ts-jest": "^29.2.5",
"axios": "^1.7.9",
"react": "^18.3.1"
},
"scripts": {
"clean": "rimraf lib lib-es",
"build": "tsc && tsc -m ES6 --outDir lib-es",
"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",
"prewatch": "pnpm build",
"watch": "tsc --watch",
"doc": "documentation readme src/** --section=API --pe ts --re ts --re d.ts",
"lint": "eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx --cache",
"lint:fix": "pnpm lint --fix",
"test": "jest",
"unimported": "unimported"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ import {
Serializable,
post,
} from "@aptos-labs/ts-sdk";
import network from "@ledgerhq/live-network/network";
import network from "@ledgerhq/live-network";
import BigNumber from "bignumber.js";
import { AptosAPI } from ".";
import { Account } from "../../../e2e/enum/Account";
import { AptosAPI } from "../../api";

jest.mock("@aptos-labs/ts-sdk");
jest.mock("@apollo/client");
let mockedAptos;
let mockedApolloClient;
let mockedPost;
let mockedAptos: jest.Mocked<any>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to inject the type for the generic Mocked ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I do that, I get a Type 'MockedObjectDeep<typeof Aptos>' is not assignable to type 'Mocked<Aptos>'
If I do

Suggested change
let mockedAptos: jest.Mocked<any>;
let mockedAptos: jest.MockedObjectDeep<typeof Aptos>;

I get Type '{ getAccountInfo: Mock<any, any, any>; }' is missing the following properties from type 'Aptos': config, account, ans, coin, and 111 more

Basically I'm not able to mock it without adding all of its properties.

Let me know if there's a better way to do it, I also hate to use any.

Copy link
Contributor

@themooneer themooneer Jan 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you try with jest.MockedObjectDeep<Partial<typeof Aptos>>?

Copy link
Contributor

@semeano semeano Jan 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With Partial, I get an error on line 71:

mockedAptos.mockImplementation(() => ({
  getAccountInfo: mockGetAccountInfo,
}));

mockImplementation does not exist

And if I remove mockedAptos = jest.mocked(Aptos); from line 27, and add the following inside the tests

mockedAptos = jest.mocked(Aptos).mockImplementation(() => ({
  getAccountInfo: mockGetAccountInfo,
}));

I get a similar error as before:
Type '{ getAccountInfo: Mock<any, any, any>; }' is missing the following properties from type 'Aptos': config, account, ans, coin, and 111 more.ts

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok ! no worries, i'll resolve this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@themooneer can you describe what is that you plan to do? Thanks

let mockedApolloClient: jest.Mocked<any>;
let mockedPost = jest.fn();

jest.mock("@ledgerhq/live-network/network");
const mockedNetwork = jest.mocked(network);
Expand Down Expand Up @@ -69,19 +68,17 @@ describe("Aptos API", () => {
describe("getAccount", () => {
it("calls getAccountInfo", async () => {
const mockGetAccountInfo = jest.fn();
mockedAptos.mockImplementation(() => {
return {
getAccountInfo: mockGetAccountInfo,
};
});
mockedAptos.mockImplementation(() => ({
getAccountInfo: mockGetAccountInfo,
}));

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

const api = new AptosAPI("aptos");
await api.getAccount(Account.APTOS_1.address);
await api.getAccount("address");

expect(mockGetAccountSpy).toHaveBeenCalledWith({
accountAddress: Account.APTOS_1.address,
accountAddress: "address",
});
});
});
Expand Down Expand Up @@ -135,7 +132,7 @@ describe("Aptos API", () => {
}));

const api = new AptosAPI("aptos");
const accountInfo = await api.getAccountInfo(Account.APTOS_1.address, "1");
const accountInfo = await api.getAccountInfo("APTOS_1_ADDRESS", "1");
themooneer marked this conversation as resolved.
Show resolved Hide resolved

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

const api = new AptosAPI("aptos");
const accountInfo = await api.getAccountInfo(Account.APTOS_1.address, "1");
const accountInfo = await api.getAccountInfo("APTOS_1_ADDRESS", "1");

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

const api = new AptosAPI("aptos");
const accountInfo = await api.getAccountInfo(Account.APTOS_1.address, "1");
const accountInfo = await api.getAccountInfo("APTOS_1_ADDRESS", "1");

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

const api = new AptosAPI("aptos");
await api.generateTransaction(Account.APTOS_1.address, payload, options);
await api.generateTransaction("APTOS_1_ADDRESS", payload, options);

expect(mockSimpleSpy).toHaveBeenCalledWith({
data: payload,
options: {
maxGasAmount: Number(options.maxGasAmount),
gasUnitPrice: Number(options.gasUnitPrice),
},
sender: Account.APTOS_1.address,
sender: "APTOS_1_ADDRESS",
});
});

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

const api = new AptosAPI("aptos");
await api.generateTransaction(Account.APTOS_1.address, payload, options);
await api.generateTransaction("APTOS_1_ADDRESS", payload, options);

expect(mockSimpleSpy).toHaveBeenCalledWith({
data: payload,
Expand All @@ -412,7 +409,7 @@ describe("Aptos API", () => {
gasUnitPrice: Number(options.gasUnitPrice),
expireTimestamp: 120,
},
sender: Account.APTOS_1.address,
sender: "APTOS_1_ADDRESS",
});
});

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

const api = new AptosAPI("aptos");
expect(
async () => await api.generateTransaction(Account.APTOS_1.address, payload, options),
async () => await api.generateTransaction("APTOS_1_ADDRESS", payload, options),
).rejects.toThrow();
});
});
Expand All @@ -454,9 +451,9 @@ describe("Aptos API", () => {
const mockSimpleSpy = jest.spyOn({ simple: mockSimple }, "simple");

const api = new AptosAPI("aptos");
const address = new Ed25519PublicKey(Account.APTOS_1.address);
const address = new Ed25519PublicKey("APTOS_1_ADDRESS");
const tx = new RawTransaction(
new AccountAddress(Uint8Array.from(Buffer.from(Account.APTOS_2.address))),
new AccountAddress(Uint8Array.from(Buffer.from("APTOS_2_ADDRESS"))),
BigInt(1),
"" as unknown as Serializable,
BigInt(100),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import broadcast from "./broadcast";
import { AptosAPI } from "./api";
import { patchOperationWithHash } from "./../../operation";
import broadcast from "../../bridge/broadcast";
import { AptosAPI } from "../../api";
import { patchOperationWithHash } from "@ledgerhq/coin-framework/operation";
import type { Account, Operation, SignedOperation } from "@ledgerhq/types-live";
import BigNumber from "bignumber.js";

jest.mock("./api");
jest.mock("./../../operation");
jest.mock("@ledgerhq/logs");
jest.mock("../../api");
jest.mock("@ledgerhq/coin-framework/operation");

describe("broadcast", () => {
const mockAccount: Account = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { createFixtureAccount } from "../../mock/fixtures/cryptoCurrencies";
import createTransaction from "./createTransaction";
import buildTransaction from "./buildTransaction";
import { AptosAPI } from "./api";
import { normalizeTransactionOptions } from "./logic";
import { createFixtureAccount, createFixtureTransaction } from "../../bridge/bridge.fixture";
import buildTransaction from "../../bridge/buildTransaction";
import { AptosAPI } from "../../api";
import { normalizeTransactionOptions } from "../../bridge/logic";
import { InputEntryFunctionData } from "@aptos-labs/ts-sdk";
import { TransactionOptions } from "./types";
import { TransactionOptions } from "../../types";

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

jest.mock("./logic", () => ({
jest.mock("../../bridge/logic", () => ({
normalizeTransactionOptions: jest.fn(() => ({
maxGasAmount: "100",
gasUnitPrice: "200",
Expand All @@ -17,7 +16,7 @@ jest.mock("./logic", () => ({
DEFAULT_GAS_PRICE: 200,
}));

jest.mock("./api", () => {
jest.mock("../../api", () => {
return {
AptosAPI: function () {
return {
Expand All @@ -30,7 +29,7 @@ jest.mock("./api", () => {
describe("buildTransaction Test", () => {
it("should return tx", async () => {
const account = createFixtureAccount();
const transaction = createTransaction();
const transaction = createFixtureTransaction();
const aptosClient = new AptosAPI(account.currency.id);
const result = await buildTransaction(account, transaction, aptosClient);

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

expect(mockedNormalizeTransactionOptions.mock.calls[0][0]).toEqual({
maxGasAmount: "100",
gasUnitPrice: "200",
maxGasAmount: "0",
gasUnitPrice: "0",
});

expect(generateTransactionArgs[0]).toBe("0x01");
expect(generateTransactionArgs[0]).toBe("address");
expect(generateTransactionArgs[1]).toEqual({
function: "0x1::aptos_account::transfer_coins",
typeArguments: ["0x1::aptos_coin::AptosCoin"],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BigNumber from "bignumber.js";
import createTransaction from "./createTransaction";
import createTransaction from "../../bridge/createTransaction";

jest.mock("./logic", () => ({
jest.mock("../../bridge/logic", () => ({
DEFAULT_GAS: 100,
DEFAULT_GAS_PRICE: 200,
}));
Expand Down
Loading
Loading