Skip to content

Commit

Permalink
chore: rebase and cherry pick again
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-forbes authored and ninabarbakadze committed Jun 1, 2024
1 parent d366698 commit f1599fd
Show file tree
Hide file tree
Showing 25 changed files with 767 additions and 405 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
8 changes: 4 additions & 4 deletions app/test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,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 @@ -250,9 +250,9 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob() {
{
"medium random with timeout height",
mustNewBlob(ns1, tmrand.Bytes(100000), appconsts.ShareVersionZero),
[]blobtypes.TxBuilderOption{
blobtypes.SetTimeoutHeight(1000),
blobtypes.SetGasLimit(1_000_000_000),
[]user.TxOption{
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 @@ -53,7 +53,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
7 changes: 4 additions & 3 deletions app/test/priority_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ 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)

cctx, _, _ := testnode.NewNetwork(t, cfg)
Expand All @@ -54,8 +55,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
5 changes: 4 additions & 1 deletion app/test/square_size_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import (
"github.com/celestiaorg/celestia-app/app/encoding"
"github.com/celestiaorg/celestia-app/pkg/appconsts"
"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"
"github.com/cosmos/cosmos-sdk/baseapp"
Expand Down Expand Up @@ -44,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 @@ -48,14 +48,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 @@ -106,7 +106,7 @@ func (s *StandardSDKIntegrationTestSuite) TestStandardSDK() {
{
name: "delegate 1 TIA",
msgFunc: func() (msgs []sdk.Msg, signer string) {
valopAddr := sdk.ValAddress(getAddress("validator", s.cctx.Keyring))
valopAddr := sdk.ValAddress(testfactory.GetAddress(s.cctx.Keyring, testnode.DefaultValidatorAccountName))
account1 := s.unusedAccount()
account1Addr := getAddress(account1, s.cctx.Keyring)
msg := stakingtypes.NewMsgDelegate(account1Addr, valopAddr, sdk.NewCoin(app.BondDenom, sdk.NewInt(1000000)))
Expand All @@ -117,10 +117,10 @@ func (s *StandardSDKIntegrationTestSuite) TestStandardSDK() {
{
name: "undelegate 1 TIA",
msgFunc: func() (msgs []sdk.Msg, signer string) {
valAccAddr := getAddress("validator", s.cctx.Keyring)
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 @@ -134,10 +134,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
6 changes: 5 additions & 1 deletion test/cmd/txsim/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"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 @@ -62,7 +63,10 @@ func setup(t testing.TB) (keyring.Keyring, string, string) {

cfg := testnode.DefaultConfig().
WithConsensusParams(cparams).
WithAccounts([]string{testfactory.TestAccName})
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
9 changes: 8 additions & 1 deletion test/txsim/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ func TestTxSimulator(t *testing.T) {

keyring, rpcAddr, grpcAddr := Setup(t)

opts := txsim.DefaultOptions().
SuppressLogs().
WithPollTime(time.Millisecond * 100)
if tc.useFeegrant {
opts.UseFeeGrant()
}

err := txsim.Run(
ctx,
[]string{rpcAddr},
Expand Down Expand Up @@ -137,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
139 changes: 139 additions & 0 deletions test/util/genesis/accounts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
package genesis

import (
"fmt"
mrand "math/rand"
"time"

"github.com/celestiaorg/celestia-app/app"
"github.com/celestiaorg/celestia-app/app/encoding"
"github.com/cosmos/cosmos-sdk/client/tx"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/tendermint/tendermint/crypto"
)

type Account struct {
Name string
InitialTokens int64
}

func NewAccounts(initBal int64, names ...string) []Account {
accounts := make([]Account, len(names))
for i, name := range names {
accounts[i] = Account{
Name: name,
InitialTokens: initBal,
}
}
return accounts
}

func (ga *Account) ValidateBasic() error {
if ga.Name == "" {
return fmt.Errorf("name cannot be empty")
}
if ga.InitialTokens <= 0 {
return fmt.Errorf("initial tokens must be positive")
}
return nil
}

type Validator struct {
Account
Stake int64

// ConsensusKey is the key used by the validator to sign votes.
ConsensusKey crypto.PrivKey
NetworkKey crypto.PrivKey
}

func NewDefaultValidator(name string) Validator {
r := mrand.New(mrand.NewSource(time.Now().UnixNano()))
return Validator{
Account: Account{
Name: name,
InitialTokens: 999_999_999_999_999_999,
},
Stake: 99_999_999_999_999_999, // save some tokens for fees
ConsensusKey: GenerateEd25519(NewSeed(r)),
NetworkKey: GenerateEd25519(NewSeed(r)),
}
}

// ValidateBasic performs stateless validation on the validitor
func (v *Validator) ValidateBasic() error {
if err := v.Account.ValidateBasic(); err != nil {
return err
}
if v.Stake <= 0 {
return fmt.Errorf("stake must be positive")
}
if v.ConsensusKey == nil {
return fmt.Errorf("consensus key cannot be empty")
}
if v.Stake > v.InitialTokens {
return fmt.Errorf("stake cannot be greater than initial tokens")
}
return nil
}

// GenTx generates a genesis transaction to create a validator as configured by
// the validator struct. It assumes the validator's genesis account has already
// been added to the keyring and that the sequence for that account is 0.
func (v *Validator) GenTx(ecfg encoding.Config, kr keyring.Keyring, chainID string) (sdk.Tx, error) {
rec, err := kr.Key(v.Name)
if err != nil {
return nil, err
}
addr, err := rec.GetAddress()
if err != nil {
return nil, err
}

commission, err := sdk.NewDecFromStr("0.5")
if err != nil {
return nil, err
}

pk, err := cryptocodec.FromTmPubKeyInterface(v.ConsensusKey.PubKey())
if err != nil {
return nil, fmt.Errorf("converting public key for node %s: %w", v.Name, err)
}

createValMsg, err := stakingtypes.NewMsgCreateValidator(
sdk.ValAddress(addr),
pk,
sdk.NewCoin(app.BondDenom, sdk.NewInt(v.Stake)),
stakingtypes.NewDescription(v.Name, "", "", "", ""),
stakingtypes.NewCommissionRates(commission, sdk.OneDec(), sdk.OneDec()),
sdk.NewInt(v.Stake/2),
)
if err != nil {
return nil, err
}

fee := sdk.NewCoins(sdk.NewCoin(app.BondDenom, sdk.NewInt(1)))
txBuilder := ecfg.TxConfig.NewTxBuilder()
err = txBuilder.SetMsgs(createValMsg)
if err != nil {
return nil, err
}
txBuilder.SetFeeAmount(fee) // Arbitrary fee
txBuilder.SetGasLimit(1000000) // Need at least 100386

txFactory := tx.Factory{}
txFactory = txFactory.
WithChainID(chainID).
WithKeybase(kr).
WithTxConfig(ecfg.TxConfig)

err = tx.Sign(txFactory, v.Name, txBuilder, true)
if err != nil {
return nil, err
}

return txBuilder.GetTx(), nil
}
Loading

0 comments on commit f1599fd

Please sign in to comment.