@ledgerhq/coin-aptos
Version:
Ledger Aptos Coin integration
92 lines • 3.42 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const broadcast_1 = __importDefault(require("../../bridge/broadcast"));
const network_1 = require("../../network");
const operation_1 = require("@ledgerhq/coin-framework/operation");
const bignumber_js_1 = __importDefault(require("bignumber.js"));
jest.mock("../../network");
jest.mock("@ledgerhq/coin-framework/operation");
describe("broadcast", () => {
const mockAccount = {
type: "Account",
seedIdentifier: "mockSeedIdentifier",
operationsCount: 0,
id: "mockAccountId",
currency: {
type: "CryptoCurrency",
id: "aptos",
name: "Aptos",
ticker: "APT",
units: [{ name: "APT", code: "APT", magnitude: 6 }],
managerAppName: "Aptos",
coinType: 637,
scheme: "aptos",
color: "#000000",
family: "aptos",
blockAvgTime: 5,
explorerViews: [],
},
balance: (0, bignumber_js_1.default)(1000),
spendableBalance: (0, bignumber_js_1.default)(1000),
operations: [],
pendingOperations: [],
lastSyncDate: new Date(),
blockHeight: 0,
index: 0,
derivationMode: "",
freshAddress: "",
freshAddressPath: "",
used: false,
swapHistory: [],
creationDate: new Date(),
balanceHistoryCache: {
HOUR: { latestDate: 0, balances: [] },
DAY: { latestDate: 0, balances: [] },
WEEK: { latestDate: 0, balances: [] },
},
};
const mockOperation = {
id: "mockOperationId",
hash: "",
type: "OUT",
value: (0, bignumber_js_1.default)(100),
fee: (0, bignumber_js_1.default)(1),
senders: ["sender"],
recipients: ["recipient"],
blockHeight: null,
blockHash: null,
accountId: "mockAccountId",
date: new Date(),
extra: {},
};
const mockSignedOperation = {
operation: mockOperation,
signature: "mockSignature",
};
it("should broadcast the signed operation and return the patched operation", async () => {
const mockHash = "mockHash";
network_1.AptosAPI.prototype.broadcast.mockResolvedValue(mockHash);
operation_1.patchOperationWithHash.mockReturnValue({
...mockOperation,
hash: mockHash,
});
const result = await (0, broadcast_1.default)({
signedOperation: mockSignedOperation,
account: mockAccount,
});
expect(network_1.AptosAPI.prototype.broadcast).toHaveBeenCalledWith("mockSignature");
expect(operation_1.patchOperationWithHash).toHaveBeenCalledWith(mockOperation, mockHash);
expect(result).toEqual({ ...mockOperation, hash: mockHash });
});
it("should throw an error if broadcast fails", async () => {
network_1.AptosAPI.prototype.broadcast.mockRejectedValue(new Error("Broadcast failed"));
await expect((0, broadcast_1.default)({
signedOperation: mockSignedOperation,
account: mockAccount,
})).rejects.toThrow("Broadcast failed");
});
});
//# sourceMappingURL=broadcast.test.js.map