From 37a79147d8228a1bcb1b013cb0735f78759f16ce Mon Sep 17 00:00:00 2001 From: Roman Date: Mon, 4 Jul 2022 17:07:10 -0400 Subject: [PATCH 1/5] e2e: refactor initialization with single node logic --- Makefile | 3 + .../cmd/balances_from_state_export.go | 9 - tests/e2e/e2e_setup_test.go | 34 ++- tests/e2e/e2e_test.go | 9 +- tests/e2e/e2e_util_test.go | 4 +- tests/e2e/initialization/chain.go | 45 +--- tests/e2e/initialization/chain/main.go | 2 +- tests/e2e/initialization/config.go | 163 +++++--------- tests/e2e/initialization/export.go | 9 +- tests/e2e/initialization/init.go | 75 +++++++ tests/e2e/initialization/init_test.go | 143 ++++++++++++ tests/e2e/initialization/main.go | 20 -- .../initialization/{validator.go => node.go} | 210 +++++++++++++----- tests/e2e/initialization/node/main.go | 66 ++++++ 14 files changed, 539 insertions(+), 253 deletions(-) create mode 100644 tests/e2e/initialization/init.go create mode 100644 tests/e2e/initialization/init_test.go delete mode 100644 tests/e2e/initialization/main.go rename tests/e2e/initialization/{validator.go => node.go} (53%) create mode 100644 tests/e2e/initialization/node/main.go diff --git a/Makefile b/Makefile index 5c759929f7b..44f86d8786f 100644 --- a/Makefile +++ b/Makefile @@ -250,6 +250,9 @@ docker-build-debug: docker-build-e2e-init-chain: @docker build -t osmosis-e2e-init-chain:debug --build-arg E2E_SCRIPT_NAME=chain -f tests/e2e/initialization/init.Dockerfile . +docker-build-e2e-init-node: + @docker build -t osmosis-e2e-init-node:debug --build-arg E2E_SCRIPT_NAME=node -f tests/e2e/initialization/init.Dockerfile . + ############################################################################### ### Linting ### ############################################################################### diff --git a/cmd/osmosisd/cmd/balances_from_state_export.go b/cmd/osmosisd/cmd/balances_from_state_export.go index 9c3ff42af77..69b36e19875 100644 --- a/cmd/osmosisd/cmd/balances_from_state_export.go +++ b/cmd/osmosisd/cmd/balances_from_state_export.go @@ -19,7 +19,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/server" sdk "github.com/cosmos/cosmos-sdk/types" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -177,14 +176,6 @@ Example: } } - authGenesis := authtypes.GenesisState{} - clientCtx.Codec.MustUnmarshalJSON(genState["auth"], &authGenesis) - accounts, err := authtypes.UnpackAccounts(authGenesis.Accounts) - if err != nil { - panic(err) - } - accounts = authtypes.SanitizeGenesisAccounts(accounts) - // Produce the map of address to total atom balance, both staked and UnbondingStake snapshotAccs := make(map[string]DerivedAccount) diff --git a/tests/e2e/e2e_setup_test.go b/tests/e2e/e2e_setup_test.go index 1a1eb1a1cfd..dbfd847d5e4 100644 --- a/tests/e2e/e2e_setup_test.go +++ b/tests/e2e/e2e_setup_test.go @@ -33,7 +33,7 @@ type syncInfo struct { } type validatorConfig struct { - validator initialization.Validator + validator initialization.Node operatorAddress string } @@ -76,57 +76,71 @@ const ( var ( // whatever number of validator configs get posted here are how many validators that will spawn on chain A and B respectively - validatorConfigsChainA = []*initialization.ValidatorConfig{ + validatorConfigsChainA = []*initialization.NodeConfig{ { + Name: "prune-default-snapshot", Pruning: "default", PruningKeepRecent: "0", PruningInterval: "0", SnapshotInterval: 1500, SnapshotKeepRecent: 2, + IsValidator: true, }, { + Name: "prune-nothing-snapshot", Pruning: "nothing", PruningKeepRecent: "0", PruningInterval: "0", SnapshotInterval: 1500, SnapshotKeepRecent: 2, + IsValidator: true, }, { + Name: "prune-custom-10000-13-snapshot", Pruning: "custom", PruningKeepRecent: "10000", PruningInterval: "13", SnapshotInterval: 1500, SnapshotKeepRecent: 2, + IsValidator: true, }, { + Name: "prune-everything-no-snapshot", Pruning: "everything", PruningKeepRecent: "0", PruningInterval: "0", SnapshotInterval: 0, SnapshotKeepRecent: 0, + IsValidator: true, }, } - validatorConfigsChainB = []*initialization.ValidatorConfig{ + validatorConfigsChainB = []*initialization.NodeConfig{ { + Name: "prune-default-snapshot", Pruning: "default", PruningKeepRecent: "0", PruningInterval: "0", SnapshotInterval: 1500, SnapshotKeepRecent: 2, + IsValidator: true, }, { + Name: "prune-nothing-snapshot", Pruning: "nothing", PruningKeepRecent: "0", PruningInterval: "0", SnapshotInterval: 1500, SnapshotKeepRecent: 2, + IsValidator: true, }, { + Name: "prune-custom-snapshot", Pruning: "custom", PruningKeepRecent: "10000", PruningInterval: "13", SnapshotInterval: 1500, SnapshotKeepRecent: 2, + IsValidator: true, }, } ) @@ -363,7 +377,7 @@ func (s *IntegrationTestSuite) runIBCRelayer(chainA *chainConfig, chainB *chainC s.connectIBCChains(chainA, chainB) } -func (s *IntegrationTestSuite) configureChain(chainId string, validatorConfigs []*initialization.ValidatorConfig, skipValidatorIndexes map[int]struct{}) { +func (s *IntegrationTestSuite) configureChain(chainId string, validatorConfigs []*initialization.NodeConfig, skipValidatorIndexes map[int]struct{}) { s.T().Logf("starting e2e infrastructure for chain-id: %s", chainId) tmpDir, err := os.MkdirTemp("", "osmosis-e2e-testnet-") @@ -428,8 +442,8 @@ func (s *IntegrationTestSuite) initializeChainConfig(chainConfig *chainConfig, i chainConfig.meta.DataDir = initializedChain.ChainMeta.DataDir chainConfig.meta.Id = initializedChain.ChainMeta.Id - chainConfig.validators = make([]*validatorConfig, 0, len(initializedChain.Validators)) - for _, val := range initializedChain.Validators { + chainConfig.validators = make([]*validatorConfig, 0, len(initializedChain.Nodes)) + for _, val := range initializedChain.Nodes { chainConfig.validators = append(chainConfig.validators, &validatorConfig{validator: *val}) } @@ -569,8 +583,8 @@ func (s *IntegrationTestSuite) createPreUpgradeState() { s.sendIBC(chainB, chainA, chainA.validators[0].validator.PublicAddress, initialization.OsmoToken) s.sendIBC(chainA, chainB, chainB.validators[0].validator.PublicAddress, initialization.StakeToken) s.sendIBC(chainB, chainA, chainA.validators[0].validator.PublicAddress, initialization.StakeToken) - s.createPool(chainA, "pool1A.json") - s.createPool(chainB, "pool1B.json") + s.createPool(chainA, "pool1A.json", initialization.ValidatorWalletName) + s.createPool(chainB, "pool1B.json", initialization.ValidatorWalletName) } func (s *IntegrationTestSuite) runPostUpgradeTests() { @@ -585,6 +599,6 @@ func (s *IntegrationTestSuite) runPostUpgradeTests() { s.sendIBC(chainB, chainA, chainA.validators[0].validator.PublicAddress, initialization.OsmoToken) s.sendIBC(chainA, chainB, chainB.validators[0].validator.PublicAddress, initialization.StakeToken) s.sendIBC(chainB, chainA, chainA.validators[0].validator.PublicAddress, initialization.StakeToken) - s.createPool(chainA, "pool2A.json") - s.createPool(chainB, "pool2B.json") + s.createPool(chainA, "pool2A.json", initialization.ValidatorWalletName) + s.createPool(chainB, "pool2B.json", initialization.ValidatorWalletName) } diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index 864f611cc94..82d5fe1a26e 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -25,24 +25,25 @@ func (s *IntegrationTestSuite) TestSuperfluidVoting() { // TODO: https://github.com/osmosis-labs/osmosis/issues/1843 s.T().Skip("Superfluid tests are broken when upgrade is skipped. To be fixed in #1843") } + const walletName = "superfluid-wallet" chainA := s.chainConfigs[0] s.submitSuperfluidProposal(chainA, "gamm/pool/1") s.depositProposal(chainA) s.voteProposal(chainA) - walletAddr := s.createWallet(chainA, 0, "wallet") + walletAddr := s.createWallet(chainA, 0, walletName) // send gamm tokens to validator's other wallet (non self-delegation wallet) s.sendTx(chainA, 0, "100000000000000000000gamm/pool/1", chainA.validators[0].validator.PublicAddress, walletAddr) // lock tokens from validator 0 on chain A - s.lockTokens(chainA, 0, "100000000000000000000gamm/pool/1", "240s", "wallet") + s.lockTokens(chainA, 0, "100000000000000000000gamm/pool/1", "240s", walletName) // superfluid delegate from validator 0 non self-delegation wallet to validator 1 on chain A - s.superfluidDelegate(chainA, chainA.validators[1].operatorAddress, "wallet") + s.superfluidDelegate(chainA, chainA.validators[1].operatorAddress, walletName) // create a text prop, deposit and vote yes s.submitTextProposal(chainA, "superfluid vote overwrite test") s.depositProposal(chainA) s.voteProposal(chainA) // set delegator vote to no - s.voteNoProposal(chainA, 0, "wallet") + s.voteNoProposal(chainA, 0, walletName) hostPort, err := s.containerManager.GetValidatorHostPort(chainA.meta.Id, 0, "1317/tcp") s.Require().NoError(err) diff --git a/tests/e2e/e2e_util_test.go b/tests/e2e/e2e_util_test.go index 4ee3f927a23..40b9ca1b52e 100644 --- a/tests/e2e/e2e_util_test.go +++ b/tests/e2e/e2e_util_test.go @@ -220,9 +220,9 @@ func (s *IntegrationTestSuite) queryPropTally(endpoint, addr string) (sdk.Int, s return noTotal, yesTotal, noWithVetoTotal, abstainTotal, nil } -func (s *IntegrationTestSuite) createPool(c *chainConfig, poolFile string) { +func (s *IntegrationTestSuite) createPool(c *chainConfig, poolFile string, from string) { s.T().Logf("creating pool for chain-id: %s", c.meta.Id) - cmd := []string{"osmosisd", "tx", "gamm", "create-pool", fmt.Sprintf("--pool-file=/osmosis/%s", poolFile), fmt.Sprintf("--chain-id=%s", c.meta.Id), "--from=val", "-b=block", "--yes", "--keyring-backend=test"} + cmd := []string{"osmosisd", "tx", "gamm", "create-pool", fmt.Sprintf("--pool-file=/osmosis/%s", poolFile), fmt.Sprintf("--chain-id=%s", c.meta.Id), fmt.Sprintf("--from=%s", from), "-b=block", "--yes", "--keyring-backend=test"} _, _, err := s.containerManager.ExecCmd(s.T(), c.meta.Id, 0, cmd, "code: 0") s.Require().NoError(err) validatorResource, exists := s.containerManager.GetValidatorResource(c.meta.Id, 0) diff --git a/tests/e2e/initialization/chain.go b/tests/e2e/initialization/chain.go index 818d05afb6b..c407e0ee042 100644 --- a/tests/e2e/initialization/chain.go +++ b/tests/e2e/initialization/chain.go @@ -12,8 +12,8 @@ const ( // internalChain contains the same info as chain, but with the validator structs instead using the internal validator // representation, with more derived data type internalChain struct { - chainMeta ChainMeta - validators []*internalValidator + chainMeta ChainMeta + nodes []*internalNode } func new(id, dataDir string) (*internalChain, error) { @@ -26,48 +26,21 @@ func new(id, dataDir string) (*internalChain, error) { }, nil } -func (c *internalChain) createAndInitValidators(count int) error { - for i := 0; i < count; i++ { - node := c.createValidator(i) - - // generate genesis files - if err := node.init(); err != nil { - return err - } - - c.validators = append(c.validators, node) - - // create keys - if err := node.createKey("val"); err != nil { - return err - } - if err := node.createNodeKey(); err != nil { - return err - } - if err := node.createConsensusKey(); err != nil { - return err - } - } - - return nil -} - -func (c *internalChain) createValidator(index int) *internalValidator { - return &internalValidator{ +func (c *internalChain) createValidator(index int) *internalNode { + return &internalNode{ chain: c, - index: index, moniker: fmt.Sprintf("%s-osmosis-%d", c.chainMeta.Id, index), } } func (c *internalChain) export() *Chain { - exportValidators := make([]*Validator, 0, len(c.validators)) - for _, v := range c.validators { - exportValidators = append(exportValidators, v.export()) + exportNodes := make([]*Node, 0, len(c.nodes)) + for _, v := range c.nodes { + exportNodes = append(exportNodes, v.export()) } return &Chain{ - ChainMeta: c.chainMeta, - Validators: exportValidators, + ChainMeta: c.chainMeta, + Nodes: exportNodes, } } diff --git a/tests/e2e/initialization/chain/main.go b/tests/e2e/initialization/chain/main.go index bdcbd12970a..429818fa5e5 100644 --- a/tests/e2e/initialization/chain/main.go +++ b/tests/e2e/initialization/chain/main.go @@ -12,7 +12,7 @@ import ( func main() { var ( - valConfig []*initialization.ValidatorConfig + valConfig []*initialization.NodeConfig dataDir string chainId string config string diff --git a/tests/e2e/initialization/config.go b/tests/e2e/initialization/config.go index 330b07ac279..f6e0d35cf04 100644 --- a/tests/e2e/initialization/config.go +++ b/tests/e2e/initialization/config.go @@ -4,11 +4,9 @@ import ( "encoding/json" "fmt" "path/filepath" - "strings" "time" "github.com/cosmos/cosmos-sdk/server" - srvconfig "github.com/cosmos/cosmos-sdk/server/config" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -18,8 +16,6 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" staketypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/gogo/protobuf/proto" - "github.com/spf13/viper" - tmconfig "github.com/tendermint/tendermint/config" tmjson "github.com/tendermint/tendermint/libs/json" epochtypes "github.com/osmosis-labs/osmosis/v7/x/epochs/types" @@ -32,22 +28,29 @@ import ( "github.com/osmosis-labs/osmosis/v7/tests/e2e/util" ) -type ValidatorConfig struct { +// NodeConfig is a confiuration for the node supplied from the test runner +// to initialization scripts. It should be backwards compatible with earlier +// versions. If this struct is updated, the change must be backported to earlier +// branches that might be used for upgrade testing. +type NodeConfig struct { + Name string // name of the config that will also be assigned to Docke container. Pruning string // default, nothing, everything, or custom PruningKeepRecent string // keep all of the last N states (only used with custom pruning) PruningInterval string // delete old states from every Nth block (only used with custom pruning) SnapshotInterval uint64 // statesync snapshot every Nth block (0 to disable) SnapshotKeepRecent uint32 // number of recent snapshots to keep and serve (0 to keep all) + IsValidator bool // flag indicating whether a node should be a validator } const ( // common - OsmoDenom = "uosmo" - StakeDenom = "stake" - OsmoIBCDenom = "ibc/ED07A3391A112B175915CD8FAF43A2DA8E4790EDE12566649D0C2F97716B8518" - StakeIBCDenom = "ibc/C053D637CCA2A2BA030E2C5EE1B28A16F71CCB0E45E8BE52766DC1B241B7787" - MinGasPrice = "0.000" - IbcSendAmount = 3300000000 + OsmoDenom = "uosmo" + StakeDenom = "stake" + OsmoIBCDenom = "ibc/ED07A3391A112B175915CD8FAF43A2DA8E4790EDE12566649D0C2F97716B8518" + StakeIBCDenom = "ibc/C053D637CCA2A2BA030E2C5EE1B28A16F71CCB0E45E8BE52766DC1B241B7787" + MinGasPrice = "0.000" + IbcSendAmount = 3300000000 + ValidatorWalletName = "val" // chainA ChainAID = "osmo-test-a" OsmoBalanceA = 200000000000 @@ -163,12 +166,37 @@ func updateModuleGenesis[V proto.Message](appGenState map[string]json.RawMessage return nil } -func initGenesis(c *internalChain, votingPeriod time.Duration) error { +func initGenesis(chain *internalChain, votingPeriod time.Duration, forkHeight int) error { + // initialize a genesis file + configDir := chain.nodes[0].configDir() + for _, val := range chain.nodes { + if chain.chainMeta.Id == ChainAID { + if err := addAccount(configDir, "", InitBalanceStrA, val.getKeyInfo().GetAddress(), forkHeight); err != nil { + return err + } + } else if chain.chainMeta.Id == ChainBID { + if err := addAccount(configDir, "", InitBalanceStrB, val.getKeyInfo().GetAddress(), forkHeight); err != nil { + return err + } + } + } + + // copy the genesis file to the remaining validators + for _, val := range chain.nodes[1:] { + _, err := util.CopyFile( + filepath.Join(configDir, "config", "genesis.json"), + filepath.Join(val.configDir(), "config", "genesis.json"), + ) + if err != nil { + return err + } + } + serverCtx := server.NewDefaultContext() config := serverCtx.Config - config.SetRoot(c.validators[0].configDir()) - config.Moniker = c.validators[0].getMoniker() + config.SetRoot(chain.nodes[0].configDir()) + config.Moniker = chain.nodes[0].getMoniker() genFilePath := config.GenesisFile() appGenState, genDoc, err := genutiltypes.GenesisStateFromGenFile(genFilePath) @@ -186,7 +214,6 @@ func initGenesis(c *internalChain, votingPeriod time.Duration) error { return err } - // pool incentives err = updateModuleGenesis(appGenState, poolitypes.ModuleName, &poolitypes.GenesisState{}, updatePoolIncentiveGenesis) if err != nil { return err @@ -227,7 +254,7 @@ func initGenesis(c *internalChain, votingPeriod time.Duration) error { return err } - err = updateModuleGenesis(appGenState, genutiltypes.ModuleName, &genutiltypes.GenesisState{}, updateGenUtilGenesis(c)) + err = updateModuleGenesis(appGenState, genutiltypes.ModuleName, &genutiltypes.GenesisState{}, updateGenUtilGenesis(chain)) if err != nil { return err } @@ -245,7 +272,7 @@ func initGenesis(c *internalChain, votingPeriod time.Duration) error { } // write the updated genesis file to each validator - for _, val := range c.validators { + for _, val := range chain.nodes { if err := util.WriteFile(filepath.Join(val.configDir(), "config", "genesis.json"), genesisJson); err != nil { return err } @@ -343,18 +370,22 @@ func updateGovGenesis(votingPeriod time.Duration) func(*govtypes.GenesisState) { func updateGenUtilGenesis(c *internalChain) func(*genutiltypes.GenesisState) { return func(genUtilGenState *genutiltypes.GenesisState) { // generate genesis txs - genTxs := make([]json.RawMessage, len(c.validators)) - for i, val := range c.validators { + genTxs := make([]json.RawMessage, 0, len(c.nodes)) + for _, node := range c.nodes { + if !node.isValidator { + continue + } + stakeAmountCoin := StakeAmountCoinA if c.chainMeta.Id != ChainAID { stakeAmountCoin = StakeAmountCoinB } - createValmsg, err := val.buildCreateValidatorMsg(stakeAmountCoin) + createValmsg, err := node.buildCreateValidatorMsg(stakeAmountCoin) if err != nil { panic("genutil genesis setup failed: " + err.Error()) } - signedTx, err := val.signMsg(createValmsg) + signedTx, err := node.signMsg(createValmsg) if err != nil { panic("genutil genesis setup failed: " + err.Error()) } @@ -363,96 +394,8 @@ func updateGenUtilGenesis(c *internalChain) func(*genutiltypes.GenesisState) { if err != nil { panic("genutil genesis setup failed: " + err.Error()) } - genTxs[i] = txRaw + genTxs = append(genTxs, txRaw) } genUtilGenState.GenTxs = genTxs } } - -func initNodes(c *internalChain, numVal, forkHeight int) error { - if err := c.createAndInitValidators(numVal); err != nil { - return err - } - - // initialize a genesis file for the first validator - val0ConfigDir := c.validators[0].configDir() - for _, val := range c.validators { - if c.chainMeta.Id == ChainAID { - if err := addAccount(val0ConfigDir, "", InitBalanceStrA, val.getKeyInfo().GetAddress(), forkHeight); err != nil { - return err - } - } else if c.chainMeta.Id == ChainBID { - if err := addAccount(val0ConfigDir, "", InitBalanceStrB, val.getKeyInfo().GetAddress(), forkHeight); err != nil { - return err - } - } - } - - // copy the genesis file to the remaining validators - for _, val := range c.validators[1:] { - _, err := util.CopyFile( - filepath.Join(val0ConfigDir, "config", "genesis.json"), - filepath.Join(val.configDir(), "config", "genesis.json"), - ) - if err != nil { - return err - } - } - return nil -} - -func initValidatorConfigs(c *internalChain, validatorConfigs []*ValidatorConfig) error { - for i, val := range c.validators { - tmCfgPath := filepath.Join(val.configDir(), "config", "config.toml") - - vpr := viper.New() - vpr.SetConfigFile(tmCfgPath) - if err := vpr.ReadInConfig(); err != nil { - return err - } - - valConfig := &tmconfig.Config{} - if err := vpr.Unmarshal(valConfig); err != nil { - return err - } - - valConfig.P2P.ListenAddress = "tcp://0.0.0.0:26656" - valConfig.P2P.AddrBookStrict = false - valConfig.P2P.ExternalAddress = fmt.Sprintf("%s:%d", val.instanceName(), 26656) - valConfig.RPC.ListenAddress = "tcp://0.0.0.0:26657" - valConfig.StateSync.Enable = false - valConfig.LogLevel = "info" - - var peers []string - - for j := 0; j < len(c.validators); j++ { - // skip adding a peer to yourself - if i == j { - continue - } - - peer := c.validators[j] - peerID := fmt.Sprintf("%s@%s%d:26656", peer.getNodeKey().ID(), peer.getMoniker(), j) - peers = append(peers, peerID) - } - - valConfig.P2P.PersistentPeers = strings.Join(peers, ",") - - tmconfig.WriteConfigFile(tmCfgPath, valConfig) - - // set application configuration - appCfgPath := filepath.Join(val.configDir(), "config", "app.toml") - - appConfig := srvconfig.DefaultConfig() - appConfig.BaseConfig.Pruning = validatorConfigs[i].Pruning - appConfig.BaseConfig.PruningKeepRecent = validatorConfigs[i].PruningKeepRecent - appConfig.BaseConfig.PruningInterval = validatorConfigs[i].PruningInterval - appConfig.API.Enable = true - appConfig.MinGasPrices = fmt.Sprintf("%s%s", MinGasPrice, OsmoDenom) - appConfig.StateSync.SnapshotInterval = validatorConfigs[i].SnapshotInterval - appConfig.StateSync.SnapshotKeepRecent = validatorConfigs[i].SnapshotKeepRecent - - srvconfig.WriteConfigFile(appCfgPath, appConfig) - } - return nil -} diff --git a/tests/e2e/initialization/export.go b/tests/e2e/initialization/export.go index c63bc82c1e1..8e42241644b 100644 --- a/tests/e2e/initialization/export.go +++ b/tests/e2e/initialization/export.go @@ -7,18 +7,19 @@ type ChainMeta struct { Id string `json:"id"` } -type Validator struct { +type Node struct { Name string `json:"name"` ConfigDir string `json:"configDir"` - Index int `json:"index"` Mnemonic string `json:"mnemonic"` PublicAddress string `json:"publicAddress"` PublicKey string `json:"publicKey"` + PeerId string `json:"peerId"` + IsValidator bool `json:"isValidator"` } type Chain struct { - ChainMeta ChainMeta `json:"chainMeta"` - Validators []*Validator `json:"validators"` + ChainMeta ChainMeta `json:"chainMeta"` + Nodes []*Node `json:"validators"` } func (c *ChainMeta) configDir() string { diff --git a/tests/e2e/initialization/init.go b/tests/e2e/initialization/init.go new file mode 100644 index 00000000000..d0b4f1ff948 --- /dev/null +++ b/tests/e2e/initialization/init.go @@ -0,0 +1,75 @@ +package initialization + +import ( + "errors" + "fmt" + "path/filepath" + "time" + + "github.com/osmosis-labs/osmosis/v7/tests/e2e/util" +) + +func Init(id, dataDir string, nodeConfigs []*NodeConfig, votingPeriod time.Duration, forkHeight int) (*Chain, error) { + chain, err := new(id, dataDir) + if err != nil { + return nil, err + } + + for _, nodeConfig := range nodeConfigs { + newNode, err := newNode(chain, nodeConfig) + if err != nil { + return nil, err + } + chain.nodes = append(chain.nodes, newNode) + } + + if err := initGenesis(chain, votingPeriod, forkHeight); err != nil { + return nil, err + } + + var peers []string + for _, peer := range chain.nodes { + peerID := fmt.Sprintf("%s@%s:26656", peer.getNodeKey().ID(), peer.getMoniker()) + peer.peerId = peerID + peers = append(peers, peerID) + } + + for _, node := range chain.nodes { + if node.isValidator { + if err := node.initValidatorConfigs(chain, peers); err != nil { + return nil, err + } + } + } + return chain.export(), nil +} + +func InitSingleNode(chainId, dataDir string, existingGenesisDir string, nodeConfig *NodeConfig, votingPeriod time.Duration, trustHeight int64, trustHash string, stateSyncRPCServers []string) (*Node, error) { + if nodeConfig.IsValidator { + return nil, errors.New("creating individual validator nodes after starting up chain is not currently supported") + } + + chain, err := new(chainId, dataDir) + if err != nil { + return nil, err + } + + newNode, err := newNode(chain, nodeConfig) + if err != nil { + return nil, err + } + + _, err = util.CopyFile( + existingGenesisDir, + filepath.Join(newNode.configDir(), "config", "genesis.json"), + ) + if err != nil { + return nil, err + } + + if err := newNode.initStateSyncConfig(trustHeight, trustHash, stateSyncRPCServers); err != nil { + return nil, err + } + + return newNode.export(), nil +} diff --git a/tests/e2e/initialization/init_test.go b/tests/e2e/initialization/init_test.go new file mode 100644 index 00000000000..c3155b86ced --- /dev/null +++ b/tests/e2e/initialization/init_test.go @@ -0,0 +1,143 @@ +package initialization_test + +import ( + "fmt" + "io/ioutil" + "os" + "path" + "path/filepath" + "testing" + "time" + + "github.com/stretchr/testify/require" + + "github.com/osmosis-labs/osmosis/v7/tests/e2e/initialization" +) + +const forkHeight = 10 + +var ( + expectedConfigFiles = []string{ + "app.toml", "config.toml", "genesis.json", "node_key.json", "priv_validator_key.json", + } +) + +// TestChainInit tests that chain initialization correctly initializes a full chain +// and produces the desired output with genesis, chain and validator configs. +func TestChainInit(t *testing.T) { + const id = initialization.ChainAID + + var ( + nodeConfigs = []*initialization.NodeConfig{ + { + Name: "0", + Pruning: "default", + PruningKeepRecent: "0", + PruningInterval: "0", + SnapshotInterval: 1500, + SnapshotKeepRecent: 2, + IsValidator: true, + }, + { + Name: "1", + Pruning: "nothing", + PruningKeepRecent: "0", + PruningInterval: "0", + SnapshotInterval: 100, + SnapshotKeepRecent: 1, + IsValidator: false, + }, + } + dataDir, err = ioutil.TempDir("", "osmosis-e2e-testnet-test") + ) + + chain, err := initialization.Init(id, dataDir, nodeConfigs, time.Second*3, forkHeight) + require.NoError(t, err) + + require.Equal(t, chain.ChainMeta.DataDir, dataDir) + require.Equal(t, chain.ChainMeta.Id, id) + + require.Equal(t, len(nodeConfigs), len(chain.Nodes)) + + actualNodes := chain.Nodes + + for i, expectedConfig := range nodeConfigs { + actualNode := actualNodes[i] + + validateNode(t, id, dataDir, expectedConfig, actualNode) + } +} + +// TestSingleNodeInit tests that node initialization correctly initializes a single node +// and produces the desired output with genesis, chain and validator config. +func TestSingleNodeInit(t *testing.T) { + const ( + id = initialization.ChainAID + ) + + var ( + existingChainNodeConfigs = []*initialization.NodeConfig{ + { + Name: "0", + Pruning: "default", + PruningKeepRecent: "0", + PruningInterval: "0", + SnapshotInterval: 1500, + SnapshotKeepRecent: 2, + IsValidator: true, + }, + { + Name: "1", + Pruning: "nothing", + PruningKeepRecent: "0", + PruningInterval: "0", + SnapshotInterval: 100, + SnapshotKeepRecent: 1, + IsValidator: true, + }, + } + expectedConfig = &initialization.NodeConfig{ + Name: "2", + Pruning: "everything", + PruningKeepRecent: "0", + PruningInterval: "0", + SnapshotInterval: 100, + SnapshotKeepRecent: 1, + IsValidator: false, + } + dataDir, err = ioutil.TempDir("", "osmosis-e2e-testnet-test") + ) + + // Setup + existingChain, err := initialization.Init(id, dataDir, existingChainNodeConfigs, time.Second*3, forkHeight) + require.NoError(t, err) + + actualNode, err := initialization.InitSingleNode(existingChain.ChainMeta.Id, dataDir, filepath.Join(existingChain.Nodes[0].ConfigDir, "config", "genesis.json"), expectedConfig, time.Second*3, 3, "testHash", []string{"some server"}) + require.NoError(t, err) + + validateNode(t, id, dataDir, expectedConfig, actualNode) +} + +func validateNode(t *testing.T, chainId string, dataDir string, expectedConfig *initialization.NodeConfig, actualNode *initialization.Node) { + require.Equal(t, fmt.Sprintf("%s-node-%s", chainId, expectedConfig.Name), actualNode.Name) + require.Equal(t, expectedConfig.IsValidator, actualNode.IsValidator) + + expectedPath := fmt.Sprintf("%s/%s/%s-node-%s", dataDir, chainId, chainId, expectedConfig.Name) + + require.Equal(t, expectedPath, actualNode.ConfigDir) + + require.NotEmpty(t, actualNode.Mnemonic) + require.NotEmpty(t, actualNode.PublicAddress) + + if expectedConfig.IsValidator { + require.NotEmpty(t, actualNode.PeerId) + } + + for _, expectedFileName := range expectedConfigFiles { + expectedFilePath := path.Join(expectedPath, "config", expectedFileName) + _, err := os.Stat(expectedFilePath) + require.NoError(t, err) + } + _, err := os.Stat(path.Join(expectedPath, "keyring-test")) + require.NoError(t, err) +} diff --git a/tests/e2e/initialization/main.go b/tests/e2e/initialization/main.go deleted file mode 100644 index 3979ea692ec..00000000000 --- a/tests/e2e/initialization/main.go +++ /dev/null @@ -1,20 +0,0 @@ -package initialization - -import "time" - -func Init(id, dataDir string, validatorConfigs []*ValidatorConfig, votingPeriod time.Duration, forkHeight int) (*Chain, error) { - chain, err := new(id, dataDir) - if err != nil { - return nil, err - } - if err := initNodes(chain, len(validatorConfigs), forkHeight); err != nil { - return nil, err - } - if err := initGenesis(chain, votingPeriod); err != nil { - return nil, err - } - if err := initValidatorConfigs(chain, validatorConfigs); err != nil { - return nil, err - } - return chain.export(), nil -} diff --git a/tests/e2e/initialization/validator.go b/tests/e2e/initialization/node.go similarity index 53% rename from tests/e2e/initialization/validator.go rename to tests/e2e/initialization/node.go index 16e302f52d9..9c9c7dd0553 100644 --- a/tests/e2e/initialization/validator.go +++ b/tests/e2e/initialization/node.go @@ -6,6 +6,7 @@ import ( "os" "path" "path/filepath" + "strings" sdkcrypto "github.com/cosmos/cosmos-sdk/crypto" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" @@ -13,6 +14,7 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keyring" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/server" + srvconfig "github.com/cosmos/cosmos-sdk/server/config" sdk "github.com/cosmos/cosmos-sdk/types" sdktx "github.com/cosmos/cosmos-sdk/types/tx" txsigning "github.com/cosmos/cosmos-sdk/types/tx/signing" @@ -20,7 +22,9 @@ import ( "github.com/cosmos/cosmos-sdk/x/genutil" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/cosmos/go-bip39" + "github.com/spf13/viper" tmcfg "github.com/tendermint/tendermint/config" + tmconfig "github.com/tendermint/tendermint/config" tmos "github.com/tendermint/tendermint/libs/os" "github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/privval" @@ -30,35 +34,60 @@ import ( "github.com/osmosis-labs/osmosis/v7/tests/e2e/util" ) -type internalValidator struct { +type internalNode struct { chain *internalChain - index int moniker string mnemonic string keyInfo keyring.Info privateKey cryptotypes.PrivKey consensusKey privval.FilePVKey nodeKey p2p.NodeKey + peerId string + isValidator bool } -func (v *internalValidator) instanceName() string { - return fmt.Sprintf("%s%d", v.moniker, v.index) +func newNode(chain *internalChain, nodeConfig *NodeConfig) (*internalNode, error) { + node := &internalNode{ + chain: chain, + moniker: fmt.Sprintf("%s-node-%s", chain.chainMeta.Id, nodeConfig.Name), + isValidator: nodeConfig.IsValidator, + } + // generate genesis files + if err := node.init(); err != nil { + return nil, err + } + // create keys + if err := node.createKey(ValidatorWalletName); err != nil { + return nil, err + } + if err := node.createNodeKey(); err != nil { + return nil, err + } + if err := node.createConsensusKey(); err != nil { + return nil, err + } + node.createAppConfig(nodeConfig) + return node, nil } -func (v *internalValidator) configDir() string { - return fmt.Sprintf("%s/%s", v.chain.chainMeta.configDir(), v.instanceName()) +func (n *internalNode) configDir() string { + return fmt.Sprintf("%s/%s", n.chain.chainMeta.configDir(), n.getMoniker()) } -func (v *internalValidator) getKeyInfo() keyring.Info { - return v.keyInfo +func (n *internalNode) getKeyInfo() keyring.Info { + return n.keyInfo } -func (v *internalValidator) getMoniker() string { - return v.moniker +func (n *internalNode) getMoniker() string { + return n.moniker } -func (v *internalValidator) buildCreateValidatorMsg(amount sdk.Coin) (sdk.Msg, error) { - description := stakingtypes.NewDescription(v.moniker, "", "", "", "") +func (n *internalNode) getMnemonic() string { + return n.mnemonic +} + +func (n *internalNode) buildCreateValidatorMsg(amount sdk.Coin) (sdk.Msg, error) { + description := stakingtypes.NewDescription(n.moniker, "", "", "", "") commissionRates := stakingtypes.CommissionRates{ Rate: sdk.MustNewDecFromStr("0.1"), MaxRate: sdk.MustNewDecFromStr("0.2"), @@ -68,13 +97,13 @@ func (v *internalValidator) buildCreateValidatorMsg(amount sdk.Coin) (sdk.Msg, e // get the initial validator min self delegation minSelfDelegation, _ := sdk.NewIntFromString("1") - valPubKey, err := cryptocodec.FromTmPubKeyInterface(v.consensusKey.PubKey) + valPubKey, err := cryptocodec.FromTmPubKeyInterface(n.consensusKey.PubKey) if err != nil { return nil, err } return stakingtypes.NewMsgCreateValidator( - sdk.ValAddress(v.keyInfo.GetAddress()), + sdk.ValAddress(n.keyInfo.GetAddress()), valPubKey, amount, description, @@ -83,33 +112,49 @@ func (v *internalValidator) buildCreateValidatorMsg(amount sdk.Coin) (sdk.Msg, e ) } -func (v *internalValidator) createConfig() error { - p := path.Join(v.configDir(), "config") +func (n *internalNode) createConfig() error { + p := path.Join(n.configDir(), "config") return os.MkdirAll(p, 0o755) } -func (v *internalValidator) createNodeKey() error { +func (n *internalNode) createAppConfig(nodeConfig *NodeConfig) { + // set application configuration + appCfgPath := filepath.Join(n.configDir(), "config", "app.toml") + + appConfig := srvconfig.DefaultConfig() + appConfig.BaseConfig.Pruning = nodeConfig.Pruning + appConfig.BaseConfig.PruningKeepRecent = nodeConfig.PruningKeepRecent + appConfig.BaseConfig.PruningInterval = nodeConfig.PruningInterval + appConfig.API.Enable = true + appConfig.MinGasPrices = fmt.Sprintf("%s%s", MinGasPrice, OsmoDenom) + appConfig.StateSync.SnapshotInterval = nodeConfig.SnapshotInterval + appConfig.StateSync.SnapshotKeepRecent = nodeConfig.SnapshotKeepRecent + + srvconfig.WriteConfigFile(appCfgPath, appConfig) +} + +func (n *internalNode) createNodeKey() error { serverCtx := server.NewDefaultContext() config := serverCtx.Config - config.SetRoot(v.configDir()) - config.Moniker = v.moniker + config.SetRoot(n.configDir()) + config.Moniker = n.moniker nodeKey, err := p2p.LoadOrGenNodeKey(config.NodeKeyFile()) if err != nil { return err } - v.nodeKey = *nodeKey + n.nodeKey = *nodeKey return nil } -func (v *internalValidator) createConsensusKey() error { +func (n *internalNode) createConsensusKey() error { serverCtx := server.NewDefaultContext() config := serverCtx.Config - config.SetRoot(v.configDir()) - config.Moniker = v.moniker + config.SetRoot(n.configDir()) + config.Moniker = n.moniker pvKeyFile := config.PrivValidatorKeyFile() if err := tmos.EnsureDir(filepath.Dir(pvKeyFile), 0o777); err != nil { @@ -122,13 +167,13 @@ func (v *internalValidator) createConsensusKey() error { } filePV := privval.LoadOrGenFilePV(pvKeyFile, pvStateFile) - v.consensusKey = filePV.Key + n.consensusKey = filePV.Key return nil } -func (v *internalValidator) createKeyFromMnemonic(name, mnemonic string) error { - kb, err := keyring.New(keyringAppName, keyring.BackendTest, v.configDir(), nil) +func (n *internalNode) createKeyFromMnemonic(name, mnemonic string) error { + kb, err := keyring.New(keyringAppName, keyring.BackendTest, n.configDir(), nil) if err != nil { return err } @@ -154,41 +199,42 @@ func (v *internalValidator) createKeyFromMnemonic(name, mnemonic string) error { return err } - v.keyInfo = info - v.mnemonic = mnemonic - v.privateKey = privKey + n.keyInfo = info + n.mnemonic = mnemonic + n.privateKey = privKey return nil } -func (v *internalValidator) createKey(name string) error { - mnemonic, err := createMnemonic() +func (n *internalNode) createKey(name string) error { + mnemonic, err := n.createMnemonic() if err != nil { return err } - return v.createKeyFromMnemonic(name, mnemonic) + return n.createKeyFromMnemonic(name, mnemonic) } -func (v *internalValidator) export() *Validator { - return &Validator{ - Name: v.instanceName(), - ConfigDir: v.configDir(), - Index: v.index, - Mnemonic: v.mnemonic, - PublicAddress: v.keyInfo.GetAddress().String(), - PublicKey: v.keyInfo.GetPubKey().Address().String(), +func (n *internalNode) export() *Node { + return &Node{ + Name: n.getMoniker(), + ConfigDir: n.configDir(), + Mnemonic: n.mnemonic, + PublicAddress: n.keyInfo.GetAddress().String(), + PublicKey: n.keyInfo.GetPubKey().Address().String(), + PeerId: n.peerId, + IsValidator: n.isValidator, } } -func (v *internalValidator) getNodeKey() *p2p.NodeKey { - return &v.nodeKey +func (n *internalNode) getNodeKey() *p2p.NodeKey { + return &n.nodeKey } -func (v *internalValidator) getGenesisDoc() (*tmtypes.GenesisDoc, error) { +func (n *internalNode) getGenesisDoc() (*tmtypes.GenesisDoc, error) { serverCtx := server.NewDefaultContext() config := serverCtx.Config - config.SetRoot(v.configDir()) + config.SetRoot(n.configDir()) genFile := config.GenesisFile() doc := &tmtypes.GenesisDoc{} @@ -209,18 +255,18 @@ func (v *internalValidator) getGenesisDoc() (*tmtypes.GenesisDoc, error) { return doc, nil } -func (v *internalValidator) init() error { - if err := v.createConfig(); err != nil { +func (n *internalNode) init() error { + if err := n.createConfig(); err != nil { return err } serverCtx := server.NewDefaultContext() config := serverCtx.Config - config.SetRoot(v.configDir()) - config.Moniker = v.moniker + config.SetRoot(n.configDir()) + config.Moniker = n.moniker - genDoc, err := v.getGenesisDoc() + genDoc, err := n.getGenesisDoc() if err != nil { return err } @@ -230,7 +276,7 @@ func (v *internalValidator) init() error { return fmt.Errorf("failed to JSON encode app genesis state: %w", err) } - genDoc.ChainID = v.chain.chainMeta.Id + genDoc.ChainID = n.chain.chainMeta.Id genDoc.Validators = nil genDoc.AppState = appState @@ -242,7 +288,7 @@ func (v *internalValidator) init() error { return nil } -func createMnemonic() (string, error) { +func (n *internalNode) createMnemonic() (string, error) { entropySeed, err := bip39.NewEntropy(256) if err != nil { return "", err @@ -256,22 +302,72 @@ func createMnemonic() (string, error) { return mnemonic, nil } +func (n *internalNode) initValidatorConfigs(c *internalChain, persistendtPeers []string) error { + tmCfgPath := filepath.Join(n.configDir(), "config", "config.toml") + + vpr := viper.New() + vpr.SetConfigFile(tmCfgPath) + if err := vpr.ReadInConfig(); err != nil { + return err + } + + valConfig := &tmconfig.Config{} + if err := vpr.Unmarshal(valConfig); err != nil { + return err + } + + valConfig.P2P.ListenAddress = "tcp://0.0.0.0:26656" + valConfig.P2P.AddrBookStrict = false + valConfig.P2P.ExternalAddress = fmt.Sprintf("%s:%d", n.getMoniker(), 26656) + valConfig.RPC.ListenAddress = "tcp://0.0.0.0:26657" + valConfig.StateSync.Enable = false + valConfig.LogLevel = "info" + valConfig.P2P.PersistentPeers = strings.Join(persistendtPeers, ",") + + tmconfig.WriteConfigFile(tmCfgPath, valConfig) + return nil +} + +func (n *internalNode) initStateSyncConfig(trustHeight int64, trustHash string, stateSyncRPCServers []string) error { + tmCfgPath := filepath.Join(n.configDir(), "config", "config.toml") + + vpr := viper.New() + vpr.SetConfigFile(tmCfgPath) + if err := vpr.ReadInConfig(); err != nil { + return err + } + + valConfig := &tmconfig.Config{} + if err := vpr.Unmarshal(valConfig); err != nil { + return err + } + + valConfig.StateSync = tmcfg.DefaultStateSyncConfig() + valConfig.StateSync.Enable = true + valConfig.StateSync.TrustHeight = trustHeight + valConfig.StateSync.TrustHash = trustHash + valConfig.StateSync.RPCServers = stateSyncRPCServers + + tmconfig.WriteConfigFile(tmCfgPath, valConfig) + return nil +} + // signMsg returns a signed tx of the provided messages, // signed by the validator, using 0 fees, a high gas limit, and a common memo. -func (v *internalValidator) signMsg(msgs ...sdk.Msg) (*sdktx.Tx, error) { +func (n *internalNode) signMsg(msgs ...sdk.Msg) (*sdktx.Tx, error) { txBuilder := util.EncodingConfig.TxConfig.NewTxBuilder() if err := txBuilder.SetMsgs(msgs...); err != nil { return nil, err } - txBuilder.SetMemo(fmt.Sprintf("%s@%s:26656", v.nodeKey.ID(), v.instanceName())) + txBuilder.SetMemo(fmt.Sprintf("%s@%s:26656", n.nodeKey.ID(), n.getMoniker())) txBuilder.SetFeeAmount(sdk.NewCoins()) txBuilder.SetGasLimit(uint64(200000 * len(msgs))) // TODO: Find a better way to sign this tx with less code. signerData := authsigning.SignerData{ - ChainID: v.chain.chainMeta.Id, + ChainID: n.chain.chainMeta.Id, AccountNumber: 0, Sequence: 0, } @@ -285,7 +381,7 @@ func (v *internalValidator) signMsg(msgs ...sdk.Msg) (*sdktx.Tx, error) { // also doesn't affect its generated sign bytes, so for code's simplicity // sake, we put it here. sig := txsigning.SignatureV2{ - PubKey: v.keyInfo.GetPubKey(), + PubKey: n.keyInfo.GetPubKey(), Data: &txsigning.SingleSignatureData{ SignMode: txsigning.SignMode_SIGN_MODE_DIRECT, Signature: nil, @@ -306,13 +402,13 @@ func (v *internalValidator) signMsg(msgs ...sdk.Msg) (*sdktx.Tx, error) { return nil, err } - sigBytes, err := v.privateKey.Sign(bytesToSign) + sigBytes, err := n.privateKey.Sign(bytesToSign) if err != nil { return nil, err } sig = txsigning.SignatureV2{ - PubKey: v.keyInfo.GetPubKey(), + PubKey: n.keyInfo.GetPubKey(), Data: &txsigning.SingleSignatureData{ SignMode: txsigning.SignMode_SIGN_MODE_DIRECT, Signature: sigBytes, diff --git a/tests/e2e/initialization/node/main.go b/tests/e2e/initialization/node/main.go new file mode 100644 index 00000000000..b8130c3d118 --- /dev/null +++ b/tests/e2e/initialization/node/main.go @@ -0,0 +1,66 @@ +package main + +import ( + "encoding/json" + "flag" + "os" + "strings" + "time" + + "github.com/osmosis-labs/osmosis/v7/tests/e2e/initialization" +) + +func main() { + var ( + nodeConfigStr string + + dataDir string + + existingGenesisDir string + + chainId string + + votingPeriod time.Duration + + stateSyncRPCServersStr string + + trustHeight int64 + + trustHash string + ) + + flag.StringVar(&dataDir, "data-dir", "", "chain data directory") + flag.StringVar(&existingGenesisDir, "genesis-dir", "", "pre-existing genesis location") + flag.StringVar(&chainId, "chain-id", "", "chain ID") + flag.StringVar(&nodeConfigStr, "node-config", "", "serialized node config") + flag.DurationVar(&votingPeriod, "voting-period", 30000000000, "voting period") + flag.StringVar(&stateSyncRPCServersStr, "rpc-servers", "", "state sync RPC servers") + flag.Int64Var(&trustHeight, "trust-height", 0, "trust Height") + flag.StringVar(&trustHash, "trust-hash", "", "trust hash") + + flag.Parse() + + if len(dataDir) == 0 { + panic("data-dir is required") + } + + var nodeConfig initialization.NodeConfig + err := json.Unmarshal([]byte(nodeConfigStr), &nodeConfig) + if err != nil { + panic(err) + } + + stateSyncRPCServers := strings.Split(stateSyncRPCServersStr, ",") + if len(stateSyncRPCServers) == 0 { + panic("rpc-servers is required, separated by commas") + } + + if err := os.MkdirAll(dataDir, 0o755); err != nil { + panic(err) + } + + _, err = initialization.InitSingleNode(chainId, dataDir, existingGenesisDir, &nodeConfig, votingPeriod, trustHeight, trustHash, stateSyncRPCServers) + if err != nil { + panic(err) + } +} From b2645a5508abaeeb035d632e0cf1dac0681a9441 Mon Sep 17 00:00:00 2001 From: Roman Date: Mon, 4 Jul 2022 17:14:22 -0400 Subject: [PATCH 2/5] lint and remove redundant getters from node --- tests/e2e/initialization/chain.go | 11 ----------- tests/e2e/initialization/config.go | 6 +++--- tests/e2e/initialization/init.go | 2 +- tests/e2e/initialization/node.go | 20 ++++---------------- 4 files changed, 8 insertions(+), 31 deletions(-) diff --git a/tests/e2e/initialization/chain.go b/tests/e2e/initialization/chain.go index c407e0ee042..690503b78a5 100644 --- a/tests/e2e/initialization/chain.go +++ b/tests/e2e/initialization/chain.go @@ -1,9 +1,5 @@ package initialization -import ( - "fmt" -) - const ( keyringPassphrase = "testpassphrase" keyringAppName = "testnet" @@ -26,13 +22,6 @@ func new(id, dataDir string) (*internalChain, error) { }, nil } -func (c *internalChain) createValidator(index int) *internalNode { - return &internalNode{ - chain: c, - moniker: fmt.Sprintf("%s-osmosis-%d", c.chainMeta.Id, index), - } -} - func (c *internalChain) export() *Chain { exportNodes := make([]*Node, 0, len(c.nodes)) for _, v := range c.nodes { diff --git a/tests/e2e/initialization/config.go b/tests/e2e/initialization/config.go index f6e0d35cf04..66644e3482a 100644 --- a/tests/e2e/initialization/config.go +++ b/tests/e2e/initialization/config.go @@ -171,11 +171,11 @@ func initGenesis(chain *internalChain, votingPeriod time.Duration, forkHeight in configDir := chain.nodes[0].configDir() for _, val := range chain.nodes { if chain.chainMeta.Id == ChainAID { - if err := addAccount(configDir, "", InitBalanceStrA, val.getKeyInfo().GetAddress(), forkHeight); err != nil { + if err := addAccount(configDir, "", InitBalanceStrA, val.keyInfo.GetAddress(), forkHeight); err != nil { return err } } else if chain.chainMeta.Id == ChainBID { - if err := addAccount(configDir, "", InitBalanceStrB, val.getKeyInfo().GetAddress(), forkHeight); err != nil { + if err := addAccount(configDir, "", InitBalanceStrB, val.keyInfo.GetAddress(), forkHeight); err != nil { return err } } @@ -196,7 +196,7 @@ func initGenesis(chain *internalChain, votingPeriod time.Duration, forkHeight in config := serverCtx.Config config.SetRoot(chain.nodes[0].configDir()) - config.Moniker = chain.nodes[0].getMoniker() + config.Moniker = chain.nodes[0].moniker genFilePath := config.GenesisFile() appGenState, genDoc, err := genutiltypes.GenesisStateFromGenFile(genFilePath) diff --git a/tests/e2e/initialization/init.go b/tests/e2e/initialization/init.go index d0b4f1ff948..c8e5f2c7048 100644 --- a/tests/e2e/initialization/init.go +++ b/tests/e2e/initialization/init.go @@ -29,7 +29,7 @@ func Init(id, dataDir string, nodeConfigs []*NodeConfig, votingPeriod time.Durat var peers []string for _, peer := range chain.nodes { - peerID := fmt.Sprintf("%s@%s:26656", peer.getNodeKey().ID(), peer.getMoniker()) + peerID := fmt.Sprintf("%s@%s:26656", peer.getNodeKey().ID(), peer.moniker) peer.peerId = peerID peers = append(peers, peerID) } diff --git a/tests/e2e/initialization/node.go b/tests/e2e/initialization/node.go index 9c9c7dd0553..f0db9409691 100644 --- a/tests/e2e/initialization/node.go +++ b/tests/e2e/initialization/node.go @@ -71,19 +71,7 @@ func newNode(chain *internalChain, nodeConfig *NodeConfig) (*internalNode, error } func (n *internalNode) configDir() string { - return fmt.Sprintf("%s/%s", n.chain.chainMeta.configDir(), n.getMoniker()) -} - -func (n *internalNode) getKeyInfo() keyring.Info { - return n.keyInfo -} - -func (n *internalNode) getMoniker() string { - return n.moniker -} - -func (n *internalNode) getMnemonic() string { - return n.mnemonic + return fmt.Sprintf("%s/%s", n.chain.chainMeta.configDir(), n.moniker) } func (n *internalNode) buildCreateValidatorMsg(amount sdk.Coin) (sdk.Msg, error) { @@ -217,7 +205,7 @@ func (n *internalNode) createKey(name string) error { func (n *internalNode) export() *Node { return &Node{ - Name: n.getMoniker(), + Name: n.moniker, ConfigDir: n.configDir(), Mnemonic: n.mnemonic, PublicAddress: n.keyInfo.GetAddress().String(), @@ -318,7 +306,7 @@ func (n *internalNode) initValidatorConfigs(c *internalChain, persistendtPeers [ valConfig.P2P.ListenAddress = "tcp://0.0.0.0:26656" valConfig.P2P.AddrBookStrict = false - valConfig.P2P.ExternalAddress = fmt.Sprintf("%s:%d", n.getMoniker(), 26656) + valConfig.P2P.ExternalAddress = fmt.Sprintf("%s:%d", n.moniker, 26656) valConfig.RPC.ListenAddress = "tcp://0.0.0.0:26657" valConfig.StateSync.Enable = false valConfig.LogLevel = "info" @@ -361,7 +349,7 @@ func (n *internalNode) signMsg(msgs ...sdk.Msg) (*sdktx.Tx, error) { return nil, err } - txBuilder.SetMemo(fmt.Sprintf("%s@%s:26656", n.nodeKey.ID(), n.getMoniker())) + txBuilder.SetMemo(fmt.Sprintf("%s@%s:26656", n.nodeKey.ID(), n.moniker)) txBuilder.SetFeeAmount(sdk.NewCoins()) txBuilder.SetGasLimit(uint64(200000 * len(msgs))) From 8492e62d83c0c08a455b2f71e57c0261127db159 Mon Sep 17 00:00:00 2001 From: Roman Date: Mon, 4 Jul 2022 17:17:14 -0400 Subject: [PATCH 3/5] restore accidental change --- cmd/osmosisd/cmd/balances_from_state_export.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cmd/osmosisd/cmd/balances_from_state_export.go b/cmd/osmosisd/cmd/balances_from_state_export.go index 69b36e19875..9c3ff42af77 100644 --- a/cmd/osmosisd/cmd/balances_from_state_export.go +++ b/cmd/osmosisd/cmd/balances_from_state_export.go @@ -19,6 +19,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/server" sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -176,6 +177,14 @@ Example: } } + authGenesis := authtypes.GenesisState{} + clientCtx.Codec.MustUnmarshalJSON(genState["auth"], &authGenesis) + accounts, err := authtypes.UnpackAccounts(authGenesis.Accounts) + if err != nil { + panic(err) + } + accounts = authtypes.SanitizeGenesisAccounts(accounts) + // Produce the map of address to total atom balance, both staked and UnbondingStake snapshotAccs := make(map[string]DerivedAccount) From 75091b250a44cd32891b23fa8988de20bc982ae3 Mon Sep 17 00:00:00 2001 From: Roman Date: Mon, 4 Jul 2022 17:19:44 -0400 Subject: [PATCH 4/5] rename init to InitChain --- tests/e2e/e2e_setup_test.go | 2 +- tests/e2e/initialization/chain/main.go | 2 +- tests/e2e/initialization/init.go | 2 +- tests/e2e/initialization/init_test.go | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/e2e/e2e_setup_test.go b/tests/e2e/e2e_setup_test.go index dbfd847d5e4..6d3a7f1dd1f 100644 --- a/tests/e2e/e2e_setup_test.go +++ b/tests/e2e/e2e_setup_test.go @@ -398,7 +398,7 @@ func (s *IntegrationTestSuite) configureChain(chainId string, validatorConfigs [ // via Docker. if s.skipUpgrade { - initializedChain, err := initialization.Init(chainId, tmpDir, validatorConfigs, time.Duration(newChainConfig.votingPeriod), s.forkHeight) + initializedChain, err := initialization.InitChain(chainId, tmpDir, validatorConfigs, time.Duration(newChainConfig.votingPeriod), s.forkHeight) s.Require().NoError(err) s.initializeChainConfig(&newChainConfig, initializedChain) return diff --git a/tests/e2e/initialization/chain/main.go b/tests/e2e/initialization/chain/main.go index 429818fa5e5..3c12471224f 100644 --- a/tests/e2e/initialization/chain/main.go +++ b/tests/e2e/initialization/chain/main.go @@ -41,7 +41,7 @@ func main() { panic(err) } - createdChain, err := initialization.Init(chainId, dataDir, valConfig, votingPeriod, forkHeight) + createdChain, err := initialization.InitChain(chainId, dataDir, valConfig, votingPeriod, forkHeight) if err != nil { panic(err) } diff --git a/tests/e2e/initialization/init.go b/tests/e2e/initialization/init.go index c8e5f2c7048..df03c842731 100644 --- a/tests/e2e/initialization/init.go +++ b/tests/e2e/initialization/init.go @@ -9,7 +9,7 @@ import ( "github.com/osmosis-labs/osmosis/v7/tests/e2e/util" ) -func Init(id, dataDir string, nodeConfigs []*NodeConfig, votingPeriod time.Duration, forkHeight int) (*Chain, error) { +func InitChain(id, dataDir string, nodeConfigs []*NodeConfig, votingPeriod time.Duration, forkHeight int) (*Chain, error) { chain, err := new(id, dataDir) if err != nil { return nil, err diff --git a/tests/e2e/initialization/init_test.go b/tests/e2e/initialization/init_test.go index c3155b86ced..fff036b42c4 100644 --- a/tests/e2e/initialization/init_test.go +++ b/tests/e2e/initialization/init_test.go @@ -51,7 +51,7 @@ func TestChainInit(t *testing.T) { dataDir, err = ioutil.TempDir("", "osmosis-e2e-testnet-test") ) - chain, err := initialization.Init(id, dataDir, nodeConfigs, time.Second*3, forkHeight) + chain, err := initialization.InitChain(id, dataDir, nodeConfigs, time.Second*3, forkHeight) require.NoError(t, err) require.Equal(t, chain.ChainMeta.DataDir, dataDir) @@ -109,7 +109,7 @@ func TestSingleNodeInit(t *testing.T) { ) // Setup - existingChain, err := initialization.Init(id, dataDir, existingChainNodeConfigs, time.Second*3, forkHeight) + existingChain, err := initialization.InitChain(id, dataDir, existingChainNodeConfigs, time.Second*3, forkHeight) require.NoError(t, err) actualNode, err := initialization.InitSingleNode(existingChain.ChainMeta.Id, dataDir, filepath.Join(existingChain.Nodes[0].ConfigDir, "config", "genesis.json"), expectedConfig, time.Second*3, 3, "testHash", []string{"some server"}) From d6a8b487b68e9c92f69fc7b9248eb51c2f2adc90 Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 5 Jul 2022 15:27:01 -0400 Subject: [PATCH 5/5] persistentPeers typo --- tests/e2e/initialization/node.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/e2e/initialization/node.go b/tests/e2e/initialization/node.go index f0db9409691..5513d270aae 100644 --- a/tests/e2e/initialization/node.go +++ b/tests/e2e/initialization/node.go @@ -290,7 +290,7 @@ func (n *internalNode) createMnemonic() (string, error) { return mnemonic, nil } -func (n *internalNode) initValidatorConfigs(c *internalChain, persistendtPeers []string) error { +func (n *internalNode) initValidatorConfigs(c *internalChain, persistentPeers []string) error { tmCfgPath := filepath.Join(n.configDir(), "config", "config.toml") vpr := viper.New() @@ -310,7 +310,7 @@ func (n *internalNode) initValidatorConfigs(c *internalChain, persistendtPeers [ valConfig.RPC.ListenAddress = "tcp://0.0.0.0:26657" valConfig.StateSync.Enable = false valConfig.LogLevel = "info" - valConfig.P2P.PersistentPeers = strings.Join(persistendtPeers, ",") + valConfig.P2P.PersistentPeers = strings.Join(persistentPeers, ",") tmconfig.WriteConfigFile(tmCfgPath, valConfig) return nil