Skip to content

feat: add jsonrpc prt tests#733

Open
mpolitzer wants to merge 1 commit intonext/2.0from
feature/add-jsonrpc-prt-tests
Open

feat: add jsonrpc prt tests#733
mpolitzer wants to merge 1 commit intonext/2.0from
feature/add-jsonrpc-prt-tests

Conversation

@mpolitzer
Copy link

@mpolitzer mpolitzer commented Jan 27, 2026

closes #682

@mpolitzer mpolitzer self-assigned this Jan 27, 2026
@mpolitzer mpolitzer added the #feat:tests Feature: tests label Jan 27, 2026
@mpolitzer mpolitzer force-pushed the feature/add-jsonrpc-prt-tests branch from 5b26aa7 to 875aa23 Compare January 27, 2026 18:19
@vfusco vfusco requested review from Copilot and removed request for renatomaia and vfusco February 11, 2026 12:35
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR expands JSON-RPC test coverage for tournament-related (“prt”) methods and adjusts repository/query behavior to make list endpoints deterministic and align empty-list responses with existing “Application not found” semantics.

Changes:

  • Add extensive JSON-RPC tests for tournament/commitment/match/match-advanced endpoints.
  • Make list endpoints return RESOURCE_NOT_FOUND: Application not found when the result is empty and the application does not exist.
  • Stabilize ordering for pagination in Postgres queries (commitments and match advances).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
internal/repository/postgres/match_advanced.go Changes ordering for ListMatchAdvances to sort by OtherParent (stabilizes pagination within a fixed epoch/tournament/id_hash).
internal/repository/postgres/commitment.go Adds secondary ORDER BY on Commitment to make pagination deterministic when many rows share the same EpochIndex.
internal/jsonrpc/jsonrpc.go Adds “application exists” checks for multiple list handlers; tweaks GetMatchAdvanced parent handling.
internal/jsonrpc/util_test.go Adds helper result structs for JSON unmarshalling in tests.
internal/jsonrpc/jsonrpc_test.go Adds large suite of tests for new/expanded tournament data methods.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mpolitzer mpolitzer force-pushed the feature/add-jsonrpc-prt-tests branch 2 times, most recently from a13fa56 to 290a589 Compare February 12, 2026 19:12
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 9 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

method := getName(t.Name())

// failure: tournament address not hex encoded -> invalid param
t.Run("malformedApplicationParameter", func(t *testing.T) {
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

The test name "malformedApplicationParameter" is misleading because this test is actually checking for a malformed tournament address parameter (not application parameter). The application parameter is valid in this test. Consider renaming to "malformedAddressParameter" to accurately reflect what is being tested.

Suggested change
t.Run("malformedApplicationParameter", func(t *testing.T) {
t.Run("malformedAddressParameter", func(t *testing.T) {

Copilot uses AI. Check for mistakes.
}

if _, err := hex.DecodeString(params.Commitment); err != nil {
if _, err := hex.DecodeString(params.Commitment); (len(params.Commitment) == 0) || (err != nil) {
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

The error message will display "Invalid commitment hex: " when the commitment parameter is empty, because hex.DecodeString("") succeeds (returns nil error). Consider checking for empty string first and providing a more specific error message, or use a validation function similar to config.ToHashFromString which requires the 0x prefix and proper hex encoding.

Suggested change
if _, err := hex.DecodeString(params.Commitment); (len(params.Commitment) == 0) || (err != nil) {
if len(params.Commitment) == 0 {
writeRPCError(w, req.ID, JSONRPC_INVALID_PARAMS, "Commitment must not be empty", nil)
return
}
if _, err := hex.DecodeString(params.Commitment); err != nil {

Copilot uses AI. Check for mistakes.
assert.Equal(t, "Application not found", resp.Error.Message)
})

// success: no tournament in the database -> 0
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

The comment says "no tournament in the database" but this test is for cartesi_listMatches and checks for empty matches. Consider updating the comment to say "no match in the database" to accurately reflect what the test does.

Suggested change
// success: no tournament in the database -> 0
// success: no match in the database -> 0

Copilot uses AI. Check for mistakes.
Comment on lines +2692 to +2693
// success: many match_advances
// create one tournament with many (match_advances) pairs.
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

The comment says "many match_advances" but this test is for cartesi_listCommitments and creates commitments. Consider updating the comment to say "many commitments" to accurately reflect what the test does.

Suggested change
// success: many match_advances
// create one tournament with many (match_advances) pairs.
// success: many commitments
// create one tournament with many commitments.

Copilot uses AI. Check for mistakes.
t.Run("cartesi_listMatchAdvances", func(t *testing.T) {
method := getName(t.Name())

// failure: no match in the database -> no application
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

The comment says "no match in the database" but this test is for cartesi_listMatchAdvances and checks for absent application. Consider updating the comment to say "no match advance in the database" to accurately reflect what the test does.

Suggested change
// failure: no match in the database -> no application
// failure: no match advance in the database -> no application

Copilot uses AI. Check for mistakes.
Comment on lines +2273 to +2275
// success: many tournaments
// create one application with many (epoch, tournament) pairs.
// use their shared Index / EpochIndex to check pagination.
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

The comment says "many tournaments" but this test is for cartesi_listMatches and creates matches, not tournaments. Consider updating the comment to say "many matches" to accurately reflect what the test does.

Suggested change
// success: many tournaments
// create one application with many (epoch, tournament) pairs.
// use their shared Index / EpochIndex to check pagination.
// success: many matches
// create one application with many (epoch, match) pairs.
// use their shared indices to check pagination.

Copilot uses AI. Check for mistakes.
t.Run("cartesi_listCommitments", func(t *testing.T) {
method := getName(t.Name())

// failure: no match in the database -> no application
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

The comment says "no match in the database" but this test is for cartesi_listCommitments and checks for absent application. Consider updating the comment to say "no commitment in the database" to accurately reflect what the test does.

Suggested change
// failure: no match in the database -> no application
// failure: no application in the database

Copilot uses AI. Check for mistakes.
assert.Equal(t, "Application not found", resp.Error.Message)
})

// success: no tournament in the database -> 0
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

The comment says "no tournament in the database" but this test is for cartesi_listCommitments and checks for empty commitments. Consider updating the comment to say "no commitment in the database" to accurately reflect what the test does.

Suggested change
// success: no tournament in the database -> 0
// success: no commitment in the database -> 0

Copilot uses AI. Check for mistakes.
assert.Equal(t, "Application not found", resp.Error.Message)
})

// success: no tournament in the database -> 0
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

The comment says "no tournament in the database" but this test is for cartesi_listMatchAdvances and checks for empty match advances. Consider updating the comment to say "no match advance in the database" to accurately reflect what the test does.

Suggested change
// success: no tournament in the database -> 0
// success: no match advance in the database -> 0

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

#feat:tests Feature: tests

Projects

Status: 🏗 In progress

Development

Successfully merging this pull request may close these issues.

Add unit tests for new JSON-RPC methods (PRT dispute entities) Tests: JSON-RPC correctness, limit & security coverage, and OpenRPC schema compliance

2 participants