-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[B2CQA-387] first detox cosmos delegation tests (#4974)
* test: first detox cosmos delegation tests * fix: fix remaining errors * chore: update cosmos integration tests snapshots
- Loading branch information
1 parent
81cd64d
commit ee4a5a8
Showing
10 changed files
with
276 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { getTextOfElement, tapById, waitForElementById } from "../helpers"; | ||
|
||
export default class StakePage { | ||
cosmosDelegationSummaryValidatorId = "cosmos-delegation-summary-validator"; | ||
cosmosDelegationSummaryValidator = () => getTextOfElement("cosmos-delegation-summary-validator"); | ||
cosmosDelegationSummaryAmountId = "cosmos-delegation-summary-amount"; | ||
cosmosDelegationAmountValue = () => getTextOfElement(this.cosmosDelegationSummaryAmountId); | ||
cosmosAssestsRemainingId = "cosmos-assets-remaining"; | ||
cosmosDelegatedRatioId = (delegatedPercent: number) => `delegate-ratio-${delegatedPercent}%`; | ||
cosmosAllAssestsUsedText = "cosmos-all-assets-used-text"; | ||
summaryContinueButtonId = "cosmos-summary-continue-button"; | ||
|
||
async selectCurrency(currencyId: string) { | ||
const id = "currency-row-" + currencyId; | ||
await waitForElementById(id); | ||
await tapById(id); | ||
} | ||
|
||
async selectAccount(accountId: string) { | ||
const id = "account-card-" + accountId; | ||
await waitForElementById(id); | ||
await tapById(id); | ||
} | ||
|
||
async delegationStart() { | ||
await tapById("cosmos-delegation-start-button"); | ||
await waitForElementById(this.cosmosDelegationSummaryValidatorId); | ||
} | ||
|
||
async setAmount(delegatedPercent: 25 | 50 | 75 | 100) { | ||
await waitForElementById(this.cosmosDelegationSummaryAmountId); | ||
await tapById(this.cosmosDelegationSummaryAmountId); | ||
await tapById(this.cosmosDelegatedRatioId(delegatedPercent)); | ||
const max = delegatedPercent == 100; | ||
const id = max ? this.cosmosAllAssestsUsedText : this.cosmosAssestsRemainingId; | ||
await waitForElementById(id); | ||
const assestsRemaining = max ? "0\u00a0ATOM" : (await getTextOfElement(id)).split(": ")[1]; | ||
await tapById("cosmos-delegation-amount-continue"); | ||
await waitForElementById(this.cosmosDelegationSummaryAmountId); | ||
const assestsDelagated = await this.cosmosDelegationAmountValue(); | ||
return [assestsDelagated, assestsRemaining]; | ||
} | ||
|
||
async summaryContinue() { | ||
await tapById(this.summaryContinueButtonId); | ||
} | ||
|
||
async successClose() { | ||
await waitForElementById("success-close-button"); | ||
await tapById("success-close-button"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { genAccount } from "@ledgerhq/live-common/mock/account"; | ||
import { | ||
getCryptoCurrencyById, | ||
setSupportedCurrencies, | ||
} from "@ledgerhq/live-common/currencies/index"; | ||
import { loadAccounts, loadBleState, loadConfig } from "../../bridge/server"; | ||
import PortfolioPage from "../../models/wallet/portfolioPage"; | ||
import StakePage from "../../models/stake"; | ||
import DeviceAction from "../../models/DeviceAction"; | ||
import { DeviceModelId } from "@ledgerhq/devices"; | ||
import { BigNumber } from "bignumber.js"; | ||
import { Unit } from "@ledgerhq/types-cryptoassets"; | ||
import { formatCurrencyUnit } from "@ledgerhq/live-common/currencies/index"; | ||
|
||
let portfolioPage: PortfolioPage; | ||
let stakePage: StakePage; | ||
let deviceAction: DeviceAction; | ||
|
||
const knownDevice = { | ||
name: "Nano X de test", | ||
id: "mock_1", | ||
modelId: DeviceModelId.nanoX, | ||
}; | ||
|
||
const testedCurrency = "cosmos"; | ||
const id = "cosmosid"; | ||
|
||
setSupportedCurrencies([testedCurrency]); | ||
const testedAccount = genAccount(id, { | ||
currency: getCryptoCurrencyById(testedCurrency), | ||
}); | ||
|
||
const COSMOS_MIN_SAFE = new BigNumber(100000); // 100000 uAtom | ||
const COSMOS_MIN_FEES = new BigNumber(6000); | ||
const formattedAmount = (unit: Unit, amount: BigNumber, showAllDigits = false) => | ||
// amount formatted with the same unit as what the input should use | ||
formatCurrencyUnit(unit, amount, { | ||
showCode: true, | ||
showAllDigits: showAllDigits, | ||
disableRounding: false, | ||
}); | ||
|
||
describe("Cosmos delegate flow", () => { | ||
beforeAll(async () => { | ||
loadConfig("onboardingcompleted", true); | ||
|
||
loadBleState({ knownDevices: [knownDevice] }); | ||
loadAccounts([testedAccount]); | ||
|
||
portfolioPage = new PortfolioPage(); | ||
deviceAction = new DeviceAction(knownDevice); | ||
stakePage = new StakePage(); | ||
|
||
await portfolioPage.waitForPortfolioPageToLoad(); | ||
}); | ||
|
||
it("open account stake flow", async () => { | ||
await portfolioPage.openTransferMenu(); | ||
await portfolioPage.navigateToStakeFromTransferMenu(); | ||
}); | ||
|
||
it("goes through the delegate flow", async () => { | ||
const delegatedPercent = 50; | ||
const usableAmount = testedAccount.spendableBalance | ||
.minus(COSMOS_MIN_SAFE) | ||
.minus(COSMOS_MIN_FEES); | ||
const delegatedAmount = usableAmount.div(100 / delegatedPercent).integerValue(); | ||
const remainingAmount = usableAmount.minus(delegatedAmount); | ||
|
||
await stakePage.selectCurrency(testedCurrency); | ||
await stakePage.selectAccount(testedAccount.id); | ||
|
||
const [assestsDelagated, assestsRemaining] = await stakePage.setAmount(delegatedPercent); | ||
expect(await stakePage.cosmosDelegationSummaryValidator()).toEqual("Ledger"); | ||
expect(assestsRemaining).toEqual(formattedAmount(testedAccount.unit, remainingAmount)); | ||
expect(assestsDelagated).toEqual(formattedAmount(testedAccount.unit, delegatedAmount, true)); | ||
|
||
await stakePage.summaryContinue(); | ||
await deviceAction.selectMockDevice(); | ||
await deviceAction.openApp(); | ||
await stakePage.successClose(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
ee4a5a8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
web-tools – ./apps/web-tools
ledger-live-tools.vercel.app
ledger-live.vercel.app
web-tools-ledgerhq.vercel.app
web-tools-git-develop-ledgerhq.vercel.app
live.ledger.tools