From 29222139e293f50b07f0941dc6d87916af813b4a Mon Sep 17 00:00:00 2001 From: jahabeebs <47253537+jahabeebs@users.noreply.github.com> Date: Mon, 9 Dec 2024 18:32:45 -0500 Subject: [PATCH] fix: update bond escalation status type --- .../src/services/prophetCodec.ts | 8 +++-- .../automated-dispute/src/types/prophet.ts | 2 +- .../tests/services/prophetCodec.spec.ts | 33 +++++++++++++++++-- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/packages/automated-dispute/src/services/prophetCodec.ts b/packages/automated-dispute/src/services/prophetCodec.ts index ebeda58..011c58f 100644 --- a/packages/automated-dispute/src/services/prophetCodec.ts +++ b/packages/automated-dispute/src/services/prophetCodec.ts @@ -267,13 +267,15 @@ export class ProphetCodec { static decodeBondEscalationStatus(status: number): BondEscalationStatus { switch (status) { case 0: - return "Active"; + return "None"; case 1: - return "Resolved"; + return "Active"; case 2: return "Escalated"; case 3: - return "NoResolution"; + return "DisputerLost"; + case 4: + return "DisputerWon"; default: throw new ProphetDecodingError("escalation.status", toHex(status.toString())); } diff --git a/packages/automated-dispute/src/types/prophet.ts b/packages/automated-dispute/src/types/prophet.ts index 54578cb..f70045d 100644 --- a/packages/automated-dispute/src/types/prophet.ts +++ b/packages/automated-dispute/src/types/prophet.ts @@ -94,7 +94,7 @@ export interface Response { export type DisputeStatus = "None" | "Active" | "Escalated" | "Won" | "Lost" | "NoResolution"; -export type BondEscalationStatus = "Active" | "Resolved" | "Escalated" | "NoResolution"; +export type BondEscalationStatus = "None" | "Active" | "Escalated" | "DisputerLost" | "DisputerWon"; export interface BondEscalation { disputeId: string; diff --git a/packages/automated-dispute/tests/services/prophetCodec.spec.ts b/packages/automated-dispute/tests/services/prophetCodec.spec.ts index 388e38b..b7b4f83 100644 --- a/packages/automated-dispute/tests/services/prophetCodec.spec.ts +++ b/packages/automated-dispute/tests/services/prophetCodec.spec.ts @@ -1,9 +1,9 @@ import { isHex } from "viem"; import { describe, expect, it } from "vitest"; -import { ProphetDecodingError } from "../../src/exceptions"; -import { ProphetCodec } from "../../src/services"; -import { DisputeStatus, Response } from "../../src/types"; +import { ProphetDecodingError } from "../../src/exceptions/index.js"; +import { ProphetCodec } from "../../src/index.js"; +import { BondEscalationStatus, DisputeStatus, Response } from "../../src/types/index.js"; describe("ProphetCodec", () => { describe("encodeResponse", () => { @@ -25,6 +25,33 @@ describe("ProphetCodec", () => { }); }); + describe("decodeBondEscalationStatus", () => { + const testCases: Array<{ input: number; expected: BondEscalationStatus }> = [ + { input: 0, expected: "None" }, + { input: 1, expected: "Active" }, + { input: 2, expected: "Escalated" }, + { input: 3, expected: "DisputerLost" }, + { input: 4, expected: "DisputerWon" }, + ]; + + testCases.forEach(({ input, expected }) => { + it(`maps status ${input} to '${expected}'`, () => { + const result = ProphetCodec.decodeBondEscalationStatus(input); + expect(result).toBe(expected); + }); + }); + + it("throws ProphetDecodingError for invalid escalation status", () => { + const invalidStatuses = [-1, 5, 999]; + + invalidStatuses.forEach((status) => { + expect(() => { + ProphetCodec.decodeBondEscalationStatus(status); + }).toThrow(ProphetDecodingError); + }); + }); + }); + describe("decodeDisputeStatus", () => { const testCases: Array<{ input: number; expected: DisputeStatus }> = [ { input: 0, expected: "None" },