diff --git a/x/evm/keeper/state_transition.go b/x/evm/keeper/state_transition.go index 4e3438b27c..332744a4ba 100644 --- a/x/evm/keeper/state_transition.go +++ b/x/evm/keeper/state_transition.go @@ -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", ) } diff --git a/x/evm/keeper/state_transition_test.go b/x/evm/keeper/state_transition_test.go new file mode 100644 index 0000000000..2bd2c8e94f --- /dev/null +++ b/x/evm/keeper/state_transition_test.go @@ -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) + } + }) + } + +}