Skip to content

Commit

Permalink
fix: revert coin-fmk remove of areAllOperationsLoaded
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Prohaszka <stephane.prohaszka@ledger.fr>
  • Loading branch information
sprohaszka-ledger committed May 16, 2024
1 parent 891488d commit 66e571a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 45 deletions.
38 changes: 36 additions & 2 deletions libs/coin-framework/src/account/helpers.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import BigNumber from "bignumber.js";
import { CryptoCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets";
import type { Account, TokenAccount } from "@ledgerhq/types-live";
import type { Account, Operation, TokenAccount } from "@ledgerhq/types-live";
import { getTokenById } from "@ledgerhq/cryptoassets/tokens";
import {
emptyHistoryCache,
getAccountCurrency,
getAccountSpendableBalance,
getFeesCurrency,
} from ".";
import { isAccountEmpty, clearAccount } from "./helpers";
import { isAccountEmpty, clearAccount, areAllOperationsLoaded } from "./helpers";

const mockAccount = {} as Account;
const tokenAccount = {
Expand Down Expand Up @@ -219,3 +219,37 @@ describe(clearAccount.name, () => {
});
});
});

describe(areAllOperationsLoaded.name, () => {
describe("given an account with subAccounts", () => {
beforeEach(() => {
mockAccount.type = "Account";
mockAccount.operations = [];
mockAccount.operationsCount = 0;
mockAccount.subAccounts = [
{
operations: [],
operationsCount: 0,
},
{
operations: [{} as Operation],
operationsCount: 1,
},
] as TokenAccount[];
});
describe("when sub account operation aren't loaded", () => {
beforeEach(() => {
(mockAccount.subAccounts as TokenAccount[])[1].operations = [];
});
it("should return false", () => {
expect(areAllOperationsLoaded(mockAccount)).toEqual(false);
});
});

describe("when sub account operation are loaded", () => {
it("should return true", () => {
expect(areAllOperationsLoaded(mockAccount)).toEqual(true);
});
});
});
});
18 changes: 13 additions & 5 deletions libs/coin-framework/src/bridge/jsHelpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ describe("jsHelpers", () => {
describe("makeSync", () => {
it("returns a function to update account that give a new instance of account", async () => {
// Given
const account = createAccount("12");
const account = createAccount({
id: "12",
creationDate: new Date("2024-05-12T17:04:12"),
lastSyncDate: new Date("2024-05-12T17:04:12"),
});

// When
const accountUpdater = makeSync({
Expand All @@ -68,7 +72,11 @@ describe("jsHelpers", () => {

it("returns a account with a corrected formatted id", async () => {
// Given
const account = createAccount("12");
const account = createAccount({
id: "12",
creationDate: new Date("2024-05-12T17:04:12"),
lastSyncDate: new Date("2024-05-12T17:04:12"),
});

// When
const accountUpdater = makeSync({
Expand Down Expand Up @@ -105,12 +113,12 @@ const emptyHistoryCache = {

// Call once for all tests the currencies. Relies on real implementation to check also consistency.
const bitcoinCurrency = listCryptoCurrencies(true).find(c => c.id === "bitcoin")!;
function createAccount(id: string): Account {
function createAccount(init: Partial<Account>): Account {
const currency = bitcoinCurrency;

return {
type: "Account",
id,
id: init.id ?? "12",
seedIdentifier: "",
derivationMode: "",
index: 0,
Expand All @@ -119,7 +127,7 @@ function createAccount(id: string): Account {
used: true,
balance: new BigNumber(0),
spendableBalance: new BigNumber(0),
creationDate: new Date(),
creationDate: init.creationDate ?? new Date(),
blockHeight: 0,
currency,
operationsCount: 0,
Expand Down
38 changes: 0 additions & 38 deletions libs/ledger-live-common/src/account/helpers.test.ts

This file was deleted.

0 comments on commit 66e571a

Please sign in to comment.