From 9bed32c0e78d7498d602433e45b0bf986c53178e Mon Sep 17 00:00:00 2001 From: Samy RABAH-MONTAROU Date: Wed, 4 Sep 2024 20:02:46 +0200 Subject: [PATCH] fix cosmos delegation flaky e2e test due to rounding error --- apps/ledger-live-mobile/e2e/specs/delegate/cosmos.spec.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/ledger-live-mobile/e2e/specs/delegate/cosmos.spec.ts b/apps/ledger-live-mobile/e2e/specs/delegate/cosmos.spec.ts index dcfd94a5d8d5..9cbd8ed1d96b 100644 --- a/apps/ledger-live-mobile/e2e/specs/delegate/cosmos.spec.ts +++ b/apps/ledger-live-mobile/e2e/specs/delegate/cosmos.spec.ts @@ -8,6 +8,7 @@ import { } from "../../models/currencies"; import { Application } from "../../page"; import DeviceAction from "../../models/DeviceAction"; +import BigNumber from "bignumber.js"; let app: Application; let deviceAction: DeviceAction; @@ -37,7 +38,12 @@ describe("Cosmos delegate flow", () => { const unit = getAccountUnit(testAccount); const usableAmount = testAccount.spendableBalance.minus(COSMOS_MIN_SAFE).minus(COSMOS_MIN_FEES); - const delegatedAmount = usableAmount.div(100 / delegatedPercent).integerValue(); + // rounding to avoid floating point errors + // NOTE: we could allow for some precision error here to avoid rounding issues + const delegatedAmount = usableAmount + .multipliedBy(delegatedPercent) + .div(100) + .integerValue(BigNumber.ROUND_CEIL); const remainingAmount = usableAmount.minus(delegatedAmount); await app.stake.selectCurrency(testedCurrency);