Skip to content

Commit

Permalink
remove test encoding config
Browse files Browse the repository at this point in the history
  • Loading branch information
gitferry committed Feb 20, 2023
1 parent 9140ef2 commit 9aadd53
Show file tree
Hide file tree
Showing 23 changed files with 100 additions and 85 deletions.
4 changes: 2 additions & 2 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func TestBabylonBlockedAddrs(t *testing.T) {
encCfg := MakeTestEncodingConfig()
encCfg := MakeEncodingConfig()
db := dbm.NewMemDB()
signer, _ := SetupPrivSigner()
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
Expand Down Expand Up @@ -48,7 +48,7 @@ func TestGetMaccPerms(t *testing.T) {
}

func TestUpgradeStateOnGenesis(t *testing.T) {
encCfg := MakeTestEncodingConfig()
encCfg := MakeEncodingConfig()
db := dbm.NewMemDB()
privSigner, err := SetupPrivSigner()
require.NoError(t, err)
Expand Down
18 changes: 11 additions & 7 deletions app/encoding.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package app

import (
appparams "github.com/babylonchain/babylon/app/params"
"github.com/cosmos/cosmos-sdk/std"

appparams "github.com/babylonchain/babylon/app/params"
)

// MakeTestEncodingConfig creates an EncodingConfig for testing. This function
// should be used only in tests or when creating a new app instance (NewApp*()).
// App user shouldn't create new codecs - use the app.AppCodec instead.
// [DEPRECATED]
func MakeTestEncodingConfig() appparams.EncodingConfig {
encodingConfig := appparams.MakeTestEncodingConfig()
var encodingConfig appparams.EncodingConfig = MakeEncodingConfig()

func GetEncodingConfig() appparams.EncodingConfig {
return encodingConfig
}

// MakeEncodingConfig creates an EncodingConfig.
func MakeEncodingConfig() appparams.EncodingConfig {
encodingConfig := appparams.MakeEncodingConfig()
std.RegisterLegacyAminoCodec(encodingConfig.Amino)
std.RegisterInterfaces(encodingConfig.InterfaceRegistry)
ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino)
Expand Down
2 changes: 1 addition & 1 deletion app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ func (app *BabylonApp) GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper {
}

func (app *BabylonApp) GetTxConfig() client.TxConfig {
return MakeTestEncodingConfig().TxConfig
return GetEncodingConfig().TxConfig
}
14 changes: 6 additions & 8 deletions app/params/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,17 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/tx"
)

// MakeTestEncodingConfig creates an EncodingConfig for a non-amino based test configuration.
// This function should be used only internally (in the SDK).
// App user should'nt create new codecs - use the app.AppCodec instead.
// [DEPRECATED]
func MakeTestEncodingConfig() EncodingConfig {
cdc := codec.NewLegacyAmino()
// MakeEncodingConfig creates an EncodingConfig for an amino based test configuration.
func MakeEncodingConfig() EncodingConfig {
amino := codec.NewLegacyAmino()
interfaceRegistry := types.NewInterfaceRegistry()
marshaler := codec.NewProtoCodec(interfaceRegistry)
txCfg := tx.NewTxConfig(marshaler, tx.DefaultSignModes)

return EncodingConfig{
InterfaceRegistry: interfaceRegistry,
Marshaler: marshaler,
TxConfig: tx.NewTxConfig(marshaler, tx.DefaultSignModes),
Amino: cdc,
TxConfig: txCfg,
Amino: amino,
}
}
7 changes: 4 additions & 3 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import (

tmjson "github.com/tendermint/tendermint/libs/json"

"github.com/babylonchain/babylon/testutil/datagen"

"github.com/babylonchain/babylon/app/params"
appparams "github.com/babylonchain/babylon/app/params"
"github.com/babylonchain/babylon/testutil/datagen"

bam "github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -79,7 +80,7 @@ type SetupOptions struct {

func setup(withGenesis bool, invCheckPeriod uint) (*BabylonApp, GenesisState) {
db := dbm.NewMemDB()
encCdc := MakeTestEncodingConfig()
encCdc := MakeEncodingConfig()
privSigner, err := SetupPrivSigner()
if err != nil {
panic(err)
Expand Down Expand Up @@ -244,7 +245,7 @@ func SetupPrivSigner() (*PrivSigner, error) {
if err != nil {
return nil, err
}
encodingCfg := appparams.MakeTestEncodingConfig()
encodingCfg := appparams.MakeEncodingConfig()
privSigner, _ := InitPrivSigner(client.Context{}, ".", kr, encodingCfg)
privSigner.WrappedPV.Clean(nodeCfg.PrivValidatorKeyFile(), nodeCfg.PrivValidatorStateFile())
return privSigner, nil
Expand Down
2 changes: 0 additions & 2 deletions app/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ func InitPrivSigner(clientCtx client.Context, nodeDir string, kr keyring.Keyring
}
wrappedPV := privval.LoadOrGenWrappedFilePV(pvKeyFile, pvStateFile)

// TODO this should probably not create separate config, but rahter accept it
// as argument
clientCtx = clientCtx.
WithInterfaceRegistry(encodingCfg.InterfaceRegistry).
WithCodec(encodingCfg.Marshaler).
Expand Down
5 changes: 3 additions & 2 deletions cmd/babylond/cmd/add_gen_bls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package cmd_test
import (
"context"
"fmt"
"github.com/cosmos/cosmos-sdk/server/config"
"path/filepath"
"testing"

"github.com/cosmos/cosmos-sdk/server/config"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/server"
Expand Down Expand Up @@ -36,7 +37,7 @@ func Test_AddGenBlsCmdWithoutGentx(t *testing.T) {
tmcfg, err := genutiltest.CreateDefaultTendermintConfig(home)
require.NoError(t, err)

appCodec := app.MakeTestEncodingConfig().Marshaler
appCodec := app.MakeEncodingConfig().Marshaler
err = genutiltest.ExecInitCmd(testMbm, home, appCodec)
require.NoError(t, err)

Expand Down
7 changes: 4 additions & 3 deletions cmd/babylond/cmd/genaccounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ import (
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/log"

"github.com/babylonchain/babylon/app"
bbncmd "github.com/babylonchain/babylon/cmd/babylond/cmd"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltest "github.com/cosmos/cosmos-sdk/x/genutil/client/testutil"

"github.com/babylonchain/babylon/app"
bbncmd "github.com/babylonchain/babylon/cmd/babylond/cmd"
)

var testMbm = module.NewBasicManager(genutil.AppModuleBasic{})
Expand Down Expand Up @@ -73,7 +74,7 @@ func TestAddGenesisAccountCmd(t *testing.T) {
cfg, err := genutiltest.CreateDefaultTendermintConfig(home)
require.NoError(t, err)

appCodec := app.MakeTestEncodingConfig().Marshaler
appCodec := app.MakeEncodingConfig().Marshaler
err = genutiltest.ExecInitCmd(testMbm, home, appCodec)
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion cmd/babylond/cmd/genbls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

func Test_GenBlsCmd(t *testing.T) {
home := t.TempDir()
encodingConfig := app.MakeTestEncodingConfig()
encodingConfig := app.MakeEncodingConfig()
logger := log.NewNopLogger()
cfg, err := genutiltest.CreateDefaultTendermintConfig(home)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/babylond/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import (
// NewRootCmd creates a new root command for babylond. It is called once in the
// main function.
func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
encodingConfig := app.MakeTestEncodingConfig()
encodingConfig := app.MakeEncodingConfig()
initClientCtx := client.Context{}.
WithCodec(encodingConfig.Marshaler).
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
Expand Down
5 changes: 3 additions & 2 deletions cmd/babylond/cmd/testnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"testing"

"github.com/babylonchain/babylon/app"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/server"
Expand All @@ -15,11 +14,13 @@ import (
"github.com/spf13/viper"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/log"

"github.com/babylonchain/babylon/app"
)

func Test_TestnetCmd(t *testing.T) {
home := t.TempDir()
encodingConfig := app.MakeTestEncodingConfig()
encodingConfig := app.MakeEncodingConfig()
logger := log.NewNopLogger()
cfg, err := genutiltest.CreateDefaultTendermintConfig(home)
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/babylond/cmd/validate_genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

func TestCheckCorrespondence(t *testing.T) {
homePath := t.TempDir()
encodingCft := app.MakeTestEncodingConfig()
encodingCft := app.MakeEncodingConfig()
clientCtx := client.Context{}.WithCodec(encodingCft.Marshaler).WithTxConfig(encodingCft.TxConfig)

// generate valid genesis doc
Expand Down Expand Up @@ -85,7 +85,7 @@ func TestCheckCorrespondence(t *testing.T) {
}

func generateTestGenesisState(home string, n int) (map[string]json.RawMessage, *tmtypes.GenesisDoc) {
encodingConfig := app.MakeTestEncodingConfig()
encodingConfig := app.MakeEncodingConfig()
logger := log.NewNopLogger()
cfg, _ := genutiltest.CreateDefaultTendermintConfig(home)

Expand Down
4 changes: 2 additions & 2 deletions simapp/sim_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func BenchmarkFullAppSimulation(b *testing.B) {
if err != nil {
b.Fatal(err)
}
babylon := app.NewBabylonApp(logger, db, nil, true, map[int64]bool{}, app.DefaultNodeHome, FlagPeriodValue, app.MakeTestEncodingConfig(), privSigner, sdksimapp.EmptyAppOptions{}, interBlockCacheOpt())
babylon := app.NewBabylonApp(logger, db, nil, true, map[int64]bool{}, app.DefaultNodeHome, FlagPeriodValue, app.MakeEncodingConfig(), privSigner, sdksimapp.EmptyAppOptions{}, interBlockCacheOpt())

// run randomized simulation
_, simParams, simErr := simulation.SimulateFromSeed(
Expand Down Expand Up @@ -93,7 +93,7 @@ func BenchmarkInvariants(b *testing.B) {
if err != nil {
b.Fatal(err)
}
babylon := app.NewBabylonApp(logger, db, nil, true, map[int64]bool{}, app.DefaultNodeHome, FlagPeriodValue, app.MakeTestEncodingConfig(), privSigner, sdksimapp.EmptyAppOptions{}, interBlockCacheOpt())
babylon := app.NewBabylonApp(logger, db, nil, true, map[int64]bool{}, app.DefaultNodeHome, FlagPeriodValue, app.MakeEncodingConfig(), privSigner, sdksimapp.EmptyAppOptions{}, interBlockCacheOpt())

// run randomized simulation
_, simParams, simErr := simulation.SimulateFromSeed(
Expand Down
24 changes: 13 additions & 11 deletions simapp/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ import (
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
dbm "github.com/tendermint/tm-db"

"github.com/babylonchain/babylon/app"
storetypes "github.com/cosmos/cosmos-sdk/store/types"

btccheckpointtypes "github.com/babylonchain/babylon/x/btccheckpoint/types"
btclightclienttypes "github.com/babylonchain/babylon/x/btclightclient/types"
checkpointingtypes "github.com/babylonchain/babylon/x/checkpointing/types"
epochingtypes "github.com/babylonchain/babylon/x/epoching/types"
"github.com/babylonchain/babylon/app"

"github.com/cosmos/cosmos-sdk/baseapp"
sdksimapp "github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/simapp/helpers"
Expand All @@ -38,6 +35,11 @@ import (
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
abci "github.com/tendermint/tendermint/abci/types"

btccheckpointtypes "github.com/babylonchain/babylon/x/btccheckpoint/types"
btclightclienttypes "github.com/babylonchain/babylon/x/btclightclient/types"
checkpointingtypes "github.com/babylonchain/babylon/x/checkpointing/types"
epochingtypes "github.com/babylonchain/babylon/x/epoching/types"
)

// Get flags every time the simulator is run
Expand Down Expand Up @@ -77,7 +79,7 @@ func TestFullAppSimulation(t *testing.T) {

privSigner, err := app.SetupPrivSigner()
require.NoError(t, err)
babylon := app.NewBabylonApp(logger, db, nil, true, map[int64]bool{}, app.DefaultNodeHome, FlagPeriodValue, app.MakeTestEncodingConfig(), privSigner, sdksimapp.EmptyAppOptions{}, fauxMerkleModeOpt)
babylon := app.NewBabylonApp(logger, db, nil, true, map[int64]bool{}, app.DefaultNodeHome, FlagPeriodValue, app.MakeEncodingConfig(), privSigner, sdksimapp.EmptyAppOptions{}, fauxMerkleModeOpt)
require.Equal(t, "BabylonApp", babylon.Name())

// run randomized simulation
Expand Down Expand Up @@ -117,7 +119,7 @@ func TestAppImportExport(t *testing.T) {

privSigner, err := app.SetupPrivSigner()
require.NoError(t, err)
babylon := app.NewBabylonApp(logger, db, nil, true, map[int64]bool{}, app.DefaultNodeHome, FlagPeriodValue, app.MakeTestEncodingConfig(), privSigner, sdksimapp.EmptyAppOptions{}, fauxMerkleModeOpt)
babylon := app.NewBabylonApp(logger, db, nil, true, map[int64]bool{}, app.DefaultNodeHome, FlagPeriodValue, app.MakeEncodingConfig(), privSigner, sdksimapp.EmptyAppOptions{}, fauxMerkleModeOpt)
require.Equal(t, "BabylonApp", babylon.Name())

// Run randomized simulation
Expand Down Expand Up @@ -157,7 +159,7 @@ func TestAppImportExport(t *testing.T) {
require.NoError(t, os.RemoveAll(newDir))
}()

newBabylon := app.NewBabylonApp(log.NewNopLogger(), newDB, nil, true, map[int64]bool{}, app.DefaultNodeHome, FlagPeriodValue, app.MakeTestEncodingConfig(), privSigner, sdksimapp.EmptyAppOptions{}, fauxMerkleModeOpt)
newBabylon := app.NewBabylonApp(log.NewNopLogger(), newDB, nil, true, map[int64]bool{}, app.DefaultNodeHome, FlagPeriodValue, app.MakeEncodingConfig(), privSigner, sdksimapp.EmptyAppOptions{}, fauxMerkleModeOpt)
require.Equal(t, "BabylonApp", newBabylon.Name())

var genesisState app.GenesisState
Expand Down Expand Up @@ -221,7 +223,7 @@ func TestAppSimulationAfterImport(t *testing.T) {

privSigner, err := app.SetupPrivSigner()
require.NoError(t, err)
babylon := app.NewBabylonApp(logger, db, nil, true, map[int64]bool{}, app.DefaultNodeHome, FlagPeriodValue, app.MakeTestEncodingConfig(), privSigner, sdksimapp.EmptyAppOptions{}, fauxMerkleModeOpt)
babylon := app.NewBabylonApp(logger, db, nil, true, map[int64]bool{}, app.DefaultNodeHome, FlagPeriodValue, app.MakeEncodingConfig(), privSigner, sdksimapp.EmptyAppOptions{}, fauxMerkleModeOpt)
require.Equal(t, "BabylonApp", babylon.Name())

// Run randomized simulation
Expand Down Expand Up @@ -266,7 +268,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
require.NoError(t, os.RemoveAll(newDir))
}()

newBabylon := app.NewBabylonApp(log.NewNopLogger(), newDB, nil, true, map[int64]bool{}, app.DefaultNodeHome, FlagPeriodValue, app.MakeTestEncodingConfig(), privSigner, sdksimapp.EmptyAppOptions{}, fauxMerkleModeOpt)
newBabylon := app.NewBabylonApp(log.NewNopLogger(), newDB, nil, true, map[int64]bool{}, app.DefaultNodeHome, FlagPeriodValue, app.MakeEncodingConfig(), privSigner, sdksimapp.EmptyAppOptions{}, fauxMerkleModeOpt)
require.Equal(t, "BabylonApp", newBabylon.Name())

newBabylon.InitChain(abci.RequestInitChain{
Expand Down Expand Up @@ -319,7 +321,7 @@ func TestAppStateDeterminism(t *testing.T) {
db := dbm.NewMemDB()
privSigner, err := app.SetupPrivSigner()
require.NoError(t, err)
babylon := app.NewBabylonApp(logger, db, nil, true, map[int64]bool{}, app.DefaultNodeHome, FlagPeriodValue, app.MakeTestEncodingConfig(), privSigner, sdksimapp.EmptyAppOptions{}, interBlockCacheOpt())
babylon := app.NewBabylonApp(logger, db, nil, true, map[int64]bool{}, app.DefaultNodeHome, FlagPeriodValue, app.MakeEncodingConfig(), privSigner, sdksimapp.EmptyAppOptions{}, interBlockCacheOpt())

fmt.Printf(
"running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n",
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/util/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func init() {
}

func initEncodingConfigAndCdc() (params.EncodingConfig, codec.Codec) {
encodingConfig := babylonApp.MakeTestEncodingConfig()
encodingConfig := babylonApp.MakeEncodingConfig()

encodingConfig.InterfaceRegistry.RegisterImplementations(
(*sdk.Msg)(nil),
Expand Down
15 changes: 8 additions & 7 deletions test/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ import (

tm "github.com/cosmos/cosmos-sdk/client/grpc/tmservice"

"github.com/babylonchain/babylon/app"
appparams "github.com/babylonchain/babylon/app/params"
"github.com/babylonchain/babylon/testutil/datagen"
bbn "github.com/babylonchain/babylon/types"
btccheckpoint "github.com/babylonchain/babylon/x/btccheckpoint/types"
lightclient "github.com/babylonchain/babylon/x/btclightclient/types"
"github.com/btcsuite/btcd/wire"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
Expand All @@ -22,6 +16,13 @@ import (
acctypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/tendermint/tendermint/types"
"google.golang.org/grpc"

"github.com/babylonchain/babylon/app"
appparams "github.com/babylonchain/babylon/app/params"
"github.com/babylonchain/babylon/testutil/datagen"
bbn "github.com/babylonchain/babylon/types"
btccheckpoint "github.com/babylonchain/babylon/x/btccheckpoint/types"
lightclient "github.com/babylonchain/babylon/x/btclightclient/types"
)

type TestTxSender struct {
Expand All @@ -37,7 +38,7 @@ func NewTestTxSender(
genesisPath string,
conn *grpc.ClientConn,
) (*TestTxSender, error) {
cfg := app.MakeTestEncodingConfig()
cfg := app.MakeEncodingConfig()

kb, err := keyring.New("babylond", "test", keyringPath, nil, cfg.Marshaler)

Expand Down
Loading

0 comments on commit 9aadd53

Please sign in to comment.