Skip to content

Commit

Permalink
Rename *codec.Codec to *codec.LegacyAmino (cosmos#6991)
Browse files Browse the repository at this point in the history
* Rename *codec.Codec to *codec.LegacyAmino

* Implement requested changes

Co-authored-by: Aaron Craelius <[email protected]>
  • Loading branch information
dauTT and aaronc authored Aug 10, 2020
1 parent c3a67ff commit f66b7ca
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 37 deletions.
8 changes: 4 additions & 4 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ var _ App = (*SimApp)(nil)
// capabilities aren't needed for testing.
type SimApp struct {
*baseapp.BaseApp
cdc *codec.Codec
cdc *codec.LegacyAmino
appCodec codec.Marshaler
interfaceRegistry types.InterfaceRegistry

Expand Down Expand Up @@ -392,10 +392,10 @@ func NewSimApp(
return app
}

// MakeCodecs constructs the *std.Codec and *codec.Codec instances used by
// MakeCodecs constructs the *std.Codec and *codec.LegacyAmino instances used by
// simapp. It is useful for tests and clients who do not want to construct the
// full simapp
func MakeCodecs() (codec.Marshaler, *codec.Codec) {
func MakeCodecs() (codec.Marshaler, *codec.LegacyAmino) {
config := MakeEncodingConfig()
return config.Marshaler, config.Amino
}
Expand Down Expand Up @@ -450,7 +450,7 @@ func (app *SimApp) BlockedAddrs() map[string]bool {
//
// NOTE: This is solely to be used for testing purposes as it may be desirable
// for modules to register their own custom testing types.
func (app *SimApp) Codec() *codec.Codec {
func (app *SimApp) LegacyAmino() *codec.LegacyAmino {
return app.cdc
}

Expand Down
2 changes: 1 addition & 1 deletion app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestSimAppExport(t *testing.T) {
app := NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0)

genesisState := NewDefaultGenesisState()
stateBytes, err := codec.MarshalJSONIndent(app.Codec(), genesisState)
stateBytes, err := codec.MarshalJSONIndent(app.LegacyAmino(), genesisState)
require.NoError(t, err)

// Initialize the chain
Expand Down
2 changes: 1 addition & 1 deletion params/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ type EncodingConfig struct {
InterfaceRegistry types.InterfaceRegistry
Marshaler codec.Marshaler
TxConfig client.TxConfig
Amino *codec.Codec
Amino *codec.LegacyAmino
}
8 changes: 4 additions & 4 deletions sim_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ func BenchmarkFullAppSimulation(b *testing.B) {

// run randomized simulation
_, simParams, simErr := simulation.SimulateFromSeed(
b, os.Stdout, app.BaseApp, AppStateFn(app.Codec(), app.SimulationManager()),
SimulationOperations(app, app.Codec(), config),
b, os.Stdout, app.BaseApp, AppStateFn(app.LegacyAmino(), app.SimulationManager()),
SimulationOperations(app, app.LegacyAmino(), config),
app.ModuleAccountAddrs(), config,
)

Expand Down Expand Up @@ -69,8 +69,8 @@ func BenchmarkInvariants(b *testing.B) {

// run randomized simulation
_, simParams, simErr := simulation.SimulateFromSeed(
b, os.Stdout, app.BaseApp, AppStateFn(app.Codec(), app.SimulationManager()),
SimulationOperations(app, app.Codec(), config),
b, os.Stdout, app.BaseApp, AppStateFn(app.LegacyAmino(), app.SimulationManager()),
SimulationOperations(app, app.LegacyAmino(), config),
app.ModuleAccountAddrs(), config,
)

Expand Down
24 changes: 12 additions & 12 deletions sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ func TestFullAppSimulation(t *testing.T) {

// run randomized simulation
_, simParams, simErr := simulation.SimulateFromSeed(
t, os.Stdout, app.BaseApp, AppStateFn(app.Codec(), app.SimulationManager()),
SimulationOperations(app, app.Codec(), config),
t, os.Stdout, app.BaseApp, AppStateFn(app.LegacyAmino(), app.SimulationManager()),
SimulationOperations(app, app.LegacyAmino(), config),
app.ModuleAccountAddrs(), config,
)

Expand Down Expand Up @@ -104,8 +104,8 @@ func TestAppImportExport(t *testing.T) {

// Run randomized simulation
_, simParams, simErr := simulation.SimulateFromSeed(
t, os.Stdout, app.BaseApp, AppStateFn(app.Codec(), app.SimulationManager()),
SimulationOperations(app, app.Codec(), config),
t, os.Stdout, app.BaseApp, AppStateFn(app.LegacyAmino(), app.SimulationManager()),
SimulationOperations(app, app.LegacyAmino(), config),
app.ModuleAccountAddrs(), config,
)

Expand Down Expand Up @@ -137,12 +137,12 @@ func TestAppImportExport(t *testing.T) {
require.Equal(t, "SimApp", newApp.Name())

var genesisState GenesisState
err = app.Codec().UnmarshalJSON(appState, &genesisState)
err = app.LegacyAmino().UnmarshalJSON(appState, &genesisState)
require.NoError(t, err)

ctxA := app.NewContext(true, abci.Header{Height: app.LastBlockHeight()})
ctxB := newApp.NewContext(true, abci.Header{Height: app.LastBlockHeight()})
newApp.mm.InitGenesis(ctxB, app.Codec(), genesisState)
newApp.mm.InitGenesis(ctxB, app.LegacyAmino(), genesisState)
newApp.StoreConsensusParams(ctxB, consensusParams)

fmt.Printf("comparing stores...\n")
Expand Down Expand Up @@ -195,8 +195,8 @@ func TestAppSimulationAfterImport(t *testing.T) {

// Run randomized simulation
stopEarly, simParams, simErr := simulation.SimulateFromSeed(
t, os.Stdout, app.BaseApp, AppStateFn(app.Codec(), app.SimulationManager()),
SimulationOperations(app, app.Codec(), config),
t, os.Stdout, app.BaseApp, AppStateFn(app.LegacyAmino(), app.SimulationManager()),
SimulationOperations(app, app.LegacyAmino(), config),
app.ModuleAccountAddrs(), config,
)

Expand Down Expand Up @@ -237,8 +237,8 @@ func TestAppSimulationAfterImport(t *testing.T) {
})

_, _, err = simulation.SimulateFromSeed(
t, os.Stdout, newApp.BaseApp, AppStateFn(app.Codec(), app.SimulationManager()),
SimulationOperations(newApp, newApp.Codec(), config),
t, os.Stdout, newApp.BaseApp, AppStateFn(app.LegacyAmino(), app.SimulationManager()),
SimulationOperations(newApp, newApp.LegacyAmino(), config),
newApp.ModuleAccountAddrs(), config,
)
require.NoError(t, err)
Expand Down Expand Up @@ -282,8 +282,8 @@ func TestAppStateDeterminism(t *testing.T) {
)

_, _, err := simulation.SimulateFromSeed(
t, os.Stdout, app.BaseApp, AppStateFn(app.Codec(), app.SimulationManager()),
SimulationOperations(app, app.Codec(), config),
t, os.Stdout, app.BaseApp, AppStateFn(app.LegacyAmino(), app.SimulationManager()),
SimulationOperations(app, app.LegacyAmino(), config),
app.ModuleAccountAddrs(), config,
)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion simd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var (
WithJSONMarshaler(encodingConfig.Marshaler).
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
WithTxConfig(encodingConfig.TxConfig).
WithCodec(encodingConfig.Amino).
WithLegacyAmino(encodingConfig.Amino).
WithInput(os.Stdin).
WithAccountRetriever(types.NewAccountRetriever(encodingConfig.Marshaler)).
WithBroadcastMode(flags.BroadcastBlock).
Expand Down
6 changes: 3 additions & 3 deletions state.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
// AppStateFn returns the initial application state using a genesis or the simulation parameters.
// It panics if the user provides files for both of them.
// If a file is not given for the genesis or the sim params, it creates a randomized one.
func AppStateFn(cdc *codec.Codec, simManager *module.SimulationManager) simtypes.AppStateFn {
func AppStateFn(cdc *codec.LegacyAmino, simManager *module.SimulationManager) simtypes.AppStateFn {
return func(r *rand.Rand, accs []simtypes.Account, config simtypes.Config,
) (appState json.RawMessage, simAccs []simtypes.Account, chainID string, genesisTimestamp time.Time) {

Expand Down Expand Up @@ -71,7 +71,7 @@ func AppStateFn(cdc *codec.Codec, simManager *module.SimulationManager) simtypes
// AppStateRandomizedFn creates calls each module's GenesisState generator function
// and creates the simulation params
func AppStateRandomizedFn(
simManager *module.SimulationManager, r *rand.Rand, cdc *codec.Codec,
simManager *module.SimulationManager, r *rand.Rand, cdc *codec.LegacyAmino,
accs []simtypes.Account, genesisTimestamp time.Time, appParams simtypes.AppParams,
) (json.RawMessage, []simtypes.Account) {
numAccs := int64(len(accs))
Expand Down Expand Up @@ -125,7 +125,7 @@ func AppStateRandomizedFn(

// AppStateFromGenesisFileFn util function to generate the genesis AppState
// from a genesis.json file.
func AppStateFromGenesisFileFn(r io.Reader, cdc *codec.Codec, genesisFile string) (tmtypes.GenesisDoc, []simtypes.Account) {
func AppStateFromGenesisFileFn(r io.Reader, cdc *codec.LegacyAmino, genesisFile string) (tmtypes.GenesisDoc, []simtypes.Account) {
bytes, err := ioutil.ReadFile(genesisFile)
if err != nil {
panic(err)
Expand Down
16 changes: 8 additions & 8 deletions test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func Setup(isCheckTx bool) *SimApp {
if !isCheckTx {
// init chain must be called to stop deliverState from being nil
genesisState := NewDefaultGenesisState()
stateBytes, err := codec.MarshalJSONIndent(app.Codec(), genesisState)
stateBytes, err := codec.MarshalJSONIndent(app.LegacyAmino(), genesisState)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -82,7 +82,7 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs

// set genesis accounts
authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs)
genesisState[authtypes.ModuleName] = app.Codec().MustMarshalJSON(authGenesis)
genesisState[authtypes.ModuleName] = app.LegacyAmino().MustMarshalJSON(authGenesis)

validators := make([]stakingtypes.Validator, 0, len(valSet.Validators))
delegations := make([]stakingtypes.Delegation, 0, len(valSet.Validators))
Expand Down Expand Up @@ -110,7 +110,7 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs

// set validators and delegations
stakingGenesis := stakingtypes.NewGenesisState(stakingtypes.DefaultParams(), validators, delegations)
genesisState[stakingtypes.ModuleName] = app.Codec().MustMarshalJSON(stakingGenesis)
genesisState[stakingtypes.ModuleName] = app.LegacyAmino().MustMarshalJSON(stakingGenesis)

totalSupply := sdk.NewCoins()
for _, b := range balances {
Expand All @@ -120,9 +120,9 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs

// update total supply
bankGenesis := banktypes.NewGenesisState(banktypes.DefaultGenesisState().Params, balances, totalSupply, []banktypes.Metadata{})
genesisState[banktypes.ModuleName] = app.Codec().MustMarshalJSON(bankGenesis)
genesisState[banktypes.ModuleName] = app.LegacyAmino().MustMarshalJSON(bankGenesis)

stateBytes, err := codec.MarshalJSONIndent(app.Codec(), genesisState)
stateBytes, err := codec.MarshalJSONIndent(app.LegacyAmino(), genesisState)
require.NoError(t, err)

// init chain will set the validator set and initialize the genesis accounts
Expand Down Expand Up @@ -156,17 +156,17 @@ func SetupWithGenesisAccounts(genAccs []authtypes.GenesisAccount, balances ...ba
genesisState := NewDefaultGenesisState()

authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs)
genesisState[authtypes.ModuleName] = app.Codec().MustMarshalJSON(authGenesis)
genesisState[authtypes.ModuleName] = app.LegacyAmino().MustMarshalJSON(authGenesis)

totalSupply := sdk.NewCoins()
for _, b := range balances {
totalSupply = totalSupply.Add(b.Coins...)
}

bankGenesis := banktypes.NewGenesisState(banktypes.DefaultGenesisState().Params, balances, totalSupply, []banktypes.Metadata{})
genesisState[banktypes.ModuleName] = app.Codec().MustMarshalJSON(bankGenesis)
genesisState[banktypes.ModuleName] = app.LegacyAmino().MustMarshalJSON(bankGenesis)

stateBytes, err := codec.MarshalJSONIndent(app.Codec(), genesisState)
stateBytes, err := codec.MarshalJSONIndent(app.LegacyAmino(), genesisState)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type App interface {

// The application types codec.
// NOTE: This shoult be sealed before being returned.
Codec() *codec.Codec
LegacyAmino() *codec.LegacyAmino

// Application updates every begin block.
BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock
Expand Down
4 changes: 2 additions & 2 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func SetupSimulation(dirPrefix, dbName string) (simtypes.Config, dbm.DB, string,

// SimulationOperations retrieves the simulation params from the provided file path
// and returns all the modules weighted operations
func SimulationOperations(app App, cdc *codec.Codec, config simtypes.Config) []simtypes.WeightedOperation {
func SimulationOperations(app App, cdc *codec.LegacyAmino, config simtypes.Config) []simtypes.WeightedOperation {
simState := module.SimulationState{
AppParams: make(simtypes.AppParams),
Cdc: cdc,
Expand All @@ -61,7 +61,7 @@ func SimulationOperations(app App, cdc *codec.Codec, config simtypes.Config) []s
panic(err)
}

app.Codec().MustUnmarshalJSON(bz, &simState.AppParams)
app.LegacyAmino().MustUnmarshalJSON(bz, &simState.AppParams)
}

simState.ParamChanges = app.SimulationManager().GenerateParamChanges(config.Seed)
Expand Down

0 comments on commit f66b7ca

Please sign in to comment.