Skip to content

Commit

Permalink
refactor!: genesis creation into its own package (#2455)
Browse files Browse the repository at this point in the history
## Overview

This PR refactors genesis creation into its own package. Besides a
general simplification and isolation of logic, this PR also allows for
the ease of adding multiple validators to the genesis. The goal being
that we can eventually use this genesis creation code across all of our
testing utilities that require it including testnode, e2e, the testapp
integration tests, and specificlally testground.

This change was spun out of my recent efforts to refactor the testground
tests and put them into celestia-app. #2033

## Checklist

- [x] New and updated code has appropriate documentation
- [x] New and updated code has new and/or updated testing
- [x] Required CI checks are passing
- [x] Visual proof for any user facing features like CLI or
documentation updates
- [ ] Linked issues closed with keywords

---------

Co-authored-by: CHAMI Rachid <[email protected]>
  • Loading branch information
evan-forbes and rach-id authored Oct 9, 2023
1 parent 995f122 commit d8d91e5
Show file tree
Hide file tree
Showing 28 changed files with 680 additions and 384 deletions.
2 changes: 1 addition & 1 deletion app/test/block_production_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (s *BlockProductionTestSuite) SetupSuite() {
}

cfg := testnode.DefaultConfig().
WithAccounts(accounts).
WithFundedAccounts(accounts...).
WithTimeoutCommit(s.timeoutCommit)

cctx, _, _ := testnode.NewNetwork(t, cfg)
Expand Down
4 changes: 2 additions & 2 deletions app/test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (s *IntegrationTestSuite) SetupSuite() {
s.accounts[i] = tmrand.Str(20)
}

cfg := testnode.DefaultConfig().WithAccounts(s.accounts)
cfg := testnode.DefaultConfig().WithFundedAccounts(s.accounts...)

cctx, _, _ := testnode.NewNetwork(t, cfg)

Expand Down Expand Up @@ -249,7 +249,7 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob() {
"medium random with timeout height",
mustNewBlob(ns1, tmrand.Bytes(100000), appconsts.ShareVersionZero),
[]user.TxOption{
user.SetTimeoutHeight(1000),
user.SetTimeoutHeight(10000),
user.SetGasLimit(1_000_000_000),
},
},
Expand Down
2 changes: 1 addition & 1 deletion app/test/max_total_blob_size_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (s *MaxTotalBlobSizeSuite) SetupSuite() {
cParams.Block.MaxBytes = 10 * mebibyte

cfg := testnode.DefaultConfig().
WithAccounts(s.accounts).
WithFundedAccounts(s.accounts...).
WithTendermintConfig(tmConfig).
WithConsensusParams(cParams)

Expand Down
2 changes: 1 addition & 1 deletion app/test/prepare_proposal_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestTimeInPrepareProposalContext(t *testing.T) {
for i := 0; i < len(accounts); i++ {
accounts[i] = tmrand.Str(9)
}
cfg := testnode.DefaultConfig().WithAccounts(accounts)
cfg := testnode.DefaultConfig().WithFundedAccounts(accounts...)
cctx, _, _ := testnode.NewNetwork(t, cfg)
ecfg := encoding.MakeConfig(app.ModuleEncodingRegisters...)
vestAccName := "vesting"
Expand Down
6 changes: 3 additions & 3 deletions app/test/priority_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (s *PriorityTestSuite) SetupSuite() {
t := s.T()

cfg := testnode.DefaultConfig().
WithAccounts(testfactory.GenerateAccounts(10)).
WithFundedAccounts(testfactory.GenerateAccounts(10)...).
// use a long block time to guarantee that some transactions are included in the same block
WithTimeoutCommit(time.Second)

Expand All @@ -54,8 +54,8 @@ func (s *PriorityTestSuite) SetupSuite() {

require.NoError(t, cctx.WaitForNextBlock())

for _, acc := range cfg.Accounts {
addr := testfactory.GetAddress(s.cctx.Keyring, acc)
for _, acc := range cfg.Genesis.Accounts() {
addr := testfactory.GetAddress(s.cctx.Keyring, acc.Name)
signer, err := user.SetupSigner(s.cctx.GoContext(), s.cctx.Keyring, s.cctx.GRPCClient, addr, s.ecfg)
signer.SetPollTime(time.Millisecond * 300)
require.NoError(t, err)
Expand Down
6 changes: 5 additions & 1 deletion app/test/qgb_rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"testing"
"time"

"github.com/celestiaorg/celestia-app/app"
"github.com/celestiaorg/celestia-app/app/encoding"
"github.com/celestiaorg/celestia-app/test/util/genesis"
"github.com/celestiaorg/celestia-app/test/util/testnode"
"github.com/celestiaorg/celestia-app/x/qgb/types"
"github.com/stretchr/testify/assert"
Expand All @@ -15,7 +18,8 @@ func TestQGBRPCQueries(t *testing.T) {
if testing.Short() {
t.Skip("skipping QGB integration test in short mode.")
}
cfg := testnode.DefaultConfig()
ecfg := encoding.MakeConfig(app.ModuleEncodingRegisters...)
cfg := testnode.DefaultConfig().WithModifiers(genesis.SetDataCommitmentWindow(ecfg.Codec, 100))

cctx, _, _ := testnode.NewNetwork(t, cfg)

Expand Down
3 changes: 2 additions & 1 deletion app/test/square_size_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/celestiaorg/celestia-app/pkg/user"
"github.com/celestiaorg/celestia-app/test/txsim"
"github.com/celestiaorg/celestia-app/test/util/blobfactory"
"github.com/celestiaorg/celestia-app/test/util/genesis"
"github.com/celestiaorg/celestia-app/test/util/testfactory"
"github.com/celestiaorg/celestia-app/test/util/testnode"
blobtypes "github.com/celestiaorg/celestia-app/x/blob/types"
Expand Down Expand Up @@ -46,7 +47,7 @@ func (s *SquareSizeIntegrationTest) SetupSuite() {
t.Log("setting up square size integration test")
s.ecfg = encoding.MakeConfig(app.ModuleEncodingRegisters...)
cfg := testnode.DefaultConfig().
WithGenesisOptions(testnode.ImmediateProposals(s.ecfg.Codec))
WithModifiers(genesis.ImmediateProposals(s.ecfg.Codec))

cctx, rpcAddr, grpcAddr := testnode.NewNetwork(t, cfg)

Expand Down
16 changes: 8 additions & 8 deletions app/test/std_sdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ func (s *StandardSDKIntegrationTestSuite) SetupSuite() {
t := s.T()
t.Log("setting up integration test suite")

accounts := make([]string, 300)
accounts := make([]string, 35)
for i := 0; i < len(accounts); i++ {
accounts[i] = tmrand.Str(9)
}

cfg := testnode.DefaultConfig().WithAccounts(accounts)
cfg := testnode.DefaultConfig().WithFundedAccounts(accounts...)
cctx, _, _ := testnode.NewNetwork(t, cfg)
s.accounts = cfg.Accounts
s.accounts = accounts
s.ecfg = encoding.MakeConfig(app.ModuleEncodingRegisters...)
s.cctx = cctx
}
Expand Down Expand Up @@ -108,7 +108,7 @@ func (s *StandardSDKIntegrationTestSuite) TestStandardSDK() {
{
name: "delegate 1 TIA",
msgFunc: func() (msgs []sdk.Msg, signer string) {
valopAddr := sdk.ValAddress(testfactory.GetAddress(s.cctx.Keyring, "validator"))
valopAddr := sdk.ValAddress(testfactory.GetAddress(s.cctx.Keyring, testnode.DefaultValidatorAccountName))
account1 := s.unusedAccount()
account1Addr := testfactory.GetAddress(s.cctx.Keyring, account1)
msg := stakingtypes.NewMsgDelegate(account1Addr, valopAddr, sdk.NewCoin(app.BondDenom, sdk.NewInt(1000000)))
Expand All @@ -119,10 +119,10 @@ func (s *StandardSDKIntegrationTestSuite) TestStandardSDK() {
{
name: "undelegate 1 TIA",
msgFunc: func() (msgs []sdk.Msg, signer string) {
valAccAddr := testfactory.GetAddress(s.cctx.Keyring, "validator")
valAccAddr := testfactory.GetAddress(s.cctx.Keyring, testnode.DefaultValidatorAccountName)
valopAddr := sdk.ValAddress(valAccAddr)
msg := stakingtypes.NewMsgUndelegate(valAccAddr, valopAddr, sdk.NewCoin(app.BondDenom, sdk.NewInt(1000000)))
return []sdk.Msg{msg}, "validator"
return []sdk.Msg{msg}, testnode.DefaultValidatorAccountName
},
expectedCode: abci.CodeTypeOK,
},
Expand All @@ -136,10 +136,10 @@ func (s *StandardSDKIntegrationTestSuite) TestStandardSDK() {
msg, err := stakingtypes.NewMsgCreateValidator(
valopAddr,
pv.PrivKey.PubKey(),
sdk.NewCoin(app.BondDenom, sdk.NewInt(1000000)),
sdk.NewCoin(app.BondDenom, sdk.NewInt(1)),
stakingtypes.NewDescription("taco tuesday", "my keybase", "www.celestia.org", "ping @celestiaorg on twitter", "fake validator"),
stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(6, 0o2), sdk.NewDecWithPrec(12, 0o2), sdk.NewDecWithPrec(1, 0o2)),
sdk.NewInt(1000000),
sdk.NewInt(1),
)
require.NoError(t, err)
return []sdk.Msg{msg}, account
Expand Down
2 changes: 1 addition & 1 deletion pkg/user/signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type SignerTestSuite struct {

func (s *SignerTestSuite) SetupSuite() {
s.encCfg = encoding.MakeConfig(app.ModuleEncodingRegisters...)
s.ctx, _, _ = testnode.NewNetwork(s.T(), testnode.DefaultConfig().WithAccounts([]string{"a"}))
s.ctx, _, _ = testnode.NewNetwork(s.T(), testnode.DefaultConfig().WithFundedAccounts("a"))
_, err := s.ctx.WaitForHeight(1)
s.Require().NoError(err)
rec, err := s.ctx.Keyring.Key("a")
Expand Down
7 changes: 5 additions & 2 deletions test/cmd/txsim/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/celestiaorg/celestia-app/app"
"github.com/celestiaorg/celestia-app/app/encoding"
"github.com/celestiaorg/celestia-app/pkg/appconsts"
"github.com/celestiaorg/celestia-app/test/util/genesis"
"github.com/celestiaorg/celestia-app/test/util/testfactory"
"github.com/celestiaorg/celestia-app/test/util/testnode"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
Expand Down Expand Up @@ -65,8 +66,10 @@ func setup(t testing.TB) (keyring.Keyring, string, string) {

cfg := testnode.DefaultConfig().
WithConsensusParams(cparams).
WithAccounts([]string{testfactory.TestAccName}).
WithGenesisOptions(testnode.FundAccounts(cdc, []sdk.AccAddress{testnode.TestAddress()}, sdk.NewCoin(app.BondDenom, sdk.NewIntFromUint64(1e15))))
WithFundedAccounts(testfactory.TestAccName).
WithModifiers(
genesis.FundAccounts(cdc, []sdk.AccAddress{testnode.TestAddress()}, sdk.NewCoin(app.BondDenom, sdk.NewIntFromUint64(1e15))),
)

cctx, rpcAddr, grpcAddr := testnode.NewNetwork(t, cfg)

Expand Down
4 changes: 2 additions & 2 deletions test/e2e/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import (
"github.com/tendermint/tendermint/types"
)

type GenesisAccount struct {
type Account struct {
PubKey cryptotypes.PubKey
InitialTokens int64
}

func MakeGenesis(nodes []*Node, accounts []*GenesisAccount) (types.GenesisDoc, error) {
func MakeGenesis(nodes []*Node, accounts []*Account) (types.GenesisDoc, error) {
encCdc := encoding.MakeConfig(app.ModuleEncodingRegisters...)
appGenState := app.ModuleBasics.DefaultGenesis(encCdc.Codec)
bankGenesis := bank.DefaultGenesisState()
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestE2ESimple(t *testing.T) {
t.Cleanup(testnet.Cleanup)
require.NoError(t, testnet.CreateGenesisNodes(4, latestVersion, 10000000))

kr, err := testnet.CreateGenesisAccount("alice", 1e12)
kr, err := testnet.CreateAccount("alice", 1e12)
require.NoError(t, err)

require.NoError(t, testnet.Setup())
Expand Down
8 changes: 4 additions & 4 deletions test/e2e/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
type Testnet struct {
seed int64
nodes []*Node
genesisAccounts []*GenesisAccount
genesisAccounts []*Account
keygen *keyGenerator
}

Expand All @@ -29,7 +29,7 @@ func New(name string, seed int64) (*Testnet, error) {
return &Testnet{
seed: seed,
nodes: make([]*Node, 0),
genesisAccounts: make([]*GenesisAccount, 0),
genesisAccounts: make([]*Account, 0),
keygen: newKeyGenerator(seed),
}, nil
}
Expand Down Expand Up @@ -67,7 +67,7 @@ func (t *Testnet) CreateNode(version string, startHeight int64) error {
return nil
}

func (t *Testnet) CreateGenesisAccount(name string, tokens int64) (keyring.Keyring, error) {
func (t *Testnet) CreateAccount(name string, tokens int64) (keyring.Keyring, error) {
cdc := encoding.MakeConfig(app.ModuleEncodingRegisters...).Codec
kr := keyring.NewInMemory(cdc)
key, _, err := kr.NewMnemonic(name, keyring.English, "", "", hd.Secp256k1)
Expand All @@ -78,7 +78,7 @@ func (t *Testnet) CreateGenesisAccount(name string, tokens int64) (keyring.Keyri
if err != nil {
return nil, err
}
t.genesisAccounts = append(t.genesisAccounts, &GenesisAccount{
t.genesisAccounts = append(t.genesisAccounts, &Account{
PubKey: pk,
InitialTokens: tokens,
})
Expand Down
4 changes: 2 additions & 2 deletions test/txsim/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func TestTxSimulator(t *testing.T) {

opts := txsim.DefaultOptions().
SuppressLogs().
WithPollTime(time.Second)
WithPollTime(time.Millisecond * 100)
if tc.useFeegrant {
opts.UseFeeGrant()
}
Expand Down Expand Up @@ -144,7 +144,7 @@ func TestTxSimulator(t *testing.T) {
func Setup(t testing.TB) (keyring.Keyring, string, string) {
t.Helper()

cfg := testnode.DefaultConfig()
cfg := testnode.DefaultConfig().WithTimeoutCommit(300 * time.Millisecond).WithFundedAccounts("txsim-master")

cctx, rpcAddr, grpcAddr := testnode.NewNetwork(t, cfg)

Expand Down
Loading

0 comments on commit d8d91e5

Please sign in to comment.