The tests work

This commit is contained in:
2026-09-07 10:56:08 +00:00
parent f01f9bc56b
commit b7bedc5476
19 changed files with 1855 additions and 1559 deletions
+31 -14
View File
@@ -11,7 +11,7 @@ import {
reserveResource,
} from "../mocks/engine";
import { type Engine } from "@xo-cash/engine";
import { p2pkhTemplate } from "../mocks/template-p2pkh";
import { p2pkhTemplate, p2pkhTemplateIdentifier } from "../mocks/template-p2pkh";
import { AppService } from "../../../src/services/app";
import { handleResourceCommand } from "../../../src/cli/commands/resource";
@@ -125,7 +125,7 @@ describe("resource command", () => {
engine = mockEngine.engine;
await engine.importTemplate(p2pkhTemplate);
app = await createMockAppService(engine);
app = await createMockAppService(engine, mockEngine.state);
tempDir = mkdtempSync(path.join(tmpdir(), "xo-cli-resource-tests-"));
});
@@ -192,7 +192,7 @@ describe("resource command with populated data", () => {
engine = mockEngine.engine;
state = mockEngine.state;
await engine.importTemplate(p2pkhTemplate);
app = await createMockAppService(engine);
app = await createMockAppService(engine, state);
tempDir = mkdtempSync(path.join(tmpdir(), "xo-cli-resource-tests-"));
});
@@ -283,9 +283,17 @@ describe("resource command with populated data", () => {
});
test("unreserve releases a reserved UTXO", async () => {
// Create an invitation
const invitation = await engine.createInvitation({
templateIdentifier: p2pkhTemplateIdentifier,
actionIdentifier: "receive",
variables: [],
});
const invitationInstance = await app.createInvitation(invitation);
const resource = await addFakeResource(state, {
valueSatoshis: 25000,
reservedBy: "inv-123",
reservedBy: invitationInstance.data.invitationIdentifier,
});
const { io, spies } = createMockIO();
@@ -299,8 +307,8 @@ describe("resource command with populated data", () => {
);
expectLogs(spies, [
{ out: "Unreserved" },
{ out: "was reserved for inv-123" },
{ out: "Archived invitation" },
{ out: invitationInstance.data.invitationIdentifier },
]);
const resources = await engine.listUnspentOutputsData();
@@ -327,15 +335,24 @@ describe("resource command with populated data", () => {
});
test("unreserve-all releases all reserved UTXOs", async () => {
// Create 2 fake invitations
const invitation1 = await engine.createInvitation({
templateIdentifier: p2pkhTemplateIdentifier,
actionIdentifier: "receive",
variables: [],
});
const invitation2 = await engine.createInvitation({
templateIdentifier: p2pkhTemplateIdentifier,
actionIdentifier: "receive",
variables: [],
});
const invitationInstance1 = await app.createInvitation(invitation1);
const invitationInstance2 = await app.createInvitation(invitation2);
await addFakeResource(state, { valueSatoshis: 50000 });
await addFakeResource(state, {
valueSatoshis: 25000,
reservedBy: "inv-123",
});
await addFakeResource(state, {
valueSatoshis: 10000,
reservedBy: "inv-456",
});
await addFakeResource(state, { valueSatoshis: 25000, reservedBy: invitationInstance1.data.invitationIdentifier });
await addFakeResource(state, { valueSatoshis: 10000, reservedBy: invitationInstance2.data.invitationIdentifier });
const { io, spies } = createMockIO();
const result = await handleResourceCommand(