Skip to content

Commit 39edc6e

Browse files
committed
chore: save work
1 parent fd4f7ce commit 39edc6e

File tree

3 files changed

+82
-69
lines changed

3 files changed

+82
-69
lines changed

libs/coin-modules/coin-aptos/src/bridge/logic.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,9 @@ export const txsToOps = (
148148
return;
149149
} else if (coin_id === APTOS_ASSET_ID) {
150150
op.id = encodeOperationId(id, tx.hash, op.type);
151-
ops.push(op); // if not aptos then should be tokens
151+
ops.push(op);
152152
} else {
153153
const token = findTokenByAddressInCurrency(coin_id.toLowerCase(), "aptos");
154-
// skip tokens that are not in the CAL
155154
if (token !== undefined) {
156155
op.accountId = encodeTokenAccountId(id, token);
157156
op.id = encodeOperationId(op.accountId, tx.hash, op.type);

libs/coin-modules/coin-aptos/src/bridge/synchronisation.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,6 @@ export const getAccountShape: GetAccountShape = async info => {
184184
accountId,
185185
transactions,
186186
);
187-
const operations = mergeOps(oldOperations, newOperations);
188-
189187
const newSubAccounts = await getSubAccounts(info, address, accountId, tokenOperations);
190188

191189
// TODO: validate correctness of cache and mergeSubAccounts
@@ -195,6 +193,18 @@ export const getAccountShape: GetAccountShape = async info => {
195193
? newSubAccounts
196194
: mergeSubAccounts(initialAccount, newSubAccounts); // Merging potential new subAccouns while preserving the references
197195

196+
let subAccountsOperations = [] as Operation[];
197+
subAccountsOperations = subAccounts
198+
.map(sa => sa.operations.filter(op => op.type === "OUT"))
199+
.flat()
200+
.map(op => ({
201+
...op,
202+
id: accountId,
203+
type: "FEES",
204+
}));
205+
206+
const operations = mergeOps(mergeOps(oldOperations, newOperations), subAccountsOperations);
207+
198208
const shape: Partial<AptosAccount> = {
199209
type: "Account",
200210
id: accountId,

libs/coin-modules/coin-aptos/src/test/bot-specs.ts

+69-65
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import { DeviceModelId } from "@ledgerhq/devices";
44
import BigNumber from "bignumber.js";
55
import type { Transaction } from "../types";
66
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";
7-
import { genericTestDestination, pickSiblings, botTest } from "@ledgerhq/coin-framework/bot/specs";
7+
import {
8+
/* genericTestDestination, */ pickSiblings,
9+
botTest,
10+
} from "@ledgerhq/coin-framework/bot/specs";
811
import type { AppSpec, TransactionTestInput } from "@ledgerhq/coin-framework/bot/types";
912
import { acceptTokenTransaction, acceptTransaction } from "./speculos-deviceActions";
1013
import { Account, TokenAccount } from "@ledgerhq/types-live";
@@ -22,71 +25,71 @@ const aptosSpecs: AppSpec<Transaction> = {
2225
firmware: "1.3.2",
2326
},
2427
genericDeviceAction: acceptTransaction,
25-
testTimeout: 6 * 60 * 1000,
28+
testTimeout: 2 * 60 * 1000,
2629
minViableAmount: MIN_SAFE,
2730
transactionCheck: ({ maxSpendable }) => {
2831
invariant(maxSpendable.gt(MIN_SAFE), "balance is too low");
2932
},
3033
mutations: [
31-
{
32-
name: "Send ~50%",
33-
feature: "send",
34-
maxRun: 1,
35-
testDestination: genericTestDestination,
36-
transaction: ({ account, siblings, bridge, maxSpendable }) => {
37-
invariant(maxSpendable.gt(MIN_SAFE), "balance is too low");
38-
const sibling = pickSiblings(siblings, maxAccount);
39-
const recipient = sibling.freshAddress;
40-
const amount = maxSpendable.div(2).integerValue();
41-
42-
const transaction = bridge.createTransaction(account);
43-
const updates: Array<Partial<Transaction>> = [
44-
{
45-
recipient,
46-
},
47-
{ amount },
48-
];
49-
50-
return {
51-
transaction,
52-
updates,
53-
};
54-
},
55-
56-
test: ({ accountBeforeTransaction, operation, account }) => {
57-
botTest("account spendable balance decreased with operation", () =>
58-
expect(account.spendableBalance).toEqual(
59-
accountBeforeTransaction.spendableBalance.minus(operation.value),
60-
),
61-
);
62-
},
63-
},
64-
{
65-
name: "Transfer Max",
66-
feature: "sendMax",
67-
maxRun: 1,
68-
transaction: ({ account, siblings, bridge }) => {
69-
const updates: Array<Partial<Transaction>> = [
70-
{
71-
recipient: pickSiblings(siblings, maxAccount).freshAddress,
72-
},
73-
{
74-
useAllAmount: true,
75-
},
76-
];
77-
78-
return {
79-
transaction: bridge.createTransaction(account),
80-
updates,
81-
};
82-
},
83-
testDestination: genericTestDestination,
84-
test: ({ account }) => {
85-
botTest("account spendable balance is zero", () =>
86-
expect(account.spendableBalance.toString()).toBe("0"),
87-
);
88-
},
89-
},
34+
// {
35+
// name: "Send ~50%",
36+
// feature: "send",
37+
// maxRun: 1,
38+
// testDestination: genericTestDestination,
39+
// transaction: ({ account, siblings, bridge, maxSpendable }) => {
40+
// invariant(maxSpendable.gt(MIN_SAFE), "balance is too low");
41+
// const sibling = pickSiblings(siblings, maxAccount);
42+
// const recipient = sibling.freshAddress;
43+
// const amount = maxSpendable.div(2).integerValue();
44+
45+
// const transaction = bridge.createTransaction(account);
46+
// const updates: Array<Partial<Transaction>> = [
47+
// {
48+
// recipient,
49+
// },
50+
// { amount },
51+
// ];
52+
53+
// return {
54+
// transaction,
55+
// updates,
56+
// };
57+
// },
58+
59+
// test: ({ accountBeforeTransaction, operation, account }) => {
60+
// botTest("account spendable balance decreased with operation", () =>
61+
// expect(account.spendableBalance).toEqual(
62+
// accountBeforeTransaction.spendableBalance.minus(operation.value),
63+
// ),
64+
// );
65+
// },
66+
// },
67+
// {
68+
// name: "Transfer Max",
69+
// feature: "sendMax",
70+
// maxRun: 1,
71+
// transaction: ({ account, siblings, bridge }) => {
72+
// const updates: Array<Partial<Transaction>> = [
73+
// {
74+
// recipient: pickSiblings(siblings, maxAccount).freshAddress,
75+
// },
76+
// {
77+
// useAllAmount: true,
78+
// },
79+
// ];
80+
81+
// return {
82+
// transaction: bridge.createTransaction(account),
83+
// updates,
84+
// };
85+
// },
86+
// testDestination: genericTestDestination,
87+
// test: ({ account }) => {
88+
// botTest("account spendable balance is zero", () =>
89+
// expect(account.spendableBalance.toString()).toBe("0"),
90+
// );
91+
// },
92+
// },
9093
{
9194
name: "Send ~50% of token amount",
9295
feature: "tokens",
@@ -98,11 +101,13 @@ const aptosSpecs: AppSpec<Transaction> = {
98101
const senderTokenAcc = findTokenSubAccountWithBalance(account);
99102
invariant(senderTokenAcc, "Sender token account with available balance not found");
100103

101-
const receiverTokenAcc = siblings.find(acc => findTokenSubAccountWithBalance(acc));
102-
invariant(receiverTokenAcc, "Recipient not found");
104+
const sibling = pickSiblings(siblings, maxAccount);
105+
106+
const recipientTokenAcc = findTokenSubAccountWithBalance(sibling);
107+
invariant(recipientTokenAcc, "Receiver token account with available balance not found");
103108

104109
const amount = senderTokenAcc.spendableBalance.div(2).integerValue();
105-
const recipient = receiverTokenAcc.freshAddress;
110+
const recipient = sibling.freshAddress;
106111
const transaction = bridge.createTransaction(account);
107112
const subAccountId = senderTokenAcc.id;
108113

@@ -134,7 +139,6 @@ function expectTokenAccountCorrectBalanceChange({
134139
if (!tokenAccId) throw new Error("Wrong subAccountId");
135140

136141
const tokenAccAfterTx = account.subAccounts?.find(acc => acc.id === tokenAccId);
137-
138142
const tokenAccBeforeTx = accountBeforeTransaction.subAccounts?.find(acc => acc.id === tokenAccId);
139143

140144
if (!tokenAccAfterTx || !tokenAccBeforeTx) {

0 commit comments

Comments
 (0)