Skip to content

Commit

Permalink
fix: use mainline ibc-go/v7 in integration tests
Browse files Browse the repository at this point in the history
Use  cosmos/ibc-go/v7 in integration tests, refactor app.go used in integration tests
  • Loading branch information
MSalopek committed May 5, 2023
1 parent d8a4462 commit d09d4d9
Show file tree
Hide file tree
Showing 16 changed files with 192 additions and 43 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ install: go.sum
export CGO_CPPFLAGS="-D_FORTIFY_SOURCE=2"
export CGO_LDFLAGS="-Wl,-z,relro,-z,now -fstack-protector"
go install $(BUILD_FLAGS) ./cmd/interchain-security-pd
go install $(BUILD_FLAGS) ./cmd/interchain-security-cd
go install $(BUILD_FLAGS) ./cmd/interchain-security-cdd
# go install $(BUILD_FLAGS) ./cmd/interchain-security-cd
# go install $(BUILD_FLAGS) ./cmd/interchain-security-cdd

# run all tests: unit, integration, diff, and E2E
test:
Expand Down
19 changes: 19 additions & 0 deletions app/consumer-democracy/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,25 @@ func New(
),
)

// pre-initialize ConsumerKeeper to satsfy ibckeeper.NewKeeper
// which would panic on nil or zero keeper
// ConsumerKeeper implements StakingKeeper but all function calls result in no-ops so this is safe
// communication over IBC is not affected by these changes
app.ConsumerKeeper = consumerkeeper.NewNonZeroKeeper(
appCodec,
keys[consumertypes.StoreKey],
app.GetSubspace(consumertypes.ModuleName),
)

app.IBCKeeper = ibckeeper.NewKeeper(
appCodec,
keys[ibchost.StoreKey],
app.GetSubspace(ibchost.ModuleName),
app.ConsumerKeeper,
app.UpgradeKeeper,
scopedIBCKeeper,
)

app.IBCKeeper = ibckeeper.NewKeeper(
appCodec,
keys[ibchost.StoreKey],
Expand Down
52 changes: 45 additions & 7 deletions app/consumer/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
simappparams "cosmossdk.io/simapp/params"

dbm "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
Expand All @@ -24,6 +23,7 @@ import (
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/runtime"
runtimeservices "github.com/cosmos/cosmos-sdk/runtime/services"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/server/api"
Expand Down Expand Up @@ -139,6 +139,7 @@ var (
)

var (
_ runtime.AppI = (*App)(nil)
_ servertypes.Application = (*App)(nil)
_ ibctesting.TestingApp = (*App)(nil)
)
Expand All @@ -151,6 +152,7 @@ type App struct { // nolint: golint
legacyAmino *codec.LegacyAmino
appCodec codec.Codec
interfaceRegistry types.InterfaceRegistry
txConfig client.TxConfig

// keys to access the substores
keys map[string]*storetypes.KVStoreKey
Expand Down Expand Up @@ -238,6 +240,7 @@ func New(
keys: keys,
tkeys: tkeys,
memKeys: memKeys,
txConfig: encodingConfig.TxConfig,
}

app.ParamsKeeper = initParamsKeeper(
Expand Down Expand Up @@ -333,16 +336,27 @@ func New(
app.BaseApp,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

// pre-initialize ConsumerKeeper to satsfy ibckeeper.NewKeeper
// which would panic on nil or zero keeper
// ConsumerKeeper implements StakingKeeper but all function calls result in no-ops so this is safe
// communication over IBC is not affected by these changes
app.ConsumerKeeper = ibcconsumerkeeper.NewNonZeroKeeper(
appCodec,
keys[ibcconsumertypes.StoreKey],
app.GetSubspace(ibcconsumertypes.ModuleName),
)

app.IBCKeeper = ibckeeper.NewKeeper(
appCodec,
keys[ibchost.StoreKey],
app.GetSubspace(ibchost.ModuleName),
&app.ConsumerKeeper,
app.ConsumerKeeper,
app.UpgradeKeeper,
scopedIBCKeeper,
)

// Create CCV consumer and modules
// initialize the actual consumer keeper
app.ConsumerKeeper = ibcconsumerkeeper.NewKeeper(
appCodec,
keys[ibcconsumertypes.StoreKey],
Expand Down Expand Up @@ -597,11 +611,17 @@ func (app *App) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.Respo
func (app *App) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
var genesisState GenesisState
if err := tmjson.Unmarshal(req.AppStateBytes, &genesisState); err != nil {
// fmt.Println("CONSUGEN:// ERRD OND tmjsonUnmarshal genesis", err)
panic(err)
}

app.UpgradeKeeper.SetModuleVersionMap(ctx, app.MM.GetVersionMap())
return app.MM.InitGenesis(ctx, app.appCodec, genesisState)
// // fmt.Println(string(req.AppStateBytes))
// fmt.Println("CONSUGEN:// EXEC INIT GENESIS ###")
// fmt.Println("## CALLING INIT GENESIS from app.go ###")
val := app.MM.InitGenesis(ctx, app.appCodec, genesisState)
// fmt.Println("CONSUGEN:// RAN GENESIS WITH NO ISSUES ###")
return val
}

// LoadHeight loads a particular height
Expand Down Expand Up @@ -725,7 +745,7 @@ func (app *App) GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper {

// GetTxConfig implements the TestingApp interface.
func (app *App) GetTxConfig() client.TxConfig {
return MakeTestEncodingConfig().TxConfig
return app.txConfig
}

// RegisterAPIRoutes registers all application module routes with the provided
Expand Down Expand Up @@ -800,6 +820,24 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
// should be used only in tests or when creating a new app instance (NewApp*()).
// App user shouldn't create new codecs - use the app.AppCodec instead.
// [DEPRECATED]
// func MakeTestEncodingConfig() appparams.EncodingConfig {
// encodingConfig := appparams.MakeTestEncodingConfig()
// std.RegisterLegacyAminoCodec(encodingConfig.Amino)
// std.RegisterInterfaces(encodingConfig.InterfaceRegistry)
// ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino)
// ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry)
// return encodingConfig
// }

// func makeEncodingConfig() simappparams.EncodingConfig {
// encodingConfig := simappparams.MakeTestEncodingConfig()
// std.RegisterLegacyAminoCodec(encodingConfig.Amino)
// std.RegisterInterfaces(encodingConfig.InterfaceRegistry)
// ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino)
// ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry)
// return encodingConfig
// }

func MakeTestEncodingConfig() appparams.EncodingConfig {
encodingConfig := appparams.MakeTestEncodingConfig()
std.RegisterLegacyAminoCodec(encodingConfig.Amino)
Expand All @@ -809,8 +847,8 @@ func MakeTestEncodingConfig() appparams.EncodingConfig {
return encodingConfig
}

func makeEncodingConfig() simappparams.EncodingConfig {
encodingConfig := simappparams.MakeTestEncodingConfig()
func makeEncodingConfig() appparams.EncodingConfig {
encodingConfig := appparams.MakeTestEncodingConfig()
std.RegisterLegacyAminoCodec(encodingConfig.Amino)
std.RegisterInterfaces(encodingConfig.InterfaceRegistry)
ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino)
Expand Down
5 changes: 4 additions & 1 deletion app/provider/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,10 @@ func (app *App) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.Res

app.UpgradeKeeper.SetModuleVersionMap(ctx, app.MM.GetVersionMap())

return app.MM.InitGenesis(ctx, app.appCodec, genesisState)
vals := app.MM.InitGenesis(ctx, app.appCodec, genesisState)
// fmt.Println("PPPPL//:: REQ ABCI VALSET", req.Validators)
// fmt.Println("PPPPL//:: PROVIDER VALSET UPDATES ###", len(vals.Validators), "\n\n", vals.Validators)
return vals
}

// LoadHeight loads a particular height
Expand Down
15 changes: 7 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
cosmossdk.io/simapp v0.0.0-20230224204036-a6adb0821462
github.com/cometbft/cometbft v0.37.1
github.com/cometbft/cometbft-db v0.8.0
github.com/cosmos/cosmos-sdk v0.47.1
github.com/cosmos/cosmos-sdk v0.47.2
github.com/cosmos/gogoproto v1.4.8
github.com/cosmos/ibc-go/v7 v7.0.0
github.com/cosmos/ics23/go v0.10.0
Expand Down Expand Up @@ -101,7 +101,7 @@ require (
github.com/gtank/merlin v0.1.1 // indirect
github.com/gtank/ristretto255 v0.1.2 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-getter v1.7.0 // indirect
github.com/hashicorp/go-getter v1.7.1 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/go-uuid v1.0.2 // indirect
Expand Down Expand Up @@ -176,10 +176,9 @@ require (
github.com/linxGnu/grocksdb v1.7.16 // indirect
)

replace (
// github.com/cosmos/cosmos-sdk => github.com/notional-labs/cosmos-sdk v0.47.2-0.20230424022356-49c2e39f3fe6
github.com/cosmos/ibc-go/v7 => github.com/notional-labs/ibc-go/v7 v7.0.0-rc0.0.20230417042817-8072b1e9aabc
// github.com/cosmos/cosmos-sdk => ../cosmos-sdk
// github.com/cosmos/cosmos-sdk => github.com/notional-labs/cosmos-sdk v0.47.2-0.20230424022356-49c2e39f3fe6
// github.com/cosmos/ibc-go/v7 => github.com/notional-labs/ibc-go/v7 v7.0.0-rc0.0.20230417042817-8072b1e9aabc

// following versions might cause unexpected behavior
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
)
// following versions might cause unexpected behavior
replace github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,8 @@ github.com/cosmos/btcutil v1.0.5 h1:t+ZFcX77LpKtDBhjucvnOH8C2l2ioGsBNEQ3jef8xFk=
github.com/cosmos/btcutil v1.0.5/go.mod h1:IyB7iuqZMJlthe2tkIFL33xPyzbFYP0XVdS8P5lUPis=
github.com/cosmos/cosmos-proto v1.0.0-beta.2 h1:X3OKvWgK9Gsejo0F1qs5l8Qn6xJV/AzgIWR2wZ8Nua8=
github.com/cosmos/cosmos-proto v1.0.0-beta.2/go.mod h1:+XRCLJ14pr5HFEHIUcn51IKXD1Fy3rkEQqt4WqmN4V0=
github.com/cosmos/cosmos-sdk v0.47.1 h1:HnaCYtaAMWZp1SdlwwE1mPJ8kFlZ/TuEJ/ciNXH6Uno=
github.com/cosmos/cosmos-sdk v0.47.1/go.mod h1:14tO5KQaTrl2q3OxBnDRfue7TRN9zkXS0cLutrSqkOo=
github.com/cosmos/cosmos-sdk v0.47.2 h1:9rSriCoiJD+4F+tEDobyM8V7HF5BtY5Ef4VYNig96s0=
github.com/cosmos/cosmos-sdk v0.47.2/go.mod h1:zYzgI8w8hhotXTSoGbbSOAKfpJTx4wOy4XgbaKhtRtc=
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y=
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
Expand All @@ -391,6 +391,8 @@ github.com/cosmos/gogoproto v1.4.8 h1:BrHKc6WFZt8+jRV71vKSQE+JrfF+JAnzrKo2VP7wIZ
github.com/cosmos/gogoproto v1.4.8/go.mod h1:hnb0DIEWTv+wdNzNcqus5xCQXq5+CXauq1FJuurRfVY=
github.com/cosmos/iavl v0.20.0 h1:fTVznVlepH0KK8NyKq8w+U7c2L6jofa27aFX6YGlm38=
github.com/cosmos/iavl v0.20.0/go.mod h1:WO7FyvaZJoH65+HFOsDir7xU9FWk2w9cHXNW1XHcl7A=
github.com/cosmos/ibc-go/v7 v7.0.0 h1:j4kyywlG0hhDmT9FmSaR5iCIka7Pz7kJTxGWY1nlV9Q=
github.com/cosmos/ibc-go/v7 v7.0.0/go.mod h1:BFh8nKWjr5zeR2OZfhkzdgDzj1+KjRn3aJLpwapStj8=
github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM=
github.com/cosmos/ics23/go v0.10.0/go.mod h1:ZfJSmng/TBNTBkFemHHHj5YY7VAU/MBU980F4VU1NG0=
github.com/cosmos/ledger-cosmos-go v0.12.2 h1:/XYaBlE2BJxtvpkHiBm97gFGSGmYGKunKyF3nNqAXZA=
Expand Down Expand Up @@ -703,8 +705,8 @@ github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtng
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
github.com/hashicorp/go-getter v1.7.0 h1:bzrYP+qu/gMrL1au7/aDvkoOVGUJpeKBgbqRHACAFDY=
github.com/hashicorp/go-getter v1.7.0/go.mod h1:W7TalhMmbPmsSMdNjD0ZskARur/9GJ17cfHTRtXV744=
github.com/hashicorp/go-getter v1.7.1 h1:SWiSWN/42qdpR0MdhaOc/bLR48PLuP1ZQtYLRlM69uY=
github.com/hashicorp/go-getter v1.7.1/go.mod h1:W7TalhMmbPmsSMdNjD0ZskARur/9GJ17cfHTRtXV744=
github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-immutable-radix v1.3.1 h1:DKHmCUm2hRBK510BaiZlwvpD40f8bJFeZnpfm2KLowc=
github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
Expand Down Expand Up @@ -920,8 +922,6 @@ github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxzi
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
github.com/neilotoole/errgroup v0.1.6/go.mod h1:Q2nLGf+594h0CLBs/Mbg6qOr7GtqDK7C2S41udRnToE=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/notional-labs/ibc-go/v7 v7.0.0-rc0.0.20230417042817-8072b1e9aabc h1:2qZf+B37YnoHcmXnB87VfcrVC50I+LZWeWu4ZEAddsc=
github.com/notional-labs/ibc-go/v7 v7.0.0-rc0.0.20230417042817-8072b1e9aabc/go.mod h1:BFh8nKWjr5zeR2OZfhkzdgDzj1+KjRn3aJLpwapStj8=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs=
Expand Down
44 changes: 40 additions & 4 deletions legacy_ibc_testing/testing/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/cosmos/ibc-go/v7/modules/core/keeper"

"github.com/cosmos/interchain-security/legacy_ibc_testing/simapp"
consumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types"
)

/*
Expand Down Expand Up @@ -65,7 +66,13 @@ type TestingApp interface {
func SetupWithGenesisValSet(t *testing.T, appIniter AppIniter, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, chainID string, powerReduction math.Int, balances ...banktypes.Balance) TestingApp {
t.Helper()
app, genesisState := appIniter()

// for k, _ := range genesisState {
// fmt.Println(k, "genesis")
// if k == "ccvconsumer" {
// fmt.Println(string(genesisState[k]))
// }
// }
// fmt.Println("AA::// EXECUTED APP INITER ###")
baseapp.SetChainID(chainID)(app.GetBaseApp())

// set genesis accounts
Expand All @@ -77,6 +84,7 @@ func SetupWithGenesisValSet(t *testing.T, appIniter AppIniter, valSet *tmtypes.V

bondAmt := sdk.TokensFromConsensusPower(1, powerReduction)

initValPowers := []abci.ValidatorUpdate{}
for _, val := range valSet.Validators {
pk, err := cryptocodec.FromTmPubKeyInterface(val.PubKey)
require.NoError(t, err)
Expand All @@ -98,26 +106,36 @@ func SetupWithGenesisValSet(t *testing.T, appIniter AppIniter, valSet *tmtypes.V

validators = append(validators, validator)
delegations = append(delegations, stakingtypes.NewDelegation(genAccs[0].GetAddress(), val.Address.Bytes(), sdk.OneDec()))

pub, _ := val.ToProto()
initValPowers = append(initValPowers, abci.ValidatorUpdate{
Power: val.VotingPower,
PubKey: pub.PubKey,
})
}
// fmt.Println("DONE VALS", len(validators), len(delegations))

// set validators and delegations
var (
stakingGenesis stakingtypes.GenesisState
bondDenom string
stakingGenesis stakingtypes.GenesisState
consumerGenesis consumertypes.GenesisState
bondDenom string
)

if genesisState[stakingtypes.ModuleName] != nil {
app.AppCodec().MustUnmarshalJSON(genesisState[stakingtypes.ModuleName], &stakingGenesis)
bondDenom = stakingGenesis.Params.BondDenom
} else {
bondDenom = sdk.DefaultBondDenom
}

// fmt.Println("DONE STAKING")

// add bonded amount to bonded pool module account
balances = append(balances, banktypes.Balance{
Address: authtypes.NewModuleAddress(stakingtypes.BondedPoolName).String(),
Coins: sdk.Coins{sdk.NewCoin(bondDenom, bondAmt.Mul(sdk.NewInt(int64(len(valSet.Validators)))))},
})
// fmt.Println("DONE balances", len(validators), len(delegations))

// set validators and delegations
stakingGenesis = *stakingtypes.NewGenesisState(stakingGenesis.Params, validators, delegations)
Expand All @@ -127,9 +145,22 @@ func SetupWithGenesisValSet(t *testing.T, appIniter AppIniter, valSet *tmtypes.V
bankGenesis := banktypes.NewGenesisState(banktypes.DefaultGenesisState().Params, balances, sdk.NewCoins(), []banktypes.Metadata{}, []banktypes.SendEnabled{})
genesisState[banktypes.ModuleName] = app.AppCodec().MustMarshalJSON(bankGenesis)

if genesisState[consumertypes.ModuleName] != nil {
app.AppCodec().MustUnmarshalJSON(genesisState[consumertypes.ModuleName], &consumerGenesis)
consumerGenesis.InitialValSet = initValPowers
// consumerGenesis.NewChain = true
consumerGenesis.Params.Enabled = true
// fmt.Println("##", len(consumerGenesis.InitialValSet))
genesisState[consumertypes.ModuleName] = app.AppCodec().MustMarshalJSON(&consumerGenesis)
}

stateBytes, err := json.MarshalIndent(genesisState, "", " ")
// fmt.Println(string(stateBytes))
require.NoError(t, err)
// fmt.Println("DONE STATE BYTES")

// fmt.Println("TRY INIT")
// // fmt.Println("## STATE ##\n\n", string(stateBytes))
// init chain will set the validator set and initialize the genesis accounts
app.InitChain(
abci.RequestInitChain{
Expand All @@ -139,9 +170,12 @@ func SetupWithGenesisValSet(t *testing.T, appIniter AppIniter, valSet *tmtypes.V
AppStateBytes: stateBytes,
},
)
// fmt.Println("DONE INIT")

// commit genesis changes
app.Commit()
// fmt.Println("DONE COMMIT")

app.BeginBlock(
abci.RequestBeginBlock{
Header: tmproto.Header{
Expand All @@ -154,5 +188,7 @@ func SetupWithGenesisValSet(t *testing.T, appIniter AppIniter, valSet *tmtypes.V
},
)

// fmt.Printf("$$$$$$$$$$$$$$$$$$$ done on %v\n\n", chainID)

return app
}
Loading

0 comments on commit d09d4d9

Please sign in to comment.