76 lines
2.1 KiB
Go
76 lines
2.1 KiB
Go
package app
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
|
|
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/db/memdb"
|
|
"github.com/cosmos/cosmos-sdk/simapp"
|
|
"github.com/tharsis/ethermint/encoding"
|
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
"github.com/tendermint/tendermint/libs/log"
|
|
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
|
tmtypes "github.com/tendermint/tendermint/types"
|
|
)
|
|
|
|
// DefaultConsensusParams defines the default Tendermint consensus params used in
|
|
// EthermintApp testing.
|
|
var DefaultConsensusParams = &tmproto.ConsensusParams{
|
|
Block: &tmproto.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,
|
|
},
|
|
},
|
|
}
|
|
|
|
// Setup initializes a new EthermintApp. A Nop logger is set in EthermintApp.
|
|
func Setup(isCheckTx bool) *EthermintApp {
|
|
db := memdb.NewDB()
|
|
app := NewEthermintApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5, encoding.MakeConfig(ModuleBasics), simapp.EmptyAppOptions{})
|
|
if !isCheckTx {
|
|
// init chain must be called to stop deliverState from being nil
|
|
genesisState := NewDefaultGenesisState()
|
|
stateBytes, err := json.MarshalIndent(genesisState, "", " ")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
// Initialize the chain
|
|
app.InitChain(
|
|
abci.RequestInitChain{
|
|
ChainId: "ethermint_9000-1",
|
|
Validators: []abci.ValidatorUpdate{},
|
|
ConsensusParams: DefaultConsensusParams,
|
|
AppStateBytes: stateBytes,
|
|
},
|
|
)
|
|
}
|
|
|
|
return app
|
|
}
|
|
|
|
// 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
|
|
}
|