Skip to content

Commit

Permalink
fix: solana tests and linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhd committed Dec 25, 2023
1 parent b4b120f commit 9a39bc6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function SolanaFeeRow({ account, parentAccount, status }: Props)

const fees = (status as SolanaTransactionStatus).estimatedFees;

const unit = getAccountUnit(account.type === "TokenAccount" ? parentAccount : account);
const unit = getAccountUnit(account.type === "TokenAccount" ? parentAccount || account : account);
const currency = getAccountCurrency(account);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
import { encodeAccountIdWithTokenAccountAddress, MAX_MEMO_LENGTH } from "./logic";
import createTransaction from "./js-createTransaction";
import { compact } from "lodash/fp";
import { assertUnreachable } from "./utils";
import { SYSTEM_ACCOUNT_RENT_EXEMPT, assertUnreachable } from "./utils";
import { getEnv } from "@ledgerhq/live-env";
import { ChainAPI } from "./api";
import {
Expand Down Expand Up @@ -69,7 +69,7 @@ const testOnChainData = {
validatorAddress: "9QU2QSxhb24FUX3Tu2FpczXjpK3VYrvRudywSZaM29mF",
fees: {
stakeAccountRentExempt: 2282880,
systemAccountRentExempt: 890880,
systemAccountRentExempt: SYSTEM_ACCOUNT_RENT_EXEMPT,
lamportsPerSignature: 5000,
},
// --- maybe outdated or not real, fine for tests ---
Expand Down
13 changes: 9 additions & 4 deletions libs/ledger-live-common/src/families/solana/specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
acceptTransferTokensWithATACreationTransaction,
acceptTransferTransaction,
} from "./speculos-deviceActions";
import { assertUnreachable } from "./utils";
import { SYSTEM_ACCOUNT_RENT_EXEMPT, assertUnreachable } from "./utils";
import { getCurrentSolanaPreloadData } from "./js-preload-data";
import { sample } from "lodash/fp";
import BigNumber from "bignumber.js";
Expand Down Expand Up @@ -78,9 +78,14 @@ const solana: AppSpec<Transaction> = {
};
},
test: input => {
const { account } = input;
botTest("account balance should be zero", () =>
expect(account.spendableBalance.toNumber()).toBe(0),
const { accountBeforeTransaction, operation } = input;
const extimatedMaxSpendable = BigNumber.max(
accountBeforeTransaction.spendableBalance.minus(SYSTEM_ACCOUNT_RENT_EXEMPT),
0,
).toNumber();

botTest("operation value should be estimated max spendable", () =>
expect(operation.value.toNumber()).toBe(extimatedMaxSpendable),
);
expectCorrectBalanceChange(input);
expectCorrectMemo(input);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function formatAmount(c: CryptoCurrency | TokenCurrency, amount: number) {
// There's a bug on the device where the token currency is being displayed as "???"
// Temporarily replace "0.05 USDC" on "0.05 ???" to pass tokens tests
function formatTokenAmount(c: TokenCurrency, amount: number) {
return formatAmount(c, amount).replace(/\D+$/, "???");
return formatAmount(c, amount).replace(/\D+$/, " ???");
}

function findTokenAccount(account: Account, id: string) {
Expand Down
2 changes: 2 additions & 0 deletions libs/ledger-live-common/src/families/solana/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export const LEDGER_VALIDATOR: ValidatorsAppValidator = {
totalScore: 6,
};

export const SYSTEM_ACCOUNT_RENT_EXEMPT = 890880;

export const assertUnreachable = (_: never): never => {
throw new Error("unreachable assertion failed");
};
Expand Down

0 comments on commit 9a39bc6

Please sign in to comment.