@ledgerhq/coin-ton
Version:
72 lines • 3.15 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@ton/core");
const bignumber_js_1 = __importDefault(require("bignumber.js"));
const api_1 = require("../../bridge/bridgeHelpers/api");
const signOperation_1 = require("../../signOperation");
const common_fixtures_1 = require("../fixtures/common.fixtures");
jest.mock("../../bridge/bridgeHelpers/api");
const spySignTransaction = jest.fn().mockImplementation(async () => Promise.resolve((0, core_1.beginCell)()
.store((0, core_1.storeMessage)({
info: {
type: "external-in",
dest: core_1.Address.parse("EQDzd8aeBOU-jqYw_ZSuZjceI5p-F4b7HMprAsUJAtRPbJfg"),
importFee: BigInt(0),
},
body: new core_1.Cell(),
}))
.endCell()));
const mockSignerContext = (_, fn) => {
return fn({
signTransaction: spySignTransaction,
getAddress: jest.fn(),
validateAddress: jest.fn(),
});
};
describe("signOperation", () => {
beforeAll(() => {
const fetchAccountInfoMock = jest.mocked(api_1.fetchAccountInfo);
fetchAccountInfoMock.mockReturnValue(Promise.resolve(common_fixtures_1.accountInfo));
});
it("should return an optimistic operation and a signed hash returned by the app bindings", done => {
const signOperation = (0, signOperation_1.buildSignOperation)(mockSignerContext);
const signOpObservable = signOperation({
account: common_fixtures_1.account,
transaction: { ...common_fixtures_1.transaction, fees: common_fixtures_1.totalFees },
deviceId: "",
});
signOpObservable.subscribe(obs => {
if (obs.type === "signed") {
const { signedOperation: { signature, operation }, } = obs;
const { amount } = common_fixtures_1.transaction;
expect(operation).toEqual({
id: "",
hash: "",
type: "OUT",
value: new bignumber_js_1.default(amount).plus(common_fixtures_1.totalFees),
fee: common_fixtures_1.totalFees,
blockHash: null,
blockHeight: null,
senders: [common_fixtures_1.account.freshAddress],
recipients: [common_fixtures_1.transaction.recipient],
accountId: common_fixtures_1.account.id,
date: expect.any(Date),
extra: {
comment: {
isEncrypted: false,
text: "",
},
explorerHash: "",
lt: "",
},
});
expect(signature).toBe("te6cckEBAQEASAAAi4gB5u+NPAnKfR1MYfspXMxuPEc0/C8N9jmU1gWKEgWontgEQA83fGngTlPo6mMP2UrmY3HiOafheG+xzKawLFCQLUT2wCDSMh+F");
done();
}
});
});
});
//# sourceMappingURL=signOperation.unit.test.js.map