@ledgerhq/coin-aptos
Version:
Ledger Aptos Coin integration
202 lines • 8.88 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const bignumber_js_1 = __importDefault(require("bignumber.js"));
const staking_1 = require("../../logic/staking");
const bridge_fixture_1 = require("../../bridge/bridge.fixture");
const constants_1 = require("../../constants");
const stakingPositions = [
{
active: (0, bignumber_js_1.default)(123456789),
inactive: (0, bignumber_js_1.default)(567567567),
pendingInactive: (0, bignumber_js_1.default)(5345),
validatorId: "validator-1",
},
{
active: (0, bignumber_js_1.default)(0),
inactive: (0, bignumber_js_1.default)(33333),
pendingInactive: (0, bignumber_js_1.default)(67868678),
validatorId: "validator-2",
},
{
active: (0, bignumber_js_1.default)(45864986459),
inactive: (0, bignumber_js_1.default)(0),
pendingInactive: (0, bignumber_js_1.default)(0),
validatorId: "validator-3",
},
];
const nonBreakableSpace = " ";
describe("mapStakingPositions", () => {
it("returns the staking positions per validator", () => {
const validators = [
{
activeStake: (0, bignumber_js_1.default)(8972343459783425),
commission: (0, bignumber_js_1.default)(8),
address: "validator-1",
name: "validator-1",
shares: "no-shares",
},
{
activeStake: (0, bignumber_js_1.default)(172343459783425),
commission: (0, bignumber_js_1.default)(8),
address: "validator-2",
name: "validator-2",
shares: "no-shares",
},
{
activeStake: (0, bignumber_js_1.default)(1743459783425),
commission: (0, bignumber_js_1.default)(7),
address: "validator-3",
name: "validator-3",
shares: "no-shares",
},
];
const expected = [
{
active: (0, bignumber_js_1.default)("123456789"),
inactive: (0, bignumber_js_1.default)("567567567"),
pendingInactive: (0, bignumber_js_1.default)("5345"),
validatorId: "validator-1",
formattedAmount: `1.23456${nonBreakableSpace}APT`,
formattedPending: `0.00005345${nonBreakableSpace}APT`,
formattedAvailable: `5.67567${nonBreakableSpace}APT`,
rank: 0,
validator: {
activeStake: (0, bignumber_js_1.default)("8972343459783425"),
commission: (0, bignumber_js_1.default)("8"),
address: "validator-1",
name: "validator-1",
shares: "no-shares",
},
},
{
active: (0, bignumber_js_1.default)("0"),
inactive: (0, bignumber_js_1.default)("33333"),
pendingInactive: (0, bignumber_js_1.default)("67868678"),
validatorId: "validator-2",
formattedAmount: `0${nonBreakableSpace}APT`,
formattedPending: `0.678686${nonBreakableSpace}APT`,
formattedAvailable: `0.00033333${nonBreakableSpace}APT`,
rank: 1,
validator: {
activeStake: (0, bignumber_js_1.default)("172343459783425"),
commission: (0, bignumber_js_1.default)("8"),
address: "validator-2",
name: "validator-2",
shares: "no-shares",
},
},
{
active: (0, bignumber_js_1.default)("45864986459"),
inactive: (0, bignumber_js_1.default)("0"),
pendingInactive: (0, bignumber_js_1.default)("0"),
validatorId: "validator-3",
formattedAmount: `458.649${nonBreakableSpace}APT`,
formattedPending: `0${nonBreakableSpace}APT`,
formattedAvailable: `0${nonBreakableSpace}APT`,
rank: 2,
validator: {
activeStake: (0, bignumber_js_1.default)("1743459783425"),
commission: (0, bignumber_js_1.default)("7"),
address: "validator-3",
name: "validator-3",
shares: "no-shares",
},
},
];
expect((0, staking_1.mapStakingPositions)(stakingPositions, validators, {
name: "Aptos",
code: "APT",
magnitude: 8,
})).toMatchObject(expected);
});
});
describe("canStake", () => {
it(`returns false for an account with a balance with less than ${constants_1.MIN_COINS_ON_SHARES_POOL} APT`, () => {
const account = (0, bridge_fixture_1.createFixtureAccount)({
balance: (0, bignumber_js_1.default)(5),
spendableBalance: (0, bignumber_js_1.default)(5),
});
const expected = (0, staking_1.canStake)(account);
expect(expected).toBe(false);
});
it(`returns true for an account with balance with more than ${constants_1.MIN_COINS_ON_SHARES_POOL} APT`, () => {
const account = (0, bridge_fixture_1.createFixtureAccount)({
balance: (0, bignumber_js_1.default)(1212312312312),
spendableBalance: (0, bignumber_js_1.default)(1212312312312),
});
const expected = (0, staking_1.canStake)(account);
expect(expected).toBe(true);
});
});
describe("canUnstake", () => {
it("returns true if there's no amount staked", () => {
const expected = (0, staking_1.canUnstake)(stakingPositions[0]);
expect(expected).toBe(true);
});
it("returns false if there's no amount staked", () => {
const expected = (0, staking_1.canUnstake)(stakingPositions[1]);
expect(expected).toBe(false);
});
});
describe("canWithdraw", () => {
it("returns true if there's no amount inactive", () => {
const expected = (0, staking_1.canWithdraw)(stakingPositions[0]);
expect(expected).toBe(true);
});
it("returns false if there's no amount inactive", () => {
const expected = (0, staking_1.canWithdraw)(stakingPositions[2]);
expect(expected).toBe(false);
});
});
describe("canRestake", () => {
it("returns true if there's no amount inactive", () => {
const expected = (0, staking_1.canRestake)(stakingPositions[0]);
expect(expected).toBe(true);
});
it("returns false if there's no amount inactive", () => {
const expected = (0, staking_1.canRestake)(stakingPositions[2]);
expect(expected).toBe(false);
});
});
describe("getDelegationOpMaxAmount", () => {
it("get maximum amount available to unstake", () => {
const account = (0, bridge_fixture_1.createFixtureAccount)({
aptosResources: {
activeBalance: (0, bignumber_js_1.default)(45988443248),
pendingInactiveBalance: (0, bignumber_js_1.default)(67874023),
inactiveBalance: (0, bignumber_js_1.default)(567600900),
stakingPositions,
},
});
const expected = (0, staking_1.getDelegationOpMaxAmount)(account, "validator-1", "unstake");
expect(expected).toEqual((0, bignumber_js_1.default)(123456789));
});
it("get maximum amount available to withdraw", () => {
const account = (0, bridge_fixture_1.createFixtureAccount)({
aptosResources: {
activeBalance: (0, bignumber_js_1.default)(45988443248),
pendingInactiveBalance: (0, bignumber_js_1.default)(67874023),
inactiveBalance: (0, bignumber_js_1.default)(567600900),
stakingPositions,
},
});
const expected = (0, staking_1.getDelegationOpMaxAmount)(account, "validator-1", "withdraw");
expect(expected).toEqual((0, bignumber_js_1.default)(567567567));
});
it("get maximum amount available to restake", () => {
const account = (0, bridge_fixture_1.createFixtureAccount)({
aptosResources: {
activeBalance: (0, bignumber_js_1.default)(45988443248),
pendingInactiveBalance: (0, bignumber_js_1.default)(67874023),
inactiveBalance: (0, bignumber_js_1.default)(567600900),
stakingPositions,
},
});
const expected = (0, staking_1.getDelegationOpMaxAmount)(account, "validator-1", "restake");
expect(expected).toEqual((0, bignumber_js_1.default)(5345));
});
});
//# sourceMappingURL=staking.test.js.map