Skip to content

Commit

Permalink
revert(evm): params store key
Browse files Browse the repository at this point in the history
* replace AllowUnprotectedTxs with RejectUnprotectedTx
  • Loading branch information
devon-chain committed Aug 12, 2022
1 parent 74828c9 commit aff4a92
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 11 deletions.
4 changes: 2 additions & 2 deletions app/ante/eth_test.go
Expand Up @@ -30,7 +30,7 @@ func (suite AnteTestSuite) TestEthSigVerificationDecorator() {
testCases := []struct {
name string
tx sdk.Tx
allowUnprotectedTxs bool
rejectUnprotectedTx bool
reCheckTx bool
expPass bool
}{
Expand All @@ -51,7 +51,7 @@ func (suite AnteTestSuite) TestEthSigVerificationDecorator() {
for _, tc := range testCases {
suite.Run(tc.name, func() {
suite.evmParamsOption = func(params *evmtypes.Params) {
params.AllowUnprotectedTxs = tc.allowUnprotectedTxs
params.AllowUnprotectedTxs = !tc.rejectUnprotectedTx
}
suite.SetupTest()
dec := ante.NewEthSigVerificationDecorator(suite.app.EvmKeeper)
Expand Down
2 changes: 2 additions & 0 deletions x/evm/keeper/grpc_query_test.go
Expand Up @@ -405,6 +405,8 @@ func (suite *KeeperTestSuite) TestQueryParams() {

res, err := suite.queryClient.Params(ctx, &types.QueryParamsRequest{})
suite.Require().NoError(err)

expParams.AllowUnprotectedTxs = !expParams.AllowUnprotectedTxs
suite.Require().Equal(expParams, res.Params)
}

Expand Down
3 changes: 3 additions & 0 deletions x/evm/keeper/params.go
Expand Up @@ -9,10 +9,13 @@ import (
// GetParams returns the total set of evm parameters.
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
k.paramSpace.GetParamSet(ctx, &params)
// TODO params store RejectUnprotectedTx, value is the opposite of AllowUnprotectedTxs
params.AllowUnprotectedTxs = !params.AllowUnprotectedTxs
return params
}

// SetParams sets the evm parameters to the param space.
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
// NOTE: params AllowUnprotectedTxs
k.paramSpace.SetParamSet(ctx, &params)
}
6 changes: 5 additions & 1 deletion x/evm/keeper/params_test.go
Expand Up @@ -6,9 +6,13 @@ import (

func (suite *KeeperTestSuite) TestParams() {
params := suite.app.EvmKeeper.GetParams(suite.ctx)
suite.Require().Equal(types.DefaultParams(), params)
defaultParams := types.DefaultParams()
defaultParams.AllowUnprotectedTxs = !defaultParams.AllowUnprotectedTxs
suite.Require().Equal(defaultParams, params)
params.EvmDenom = "inj"
params.AllowUnprotectedTxs = !params.AllowUnprotectedTxs // NOTE
suite.app.EvmKeeper.SetParams(suite.ctx, params)
newParams := suite.app.EvmKeeper.GetParams(suite.ctx)
params.AllowUnprotectedTxs = !params.AllowUnprotectedTxs // NOTE
suite.Require().Equal(newParams, params)
}
4 changes: 3 additions & 1 deletion x/evm/keeper/state_transition_test.go
Expand Up @@ -489,7 +489,9 @@ func (suite *KeeperTestSuite) TestEVMConfig() {
suite.SetupTest()
cfg, err := suite.app.EvmKeeper.EVMConfig(suite.ctx)
suite.Require().NoError(err)
suite.Require().Equal(types.DefaultParams(), cfg.Params)
defaultParams := types.DefaultParams()
defaultParams.AllowUnprotectedTxs = !defaultParams.AllowUnprotectedTxs
suite.Require().Equal(defaultParams, cfg.Params)
// london hardfork is enabled by default
suite.Require().Equal(big.NewInt(0), cfg.BaseFee)
suite.Require().Equal(suite.address, cfg.CoinBase)
Expand Down
2 changes: 1 addition & 1 deletion x/evm/migrations/v2/migrate.go
Expand Up @@ -14,6 +14,6 @@ func MigrateStore(ctx sdk.Context, paramstore *paramtypes.Subspace) error {
}

// add RejectUnprotected
paramstore.Set(ctx, types.ParamStoreKeyAllowUnprotectedTxs, types.DefaultAllowUnprotectedTxs)
paramstore.Set(ctx, types.ParamStoreKeyRejectUnprotectedTx, types.DefaultRejectUnprotectedTx)
return nil
}
6 changes: 3 additions & 3 deletions x/evm/migrations/v2/migrate_test.go
Expand Up @@ -32,7 +32,7 @@ func TestMigrateStore(t *testing.T) {

require.Panics(t, func() {
var result bool
paramstore.Get(ctx, types.ParamStoreKeyAllowUnprotectedTxs, &result)
paramstore.Get(ctx, types.ParamStoreKeyRejectUnprotectedTx, &result)
})

paramstore = paramtypes.NewSubspace(
Expand All @@ -42,6 +42,6 @@ func TestMigrateStore(t *testing.T) {
require.NoError(t, err)

var result bool
paramstore.Get(ctx, types.ParamStoreKeyAllowUnprotectedTxs, &result)
require.Equal(t, types.DefaultAllowUnprotectedTxs, result)
paramstore.Get(ctx, types.ParamStoreKeyRejectUnprotectedTx, &result)
require.Equal(t, types.DefaultRejectUnprotectedTx, result)
}
8 changes: 5 additions & 3 deletions x/evm/types/params.go
Expand Up @@ -20,7 +20,9 @@ var (
// DefaultMinGasMultiplier is 0.5 or 50%
DefaultMinGasMultiplier = sdk.NewDecWithPrec(50, 2)
// DefaultAllowUnprotectedTxs rejects all unprotected txs (i.e false)
DefaultAllowUnprotectedTxs = false
DefaultAllowUnprotectedTxs = true

DefaultRejectUnprotectedTx = false
)

// Parameter keys
Expand All @@ -30,7 +32,7 @@ var (
ParamStoreKeyEnableCall = []byte("EnableCall")
ParamStoreKeyExtraEIPs = []byte("EnableExtraEIPs")
ParamStoreKeyChainConfig = []byte("ChainConfig")
ParamStoreKeyAllowUnprotectedTxs = []byte("AllowUnprotectedTxs")
ParamStoreKeyRejectUnprotectedTx = []byte("RejectUnprotectedTx")

// AvailableExtraEIPs define the list of all EIPs that can be enabled by the
// EVM interpreter. These EIPs are applied in order and can override the
Expand Down Expand Up @@ -77,7 +79,7 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
paramtypes.NewParamSetPair(ParamStoreKeyEnableCall, &p.EnableCall, validateBool),
paramtypes.NewParamSetPair(ParamStoreKeyExtraEIPs, &p.ExtraEIPs, validateEIPs),
paramtypes.NewParamSetPair(ParamStoreKeyChainConfig, &p.ChainConfig, validateChainConfig),
paramtypes.NewParamSetPair(ParamStoreKeyAllowUnprotectedTxs, &p.AllowUnprotectedTxs, validateBool),
paramtypes.NewParamSetPair(ParamStoreKeyRejectUnprotectedTx, &p.AllowUnprotectedTxs, validateBool),
}
}

Expand Down

0 comments on commit aff4a92

Please sign in to comment.