Skip to content

Add off-chain voting anchor tests - #3498

Merged
mkoura merged 2 commits into
masterfrom
artur/offchain-voting-anchor-tests
Aug 6, 2026
Merged

Add off-chain voting anchor tests#3498
mkoura merged 2 commits into
masterfrom
artur/offchain-voting-anchor-tests

Conversation

@ArturWieczorek

@ArturWieczorek ArturWieczorek commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

Conway tests verifying cardano-db-sync's off-chain voting anchor handling (db-sync PR #2005, issue #1995). When an anchor's hash matches, db-sync stores it regardless of whether it parses, recording the outcome in off_chain_vote_data.is_valid:

  • TRUE - valid JSON db-sync can decode (CIP-100 / CIP-108 / CIP-119)
  • FALSE - valid JSON it cannot decode against any CIP schema (warning records why)
  • NULL - not valid JSON (error object in json, raw bytes preserved)

Covered for both gov-action (info action) and DRep anchors.

Helper changes

  • get_action_data / check_action_data: optional voting_anchor_id to select the correct row when several anchors share the same content hash; check_action_data now asserts is_valid is TRUE.
  • GovActionProposalDBRow.param_proposal made nullable - it is NULL for info actions and only set for parameter-change actions. test_pparam_update still passes.

Anchor data files and URLs

Each vector lives in a committed file under cardano_node_tests/tests/data/, fetched by db-sync over HTTP from its public raw.githubusercontent.com URL. The URLs are kept as PUBLIC_ACTION_ANCHOR_* constants in common.py, following #3531 (no tinyurl). File names are short so the raw URL stays under the 128-byte on-chain anchor limit:

  • ga_anchor.json - conformant (already on master)
  • ga_anchor_nonconf.json - valid JSON, not CIP-decodable
  • ga_anchor_invalid.json - not valid JSON

The last two were added with long names in #3497 and are renamed here.

Verification

Verified end-to-end on a local dev cluster - 5 passed on db-sync 13.7.2.1 (rev db8cdf6, which includes PR #2005):

5 passed in 1573.88s (0:26:13)

Note on CI / merge order

The ga_anchor_nonconf.json / ga_anchor_invalid.json URLs point at master, so the four non-conformant / invalid tests only go green once those renamed files are on master (the same bootstrap this PR originally had with #3497). The conformant test passes already. Local verification used a byte-identical shortlink for the two pending files - hashes are computed from the committed files, so db-sync behaves identically once the URLs resolve.

@ArturWieczorek ArturWieczorek changed the title test(db-sync): add off-chain voting anchor tests Add off-chain voting anchor tests Jul 16, 2026
@ArturWieczorek
ArturWieczorek force-pushed the artur/offchain-voting-anchor-tests branch from 56ebbcb to 7f2eee1 Compare July 16, 2026 13:18
@ArturWieczorek

ArturWieczorek commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator Author

Local cluster tests: 💚

============================= test session starts ==============================
platform linux -- Python 3.13.9, pytest-9.0.3, pluggy-1.5.0
metadata: cardano-node: 11.0.1, cardano-cli: 11.0.0.0, TESTNET_VARIANT: local_fast,
  CLUSTERS_COUNT: 1, HAS_CC: True, HAS_DBSYNC: True, db-sync: 13.7.2.1
  (rev db8cdf668cda632e9a09c30e1159fcb9fb34e952), HAS_SMASH: True, network magic: 42
rootdir: /home/artur/Projects/cardano-node-tests
configfile: pyproject.toml
collected 5 items

test_offchain_voting_anchor.py::TestGovActionAnchor::test_valid_voting_anchor_json@long PASSED [ 20%]
test_offchain_voting_anchor.py::TestGovActionAnchor::test_valid_voting_anchor_json_not_conforming_to_cip_100@long PASSED [ 40%]
test_offchain_voting_anchor.py::TestGovActionAnchor::test_invalid_voting_anchor_json@long PASSED [ 60%]
test_offchain_voting_anchor.py::TestDrepAnchor::test_drep_anchor_json_not_conforming@long PASSED [ 80%]
test_offchain_voting_anchor.py::TestDrepAnchor::test_drep_invalid_anchor_json@long PASSED [100%]

======================== 5 passed in 1573.88s (0:26:13) ========================

Full log:
cardano-node-tests-pr-3498-logs.txt

@ArturWieczorek
ArturWieczorek marked this pull request as ready for review July 16, 2026 13:30
@mkoura
mkoura force-pushed the artur/offchain-voting-anchor-tests branch 3 times, most recently from 5121d90 to fa341ef Compare August 6, 2026 08:34
@mkoura
mkoura requested a lite review from Copilot August 6, 2026 08:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds new Conway-era end-to-end coverage for cardano-db-sync’s off-chain voting anchor ingestion, specifically validating how db-sync stores anchor payloads (including non-decodable and invalid JSON cases) and records parse outcomes via off_chain_vote_data.is_valid. It also extends db-sync helper utilities to reliably target the correct off_chain_vote_data row when multiple anchors share the same content hash.

Changes:

  • Add a new tests_conway/test_offchain_voting_anchor.py suite covering gov-action and DRep anchors for is_valid = TRUE/FALSE/NULL scenarios.
  • Extend db-sync helpers to (a) resolve a gov-action’s voting_anchor_id, (b) wait for the off-chain row to appear, and (c) make check_action_data select the correct row and assert is_valid=True.
  • Add/rename committed anchor-vector files and expose their raw GitHub URLs via new common.py constants; make GovActionProposalDBRow.param_proposal nullable.

Reviewed changes

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

Show a summary per file
File Description
cardano_node_tests/utils/dbsync_utils.py Adds db-sync-specific timeout error, voting-anchor-id resolution, and robust wait/selection logic for off-chain vote data; updates check_action_data to target correct rows.
cardano_node_tests/utils/dbsync_queries.py Makes GovActionProposalDBRow.param_proposal nullable to match info-action behavior.
cardano_node_tests/tests/tests_conway/test_offchain_voting_anchor.py New db-sync Conway tests for off-chain voting anchor storage/decoding outcomes across gov-actions and DReps.
cardano_node_tests/tests/tests_conway/test_info.py Updates check_action_data call to pass the action txid for voting-anchor-id resolution.
cardano_node_tests/tests/data/ga_anchor_nonconf.json Adds valid-JSON but non-decodable/non-conformant test vector.
cardano_node_tests/tests/data/ga_anchor_invalid.json Adds intentionally invalid JSON test vector.
cardano_node_tests/tests/common.py Adds new public raw GitHub URL constants for the new anchor vectors.
Suppressed comments (2)

cardano_node_tests/utils/dbsync_utils.py:1522

  • typing.cast should receive the type object (e.g. dict[str, tp.Any]), not a string literal; otherwise static type checking can’t validate the cast.
        gov_action_data=tp.cast("dict[str, tp.Any]", gov_action or {}),

cardano_node_tests/utils/dbsync_utils.py:1575

  • typing.cast expects a type object, not a quoted string. Using the actual class here keeps the cast useful for static analysis.
        return tp.cast(
            "dbsync_types.OffChainVoteDataRecord",
            retry_query(query_func=_query_func, timeout=timeout),
        )

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

Comment thread cardano_node_tests/utils/dbsync_utils.py
Comment thread cardano_node_tests/utils/dbsync_utils.py Outdated
Comment thread cardano_node_tests/tests/common.py
ArturWieczorek and others added 2 commits August 6, 2026 11:24
Verify db-sync off-chain voting anchor handling (PR #2005, issue
#1995): an anchor whose hash matches is stored regardless of whether
it parses, with off_chain_vote_data.is_valid set to TRUE (CIP
decodable), FALSE (valid JSON, not decodable) or NULL (not valid
JSON), for both gov-action and DRep anchors.

The test vector files use short names so their public raw-content
URLs stay under the 128-byte on-chain anchor limit; the URLs are
kept as PUBLIC_ACTION_ANCHOR_* constants in common.

Supporting helper changes:

- get_action_data / check_action_data: optional voting_anchor_id to
  pick the right row when several anchors share a content hash, and
  assert is_valid.
- GovActionProposalDBRow.param_proposal made nullable; it is NULL for
  info actions and only set for parameter-change actions.
Address multi-round review findings:

* Use VERSIONS.CONWAY_FIRST for the era check so the module is not
  skipped on protocol versions 9 and 10.
* Add the needs_dbsync marker so tests skip instead of failing with a
  raw db connection error when db-sync is not available.
* Promote the off-chain vote data wait helper to dbsync_utils, make
  voting_anchor_id required and report fetch errors, elapsed time and
  a data-presence diagnostic on timeout, so a db-sync regression, a
  failed download, a too short timeout and a wrong anchor id are all
  distinguishable.
* Require voting_anchor_id in get_action_data. The same content can
  back several anchors, so a hash-only lookup can silently validate a
  row fetched for a different anchor and mask a failure.
* Make check_action_data self-contained: it resolves the gov action's
  own voting_anchor_id from the proposal's tx when not provided and
  waits for the off-chain data row, so tests don't need any db-sync
  related logic of their own.
* Raise dedicated DbSyncTimeoutError from retry_query so low-level
  socket timeouts are not misattributed to db-sync waits.
* Check is_valid and the presence of the gov action data row in
  check_action_data.
* Cover the CIP-100 fallback on DRep anchors (is_valid=TRUE with empty
  off_chain_vote_drep_data).
* Register the DRep retirement finalizer before submitting the
  registration tx and skip retirement when the DRep is not registered,
  so a failed test cannot leak a registered DRep.
* Correct the module docstring claim about gov action hash validation
  and fix various docstring inaccuracies.
@mkoura
mkoura force-pushed the artur/offchain-voting-anchor-tests branch from fa341ef to 1cf5321 Compare August 6, 2026 09:24
@mkoura
mkoura merged commit 7d4533d into master Aug 6, 2026
3 checks passed
@mkoura
mkoura deleted the artur/offchain-voting-anchor-tests branch August 6, 2026 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants