Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking β€œSign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/live 15126 aptos unit tests bride boradcast prepare transactions #8742

Prev Previous commit
Next Next commit
Update logic.ts:getMaxSendBalance tests
may01 committed Dec 19, 2024
commit 1db222d6ecc500e1e29b9af96ae05732c52b384f
46 changes: 37 additions & 9 deletions libs/ledger-live-common/src/families/aptos/logic.test.ts
Original file line number Diff line number Diff line change
@@ -32,18 +32,45 @@ describe("Aptos logic ", () => {
});

describe("getMaxSendBalance", () => {
it("should return the correct max send balance", () => {
it("should return the correct max send balance when amount is greater than total gas", () => {
const amount = new BigNumber(1000000);
const result = getMaxSendBalance(amount);
expect(result.isEqualTo(amount.minus(BigNumber((2000 + 5) * 100)))).toBe(true);
const gas = new BigNumber(200);
const gasPrice = new BigNumber(100);
const result = getMaxSendBalance(amount, gas, gasPrice);
expect(result.isEqualTo(amount.minus(gas.multipliedBy(gasPrice)))).toBe(true);
});

// TOFIX: this test should be updated after validation of the getMaxSendBalance strategy for small amounts
// it("should return the original amount if it is less than the total gas", () => {
// const amount = new BigNumber(1000);
// const result = getMaxSendBalance(amount);
// expect(result).toEqual(amount);
// });
it("should return zero when amount is less than total gas", () => {
const amount = new BigNumber(1000);
const gas = new BigNumber(200);
const gasPrice = new BigNumber(100);
const result = getMaxSendBalance(amount, gas, gasPrice);
expect(result.isEqualTo(new BigNumber(0))).toBe(true);
});

it("should return zero when amount is equal to total gas", () => {
const amount = new BigNumber(20000);
const gas = new BigNumber(200);
const gasPrice = new BigNumber(100);
const result = getMaxSendBalance(amount, gas, gasPrice);
expect(result.isEqualTo(new BigNumber(0))).toBe(true);
});

it("should handle zero amount", () => {
const amount = new BigNumber(0);
const gas = new BigNumber(200);
const gasPrice = new BigNumber(100);
const result = getMaxSendBalance(amount, gas, gasPrice);
expect(result.isEqualTo(new BigNumber(0))).toBe(true);
});

it("should handle zero gas and gas price", () => {
const amount = new BigNumber(1000000);
const gas = new BigNumber(0);
const gasPrice = new BigNumber(0);
const result = getMaxSendBalance(amount, gas, gasPrice);
expect(result.isEqualTo(amount)).toBe(true);
});
});

describe("normalizeTransactionOptions", () => {
@@ -543,4 +570,5 @@ describe("Aptos sync logic ", () => {
expect(result).toEqual(new BigNumber(90).negated()); // 100 - 10
});
});

});