clawchain/x/governance/keeper/genesis_coverage_test.go
caelum0x 9e2746707a feat(governance): complete governance module with veto votes, cancel, queries, and execution log
- Task 1.1/1.2: Add no_with_veto vote option with 33.4% veto threshold
  - New VoteOptionNoWithVeto constant and DefaultVetoThresholdBps (3340)
  - VetoVotes field on Proposal struct (proto field 15)
  - CastVote handles no_with_veto; TallyProposal rejects if veto > 33.4%

- Task 1.3: Add MsgCancelProposal
  - New ErrUnauthorizedCancel (1411) and ErrProposalNotCancellable (1412)
  - ProposalStatusCancelled constant
  - CancelProposal keeper method: checks proposer, voting status, refunds deposit

- Task 1.4: Add QueryTallyResult and QueryVoterVotes
  - QueryTallyResult returns counts, percentages (bps), pass/veto status
  - QueryVoterVotes walks Votes collection filtered by voter address

- Task 1.5: ParamExecutor coverage for marketplace, reputation, messaging, modelregistry
  - All 4 modules tested via mock executor registration + ExecuteProposal

- Task 1.6: Execution log fields
  - ExecutionHeight (proto field 16) and ExecutionError (proto field 17) on Proposal
  - ExecuteProposal sets these on both success and failure paths

All 24 tests pass (5 existing + 19 new), go build ./... clean.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-16 14:24:34 +03:00

55 lines
1.4 KiB
Go

package keeper_test
import (
"testing"
"cosmossdk.io/math"
"github.com/stretchr/testify/require"
"clawchain/x/governance/types"
)
func TestGenesisInitAndExport_WithProposalAndVote(t *testing.T) {
f := initFixture(t)
gen := types.GenesisState{
Proposals: []types.Proposal{
{
ProposalId: 7,
Title: "Tune Messaging Limit",
Description: "Raise max message size",
Module: "messaging",
ParamKey: "max_message_size",
ProposedValue: "8192",
Proposer: "cosmos1qypqxpq9qcrsszg2pvxq6rs0zqg3yyc5lzv7xu",
Deposit: "10000000uclaw",
Status: types.ProposalStatusVoting,
VotingEndBlock: 100,
YesVotes: math.ZeroInt(),
NoVotes: math.ZeroInt(),
AbstainVotes: math.ZeroInt(),
CreatedAt: 1,
},
},
Votes: []types.Vote{
{
ProposalId: 7,
Voter: "cosmos1s3nh6tafl4amaxkke9kdejhp09lk93g9ev39r4",
Option: types.VoteOptionYes,
Weight: math.LegacyMustNewDecFromStr("1.0"),
},
},
ProposalCount: 8,
}
require.NoError(t, f.keeper.InitGenesis(f.ctx, gen))
exported, err := f.keeper.ExportGenesis(f.ctx)
require.NoError(t, err)
require.NotNil(t, exported)
require.Len(t, exported.Proposals, 1)
require.Len(t, exported.Votes, 1)
require.EqualValues(t, 7, exported.Proposals[0].ProposalId)
require.Equal(t, types.VoteOptionYes, exported.Votes[0].Option)
}