Skip to content

Commit

Permalink
feat(aptos): add coin feature flag for testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
jccguimaraes committed Dec 6, 2024
1 parent 553f5ab commit e1e3178
Showing 1 changed file with 44 additions and 37 deletions.
81 changes: 44 additions & 37 deletions libs/coin-modules/coin-aptos/src/test/bot-specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,21 @@ import { botTest, genericTestDestination, pickSiblings } from "@ledgerhq/coin-fr
import { acceptTransaction } from "./bot-deviceActions";
import type { Transaction } from "../types";
import BigNumber from "bignumber.js";
import { isAccountEmpty } from "@ledgerhq/coin-framework/account";
import { AccountLike } from "@ledgerhq/types-live";

const currency = getCryptoCurrencyById("aptos");
const minAmountCutoff = parseCurrencyUnit(currency.units[0], "0.1");
const minimalAmount = parseCurrencyUnit(currency.units[0], "0.5");
const reserve = parseCurrencyUnit(currency.units[0], "1");
const maxAccount = 1;
const minAmountCutoff = parseCurrencyUnit(currency.units[0], "0.0001");
const reserve = parseCurrencyUnit(currency.units[0], "0.5");

const minBalanceNewAccount = parseCurrencyUnit(currency.units[0], "0.5");
const maxAccountSiblings = 4;

const checkSendableToEmptyAccount = (amount: BigNumber, recipient: AccountLike) => {
if (isAccountEmpty(recipient) && amount.lte(minBalanceNewAccount)) {
invariant(amount.gt(minBalanceNewAccount), "not enough funds to send to new account");
}
};

const aptos: AppSpec<Transaction> = {
name: "Aptos",
Expand All @@ -31,34 +40,27 @@ const aptos: AppSpec<Transaction> = {
testDestination: genericTestDestination,
transaction: ({ account, siblings, bridge, maxSpendable }) => {
invariant(maxSpendable.gt(minAmountCutoff), "balance is too low");
const transaction = bridge.createTransaction(account);
const sibling = pickSiblings(siblings, 3);

const sibling = pickSiblings(siblings, maxAccountSiblings);
const recipient = sibling.freshAddress;
let amount = maxSpendable.div(1.9 + 0.2 * Math.random()).integerValue();
const transaction = bridge.createTransaction(account);

if (!sibling.used && amount.lt(reserve)) {
invariant(
maxSpendable.gt(reserve.plus(minAmountCutoff)),
"not enough funds to send to new account",
);
amount = reserve;
}
const amount = maxSpendable.div(1.9 + 0.2 * Math.random()).integerValue();

checkSendableToEmptyAccount(amount, sibling);

const updates = [
{
amount,
},
{
recipient,
},
];

return {
transaction,
updates: [
{
amount,
},
{
recipient,
},
Math.random() > 0.5
? {
tag: 123,
}
: null,
],
updates,
};
},
test: ({ account, accountBeforeTransaction, operation }) => {
Expand All @@ -70,18 +72,24 @@ const aptos: AppSpec<Transaction> = {
},
},
{
name: "send max to another account",
name: "send max",
maxRun: 1,
testDestination: genericTestDestination,
transaction: ({ account, siblings, bridge, maxSpendable }) => {
invariant(maxSpendable.gt(minimalAmount), "balance is too low");
const sibling = pickSiblings(siblings, maxAccount);
const recipient = sibling.freshAddress;
invariant(maxSpendable.gt(0), "Spendable balance is too low");

const sibling = pickSiblings(siblings, maxAccountSiblings);

// Send the full spendable balance
const amount = maxSpendable;

checkSendableToEmptyAccount(amount, sibling);

return {
transaction: bridge.createTransaction(account),
updates: [
{
recipient,
recipient: sibling.freshAddress,
},
{
useAllAmount: true,
Expand All @@ -90,13 +98,12 @@ const aptos: AppSpec<Transaction> = {
};
},
test: ({ account }) => {
botTest("account spendable balance is zero", () =>
expect(account.balance.toString()).toBe(new BigNumber(0).toString()),
botTest("account spendable balance is very low", () =>
expect(account.spendableBalance.lt(reserve)).toBe(true),
);
},
},
],
};
export default {
aptos,
};

export default { aptos };

4 comments on commit e1e3178

@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' ($0.00) ⏲ 6ms

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

Details of the 0 mutations
Portfolio ($0.00) – Details of the 0 currencies
Spec (accounts) State Remaining Runs (est) funds?

Performance ⏲ 6ms

Time spent for each spec: (total across mutations)

Spec (accounts) preload scan re-sync tx status sign op broadcast test destination test
TOTAL N/A N/A N/A N/A N/A N/A N/A N/A

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

@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' ($0.00) ⏲ 6ms

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

Details of the 0 mutations
Portfolio ($0.00) – Details of the 0 currencies
Spec (accounts) State Remaining Runs (est) funds?

Performance ⏲ 6ms

Time spent for each spec: (total across mutations)

Spec (accounts) preload scan re-sync tx status sign op broadcast test destination test
TOTAL N/A N/A N/A N/A N/A N/A N/A N/A

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

@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' ($0.00) ⏲ 6ms

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

Details of the 0 mutations
Portfolio ($0.00) – Details of the 0 currencies
Spec (accounts) State Remaining Runs (est) funds?

Performance ⏲ 6ms

Time spent for each spec: (total across mutations)

Spec (accounts) preload scan re-sync tx status sign op broadcast test destination test
TOTAL N/A N/A N/A N/A N/A N/A N/A N/A

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

@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' ($0.00) ⏲ 6ms

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

Details of the 0 mutations
Portfolio ($0.00) – Details of the 0 currencies
Spec (accounts) State Remaining Runs (est) funds?

Performance ⏲ 6ms

Time spent for each spec: (total across mutations)

Spec (accounts) preload scan re-sync tx status sign op broadcast test destination test
TOTAL N/A N/A N/A N/A 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.