-
Notifications
You must be signed in to change notification settings - Fork 122
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
refactor!: Split out consumer genesis state #1324
Merged
Merged
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
0189212
Split ConsumerGenesis datatype
bermuell 8ef2167
Move other non-shared types to consumer
bermuell f60fc54
fix some protbuf lint issues
bermuell bff3d09
make proto-format
bermuell 1b0a565
Rename PrivateConsumerGenesisState to GenesisState
bermuell ae9aa50
Fix linter issues
bermuell 3635fa0
Correct some proto buf
bermuell 320bb50
Protobuf use deprecated instead of reserved
bermuell cf80174
Add genesis transformation command to interchain-security-cd
bermuell 52bf055
Remove unused field from test data
bermuell e99770a
Added some basic checks
bermuell 0948a6e
Fix linter warnings
bermuell 8326811
Added test
bermuell ea77c6e
Minor test fixes + lint warnings
bermuell 1de4699
Fix lint warning
bermuell 043219f
Updated comment
bermuell 6d94ef8
Addressed comments
bermuell 0e31c3b
Merge remote-tracking branch 'origin/main' into bernd/1214-splitConsu…
bermuell a60d199
Update docs
bermuell 2713327
Addressed comments
bermuell 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
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
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 |
---|---|---|
@@ -0,0 +1,213 @@ | ||
package app_test | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"io/fs" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
"time" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/x/auth/types" | ||
|
||
app "github.com/cosmos/interchain-security/v3/app/consumer" | ||
consumerTypes "github.com/cosmos/interchain-security/v3/x/ccv/consumer/types" | ||
) | ||
|
||
// Testdata mapping consumer genesis exports to a provider module version as | ||
// used by transformation function for consumer genesis content. | ||
var consumerGenesisStates map[string]string = map[string]string{ | ||
"v2": ` | ||
{ | ||
"params": { | ||
"enabled": true, | ||
"blocks_per_distribution_transmission": "1500", | ||
"distribution_transmission_channel": "", | ||
"provider_fee_pool_addr_str": "", | ||
"ccv_timeout_period": "2419200s", | ||
"transfer_timeout_period": "3600s", | ||
"consumer_redistribution_fraction": "0.75", | ||
"historical_entries": "10000", | ||
"unbonding_period": "1728000s", | ||
"soft_opt_out_threshold": "", | ||
"reward_denoms": [], | ||
"provider_reward_denoms": [] | ||
}, | ||
"provider_client_id": "", | ||
"provider_channel_id": "", | ||
"new_chain": true, | ||
"provider_client_state": { | ||
"chain_id": "cosmoshub-4", | ||
"trust_level": { | ||
"numerator": "1", | ||
"denominator": "3" | ||
}, | ||
"trusting_period": "1197504s", | ||
"unbonding_period": "1814400s", | ||
"max_clock_drift": "10s", | ||
"frozen_height": { | ||
"revision_number": "0", | ||
"revision_height": "0" | ||
}, | ||
"latest_height": { | ||
"revision_number": "4", | ||
"revision_height": "15211521" | ||
}, | ||
"proof_specs": [ | ||
{ | ||
"leaf_spec": { | ||
"hash": "SHA256", | ||
"prehash_key": "NO_HASH", | ||
"prehash_value": "SHA256", | ||
"length": "VAR_PROTO", | ||
"prefix": "AA==" | ||
}, | ||
"inner_spec": { | ||
"child_order": [ | ||
0, | ||
1 | ||
], | ||
"child_size": 33, | ||
"min_prefix_length": 4, | ||
"max_prefix_length": 12, | ||
"empty_child": null, | ||
"hash": "SHA256" | ||
}, | ||
"max_depth": 0, | ||
"min_depth": 0 | ||
}, | ||
{ | ||
"leaf_spec": { | ||
"hash": "SHA256", | ||
"prehash_key": "NO_HASH", | ||
"prehash_value": "SHA256", | ||
"length": "VAR_PROTO", | ||
"prefix": "AA==" | ||
}, | ||
"inner_spec": { | ||
"child_order": [ | ||
0, | ||
1 | ||
], | ||
"child_size": 32, | ||
"min_prefix_length": 1, | ||
"max_prefix_length": 1, | ||
"empty_child": null, | ||
"hash": "SHA256" | ||
}, | ||
"max_depth": 0, | ||
"min_depth": 0 | ||
} | ||
], | ||
"upgrade_path": [ | ||
"upgrade", | ||
"upgradedIBCState" | ||
], | ||
"allow_update_after_expiry": true, | ||
"allow_update_after_misbehaviour": true | ||
}, | ||
"provider_consensus_state": { | ||
"timestamp": "2023-05-08T11:00:01.563901871Z", | ||
"root": { | ||
"hash": "qKVnVSXlsjDHC8ekKcy/0zSjzr3YekCurld9R4W07EI=" | ||
}, | ||
"next_validators_hash": "E08978F493101A3C5D459FB3087B8CFBA9E82D7A1FE1441E7D77E11AC0586BAC" | ||
}, | ||
"maturing_packets": [], | ||
"initial_val_set": [ | ||
{ | ||
"pub_key": { | ||
"ed25519": "cOQZvh/h9ZioSeUMZB/1Vy1Xo5x2sjrVjlE/qHnYifM=" | ||
}, | ||
"power": "2345194" | ||
}, | ||
{ | ||
"pub_key": { | ||
"ed25519": "vGSKfbQyKApvBhinpOOA0XQAdjxceihYNwtGskfZGyQ=" | ||
}, | ||
"power": "463811" | ||
} | ||
], | ||
"height_to_valset_update_id": [], | ||
"outstanding_downtime_slashing": [], | ||
"pending_consumer_packets": { | ||
"list": [] | ||
}, | ||
"last_transmission_block_height": { | ||
"height": "0" | ||
}, | ||
"preCCV": false | ||
} | ||
|
||
`, | ||
} | ||
|
||
func getClientCtx() client.Context { | ||
encodingConfig := app.MakeTestEncodingConfig() | ||
return client.Context{}. | ||
WithCodec(encodingConfig.Codec). | ||
WithInterfaceRegistry(encodingConfig.InterfaceRegistry). | ||
WithTxConfig(encodingConfig.TxConfig). | ||
WithLegacyAmino(encodingConfig.Amino). | ||
WithInput(os.Stdin). | ||
WithAccountRetriever(types.AccountRetriever{}) | ||
} | ||
|
||
// Setup client context | ||
func getGenesisTransformCmd() (*cobra.Command, error) { | ||
cmd := app.GetConsumerGenesisTransformCmd() | ||
clientCtx := getClientCtx() | ||
ctx := context.WithValue(context.Background(), client.ClientContextKey, &clientCtx) | ||
cmd.SetContext(ctx) | ||
err := client.SetCmdClientContext(cmd, clientCtx) | ||
return cmd, err | ||
} | ||
|
||
// Check transformation of a version 2 ConsumerGenesis export to | ||
// consumer genesis json format used by current consumer implementation. | ||
func TestConsumerGenesisTransformationV2(t *testing.T) { | ||
version := "v2" | ||
filePath := filepath.Join(t.TempDir(), "oldConsumerGenesis.json") | ||
|
||
err := os.WriteFile( | ||
filePath, | ||
[]byte(consumerGenesisStates[version]), | ||
fs.FileMode(0o644)) | ||
require.NoError(t, err) | ||
defer os.Remove(filePath) | ||
|
||
cmd, err := getGenesisTransformCmd() | ||
require.NoError(t, err, "Error setting up transformation command: %s", err) | ||
cmd.SetArgs([]string{filePath}) | ||
|
||
output := new(bytes.Buffer) | ||
cmd.SetOutput(output) | ||
require.NoError(t, err) | ||
_, err = cmd.ExecuteC() | ||
require.NoError(t, err) | ||
|
||
consumerGenesis := consumerTypes.GenesisState{} | ||
|
||
bz := output.Bytes() | ||
ctx := client.GetClientContextFromCmd(cmd) | ||
err = ctx.Codec.UnmarshalJSON(bz, &consumerGenesis) | ||
require.NoError(t, err, "Error unmarshalling transformed genesis state :%s", err) | ||
|
||
// Some basic sanity checks on the content. | ||
require.Nil(t, consumerGenesis.ProviderClientState) | ||
require.NotNil(t, consumerGenesis.Provider.ClientState) | ||
require.Equal(t, "cosmoshub-4", consumerGenesis.Provider.ClientState.ChainId) | ||
|
||
require.Nil(t, consumerGenesis.ProviderConsensusState) | ||
require.NotNil(t, consumerGenesis.Provider.ConsensusState) | ||
require.Equal(t, time.Date(2023, time.May, 8, 11, 0, 1, 563901871, time.UTC), | ||
consumerGenesis.Provider.ConsensusState.Timestamp) | ||
|
||
require.Empty(t, consumerGenesis.InitialValSet) | ||
require.NotEmpty(t, consumerGenesis.Provider.InitialValSet) | ||
} |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
nit: perhaps add a
strings.TrimSpace()
call here