Skip to content

Commit

Permalink
Merge branch 'main' into faddat/gitpod
Browse files Browse the repository at this point in the history
  • Loading branch information
faddat authored May 7, 2022
2 parents 64f6ed1 + 56a30f5 commit b847219
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 50 deletions.
19 changes: 16 additions & 3 deletions tests/e2e/chain/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ import (
"github.com/osmosis-labs/osmosis/v7/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"
Expand Down Expand Up @@ -234,8 +242,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 @@ -266,7 +274,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 @@ -308,8 +316,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
6 changes: 3 additions & 3 deletions tests/e2e/chain/main.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package chain

func Init(id, dataDir string) (*Chain, error) {
func Init(id, dataDir string, validatorConfigs []*ValidatorConfig) (*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 {
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
15 changes: 12 additions & 3 deletions tests/e2e/chain_init/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,23 @@ import (

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

flag.StringVar(&dataDir, "data-dir", "", "chain data directory")
flag.StringVar(&chainId, "chain-id", "", "chain ID")
flag.StringVar(&config, "config", "", "serialized config")

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,7 +36,7 @@ func main() {
panic(err)
}

createdChain, err := chain.Init(chainId, dataDir)
createdChain, err := chain.Init(chainId, dataDir, valConfig)
if err != nil {
panic(err)
}
Expand Down
64 changes: 59 additions & 5 deletions tests/e2e/e2e_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,56 @@ import (
"github.com/osmosis-labs/osmosis/v7/tests/e2e/util"
)

const maxRetries = 10 // max retries for json unmarshalling
var (
// common
maxRetries = 10 // max retries for json unmarshalling
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 @@ -65,8 +114,8 @@ func (s *IntegrationTestSuite) SetupSuite() {
// 4. Execute various e2e tests, including IBC.
s.configureDockerResources(chain.ChainAID, chain.ChainBID)

s.configureChain(chain.ChainAID)
s.configureChain(chain.ChainBID)
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 @@ -267,22 +316,27 @@ 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)

s.initResource, err = s.dkrPool.RunWithOptions(
&dockertest.RunOptions{
Name: fmt.Sprintf("%s", chainId),
Repository: "osmolabs/osmosis-init",
Tag: "v7.2.1",
Tag: "v7.3.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),
},
User: "root:root",
Mounts: []string{
Expand Down
73 changes: 37 additions & 36 deletions tests/e2e/e2e_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,42 +200,43 @@ func (s *IntegrationTestSuite) voteProposal(c *chain.Chain) {
defer cancel()

s.T().Logf("voting for upgrade proposal for chain-id: %s", c.ChainMeta.Id)
exec, err := s.dkrPool.Client.CreateExec(docker.CreateExecOptions{
Context: ctx,
AttachStdout: true,
AttachStderr: true,
Container: s.valResources[c.ChainMeta.Id][0].Container.ID,
User: "root",
Cmd: []string{
"osmosisd", "tx", "gov", "vote", "1", "yes", "--from=val", fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "-b=block", "--yes", "--keyring-backend=test",
},
})
s.Require().NoError(err)

var (
outBuf bytes.Buffer
errBuf bytes.Buffer
)

err = s.dkrPool.Client.StartExec(exec.ID, docker.StartExecOptions{
Context: ctx,
Detach: false,
OutputStream: &outBuf,
ErrorStream: &errBuf,
})

s.Require().NoErrorf(
err,
"failed to vote for proposal; stdout: %s, stderr: %s", outBuf.String(), errBuf.String(),
)

s.Require().Truef(
strings.Contains(outBuf.String(), "code: 0"),
"tx returned non code 0",
)

s.T().Log("successfully voted for proposal")

for i := range c.Validators {
exec, err := s.dkrPool.Client.CreateExec(docker.CreateExecOptions{
Context: ctx,
AttachStdout: true,
AttachStderr: true,
Container: s.valResources[c.ChainMeta.Id][i].Container.ID,
User: "root",
Cmd: []string{
"osmosisd", "tx", "gov", "vote", "1", "yes", "--from=val", fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "-b=block", "--yes", "--keyring-backend=test",
},
})
s.Require().NoError(err)

var (
outBuf bytes.Buffer
errBuf bytes.Buffer
)

err = s.dkrPool.Client.StartExec(exec.ID, docker.StartExecOptions{
Context: ctx,
Detach: false,
OutputStream: &outBuf,
ErrorStream: &errBuf,
})

s.Require().NoErrorf(
err,
"failed to vote for proposal; stdout: %s, stderr: %s", outBuf.String(), errBuf.String(),
)

s.Require().Truef(
strings.Contains(outBuf.String(), "code: 0"),
"tx returned non code 0",
)

s.T().Logf("successfully voted for proposal on container: %s", s.valResources[c.ChainMeta.Id][i].Container.ID)
}
}

func (s *IntegrationTestSuite) chainStatus(containerId string) []byte {
Expand Down

0 comments on commit b847219

Please sign in to comment.