Skip to content

Commit

Permalink
test: call directly cli function instead of using bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
abdurrahman-ledger committed Oct 17, 2024
1 parent 917c122 commit 0838329
Show file tree
Hide file tree
Showing 66 changed files with 23,404 additions and 39,339 deletions.
11 changes: 9 additions & 2 deletions apps/cli/src/commands/blockchain/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ import { generateMnemonic } from "bip39";
import { from } from "rxjs";
import { getEnv } from "@ledgerhq/live-env";
import { bot } from "@ledgerhq/live-common/bot/index";
import { currencyOpt } from "../../scan";
import { CurrencyCommonOpts, currencyOpt } from "../../scan";

export type BotJobOpts = CurrencyCommonOpts &
Partial<{
mutation: string;
filter?: { currencies: string[] };
}>;

export default {
description:
"Run a bot test engine with speculos that automatically create accounts and do transactions",
Expand All @@ -16,7 +23,7 @@ export default {
desc: "filter the mutation to run by a regexp pattern",
},
],
job: (arg: any) => {
job: (arg: BotJobOpts) => {
const SEED = getEnv("SEED");

if (!SEED) {
Expand Down
3 changes: 2 additions & 1 deletion apps/cli/src/commands/blockchain/botPortfolio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { listSupportedCurrencies } from "@ledgerhq/live-common/currencies/index"
import { getCurrencyBridge } from "@ledgerhq/live-common/bridge/index";
import { accountFormatters } from "@ledgerhq/live-common/account/index";
const blacklist = ["decred", "tezos", "stellar", "ethereum_classic"];
export type BotPortfolioJobOpts = { format: string };
export default {
description: "Use speculos and a list of supported coins to retrieve all accounts",
args: [
Expand All @@ -15,7 +16,7 @@ export default {
desc: "how to display the data",
},
],
job: (opts: { format: string }) => {
job: (opts: BotPortfolioJobOpts) => {
return from(listSupportedCurrencies()).pipe(
filter(c => !blacklist.includes(c.id) && !c.isTestnetFor),
map(currency =>
Expand Down
3 changes: 2 additions & 1 deletion apps/cli/src/commands/blockchain/broadcast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import { scan, scanCommonOpts } from "../../scan";
import type { ScanCommonOpts } from "../../scan";
import type { InferSignedOperationsOpts } from "../../signedOperation";
import { inferSignedOperations, inferSignedOperationsOpts } from "../../signedOperation";
export type BroadcastJobOpts = InferSignedOperationsOpts & ScanCommonOpts;
export default {
description: "Broadcast signed operation(s)",
args: [...scanCommonOpts, ...inferSignedOperationsOpts],
job: (opts: ScanCommonOpts & InferSignedOperationsOpts) =>
job: (opts: BroadcastJobOpts) =>
scan(opts).pipe(
concatMap(account =>
inferSignedOperations(account, opts).pipe(
Expand Down
4 changes: 3 additions & 1 deletion apps/cli/src/commands/blockchain/confirmOp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { formatOperation, toOperationRaw } from "@ledgerhq/live-common/account/i
import { decodeOperationId, findOperationInAccount } from "@ledgerhq/live-common/operation";
import { scan } from "../../scan";

export type ConfirmOpJobOpts = { id?: string; format?: "json" | "text" };

export default {
description:
"Quickly verify if an operation id exists with our explorers (by synchronising the parent account)",
Expand All @@ -20,7 +22,7 @@ export default {
desc: "how to display the data",
},
],
job: ({ id, format }: { id?: string; format?: "json" | "text" }) => {
job: ({ id, format }: ConfirmOpJobOpts) => {
if (!id) throw new Error("--id is required");
const { accountId } = decodeOperationId(id);
return scan({
Expand Down
4 changes: 3 additions & 1 deletion apps/cli/src/commands/blockchain/estimateMaxSpendable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ const format = (account: AccountLike, value) => {
return `${name}: ${amount}`;
};

export type EstimateMaxSpendableJobOpts = ScanCommonOpts;

export default {
description: "estimate the max spendable of an account",
args: [...scanCommonOpts],
job: (opts: ScanCommonOpts) =>
job: (opts: EstimateMaxSpendableJobOpts) =>
scan(opts).pipe(
concatMap(account => {
const bridge = getAccountBridge(account);
Expand Down
11 changes: 6 additions & 5 deletions apps/cli/src/commands/blockchain/generateTestScanAccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import { accountFormatters } from "@ledgerhq/live-common/account/index";
import { scan, scanCommonOpts } from "../../scan";
import type { ScanCommonOpts } from "../../scan";
import { Account } from "@ledgerhq/types-live";

export type GenerateTestScanAccountsJobOpts = ScanCommonOpts & {
format: string;
};

export default {
description: "Generate a test for scan accounts (live-common dataset)",
args: [
Expand All @@ -16,11 +21,7 @@ export default {
desc: "how to display the data",
},
],
job: (
opts: ScanCommonOpts & {
format: string;
},
) => {
job: (opts: GenerateTestScanAccountsJobOpts) => {
if (!opts.currency) throw new Error("-c currency is missing");
const apdus: string[] = [];
listen(log => {
Expand Down
4 changes: 3 additions & 1 deletion apps/cli/src/commands/blockchain/generateTestTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ const toJS = obj => {

const toTransactionStatusJS = status => toJS(status);

export type GenerateTestTransactionJobOpts = InferTransactionsOpts & ScanCommonOpts;

export default {
description: "Generate a test for transaction (live-common dataset)",
args: [...scanCommonOpts, ...inferTransactionsOpts],
job: (opts: ScanCommonOpts & InferTransactionsOpts) =>
job: (opts: GenerateTestTransactionJobOpts) =>
scan(opts).pipe(
switchMap(account =>
from(inferTransactions(account, opts)).pipe(
Expand Down
26 changes: 16 additions & 10 deletions apps/cli/src/commands/blockchain/getAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,21 @@ import { mergeMap } from "rxjs/operators";
import { asDerivationMode } from "@ledgerhq/coin-framework/derivation";
import { withDevice } from "@ledgerhq/live-common/hw/deviceAccess";
import getAddress from "@ledgerhq/live-common/hw/getAddress/index";
import { currencyOpt, deviceOpt, inferCurrency } from "../../scan";
import {
CurrencyCommonOpts,
currencyOpt,
DeviceCommonOpts,
deviceOpt,
inferCurrency,
} from "../../scan";

export type GetAddressJobOpts = CurrencyCommonOpts &
DeviceCommonOpts & {
path?: string;
derivationMode?: string;
verify?: boolean;
};

export default {
description: "Get an address with the device on specific derivations (advanced)",
args: [
Expand All @@ -26,15 +40,7 @@ export default {
desc: "also ask verification on device",
},
],
job: (
arg: Partial<{
currency: string;
device: string;
path: string;
derivationMode: string;
verify: boolean;
}>,
) =>
job: (arg: Partial<GetAddressJobOpts>) =>
inferCurrency(arg).pipe(
mergeMap(currency => {
if (!currency) {
Expand Down
4 changes: 4 additions & 0 deletions apps/cli/src/commands/blockchain/getTransactionStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ const getTransactionStatusFormatters = {
"STATUS " +
JSON.stringify(toTransactionStatusRaw(status, account.currency.family)),
};
export type GetTransactionStatusJobOpts = ScanCommonOpts &
InferTransactionsOpts & {
format: string;
};
export default {
description: "Prepare a transaction and returns 'TransactionStatus' meta information",
args: [
Expand Down
10 changes: 5 additions & 5 deletions apps/cli/src/commands/blockchain/receive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { getAccountBridge } from "@ledgerhq/live-common/bridge/index";
import { scan, scanCommonOpts } from "../../scan";
import type { ScanCommonOpts } from "../../scan";
import { asQR } from "../../qr";
export type ReceiveJobOpts = ScanCommonOpts & {
qr: boolean;
};

export default {
description: "Receive crypto-assets (verify on device)",
args: [
Expand All @@ -14,11 +18,7 @@ export default {
desc: "also display a QR Code",
},
],
job: (
opts: ScanCommonOpts & {
qr: boolean;
},
) =>
job: (opts: ReceiveJobOpts) =>
scan(opts).pipe(
concatMap(account =>
concat(
Expand Down
22 changes: 12 additions & 10 deletions apps/cli/src/commands/blockchain/satstack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ function requiredNodeConfig(nodeConfig) {
return nodeConfig;
}

export type SatstackJobOpts = {
"no-device": boolean;
"no-save": boolean;
device: string;
lss: string;
rpcHOST: string;
rpcUSER: string;
rpcPASSWORD: string;
rpcTLS: boolean;
};

export default {
description: "SatStack: Generate and manage lss.json file",
args: [
Expand Down Expand Up @@ -81,16 +92,7 @@ export default {
rpcUSER,
rpcPASSWORD,
rpcTLS,
}: {
"no-device": boolean;
"no-save": boolean;
device: string;
lss: string;
rpcHOST: string;
rpcUSER: string;
rpcPASSWORD: string;
rpcTLS: boolean;
}) => {
}: SatstackJobOpts) => {
setEnv("SATSTACK", true);
const maybeExistingConfigO = !lss
? of(null)
Expand Down
5 changes: 4 additions & 1 deletion apps/cli/src/commands/blockchain/satstackStatus.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { first } from "rxjs/operators";
import { statusObservable } from "@ledgerhq/live-common/families/bitcoin/satstack";
import { setEnv } from "@ledgerhq/live-env";

export type SatstackStatusJobOpts = { continuous?: boolean };

export default {
description: "Check StackSats status",
args: [
Expand All @@ -10,7 +13,7 @@ export default {
desc: "enable status polling",
},
],
job: ({ continuous }: { continuous?: boolean }) => {
job: ({ continuous }: SatstackStatusJobOpts) => {
setEnv("SATSTACK", true);

if (!continuous) {
Expand Down
11 changes: 4 additions & 7 deletions apps/cli/src/commands/blockchain/scanDescriptors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { deviceOpt, currencyOpt } from "../../scan";
import { deviceOpt, currencyOpt, CurrencyCommonOpts, DeviceCommonOpts } from "../../scan";
import { findCryptoCurrencyByKeyword } from "@ledgerhq/live-common/currencies/index";
import { scanDescriptors } from "@ledgerhq/coin-bitcoin/descriptor";
import { SignerContext } from "@ledgerhq/coin-bitcoin/lib/signer";
Expand All @@ -18,15 +18,12 @@ const createBitcoinSignerContext =
withDevice(deviceId)(transport => from(fn(new Btc({ transport, currency: currency.id })))),
);

export type ScanDescriptorsJobOpts = CurrencyCommonOpts & DeviceCommonOpts;

export default {
description: "Synchronize accounts with blockchain",
args: [deviceOpt, currencyOpt],
job: (
opts: Partial<{
device: string;
currency: string;
}>,
) =>
job: (opts: Partial<ScanDescriptorsJobOpts>) =>
scanDescriptors(
opts.device || "",
requiredCurrency(findCryptoCurrencyByKeyword(opts.currency || "bitcoin")),
Expand Down
17 changes: 9 additions & 8 deletions apps/cli/src/commands/blockchain/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ import { scan, scanCommonOpts } from "../../scan";
import type { ScanCommonOpts } from "../../scan";
import type { InferTransactionsOpts } from "../../transaction";
import { inferTransactions, inferTransactionsOpts } from "../../transaction";

export type SendJobOpts = ScanCommonOpts &
InferTransactionsOpts & {
"ignore-errors": boolean;
"disable-broadcast": boolean;
format: string;
};

export default {
description: "Send crypto-assets",
args: [
Expand All @@ -37,14 +45,7 @@ export default {
desc: "default | json | silent",
},
],
job: (
opts: ScanCommonOpts &
InferTransactionsOpts & {
"ignore-errors": boolean;
"disable-broadcast": boolean;
format: string;
},
) => {
job: (opts: SendJobOpts) => {
const l =
opts.format !== "json" && opts.format !== "silent" // eslint-disable-next-line no-console
? l => console.log(l)
Expand Down
10 changes: 8 additions & 2 deletions apps/cli/src/commands/blockchain/signMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import { from } from "rxjs";
import { switchMap } from "rxjs/operators";
import { withDevice } from "@ledgerhq/live-common/hw/deviceAccess";
import signMessage, { prepareMessageToSign } from "@ledgerhq/live-common/hw/signMessage/index";
import { scan, scanCommonOpts } from "../../scan";
import { scan, ScanCommonOpts, scanCommonOpts } from "../../scan";

export type SignMessageJobOpts = {
message: string;
path?: string;
parser?: "string" | "file";
} & ScanCommonOpts;

export default {
description: "Sign a message with the device on specific derivations (advanced)",
Expand All @@ -26,7 +32,7 @@ export default {
default: "String",
},
],
job: (opts: any) => {
job: (opts: SignMessageJobOpts) => {
return scan(opts).pipe(
switchMap(account => {
if (!account.currency) {
Expand Down
11 changes: 6 additions & 5 deletions apps/cli/src/commands/blockchain/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import { getCryptoCurrencyById } from "@ledgerhq/live-common/currencies/index";
import { getCurrencyBridge } from "@ledgerhq/live-common/bridge/index";
import { scan, scanCommonOpts } from "../../scan";
import type { ScanCommonOpts } from "../../scan";

export type SyncJobOpts = ScanCommonOpts & {
format: string;
};

export default {
description: "Synchronize accounts with blockchain",
args: [
Expand All @@ -16,11 +21,7 @@ export default {
desc: "how to display the data",
},
],
job: (
opts: ScanCommonOpts & {
format: string;
},
) =>
job: (opts: SyncJobOpts) =>
scan(opts).pipe(
switchMap(async account => {
const { currencyId } = decodeAccountId(account.id);
Expand Down
5 changes: 4 additions & 1 deletion apps/cli/src/commands/blockchain/testDetectOpCollision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ import { flattenAccounts } from "@ledgerhq/live-common/account/index";
import { scan, scanCommonOpts } from "../../scan";
import type { ScanCommonOpts } from "../../scan";
import type { Account } from "@ledgerhq/types-live";

export type TestDetectOpCollisionJobOpts = ScanCommonOpts;

export default {
description: "Detect operation collisions",
args: [...scanCommonOpts],
job: (opts: ScanCommonOpts) =>
job: (opts: TestDetectOpCollisionJobOpts) =>
scan(opts).pipe(
reduce((all: Account[], a) => all.concat(a), []),
concatMap(accounts => {
Expand Down
Loading

0 comments on commit 0838329

Please sign in to comment.