Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shifty11 committed Mar 20, 2024
1 parent e429838 commit 227bd41
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 44 deletions.
5 changes: 5 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,3 +487,8 @@ func BlockedAddresses() map[string]bool {
}
return result
}

// InterfaceRegistry returns an InterfaceRegistry
func (app *App) InterfaceRegistry() codectypes.InterfaceRegistry {
return app.interfaceRegistry
}
7 changes: 7 additions & 0 deletions app/kyve.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ func RegisterKyveModules(registry cdctypes.InterfaceRegistry) map[string]appmodu
teamTypes.ModuleName: teamModule.AppModule{},
fundersTypes.ModuleName: fundersModule.AppModule{},
}
for _, module := range modules {
if mod, ok := module.(interface {
RegisterInterfaces(registry cdctypes.InterfaceRegistry)
}); ok {
mod.RegisterInterfaces(registry)
}
}

return modules
}
4 changes: 2 additions & 2 deletions app/old/app_Old.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func init() {
// App extends an ABCI application, but with most of its parameters exported.
// They are exported for convenience in creating helper functions, as object
// capabilities aren't needed for testing.
type AppOld struct {
type App struct {
*baseapp.BaseApp
legacyAmino *codec.LegacyAmino
appCodec codec.Codec
Expand Down Expand Up @@ -312,7 +312,7 @@ func NewKYVEApp(
bundlesTypes.MemStoreKey, delegationTypes.MemStoreKey,
)

app := &AppOld{
app := &App{
BaseApp: bApp,
legacyAmino: legacyAmino,
appCodec: appCodec,
Expand Down
31 changes: 20 additions & 11 deletions app/old/test_helpers.go → app/test_helpers.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package old
package app

import (
"encoding/json"
"github.com/cosmos/cosmos-sdk/types/module"
"time"

"cosmossdk.io/math"
Expand All @@ -12,7 +13,6 @@ import (
cmtTypes "github.com/cometbft/cometbft/types"
dbm "github.com/cosmos/cosmos-db"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
codecTypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptoCodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
Expand Down Expand Up @@ -53,7 +53,7 @@ type EmptyAppOptions struct{}

func (ao EmptyAppOptions) Get(_ string) interface{} { return nil }

func DefaultGenesisWithValSet(codec codec.Codec) map[string]json.RawMessage {
func DefaultGenesisWithValSet(app *App) map[string]json.RawMessage {
bondingDenom := globalTypes.Denom

// Generate a new validator.
Expand Down Expand Up @@ -89,12 +89,11 @@ func DefaultGenesisWithValSet(codec codec.Codec) map[string]json.RawMessage {
}

// Default genesis state.
config := MakeEncodingConfig()
genesisState := ModuleBasics.DefaultGenesis(config.Marshaler)
genesisState := app.DefaultGenesis()

// Update x/auth state.
authGenesis := authTypes.NewGenesisState(authTypes.DefaultParams(), []authTypes.GenesisAccount{delegator})
genesisState[authTypes.ModuleName] = codec.MustMarshalJSON(authGenesis)
genesisState[authTypes.ModuleName] = app.AppCodec().MustMarshalJSON(authGenesis)

// Update x/bank state.
bondedCoins := sdk.NewCoins(sdk.NewCoin(bondingDenom, sdk.DefaultPowerReduction))
Expand All @@ -111,14 +110,14 @@ func DefaultGenesisWithValSet(codec codec.Codec) map[string]json.RawMessage {
Coins: teamCoins,
},
}, bondedCoins.Add(sdk.NewInt64Coin(globalTypes.Denom, int64(teamTypes.TEAM_ALLOCATION))), []bankTypes.Metadata{}, []bankTypes.SendEnabled{})
genesisState[bankTypes.ModuleName] = codec.MustMarshalJSON(bankGenesis)
genesisState[bankTypes.ModuleName] = app.AppCodec().MustMarshalJSON(bankGenesis)

// Update x/staking state.
stakingParams := stakingTypes.DefaultParams()
stakingParams.BondDenom = bondingDenom

stakingGenesis := stakingTypes.NewGenesisState(stakingParams, validators, delegations)
genesisState[stakingTypes.ModuleName] = codec.MustMarshalJSON(stakingGenesis)
genesisState[stakingTypes.ModuleName] = app.AppCodec().MustMarshalJSON(stakingGenesis)

// Return.
return genesisState
Expand All @@ -133,10 +132,19 @@ func Setup() *App {
setPrefixes("kyve")

// app := NewKYVEApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5, config, EmptyAppOptions{})
app := NewKYVEApp(log.NewNopLogger(), db, nil, true, EmptyAppOptions{}, baseapp.SetChainID("kyve-test"))
// init chain must be called to stop deliverState from being nil
app, err := New(log.NewNopLogger(), db, nil, true, EmptyAppOptions{}, baseapp.SetChainID("kyve-test"))
if err != nil {
panic(err)
}

// TODO: Do we need this?
kyveModules := RegisterKyveModules(app.InterfaceRegistry())
for name, mod := range kyveModules {
app.ModuleManager.Modules[name] = module.CoreAppModuleBasicAdaptor(name, mod)
//app.autoCliOpts.Modules[name] = mod
}

genesisState := DefaultGenesisWithValSet(app.AppCodec())
genesisState := DefaultGenesisWithValSet(app)
stateBytes, err := json.MarshalIndent(genesisState, "", " ")
if err != nil {
panic(err)
Expand Down Expand Up @@ -171,4 +179,5 @@ func setPrefixes(accountAddressPrefix string) {
config.SetBech32PrefixForAccount(accountAddressPrefix, accountPubKeyPrefix)
config.SetBech32PrefixForValidator(validatorAddressPrefix, validatorPubKeyPrefix)
config.SetBech32PrefixForConsensusNode(consNodeAddressPrefix, consNodePubKeyPrefix)
config.Seal()
}
3 changes: 2 additions & 1 deletion testutil/integration/checks.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package integration

import (
"cosmossdk.io/store"
"time"

"github.com/KYVENetwork/chain/x/funders"
Expand Down Expand Up @@ -578,7 +579,7 @@ func (suite *KeeperTestSuite) verifyFullStaker(fullStaker querytypes.FullStaker,
}
}

func (suite *KeeperTestSuite) deleteStore(store sdk.KVStore) {
func (suite *KeeperTestSuite) deleteStore(store store.KVStore) {
iterator := store.Iterator(nil, nil)
keys := make([][]byte, 0)
for ; iterator.Valid(); iterator.Next() {
Expand Down
27 changes: 13 additions & 14 deletions testutil/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (suite *KeeperTestSuite) SetupApp(startTime int64) {
ePriv := ed25519.GenPrivKeyFromSecret([]byte{1})
suite.consAddress = sdk.ConsAddress(ePriv.PubKey().Address())

suite.ctx = suite.app.BaseApp.NewContext(false, tmproto.Header{
suite.ctx = suite.app.BaseApp.NewContextLegacy(false, tmproto.Header{
Height: 1,
ChainID: "kyve-test",
Time: time.Unix(startTime, 0).UTC(),
Expand All @@ -223,25 +223,25 @@ func (suite *KeeperTestSuite) SetupApp(startTime int64) {
})
suite.registerQueryClients()

mintParams := suite.app.MintKeeper.GetParams(suite.ctx)
mintParams, _ := suite.app.MintKeeper.Params.Get(suite.ctx)
mintParams.MintDenom = suite.denom
_ = suite.app.MintKeeper.SetParams(suite.ctx, mintParams)
_ = suite.app.MintKeeper.Params.Set(suite.ctx, mintParams)

stakingParams := suite.app.StakingKeeper.GetParams(suite.ctx)
stakingParams, _ := suite.app.StakingKeeper.GetParams(suite.ctx)
stakingParams.BondDenom = suite.denom
_ = suite.app.StakingKeeper.SetParams(suite.ctx, stakingParams)

govParams := suite.app.GovKeeper.GetParams(suite.ctx)
govParams, _ := suite.app.GovKeeper.Params.Get(suite.ctx)
govParams.MinDeposit = sdk.NewCoins(sdk.NewInt64Coin(KYVE_DENOM, int64(100_000_000_000))) // set min deposit to 100 KYVE
_ = suite.app.GovKeeper.SetParams(suite.ctx, govParams)
_ = suite.app.GovKeeper.Params.Set(suite.ctx, govParams)

// Set Validator
valAddr := sdk.ValAddress(suite.address.Bytes())
validator, _ := stakingtypes.NewValidator(valAddr, ePriv.PubKey(), stakingtypes.Description{})
validator, _ := stakingtypes.NewValidator(valAddr.String(), ePriv.PubKey(), stakingtypes.Description{})
validator = stakingkeeper.TestingUpdateValidator(suite.app.StakingKeeper, suite.ctx, validator, true)
//_ = suite.app.StakingKeeper.AfterValidatorCreated(suite.ctx, validator.GetOperator())
_ = suite.app.StakingKeeper.SetValidatorByConsAddr(suite.ctx, validator)
validators := suite.app.StakingKeeper.GetValidators(suite.ctx, 1)
validators, _ := suite.app.StakingKeeper.GetValidators(suite.ctx, 1)
suite.validator = validators[0]
}

Expand All @@ -255,14 +255,13 @@ func (suite *KeeperTestSuite) CommitAfterSeconds(seconds uint64) {

func (suite *KeeperTestSuite) CommitAfter(t time.Duration) {
header := suite.ctx.BlockHeader()
suite.app.EndBlock(abci.RequestEndBlock{Height: header.Height})
_ = suite.app.Commit()

header.Height += 1
header.Time = header.Time.Add(t)
suite.app.BeginBlock(abci.RequestBeginBlock{Header: header})

suite.ctx = suite.app.BaseApp.NewContext(false, header)
// TODO: check if this does still the same as before
_, _ = suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: header.Height})
_, _ = suite.app.Commit()

suite.ctx = suite.app.BaseApp.NewContextLegacy(false, header)

suite.registerQueryClients()
}
Expand Down
33 changes: 17 additions & 16 deletions x/bundles/keeper/msg_server_update_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,17 @@ var _ = Describe("msg_server_update_params.go", Ordered, func() {

gov := s.App().GovKeeper.GetGovernanceAccount(s.Ctx()).GetAddress().String()

minDeposit := s.App().GovKeeper.GetParams(s.Ctx()).MinDeposit
votingPeriod := s.App().GovKeeper.GetParams(s.Ctx()).VotingPeriod
params, _ := s.App().GovKeeper.Params.Get(s.Ctx())
minDeposit := params.MinDeposit
votingPeriod := params.VotingPeriod

delegations := s.App().StakingKeeper.GetAllDelegations(s.Ctx())
delegations, _ := s.App().StakingKeeper.GetAllDelegations(s.Ctx())
voter := sdk.MustAccAddressFromBech32(delegations[0].DelegatorAddress)

BeforeEach(func() {
s = i.NewCleanChain()

delegations := s.App().StakingKeeper.GetAllDelegations(s.Ctx())
delegations, _ := s.App().StakingKeeper.GetAllDelegations(s.Ctx())
voter = sdk.MustAccAddressFromBech32(delegations[0].DelegatorAddress)
})

Expand Down Expand Up @@ -93,7 +94,7 @@ var _ = Describe("msg_server_update_params.go", Ordered, func() {
}

proposal, _ := govV1Types.NewMsgSubmitProposal(
[]sdk.Msg{msg}, minDeposit, i.DUMMY[0], "", "title", "summary",
[]sdk.Msg{msg}, minDeposit, i.DUMMY[0], "", "title", "summary", false,
)

// ACT
Expand All @@ -118,7 +119,7 @@ var _ = Describe("msg_server_update_params.go", Ordered, func() {
}

proposal, _ := govV1Types.NewMsgSubmitProposal(
[]sdk.Msg{msg}, minDeposit, i.DUMMY[0], "", "title", "summary",
[]sdk.Msg{msg}, minDeposit, i.DUMMY[0], "", "title", "summary", false,
)

vote := govV1Types.NewMsgVote(
Expand Down Expand Up @@ -154,7 +155,7 @@ var _ = Describe("msg_server_update_params.go", Ordered, func() {
}

proposal, _ := govV1Types.NewMsgSubmitProposal(
[]sdk.Msg{msg}, minDeposit, i.DUMMY[0], "", "title", "summary",
[]sdk.Msg{msg}, minDeposit, i.DUMMY[0], "", "title", "summary", false,
)

vote := govV1Types.NewMsgVote(
Expand Down Expand Up @@ -192,7 +193,7 @@ var _ = Describe("msg_server_update_params.go", Ordered, func() {
}

proposal, _ := govV1Types.NewMsgSubmitProposal(
[]sdk.Msg{msg}, minDeposit, i.DUMMY[0], "", "title", "summary",
[]sdk.Msg{msg}, minDeposit, i.DUMMY[0], "", "title", "summary", false,
)

// ACT
Expand Down Expand Up @@ -224,7 +225,7 @@ var _ = Describe("msg_server_update_params.go", Ordered, func() {
}

proposal, _ := govV1Types.NewMsgSubmitProposal(
[]sdk.Msg{msg}, minDeposit, i.DUMMY[0], "", "title", "summary",
[]sdk.Msg{msg}, minDeposit, i.DUMMY[0], "", "title", "summary", false,
)

vote := govV1Types.NewMsgVote(
Expand Down Expand Up @@ -262,7 +263,7 @@ var _ = Describe("msg_server_update_params.go", Ordered, func() {
}

proposal, _ := govV1Types.NewMsgSubmitProposal(
[]sdk.Msg{msg}, minDeposit, i.DUMMY[0], "", "title", "summary",
[]sdk.Msg{msg}, minDeposit, i.DUMMY[0], "", "title", "summary", false,
)

// ACT
Expand Down Expand Up @@ -294,7 +295,7 @@ var _ = Describe("msg_server_update_params.go", Ordered, func() {
}

proposal, _ := govV1Types.NewMsgSubmitProposal(
[]sdk.Msg{msg}, minDeposit, i.DUMMY[0], "", "title", "summary",
[]sdk.Msg{msg}, minDeposit, i.DUMMY[0], "", "title", "summary", false,
)

vote := govV1Types.NewMsgVote(
Expand Down Expand Up @@ -332,7 +333,7 @@ var _ = Describe("msg_server_update_params.go", Ordered, func() {
}

proposal, _ := govV1Types.NewMsgSubmitProposal(
[]sdk.Msg{msg}, minDeposit, i.DUMMY[0], "", "title", "summary",
[]sdk.Msg{msg}, minDeposit, i.DUMMY[0], "", "title", "summary", false,
)

// ACT
Expand Down Expand Up @@ -364,7 +365,7 @@ var _ = Describe("msg_server_update_params.go", Ordered, func() {
}

proposal, _ := govV1Types.NewMsgSubmitProposal(
[]sdk.Msg{msg}, minDeposit, i.DUMMY[0], "", "title", "summary",
[]sdk.Msg{msg}, minDeposit, i.DUMMY[0], "", "title", "summary", false,
)

vote := govV1Types.NewMsgVote(
Expand Down Expand Up @@ -402,7 +403,7 @@ var _ = Describe("msg_server_update_params.go", Ordered, func() {
}

proposal, _ := govV1Types.NewMsgSubmitProposal(
[]sdk.Msg{msg}, minDeposit, i.DUMMY[0], "", "title", "summary",
[]sdk.Msg{msg}, minDeposit, i.DUMMY[0], "", "title", "summary", false,
)

// ACT
Expand Down Expand Up @@ -434,7 +435,7 @@ var _ = Describe("msg_server_update_params.go", Ordered, func() {
}

proposal, _ := govV1Types.NewMsgSubmitProposal(
[]sdk.Msg{msg}, minDeposit, i.DUMMY[0], "", "title", "summary",
[]sdk.Msg{msg}, minDeposit, i.DUMMY[0], "", "title", "summary", false,
)

vote := govV1Types.NewMsgVote(
Expand Down Expand Up @@ -472,7 +473,7 @@ var _ = Describe("msg_server_update_params.go", Ordered, func() {
}

proposal, _ := govV1Types.NewMsgSubmitProposal(
[]sdk.Msg{msg}, minDeposit, i.DUMMY[0], "", "title", "summary",
[]sdk.Msg{msg}, minDeposit, i.DUMMY[0], "", "title", "summary", false,
)

// ACT
Expand Down

0 comments on commit 227bd41

Please sign in to comment.