2020-04-01 18:49:21 +00:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
2021-04-17 10:00:07 +00:00
|
|
|
"encoding/json"
|
|
|
|
"time"
|
|
|
|
|
2022-04-05 07:09:27 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
|
2021-04-17 10:00:07 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/simapp"
|
2021-06-22 10:49:18 +00:00
|
|
|
"github.com/tharsis/ethermint/encoding"
|
2021-04-17 10:00:07 +00:00
|
|
|
|
2020-04-01 18:49:21 +00:00
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
2022-04-05 07:09:27 +00:00
|
|
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
2020-04-01 18:49:21 +00:00
|
|
|
"github.com/tendermint/tendermint/libs/log"
|
2021-04-17 10:00:07 +00:00
|
|
|
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
|
|
|
tmtypes "github.com/tendermint/tendermint/types"
|
2020-04-01 18:49:21 +00:00
|
|
|
dbm "github.com/tendermint/tm-db"
|
|
|
|
)
|
|
|
|
|
2021-04-17 10:00:07 +00:00
|
|
|
// DefaultConsensusParams defines the default Tendermint consensus params used in
|
|
|
|
// EthermintApp testing.
|
|
|
|
var DefaultConsensusParams = &abci.ConsensusParams{
|
|
|
|
Block: &abci.BlockParams{
|
|
|
|
MaxBytes: 200000,
|
|
|
|
MaxGas: -1, // no limit
|
|
|
|
},
|
|
|
|
Evidence: &tmproto.EvidenceParams{
|
|
|
|
MaxAgeNumBlocks: 302400,
|
|
|
|
MaxAgeDuration: 504 * time.Hour, // 3 weeks is the max duration
|
|
|
|
MaxBytes: 10000,
|
|
|
|
},
|
|
|
|
Validator: &tmproto.ValidatorParams{
|
|
|
|
PubKeyTypes: []string{
|
|
|
|
tmtypes.ABCIPubKeyTypeEd25519,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-04-01 18:49:21 +00:00
|
|
|
// Setup initializes a new EthermintApp. A Nop logger is set in EthermintApp.
|
2021-12-28 07:59:28 +00:00
|
|
|
func Setup(isCheckTx bool, patchGenesis func(*EthermintApp, simapp.GenesisState) simapp.GenesisState) *EthermintApp {
|
2020-04-01 18:49:21 +00:00
|
|
|
db := dbm.NewMemDB()
|
2021-06-04 13:14:45 +00:00
|
|
|
app := NewEthermintApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5, encoding.MakeConfig(ModuleBasics), simapp.EmptyAppOptions{})
|
2020-04-01 18:49:21 +00:00
|
|
|
if !isCheckTx {
|
|
|
|
// init chain must be called to stop deliverState from being nil
|
2020-04-17 22:32:01 +00:00
|
|
|
genesisState := NewDefaultGenesisState()
|
2021-12-28 07:59:28 +00:00
|
|
|
if patchGenesis != nil {
|
|
|
|
genesisState = patchGenesis(app, genesisState)
|
2021-10-19 08:49:29 +00:00
|
|
|
}
|
|
|
|
|
2021-04-17 10:00:07 +00:00
|
|
|
stateBytes, err := json.MarshalIndent(genesisState, "", " ")
|
2020-04-01 18:49:21 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize the chain
|
|
|
|
app.InitChain(
|
|
|
|
abci.RequestInitChain{
|
2021-08-17 14:11:26 +00:00
|
|
|
ChainId: "ethermint_9000-1",
|
2021-04-17 10:00:07 +00:00
|
|
|
Validators: []abci.ValidatorUpdate{},
|
|
|
|
ConsensusParams: DefaultConsensusParams,
|
|
|
|
AppStateBytes: stateBytes,
|
2020-04-01 18:49:21 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return app
|
|
|
|
}
|
2022-04-05 07:09:27 +00:00
|
|
|
|
|
|
|
// CreateRandomAccounts will generate random accounts
|
|
|
|
func CreateRandomAccounts(accNum int) []sdk.AccAddress {
|
|
|
|
// createRandomAccounts is a strategy used by addTestAddrs() in order to generated addresses in random order.
|
|
|
|
testAddrs := make([]sdk.AccAddress, accNum)
|
|
|
|
for i := 0; i < accNum; i++ {
|
|
|
|
pk := ed25519.GenPrivKey().PubKey()
|
|
|
|
testAddrs[i] = sdk.AccAddress(pk.Address())
|
|
|
|
}
|
|
|
|
|
|
|
|
return testAddrs
|
|
|
|
}
|