Skip to content

test(x/gov): expand genesis InitGenesis/ExportGenesis coverage#26354

Open
isotauon wants to merge 7 commits intocosmos:mainfrom
isotauon:test/gov-genesis-coverage
Open

test(x/gov): expand genesis InitGenesis/ExportGenesis coverage#26354
isotauon wants to merge 7 commits intocosmos:mainfrom
isotauon:test/gov-genesis-coverage

Conversation

@isotauon
Copy link
Copy Markdown
Contributor

Description

Closes: #25618

Adds two tests to x/gov/keeper/genesis_test.go, addressing the follow-up @aljo242 left on PR #25616:

  • TestInitGenesis_PanicsWhenDistrCancelDestSetWithoutDistrKeeper — exercises the guard added in refactor!(gov): make distribution keeper optional #25616 (x/gov/keeper/genesis.go:22-24) that requires a non-nil distribution keeper whenever the distribution module address is configured as the proposal cancel destination. Uses require.PanicsWithValue to assert the exact panic message.

  • TestInitGenesis_RoundTripProposalsAndVotes — populates the genesis state with proposals in both StatusDepositPeriod and StatusVotingPeriod plus a vote, calls InitGenesis, then ExportGenesis, and verifies that the constitution, starting proposal id, both proposals (with statuses preserved) and the vote round-trip correctly. The pre-existing TestImportExportQueues_ErrorInconsistentState only round-tripped a default genesis, which left both branches of the proposal.Status switch and the votes-export path uncovered.

Helper change

To construct a separate keeper with a nil distribution keeper in the first test (the field is unexported and must be set via NewKeeper), setupGovKeeper now also returns the KVStoreService it built. All eight in-package callers across keeper_test.go, deposit_test.go, hooks_test.go, tally_test.go, and vote_test.go pass an extra blank identifier.

No production code is changed; this is test-only, so no CHANGELOG entry is added.

The proposal_messages event attribute was being built by prepending a
comma to each message type URL inside the loop, producing values like
",/cosmos.bank.v1beta1.MsgSend,/cosmos.staking.v1beta1.MsgDelegate"
instead of the intended comma-separated list. This broke downstream
consumers that split the attribute on commas.

Replace the manual accumulator with strings.Join over a []string of
type URLs, and add a regression test that asserts the emitted attribute
has no leading comma.

Closes: cosmos#26045
Add two tests for the gov keeper's genesis handling:

- TestInitGenesis_PanicsWhenDistrCancelDestSetWithoutDistrKeeper
  exercises the guard added in cosmos#25616 that requires a non-nil
  distribution keeper whenever the distribution module address is
  configured as the proposal cancel destination.

- TestInitGenesis_RoundTripProposalsAndVotes verifies that proposals
  in both deposit and voting period statuses, plus a vote, survive
  an InitGenesis -> ExportGenesis round-trip.

To support constructing a fresh keeper with a nil distribution keeper
in the first test, setupGovKeeper now also returns the KVStoreService
it built. All in-package callers pass an extra blank identifier.

Closes: cosmos#25618
@isotauon isotauon requested a review from a team as a code owner April 27, 2026 21:38
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 27, 2026

PR author is not in the allowed authors list.

@aljo242 aljo242 added the backport/v0.54.x Backport PR's to release/v0.54.x branch label May 4, 2026
@aljo242 aljo242 enabled auto-merge May 4, 2026 17:15
@codecov
Copy link
Copy Markdown

codecov Bot commented May 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 64.86%. Comparing base (3ca76ce) to head (360e135).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #26354      +/-   ##
==========================================
- Coverage   64.87%   64.86%   -0.02%     
==========================================
  Files         890      874      -16     
  Lines       58583    57601     -982     
==========================================
- Hits        38008    37365     -643     
+ Misses      20575    20236     -339     
Files with missing lines Coverage Δ
x/gov/keeper/proposal.go 83.09% <100.00%> (ø)

... and 18 files with indirect coverage changes

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/v0.54.x Backport PR's to release/v0.54.x branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test x/gov genesis function more thoroughly

2 participants