Skip to content

Commit

Permalink
feat: add bot filter by feature
Browse files Browse the repository at this point in the history
  • Loading branch information
hedi-edelbloute committed Jan 15, 2025
1 parent 04af7d7 commit dfda688
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 4 deletions.
8 changes: 8 additions & 0 deletions .changeset/wicked-timers-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@ledgerhq/live-common": minor
"@ledgerhq/coin-framework": minor
"@ledgerhq/coin-bitcoin": patch
"@ledgerhq/coin-cosmos": patch
---

Bot feature : Add filter for features
1 change: 1 addition & 0 deletions .github/workflows/bot-nonreg-nitrogen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ jobs:
BOT_ENVIRONMENT: production
# We don't run these currencies daily because fees are expensive
BOT_DISABLED_CURRENCIES: bitcoin,ethereum,qtum,decred,cardano,axelar,cosmos,secret_network,avalanche_c_chain,bsc,filecoin,tron,cronos,fantom,boba,telos_evm,polygon_zk_evm,polkadot
BOT_FILTER_FEATURES: send
1 change: 1 addition & 0 deletions .github/workflows/bot-nonreg-oxygen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ jobs:
BOT_ENVIRONMENT: production
# We only run these currencies on a weekly basis because fees are expensive
BOT_FILTER_CURRENCIES: qtum,decred,cardano,axelar,cosmos,secret_network,avalanche_c_chain,bsc,filecoin,tron,cronos,fantom,boba,telos_evm,polygon_zk_evm,polkadot
BOT_FILTER_FEATURES: send
4 changes: 4 additions & 0 deletions .github/workflows/bot-testing-nitrogen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ on:
currencies:
description: currency ids to test, separated with commas (,)
required: false
features:
description: features to test(send,sendMax,tokens,staking)
required: false
speculos_websocket:
description: check to use speculos with Websocket
type: boolean
Expand Down Expand Up @@ -48,4 +51,5 @@ jobs:
BOT_ENVIRONMENT: testing
BOT_FILTER_FAMILIES: ${{github.event.inputs.families}}
BOT_FILTER_CURRENCIES: ${{github.event.inputs.currencies}}
BOT_FILTER_FEATURES: ${{github.event.inputs.features}}
SPECULOS_USE_WEBSOCKET: ${{inputs.speculos_websocket}}
6 changes: 5 additions & 1 deletion libs/coin-framework/src/bot/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ export type TransactionRes<T extends TransactionCommon> = {
export type MutationSpec<T extends TransactionCommon> = {
// Name what this mutation is doing
name: string;
// related feature to test
feature?: MutationFeatureType;
// The maximum number of times to execute this mutation for a given test run
maxRun: number;
// Express the transaction to be done
Expand Down Expand Up @@ -118,7 +120,7 @@ export type AppSpec<T extends TransactionCommon> = {
testTimeout?: number;
// how much should we retry scan accounts if an error occurs
scanAccountsRetries?: number;
// if define, will run the mutations {multipleRuns} times in order to cover 2 txs in the same run and detect possible issues at the "second tx time"
// if defined, will run the mutations {multipleRuns} times in order to cover 2 txs in the same run and detect possible issues at the "second tx time"
multipleRuns?: number;
// if the nano app depends on an app, name of this app
dependency?: string | undefined;
Expand Down Expand Up @@ -266,3 +268,5 @@ export type FlowDesc<T extends TransactionCommon> = {
steps: Array<Step<T>>;
fallback?: (arg0: DeviceActionArg<T, State<T>>) => Step<T> | null | undefined;
};

export type MutationFeatureType = "send" | "sendMax" | "tokens" | "staking";
2 changes: 2 additions & 0 deletions libs/coin-modules/coin-bitcoin/src/specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ const bitcoinLikeMutations = ({
}: Arg = {}): MutationSpec<Transaction>[] => [
{
name: "move ~50%",
feature: "send",
maxRun: 1,
transaction: ({ account, siblings, bridge, maxSpendable }) => {
invariant(maxSpendable.gt(minimalAmount), "balance is too low");
Expand Down Expand Up @@ -282,6 +283,7 @@ const bitcoinLikeMutations = ({
},
{
name: "send max",
feature: "sendMax",
maxRun: 1,
transaction: ({ account, siblings, bridge, maxSpendable }) => {
invariant(maxSpendable.gt(minimalAmount), "balance is too low");
Expand Down
5 changes: 4 additions & 1 deletion libs/coin-modules/coin-cosmos/src/specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ function cosmosLikeMutations(minimalTransactionAmount: BigNumber): MutationSpec<
return [
{
name: "send some",
maxRun: 2,
feature: "send",
maxRun: 1,
testDestination: genericTestDestination,
test: ({ account, accountBeforeTransaction, operation }) => {
expect(account.balance.toString()).toBe(
Expand Down Expand Up @@ -148,6 +149,7 @@ function cosmosLikeMutations(minimalTransactionAmount: BigNumber): MutationSpec<
},
{
name: "send max",
feature: "sendMax",
maxRun: 1,
testDestination: genericTestDestination,
transaction: ({ account, siblings, bridge, maxSpendable }) => {
Expand Down Expand Up @@ -381,6 +383,7 @@ function cosmosLikeMutations(minimalTransactionAmount: BigNumber): MutationSpec<
},
{
name: "claim rewards",
feature: "staking",
maxRun: 1,
transaction: ({ account, bridge, maxSpendable }) => {
const { cosmosResources } = account as CosmosAccount;
Expand Down
12 changes: 11 additions & 1 deletion libs/ledger-live-common/src/bot/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ const {
BOT_FILTER_FAMILIES,
BOT_DISABLED_CURRENCIES,
BOT_DISABLED_FAMILIES,
BOT_FILTER_FEATURES,
} = process.env;

const arg: Partial<{
filter: Partial<{ currencies: string[]; families: string[]; mutation: string }>;
filter: Partial<{
currencies: string[];
families: string[];
mutation: string;
features: string[];
}>;
disabled: Partial<{ currencies: string[]; families: string[] }>;
}> = {};

Expand All @@ -34,4 +40,8 @@ if (BOT_DISABLED_FAMILIES) {
arg.disabled.families = BOT_DISABLED_FAMILIES.split(",");
}

if (BOT_FILTER_FEATURES) {
arg.filter.features = BOT_FILTER_FEATURES.split(",");
}

bot(arg);
15 changes: 15 additions & 0 deletions libs/ledger-live-common/src/bot/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ describe("getSpecs", () => {
expect(specs.every(spec => spec.currency.family === "bitcoin")).toEqual(true);
});

it("should filter by feature correctly", () => {
setSupportedCurrencies(["bitcoin"]);
const specs = getSpecs({ disabled: {}, filter: { features: ["send"] } });
expect(specs[0].mutations.length).toBeGreaterThan(0);
expect(specs[0].mutations.every(spec => spec.feature === "send")).toEqual(true);
});

it("should filter multiple features correctly", () => {
setSupportedCurrencies(["bitcoin"]);
const currentFilter = ["send", "sendMax"];
const specs = getSpecs({ disabled: {}, filter: { features: currentFilter } });
expect(specs[0].mutations.length).toBeGreaterThan(0);
expect(specs[0].mutations.every(spec => currentFilter.includes(spec.feature))).toEqual(true);
});

it("should disable currencies correctly", () => {
setSupportedCurrencies(["bitcoin", "ethereum", "digibyte"]);
const specs = getSpecs({ disabled: { currencies: ["digibyte"] }, filter: {} });
Expand Down
15 changes: 14 additions & 1 deletion libs/ledger-live-common/src/bot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ import { sha256 } from "../crypto";
import { getDefaultAccountName } from "@ledgerhq/live-wallet/accountName";

type Arg = Partial<{
filter: Partial<{ currencies: string[]; families: string[]; mutation: string }>;
filter: Partial<{
currencies: string[];
families: string[];
mutation: string;
features: string[];
}>;
disabled: Partial<{ currencies: string[]; families: string[] }>;
}>;
const usd = getFiatCurrencyByTicker("USD");
Expand Down Expand Up @@ -105,6 +110,7 @@ export function getSpecs({ disabled, filter }) {
const filteredCurrencies = filter?.currencies || [];
const filteredFamilies = filter?.families || [];
const filteredMutation = filter?.mutation;
const filteredFeatures = filter.features || [];
let disabledCurrencies = disabled?.currencies || [];
let disabledFamilies = disabled?.families || [];

Expand Down Expand Up @@ -155,6 +161,13 @@ export function getSpecs({ disabled, filter }) {
};
}

if (filteredFeatures) {
spec = {
...spec,
mutations: spec.mutations.filter(m => filteredFeatures.includes(m.feature)),
};
}

specs.push(spec);
}
}
Expand Down
4 changes: 4 additions & 0 deletions tools/actions/composites/bot/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ inputs:
BOT_FILTER_CURRENCIES:
description: "currencies to filter on"
required: false
BOT_FILTER_FEATURES:
description: "features to filter on"
required: false
BOT_DISABLED_FAMILIES:
description: "disabled families"
required: false
Expand Down Expand Up @@ -74,6 +77,7 @@ runs:
GITHUB_WORKFLOW: ${{ github.workflow }}
BOT_FILTER_FAMILIES: ${{ inputs.BOT_FILTER_FAMILIES }}
BOT_FILTER_CURRENCIES: ${{ inputs.BOT_FILTER_CURRENCIES }}
BOT_FILTER_FEATURES: ${{ inputs.BOT_FILTER_FEATURES }}
BOT_DISABLED_FAMILIES: ${{ inputs.BOT_DISABLED_FAMILIES }}
BOT_DISABLED_CURRENCIES: ${{ inputs.BOT_DISABLED_CURRENCIES }}
SHOW_LEGACY_NEW_ACCOUNT: ${{ inputs.SHOW_LEGACY_NEW_ACCOUNT }}
Expand Down

1 comment on commit dfda688

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

[Bot] Testing with 'Nitrogen' ($0.00) ⏲ 5ms

What is the bot and how does it work? Everything is documented here!

Details of the 0 mutations
Portfolio ($0.00) – Details of the 0 currencies
Spec (accounts) State Remaining Runs (est) funds?

Performance ⏲ 5ms

Time spent for each spec: (total across mutations)

Spec (accounts) preload scan re-sync tx status sign op broadcast test destination test
TOTAL N/A N/A N/A N/A N/A N/A N/A N/A

What is the bot and how does it work? Everything is documented here!

Please sign in to comment.