Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update bond escalation status type #100

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading