Skip to content
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

Pass through an AppIniter func to be able to launch chains with different apps #1

Merged
merged 3 commits into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions testing/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ import (
"github.com/cosmos/ibc-go/v3/testing/simapp"
)

var DefaultTestingAppInit func() (TestingApp, map[string]json.RawMessage) = SetupTestingApp
type AppIniter func() (TestingApp, map[string]json.RawMessage)

var DefaultTestingAppInit AppIniter = SetupTestingApp

type TestingApp interface {
abci.Application
Expand Down Expand Up @@ -58,8 +60,8 @@ func SetupTestingApp() (TestingApp, map[string]json.RawMessage) {
// that also act as delegators. For simplicity, each validator is bonded with a delegation
// of one consensus engine unit (10^6) in the default token of the simapp from first genesis
// account. A Nop logger is set in SimApp.
func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, chainID string, powerReduction sdk.Int, balances ...banktypes.Balance) TestingApp {
app, genesisState := DefaultTestingAppInit()
func SetupWithGenesisValSet(t *testing.T, appIniter AppIniter, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, chainID string, powerReduction sdk.Int, balances ...banktypes.Balance) TestingApp {
app, genesisState := appIniter()

// set genesis accounts
authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs)
Expand Down
8 changes: 4 additions & 4 deletions testing/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ type TestChain struct {
//
// CONTRACT: Validator array must be provided in the order expected by Tendermint.
// i.e. sorted first by power and then lexicographically by address.
func NewTestChainWithValSet(t *testing.T, coord *Coordinator, chainID string, valSet *tmtypes.ValidatorSet, signers map[string]tmtypes.PrivValidator) *TestChain {
func NewTestChainWithValSet(t *testing.T, coord *Coordinator, appIniter AppIniter, chainID string, valSet *tmtypes.ValidatorSet, signers map[string]tmtypes.PrivValidator) *TestChain {
genAccs := []authtypes.GenesisAccount{}
genBals := []banktypes.Balance{}
senderAccs := []SenderAccount{}
Expand Down Expand Up @@ -119,7 +119,7 @@ func NewTestChainWithValSet(t *testing.T, coord *Coordinator, chainID string, va
senderAccs = append(senderAccs, senderAcc)
}

app := SetupWithGenesisValSet(t, valSet, genAccs, chainID, sdk.DefaultPowerReduction, genBals...)
app := SetupWithGenesisValSet(t, appIniter, valSet, genAccs, chainID, sdk.DefaultPowerReduction, genBals...)

// create current header and call begin block
header := tmproto.Header{
Expand Down Expand Up @@ -155,7 +155,7 @@ func NewTestChainWithValSet(t *testing.T, coord *Coordinator, chainID string, va

// NewTestChain initializes a new test chain with a default of 4 validators
// Use this function if the tests do not need custom control over the validator set
func NewTestChain(t *testing.T, coord *Coordinator, chainID string) *TestChain {
func NewTestChain(t *testing.T, coord *Coordinator, appIniter AppIniter, chainID string) *TestChain {
// generate validators private/public key
var (
validatorsPerChain = 4
Expand All @@ -176,7 +176,7 @@ func NewTestChain(t *testing.T, coord *Coordinator, chainID string) *TestChain {
// or, if equal, by address lexical order
valSet := tmtypes.NewValidatorSet(validators)

return NewTestChainWithValSet(t, coord, chainID, valSet, signersByAddress)
return NewTestChainWithValSet(t, coord, appIniter, chainID, valSet, signersByAddress)
}

// GetContext returns the current context for the application.
Expand Down
6 changes: 3 additions & 3 deletions testing/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

var (
ChainIDPrefix = "testchain"
globalStartTime = time.Date(2020, 1, 2, 0, 0, 0, 0, time.UTC)
GlobalStartTime = time.Date(2020, 1, 2, 0, 0, 0, 0, time.UTC)
TimeIncrement = time.Second * 5
)

Expand All @@ -30,12 +30,12 @@ func NewCoordinator(t *testing.T, n int) *Coordinator {
chains := make(map[string]*TestChain)
coord := &Coordinator{
T: t,
CurrentTime: globalStartTime,
CurrentTime: GlobalStartTime,
}

for i := 1; i <= n; i++ {
chainID := GetChainID(i)
chains[chainID] = NewTestChain(t, coord, chainID)
chains[chainID] = NewTestChain(t, coord, DefaultTestingAppInit, chainID)
}
coord.Chains = chains

Expand Down