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 13, 2024
1 parent 14b1501 commit ba02bd0
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 57 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 { Account, SubAccount, TokenAccount } from "@ledgerhq/types-live";
import type { Account, Operation, SubAccount, 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 SubAccount[];
});
describe("when sub account operation aren't loaded", () => {
beforeEach(() => {
(mockAccount.subAccounts as SubAccount[])[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);
});
});
});
});
12 changes: 12 additions & 0 deletions libs/coin-framework/src/account/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,15 @@ export function getParentAccount(account: AccountLike, accounts: AccountLike[]):
}
}
}

export function areAllOperationsLoaded(account: AccountLike): boolean {
if (account.operationsCount !== account.operations.length) {
return false;
}

if (account.type === "Account" && account.subAccounts) {
return account.subAccounts.every(areAllOperationsLoaded);
}

return true;
}
1 change: 1 addition & 0 deletions libs/coin-framework/src/account/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export {
isAccount,
isTokenAccount,
getParentAccount,
areAllOperationsLoaded,
} from "./helpers";
export { addPendingOperation } from "./pending";
export { getReceiveFlowError, checkAccountSupported } from "./support";
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.

12 changes: 0 additions & 12 deletions libs/ledger-live-common/src/account/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,3 @@ export const getVotesCount = (
return 0;
}
};

export function areAllOperationsLoaded(account: AccountLike): boolean {
if (account.operationsCount !== account.operations.length) {
return false;
}

if (account.type === "Account" && account.subAccounts) {
return account.subAccounts.every(areAllOperationsLoaded);
}

return true;
}

1 comment on commit ba02bd0

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Bot] Testing with 'Nitrogen' ❌ 1 txs ($4.68) ⏲ 69.3s

❌ 1 specs have problems: Tezos

What is the bot and how does it work? Everything is documented here!

❌ 1 mutation errors
necessary accounts resynced in 0.27ms
▬ TezosWallet 3.0.3 on nanoS 2.1.0
→ FROM undefined: 5.28869 XTZ (152ops) (tz1aDK1uFAmnUXZ7KJPEmcCEFeYHiVZ56zVF on 44'/1729'/0'/0') tezbox#0 js:2:tezos:0240051fc51799e60dcc8870415b87fc4fd948e71b23fdc0d9b8ac7438cf7d4708:tezbox
max spendable ~5.28775
★ using mutation 'delegate unrevealed'
✔️ transaction 
DELEGATE 0 XTZ
TO tz1Scdr2HsZiQjc7bHMeBbmDRXYVvdhjJbBh
with fees=0.000371
with gasLimit=200
with storageLimit=0
(estimatedFees 0.000745)
STATUS (773ms)
  amount: 0 XTZ
  estimated fees: 0.000745 XTZ
  total spent: 0.000745 XTZ
errors: 
warnings: 
⚠️ Error: device action timeout. Recent events was:
{"text":"Review operation","x":13,"y":17,"w":107,"h":11}
{"text":"Operation (0)","x":26,"y":-1,"w":94,"h":11}
{"text":"Reveal","x":47,"y":10,"w":81,"h":11}
(totally spent 61.3s – ends at 2024-05-14T08:52:40.705Z)
⚠️ 2 spec hints
  • Spec Tezos:
    • mutations should define a test(): send unrevealed, send revealed, send max (non delegating), delegate unrevealed, delegate revealed, undelegate unrevealed, undelegate revealed
    • There are not enough accounts (3) to cover all mutations (7).
      Please increase the account target to at least 8 accounts
Details of the 1 mutations

Spec Tezos (3)

Spec Tezos found 3 Tezos accounts (preload: 175ms). Will use TezosWallet 3.0.3 on nanoS 2.1.0
undefined: 5.28869 XTZ (152ops) (tz1aDK1uFAmnUXZ7KJPEmcCEFeYHiVZ56zVF on 44'/1729'/0'/0') tezbox#0 js:2:tezos:0240051fc51799e60dcc8870415b87fc4fd948e71b23fdc0d9b8ac7438cf7d4708:tezbox
undefined: 0 XTZ (4ops) (tz1he4fPXP3c9fFrztYT3k7KyYuLb28arFNn on 44'/1729'/1'/0') tezbox#1 js:2:tezos:02fe3d777af5380ef0a431c4985772c9669743050cee5feff717c3c3272d7a2810:tezbox
undefined: 0 XTZ (0ops) (tz1SApkt3kmMaqNE1qtgADc6m3B49HZkFVDA on 44'/1729'/2'/0') tezbox#2 js:2:tezos:029d7bcf10737806147b22ba4578747ce4ac53e26b443c9eb1ac0e4d5bfbb8f67e:tezbox
necessary accounts resynced in 0.27ms
▬ TezosWallet 3.0.3 on nanoS 2.1.0
→ FROM undefined: 5.28869 XTZ (152ops) (tz1aDK1uFAmnUXZ7KJPEmcCEFeYHiVZ56zVF on 44'/1729'/0'/0') tezbox#0 js:2:tezos:0240051fc51799e60dcc8870415b87fc4fd948e71b23fdc0d9b8ac7438cf7d4708:tezbox
max spendable ~5.28775
★ using mutation 'delegate unrevealed'
✔️ transaction 
DELEGATE 0 XTZ
TO tz1Scdr2HsZiQjc7bHMeBbmDRXYVvdhjJbBh
with fees=0.000371
with gasLimit=200
with storageLimit=0
(estimatedFees 0.000745)
STATUS (773ms)
  amount: 0 XTZ
  estimated fees: 0.000745 XTZ
  total spent: 0.000745 XTZ
errors: 
warnings: 
⚠️ Error: device action timeout. Recent events was:
{"text":"Review operation","x":13,"y":17,"w":107,"h":11}
{"text":"Operation (0)","x":26,"y":-1,"w":94,"h":11}
{"text":"Reveal","x":47,"y":10,"w":81,"h":11}
(totally spent 61.3s – ends at 2024-05-14T08:52:40.708Z)

Details of the 6 uncovered mutations

Spec Tezos (6)

  • send unrevealed: balance is too low (2)
  • send revealed: balance is too low (2)
  • send max (non delegating): balance is too low (2)
  • delegate revealed: balance is too low (2)
  • undelegate unrevealed: balance is too low (2)
  • undelegate revealed: balance is too low (2)
Portfolio ($4.68) – Details of the 1 currencies
Spec (accounts) State Remaining Runs (est) funds?
Tezos (3) 156 ops , 5.28869 XTZ ($4.68) 👍 182 tz1aDK1uFAmnUXZ7KJPEmcCEFeYHiVZ56zVF
undefined: 5.28869 XTZ (152ops) (tz1aDK1uFAmnUXZ7KJPEmcCEFeYHiVZ56zVF on 44'/1729'/0'/0') tezbox#0 js:2:tezos:0240051fc51799e60dcc8870415b87fc4fd948e71b23fdc0d9b8ac7438cf7d4708:tezbox
undefined: 0 XTZ (4ops) (tz1he4fPXP3c9fFrztYT3k7KyYuLb28arFNn on 44'/1729'/1'/0') tezbox#1 js:2:tezos:02fe3d777af5380ef0a431c4985772c9669743050cee5feff717c3c3272d7a2810:tezbox
undefined: 0 XTZ (0ops) (tz1SApkt3kmMaqNE1qtgADc6m3B49HZkFVDA on 44'/1729'/2'/0') tezbox#2 js:2:tezos:029d7bcf10737806147b22ba4578747ce4ac53e26b443c9eb1ac0e4d5bfbb8f67e:tezbox
Performance ⏲ 69.3s

Time spent for each spec: (total across mutations)

Spec (accounts) preload scan re-sync tx status sign op broadcast test destination test
TOTAL 175ms 3.4s 0.65ms 773ms N/A N/A N/A N/A
Tezos (2) 175ms 3.4s 0.65ms 773ms N/A N/A N/A N/A

What is the bot and how does it work? Everything is documented here!

Please sign in to comment.