Skip to content

Commit

Permalink
feat: use EboRegistry interface
Browse files Browse the repository at this point in the history
  • Loading branch information
0xyaco committed Aug 7, 2024
1 parent 33271d7 commit 6647610
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
6 changes: 2 additions & 4 deletions packages/automated-dispute/src/eboActor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { BlockNumberService } from "@ebo-agent/blocknumber";
import { Caip2ChainId } from "@ebo-agent/blocknumber/dist/types.js";
import { ILogger } from "@ebo-agent/shared";

import { EboRegistry } from "./eboRegistry.js";
import { RequestMismatch } from "./exceptions/requestMismatch.js";
import { EboRegistry } from "./interfaces/eboRegistry.js";
import { ProtocolProvider } from "./protocolProvider.js";
import { EboEvent } from "./types/events.js";
import { Dispute, Response } from "./types/prophet.js";
Expand Down Expand Up @@ -37,9 +37,7 @@ export class EboActor {
chainId,
);

if (this.alreadyProposed(currentEpoch, chainId, epochBlockNumber)) {
return;
}
if (this.alreadyProposed(currentEpoch, chainId, epochBlockNumber)) return;

await this.protocolProvider.proposeResponse(
this.requestId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { EboRegistry } from "./interfaces/eboRegistry.js";
import { Dispute, Request, Response } from "./types/prophet.js";

export class EboRegistry {
export class EboMemoryRegistry implements EboRegistry {
private requests: Map<string, Request>;
private responses: Map<string, Response>;
private dispute: Map<string, Dispute>;
Expand All @@ -11,21 +12,10 @@ export class EboRegistry {
this.dispute = new Map();
}

/**
* Add a `Request` by ID.
*
* @param requestId the ID of the `Request`
* @param request the `Request`
*/
public addRequest(requestId: string, request: Request) {
this.requests.set(requestId, request);
}

/**
* Return all responses
*
* @returns responses map
*/
public getResponses() {
return this.responses;
}
Expand Down
18 changes: 18 additions & 0 deletions packages/automated-dispute/src/interfaces/eboRegistry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Request, Response } from "../types/prophet.js";

export interface EboRegistry {
/**
* Add a `Request` by ID.
*
* @param requestId the ID of the `Request`
* @param request the `Request`
*/
addRequest(requestId: string, request: Request): void;

/**
* Return all responses
*
* @returns responses map
*/
getResponses(): Map<string, Response>;
}
8 changes: 4 additions & 4 deletions packages/automated-dispute/tests/eboActor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { BlockNumberService } from "@ebo-agent/blocknumber";
import { Caip2ChainId } from "@ebo-agent/blocknumber/dist/types.js";
import { Logger } from "@ebo-agent/shared";
import { Address } from "viem";
import { beforeEach, describe, expect, it, Mock, vi } from "vitest";
import { beforeEach, describe, expect, it, vi } from "vitest";

import { EboActor } from "../src/eboActor.js";
import { EboRegistry } from "../src/eboRegistry.js";
import { EboMemoryRegistry } from "../src/eboMemoryRegistry.js";
import { RequestMismatch } from "../src/exceptions/requestMismatch.js";
import { ProtocolProvider } from "../src/protocolProvider.js";
import { EboEvent } from "../src/types/events.js";
Expand Down Expand Up @@ -52,7 +52,7 @@ describe("EboActor", () => {

let protocolProvider: ProtocolProvider;
let blockNumberService: BlockNumberService;
let registry: EboRegistry;
let registry: EboMemoryRegistry;

beforeEach(() => {
protocolProvider = new ProtocolProvider(["http://localhost:8538"], protocolContracts);
Expand All @@ -61,7 +61,7 @@ describe("EboActor", () => {
chainRpcUrls.set(indexedChainId, ["http://localhost:8539"]);

blockNumberService = new BlockNumberService(chainRpcUrls, logger);
registry = new EboRegistry();
registry = new EboMemoryRegistry();
});

it("proposes a response", async () => {
Expand Down

0 comments on commit 6647610

Please sign in to comment.