-
Notifications
You must be signed in to change notification settings - Fork 683
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
Fix e2e tests for pre sdk v0.47 chains #3026
Merged
chatton
merged 6 commits into
main
from
cian/fix-e2e-tests-for-older-versions-of-the-sdk
Jan 24, 2023
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
18be12d
chore: refactoring genesis modification function to not rely on concr…
chatton b181ee3
chore: adding docstring to explain why unsafe map is being used
chatton a928aec
Merge branch 'main' into cian/fix-e2e-tests-for-older-versions-of-the…
chatton 0275965
chore: PR feedback
chatton 128cfd9
chore: removing accidental file
chatton d2e836b
Merge branch 'main' into cian/fix-e2e-tests-for-older-versions-of-the…
chatton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -8,14 +8,11 @@ import ( | |||||
"github.com/cosmos/cosmos-sdk/codec" | ||||||
sdk "github.com/cosmos/cosmos-sdk/types" | ||||||
"github.com/cosmos/cosmos-sdk/types/module/testutil" | ||||||
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" | ||||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" | ||||||
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" | ||||||
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" | ||||||
gogoproto "github.com/cosmos/gogoproto/proto" | ||||||
"github.com/strangelove-ventures/ibctest/v6/ibc" | ||||||
tmjson "github.com/tendermint/tendermint/libs/json" | ||||||
tmtypes "github.com/tendermint/tendermint/types" | ||||||
|
||||||
"github.com/cosmos/ibc-go/e2e/semverutil" | ||||||
"github.com/cosmos/ibc-go/e2e/testvalues" | ||||||
|
@@ -190,42 +187,64 @@ var govGenesisFeatureReleases = semverutil.FeatureReleases{ | |||||
|
||||||
// defaultModifyGenesis will only modify governance params to ensure the voting period and minimum deposit | ||||||
// are functional for e2e testing purposes. | ||||||
// Note: this function intentionally does not use the type defined here https://github.com/tendermint/tendermint/blob/64747b2b184184ecba4f4bffc54ffbcb47cfbcb0/types/genesis.go#L39 | ||||||
// and uses a map[string]interface{} instead. | ||||||
// this is because ibctest performs the following steps when creating the genesis.json file for chains. | ||||||
// - 1. Let the chain binary create its own genesis file. | ||||||
// - 2. Apply any provided functions to modify the bytes of the file. | ||||||
// - 3. Overwrite the file with the new contents. | ||||||
// This is a problem because when the tendermint types change, marshalling into the type will cause us to lose | ||||||
// values if the types have changed in between the versis of the chain in the test and the version of tendermint | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
// imported by the e2e tests. | ||||||
// By using a raw map[string]interface{} we preserve the values unknown to the e2e tests and can still change | ||||||
// the values we care about. | ||||||
// TODO: handle these genesis modifications in a way which is type safe and does not require us to rely on | ||||||
// map[string]interface{} | ||||||
func defaultModifyGenesis() func(ibc.ChainConfig, []byte) ([]byte, error) { | ||||||
const appStateKey = "app_state" | ||||||
return func(chainConfig ibc.ChainConfig, genbz []byte) ([]byte, error) { | ||||||
genDoc, err := tmtypes.GenesisDocFromJSON(genbz) | ||||||
genesisDocMap := map[string]interface{}{} | ||||||
err := json.Unmarshal(genbz, &genesisDocMap) | ||||||
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) | ||||||
appStateMap, ok := genesisDocMap[appStateKey].(map[string]interface{}) | ||||||
if !ok { | ||||||
return nil, fmt.Errorf("failed to extract to app_state") | ||||||
} | ||||||
|
||||||
govGenBz, err := modifyGovAppState(chainConfig, appState[govtypes.ModuleName]) | ||||||
govModuleBytes, err := json.Marshal(appStateMap[govtypes.ModuleName]) | ||||||
if err != nil { | ||||||
return nil, err | ||||||
return nil, fmt.Errorf("failed to extract gov genesis bytes: %s", err) | ||||||
} | ||||||
|
||||||
appState[govtypes.ModuleName] = govGenBz | ||||||
|
||||||
genDoc.AppState, err = json.Marshal(appState) | ||||||
govModuleGenesisBytes, err := modifyGovAppState(chainConfig, govModuleBytes) | ||||||
if err != nil { | ||||||
return nil, err | ||||||
} | ||||||
|
||||||
bz, err := tmjson.MarshalIndent(genDoc, "", " ") | ||||||
govModuleGenesisMap := map[string]interface{}{} | ||||||
err = json.Unmarshal(govModuleGenesisBytes, &govModuleGenesisMap) | ||||||
if err != nil { | ||||||
return nil, fmt.Errorf("failed to unmarshal gov genesis bytes into map: %w", err) | ||||||
} | ||||||
|
||||||
appStateMap[govtypes.ModuleName] = govModuleGenesisMap | ||||||
genesisDocMap[appStateKey] = appStateMap | ||||||
|
||||||
finalGenesisDocBytes, err := json.MarshalIndent(genesisDocMap, "", " ") | ||||||
if err != nil { | ||||||
return nil, err | ||||||
} | ||||||
|
||||||
return bz, nil | ||||||
return finalGenesisDocBytes, nil | ||||||
} | ||||||
} | ||||||
|
||||||
// modifyGovAppState takes the existing gov app state and marshals it to either a govv1 GenesisState | ||||||
// or a govv1beta1 GenesisState depending on the simapp version. | ||||||
func modifyGovAppState(chainConfig ibc.ChainConfig, govAppState json.RawMessage) ([]byte, error) { | ||||||
func modifyGovAppState(chainConfig ibc.ChainConfig, govAppState []byte) ([]byte, error) { | ||||||
cfg := testutil.MakeTestEncodingConfig() | ||||||
|
||||||
cdc := codec.NewProtoCodec(cfg.InterfaceRegistry) | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we link to a release tag instead of a commit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think that's a good idea, will update the comment!