Skip to content

Commit

Permalink
fix: replace noop with FinalizeRequest command
Browse files Browse the repository at this point in the history
  • Loading branch information
0xyaco committed Sep 9, 2024
1 parent 92ed29f commit 165c8e8
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 72 deletions.
7 changes: 5 additions & 2 deletions packages/automated-dispute/src/eboActor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
AddDispute,
AddRequest,
AddResponse,
Noop,
FinalizeRequest,
UpdateDisputeStatus,
} from "./services/index.js";
import {
Expand Down Expand Up @@ -202,7 +202,10 @@ export class EboActor {
);

case "RequestFinalized":
return Noop.buildFromEvent();
return FinalizeRequest.buildFromEvent(
event as EboEvent<"RequestFinalized">,
this.registry,
);

default:
throw new UnknownEvent(event.name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ export * from "./addDispute.js";
export * from "./addRequest.js";
export * from "./addResponse.js";
export * from "./finalizeRequest.js";
export * from "./noop.js";
export * from "./updateDisputeStatus.js";

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,43 +1,60 @@
import { ILogger } from "@ebo-agent/shared";
import { describe, expect, it, vi } from "vitest";

import { FinalizeRequest } from "../../src/services/index.js";
import { EboEvent } from "../../src/types/index.js";
import mocks from "../mocks/index.js";
import { DEFAULT_MOCKED_REQUEST_CREATED_DATA } from "./fixtures.js";

const logger: ILogger = mocks.mockLogger();

describe("EboActor", () => {
describe("onRequestFinalized", () => {
const actorRequest = DEFAULT_MOCKED_REQUEST_CREATED_DATA;

const event: EboEvent<"RequestFinalized"> = {
name: "RequestFinalized",
requestId: actorRequest.id,
blockNumber: 1n,
logIndex: 1,
metadata: {
blockNumber: 1n,
caller: "0x01",
describe("processEvents", () => {
describe("when RequestFinalized is enqueued", () => {
const actorRequest = DEFAULT_MOCKED_REQUEST_CREATED_DATA;

const event: EboEvent<"RequestFinalized"> = {
name: "RequestFinalized",
requestId: actorRequest.id,
responseId: "0x02",
},
};
blockNumber: 1n,
logIndex: 1,
metadata: {
blockNumber: 1n,
caller: "0x01",
requestId: actorRequest.id,
responseId: "0x02",
},
};

it("logs a message during request finalization", async () => {
const { actor, registry } = mocks.buildEboActor(actorRequest, logger);

vi.spyOn(registry, "getRequest").mockReturnValue(actorRequest);

const mockInfo = vi.spyOn(logger, "info");

actor.enqueue(event);

await actor.processEvents();

expect(mockInfo).toHaveBeenCalledWith(
expect.stringMatching(`Request ${actorRequest.id} has been finalized.`),
);
});

it("logs a message during request finalization", async () => {
const { actor, registry } = mocks.buildEboActor(actorRequest, logger);
it("uses the FinalizeRequest registry command", async () => {
const { actor, registry } = mocks.buildEboActor(actorRequest, logger);

vi.spyOn(registry, "getRequest").mockReturnValue(actorRequest);
vi.spyOn(registry, "getRequest").mockReturnValue(actorRequest);

const mockInfo = vi.spyOn(logger, "info");
const mockBuildFromEvent = vi.spyOn(FinalizeRequest, "buildFromEvent");

actor.enqueue(event);
actor.enqueue(event);

await actor.processEvents();
await actor.processEvents();

expect(mockInfo).toHaveBeenCalledWith(
expect.stringMatching(`Request ${actorRequest.id} has been finalized.`),
);
expect(mockBuildFromEvent).toHaveBeenCalledWith(event, registry);
});
});
});
});

This file was deleted.

0 comments on commit 165c8e8

Please sign in to comment.