Skip to content

Commit

Permalink
Merge pull request #120 from binance-chain/develop
Browse files Browse the repository at this point in the history
Release v0.25.0 binance.17
  • Loading branch information
yutianwu authored Apr 16, 2019
2 parents 2fbc5aa + a2761ec commit 7b2491f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
1 change: 1 addition & 0 deletions types/stake.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type Validator interface {
GetJailed() bool // whether the validator is jailed
GetMoniker() string // moniker of the validator
GetStatus() BondStatus // status of the validator
GetFeeAddr() AccAddress // fee address of validator
GetOperator() ValAddress // operator address to receive/return validators coins
GetConsPubKey() crypto.PubKey // validation consensus pubkey
GetConsAddr() ConsAddress // validation consensus address
Expand Down
26 changes: 18 additions & 8 deletions x/gov/endblocker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"

"github.com/cosmos/cosmos-sdk/x/mock"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/gov"
"github.com/cosmos/cosmos-sdk/x/stake"
Expand All @@ -16,7 +18,9 @@ import (
func TestTickExpiredDepositPeriod(t *testing.T) {
mapp, ck, keeper, stakeKeeper, addrs, pubKeys, _ := getMockApp(t, 10)

validator := stake.NewValidator(sdk.ValAddress(addrs[0]), pubKeys[0], stake.Description{})
_, feeAccount := mock.GeneratePrivKeyAddressPairs(1)
validator := stake.NewValidatorWithFeeAddr(feeAccount[0], sdk.ValAddress(addrs[0]), pubKeys[0], stake.Description{})

mapp.BeginBlock(abci.RequestBeginBlock{})
ctx := mapp.BaseApp.NewContext(sdk.RunTxModeDeliver, abci.Header{ProposerAddress: pubKeys[0].Address()})

Expand Down Expand Up @@ -55,9 +59,9 @@ func TestTickExpiredDepositPeriod(t *testing.T) {
require.True(t, gov.ShouldPopInactiveProposalQueue(ctx, keeper))
gov.EndBlocker(ctx, keeper)

validatorCoins := ck.GetCoins(ctx, addrs[0])
validatorCoins := ck.GetCoins(ctx, feeAccount[0])
// check distribute deposits to proposer
require.Equal(t, validatorCoins, sdk.Coins{sdk.NewCoin(gov.DefaultDepositDenom, 6000e8)})
require.Equal(t, validatorCoins, sdk.Coins{sdk.NewCoin(gov.DefaultDepositDenom, 1000e8)})
require.Equal(t, sdk.Coins(nil), ck.GetCoins(ctx, gov.DepositedCoinsAccAddr))

require.Nil(t, keeper.InactiveProposalQueuePeek(ctx))
Expand All @@ -67,7 +71,9 @@ func TestTickExpiredDepositPeriod(t *testing.T) {
func TestTickMultipleExpiredDepositPeriod(t *testing.T) {
mapp, ck, keeper, stakeKeeper, addrs, pubKeys, _ := getMockApp(t, 10)

validator := stake.NewValidator(sdk.ValAddress(addrs[0]), pubKeys[0], stake.Description{})
_, feeAccount := mock.GeneratePrivKeyAddressPairs(1)
validator := stake.NewValidatorWithFeeAddr(feeAccount[0], sdk.ValAddress(addrs[0]), pubKeys[0], stake.Description{})

mapp.BeginBlock(abci.RequestBeginBlock{})
ctx := mapp.BaseApp.NewContext(sdk.RunTxModeDeliver, abci.Header{ProposerAddress: pubKeys[0].Address()})

Expand Down Expand Up @@ -176,7 +182,9 @@ func TestTickPassedDepositPeriod(t *testing.T) {
func TestTickPassedVotingPeriodRejected(t *testing.T) {
mapp, ck, keeper, stakeKeeper, addrs, pubKeys, _ := getMockApp(t, 10)

validator := stake.NewValidator(sdk.ValAddress(addrs[0]), pubKeys[0], stake.Description{})
_, feeAccount := mock.GeneratePrivKeyAddressPairs(1)
validator := stake.NewValidatorWithFeeAddr(feeAccount[0], sdk.ValAddress(addrs[0]), pubKeys[0], stake.Description{})

mapp.BeginBlock(abci.RequestBeginBlock{})
ctx := mapp.BaseApp.NewContext(sdk.RunTxModeDeliver, abci.Header{ProposerAddress: pubKeys[0].Address()})

Expand Down Expand Up @@ -240,15 +248,17 @@ func TestTickPassedVotingPeriodRejected(t *testing.T) {
require.Equal(t, gov.StatusRejected, keeper.GetProposal(ctx, int64(proposalID)).GetStatus())

// check distribute deposits to proposer
validatorCoins := ck.GetCoins(ctx, addrs[0])
require.Equal(t, validatorCoins, sdk.Coins{sdk.NewCoin(gov.DefaultDepositDenom, 6000e8)})
validatorCoins := ck.GetCoins(ctx, feeAccount[0])
require.Equal(t, validatorCoins, sdk.Coins{sdk.NewCoin(gov.DefaultDepositDenom, 2000e8)})
require.Equal(t, sdk.Coins(nil), ck.GetCoins(ctx, gov.DepositedCoinsAccAddr))
}

func TestTickPassedVotingPeriodPassed(t *testing.T) {
mapp, ck, keeper, stakeKeeper, addrs, pubKeys, _ := getMockApp(t, 3)

validator0 := stake.NewValidator(sdk.ValAddress(addrs[0]), pubKeys[0], stake.Description{})
_, feeAccount := mock.GeneratePrivKeyAddressPairs(1)
validator0 := stake.NewValidatorWithFeeAddr(feeAccount[0], sdk.ValAddress(addrs[0]), pubKeys[0], stake.Description{})

mapp.BeginBlock(abci.RequestBeginBlock{})
ctx := mapp.BaseApp.NewContext(sdk.RunTxModeDeliver, abci.Header{ProposerAddress: pubKeys[0].Address()})

Expand Down
4 changes: 2 additions & 2 deletions x/gov/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ func (keeper Keeper) RefundDeposits(ctx sdk.Context, proposalID int64) {
func (keeper Keeper) DistributeDeposits(ctx sdk.Context, proposalID int64) {
proposerValAddr := ctx.BlockHeader().ProposerAddress
proposerValidator := keeper.vs.ValidatorByConsAddr(ctx, proposerValAddr)
proposerAccAddr := proposerValidator.GetOperator()
proposerAccAddr := proposerValidator.GetFeeAddr()

store := ctx.KVStore(keeper.storeKey)
depositsIterator := keeper.GetDeposits(ctx, proposalID)
Expand All @@ -475,7 +475,7 @@ func (keeper Keeper) DistributeDeposits(ctx sdk.Context, proposalID int64) {
ctx.Logger().Info("distribute empty deposits")
}

_, err := keeper.ck.SendCoins(ctx, DepositedCoinsAccAddr, sdk.AccAddress(proposerAccAddr), depositCoins)
_, err := keeper.ck.SendCoins(ctx, DepositedCoinsAccAddr, proposerAccAddr, depositCoins)
if err != nil {
panic(fmt.Sprintf("distribute deposits error(%s) should not happen", err.Error()))
}
Expand Down

0 comments on commit 7b2491f

Please sign in to comment.