UNPKG

@ledgerhq/coin-celo

Version:
211 lines 10.3 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 getFeesForTransaction_1 = __importDefault(require("../../bridge/getFeesForTransaction")); const fixtures_1 = require("../../bridge/fixtures"); const chainIdMock = jest.fn(); const nonceMock = jest.fn(); const voteMock = jest.fn(() => ({ txo: { encodeABI: jest.fn(() => ({ data: "vote_data" })), estimateGas: jest.fn(async () => 1), }, })); const revokeMock = jest.fn(); const voteSignerToAccountMock = jest.fn(); jest.mock("../../network/sdk", () => { return { celoKit: jest.fn(() => ({ contracts: { getLockedGold: jest.fn(async () => ({ address: "address", 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), }, })), getAccountNonvotingLockedGold: jest.fn(() => (0, bignumber_js_1.default)(0)), })), getElection: jest.fn(async () => ({ vote: voteMock, revoke: revokeMock, activate: jest.fn(() => ({ find: jest.fn(() => ({ txo: { encodeABI: jest.fn(() => ({ data: "vote_data" })), estimateGas: jest.fn(async () => 3), }, })), })), address: "vote_address", })), getAccounts: jest.fn(async () => ({ voteSignerToAccount: voteSignerToAccountMock, 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: chainIdMock, nonce: nonceMock, estimateGasWithInflationFactor: jest.fn().mockReturnValue(3), gasPrice: jest.fn(async () => (0, bignumber_js_1.default)(2)), }, })), }; }); describe("getFeesForTransaction", () => { it("should return the correct fees for a send transaction", async () => { const fees = await (0, getFeesForTransaction_1.default)({ account: { ...fixtures_1.accountFixture, balance: (0, bignumber_js_1.default)(123), spendableBalance: (0, bignumber_js_1.default)(123) }, transaction: fixtures_1.transactionFixture, }); expect(fees).toEqual((0, bignumber_js_1.default)(24)); }); it("should return the correct fees for a revoke transaction without revoked transactions", async () => { revokeMock.mockClear(); revokeMock.mockReturnValue({ find: jest.fn(() => false), }); const fees = await (0, getFeesForTransaction_1.default)({ account: { ...fixtures_1.accountFixture, balance: (0, bignumber_js_1.default)(123), spendableBalance: (0, bignumber_js_1.default)(123) }, transaction: { ...fixtures_1.transactionFixture, mode: "revoke" }, }); expect(fees).toEqual((0, bignumber_js_1.default)(0)); }); it("should return the correct fees for a revoke transaction with revoked transactions", async () => { revokeMock.mockClear(); revokeMock.mockReturnValue({ find: jest.fn(() => ({ txo: { encodeABI: jest.fn(() => ({ data: "revoke_data" })), estimateGas: jest.fn(async () => 2), }, })), }); const fees = await (0, getFeesForTransaction_1.default)({ account: { ...fixtures_1.accountFixture, balance: (0, bignumber_js_1.default)(123), spendableBalance: (0, bignumber_js_1.default)(123) }, transaction: { ...fixtures_1.transactionFixture, mode: "revoke" }, }); expect(fees).toEqual((0, bignumber_js_1.default)(4)); }); it("should return the correct fees for a revoke transaction with revoked transactions and useAllAmount set to true", async () => { revokeMock.mockClear(); revokeMock.mockReturnValue({ find: jest.fn(() => ({ txo: { encodeABI: jest.fn(() => ({ data: "revoke_data" })), estimateGas: jest.fn(async () => 2), }, })), }); const fees = await (0, getFeesForTransaction_1.default)({ account: { ...fixtures_1.accountFixture, balance: (0, bignumber_js_1.default)(123), spendableBalance: (0, bignumber_js_1.default)(123), celoResources: { ...fixtures_1.accountFixture.celoResources, votes: [ { activatable: true, amount: (0, bignumber_js_1.default)(10), index: 0, revokable: true, type: "active", validatorGroup: fixtures_1.transactionFixture.recipient, }, ], }, }, transaction: { ...fixtures_1.transactionFixture, mode: "revoke", useAllAmount: true }, }); expect(fees).toEqual((0, bignumber_js_1.default)(4)); }); it("should return the correct fees for a withdraw transaction", async () => { const fees = await (0, getFeesForTransaction_1.default)({ account: { ...fixtures_1.accountFixture, balance: (0, bignumber_js_1.default)(123), spendableBalance: (0, bignumber_js_1.default)(123) }, transaction: { ...fixtures_1.transactionFixture, mode: "withdraw" }, }); expect(fees).toEqual((0, bignumber_js_1.default)(6)); }); it("should return the correct fees for a vote transaction", async () => { const fees = await (0, getFeesForTransaction_1.default)({ account: { ...fixtures_1.accountFixture, balance: (0, bignumber_js_1.default)(123), spendableBalance: (0, bignumber_js_1.default)(123) }, transaction: { ...fixtures_1.transactionFixture, mode: "vote" }, }); expect(fees).toEqual((0, bignumber_js_1.default)(2)); }); it("should return the correct fees for a lock transaction", async () => { const fees = await (0, getFeesForTransaction_1.default)({ account: { ...fixtures_1.accountFixture, balance: (0, bignumber_js_1.default)(123), spendableBalance: (0, bignumber_js_1.default)(123) }, transaction: { ...fixtures_1.transactionFixture, mode: "lock" }, }); expect(fees).toEqual((0, bignumber_js_1.default)(4)); }); it("should return the correct fees for a unlock transaction", async () => { const fees = await (0, getFeesForTransaction_1.default)({ account: { ...fixtures_1.accountFixture, balance: (0, bignumber_js_1.default)(123), spendableBalance: (0, bignumber_js_1.default)(123) }, transaction: { ...fixtures_1.transactionFixture, mode: "unlock" }, }); expect(fees).toEqual((0, bignumber_js_1.default)(6)); }); it("should return the correct fees for an activate transaction", async () => { const fees = await (0, getFeesForTransaction_1.default)({ account: { ...fixtures_1.accountFixture, balance: (0, bignumber_js_1.default)(123), spendableBalance: (0, bignumber_js_1.default)(123) }, transaction: { ...fixtures_1.transactionFixture, mode: "activate" }, }); expect(fees).toEqual((0, bignumber_js_1.default)(6)); }); it("should return the correct fees for a register transaction", async () => { const fees = await (0, getFeesForTransaction_1.default)({ account: { ...fixtures_1.accountFixture, balance: (0, bignumber_js_1.default)(123), spendableBalance: (0, bignumber_js_1.default)(123) }, transaction: { ...fixtures_1.transactionFixture, mode: "register" }, }); expect(fees).toEqual((0, bignumber_js_1.default)(6)); }); }); //# sourceMappingURL=getFeesForTransaction.test.js.map