Skip to content

Commit

Permalink
test: add init changes to v8.x (#1518)
Browse files Browse the repository at this point in the history
* add init changed to v8.x

* fix error

* upgrade to v8 init

* add start to dockerfile
  • Loading branch information
czarcas7ic authored May 16, 2022
1 parent f3a64c4 commit f3e2f2e
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 24 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ EXPOSE 26656
EXPOSE 26657
EXPOSE 1317

ENTRYPOINT ["osmosisd"]
ENTRYPOINT ["osmosisd"]
CMD [ "start" ]
43 changes: 38 additions & 5 deletions tests/e2e/chain/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"path/filepath"
"strings"
"time"

"github.com/cosmos/cosmos-sdk/server"
srvconfig "github.com/cosmos/cosmos-sdk/server/config"
Expand All @@ -13,18 +14,28 @@ import (
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/spf13/viper"
tmconfig "github.com/tendermint/tendermint/config"
tmjson "github.com/tendermint/tendermint/libs/json"

"github.com/osmosis-labs/osmosis/v8/tests/e2e/util"
)

type ValidatorConfig struct {
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)
}

const (
// common
OsmoDenom = "uosmo"
StakeDenom = "stake"
IbcDenom = "ibc/ED07A3391A112B175915CD8FAF43A2DA8E4790EDE12566649D0C2F97716B8518"
OsmoIBCDenom = "ibc/ED07A3391A112B175915CD8FAF43A2DA8E4790EDE12566649D0C2F97716B8518"
StakeIBCDenom = "ibc/C053D637CCA2A2BA030E2C5EE1B28A16F71CCB0E45E8BE52766DC1B241B7787"
MinGasPrice = "0.000"
IbcSendAmount = 3300000000
// chainA
Expand All @@ -47,6 +58,8 @@ var (

InitBalanceStrA = fmt.Sprintf("%d%s,%d%s", OsmoBalanceA, OsmoDenom, StakeBalanceA, StakeDenom)
InitBalanceStrB = fmt.Sprintf("%d%s,%d%s", OsmoBalanceB, OsmoDenom, StakeBalanceB, StakeDenom)
OsmoToken = sdk.NewInt64Coin(OsmoDenom, IbcSendAmount) // 3,300uosmo
StakeToken = sdk.NewInt64Coin(StakeDenom, IbcSendAmount) // 3,300ustake
)

func addAccount(path, moniker, amountStr string, accAddr sdk.AccAddress) error {
Expand Down Expand Up @@ -120,7 +133,7 @@ func addAccount(path, moniker, amountStr string, accAddr sdk.AccAddress) error {
return genutil.ExportGenesisFile(genDoc, genFile)
}

func initGenesis(c *internalChain) error {
func initGenesis(c *internalChain, votingPeriod time.Duration) error {
serverCtx := server.NewDefaultContext()
config := serverCtx.Config

Expand Down Expand Up @@ -158,6 +171,21 @@ func initGenesis(c *internalChain) error {
}
appGenState[banktypes.ModuleName] = bz

var govGenState govtypes.GenesisState
if err := util.Cdc.UnmarshalJSON(appGenState[govtypes.ModuleName], &govGenState); err != nil {
return err
}

govGenState.VotingParams = govtypes.VotingParams{
VotingPeriod: votingPeriod,
}

gz, err := util.Cdc.MarshalJSON(&govGenState)
if err != nil {
return err
}
appGenState[govtypes.ModuleName] = gz

var genUtilGenState genutiltypes.GenesisState
if err := util.Cdc.UnmarshalJSON(appGenState[genutiltypes.ModuleName], &genUtilGenState); err != nil {
return err
Expand Down Expand Up @@ -217,8 +245,8 @@ func initGenesis(c *internalChain) error {
return nil
}

func initNodes(c *internalChain) error {
if err := c.createAndInitValidators(2); err != nil {
func initNodes(c *internalChain, numVal int) error {
if err := c.createAndInitValidators(numVal); err != nil {
return err
}

Expand Down Expand Up @@ -249,7 +277,7 @@ func initNodes(c *internalChain) error {
return nil
}

func initValidatorConfigs(c *internalChain) error {
func initValidatorConfigs(c *internalChain, validatorConfigs []*ValidatorConfig) error {
for i, val := range c.validators {
tmCfgPath := filepath.Join(val.configDir(), "config", "config.toml")

Expand Down Expand Up @@ -291,8 +319,13 @@ func initValidatorConfigs(c *internalChain) error {
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)
}
Expand Down
10 changes: 6 additions & 4 deletions tests/e2e/chain/main.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package chain

func Init(id, dataDir string) (*Chain, error) {
import "time"

func Init(id, dataDir string, validatorConfigs []*ValidatorConfig, votingPeriod time.Duration) (*Chain, error) {
chain, err := new(id, dataDir)
if err != nil {
return nil, err
}
if err := initNodes(chain); err != nil {
if err := initNodes(chain, len(validatorConfigs)); err != nil {
return nil, err
}
if err := initGenesis(chain); err != nil {
if err := initGenesis(chain, votingPeriod); err != nil {
return nil, err
}
if err := initValidatorConfigs(chain); err != nil {
if err := initValidatorConfigs(chain, validatorConfigs); err != nil {
return nil, err
}
return chain.export(), nil
Expand Down
20 changes: 16 additions & 4 deletions tests/e2e/chain_init/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,32 @@ import (
"flag"
"fmt"
"os"
"time"

"github.com/osmosis-labs/osmosis/v8/tests/e2e/chain"
)

func main() {
var (
dataDir string
chainId string
valConfig []*chain.ValidatorConfig
dataDir string
chainId string
config string
votingPeriod time.Duration
)

flag.StringVar(&dataDir, "data-dir", "", "chain data directory")
flag.StringVar(&chainId, "chain-id", "", "chain ID")
flag.StringVar(&config, "config", "", "serialized config")
flag.DurationVar(&votingPeriod, "voting-period", 30000000000, "voting period")

flag.Parse()

err := json.Unmarshal([]byte(config), &valConfig)
if err != nil {
panic(err)
}

if len(dataDir) == 0 {
panic("data-dir is required")
}
Expand All @@ -27,14 +39,14 @@ func main() {
panic(err)
}

createdChain, err := chain.Init(chainId, dataDir)
createdChain, err := chain.Init(chainId, dataDir, valConfig, votingPeriod)
if err != nil {
panic(err)
}

b, _ := json.Marshal(createdChain)
fileName := fmt.Sprintf("%v/%v-encode", dataDir, chainId)
if err = os.WriteFile(fileName, b, 0777); err != nil {
if err = os.WriteFile(fileName, b, 0o777); err != nil {
panic(err)
}
}
100 changes: 91 additions & 9 deletions tests/e2e/e2e_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,75 @@ import (
"github.com/osmosis-labs/osmosis/v8/tests/e2e/util"
)

const maxRetries = 10 // max retries for json unmarshalling
var (
// voting period for chain A
votingPeriodA float32
// voting period for chain B
votingPeriodB float32
// estimated number of blocks it takes to submit for a proposal
propSubmitBlocks float32 = 10
// estimated number of blocks it takes to deposit for a proposal
propDepositBlocks float32 = 10
// number of blocks it takes to vote for a single validator to vote for a proposal
propVoteBlocks float32 = 1.2
// number of blocks used as a calculation buffer
propBufferBlocks float32 = 5
// variable used to switch between chain A and B prop height in for loop
propHeight int
// upgrade proposal height for chain A
propHeightA int
// upgrade proposal height for chain B
propHeightB int
// max retries for json unmarshalling
maxRetries = 60
// whatever number of validator configs get posted here are how many validators that will spawn on chain A and B respectively
validatorConfigsChainA = []*chain.ValidatorConfig{
{
Pruning: "default",
PruningKeepRecent: "0",
PruningInterval: "0",
SnapshotInterval: 1500,
SnapshotKeepRecent: 2,
},
{
Pruning: "nothing",
PruningKeepRecent: "0",
PruningInterval: "0",
SnapshotInterval: 1500,
SnapshotKeepRecent: 2,
},
{
Pruning: "custom",
PruningKeepRecent: "10000",
PruningInterval: "13",
SnapshotInterval: 1500,
SnapshotKeepRecent: 2,
},
}
validatorConfigsChainB = []*chain.ValidatorConfig{
{
Pruning: "default",
PruningKeepRecent: "0",
PruningInterval: "0",
SnapshotInterval: 1500,
SnapshotKeepRecent: 2,
},
{
Pruning: "nothing",
PruningKeepRecent: "0",
PruningInterval: "0",
SnapshotInterval: 1500,
SnapshotKeepRecent: 2,
},
{
Pruning: "custom",
PruningKeepRecent: "10000",
PruningInterval: "13",
SnapshotInterval: 1500,
SnapshotKeepRecent: 2,
},
}
)

type IntegrationTestSuite struct {
suite.Suite
Expand Down Expand Up @@ -57,10 +125,8 @@ func (s *IntegrationTestSuite) SetupSuite() {
// 4. Execute various e2e tests, including IBC.
s.configureDockerResources(chain.ChainAID, chain.ChainBID)

s.configureChain(chain.ChainAID)
s.Require().NoError(s.dkrPool.Purge(s.initResource))
s.configureChain(chain.ChainBID)
s.Require().NoError(s.dkrPool.Purge(s.initResource))
s.configureChain(chain.ChainAID, validatorConfigsChainA)
s.configureChain(chain.ChainBID, validatorConfigsChainB)

s.runValidators(s.chains[0], 0)
s.runValidators(s.chains[1], 10)
Expand Down Expand Up @@ -257,22 +323,38 @@ func (s *IntegrationTestSuite) runIBCRelayer() {
s.connectIBCChains()
}

func (s *IntegrationTestSuite) configureChain(chainId string) {
func (s *IntegrationTestSuite) configureChain(chainId string, validatorConfigs []*chain.ValidatorConfig) {

s.T().Logf("starting e2e infrastructure for chain-id: %s", chainId)
tmpDir, err := ioutil.TempDir("", "osmosis-e2e-testnet-")

s.T().Logf("temp directory for chain-id %v: %v", chainId, tmpDir)
s.Require().NoError(err)

b, err := json.Marshal(validatorConfigs)
s.Require().NoError(err)

numVal := float32(len(validatorConfigs))
// voting period is number of blocks it takes to deposit, 1.2 seconds per validator to vote on the prop, then a buffer
votingPeriodNum := propDepositBlocks + numVal*propVoteBlocks + propBufferBlocks
if chainId == chain.ChainAID {
votingPeriodA = votingPeriodNum
} else if chainId == chain.ChainBID {
votingPeriodB = votingPeriodNum
}
votingPeriod := time.Duration(int(votingPeriodNum) * 1000000000)

s.initResource, err = s.dkrPool.RunWithOptions(
&dockertest.RunOptions{
Name: fmt.Sprintf("%s", chainId),
Repository: "osmosis-e2e-chain-init",
Tag: "debug",
Repository: "osmolabs/osmosis-init",
Tag: "v8.0.0",
NetworkID: s.dkrNet.Network.ID,
Cmd: []string{
fmt.Sprintf("--data-dir=%s", tmpDir),
fmt.Sprintf("--chain-id=%s", chainId),
fmt.Sprintf("--config=%s", b),
fmt.Sprintf("--voting-period=%v", votingPeriod),
},
User: "root:root",
Mounts: []string{
Expand Down Expand Up @@ -306,7 +388,7 @@ func (s *IntegrationTestSuite) configureChain(chainId string) {
}
}
s.chains = append(s.chains, &newChain)

s.Require().NoError(s.dkrPool.Purge(s.initResource))
}

func (s *IntegrationTestSuite) configureDockerResources(chainIDOne, chainIDTwo string) {
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
func (s *IntegrationTestSuite) TestQueryBalances() {
var (
expectedDenomsA = []string{chain.OsmoDenom, chain.StakeDenom}
expectedDenomsB = []string{chain.OsmoDenom, chain.StakeDenom, chain.IbcDenom}
expectedDenomsB = []string{chain.OsmoDenom, chain.StakeDenom, chain.OsmoIBCDenom}
expectedBalancesA = []uint64{chain.OsmoBalanceA - chain.IbcSendAmount, chain.StakeBalanceA - chain.StakeAmountA}
expectedBalancesB = []uint64{chain.OsmoBalanceB, chain.StakeBalanceB - chain.StakeAmountB, chain.IbcSendAmount}
)
Expand Down

0 comments on commit f3e2f2e

Please sign in to comment.