Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/gentle-mangos-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"live-mobile": patch
---

Add test ids to the Tezos staking-section rows (staked and unstaking) so e2e can target them distinctly from the delegation card
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Props = Readonly<{
onPress: () => void;
isLast?: boolean;
statusLabel?: string;
testID?: string;
}>;

export default function DelegationRow({
Expand All @@ -33,13 +34,14 @@ export default function DelegationRow({
onPress,
isLast = false,
statusLabel,
testID = "tezos-delegation-row",
}: Props) {
const { colors } = useTheme();
const { t } = useTranslation();

return (
<TouchableOpacity
testID="tezos-delegation-row"
testID={testID}
style={[
styles.row,
styles.wrapper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default function UnstakingRow({ position, unit, currency, onPress, isLast

return (
<DelegationRow
testID={`tezos-unstaking-row-${position.uid}`}
baker={baker}
address={address}
amount={position.amount}
Comment thread
Copilot marked this conversation as resolved.
Comment on lines 24 to 29
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ export default function TezosDelegation({ account }: Props) {
<View style={[styles.card, { backgroundColor: colors.card }]}>
{info.isStaked && (
<DelegationRow
testID="tezos-staking-row"
baker={currentBaker}
address={currentAddress}
amount={info.stakedBalance}
Expand Down
6 changes: 6 additions & 0 deletions e2e/mobile/page/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import SettingsPage from "./settings/settings.page";
import SpeculosPage from "./speculos.page";
import StakePage from "./trade/stake.page";
import TezosStakePage from "./trade/tezosStake.page";
import SwapPage from "./trade/swap.page";
import SwapLiveAppPage from "./liveApps/swapLiveApp";
import WalletTabNavigatorPage from "./wallet/walletTabNavigator.page";
Expand Down Expand Up @@ -76,6 +77,7 @@
private settingsGeneralPageInstance = lazyInit(SettingsGeneralPage);
private speculosPageInstance = lazyInit(SpeculosPage);
private stakePageInstance = lazyInit(StakePage);
private tezosStakePageInstance = lazyInit(TezosStakePage);

Check warning on line 80 in e2e/mobile/page/index.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Member 'tezosStakePageInstance' is never reassigned; mark it as `readonly`.

See more on https://sonarcloud.io/project/issues?id=LedgerHQ_ledger-live&issues=AZ72wee4BpqvSMkb5JfJ&open=AZ72wee4BpqvSMkb5JfJ&pullRequest=18901
private swapLiveAppInstance = lazyInit(SwapLiveAppPage);
private swapPageInstance = lazyInit(SwapPage);
private walletTabNavigatorPageInstance = lazyInit(WalletTabNavigatorPage);
Expand Down Expand Up @@ -190,6 +192,10 @@
return this.stakePageInstance();
}

public get tezosStake() {
return this.tezosStakePageInstance();
}

public get swap() {
return this.swapPageInstance();
}
Expand Down
102 changes: 102 additions & 0 deletions e2e/mobile/page/trade/tezosStake.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { Step } from "jest-allure2-reporter/api";

const accountScrollViewId = "account-screen-scrollView";

// Buttons built from ~/components/Button render their testID with an "enabled-"/"disabled-"
// prefix reflecting the disabled state; the amount continue buttons are only tappable once enabled.
const enabled = (id: string) => `enabled-${id}`;

export default class TezosStakePage {
// Stake flow (TezosStakeFlow)
stakeAmountInputId = "tezos-stake-amount-input";
stakeAmountContinueId = "tezos-stake-amount-continue";
// Unstake flow (TezosUnstakeFlow)
unstakeAmountInputId = "tezos-unstake-amount-input";
unstakeAmountContinueId = "tezos-unstake-amount-continue";
// Earning-choice chooser (TezosDelegationFlow -> TezosEarnRewards) and the delegation summary it leads to
earnRewardsStartButtonId = "tezos-earn-rewards-start-button";
delegationSummaryValidatorId = "tezos-delegation-summary-validator";
// Account staking-section cards (families/tezos/Delegations)
stakingRowId = "tezos-staking-row";
delegationRowId = "tezos-delegation-row";
// DelegationDrawer actions: Touchable sets testID to the analytics event when no explicit testID is given
stakeMoreActionId = "TezosStakeMore";
unstakeActionId = "TezosUnstake";
changeValidatorActionId = "TezosChangeBaker";
endDelegationActionId = "TezosEndDelegation";
// Unstake-required guard drawer
unstakeRequiredCloseId = "tezos-unstake-required-close";

@Step("Verify the earning-choice chooser is shown")
async verifyEarningChoice() {
await waitForElementById(this.earnRewardsStartButtonId);
}

@Step("Start earning from the earning-choice chooser")
async startEarning() {
await tapById(this.earnRewardsStartButtonId);
}

@Step("Verify the delegation summary is shown")
async verifyDelegationSummary() {
await waitForElementById(this.delegationSummaryValidatorId);
}

@Step("Fill stake amount $0")
async fillStakeAmount(amount: string) {
await waitForElementById(this.stakeAmountInputId);
await typeTextById(this.stakeAmountInputId, amount);
await waitForElementById(enabled(this.stakeAmountContinueId)); // Issue with RN75 : QAA-370
}

@Step("Continue from the stake amount step")
async continueStakeAmount() {
await tapById(enabled(this.stakeAmountContinueId));
}

@Step("Open the unstake flow from the staking section")
async openUnstakeFromStakingSection() {
await scrollToId(this.stakingRowId, accountScrollViewId);
await tapById(this.stakingRowId);
await waitForElementById(this.unstakeActionId);
await tapById(this.unstakeActionId);
}

@Step("Fill unstake amount $0")
async fillUnstakeAmount(amount: string) {
await waitForElementById(this.unstakeAmountInputId);
await typeTextById(this.unstakeAmountInputId, amount);
await waitForElementById(enabled(this.unstakeAmountContinueId)); // Issue with RN75 : QAA-370
}

@Step("Continue from the unstake amount step")
async continueUnstakeAmount() {
await tapById(enabled(this.unstakeAmountContinueId));
}

@Step("Open change-validator from the delegation section")
async openChangeValidator() {
await scrollToId(this.delegationRowId, accountScrollViewId);
await tapById(this.delegationRowId);
await waitForElementById(this.changeValidatorActionId);
await tapById(this.changeValidatorActionId);
}

@Step("Open stop-delegation from the delegation section")
async openStopDelegation() {
await scrollToId(this.delegationRowId, accountScrollViewId);
await tapById(this.delegationRowId);
await waitForElementById(this.endDelegationActionId);
await tapById(this.endDelegationActionId);
}

@Step("Verify the unstake-required guard is shown")
async verifyUnstakeRequired() {
await waitForElementById(this.unstakeRequiredCloseId);
}

@Step("Dismiss the unstake-required guard")
async dismissUnstakeRequired() {
await tapById(this.unstakeRequiredCloseId);
}
}
6 changes: 6 additions & 0 deletions e2e/mobile/specs/stake/changeValidatorBlockedTEZOS.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Account } from "@ledgerhq/live-common/e2e/enum/Account";
import { runUnstakeRequiredTezos } from "./stake";

// XTZ_2 (index 1) is DELEGATED + STAKED: changing validator is blocked until the user unstakes first.
const delegation = new Delegate(Account.XTZ_2, "N/A", "Ledger by Kiln");
runUnstakeRequiredTezos(delegation, "changeValidator", ["B2CQA-5919"]);
6 changes: 6 additions & 0 deletions e2e/mobile/specs/stake/earnChoiceTEZOS.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Account } from "@ledgerhq/live-common/e2e/enum/Account";
import { runEarningChoiceTezos } from "./stake";

// XTZ_1 (index 0) is funded + UNDELEGATED: with the staking flag on, Earn opens the earning-choice chooser.
const delegation = new Delegate(Account.XTZ_1, "N/A", "Ledger by Kiln");
runEarningChoiceTezos(delegation, ["B2CQA-5915"]);
6 changes: 6 additions & 0 deletions e2e/mobile/specs/stake/endDelegationBlockedTEZOS.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Account } from "@ledgerhq/live-common/e2e/enum/Account";
import { runUnstakeRequiredTezos } from "./stake";

// XTZ_2 (index 1) is DELEGATED + STAKED: stopping delegation is blocked until the user unstakes first.
const delegation = new Delegate(Account.XTZ_2, "N/A", "Ledger by Kiln");
runUnstakeRequiredTezos(delegation, "stopDelegation", ["B2CQA-5921"]);
148 changes: 148 additions & 0 deletions e2e/mobile/specs/stake/stake.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import { setEnv } from "@ledgerhq/live-env";
import { DelegateType } from "@ledgerhq/live-common/e2e/models/Delegate";
import { Team } from "@ledgerhq/live-common/e2e/enum/Team";
import { setTeamOwner } from "../../helpers/allure/allure-helper";

const TEZOS_STAKING_TAGS = [
"@NanoSP",
"@LNS",
"@NanoX",
"@Stax",
"@Flex",
"@NanoGen5",
"@tezos",
"@family-tezos",
];

// Mobile twin of desktop's lldTezosStaking; the staking screens, routing and the account-screen
// staking section are all gated on it (default off).
const STAKING_FEATURE_FLAGS = { llmTezosStaking: { enabled: true } };

async function initStakingAccount(delegation: DelegateType) {
await app.init({
speculosApp: delegation.account.currency.speculosApp,
cliCommands: [liveDataWithAddressCommand(delegation.account)],
featureFlags: STAKING_FEATURE_FLAGS,
});
await app.mainNavigation.waitForWallet40Ready();
}

async function goToTezosAccount(delegation: DelegateType) {
await app.portfolio.goToAccounts(delegation.account.currency.name);
await app.common.goToAccountByName(delegation.account.accountName);
}

function tagSuite(tmsLinks: string[], tags: string[]) {
setTeamOwner(Team.EARN);
tags.forEach(tag => $Tag(tag));
tmsLinks.forEach(tms => $TmsLink(tms));
}

export function runEarningChoiceTezos(
delegation: DelegateType,
tmsLinks: string[],
tags: string[] = TEZOS_STAKING_TAGS,
) {
setEnv("DISABLE_TRANSACTION_BROADCAST", true);
tagSuite(tmsLinks, tags);
describe("Earning choice on TEZOS", () => {
beforeAll(async () => {
await initStakingAccount(delegation);
});

it("Earning choice routes to the delegation summary", async () => {
await goToTezosAccount(delegation);
// Funded + undelegated => Earn opens the earning-choice chooser (not the legacy delegate starter).
await app.account.tapEarn();
await app.tezosStake.verifyEarningChoice();
await app.tezosStake.startEarning();
// Undelegated => the single chooser CTA leads into the delegation summary.
await app.tezosStake.verifyDelegationSummary();
});
});
}

export function runStakeTezos(
delegation: DelegateType,
tmsLinks: string[],
tags: string[] = TEZOS_STAKING_TAGS,
) {
// Broadcast off so CI never mutates the seed; the app still reaches the success screen.
setEnv("DISABLE_TRANSACTION_BROADCAST", true);
tagSuite(tmsLinks, tags);
describe("Stake flow on TEZOS", () => {
beforeAll(async () => {
await initStakingAccount(delegation);
});

it("Stake on a delegated account", async () => {
await app.speculos.goToSettings();
await app.speculos.activateExpertMode();
await goToTezosAccount(delegation);
// Already delegated => Earn opens the stake amount step directly (skipDelegation).
await app.account.tapEarn();
await app.tezosStake.fillStakeAmount(delegation.amount);
await app.tezosStake.continueStakeAmount();
// Tezos signs stake via the same on-device review flow as delegation.
await app.speculos.signDelegationTransaction(delegation);
await app.common.successViewDetails();
});
});
}

export function runUnstakeTezos(
delegation: DelegateType,
tmsLinks: string[],
tags: string[] = TEZOS_STAKING_TAGS,
) {
setEnv("DISABLE_TRANSACTION_BROADCAST", true);
tagSuite(tmsLinks, tags);
describe("Unstake flow on TEZOS", () => {
beforeAll(async () => {
await initStakingAccount(delegation);
});

it("Unstake from a staked account", async () => {
await app.speculos.goToSettings();
await app.speculos.activateExpertMode();
await goToTezosAccount(delegation);
// Delegated + staked => the staking section card opens the unstake action.
await app.tezosStake.openUnstakeFromStakingSection();
await app.tezosStake.fillUnstakeAmount(delegation.amount);
await app.tezosStake.continueUnstakeAmount();
await app.speculos.signDelegationTransaction(delegation);
await app.common.successViewDetails();
});
});
}

export function runUnstakeRequiredTezos(
delegation: DelegateType,
action: "changeValidator" | "stopDelegation",
tmsLinks: string[],
tags: string[] = TEZOS_STAKING_TAGS,
) {
setEnv("DISABLE_TRANSACTION_BROADCAST", true); // assertion-only: never signs or broadcasts
tagSuite(tmsLinks, tags);
const title =
action === "changeValidator"
? "Change validator is blocked while staked"
: "Stopping delegation is blocked while staked";
describe(`Unstake required guard on TEZOS - ${action}`, () => {
beforeAll(async () => {
await initStakingAccount(delegation);
});

it(title, async () => {
await goToTezosAccount(delegation);
// Delegated + staked => both actions hit the "unstake first" guard instead of the real flow.
if (action === "changeValidator") {
await app.tezosStake.openChangeValidator();
} else {
await app.tezosStake.openStopDelegation();
}
await app.tezosStake.verifyUnstakeRequired();
await app.tezosStake.dismissUnstakeRequired();
});
});
}
6 changes: 6 additions & 0 deletions e2e/mobile/specs/stake/stakeTEZOS.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Account } from "@ledgerhq/live-common/e2e/enum/Account";
import { runStakeTezos } from "./stake";

// XTZ_2 (index 1) is DELEGATED + STAKED: Earn opens the stake amount step directly.
const delegation = new Delegate(Account.XTZ_2, "0.005", "Ledger by Kiln");
runStakeTezos(delegation, ["B2CQA-5917"]);
6 changes: 6 additions & 0 deletions e2e/mobile/specs/stake/unstakeTEZOS.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Account } from "@ledgerhq/live-common/e2e/enum/Account";
import { runUnstakeTezos } from "./stake";

// XTZ_2 (index 1) is DELEGATED + STAKED: the account screen shows the staking section with the unstake action.
const delegation = new Delegate(Account.XTZ_2, "0.005", "Ledger by Kiln");
runUnstakeTezos(delegation, ["B2CQA-5918"]);
Loading