Skip to content

Commit

Permalink
Tests update to follow up cache update
Browse files Browse the repository at this point in the history
  • Loading branch information
may01 committed Jan 8, 2025
1 parent 4f4cf07 commit 526b5db
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 265 deletions.
3 changes: 0 additions & 3 deletions libs/ledger-live-common/src/families/aptos/api/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,6 @@ describe("Aptos API", () => {
options: {
maxGasAmount: Number(options.maxGasAmount),
gasUnitPrice: Number(options.gasUnitPrice),
accountSequenceNumber: Number(options.sequenceNumber),
expireTimestamp: Number(options.expirationTimestampSecs),
},
sender: Account.APTOS_1.address,
});
Expand Down Expand Up @@ -415,7 +413,6 @@ describe("Aptos API", () => {
options: {
maxGasAmount: Number(options.maxGasAmount),
gasUnitPrice: Number(options.gasUnitPrice),
accountSequenceNumber: Number(options.sequenceNumber),
expireTimestamp: 120,
},
sender: Account.APTOS_1.address,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,8 @@ const aptos: CurrenciesData<Transaction> = {
family: "aptos",
mode: "send",
fees: "1100",
//options: '{ "maxGasAmount": "11", "gasUnitPrice": "100" }',
estimate:
'{ "maxGasAmount": "11", "gasUnitPrice": "100", "sequenceNumber": "1", "expirationTimestampSecs": "1734535375" }',
firstEmulation: "false",
errors: "{}",
}),
expectedStatus: () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import buildTransaction from "./buildTransaction";
import { AptosAPI } from "./api";
import { normalizeTransactionOptions } from "./logic";
import { InputEntryFunctionData } from "@aptos-labs/ts-sdk";
import { TransactionOptions } from "./types";
import { TransactionEstimate } from "./types";

const generateTransaction = jest.fn(() => "tx");

Expand Down Expand Up @@ -43,7 +43,7 @@ describe("buildTransaction Test", () => {
expect(mockedNormalizeTransactionOptions).toHaveBeenCalledTimes(1);
expect(generateTransaction).toHaveBeenCalledTimes(1);

const generateTransactionArgs: [string, InputEntryFunctionData, TransactionOptions][] =
const generateTransactionArgs: [string, InputEntryFunctionData, TransactionEstimate][] =
generateTransaction.mock.calls[0];

expect(mockedNormalizeTransactionOptions.mock.calls[0][0]).toEqual({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ describe("createTransaction Test", () => {
amount: BigNumber(0),
recipient: "",
useAllAmount: false,
firstEmulation: true,
options: {
maxGasAmount: "100",
gasUnitPrice: "200",
},
estimate: {
maxGasAmount: "100",
gasUnitPrice: "200",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ import estimateMaxSpendable from "./estimateMaxSpendable";
import BigNumber from "bignumber.js";

jest.mock("./getFeesForTransaction", () => ({
getEstimatedGas: jest.fn(() => ({
fees: new BigNumber(0),
estimate: {
maxGasAmount: 1,
gasUnitPrice: 2,
sequenceNumber: "",
expirationTimestampSecs: "",
},
errors: {},
})),
getEstimatedGas: jest.fn(() =>
Promise.resolve({
fees: new BigNumber(0),
estimate: {
maxGasAmount: 1,
gasUnitPrice: 2,
sequenceNumber: "",
expirationTimestampSecs: "",
},
errors: {},
}),
),
}));

describe("estimateMaxSpendable Test", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,87 +36,15 @@ jest.mock("./logic", () => {

describe("getFeesForTransaction Test", () => {
describe("when using getFee", () => {
describe("with vm_status as SEQUENCE_NUMBER", () => {
it("should return a fee estimation object", async () => {
simulateTransaction = jest.fn(() => [
{
success: false,
vm_status: ["SEQUENCE_NUMBER"],
expiration_timestamp_secs: 5,
},
]);

const account = createFixtureAccount();
const transaction = createTransaction();
const aptosClient = new AptosAPI(account.currency.id);

transaction.amount = new BigNumber(1);
account.xpub = "xpub";
account.spendableBalance = new BigNumber(100000000);

const result = await getFeesForTransaction.getFee(account, transaction, aptosClient);

const expected = {
fees: new BigNumber(20301),
estimate: {
maxGasAmount: "201",
gasUnitPrice: "101",
sequenceNumber: "123",
expirationTimestampSecs: "",
},
errors: {
sequenceNumber: ["SEQUENCE_NUMBER"],
},
};

expect(result).toEqual(expected);
});
});

describe("with vm_status as TRANSACTION_EXPIRED", () => {
it("should return a fee estimation object", async () => {
simulateTransaction = jest.fn(() => [
{
success: false,
vm_status: ["TRANSACTION_EXPIRED"],
expiration_timestamp_secs: 5,
},
]);

const account = createFixtureAccount();
const transaction = createTransaction();
const aptosClient = new AptosAPI(account.currency.id);

transaction.amount = new BigNumber(1);
account.xpub = "xpub";
account.spendableBalance = new BigNumber(100000000);

const result = await getFeesForTransaction.getFee(account, transaction, aptosClient);

const expected = {
fees: new BigNumber(20301),
estimate: {
maxGasAmount: "201",
gasUnitPrice: "101",
sequenceNumber: "123",
expirationTimestampSecs: "",
},
errors: {
expirationTimestampSecs: ["TRANSACTION_EXPIRED"],
},
};

expect(result).toEqual(expected);
});
});

describe("with vm_status as INSUFFICIENT_BALANCE", () => {
it("should return a fee estimation object", async () => {
simulateTransaction = jest.fn(() => [
{
success: false,
vm_status: ["INSUFFICIENT_BALANCE"],
expiration_timestamp_secs: 5,
gas_used: "201",
gas_unit_price: "101",
},
]);

Expand All @@ -135,8 +63,6 @@ describe("getFeesForTransaction Test", () => {
estimate: {
maxGasAmount: "201",
gasUnitPrice: "101",
sequenceNumber: "123",
expirationTimestampSecs: "",
},
errors: {},
};
Expand All @@ -152,6 +78,8 @@ describe("getFeesForTransaction Test", () => {
success: false,
vm_status: ["DUMMY_STATE"],
expiration_timestamp_secs: 5,
gas_used: "9",
gas_unit_price: "100",
},
]);

Expand All @@ -173,10 +101,24 @@ describe("getFeesForTransaction Test", () => {
describe("when using getEstimatedGas", () => {
describe("when key not in cache", () => {
it("should return cached fee", async () => {
simulateTransaction = jest.fn(() => [
{
success: true,
vm_status: [],
expiration_timestamp_secs: 5,
gas_used: "9",
gas_unit_price: "102",
},
]);

const account = createFixtureAccount();
const transaction = createTransaction();
const aptosClient = new AptosAPI(account.currency.id);

transaction.amount = new BigNumber(1);
account.xpub = "xpub";
account.spendableBalance = new BigNumber(100000000);

const result = await getFeesForTransaction.getEstimatedGas(
account,
transaction,
Expand All @@ -186,19 +128,17 @@ describe("getFeesForTransaction Test", () => {
const expected = {
errors: {},
estimate: {
expirationTimestampSecs: "",
gasUnitPrice: "101",
maxGasAmount: "201",
sequenceNumber: "123",
gasUnitPrice: "102",
maxGasAmount: "9",
},
fees: new BigNumber("20301"),
fees: new BigNumber("918"),
};

expect(result).toEqual(expected);
});
});

describe("when key is in cache 22", () => {
describe("when key is in cache", () => {
beforeEach(() => {
jest.clearAllMocks();
});
Expand All @@ -212,6 +152,16 @@ describe("getFeesForTransaction Test", () => {

transaction.amount = new BigNumber(10);

simulateTransaction = jest.fn(() => [
{
success: true,
vm_status: [],
expiration_timestamp_secs: 5,
gas_used: "9",
gas_unit_price: "100",
},
]);

const result1 = await getFeesForTransaction.getEstimatedGas(
account,
transaction,
Expand All @@ -228,10 +178,8 @@ describe("getFeesForTransaction Test", () => {
const expected = {
errors: {},
estimate: {
expirationTimestampSecs: "",
gasUnitPrice: "101",
maxGasAmount: "201",
sequenceNumber: "123",
},
fees: new BigNumber("20301"),
};
Expand Down
Loading

0 comments on commit 526b5db

Please sign in to comment.