diff --git a/x/evm/types/state_transition.go b/x/evm/types/state_transition.go index a763a4db8..2236ac8d4 100644 --- a/x/evm/types/state_transition.go +++ b/x/evm/types/state_transition.go @@ -62,7 +62,7 @@ func GetHashFn(ctx sdk.Context) vm.GetHashFunc { // get the Tendermint block hash from the current header tmBlockHash := tmHeader.Hash() - // NOTE: if the validator set hash is missint the hash will be returned as nil + // NOTE: if the validator set hash is missing the hash will be returned as nil, // so we need to check for this case to prevent a panic when calling Bytes() if tmBlockHash == nil { return common.Hash{} @@ -160,7 +160,7 @@ func (st StateTransition) TransitionDb(ctx sdk.Context, config ChainConfig) (*Ex recipientLog = fmt.Sprintf("contract address %s", contractAddress.String()) default: if !params.EnableCall { - return nil, ErrCreateDisabled + return nil, ErrCallDisabled } // Increment the nonce for the next transaction (just for evm state transition) diff --git a/x/evm/types/state_transition_test.go b/x/evm/types/state_transition_test.go index c6577c989..ec204fb15 100644 --- a/x/evm/types/state_transition_test.go +++ b/x/evm/types/state_transition_test.go @@ -3,16 +3,67 @@ package types_test import ( "math/big" + abci "github.com/tendermint/tendermint/abci/types" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/ethermint/crypto/ethsecp256k1" ethermint "github.com/cosmos/ethermint/types" "github.com/cosmos/ethermint/x/evm/types" + "github.com/ethereum/go-ethereum/common" ethcmn "github.com/ethereum/go-ethereum/common" ethcrypto "github.com/ethereum/go-ethereum/crypto" ) +func (suite *StateDBTestSuite) TestGetHashFn() { + testCase := []struct { + name string + height uint64 + malleate func() + expEmptyHash bool + }{ + { + "height mismatch", + 100, + func() {}, + true, + }, + { + "nil tendermint hash", + 1, + func() {}, + true, + }, + { + "valid hash", + 1, + func() { + suite.ctx = suite.ctx.WithBlockHeader( + abci.Header{ + ChainID: "ethermint-1", + Height: 1, + ValidatorsHash: []byte("val_hash"), + }, + ) + }, + false, + }, + } + + for _, tc := range testCase { + tc.malleate() + + hash := types.GetHashFn(suite.ctx)(tc.height) + if tc.expEmptyHash { + suite.Require().Equal(common.Hash{}, hash) + } else { + suite.Require().Equal(int64(tc.height), suite.ctx.BlockHeight()) + suite.Require().NotEqual(common.Hash{}, hash) + } + } +} + func (suite *StateDBTestSuite) TestTransitionDb() { suite.stateDB.SetNonce(suite.address, 123) @@ -104,9 +155,52 @@ func (suite *StateDBTestSuite) TestTransitionDb() { }, false, }, + { + "call disabled", + func() { + params := types.NewParams(ethermint.AttoPhoton, true, false) + suite.stateDB.SetParams(params) + }, + types.StateTransition{ + AccountNonce: 123, + Price: big.NewInt(10), + GasLimit: 11, + Recipient: &recipient, + Amount: big.NewInt(50), + Payload: []byte("data"), + ChainID: big.NewInt(1), + Csdb: suite.stateDB, + TxHash: ðcmn.Hash{}, + Sender: suite.address, + Simulate: suite.ctx.IsCheckTx(), + }, + false, + }, + { + "create disabled", + func() { + params := types.NewParams(ethermint.AttoPhoton, false, true) + suite.stateDB.SetParams(params) + }, + types.StateTransition{ + AccountNonce: 123, + Price: big.NewInt(10), + GasLimit: 11, + Recipient: nil, + Amount: big.NewInt(50), + Payload: []byte("data"), + ChainID: big.NewInt(1), + Csdb: suite.stateDB, + TxHash: ðcmn.Hash{}, + Sender: suite.address, + Simulate: suite.ctx.IsCheckTx(), + }, + false, + }, { "nil gas price", func() { + suite.stateDB.SetParams(types.DefaultParams()) invalidGas := sdk.DecCoins{ {Denom: ethermint.AttoPhoton}, }