11package vesting_test
22
33import (
4+ stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
45 "testing"
6+ "time"
57
68 "github.com/stretchr/testify/suite"
79 tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
@@ -108,8 +110,22 @@ func (suite *HandlerTestSuite) TestMsgDonateVestingToken() {
108110 addr1 := sdk .AccAddress ([]byte ("addr1_______________" ))
109111 addr2 := sdk .AccAddress ([]byte ("addr2_______________" ))
110112 addr3 := sdk .AccAddress ([]byte ("addr3_______________" ))
113+ addr4 := sdk .AccAddress ([]byte ("addr4_______________" ))
111114
112115 valAddr := sdk .ValAddress ([]byte ("validator___________" ))
116+ suite .app .StakingKeeper .SetValidator (ctx , stakingtypes.Validator {
117+ OperatorAddress : valAddr .String (),
118+ ConsensusPubkey : nil ,
119+ Jailed : false ,
120+ Status : 0 ,
121+ Tokens : sdk .NewInt (2 ),
122+ DelegatorShares : sdk .MustNewDecFromStr ("1.1" ),
123+ Description : stakingtypes.Description {},
124+ UnbondingHeight : 0 ,
125+ UnbondingTime : time.Time {},
126+ Commission : stakingtypes.Commission {},
127+ MinSelfDelegation : sdk .NewInt (1 ),
128+ })
113129
114130 acc1 := suite .app .AccountKeeper .NewAccountWithAddress (ctx , addr1 )
115131 suite .app .AccountKeeper .SetAccount (ctx , acc1 )
@@ -133,6 +149,18 @@ func (suite *HandlerTestSuite) TestMsgDonateVestingToken() {
133149 suite .app .AccountKeeper .SetAccount (ctx , acc3 )
134150 suite .Require ().NoError (simapp .FundAccount (suite .app .BankKeeper , ctx , addr3 , balances ))
135151
152+ acc4 := types .NewPermanentLockedAccount (
153+ suite .app .AccountKeeper .NewAccountWithAddress (ctx , addr4 ).(* authtypes.BaseAccount ), balances ,
154+ )
155+ acc4 .DelegatedVesting = balances
156+ suite .app .AccountKeeper .SetAccount (ctx , acc4 )
157+ suite .app .StakingKeeper .SetDelegation (ctx , stakingtypes.Delegation {
158+ DelegatorAddress : addr4 .String (),
159+ ValidatorAddress : valAddr .String (),
160+ Shares : sdk .MustNewDecFromStr ("0.1" ),
161+ })
162+ suite .Require ().NoError (simapp .FundAccount (suite .app .BankKeeper , ctx , addr4 , balances ))
163+
136164 testCases := []struct {
137165 name string
138166 msg * types.MsgDonateAllVestingTokens
@@ -153,12 +181,19 @@ func (suite *HandlerTestSuite) TestMsgDonateVestingToken() {
153181 msg : types .NewMsgDonateAllVestingTokens (addr3 ),
154182 expectErr : false ,
155183 },
184+ {
185+ name : "donate from vesting account with dust delegation" ,
186+ msg : types .NewMsgDonateAllVestingTokens (addr4 ),
187+ expectErr : false ,
188+ },
156189 }
157190
158191 for _ , tc := range testCases {
159192 tc := tc
160193
161194 suite .Run (tc .name , func () {
195+ // Rollback context after every test case
196+ ctx , _ := ctx .CacheContext ()
162197 res , err := suite .handler (ctx , tc .msg )
163198 if tc .expectErr {
164199 suite .Require ().Error (err )
@@ -178,6 +213,9 @@ func (suite *HandlerTestSuite) TestMsgDonateVestingToken() {
178213 suite .Require ().True (ok )
179214 balance := suite .app .BankKeeper .GetAllBalances (ctx , fromAddr )
180215 suite .Require ().Empty (balance )
216+
217+ _ , broken := stakingkeeper .DelegatorSharesInvariant (suite .app .StakingKeeper )(ctx )
218+ suite .Require ().False (broken )
181219 }
182220 })
183221 }
0 commit comments