Skip to content

Commit

Permalink
chore: refactor some tests and decode bond escalation
Browse files Browse the repository at this point in the history
  • Loading branch information
jahabeebs committed Nov 4, 2024
1 parent ec7aebe commit f3ca2c7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,7 @@ export class ProtocolProvider implements IProtocolProvider {

const bondEscalation: BondEscalation = {
disputeId: result.disputeId,
status: ProphetCodec.decodeBondEscalationStatus(result.disputeId, result.status),
status: ProphetCodec.decodeBondEscalationStatus(result.status),
amountOfPledgesForDispute: result.amountOfPledgesForDispute,
amountOfPledgesAgainstDispute: result.amountOfPledgesAgainstDispute,
};
Expand Down
5 changes: 2 additions & 3 deletions packages/automated-dispute/src/services/prophetCodec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,10 @@ export class ProphetCodec {
/**
* Decodes the BondEscalationStatus enum from the contract.
*
* @param id - The ID of the request.
* @param status - The numeric status from the contract.
* @returns The corresponding BondEscalationStatus string.
*/
static decodeBondEscalationStatus(id: Hex, status: number): BondEscalationStatus {
static decodeBondEscalationStatus(status: number): BondEscalationStatus {
switch (status) {
case 0:
return "Active";
Expand All @@ -276,7 +275,7 @@ export class ProphetCodec {
case 3:
return "NoResolution";
default:
throw new ProphetDecodingError(id, toHex(status.toString()));
throw new ProphetDecodingError("escalation.status", toHex(status.toString()));
}
}
}
36 changes: 35 additions & 1 deletion packages/automated-dispute/tests/services/eboActor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,14 +564,17 @@ describe("EboActor", () => {
);
});

it("settles dispute when amountOfPledgesForDispute !== amountOfPledgesAgainstDispute", async () => {
it("settles dispute when amountOfPledgesForDispute > amountOfPledgesAgainstDispute", async () => {
const { actor, protocolProvider } = mocks.buildEboActor(request, logger);
const response = mocks.buildResponse(request);
const dispute = mocks.buildDispute(request, response);

const settleDisputeMock = vi
.spyOn(protocolProvider, "settleDispute")
.mockResolvedValue();
const escalateDisputeMock = vi
.spyOn(protocolProvider, "escalateDispute")
.mockResolvedValue();

vi.spyOn(protocolProvider.read, "getEscalation").mockResolvedValue({
disputeId: dispute.id,
Expand All @@ -580,13 +583,44 @@ describe("EboActor", () => {
amountOfPledgesAgainstDispute: BigInt(5),
});

await actor["settleDispute"](request, response, dispute);
expect(settleDisputeMock).toHaveBeenCalledWith(
request.prophetData,
response.prophetData,
dispute.prophetData,
);
expect(escalateDisputeMock).not.toHaveBeenCalled();

expect(logger.info).toHaveBeenCalledWith(`Dispute ${dispute.id} settled.`);
});

it("settles dispute when amountOfPledgesForDispute < amountOfPledgesAgainstDispute", async () => {
const { actor, protocolProvider } = mocks.buildEboActor(request, logger);
const response = mocks.buildResponse(request);
const dispute = mocks.buildDispute(request, response);

const settleDisputeMock = vi
.spyOn(protocolProvider, "settleDispute")
.mockResolvedValue();
const escalateDisputeMock = vi
.spyOn(protocolProvider, "escalateDispute")
.mockResolvedValue();

vi.spyOn(protocolProvider.read, "getEscalation").mockResolvedValue({
disputeId: dispute.id,
status: "Active",
amountOfPledgesForDispute: BigInt(5),
amountOfPledgesAgainstDispute: BigInt(10),
});

await actor["settleDispute"](request, response, dispute);

expect(settleDisputeMock).toHaveBeenCalledWith(
request.prophetData,
response.prophetData,
dispute.prophetData,
);
expect(escalateDisputeMock).not.toHaveBeenCalled();

expect(logger.info).toHaveBeenCalledWith(`Dispute ${dispute.id} settled.`);
});
Expand Down

0 comments on commit f3ca2c7

Please sign in to comment.