Skip to content

Commit

Permalink
fix: bot test (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidecarpini authored Oct 2, 2023
1 parent 481c901 commit 63a925e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Array [
Object {
"approvals": undefined,
"id": "js:2:vechain:0x0fe6688548f0C303932bB197B0A96034f1d74dba:vechain+vechain%2Fvtho",
"operationsCount": 1,
"operationsCount": 0,
"parentId": "js:2:vechain:0x0fe6688548f0C303932bB197B0A96034f1d74dba:vechain",
"pendingOperations": Array [],
"starred": false,
Expand Down Expand Up @@ -141,29 +141,7 @@ Array [
"value": "10000000000000000000",
},
],
Array [
Object {
"accountId": "js:2:vechain:0x0fe6688548f0C303932bB197B0A96034f1d74dba:vechain+vechain%2Fvtho",
"blockHash": "0x00fa5b4ee2eca5cf65907e3695bbea044cd1f78224534dc0ba02526890055ecc",
"blockHeight": 16407374,
"contract": undefined,
"extra": Object {},
"fee": "365180000000000000",
"hash": "0x5fdd7191c4d476a8e86060d516366e87421f65667b9b3c14c33a740c04921b10",
"id": "js:2:vechain:0x0fe6688548f0C303932bB197B0A96034f1d74dba:vechain+vechain%2Fvtho-0x5fdd7191c4d476a8e86060d516366e87421f65667b9b3c14c33a740c04921b10-IN",
"operator": undefined,
"recipients": Array [
"0x0fe6688548f0c303932bb197b0a96034f1d74dba",
],
"senders": Array [
"0xcf130b42ae31c4931298b4b1c0f1d974b8732957",
],
"standard": undefined,
"tokenId": undefined,
"type": "IN",
"value": "10000000000000000000",
},
],
Array [],
Array [
Object {
"accountId": "js:2:vechain:0x02961B92B8D20A4ea12f1f1CeFA74Dd7B4355A86:vechain",
Expand Down
21 changes: 21 additions & 0 deletions libs/ledger-live-common/src/families/vechain/js-synchronisation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { emptyHistoryCache } from "../../account";
import { getAccount, getLastBlockHeight, getOperations, getTokenOperations } from "./api";
import { findTokenById, getTokenById } from "@ledgerhq/cryptoassets/tokens";
import { VTHO_ADDRESS } from "./contracts/constants";
import { Operation } from "@ledgerhq/types-live";
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";

const getAccountShape: GetAccountShape = async info => {
const { initialAccount, currency, derivationMode } = info;
Expand Down Expand Up @@ -37,6 +39,25 @@ const getAccountShape: GetAccountShape = async info => {
const vthoAccountId = encodeTokenAccountId(accountId, findTokenById("vechain/vtho")!);
const vthoOperations = await getTokenOperations(vthoAccountId, address, VTHO_ADDRESS, 0);

// Generate type "NONE" operations on main account for each token operation to run bot tests
// vthoOperations.forEach(operation => {
// const op: Operation = {
// id: encodeOperationId(accountId, operation.hash, "NONE" as const),
// hash: "",
// type: "NONE",
// value: new BigNumber(0),
// fee: new BigNumber(0),
// senders: [],
// recipients: [],
// blockHash: "",
// blockHeight: 0,
// accountId,
// date: operation.date,
// extra: {},
// };
// newOperations.push(op);
// });

const operations = mergeOps(oldOperations, newOperations);

//Account creation date set to now if there are no operation or at the first operation on the account
Expand Down
8 changes: 6 additions & 2 deletions libs/ledger-live-common/src/families/vechain/specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,14 @@ const vechain: AppSpec<Transaction> = {
account,
siblings,
bridge,
maxSpendable,
}: TransactionArg<Transaction>): TransactionRes<Transaction> => {
const sibling = pickSiblings(siblings, 4);
const recipient = sibling.freshAddress;
const transaction = bridge.createTransaction(account);
transaction.useAllAmount = true;
const updates = [{ recipient }];
const amount = maxSpendable.integerValue();
const updates = [{ amount }, { recipient }];
return {
transaction,
updates,
Expand Down Expand Up @@ -131,7 +133,9 @@ const vechain: AppSpec<Transaction> = {
throw new Error("no VTHO account");
const transaction = bridge.createTransaction(account);
transaction.useAllAmount = true;
const updates = [{ recipient }, { subAccountId: account.subAccounts[0].id }];
transaction.subAccountId = account.subAccounts[0].id;
const amount = account.subAccounts[0].spendableBalance.integerValue();
const updates = [{ amount }, { recipient }, { subAccountId: account.subAccounts[0].id }];
return {
transaction,
updates,
Expand Down

0 comments on commit 63a925e

Please sign in to comment.