b6d7b1a9ec
Extends x/guild with P3 (v0.7) Guild Charter + Chapter Federation runtime + Household one-tap exit + Confederation Voice delegation + D-087 PierCarriesVoice locked const + REQ-064 cooling consts. - x/guild/types: extend Guild (CommonBondHash, PublicProfile, ParentGuildID, IsChapter, SecessionTermsHash, GoodStandingLiens); add GuildPublicProfile, Lien, SecessionTerms, ConfederationVoice structs; add PierCarriesVoice=false (D-087), CoolingSecessionCoverActiveDays=21, CoolingSecessionNonCoverDays=14 consts; extend Params + GenesisState (Chapters slice + Chapter->ParentGuildID ref check). - x/guild/types/msg_guild.go: 5 Msg* (CreateGuild, CreateChapter, OneTapExitStand, DelegateConfederationVoice, AddLien) + MsgServer interface + Response types (Disclaimer surfaced per REQ-061). - x/guild/types/expected_keepers.go: StandKeeper + StashKeeper G-003 shims. - x/guild/keeper: NEW store-backed Keeper (guild/lien/delegation stores) + MsgServer handlers + simtest (8 cases). - x/guild/module.go: AppModule (D-054 simtest-grade). - x/stand/types: IsHousehold + IsConfederation helpers + ConfederationVoice type-level scaffold (REQ-057/REQ-058). Coverage: x/guild 85.7%, keeper 94.3%, types 97.1%. G-006/G-028 intact. go.mod/go.sum diff EMPTY. go vet clean. REQs: REQ-051, REQ-053, REQ-057, REQ-058, REQ-061 ---ci--- project: oy phase: 3 milestone: v0.7 status: execute ---/ci---
105 lines
3.2 KiB
Go
105 lines
3.2 KiB
Go
package guild_test
|
|
|
|
// module_test.go exercises the x/guild AppModule (D-054 simtest-grade).
|
|
// The AppModule wraps the Keeper + exposes the MsgServer; this test
|
|
// constructs an AppModule with nil shims + asserts Name, ConsensusVersion,
|
|
// MsgServer, InitGenesis, ExportGenesis. Coverage target: the module.go
|
|
// surface.
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"cosmossdk.io/log"
|
|
"cosmossdk.io/store"
|
|
storetypes "cosmossdk.io/store/types"
|
|
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
|
dbm "github.com/cosmos/cosmos-db"
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/oy/openyield/x/guild"
|
|
"github.com/oy/openyield/x/guild/types"
|
|
)
|
|
|
|
func newModuleTestContext(t *testing.T) (sdk.Context, guild.AppModule, codec.Codec) {
|
|
t.Helper()
|
|
db := dbm.NewMemDB()
|
|
cdc := newModuleTestCodec()
|
|
storeKey := storetypes.NewKVStoreKey(types.StoreKey)
|
|
cms := store.NewCommitMultiStore(db, log.NewNopLogger(), nil)
|
|
cms.MountStoreWithDB(storeKey, storetypes.StoreTypeDB, nil)
|
|
if err := cms.LoadLatestVersion(); err != nil {
|
|
t.Fatalf("load latest version: %v", err)
|
|
}
|
|
ctx := sdk.NewContext(cms, cmtproto.Header{}, false, log.NewNopLogger())
|
|
am := guild.NewAppModule(cdc, storeKey, nil, nil)
|
|
return ctx, am, cdc
|
|
}
|
|
|
|
func newModuleTestCodec() codec.Codec {
|
|
registry := codectypes.NewInterfaceRegistry()
|
|
return codec.NewProtoCodec(registry)
|
|
}
|
|
|
|
// TestAppModuleName asserts the module name.
|
|
func TestAppModuleName(t *testing.T) {
|
|
_, am, _ := newModuleTestContext(t)
|
|
if am.Name() != types.ModuleName {
|
|
t.Errorf("Name = %q, want %q", am.Name(), types.ModuleName)
|
|
}
|
|
}
|
|
|
|
// TestAppModuleConsensusVersion asserts ConsensusVersion == 1.
|
|
func TestAppModuleConsensusVersion(t *testing.T) {
|
|
_, am, _ := newModuleTestContext(t)
|
|
if am.ConsensusVersion() != guild.ConsensusVersion {
|
|
t.Errorf("ConsensusVersion = %d, want %d", am.ConsensusVersion(), guild.ConsensusVersion)
|
|
}
|
|
if guild.ConsensusVersion != 1 {
|
|
t.Errorf("ConsensusVersion const = %d, want 1", guild.ConsensusVersion)
|
|
}
|
|
}
|
|
|
|
// TestAppModuleMsgServer asserts MsgServer returns a non-nil MsgServer.
|
|
func TestAppModuleMsgServer(t *testing.T) {
|
|
_, am, _ := newModuleTestContext(t)
|
|
srv := am.MsgServer()
|
|
if srv == nil {
|
|
t.Fatal("MsgServer() returned nil")
|
|
}
|
|
}
|
|
|
|
// TestAppModuleInitExportGenesis asserts InitGenesis + ExportGenesis round-
|
|
// trip an empty genesis.
|
|
func TestAppModuleInitExportGenesis(t *testing.T) {
|
|
ctx, am, cdc := newModuleTestContext(t)
|
|
|
|
empty := types.DefaultGenesisState()
|
|
data := cdc.MustMarshalJSON(empty)
|
|
am.InitGenesis(ctx, cdc, data)
|
|
|
|
exported := am.ExportGenesis(ctx, cdc)
|
|
if len(exported) == 0 {
|
|
t.Fatal("ExportGenesis returned empty bytes")
|
|
}
|
|
var gs types.GenesisState
|
|
if err := json.Unmarshal(exported, &gs); err != nil {
|
|
t.Fatalf("ExportGenesis bytes not valid JSON: %v", err)
|
|
}
|
|
}
|
|
|
|
// TestAppModuleRegisterServicesNoPanic asserts RegisterServices does not
|
|
// panic with a nil configurator (simtest-grade — the method is a no-op stub
|
|
// for the hand-rolled MsgServer wiring).
|
|
func TestAppModuleRegisterServicesNoPanic(t *testing.T) {
|
|
_, am, _ := newModuleTestContext(t)
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
t.Errorf("RegisterServices panicked: %v", r)
|
|
}
|
|
}()
|
|
am.RegisterServices(nil)
|
|
}
|