Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
fedekunze committed Nov 25, 2020
1 parent f5033f5 commit df3e15c
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 2 deletions.
4 changes: 2 additions & 2 deletions x/evm/types/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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)
Expand Down
94 changes: 94 additions & 0 deletions x/evm/types/state_transition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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: &ethcmn.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: &ethcmn.Hash{},
Sender: suite.address,
Simulate: suite.ctx.IsCheckTx(),
},
false,
},
{
"nil gas price",
func() {
suite.stateDB.SetParams(types.DefaultParams())
invalidGas := sdk.DecCoins{
{Denom: ethermint.AttoPhoton},
}
Expand Down

0 comments on commit df3e15c

Please sign in to comment.