Breaking-Change: Extremely rough update to work with Kioks wallet

This commit is contained in:
2026-05-22 14:11:07 +02:00
parent 3d6518e465
commit def261b568
17 changed files with 422 additions and 107 deletions

View File

@@ -1,5 +1,5 @@
import { expect, test, describe, beforeEach, afterEach } from "vitest";
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import path from "node:path";
@@ -98,6 +98,13 @@ const testCases: TestCase[] = [
shouldThrow: false,
expectedData: {},
},
{
name: "export returns raw template json to stdout",
inputs: ["export", p2pkhTemplateIdentifier],
shouldThrow: false,
expectedData: {},
logs: [{ out: "\"name\":\"Wallet (P2PKH)\"" }],
},
// Error cases - subcommand
{
name: "throws when no subcommand provided",
@@ -124,6 +131,18 @@ const testCases: TestCase[] = [
shouldThrow: true,
expectedEvent: "template.import.file_not_found",
},
{
name: "throws when export called without template identifier",
inputs: ["export"],
shouldThrow: true,
expectedEvent: "template.export.identifier_missing",
},
{
name: "throws when export called with unknown template",
inputs: ["export", "unknown-template"],
shouldThrow: true,
expectedEvent: "template.export.not_found",
},
// Error cases - list category
{
name: "throws when list category called without template identifier",
@@ -263,4 +282,42 @@ describe("template command", () => {
process.chdir(originalCwd);
}
});
test("export prints exact engine template JSON to stdout", async () => {
const { io, capture } = createMockIO();
const expectedTemplate = await engine.getTemplate(p2pkhTemplateIdentifier);
expect(expectedTemplate).toBeDefined();
await handleTemplateCommand(
createCommandDeps(app, io),
["export", p2pkhTemplateIdentifier],
{},
);
expect(capture.out[0]).toBe(JSON.stringify(expectedTemplate));
});
test("export writes exact engine template JSON to file", async () => {
const outputFile = "exported-template.json";
const outputPath = path.join(tempDir, outputFile);
const { io } = createMockIO();
const expectedTemplate = await engine.getTemplate(p2pkhTemplateIdentifier);
expect(expectedTemplate).toBeDefined();
const originalCwd = process.cwd();
process.chdir(tempDir);
try {
const result = await handleTemplateCommand(
createCommandDeps(app, io),
["export", p2pkhTemplateIdentifier],
{ output: outputFile },
);
const exportedTemplate = readFileSync(outputPath, "utf8");
expect(exportedTemplate).toBe(JSON.stringify(expectedTemplate));
expect(result.outputFile).toBe(path.resolve(process.cwd(), outputFile));
} finally {
process.chdir(originalCwd);
}
});
});