-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into feat/grt-140-implement-eborequestcreator-rpc-…
…calls
- Loading branch information
Showing
17 changed files
with
354 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./commandAlreadyRun.js"; | ||
export * from "./commandNotRun.js"; | ||
export * from "./disputeNotFound.js"; | ||
export * from "./requestNotFound.js"; |
7 changes: 7 additions & 0 deletions
7
packages/automated-dispute/src/exceptions/eboRegistry/requestNotFound.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export class RequestNotFound extends Error { | ||
constructor(requestId: string) { | ||
super(`Request ${requestId} was not found.`); | ||
|
||
this.name = "RequestNotFound"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
packages/automated-dispute/src/services/eboRegistry/commands/finalizeRequest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { CommandAlreadyRun, CommandNotRun, RequestNotFound } from "../../../exceptions/index.js"; | ||
import { EboRegistry, EboRegistryCommand } from "../../../interfaces/index.js"; | ||
import { EboEvent, Request, RequestStatus } from "../../../types/index.js"; | ||
|
||
export class FinalizeRequest implements EboRegistryCommand { | ||
private wasRun: boolean = false; | ||
private previousStatus?: RequestStatus; | ||
|
||
private constructor( | ||
private readonly registry: EboRegistry, | ||
private readonly request: Request, | ||
) {} | ||
|
||
public static buildFromEvent( | ||
event: EboEvent<"RequestFinalized">, | ||
registry: EboRegistry, | ||
): FinalizeRequest { | ||
const requestId = event.metadata.requestId; | ||
const request = registry.getRequest(requestId); | ||
|
||
if (!request) throw new RequestNotFound(requestId); | ||
|
||
return new FinalizeRequest(registry, request); | ||
} | ||
|
||
run(): void { | ||
if (this.wasRun) throw new CommandAlreadyRun(FinalizeRequest.name); | ||
|
||
this.previousStatus = this.request.status; | ||
|
||
this.registry.updateRequestStatus(this.request.id, "Finalized"); | ||
|
||
this.wasRun = true; | ||
} | ||
|
||
undo(): void { | ||
if (!this.wasRun || !this.previousStatus) throw new CommandNotRun(FinalizeRequest.name); | ||
|
||
this.registry.updateRequestStatus(this.request.id, this.previousStatus); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
packages/automated-dispute/src/services/eboRegistry/commands/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export * from "./addDispute.js"; | ||
export * from "./addRequest.js"; | ||
export * from "./addResponse.js"; | ||
export * from "./noop.js"; | ||
export * from "./finalizeRequest.js"; | ||
export * from "./updateDisputeStatus.js"; |
22 changes: 0 additions & 22 deletions
22
packages/automated-dispute/src/services/eboRegistry/commands/noop.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 48 additions & 23 deletions
71
packages/automated-dispute/tests/eboActor/onRequestFinalized.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,68 @@ | ||
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("uses the FinalizeRequest registry command", async () => { | ||
const { actor, registry } = mocks.buildEboActor(actorRequest, logger); | ||
|
||
it("logs a message during request finalization", async () => { | ||
const { actor, registry } = mocks.buildEboActor(actorRequest, logger); | ||
vi.spyOn(registry, "getRequest").mockReturnValue(actorRequest); | ||
|
||
vi.spyOn(registry, "getRequest").mockReturnValue(actorRequest); | ||
const mockFinalizeRequest = { | ||
run: vi.fn(), | ||
undo: vi.fn(), | ||
} as unknown as FinalizeRequest; | ||
|
||
const mockInfo = vi.spyOn(logger, "info"); | ||
const mockBuildFromEvent = vi | ||
.spyOn(FinalizeRequest, "buildFromEvent") | ||
.mockReturnValue(mockFinalizeRequest); | ||
|
||
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); | ||
expect(mockFinalizeRequest.run).toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.