Fix tests

This commit is contained in:
2026-04-27 09:45:38 +00:00
parent e97054fa34
commit bd1ae909b5
7 changed files with 92 additions and 44 deletions

View File

@@ -22,6 +22,7 @@ import {
expectLogs,
type LogExpectation,
} from "../mocks/command";
import { State } from "@xo-cash/state";
type TestCase = {
name: string;
@@ -120,7 +121,8 @@ describe("resource command", () => {
let tempDir: string;
beforeEach(async () => {
engine = await createMockEngine(DEFAULT_SEED);
const mockEngine = await createMockEngine(DEFAULT_SEED);
engine = mockEngine.engine;
await engine.importTemplate(p2pkhTemplate);
app = await createMockAppService(engine);
@@ -181,11 +183,14 @@ describe("resource command", () => {
describe("resource command with populated data", () => {
let engine: Engine;
let state: State;
let app: AppService;
let tempDir: string;
beforeEach(async () => {
engine = await createMockEngine(DEFAULT_SEED);
const mockEngine = await createMockEngine(DEFAULT_SEED);
engine = mockEngine.engine;
state = mockEngine.state;
await engine.importTemplate(p2pkhTemplate);
app = await createMockAppService(engine);
tempDir = mkdtempSync(path.join(tmpdir(), "xo-cli-resource-tests-"));
@@ -197,8 +202,8 @@ describe("resource command with populated data", () => {
});
test("list returns count when resources exist", async () => {
await addFakeResource(engine, { valueSatoshis: 50000 });
await addFakeResource(engine, { valueSatoshis: 25000 });
await addFakeResource(state, { valueSatoshis: 50000 });
await addFakeResource(state, { valueSatoshis: 25000 });
const { io, spies } = createMockIO();
const result = await handleResourceCommand(
@@ -212,8 +217,8 @@ describe("resource command with populated data", () => {
});
test("list shows total satoshis", async () => {
await addFakeResource(engine, { valueSatoshis: 50000 });
await addFakeResource(engine, { valueSatoshis: 25000 });
await addFakeResource(state, { valueSatoshis: 50000 });
await addFakeResource(state, { valueSatoshis: 25000 });
const { io, spies } = createMockIO();
await handleResourceCommand(createCommandDeps(app, io), ["list"], {});
@@ -222,8 +227,8 @@ describe("resource command with populated data", () => {
});
test("list excludes reserved resources by default", async () => {
await addFakeResource(engine, { valueSatoshis: 50000 });
await addFakeResource(engine, {
await addFakeResource(state, { valueSatoshis: 50000 });
await addFakeResource(state, {
valueSatoshis: 25000,
reservedBy: "inv-123",
});
@@ -239,12 +244,12 @@ describe("resource command with populated data", () => {
});
test("list reserved shows only reserved resources", async () => {
await addFakeResource(engine, { valueSatoshis: 50000 });
await addFakeResource(engine, {
await addFakeResource(state, { valueSatoshis: 50000 });
await addFakeResource(state, {
valueSatoshis: 25000,
reservedBy: "inv-123",
});
await addFakeResource(engine, {
await addFakeResource(state, {
valueSatoshis: 10000,
reservedBy: "inv-456",
});
@@ -261,8 +266,8 @@ describe("resource command with populated data", () => {
});
test("list all shows both reserved and unreserved", async () => {
await addFakeResource(engine, { valueSatoshis: 50000 });
await addFakeResource(engine, {
await addFakeResource(state, { valueSatoshis: 50000 });
await addFakeResource(state, {
valueSatoshis: 25000,
reservedBy: "inv-123",
});
@@ -278,7 +283,7 @@ describe("resource command with populated data", () => {
});
test("unreserve releases a reserved UTXO", async () => {
const resource = await addFakeResource(engine, {
const resource = await addFakeResource(state, {
valueSatoshis: 25000,
reservedBy: "inv-123",
});
@@ -306,7 +311,7 @@ describe("resource command with populated data", () => {
});
test("unreserve reports when UTXO is not reserved", async () => {
const resource = await addFakeResource(engine, { valueSatoshis: 25000 });
const resource = await addFakeResource(state, { valueSatoshis: 25000 });
const { io, spies } = createMockIO();
await handleResourceCommand(
@@ -322,12 +327,12 @@ describe("resource command with populated data", () => {
});
test("unreserve-all releases all reserved UTXOs", async () => {
await addFakeResource(engine, { valueSatoshis: 50000 });
await addFakeResource(engine, {
await addFakeResource(state, { valueSatoshis: 50000 });
await addFakeResource(state, {
valueSatoshis: 25000,
reservedBy: "inv-123",
});
await addFakeResource(engine, {
await addFakeResource(state, {
valueSatoshis: 10000,
reservedBy: "inv-456",
});
@@ -348,7 +353,7 @@ describe("resource command with populated data", () => {
});
test("list displays outpoint information", async () => {
const resource = await addFakeResource(engine, { valueSatoshis: 12345 });
const resource = await addFakeResource(state, { valueSatoshis: 12345 });
const { io, spies } = createMockIO();
await handleResourceCommand(createCommandDeps(app, io), ["list"], {});