Skip to content

Commit

Permalink
Merge pull request #39 from sunriselayer/test-encoding
Browse files Browse the repository at this point in the history
Test encoding
  • Loading branch information
kimurayu45z committed Jun 3, 2024
2 parents 101a40b + 7aa053e commit 01f3564
Show file tree
Hide file tree
Showing 28 changed files with 138 additions and 191 deletions.
4 changes: 2 additions & 2 deletions app/ante/panic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"fmt"
"testing"

"github.com/sunriselayer/sunrise/app"
"github.com/sunriselayer/sunrise/app/ante"
"github.com/sunriselayer/sunrise/app/encoding"
appconsts "github.com/sunriselayer/sunrise/pkg/appconsts"
testencoding "github.com/sunriselayer/sunrise/test/util/encoding"
"github.com/sunriselayer/sunrise/test/util/testnode"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -19,7 +19,7 @@ func TestPanicHandlerDecorator(t *testing.T) {
decorator := ante.NewHandlePanicDecorator()
anteHandler := sdk.ChainAnteDecorators(decorator, mockPanicDecorator{})
ctx := sdk.Context{}
encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...)
encCfg := encoding.MakeConfig(testencoding.ModuleEncodingRegisters...)
builder := encCfg.TxConfig.NewTxBuilder()
err := builder.SetMsgs(banktypes.NewMsgSend(testnode.RandomAddress().(sdk.AccAddress), testnode.RandomAddress().(sdk.AccAddress), sdk.NewCoins(sdk.NewInt64Coin(appconsts.BondDenom, 10))))
require.NoError(t, err)
Expand Down
16 changes: 14 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,15 @@ import (
)

const (
AccountAddressPrefix = "sunrise"
Name = "sunrise"
Bech32MainPrefix = "sunrise"
Name = "sunrise"

Bech32PrefixAccAddr = Bech32MainPrefix
Bech32PrefixAccPub = Bech32MainPrefix + "pub"
Bech32PrefixValAddr = Bech32MainPrefix + "valoper"
Bech32PrefixValPub = Bech32MainPrefix + "valoperpub"
Bech32PrefixConsAddr = Bech32MainPrefix + "valcons"
Bech32PrefixConsPub = Bech32MainPrefix + "valconspub"
)

var (
Expand Down Expand Up @@ -485,3 +492,8 @@ func BlockedAddresses() map[string]bool {
}
return result
}

// GetTxConfig implements the TestingApp interface.
func (app *App) GetTxConfig() client.TxConfig {
return app.txConfig
}
6 changes: 3 additions & 3 deletions app/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ var (
{
Name: authtypes.ModuleName,
Config: appconfig.WrapAny(&authmodulev1.Module{
Bech32Prefix: AccountAddressPrefix,
Bech32Prefix: Bech32MainPrefix,
ModuleAccountPermissions: moduleAccPerms,
// By default modules authority is the governance module. This is configurable with the following:
// Authority: "group", // A custom module authority can be set using a module name
Expand All @@ -291,8 +291,8 @@ var (
Config: appconfig.WrapAny(&stakingmodulev1.Module{
// NOTE: specifying a prefix is only necessary when using bech32 addresses
// If not specfied, the auth Bech32Prefix appended with "valoper" and "valcons" is used by default
Bech32PrefixValidator: AccountAddressPrefix + "valoper",
Bech32PrefixConsensus: AccountAddressPrefix + "valcons",
Bech32PrefixValidator: Bech32PrefixValAddr,
Bech32PrefixConsensus: Bech32PrefixConsAddr,
}),
},
{
Expand Down
133 changes: 0 additions & 133 deletions app/consts.go

This file was deleted.

4 changes: 2 additions & 2 deletions app/errors/insufficient_gas_price_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
"github.com/stretchr/testify/require"
"github.com/sunriselayer/sunrise/app"
"github.com/sunriselayer/sunrise/app/defaultoverrides"
"github.com/sunriselayer/sunrise/app/encoding"
apperr "github.com/sunriselayer/sunrise/app/errors"
"github.com/sunriselayer/sunrise/pkg/appconsts"
apprand "github.com/sunriselayer/sunrise/pkg/random"
"github.com/sunriselayer/sunrise/pkg/user"
testutil "github.com/sunriselayer/sunrise/test/util"
testencoding "github.com/sunriselayer/sunrise/test/util/encoding"
"github.com/sunriselayer/sunrise/test/util/testfactory"
blob "github.com/sunriselayer/sunrise/x/blob/types"
)
Expand All @@ -36,7 +36,7 @@ func TestInsufficientMinGasPriceIntegration(t *testing.T) {
require.NoError(t, err)
ctx := testApp.NewContext(true).WithMinGasPrices(minGasPrice)
addr := testfactory.GetAddress(kr, account)
enc := encoding.MakeConfig(app.ModuleEncodingRegisters...)
enc := encoding.MakeConfig(testencoding.ModuleEncodingRegisters...)
acc := testutil.DirectQueryAccount(testApp, addr)
signer, err := user.NewSigner(kr, nil, addr, enc.TxConfig, testutil.ChainID, acc.GetAccountNumber(), acc.GetSequence())
require.NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions app/errors/nonce_mismatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
"github.com/stretchr/testify/require"
"github.com/sunriselayer/sunrise/app"
"github.com/sunriselayer/sunrise/app/defaultoverrides"
"github.com/sunriselayer/sunrise/app/encoding"
apperr "github.com/sunriselayer/sunrise/app/errors"
"github.com/sunriselayer/sunrise/pkg/appconsts"
apprand "github.com/sunriselayer/sunrise/pkg/random"
"github.com/sunriselayer/sunrise/pkg/user"
testutil "github.com/sunriselayer/sunrise/test/util"
testencoding "github.com/sunriselayer/sunrise/test/util/encoding"
"github.com/sunriselayer/sunrise/test/util/testfactory"
blob "github.com/sunriselayer/sunrise/x/blob/types"
)
Expand All @@ -24,12 +24,12 @@ import (
func TestNonceMismatchIntegration(t *testing.T) {
account := "test"
testApp, kr := testutil.SetupTestAppWithGenesisValSet(defaultoverrides.DefaultConsensusParams().ToProto(), account)
encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...)
encCfg := encoding.MakeConfig(testencoding.ModuleEncodingRegisters...)
minGasPrice, err := sdk.ParseDecCoins(fmt.Sprintf("%v%s", appconsts.DefaultMinGasPrice, appconsts.BondDenom))
require.NoError(t, err)
ctx := testApp.NewContext(true).WithMinGasPrices(minGasPrice)
addr := testfactory.GetAddress(kr, account)
enc := encoding.MakeConfig(app.ModuleEncodingRegisters...)
enc := encoding.MakeConfig(testencoding.ModuleEncodingRegisters...)
acc := testutil.DirectQueryAccount(testApp, addr)
// set the sequence to an incorrect value
signer, err := user.NewSigner(kr, nil, addr, enc.TxConfig, testutil.ChainID, acc.GetAccountNumber(), 2)
Expand Down
3 changes: 2 additions & 1 deletion cmd/sunrised/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

func initSDKConfig() {
// Set prefixes
accountAddressPrefix := app.Bech32PrefixAccAddr
accountPubKeyPrefix := app.Bech32PrefixAccPub
validatorAddressPrefix := app.Bech32PrefixValAddr
validatorPubKeyPrefix := app.Bech32PrefixValPub
Expand All @@ -20,7 +21,7 @@ func initSDKConfig() {

// Set and seal config
config := sdk.GetConfig()
config.SetBech32PrefixForAccount(app.AccountAddressPrefix, accountPubKeyPrefix)
config.SetBech32PrefixForAccount(accountAddressPrefix, accountPubKeyPrefix)
config.SetBech32PrefixForValidator(validatorAddressPrefix, validatorPubKeyPrefix)
config.SetBech32PrefixForConsensusNode(consNodeAddressPrefix, consNodePubKeyPrefix)
config.Seal()
Expand Down
9 changes: 5 additions & 4 deletions test/e2e/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import (
slashing "github.com/cosmos/cosmos-sdk/x/slashing/types"
staking "github.com/cosmos/cosmos-sdk/x/staking/types"

"github.com/sunriselayer/sunrise/app"
testencoding "github.com/sunriselayer/sunrise/test/util/encoding"

"github.com/sunriselayer/sunrise/app/defaultoverrides"
"github.com/sunriselayer/sunrise/app/encoding"
"github.com/sunriselayer/sunrise/pkg/appconsts"
Expand All @@ -33,8 +34,8 @@ type Account struct {
}

func MakeGenesis(nodes []*Node, accounts []*Account) (types.GenesisDoc, error) {
encCdc := encoding.MakeConfig(app.ModuleEncodingRegisters...)
appGenState := app.ModuleBasics().DefaultGenesis(encCdc.Codec)
encCdc := encoding.MakeConfig(testencoding.ModuleEncodingRegisters...)
appGenState := testencoding.ModuleBasics.DefaultGenesis(encCdc.Codec)
bankGenesis := bank.DefaultGenesisState()
stakingGenesis := staking.DefaultGenesisState()
slashingGenesis := slashing.DefaultGenesisState()
Expand Down Expand Up @@ -117,7 +118,7 @@ func MakeGenesis(nodes []*Node, accounts []*Account) (types.GenesisDoc, error) {
appGenState[staking.ModuleName] = encCdc.Codec.MustMarshalJSON(stakingGenesis)
appGenState[slashing.ModuleName] = encCdc.Codec.MustMarshalJSON(slashingGenesis)

if err := app.ModuleBasics().ValidateGenesis(encCdc.Codec, encCdc.TxConfig, appGenState); err != nil {
if err := testencoding.ModuleBasics.ValidateGenesis(encCdc.Codec, encCdc.TxConfig, appGenState); err != nil {
return types.GenesisDoc{}, fmt.Errorf("validating genesis: %w", err)
}

Expand Down
4 changes: 2 additions & 2 deletions test/e2e/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"time"

"github.com/stretchr/testify/require"
"github.com/sunriselayer/sunrise/app"
"github.com/sunriselayer/sunrise/app/encoding"
v1 "github.com/sunriselayer/sunrise/pkg/appconsts/v1"
"github.com/sunriselayer/sunrise/test/txsim"
testencoding "github.com/sunriselayer/sunrise/test/util/encoding"
"github.com/sunriselayer/sunrise/test/util/testnode"
)

Expand Down Expand Up @@ -57,7 +57,7 @@ func TestE2ESimple(t *testing.T) {
sequences := txsim.NewBlobSequence(txsim.NewRange(200, 4000), txsim.NewRange(1, 3)).Clone(5)
sequences = append(sequences, txsim.NewSendSequence(4, 1000, 100).Clone(5)...)

encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...)
encCfg := encoding.MakeConfig(testencoding.ModuleEncodingRegisters...)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
opts := txsim.DefaultOptions().WithSeed(seed).SuppressLogs()
Expand Down
5 changes: 3 additions & 2 deletions test/e2e/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/rs/zerolog/log"
"github.com/sunriselayer/sunrise/app"
"github.com/sunriselayer/sunrise/app/encoding"

testencoding "github.com/sunriselayer/sunrise/test/util/encoding"
)

type Testnet struct {
Expand Down Expand Up @@ -68,7 +69,7 @@ func (t *Testnet) CreateNode(version string, startHeight, upgradeHeight int64) e
}

func (t *Testnet) CreateAccount(name string, tokens int64) (keyring.Keyring, error) {
cdc := encoding.MakeConfig(app.ModuleEncodingRegisters...).Codec
cdc := encoding.MakeConfig(testencoding.ModuleEncodingRegisters...).Codec
kr := keyring.NewInMemory(cdc)
key, _, err := kr.NewMnemonic(name, keyring.English, "", "", hd.Secp256k1)
if err != nil {
Expand Down
7 changes: 4 additions & 3 deletions test/e2e/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import (
"github.com/celestiaorg/knuu/pkg/knuu"
"github.com/cometbft/cometbft/rpc/client/http"
"github.com/stretchr/testify/require"
"github.com/sunriselayer/sunrise/app"
"github.com/sunriselayer/sunrise/app/encoding"
v1 "github.com/sunriselayer/sunrise/pkg/appconsts/v1"
v2 "github.com/sunriselayer/sunrise/pkg/appconsts/v2"
"github.com/sunriselayer/sunrise/test/txsim"

testencoding "github.com/sunriselayer/sunrise/test/util/encoding"
)

// This will only run tests within the v1 major release cycle
Expand Down Expand Up @@ -71,7 +72,7 @@ func TestMinorVersionCompatibility(t *testing.T) {
sequences = append(sequences, txsim.NewSendSequence(4, 1000, 100).Clone(5)...)

errCh := make(chan error)
encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...)
encCfg := encoding.MakeConfig(testencoding.ModuleEncodingRegisters...)
opts := txsim.DefaultOptions().WithSeed(seed).SuppressLogs()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down Expand Up @@ -170,7 +171,7 @@ func TestMajorUpgradeToV2(t *testing.T) {
require.NoError(t, testnet.Start())

errCh := make(chan error)
encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...)
encCfg := encoding.MakeConfig(testencoding.ModuleEncodingRegisters...)
opts := txsim.DefaultOptions().WithSeed(seed).SuppressLogs()
sequences := txsim.NewBlobSequence(txsim.NewRange(200, 4000), txsim.NewRange(1, 3)).Clone(5)
sequences = append(sequences, txsim.NewSendSequence(4, 1000, 100).Clone(5)...)
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 @@ -11,9 +11,9 @@ import (
"time"

blob "github.com/sunriselayer/sunrise/api/sunrise/blob/v1"
"github.com/sunriselayer/sunrise/app"
"github.com/sunriselayer/sunrise/app/encoding"
"github.com/sunriselayer/sunrise/test/txsim"
testencoding "github.com/sunriselayer/sunrise/test/util/encoding"
"github.com/sunriselayer/sunrise/test/util/testnode"

"github.com/cosmos/cosmos-sdk/crypto/keyring"
Expand All @@ -29,7 +29,7 @@ func TestTxSimulator(t *testing.T) {
t.Skip("skipping TestTxSimulator in short mode.")
}

encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...)
encCfg := encoding.MakeConfig(testencoding.ModuleEncodingRegisters...)
testCases := []struct {
name string
sequences []txsim.Sequence
Expand Down
Loading

0 comments on commit 01f3564

Please sign in to comment.