Skip to content

Commit

Permalink
feat: add simple validation for fun token fee in set params
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasmatt committed Oct 24, 2024
1 parent dd27f4b commit e0ff7bc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
24 changes: 20 additions & 4 deletions app/evmante/evmante_validate_basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ func (s *TestSuite) TestEthValidateBasicDecorator() {
},
wantErr: "",
},
{
name: "sad: fail to set params",
txSetup: func(deps *evmtest.TestDeps) sdk.Tx {
return evmtest.HappyCreateContractTx(deps)
},
paramsSetup: func(deps *evmtest.TestDeps) evm.Params {
return evm.Params{
CreateFuntokenFee: sdk.NewInt(-1),
}
},
wantErr: "createFuntokenFee cannot be negative: -1",
},
{
name: "happy: ctx recheck should ignore validation",
ctxSetup: func(deps *evmtest.TestDeps) {
Expand Down Expand Up @@ -195,12 +207,16 @@ func (s *TestSuite) TestEthValidateBasicDecorator() {
if tc.ctxSetup != nil {
tc.ctxSetup(&deps)
}
var err error
if tc.paramsSetup != nil {
deps.EvmKeeper.SetParams(deps.Ctx, tc.paramsSetup(&deps))
err = deps.EvmKeeper.SetParams(deps.Ctx, tc.paramsSetup(&deps))
}

if err == nil {
_, err = anteDec.AnteHandle(
deps.Ctx, tx, false, evmtest.NextNoOpAnteHandler,
)
}
_, err := anteDec.AnteHandle(
deps.Ctx, tx, false, evmtest.NextNoOpAnteHandler,
)
if tc.wantErr != "" {
s.Require().ErrorContains(err, tc.wantErr)
return
Expand Down
8 changes: 7 additions & 1 deletion x/evm/keeper/evm_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package keeper

import (
"fmt"
"math/big"

"github.com/NibiruChain/collections"
Expand Down Expand Up @@ -116,8 +117,13 @@ func (k Keeper) GetParams(ctx sdk.Context) (params evm.Params) {
}

// SetParams: Setter for the module parameters.
func (k Keeper) SetParams(ctx sdk.Context, params evm.Params) {
func (k Keeper) SetParams(ctx sdk.Context, params evm.Params) (err error) {
if params.CreateFuntokenFee.IsNegative() {
return fmt.Errorf("createFuntokenFee cannot be negative: %s", params.CreateFuntokenFee)
}

k.EvmState.ModuleParams.Set(ctx, params)
return
}

// SetState updates contract storage and deletes if the value is empty.
Expand Down
5 changes: 4 additions & 1 deletion x/evm/keeper/msg_update_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ func (k *Keeper) UpdateParams(
return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority, expected %s, got %s", k.authority.String(), req.Authority)
}
ctx := sdk.UnwrapSDKContext(goCtx)
k.SetParams(ctx, req.Params)
err = k.SetParams(ctx, req.Params)
if err != nil {
return nil, errors.Wrapf(err, "failed to set params")
}
return &evm.MsgUpdateParamsResponse{}, nil
}

0 comments on commit e0ff7bc

Please sign in to comment.