Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
fedekunze committed Jul 14, 2021
1 parent 7c7068a commit e27e1aa
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
2 changes: 1 addition & 1 deletion x/evm/keeper/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ func (k Keeper) GetCoinbaseAddress() (common.Address, error) {
if !found {
return common.Address{}, stacktrace.Propagate(
sdkerrors.Wrap(stakingtypes.ErrNoValidatorFound, consAddr.String()),
"failed to retrieve validator from proposer address",
"failed to retrieve validator from block proposer address",
)
}

Expand Down
73 changes: 73 additions & 0 deletions x/evm/keeper/state_transition_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package keeper_test

import (
"fmt"

"github.com/tharsis/ethermint/tests"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

func (suite *KeeperTestSuite) TestGetCoinbaseAddress() {
valOpAddr := tests.GenerateAddress()

testCases := []struct {
msg string
malleate func()
expPass bool
}{
{
"validator not found",
func() {},
false,
},
{
"success",
func() {
valConsAddr, privkey := tests.NewAddrKey()

pkAny, err := codectypes.NewAnyWithValue(privkey.PubKey())
suite.Require().NoError(err)

validator := stakingtypes.Validator{
OperatorAddress: sdk.ValAddress(valOpAddr.Bytes()).String(),
ConsensusPubkey: pkAny,
}

suite.app.StakingKeeper.SetValidator(suite.ctx, validator)
err = suite.app.StakingKeeper.SetValidatorByConsAddr(suite.ctx, validator)
suite.Require().NoError(err)

header := suite.ctx.BlockHeader()
header.ProposerAddress = valConsAddr.Bytes()
suite.ctx = suite.ctx.WithBlockHeader(header)

validator, found := suite.app.StakingKeeper.GetValidatorByConsAddr(suite.ctx, valConsAddr.Bytes())
suite.Require().True(found)

suite.app.EvmKeeper.WithContext(suite.ctx)
suite.Require().NotEmpty(suite.ctx.BlockHeader().ProposerAddress)
},
true,
},
}

for _, tc := range testCases {
suite.Run(fmt.Sprintf("Case %s", tc.msg), func() {
suite.SetupTest() // reset

tc.malleate()

coinbase, err := suite.app.EvmKeeper.GetCoinbaseAddress()
if tc.expPass {
suite.Require().NoError(err)
suite.Require().Equal(valOpAddr, coinbase)
} else {
suite.Require().Error(err)
}
})
}

}

0 comments on commit e27e1aa

Please sign in to comment.