diff --git a/x/distribution/keeper/allocation_test.go b/x/distribution/keeper/allocation_test.go index d32b43690cac..8cf3bb0ceea1 100644 --- a/x/distribution/keeper/allocation_test.go +++ b/x/distribution/keeper/allocation_test.go @@ -21,12 +21,14 @@ func TestAllocateTokensToValidatorWithCommission(t *testing.T) { ctx := app.BaseApp.NewContext(false, tmproto.Header{}) addrs := simapp.AddTestAddrs(app, ctx, 3, sdk.NewInt(1234)) + randomEthAddress, err := teststaking.RandomEthAddress() + require.NoError(t, err) valAddrs := simapp.ConvertAddrsToValAddrs(addrs) tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper) // create validator with 50% commission tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0)) - tstaking.CreateValidator(sdk.ValAddress(addrs[0]), valConsPk1, sdk.NewInt(100), true) + tstaking.CreateValidator(sdk.ValAddress(addrs[0]), valConsPk1, sdk.NewInt(100), sdk.AccAddress(valConsPk1.Address()), *randomEthAddress, true) val := app.StakingKeeper.Validator(ctx, valAddrs[0]) // allocate tokens @@ -53,16 +55,20 @@ func TestAllocateTokensToManyValidators(t *testing.T) { app.DistrKeeper.SetFeePool(ctx, disttypes.InitialFeePool()) addrs := simapp.AddTestAddrs(app, ctx, 2, sdk.NewInt(1234)) + randomEthAddress, err := teststaking.RandomEthAddress() + require.NoError(t, err) valAddrs := simapp.ConvertAddrsToValAddrs(addrs) tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper) // create validator with 50% commission tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0)) - tstaking.CreateValidator(valAddrs[0], valConsPk1, sdk.NewInt(100), true) + tstaking.CreateValidator(valAddrs[0], valConsPk1, sdk.NewInt(100), sdk.AccAddress(valConsPk1.Address()), *randomEthAddress, true) // create second validator with 0% commission + randomEthAddress2, err := teststaking.RandomEthAddress() + require.NoError(t, err) tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDec(0), sdk.NewDec(0), sdk.NewDec(0)) - tstaking.CreateValidator(valAddrs[1], valConsPk2, sdk.NewInt(100), true) + tstaking.CreateValidator(valAddrs[1], valConsPk2, sdk.NewInt(100), sdk.AccAddress(valConsPk2.Address()), *randomEthAddress2, true) abciValA := abci.Validator{ Address: valConsPk1.Address(), @@ -131,16 +137,22 @@ func TestAllocateTokensTruncation(t *testing.T) { tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper) // create validator with 10% commission + randomEthAddress, err := teststaking.RandomEthAddress() + require.NoError(t, err) tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(1, 1), sdk.NewDecWithPrec(1, 1), sdk.NewDec(0)) - tstaking.CreateValidator(valAddrs[0], valConsPk1, sdk.NewInt(110), true) + tstaking.CreateValidator(valAddrs[0], valConsPk1, sdk.NewInt(110), sdk.AccAddress(valConsPk1.Address()), *randomEthAddress, true) // create second validator with 10% commission + randomEthAddress2, err := teststaking.RandomEthAddress() + require.NoError(t, err) tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(1, 1), sdk.NewDecWithPrec(1, 1), sdk.NewDec(0)) - tstaking.CreateValidator(valAddrs[1], valConsPk2, sdk.NewInt(100), true) + tstaking.CreateValidator(valAddrs[1], valConsPk2, sdk.NewInt(100), sdk.AccAddress(valConsPk2.Address()), *randomEthAddress2, true) // create third validator with 10% commission + randomEthAddress3, err := teststaking.RandomEthAddress() + require.NoError(t, err) tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(1, 1), sdk.NewDecWithPrec(1, 1), sdk.NewDec(0)) - tstaking.CreateValidator(valAddrs[2], valConsPk3, sdk.NewInt(100), true) + tstaking.CreateValidator(valAddrs[2], valConsPk3, sdk.NewInt(100), sdk.AccAddress(valConsPk3.Address()), *randomEthAddress3, true) abciValA := abci.Validator{ Address: valConsPk1.Address(), diff --git a/x/distribution/keeper/delegation_test.go b/x/distribution/keeper/delegation_test.go index 7b18c0241f3b..060da3282bcc 100644 --- a/x/distribution/keeper/delegation_test.go +++ b/x/distribution/keeper/delegation_test.go @@ -26,8 +26,10 @@ func TestCalculateRewardsBasic(t *testing.T) { valAddrs := simapp.ConvertAddrsToValAddrs(addr) // create validator with 50% commission + randomEthAddress, err := teststaking.RandomEthAddress() + require.NoError(t, err) tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0)) - tstaking.CreateValidator(valAddrs[0], valConsPk1, sdk.NewInt(100), true) + tstaking.CreateValidator(valAddrs[0], valConsPk1, sdk.NewInt(100), sdk.AccAddress(valConsPk1.Address()), *randomEthAddress, true) // end block to bond validator and start new block staking.EndBlocker(ctx, app.StakingKeeper) @@ -82,7 +84,9 @@ func TestCalculateRewardsAfterSlash(t *testing.T) { // create validator with 50% commission tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0)) valPower := int64(100) - tstaking.CreateValidatorWithValPower(valAddrs[0], valConsPk1, valPower, true) + randomEthAddress, err := teststaking.RandomEthAddress() + require.NoError(t, err) + tstaking.CreateValidatorWithValPower(valAddrs[0], valConsPk1, valPower, sdk.AccAddress(valConsPk1.Address()), *randomEthAddress, true) // end block to bond validator staking.EndBlocker(ctx, app.StakingKeeper) @@ -143,9 +147,11 @@ func TestCalculateRewardsAfterManySlashes(t *testing.T) { valAddrs := simapp.ConvertAddrsToValAddrs(addr) // create validator with 50% commission + randomEthAddress, err := teststaking.RandomEthAddress() + require.NoError(t, err) valPower := int64(100) tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0)) - tstaking.CreateValidatorWithValPower(valAddrs[0], valConsPk1, valPower, true) + tstaking.CreateValidatorWithValPower(valAddrs[0], valConsPk1, valPower, sdk.AccAddress(valConsPk1.Address()), *randomEthAddress, true) // end block to bond validator staking.EndBlocker(ctx, app.StakingKeeper) @@ -218,8 +224,10 @@ func TestCalculateRewardsMultiDelegator(t *testing.T) { valAddrs := simapp.ConvertAddrsToValAddrs(addr) // create validator with 50% commission + randomEthAddress, err := teststaking.RandomEthAddress() + require.NoError(t, err) tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0)) - tstaking.CreateValidator(valAddrs[0], valConsPk1, sdk.NewInt(100), true) + tstaking.CreateValidator(valAddrs[0], valConsPk1, sdk.NewInt(100), sdk.AccAddress(valConsPk1.Address()), *randomEthAddress, true) // end block to bond validator staking.EndBlocker(ctx, app.StakingKeeper) @@ -290,9 +298,11 @@ func TestWithdrawDelegationRewardsBasic(t *testing.T) { app.AccountKeeper.SetModuleAccount(ctx, distrAcc) // create validator with 50% commission + randomEthAddress, err := teststaking.RandomEthAddress() + require.NoError(t, err) power := int64(100) tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0)) - valTokens := tstaking.CreateValidatorWithValPower(valAddrs[0], valConsPk1, power, true) + valTokens := tstaking.CreateValidatorWithValPower(valAddrs[0], valConsPk1, power, sdk.AccAddress(valConsPk1.Address()), *randomEthAddress, true) // assert correct initial balance expTokens := balanceTokens.Sub(valTokens) @@ -320,7 +330,7 @@ func TestWithdrawDelegationRewardsBasic(t *testing.T) { require.Equal(t, uint64(2), app.DistrKeeper.GetValidatorHistoricalReferenceCount(ctx)) // withdraw rewards - _, err := app.DistrKeeper.WithdrawDelegationRewards(ctx, sdk.AccAddress(valAddrs[0]), valAddrs[0]) + _, err = app.DistrKeeper.WithdrawDelegationRewards(ctx, sdk.AccAddress(valAddrs[0]), valAddrs[0]) require.Nil(t, err) // historical count should still be 2 (added one record, cleared one) @@ -354,9 +364,11 @@ func TestCalculateRewardsAfterManySlashesInSameBlock(t *testing.T) { tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper) // create validator with 50% commission + randomEthAddress, err := teststaking.RandomEthAddress() + require.NoError(t, err) valPower := int64(100) tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0)) - tstaking.CreateValidatorWithValPower(valAddrs[0], valConsPk1, valPower, true) + tstaking.CreateValidatorWithValPower(valAddrs[0], valConsPk1, valPower, sdk.AccAddress(valConsPk1.Address()), *randomEthAddress, true) // end block to bond validator staking.EndBlocker(ctx, app.StakingKeeper) @@ -422,9 +434,11 @@ func TestCalculateRewardsMultiDelegatorMultiSlash(t *testing.T) { valAddrs := simapp.ConvertAddrsToValAddrs(addr) // create validator with 50% commission + randomEthAddress, err := teststaking.RandomEthAddress() + require.NoError(t, err) tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0)) valPower := int64(100) - tstaking.CreateValidatorWithValPower(valAddrs[0], valConsPk1, valPower, true) + tstaking.CreateValidatorWithValPower(valAddrs[0], valConsPk1, valPower, sdk.AccAddress(valConsPk1.Address()), *randomEthAddress, true) // end block to bond validator staking.EndBlocker(ctx, app.StakingKeeper) @@ -506,8 +520,10 @@ func TestCalculateRewardsMultiDelegatorMultWithdraw(t *testing.T) { tokens := sdk.DecCoins{sdk.NewDecCoinFromDec(sdk.DefaultBondDenom, sdk.NewDec(initial))} // create validator with 50% commission + randomEthAddress, err := teststaking.RandomEthAddress() + require.NoError(t, err) tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0)) - tstaking.CreateValidator(valAddrs[0], valConsPk1, sdk.NewInt(100), true) + tstaking.CreateValidator(valAddrs[0], valConsPk1, sdk.NewInt(100), sdk.AccAddress(valConsPk1.Address()), *randomEthAddress, true) // end block to bond validator staking.EndBlocker(ctx, app.StakingKeeper) @@ -545,7 +561,7 @@ func TestCalculateRewardsMultiDelegatorMultWithdraw(t *testing.T) { app.DistrKeeper.AllocateTokensToValidator(ctx, val, tokens) // first delegator withdraws - _, err := app.DistrKeeper.WithdrawDelegationRewards(ctx, sdk.AccAddress(valAddrs[0]), valAddrs[0]) + _, err = app.DistrKeeper.WithdrawDelegationRewards(ctx, sdk.AccAddress(valAddrs[0]), valAddrs[0]) require.NoError(t, err) // second delegator withdraws diff --git a/x/distribution/keeper/grpc_query_test.go b/x/distribution/keeper/grpc_query_test.go index d51f4a28a0ba..9aaef6fa8a64 100644 --- a/x/distribution/keeper/grpc_query_test.go +++ b/x/distribution/keeper/grpc_query_test.go @@ -344,7 +344,9 @@ func (suite *KeeperTestSuite) TestGRPCDelegationRewards() { tstaking := teststaking.NewHelper(suite.T(), ctx, app.StakingKeeper) tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0)) - tstaking.CreateValidator(valAddrs[0], valConsPk1, sdk.NewInt(100), true) + randomEthAddress, err := teststaking.RandomEthAddress() + suite.NoError(err) + tstaking.CreateValidator(valAddrs[0], valConsPk1, sdk.NewInt(100), sdk.AccAddress(valConsPk1.Address()), *randomEthAddress, true) staking.EndBlocker(ctx, app.StakingKeeper) ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) diff --git a/x/distribution/keeper/querier_test.go b/x/distribution/keeper/querier_test.go index 9e1fe7cccce5..a17394d9f089 100644 --- a/x/distribution/keeper/querier_test.go +++ b/x/distribution/keeper/querier_test.go @@ -175,7 +175,9 @@ func TestQueries(t *testing.T) { // test delegation rewards query tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper) tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0)) - tstaking.CreateValidator(valOpAddr1, valConsPk1, sdk.NewInt(100), true) + randomEthAddress, err := teststaking.RandomEthAddress() + require.NoError(t, err) + tstaking.CreateValidator(valOpAddr1, valConsPk1, sdk.NewInt(100), sdk.AccAddress(valConsPk1.Address()), *randomEthAddress, true) staking.EndBlocker(ctx, app.StakingKeeper) diff --git a/x/evidence/keeper/infraction_test.go b/x/evidence/keeper/infraction_test.go index 4c7368b1df7c..83fec06b3b6e 100644 --- a/x/evidence/keeper/infraction_test.go +++ b/x/evidence/keeper/infraction_test.go @@ -16,9 +16,11 @@ func (suite *KeeperTestSuite) TestHandleDoubleSign() { power := int64(100) stakingParams := suite.app.StakingKeeper.GetParams(ctx) operatorAddr, val := valAddresses[0], pubkeys[0] + randomEthAddress, err := teststaking.RandomEthAddress() + suite.NoError(err) tstaking := teststaking.NewHelper(suite.T(), ctx, suite.app.StakingKeeper) - selfDelegation := tstaking.CreateValidatorWithValPower(operatorAddr, val, power, true) + selfDelegation := tstaking.CreateValidatorWithValPower(operatorAddr, val, power, sdk.AccAddress(val.Address()), *randomEthAddress, true) // execute end-blocker and verify validator attributes staking.EndBlocker(ctx, suite.app.StakingKeeper) @@ -82,9 +84,11 @@ func (suite *KeeperTestSuite) TestHandleDoubleSign_TooOld() { power := int64(100) stakingParams := suite.app.StakingKeeper.GetParams(ctx) operatorAddr, val := valAddresses[0], pubkeys[0] + randomEthAddress, err := teststaking.RandomEthAddress() + suite.NoError(err) tstaking := teststaking.NewHelper(suite.T(), ctx, suite.app.StakingKeeper) - amt := tstaking.CreateValidatorWithValPower(operatorAddr, val, power, true) + amt := tstaking.CreateValidatorWithValPower(operatorAddr, val, power, sdk.AccAddress(val.Address()), *randomEthAddress, true) // execute end-blocker and verify validator attributes staking.EndBlocker(ctx, suite.app.StakingKeeper) diff --git a/x/slashing/abci_test.go b/x/slashing/abci_test.go index f2958d4d3b62..b6c4180b498a 100644 --- a/x/slashing/abci_test.go +++ b/x/slashing/abci_test.go @@ -27,7 +27,9 @@ func TestBeginBlocker(t *testing.T) { // bond the validator power := int64(100) - amt := tstaking.CreateValidatorWithValPower(addr, pk, power, true) + randomEthAddress, err := teststaking.RandomEthAddress() + require.NoError(t, err) + amt := tstaking.CreateValidatorWithValPower(addr, pk, power, sdk.AccAddress(pk.Address()), *randomEthAddress, true) staking.EndBlocker(ctx, app.StakingKeeper) require.Equal( t, app.BankKeeper.GetAllBalances(ctx, sdk.AccAddress(addr)), diff --git a/x/slashing/keeper/keeper_test.go b/x/slashing/keeper/keeper_test.go index 03869e3a74c9..60d0f6e4d706 100644 --- a/x/slashing/keeper/keeper_test.go +++ b/x/slashing/keeper/keeper_test.go @@ -31,7 +31,9 @@ func TestUnJailNotBonded(t *testing.T) { // create max (5) validators all with the same power for i := uint32(0); i < p.MaxValidators; i++ { addr, val := valAddrs[i], pks[i] - tstaking.CreateValidatorWithValPower(addr, val, 100, true) + randomEthAddress, err := teststaking.RandomEthAddress() + require.NoError(t, err) + tstaking.CreateValidatorWithValPower(addr, val, 100, sdk.AccAddress(val.Address()), *randomEthAddress, true) } staking.EndBlocker(ctx, app.StakingKeeper) @@ -40,7 +42,9 @@ func TestUnJailNotBonded(t *testing.T) { // create a 6th validator with less power than the cliff validator (won't be bonded) addr, val := valAddrs[5], pks[5] amt := app.StakingKeeper.TokensFromConsensusPower(ctx, 50) - msg := tstaking.CreateValidatorMsg(addr, val, amt) + randomEthAddress, err := teststaking.RandomEthAddress() + require.NoError(t, err) + msg := tstaking.CreateValidatorMsg(addr, val, amt, sdk.AccAddress(val.Address()), *randomEthAddress) msg.MinSelfDelegation = amt res, err := tstaking.CreateValidatorWithMsg(sdk.WrapSDKContext(ctx), msg) require.NoError(t, err) @@ -91,9 +95,11 @@ func TestHandleNewValidator(t *testing.T) { addr, val := valAddrs[0], pks[0] tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper) ctx = ctx.WithBlockHeight(app.SlashingKeeper.SignedBlocksWindow(ctx) + 1) + randomEthAddress, err := teststaking.RandomEthAddress() + require.NoError(t, err) // Validator created - amt := tstaking.CreateValidatorWithValPower(addr, val, 100, true) + amt := tstaking.CreateValidatorWithValPower(addr, val, 100, sdk.AccAddress(val.Address()), *randomEthAddress, true) staking.EndBlocker(ctx, app.StakingKeeper) require.Equal( @@ -136,9 +142,11 @@ func TestHandleAlreadyJailed(t *testing.T) { pks := simapp.CreateTestPubKeys(1) addr, val := valAddrs[0], pks[0] power := int64(100) + randomEthAddress, err := teststaking.RandomEthAddress() + require.NoError(t, err) tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper) - amt := tstaking.CreateValidatorWithValPower(addr, val, power, true) + amt := tstaking.CreateValidatorWithValPower(addr, val, power, sdk.AccAddress(val.Address()), *randomEthAddress, true) staking.EndBlocker(ctx, app.StakingKeeper) @@ -197,8 +205,10 @@ func TestValidatorDippingInAndOut(t *testing.T) { consAddr := sdk.ConsAddress(addr) tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper) valAddr := sdk.ValAddress(addr) + randomEthAddress, err := teststaking.RandomEthAddress() + require.NoError(t, err) - tstaking.CreateValidatorWithValPower(valAddr, val, power, true) + tstaking.CreateValidatorWithValPower(valAddr, val, power, sdk.AccAddress(val.Address()), *randomEthAddress, true) validatorUpdates := staking.EndBlocker(ctx, app.StakingKeeper) require.Equal(t, 2, len(validatorUpdates)) tstaking.CheckValidator(valAddr, stakingtypes.Bonded, false) @@ -211,7 +221,9 @@ func TestValidatorDippingInAndOut(t *testing.T) { } // kick first validator out of validator set - tstaking.CreateValidatorWithValPower(sdk.ValAddress(pks[1].Address()), pks[1], power+1, true) + randomEthAddress2, err := teststaking.RandomEthAddress() + require.NoError(t, err) + tstaking.CreateValidatorWithValPower(sdk.ValAddress(pks[1].Address()), pks[1], power+1, sdk.AccAddress(pks[1].Address()), *randomEthAddress2, true) validatorUpdates = staking.EndBlocker(ctx, app.StakingKeeper) require.Equal(t, 2, len(validatorUpdates)) tstaking.CheckValidator(sdk.ValAddress(pks[1].Address()), stakingtypes.Bonded, false) diff --git a/x/staking/keeper/msg_server.go b/x/staking/keeper/msg_server.go index 5cae6a123bc9..b1eee85b5389 100644 --- a/x/staking/keeper/msg_server.go +++ b/x/staking/keeper/msg_server.go @@ -424,7 +424,7 @@ func (k msgServer) validateEthereumAddress(ctx sdk.Context, ethAddr string) (typ if err != nil { return types.EthAddress{}, err } - if evmAddr.GetAddress() == types.EthZeroAddress { + if evmAddr.GetAddress() == types.EthZeroAddress.GetAddress() { return types.EthAddress{}, types.ErrValidatorEthereumZeroAddress } if _, found := k.GetValidatorByEthereumAddress(ctx, *evmAddr); found { diff --git a/x/staking/teststaking/helper.go b/x/staking/teststaking/helper.go index 7c39396ab3a7..66cbb46ae713 100644 --- a/x/staking/teststaking/helper.go +++ b/x/staking/teststaking/helper.go @@ -33,26 +33,24 @@ func NewHelper(t *testing.T, ctx sdk.Context, k keeper.Keeper) *Helper { } // CreateValidator calls staking module `MsgServer/CreateValidator` to create a new validator -func (sh *Helper) CreateValidator(addr sdk.ValAddress, pk cryptotypes.PubKey, stakeAmount sdk.Int, ok bool) { +func (sh *Helper) CreateValidator(addr sdk.ValAddress, pk cryptotypes.PubKey, stakeAmount sdk.Int, orchAddress sdk.AccAddress, ethAddress stakingtypes.EthAddress, ok bool) { coin := sdk.NewCoin(sh.Denom, stakeAmount) - sh.createValidator(addr, pk, coin, ok) + sh.createValidator(addr, pk, coin, orchAddress, ethAddress, ok) } // CreateValidatorWithValPower calls staking module `MsgServer/CreateValidator` to create a new validator with zero // commission -func (sh *Helper) CreateValidatorWithValPower(addr sdk.ValAddress, pk cryptotypes.PubKey, valPower int64, ok bool) sdk.Int { +func (sh *Helper) CreateValidatorWithValPower(addr sdk.ValAddress, pk cryptotypes.PubKey, valPower int64, orchAddress sdk.AccAddress, ethAddress stakingtypes.EthAddress, ok bool) sdk.Int { amount := sh.k.TokensFromConsensusPower(sh.Ctx, valPower) coin := sdk.NewCoin(sh.Denom, amount) - sh.createValidator(addr, pk, coin, ok) + sh.createValidator(addr, pk, coin, orchAddress, ethAddress, ok) return amount } // CreateValidatorMsg returns a message used to create validator in this service. -func (sh *Helper) CreateValidatorMsg(addr sdk.ValAddress, pk cryptotypes.PubKey, stakeAmount sdk.Int) *stakingtypes.MsgCreateValidator { +func (sh *Helper) CreateValidatorMsg(addr sdk.ValAddress, pk cryptotypes.PubKey, stakeAmount sdk.Int, orchAddress sdk.AccAddress, ethAddress stakingtypes.EthAddress) *stakingtypes.MsgCreateValidator { coin := sdk.NewCoin(sh.Denom, stakeAmount) - randomEthAddress, err := RandomEthAddress() - require.NoError(sh.t, err) - msg, err := stakingtypes.NewMsgCreateValidator(addr, pk, coin, stakingtypes.Description{}, sh.Commission, sdk.OneInt(), sdk.AccAddress(pk.Address()), *randomEthAddress) + msg, err := stakingtypes.NewMsgCreateValidator(addr, pk, coin, stakingtypes.Description{}, sh.Commission, sdk.OneInt(), orchAddress, ethAddress) require.NoError(sh.t, err) return msg } @@ -62,10 +60,8 @@ func (sh *Helper) CreateValidatorWithMsg(ctx context.Context, msg *stakingtypes. return sh.msgSrvr.CreateValidator(ctx, msg) } -func (sh *Helper) createValidator(addr sdk.ValAddress, pk cryptotypes.PubKey, coin sdk.Coin, ok bool) { - randomEthAddress, err := RandomEthAddress() - require.NoError(sh.t, err) - msg, err := stakingtypes.NewMsgCreateValidator(addr, pk, coin, stakingtypes.Description{}, sh.Commission, sdk.OneInt(), sdk.AccAddress(pk.Address()), *randomEthAddress) +func (sh *Helper) createValidator(addr sdk.ValAddress, pk cryptotypes.PubKey, coin sdk.Coin, orchAddress sdk.AccAddress, ethAddress stakingtypes.EthAddress, ok bool) { + msg, err := stakingtypes.NewMsgCreateValidator(addr, pk, coin, stakingtypes.Description{}, sh.Commission, sdk.OneInt(), orchAddress, ethAddress) require.NoError(sh.t, err) res, err := sh.msgSrvr.CreateValidator(sdk.WrapSDKContext(sh.Ctx), msg) if ok { diff --git a/x/staking/types/ethereum.go b/x/staking/types/ethereum.go index 61bfe749efda..d5a470f1149c 100644 --- a/x/staking/types/ethereum.go +++ b/x/staking/types/ethereum.go @@ -13,9 +13,10 @@ import ( const ( // ETHContractAddressLen is the length of contract address strings ETHContractAddressLen = 42 - EthZeroAddress = "0x0000000000000000000000000000000000000000" ) +var EthZeroAddress, _ = NewEthAddress("0x0000000000000000000000000000000000000000") + // EthAddress Regular EthAddress type EthAddress struct { address string