UNPKG

@ledgerhq/coin-celo

Version:
108 lines 4.71 kB
"use strict"; 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 estimateMaxSpendable_1 = __importDefault(require("../../bridge/estimateMaxSpendable")); const fixtures_1 = require("../../bridge/fixtures"); jest.mock("../../bridge/getFeesForTransaction", async () => 12); const voteMock = jest.fn(() => ({ txo: { encodeABI: jest.fn(() => ({ data: "vote_data" })), estimateGas: jest.fn(async () => 1), }, })); jest.mock("../../network/sdk", () => { return { celoKit: jest.fn(() => ({ contracts: { getLockedGold: jest.fn(async () => ({ address: "address", getAccountNonvotingLockedGold: jest.fn(async () => (0, bignumber_js_1.default)(22)), lock: jest.fn(() => ({ txo: { encodeABI: jest.fn(() => ({ data: "lock_data" })), estimateGas: jest.fn(async () => 2), }, })), unlock: jest.fn(() => ({ txo: { encodeABI: jest.fn(() => ({ data: "unlock_data" })), estimateGas: jest.fn(async () => 3), }, })), withdraw: jest.fn(() => ({ txo: { encodeABI: jest.fn(() => ({ data: "withdraw_data" })), estimateGas: jest.fn(async () => 3), }, })), vote: jest.fn(() => ({ txo: { encodeABI: jest.fn(() => ({ data: "vote_data" })), estimateGas: jest.fn(async () => 3), }, })), })), getElection: jest.fn(async () => ({ vote: voteMock, revoke: jest.fn(), address: "vote_address", })), getAccounts: jest.fn(async () => ({ voteSignerToAccount: jest.fn(), createAccount: jest.fn(() => ({ txo: { encodeABI: jest.fn(() => ({ data: "register_data" })), estimateGas: jest.fn(async () => 3), }, })), address: "register_address", })), getStableToken: jest.fn(async () => ({ address: "stable_token_address", transfer: jest.fn(() => ({ txo: { encodeABI: jest.fn(() => ({ data: "send_token_data" })), }, })), })), getErc20: jest.fn(async () => ({ address: "erc20_token_address", transfer: jest.fn(() => ({ txo: { encodeABI: jest.fn(() => ({ data: "send_token_data" })), }, })), })), }, connection: { chainId: jest.fn(), nonce: jest.fn(), estimateGasWithInflationFactor: jest.fn().mockReturnValue(3), }, })), }; }); describe("estimateMaxSpendable", () => { it("returns the maximum spendable for a celo account", async () => { const maximumAmount = await (0, estimateMaxSpendable_1.default)({ account: { ...fixtures_1.accountFixture, balance: (0, bignumber_js_1.default)(100), spendableBalance: (0, bignumber_js_1.default)(100) }, transaction: fixtures_1.transactionFixture, }); expect(maximumAmount).toEqual((0, bignumber_js_1.default)(100)); }); it("returns the maximum spendable for a celo account", async () => { const maximumAmount = await (0, estimateMaxSpendable_1.default)({ account: { ...fixtures_1.accountWithTokenAccountFixture, balance: (0, bignumber_js_1.default)(100), spendableBalance: (0, bignumber_js_1.default)(100), }, transaction: fixtures_1.tokenTransactionFixture, }); expect(maximumAmount).toEqual((0, bignumber_js_1.default)(212)); }); }); //# sourceMappingURL=estimateMaxSpendable.test.js.map