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: Ensure that SDK getDispute() returns the RTA/Invalid answer #1831

Merged
merged 5 commits into from
Jan 15, 2025

Conversation

jaybuidl
Copy link
Member

@jaybuidl jaybuidl commented Jan 13, 2025

Resolves https://github.com/kleros/atlas/issues/369


PR-Codex overview

This PR updates the @kleros/kleros-sdk package version and enhances the getDispute functionality to include a standard "Refuse to Arbitrate" answer in various scenarios. It also adds tests to ensure this behavior works correctly.

Detailed summary

  • Updated version in package.json from 2.1.10 to 2.1.12.
  • Added a standard "Refuse to Arbitrate" answer to populatedTemplate.answers in getDispute.
  • Implemented tests for getDispute in getDispute.test.ts:
    • Check for addition when answers array is empty.
    • Validate addition when the option doesn't exist.
    • Ensure overwriting of existing answers with id 0x0 or 0x00.
    • Test error handling for missing dispute details and templates.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • New Features

    • Added "Refuse to Arbitrate" option to dispute answers.
    • Ensured the option is always present in the dispute template.
  • Tests

    • Added comprehensive test suite for the getDispute function.
    • Validated error handling and option inclusion scenarios.
  • Version Update

    • Bumped package version from 2.1.10 to 2.1.12.

Copy link
Contributor

coderabbitai bot commented Jan 13, 2025

Walkthrough

This pull request updates the version of the @kleros/kleros-sdk package from 2.1.10 to 2.1.12. The getDispute function is enhanced to guarantee that a "Refuse to Arbitrate" option is always included in the answers array. Additionally, a new test suite is introduced for the getDispute function, validating its behavior across various scenarios, including the addition of the "Refuse to Arbitrate" option and error handling.

Changes

File Change Summary
kleros-sdk/package.json Version bumped from 2.1.10 to 2.1.12
kleros-sdk/src/utils/getDispute.ts Added logic to ensure "Refuse to Arbitrate" option is included in answers array
kleros-sdk/test/getDispute.test.ts Introduced test suite for getDispute function with multiple scenarios

Assessment against linked issues

Objective Addressed Explanation
Confirm issue cause [#369]
Fix bug in won side [#369] Requires further investigation of specific dispute details.
Improve logging [#369] No logging improvements visible in this PR.

Possibly related PRs

Suggested labels

Type: Maintenance :construction:

Suggested reviewers

  • alcercu

Poem

🐰 In Kleros land, where disputes arise,
"Refuse to Arbitrate" now wears a prize.
With version updated, our tests take flight,
Ensuring fairness in the legal night!
A hop, a skip, through code we go,
For justice and clarity, we’ll always sow! 🏹


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6d0cbeb and 147215a.

📒 Files selected for processing (3)
  • kleros-sdk/package.json (1 hunks)
  • kleros-sdk/src/utils/getDispute.ts (1 hunks)
  • kleros-sdk/test/getDispute.test.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • kleros-sdk/package.json
  • kleros-sdk/src/utils/getDispute.ts
  • kleros-sdk/test/getDispute.test.ts
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: contracts-testing
  • GitHub Check: Analyze (javascript)
  • GitHub Check: dependency-review

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Jan 13, 2025

Deploy Preview for kleros-v2-testnet ready!

Name Link
🔨 Latest commit 364cb02
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-testnet/deploys/678779162fb13e00089a1e13
😎 Deploy Preview https://deploy-preview-1831--kleros-v2-testnet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Jan 13, 2025

Deploy Preview for kleros-v2-university ready!

Name Link
🔨 Latest commit 364cb02
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-university/deploys/678779164bf8750008cdf67f
😎 Deploy Preview https://deploy-preview-1831--kleros-v2-university.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Jan 13, 2025

Deploy Preview for kleros-v2-neo ready!

Name Link
🔨 Latest commit 364cb02
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-neo/deploys/678779160c88d9000893f7ad
😎 Deploy Preview https://deploy-preview-1831--kleros-v2-neo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
kleros-sdk/test/getDispute.test.ts (3)

28-61: Add test cases for edge cases and malformed data

While the test coverage is good, consider adding these test cases:

  1. Malformed answer structure (missing required fields)
  2. Non-hex IDs in answers array
  3. Snapshot test for the entire dispute object

Example test case for malformed data:

it("should handle malformed answer structure gracefully", async () => {
  const mockTemplate = {
    disputeTemplate: {
      templateData: JSON.stringify({
        answers: [
          { /* missing id */ },
          { id: null },
          { id: undefined },
        ],
      }),
      templateDataMappings: "",
    },
  };
  
  // ... setup mocks ...
  
  const result = await getDispute({
    disputeId: mockDisputeId,
    coreSubgraph: mockCoreSubgraph,
    dtrSubgraph: mockDtrSubgraph,
  });
  
  expect(result?.answers[0].id).toBe("0x0");
});

198-208: Enhance error test with specific error type

The error test could be more specific by checking the exact error type.

   await expect(
     getDispute({
       disputeId: mockDisputeId,
       coreSubgraph: mockCoreSubgraph,
       dtrSubgraph: mockDtrSubgraph,
     })
-  ).rejects.toThrow("Dispute details not found");
+  ).rejects.toThrow(NotFoundError);
+  ).rejects.toThrowError("Dispute details not found for disputeId: 123");

6-8: Consider using more specific mock imports

Instead of mocking the entire module, consider mocking specific functions for better test isolation.

-vi.mock("../src/requests/fetchDisputeDetails");
-vi.mock("../src/requests/fetchDisputeTemplateFromId");
+vi.mock("../src/requests/fetchDisputeDetails", () => ({
+  default: vi.fn()
+}));
+vi.mock("../src/requests/fetchDisputeTemplateFromId", () => ({
+  default: vi.fn()
+}));
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6f21310 and 6411a42.

📒 Files selected for processing (3)
  • kleros-sdk/package.json (1 hunks)
  • kleros-sdk/src/utils/getDispute.ts (1 hunks)
  • kleros-sdk/test/getDispute.test.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • kleros-sdk/package.json
⏰ Context from checks skipped due to timeout of 90000ms (18)
  • GitHub Check: Redirect rules - kleros-v2-neo
  • GitHub Check: Header rules - kleros-v2-neo
  • GitHub Check: Pages changed - kleros-v2-neo
  • GitHub Check: Redirect rules - kleros-v2-university
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-university
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-university
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Copy labels from linked issues
  • GitHub Check: SonarCloud
  • GitHub Check: contracts-testing
  • GitHub Check: Copy labels from linked issues
  • GitHub Check: dependency-review
  • GitHub Check: Analyze (javascript)

Copy link

netlify bot commented Jan 13, 2025

Deploy Preview for kleros-v2-testnet-devtools failed. Why did it fail? →

Name Link
🔨 Latest commit 364cb02
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-testnet-devtools/deploys/678779161aed8a0008123e2c

coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 13, 2025
salgozino
salgozino previously approved these changes Jan 13, 2025
Copy link

@salgozino salgozino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
Thanks for the quick change

Copy link
Contributor

@Harman-singh-waraich Harman-singh-waraich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@jaybuidl jaybuidl force-pushed the fix/sdk-getdispute-answer0 branch from 6411a42 to 6d0cbeb Compare January 14, 2025 17:28
Copy link
Contributor

@alcercu alcercu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link

codeclimate bot commented Jan 15, 2025

Code Climate has analyzed commit 364cb02 and detected 2 issues on this pull request.

Here's the issue category breakdown:

Category Count
Duplication 2

View more on Code Climate.

@jaybuidl jaybuidl merged commit 09e3971 into dev Jan 15, 2025
21 of 27 checks passed
@jaybuidl jaybuidl deleted the fix/sdk-getdispute-answer0 branch January 15, 2025 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants