Skip to content

Commit

Permalink
✅ (signer-btc): Add tests for update psbt & sign transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
jdabbech-ledger committed Jan 17, 2025
1 parent f919cd2 commit 06753e0
Show file tree
Hide file tree
Showing 12 changed files with 919 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@ import {
type CommandErrorResult,
type DeviceActionState,
type ExecuteDeviceActionReturnType,
type HexaString,
type OpenAppDAError,
type OpenAppDARequiredInteraction,
} from "@ledgerhq/device-management-kit";

import { type SignPsbtDARequiredInteraction } from "@api/app-binder/SignPsbtDeviceActionTypes";
import { type Psbt as ApiPsbt } from "@api/model/Psbt";
import { type PsbtSignature } from "@api/model/Signature";
import { type Wallet as ApiWallet } from "@api/model/Wallet";
import { type BtcErrorCodes } from "@internal/app-binder/command/utils/bitcoinAppErrors";
import { type PsbtSignature } from "@internal/app-binder/task/SignPsbtTask";
import { type DataStoreService } from "@internal/data-store/service/DataStoreService";
import { type Psbt as InternalPsbt } from "@internal/psbt/model/Psbt";
import { type PsbtMapper } from "@internal/psbt/service/psbt/PsbtMapper";
import { type ValueParser } from "@internal/psbt/service/value/ValueParser";
import { type WalletBuilder } from "@internal/wallet/service/WalletBuilder";
import { type WalletSerializer } from "@internal/wallet/service/WalletSerializer";

export type SignTransactionDAOutput = string;
export type SignTransactionDAOutput = HexaString;

export type SignTransactionDAInput = {
psbt: ApiPsbt;
Expand Down Expand Up @@ -52,7 +53,7 @@ export type SignTransactionDAInternalState = {
readonly error: SignTransactionDAError | null;
readonly signatures: PsbtSignature[] | null;
readonly signedPsbt: InternalPsbt | null;
readonly transaction: string | null;
readonly transaction: HexaString | null;
};

export type SignTransactionDAReturnType = ExecuteDeviceActionReturnType<
Expand Down
29 changes: 29 additions & 0 deletions packages/signer/signer-btc/src/internal/DefaultSignerBtc.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { type DeviceManagementKit } from "@ledgerhq/device-management-kit";

import { DefaultDescriptorTemplate, DefaultWallet } from "@api/model/Wallet";
import { DefaultSignerBtc } from "@internal/DefaultSignerBtc";
import { GetExtendedPublicKeyUseCase } from "@internal/use-cases/get-extended-public-key/GetExtendedPublicKeyUseCase";
import { SignPsbtUseCase } from "@internal/use-cases/sign-psbt/SignPsbtUseCase";
import { SignTransactionUseCase } from "@internal/use-cases/sign-transaction/SignTransactionUseCase";

import { SignMessageUseCase } from "./use-cases/sign-message/SignMessageUseCase";

Expand Down Expand Up @@ -39,4 +42,30 @@ describe("DefaultSignerBtc", () => {
signer.signMessage(derivationPath, message);
expect(SignMessageUseCase.prototype.execute).toHaveBeenCalled();
});
it("should call signPsbtUseCase", () => {
jest.spyOn(SignPsbtUseCase.prototype, "execute");
const sessionId = "session-id";
const dmk = {
executeDeviceAction: jest.fn(),
} as unknown as DeviceManagementKit;
const signer = new DefaultSignerBtc({ dmk, sessionId });
signer.signPsbt(
new DefaultWallet("44'/0'/0'", DefaultDescriptorTemplate.NATIVE_SEGWIT),
"",
);
expect(SignPsbtUseCase.prototype.execute).toHaveBeenCalled();
});
it("should call signTransactionUseCase", () => {
jest.spyOn(SignTransactionUseCase.prototype, "execute");
const sessionId = "session-id";
const dmk = {
executeDeviceAction: jest.fn(),
} as unknown as DeviceManagementKit;
const signer = new DefaultSignerBtc({ dmk, sessionId });
signer.signTransaction(
new DefaultWallet("44'/0'/0'", DefaultDescriptorTemplate.NATIVE_SEGWIT),
"",
);
expect(SignTransactionUseCase.prototype.execute).toHaveBeenCalled();
});
});
Loading

0 comments on commit 06753e0

Please sign in to comment.