Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add genesis modification function to e2e #2112

Merged
merged 7 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions e2e/testconfig/testconfig.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
package testconfig

import (
"encoding/json"
"fmt"
"os"

"github.com/cosmos/cosmos-sdk/codec"
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
sdk "github.com/cosmos/cosmos-sdk/types"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
"github.com/strangelove-ventures/ibctest/ibc"
tmjson "github.com/tendermint/tendermint/libs/json"
tmtypes "github.com/tendermint/tendermint/types"

"github.com/cosmos/ibc-go/e2e/testvalues"
)

const (
Expand Down Expand Up @@ -150,3 +161,51 @@ func newDefaultSimappConfig(cc ChainConfig, name, chainID, denom string) ibc.Cha
NoHostMount: false,
}
}

// defaultModifyGenesis will only modify governance params to ensure the voting period and minimum deposit
// are functional for e2e testing purposes.
func defaultModifyGenesis(denom string) func([]byte) ([]byte, error) {
return func(genbz []byte) ([]byte, error) {
genDoc, err := tmtypes.GenesisDocFromJSON(genbz)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal genesis bytes into genesis doc: %w", err)
}

var appState genutiltypes.AppMap
if err := json.Unmarshal(genDoc.AppState, &appState); err != nil {
return nil, fmt.Errorf("failed to unmarshal genesis bytes into app state: %w", err)
}

cfg := simappparams.MakeTestEncodingConfig()
govv1beta1.RegisterInterfaces(cfg.InterfaceRegistry)
cdc := codec.NewProtoCodec(cfg.InterfaceRegistry)
Comment on lines +179 to +181
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you think about moving this to some separate initialization function, is there a benefit to having a new instance each time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No benefit. Ideally this function would be exposed on ibctest. Where would you suggest we add this initialization function? Are you suggesting we keep a global variable? I think that'd be fine since it is just for testing

I'd be happy to add a generateCodec() function, but it would still recreate the instance each time

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I guess there wouldn't be much benefit either way, maybe we could consider it if we find ourselves generating the same codec in multiple places. It's probably fine for now to leave this as is

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave as is. I think it'll be easier to wait for a natural place to initialize the codec than to look for one right now


govGenesisState := &govv1beta1.GenesisState{}
if err := cdc.UnmarshalJSON(appState[govtypes.ModuleName], govGenesisState); err != nil {
return nil, fmt.Errorf("failed to unmarshal genesis bytes into gov genesis state: %w", err)
}

// set correct minimum deposit using configured denom
govGenesisState.DepositParams.MinDeposit = sdk.NewCoins(sdk.NewCoin(denom, govv1beta1.DefaultMinDepositTokens))
govGenesisState.VotingParams.VotingPeriod = testvalues.VotingPeriod

govGenBz, err := cdc.MarshalJSON(govGenesisState)
if err != nil {
return nil, fmt.Errorf("failed to marshal gov genesis state: %w", err)
}

appState[govtypes.ModuleName] = govGenBz

genDoc.AppState, err = json.Marshal(appState)
if err != nil {
return nil, err
}

bz, err := tmjson.MarshalIndent(genDoc, "", " ")
chatton marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return nil, err
}

return bz, nil
}
}
9 changes: 6 additions & 3 deletions e2e/testvalues/values.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package testvalues

import (
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/strangelove-ventures/ibctest/ibc"

feetypes "github.com/cosmos/ibc-go/v5/modules/apps/29-fee/types"
)

const (
StartingTokenAmount int64 = 100_000_000
IBCTransferAmount int64 = 10_000
InvalidAddress string = "<invalid-address>"
StartingTokenAmount int64 = 100_000_000
IBCTransferAmount int64 = 10_000
InvalidAddress string = "<invalid-address>"
VotingPeriod time.Duration = time.Second * 30
)

// ImmediatelyTimeout returns an ibc.IBCTimeout which will cause an IBC transfer to timeout immediately.
Expand Down