@ledgerhq/coin-icon
Version:
Ledger Icon Coin integration
70 lines • 3.03 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 bridge_fixture_1 = require("../../types/bridge.fixture");
const buildTransaction_1 = require("../../buildTransaction");
const mockFrom = jest.fn().mockReturnThis();
const mockTo = jest.fn().mockReturnThis();
const mockValue = jest.fn().mockReturnThis();
const mockNid = jest.fn().mockReturnThis();
const mockNonce = jest.fn().mockReturnThis();
const mockTimestamp = jest.fn().mockReturnThis();
const mockVersion = jest.fn().mockReturnThis();
const mockStepLimit = jest.fn().mockReturnThis();
const mockBuild = jest.fn().mockReturnValue("mocked-transaction");
jest.mock("icon-sdk-js", () => ({
IconBuilder: {
IcxTransactionBuilder: jest.fn().mockImplementation(() => ({
from: mockFrom,
to: mockTo,
value: mockValue,
nid: mockNid,
nonce: mockNonce,
timestamp: mockTimestamp,
version: mockVersion,
stepLimit: mockStepLimit,
build: mockBuild,
})),
},
IconConverter: {
toHexNumber: jest.fn(value => `0x${value}`),
},
}));
jest.mock("../../logic", () => ({
getNid: jest.fn().mockReturnValue(1),
getNonce: jest.fn().mockReturnValue(1),
}));
describe("buildTransaction", () => {
const account = (0, bridge_fixture_1.createFixtureAccount)();
const transaction = (0, bridge_fixture_1.createFixtureTransaction)({
mode: "send",
recipient: "WHATEVER",
});
afterEach(() => {
jest.clearAllMocks();
});
it("should build a transfer transaction", async () => {
const stepLimit = new bignumber_js_1.default(100000);
const result = await (0, buildTransaction_1.buildTransaction)(account, transaction, stepLimit);
expect(mockFrom).toHaveBeenCalledWith(account.freshAddress);
expect(mockTo).toHaveBeenCalledWith(transaction.recipient);
expect(mockValue).toHaveBeenCalledWith(expect.any(String));
expect(mockNid).toHaveBeenCalledWith(expect.any(String));
expect(mockNonce).toHaveBeenCalledWith(expect.any(String));
expect(mockTimestamp).toHaveBeenCalledWith(expect.any(String));
expect(mockVersion).toHaveBeenCalledWith(expect.any(String));
expect(mockStepLimit).toHaveBeenCalledWith(expect.any(String));
expect(result.unsigned).toBe("mocked-transaction");
});
it("should throw an error for unsupported transaction mode", async () => {
const invalidTransaction = {
...transaction,
mode: "invalid-mode",
};
await expect((0, buildTransaction_1.buildTransaction)(account, invalidTransaction)).rejects.toThrow("Unsupported transaction mode: invalid-mode");
});
});
//# sourceMappingURL=buildTransaction.test.js.map