Skip to content

Commit

Permalink
Merge pull request #1 from informalsystems/danwt/support-different-ap…
Browse files Browse the repository at this point in the history
…p.go

Pass through an AppIniter func to be able to launch chains with different apps
  • Loading branch information
sainoe authored May 5, 2022
2 parents 988da45 + d6b3f32 commit 1f45da8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
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

0 comments on commit 1f45da8

Please sign in to comment.