Skip to content

[KLC-2332] Override KLV and KFI asset metadata in GetAsset response#40

Closed
Beroni wants to merge 4 commits into
developfrom
KLC-2332-fix-return-of-klv-and-kfi-endpoints-on-node-calls
Closed

[KLC-2332] Override KLV and KFI asset metadata in GetAsset response#40
Beroni wants to merge 4 commits into
developfrom
KLC-2332-fix-return-of-klv-and-kfi-endpoints-on-node-calls

Conversation

@Beroni

@Beroni Beroni commented Apr 29, 2026

Copy link
Copy Markdown
Member

Summary

Override the KLV and KFI asset metadata in the GetAsset node
API response so clients receive up-to-date logo and URI values
instead of the stale ones registered at genesis.

Problem

The KLV and KFI assets had their Logo and URIs registered at
genesis and have since become outdated. Updating those fields
on-chain would require a hard fork, so the GET /asset/:id
endpoint kept returning incorrect metadata for the two native
assets.

Solution

Patch the response in the API layer: after fetching the asset,
if the ID is KLV or KFI, replace the Logo and URIs with
the current canonical values before serializing the response.
All other assets are returned untouched.

Key Changes

  • New:
    • replaceKDAInfo helper in network/api/asset/routes.go
      that overrides Logo and URIs for KLV and KFI.
    • KLVAssetID and KFIAssetID constants in
      network/api/asset/routes.go.
  • Updated:
    • GetAsset in network/api/asset/routes.go now calls
      replaceKDAInfo before returning the response.
  • Removed:
    • None.

Testing

  • All existing tests pass (make tests)
  • New tests added for new functionality
  • Manual testing performed:
    • Hit GET /asset/KLV and GET /asset/KFI against a local
      node and confirmed the logo URL and URIs match the expected
      values.
    • Hit GET /asset/<other-asset> and confirmed the response is
      unchanged.

Configuration Changes

None.

Breaking Changes

None. The override is response-only and applies to two
well-known asset IDs; the data shape is unchanged.

Related Issues

Fixes # KLC-2332
Related to #

Checklist

  • Code follows project style guidelines (make goimports)
  • Tests added/updated and passing
  • Documentation updated (README, CLAUDE.md, code comments)
  • Commit messages follow Conventional
    Commits
  • No unnecessary files included
  • Breaking changes documented above
  • Configuration changes documented above

Scope and Impact Assessment

This change is non-consensus and strictly API-layer. It patches HTTP responses for two well-known native asset IDs (KLV, KFI) by replacing Logo and URIs after the asset is fetched and before JSON serialization. It does not modify on-chain state, transaction processing, consensus, KVM, or peer networking. Node stability and data integrity are not impacted because the mutation is local to the request-scoped response object.

Changes

  • Added unexported constants klvAssetID and kfiAssetID in network/api/asset/routes.go.
  • Added replaceKDAInfo(asset *kapps.KDAData) helper in network/api/asset/routes.go which:
    • no-ops on nil asset,
    • checks asset.ID and only applies when ID == "KLV" or "KFI",
    • overwrites asset.Logo with a canonical URL and replaces asset.URIs with a fixed mapping.
  • Updated GetAsset handler in network/api/asset/routes.go to call replaceKDAInfo before returning the response.
  • Tests: expanded network/api/asset/routes_test.go with TestGetAsset (table-driven) to assert KLV/KFI overrides and that non-native assets pass through unchanged, plus TestGetAsset_InvalidFacade and route setup changes (startNodeServer signature updated and extra open routes in test config).

Implementation details relevant to safety and cross-cutting concerns

  • Scope and mutation: The helper mutates only the in-memory KDAData returned by the facade within the request handler; there is no persistence or global/shared state modification.
  • Guards: replaceKDAInfo guards against nil assets and only runs for the two explicit IDs.
  • Error handling: Existing error paths are unchanged — facade retrieval errors still return internal-server-error responses. The change does not introduce new error codes.
  • Concurrency: No concurrency primitives or shared runtime components are altered; mutation is confined to the request lifecycle.
  • Surface area: Only GET /asset/:id responses for KLV and KFI are affected.

Blockchain-critical impact

  • Consensus: none.
  • Transaction processing / KVM / state management: none.
  • Networking / peer sync: none.
  • Data integrity: on-chain data remains unchanged; this is a presentation-layer override.
  • Node stability: unaffected.

Testing

  • Existing test suite passes; tests were updated/added to validate:
    • Non-native assets remain unchanged,
    • KLV and KFI return the overridden Logo and URIs,
    • Facade error and invalid-facade context produce internal error responses.
  • Manual verification reported for GET /asset/KLV and GET /asset/KFI.

Configuration / Breaking changes

  • None; response-only override limited to two known IDs.

Related issue

  • Fixes KLC-2332

Copilot AI review requested due to automatic review settings April 29, 2026 18:36
@coderabbitai

coderabbitai Bot commented Apr 29, 2026

Copy link
Copy Markdown

Walkthrough

GetAsset in network/api/asset/routes.go now applies a post-fetch mutation via a new replaceKDAInfo helper: when asset.ID equals KLV or KFI it overwrites asset.Logo and replaces asset.URIs with fixed external links; nil guards and early returns preserve non-matching assets.

Changes

Asset response + tests

Layer / File(s) Summary
Constants / Helper
network/api/asset/routes.go
Introduces constants for KLV/KFI and the replaceKDAInfo helper that mutates *kapps.KDAData (sets Logo and replaces URIs).
Handler Invocation
network/api/asset/routes.go
GetAsset now calls replaceKDAInfo after fetching the asset; helper includes nil checks and early-return for non-matching IDs.
Test wiring / helper
network/api/asset/routes_test.go
startNodeServer updated to startNodeServer(t, handler) and requires successful router wrapper creation (require.NoError). Test route config adds /nft/:owner/*id and /pool/:id/.
Behavioral tests
network/api/asset/routes_test.go
Adds TestGetAsset (table-driven) asserting HTTP status and shared.GenericAPIResponse payload, verifying KLV/KFI logos and URIs are overridden and non-native assets are unchanged. Adds TestGetAsset_InvalidFacade asserting internal-error when facade is invalid.
Sanity test
network/api/asset/routes_test.go
Replaces prior empty-trail 404 test with TestAssetRoute_EmptyTrailReturns404 using the new server helper.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 5 | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title follows the required format [KLC-XXXX] type: description, with JIRA key KLC-2332, but is missing the required type prefix (feat, fix, refactor, etc.). Prepend the appropriate type prefix to the title, e.g., KLC-2332 fix: Override KLV and KFI asset metadata in GetAsset response.
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Error Handling ⚠️ Warning Unchecked error return in routes_test.go line 32: req, _ := http.NewRequest() silently discards error with blank identifier. Other test cases properly check errors with require.NoError(). Line 32: Change req, _ := http.NewRequest(...) to req, err := http.NewRequest(...); require.NoError(t, err) to match pattern used elsewhere in tests (lines 129, 181).
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Concurrency Safety ✅ Passed No concurrent primitives introduced. In-place asset mutations are safe—each HTTP request receives its own asset instance. No goroutines, channels, or mutexes involved. No data races.
State Consistency ✅ Passed PR modifies only API response objects (in-memory Logo/URIs fields serialized to HTTP response). No blockchain state, accounts, or storage modified. State consistency check is not applicable.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch KLC-2332-fix-return-of-klv-and-kfi-endpoints-on-node-calls

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown

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 updates the node REST API GET /asset/:id response to override stale on-chain metadata (logo + URIs) for the two native assets KLV and KFI, ensuring clients receive current canonical values without requiring a hard fork.

Changes:

  • Added KLVAssetID / KFIAssetID constants in the asset API routes.
  • Added replaceKDAInfo helper to override Logo and URIs for KLV and KFI.
  • Updated GetAsset to call replaceKDAInfo before serializing the response.

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

Comment thread network/api/asset/routes.go Outdated
Comment thread network/api/asset/routes.go

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@network/api/asset/routes.go`:
- Around line 113-140: Add regression tests for the replaceKDAInfo helper to
ensure the KLV/KFI override path never regresses: create unit tests that call
replaceKDAInfo with a kapps.KDAData instance having ID == KLVAssetID and another
with ID == KFIAssetID and assert their Logo and URIs are replaced to the
expected values (KLV -> klv-logo.png, KFI -> kfi-logo.png and the full URIs
map), and include a third test using a non-matching ID to assert the Logo and
URIs remain unchanged; locate replaceKDAInfo and the constants
KLVAssetID/KFIAssetID to build the inputs and assertions.
- Around line 21-22: The KLVAssetID and KFIAssetID constants are duplicated
here; remove the local declarations for KLVAssetID and KFIAssetID in routes.go
and instead use the canonical constants from the existing package that defines
them (import that package and replace local uses with package.KLVAssetID and
package.KFIAssetID), or if they truly belong to a shared domain, move the
canonical definitions into a shared package and update references (including
functions/handlers that reference KLVAssetID/KFIAssetID) to import and reference
the single source of truth.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 122f211d-a9f6-485f-9ba0-ac64b892929f

📥 Commits

Reviewing files that changed from the base of the PR and between 405d01b and 45f3d0b.

📒 Files selected for processing (1)
  • network/api/asset/routes.go
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Agent
  • GitHub Check: Analyze (go)
  • GitHub Check: setup-and-lint / setup-and-lint
🧰 Additional context used
📓 Path-based instructions (2)
**/*.go

📄 CodeRabbit inference engine (Custom checks)

**/*.go: Verify that any new or modified concurrent code (goroutines, channels, mutexes, sync primitives) is free of race conditions. Check for: proper lock/unlock pairing, no goroutine leaks, correct channel lifecycle management, and proper context cancellation propagation.
Verify that errors are not silently discarded. Check for: unchecked error returns, error wrapping with context, proper error propagation up the call chain, and no bare panic() calls outside of init() functions.

Files:

  • network/api/asset/routes.go
network/**

⚙️ CodeRabbit configuration file

network/**: Peer-to-peer networking layer. - Check for proper input validation on all received messages - Verify rate limiting and DoS protection mechanisms - Ensure connection handling is goroutine-safe - Look for potential message amplification attacks - Verify TLS/authentication on peer connections

Files:

  • network/api/asset/routes.go
🧠 Learnings (1)
📚 Learning: 2026-04-21T20:12:22.959Z
Learnt from: phcarneirobc
Repo: klever-io/klever-go PR: 38
File: indexer/eventsProcessor.go:188-211
Timestamp: 2026-04-21T20:12:22.959Z
Learning: In Go structs that are JSON-marshaled, if a field is a `bool` and has the `json:"...,omitempty"` tag, then leaving that field at its zero value (`false`) is functionally equivalent (in the resulting JSON) to explicitly setting `Foundation: false`. Reviewers should not flag struct literals that omit such `bool` fields as an inconsistency; they will serialize identically because `omitempty` suppresses `false` values.

Applied to files:

  • network/api/asset/routes.go
🔇 Additional comments (1)
network/api/asset/routes.go (1)

100-140: No change needed.

The GetAsset method allocates a fresh &kapps.KDAData{} struct on each call and deserializes into it before returning. There is no pointer caching or reuse across requests. Mutations in replaceKDAInfo affect only the caller's response object, not any shared state. The concern about branding leaking into later requests does not apply here.

			> Likely an incorrect or invalid review comment.

Comment thread network/api/asset/routes.go Outdated
Comment thread network/api/asset/routes.go

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@network/api/asset/routes_test.go`:
- Around line 175-176: The calls to wrapper.NewRouterWrapper are ignoring
returned errors (e.g., the call that assigns assetRoute and the other
occurrence), which can hide config problems; change both sites to capture the
error (e.g., assetRoute, err := wrapper.NewRouterWrapper(...)) and fail the test
immediately with a clear message and wrapped error (e.g., using t.Fatalf or
require.NoError) so route setup errors propagate instead of being discarded
before calling asset.Routes or other route setup functions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 95e1154d-6cf8-4e33-88fe-d9e3e19d4008

📥 Commits

Reviewing files that changed from the base of the PR and between 45f3d0b and 6e34e02.

📒 Files selected for processing (1)
  • network/api/asset/routes_test.go
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (go)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.go

📄 CodeRabbit inference engine (Custom checks)

**/*.go: Verify that any new or modified concurrent code (goroutines, channels, mutexes, sync primitives) is free of race conditions. Check for: proper lock/unlock pairing, no goroutine leaks, correct channel lifecycle management, and proper context cancellation propagation.
Verify that errors are not silently discarded. Check for: unchecked error returns, error wrapping with context, proper error propagation up the call chain, and no bare panic() calls outside of init() functions.

Files:

  • network/api/asset/routes_test.go
network/**

⚙️ CodeRabbit configuration file

network/**: Peer-to-peer networking layer. - Check for proper input validation on all received messages - Verify rate limiting and DoS protection mechanisms - Ensure connection handling is goroutine-safe - Look for potential message amplification attacks - Verify TLS/authentication on peer connections

Files:

  • network/api/asset/routes_test.go
**/*_test.go

⚙️ CodeRabbit configuration file

**/*_test.go: Test files. Review for: - Adequate coverage of edge cases and error paths - Proper use of test helpers and assertions - Race condition coverage (tests should use -race flag patterns) - No hardcoded sleep for synchronization (use channels or sync primitives) - Test isolation (no shared mutable state between tests)

Files:

  • network/api/asset/routes_test.go
🧠 Learnings (1)
📚 Learning: 2026-04-21T20:12:22.959Z
Learnt from: phcarneirobc
Repo: klever-io/klever-go PR: 38
File: indexer/eventsProcessor.go:188-211
Timestamp: 2026-04-21T20:12:22.959Z
Learning: In Go structs that are JSON-marshaled, if a field is a `bool` and has the `json:"...,omitempty"` tag, then leaving that field at its zero value (`false`) is functionally equivalent (in the resulting JSON) to explicitly setting `Foundation: false`. Reviewers should not flag struct literals that omit such `bool` fields as an inconsistency; they will serialize identically because `omitempty` suppresses `false` values.

Applied to files:

  • network/api/asset/routes_test.go
🔇 Additional comments (1)
network/api/asset/routes_test.go (1)

37-163: Good coverage for override and passthrough behavior.

This table-driven test exercises the key success and failure paths for GetAsset (non-native passthrough, KLV/KFI overrides, facade error) and validates response envelope fields.

Comment thread network/api/asset/routes_test.go Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
network/api/asset/routes.go (1)

21-23: 🛠️ Refactor suggestion | 🟠 Major

Use canonical KDA identifiers instead of local string IDs

Line 21-22 and Line 121-123 introduce a second source of truth for KLV/KFI IDs and rely on string(asset.ID) matching. Prefer kdautils.KLVIdentifier / kdautils.KFIIdentifier with bytes.Equal to avoid drift and keep ID handling consistent with the rest of the codebase.

Proposed refactor
 import (
+	"bytes"
 	"fmt"
 	"net/http"
 
 	"github.com/gin-gonic/gin"
 	kdafeespool "github.com/klever-io/klever-go/core/kapp/kdaFeesPool"
+	"github.com/klever-io/klever-go/core/process/kda/kdautils"
 	"github.com/klever-io/klever-go/kapps"
 	"github.com/klever-io/klever-go/network/api/errors"
 	"github.com/klever-io/klever-go/network/api/shared"
 	"github.com/klever-io/klever-go/network/api/wrapper"
 )
@@
-	klvAssetID = "KLV"
-	kfiAssetID = "KFI"
 )
@@
-	id := string(asset.ID)
-	if id != klvAssetID && id != kfiAssetID {
+	isKLV := bytes.Equal(asset.ID, kdautils.KLVIdentifier)
+	isKFI := bytes.Equal(asset.ID, kdautils.KFIIdentifier)
+	if !isKLV && !isKFI {
 		return
 	}
 
 	asset.Logo = "https://kleverscan.org/assets/klv-logo.png"
-	if id == kfiAssetID {
+	if isKFI {
 		asset.Logo = "https://kleverscan.org/assets/kfi-logo.png"
 	}

Also applies to: 121-129

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@network/api/asset/routes.go` around lines 21 - 23, Replace the local string
constants klvAssetID/kfiAssetID and any use of string(asset.ID) comparisons with
the canonical byte identifiers kdautils.KLVIdentifier and kdautils.KFIIdentifier
and compare using bytes.Equal; specifically, remove or stop relying on
klvAssetID/kfiAssetID, update places that do string(asset.ID) == klvAssetID / ==
kfiAssetID (e.g., the comparison logic around asset.ID) to use
bytes.Equal(asset.ID, kdautils.KLVIdentifier) and bytes.Equal(asset.ID,
kdautils.KFIIdentifier) so ID handling matches the rest of the codebase and
avoids drift.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@network/api/asset/routes_test.go`:
- Around line 129-130: The tests currently discard errors returned by
http.NewRequest (calls creating req at the GET /asset tests around the req
creation lines); change both occurrences to capture the error and fail the test
on error (e.g., err := http.NewRequest(...); if err != nil { t.Fatalf("failed to
create request: %v", err) }) or use require.NoError(t, err) if you prefer
testify — update the creation of req in the test function(s) that use tc.assetID
and the similar request at line ~180 to handle the error explicitly.

---

Duplicate comments:
In `@network/api/asset/routes.go`:
- Around line 21-23: Replace the local string constants klvAssetID/kfiAssetID
and any use of string(asset.ID) comparisons with the canonical byte identifiers
kdautils.KLVIdentifier and kdautils.KFIIdentifier and compare using bytes.Equal;
specifically, remove or stop relying on klvAssetID/kfiAssetID, update places
that do string(asset.ID) == klvAssetID / == kfiAssetID (e.g., the comparison
logic around asset.ID) to use bytes.Equal(asset.ID, kdautils.KLVIdentifier) and
bytes.Equal(asset.ID, kdautils.KFIIdentifier) so ID handling matches the rest of
the codebase and avoids drift.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 0bed3b72-21a9-477b-8df0-7977600d0b2b

📥 Commits

Reviewing files that changed from the base of the PR and between 6e34e02 and 96cee5e.

📒 Files selected for processing (2)
  • network/api/asset/routes.go
  • network/api/asset/routes_test.go
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: setup-and-lint / setup-and-lint
  • GitHub Check: Analyze (go)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.go

📄 CodeRabbit inference engine (Custom checks)

**/*.go: Verify that any new or modified concurrent code (goroutines, channels, mutexes, sync primitives) is free of race conditions. Check for: proper lock/unlock pairing, no goroutine leaks, correct channel lifecycle management, and proper context cancellation propagation.
Verify that errors are not silently discarded. Check for: unchecked error returns, error wrapping with context, proper error propagation up the call chain, and no bare panic() calls outside of init() functions.

Files:

  • network/api/asset/routes.go
  • network/api/asset/routes_test.go
network/**

⚙️ CodeRabbit configuration file

network/**: Peer-to-peer networking layer. - Check for proper input validation on all received messages - Verify rate limiting and DoS protection mechanisms - Ensure connection handling is goroutine-safe - Look for potential message amplification attacks - Verify TLS/authentication on peer connections

Files:

  • network/api/asset/routes.go
  • network/api/asset/routes_test.go
**/*_test.go

⚙️ CodeRabbit configuration file

**/*_test.go: Test files. Review for: - Adequate coverage of edge cases and error paths - Proper use of test helpers and assertions - Race condition coverage (tests should use -race flag patterns) - No hardcoded sleep for synchronization (use channels or sync primitives) - Test isolation (no shared mutable state between tests)

Files:

  • network/api/asset/routes_test.go
🧠 Learnings (1)
📚 Learning: 2026-04-21T20:12:22.959Z
Learnt from: phcarneirobc
Repo: klever-io/klever-go PR: 38
File: indexer/eventsProcessor.go:188-211
Timestamp: 2026-04-21T20:12:22.959Z
Learning: In Go structs that are JSON-marshaled, if a field is a `bool` and has the `json:"...,omitempty"` tag, then leaving that field at its zero value (`false`) is functionally equivalent (in the resulting JSON) to explicitly setting `Foundation: false`. Reviewers should not flag struct literals that omit such `bool` fields as an inconsistency; they will serialize identically because `omitempty` suppresses `false` values.

Applied to files:

  • network/api/asset/routes.go
  • network/api/asset/routes_test.go
🔇 Additional comments (1)
network/api/asset/routes_test.go (1)

38-164: Good regression coverage for KLV/KFI override behavior

This table-driven suite correctly pins the KLV/KFI rewrite path and the non-native pass-through path, including response payload validation for Logo and URIs.

Comment thread network/api/asset/routes_test.go Outdated
coderabbitai[bot]
coderabbitai Bot previously approved these changes May 5, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
network/api/asset/routes_test.go (1)

32-32: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Handle request-construction errors in this test path.

Line 32 discards the http.NewRequest error, which can mask setup failures and produce misleading assertions.

Suggested fix
-	req, _ := http.NewRequest("GET", "/asset", nil)
+	req, err := http.NewRequest("GET", "/asset", nil)
+	require.NoError(t, err)

As per coding guidelines, "**/*.go: Verify that errors are not silently discarded. Check for: unchecked error returns..."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@network/api/asset/routes_test.go` at line 32, The test currently ignores the
error returned by http.NewRequest (req, _ := http.NewRequest(...)); update the
test in routes_test.go to check the returned error from http.NewRequest and fail
the test on error (e.g., if err != nil { t.Fatalf("failed to create request:
%v", err) } or use your test helper like require.NoError(t, err)), ensuring the
request construction error is not silently discarded and the rest of the test
uses the validated req variable.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@network/api/asset/routes_test.go`:
- Around line 56-58: The tests share the staleURIs map between the KLV and KFI
table cases which breaks test isolation; update the test table to create a fresh
map instance for each case (e.g. construct staleURIs inside each test case entry
or in the per-case setup) instead of reusing the top-level staleURIs variable so
KLV and KFI get independent maps; this keeps behavior correct even if
replaceKDAInfo() changes from reassigning the URIs field to mutating it in place
and prevents cross-case flakiness.

---

Duplicate comments:
In `@network/api/asset/routes_test.go`:
- Line 32: The test currently ignores the error returned by http.NewRequest
(req, _ := http.NewRequest(...)); update the test in routes_test.go to check the
returned error from http.NewRequest and fail the test on error (e.g., if err !=
nil { t.Fatalf("failed to create request: %v", err) } or use your test helper
like require.NoError(t, err)), ensuring the request construction error is not
silently discarded and the rest of the test uses the validated req variable.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 8a6931ff-8453-42d2-8383-fa5ab419c7b4

📥 Commits

Reviewing files that changed from the base of the PR and between 96cee5e and b5f70e3.

📒 Files selected for processing (1)
  • network/api/asset/routes_test.go
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: setup-and-lint / setup-and-lint
  • GitHub Check: Analyze (go)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.go

📄 CodeRabbit inference engine (Custom checks)

**/*.go: Verify that any new or modified concurrent code (goroutines, channels, mutexes, sync primitives) is free of race conditions. Check for: proper lock/unlock pairing, no goroutine leaks, correct channel lifecycle management, and proper context cancellation propagation.
Verify that errors are not silently discarded. Check for: unchecked error returns, error wrapping with context, proper error propagation up the call chain, and no bare panic() calls outside of init() functions.

Files:

  • network/api/asset/routes_test.go
network/**

⚙️ CodeRabbit configuration file

network/**: Peer-to-peer networking layer. - Check for proper input validation on all received messages - Verify rate limiting and DoS protection mechanisms - Ensure connection handling is goroutine-safe - Look for potential message amplification attacks - Verify TLS/authentication on peer connections

Files:

  • network/api/asset/routes_test.go
**/*_test.go

⚙️ CodeRabbit configuration file

**/*_test.go: Test files. Review for: - Adequate coverage of edge cases and error paths - Proper use of test helpers and assertions - Race condition coverage (tests should use -race flag patterns) - No hardcoded sleep for synchronization (use channels or sync primitives) - Test isolation (no shared mutable state between tests)

Files:

  • network/api/asset/routes_test.go
🧠 Learnings (1)
📚 Learning: 2026-04-21T20:12:22.959Z
Learnt from: phcarneirobc
Repo: klever-io/klever-go PR: 38
File: indexer/eventsProcessor.go:188-211
Timestamp: 2026-04-21T20:12:22.959Z
Learning: In Go structs that are JSON-marshaled, if a field is a `bool` and has the `json:"...,omitempty"` tag, then leaving that field at its zero value (`false`) is functionally equivalent (in the resulting JSON) to explicitly setting `Foundation: false`. Reviewers should not flag struct literals that omit such `bool` fields as an inconsistency; they will serialize identically because `omitempty` suppresses `false` values.

Applied to files:

  • network/api/asset/routes_test.go
🔇 Additional comments (1)
network/api/asset/routes_test.go (1)

202-204: Good fail-fast setup for router wrapper initialization.

Using require.NoError here is the right pattern to surface route setup failures immediately.

Comment thread network/api/asset/routes_test.go
@fbsobreira

Copy link
Copy Markdown
Member

deferred, old finance domain have been redirected via NS

@fbsobreira fbsobreira closed this May 7, 2026
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.

3 participants