Skip to content

Commit

Permalink
fix: update bond escalation status type
Browse files Browse the repository at this point in the history
  • Loading branch information
jahabeebs committed Dec 9, 2024
1 parent 6575d77 commit 2922213
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
8 changes: 5 additions & 3 deletions packages/automated-dispute/src/services/prophetCodec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
Expand Down
2 changes: 1 addition & 1 deletion packages/automated-dispute/src/types/prophet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
33 changes: 30 additions & 3 deletions packages/automated-dispute/tests/services/prophetCodec.spec.ts
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand All @@ -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" },
Expand Down

0 comments on commit 2922213

Please sign in to comment.