2018-10-10 19:53:25 -07:00
|
|
|
package keeper
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2018-12-10 06:27:25 -08:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2018-10-10 19:53:25 -07:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
)
|
|
|
|
|
2019-01-16 14:17:56 -08:00
|
|
|
func TestSetWithdrawAddr(t *testing.T) {
|
|
|
|
ctx, _, keeper, _, _ := CreateTestInputDefault(t, false, 1000)
|
|
|
|
|
|
|
|
keeper.SetWithdrawAddrEnabled(ctx, false)
|
|
|
|
|
|
|
|
err := keeper.SetWithdrawAddr(ctx, delAddr1, delAddr2)
|
|
|
|
require.NotNil(t, err)
|
|
|
|
|
|
|
|
keeper.SetWithdrawAddrEnabled(ctx, true)
|
|
|
|
|
|
|
|
err = keeper.SetWithdrawAddr(ctx, delAddr1, delAddr2)
|
|
|
|
require.Nil(t, err)
|
|
|
|
}
|
|
|
|
|
2019-01-16 13:38:05 -08:00
|
|
|
func TestWithdrawValidatorCommission(t *testing.T) {
|
|
|
|
ctx, ak, keeper, _, _ := CreateTestInputDefault(t, false, 1000)
|
|
|
|
|
2019-02-15 07:33:23 -08:00
|
|
|
valCommission := sdk.DecCoins{
|
|
|
|
sdk.NewDecCoinFromDec("mytoken", sdk.NewDec(5).Quo(sdk.NewDec(4))),
|
|
|
|
sdk.NewDecCoinFromDec("stake", sdk.NewDec(3).Quo(sdk.NewDec(2))),
|
|
|
|
}
|
|
|
|
|
2019-01-16 13:38:05 -08:00
|
|
|
// check initial balance
|
|
|
|
balance := ak.GetAccount(ctx, sdk.AccAddress(valOpAddr3)).GetCoins()
|
2019-06-12 08:57:47 -07:00
|
|
|
expTokens := sdk.TokensFromConsensusPower(1000)
|
2019-02-05 21:30:48 -08:00
|
|
|
require.Equal(t, sdk.Coins{
|
2019-06-12 08:57:47 -07:00
|
|
|
sdk.NewCoin("stake", sdk.TokensFromConsensusPower(1000)),
|
2019-02-05 21:30:48 -08:00
|
|
|
}, balance)
|
2019-01-16 13:38:05 -08:00
|
|
|
|
2019-03-06 10:54:12 -08:00
|
|
|
// set outstanding rewards
|
|
|
|
keeper.SetValidatorOutstandingRewards(ctx, valOpAddr3, valCommission)
|
|
|
|
|
2019-01-16 13:38:05 -08:00
|
|
|
// set commission
|
2019-02-15 07:33:23 -08:00
|
|
|
keeper.SetValidatorAccumulatedCommission(ctx, valOpAddr3, valCommission)
|
2019-01-16 13:38:05 -08:00
|
|
|
|
|
|
|
// withdraw commission
|
|
|
|
keeper.WithdrawValidatorCommission(ctx, valOpAddr3)
|
|
|
|
|
|
|
|
// check balance increase
|
|
|
|
balance = ak.GetAccount(ctx, sdk.AccAddress(valOpAddr3)).GetCoins()
|
2019-02-05 21:30:48 -08:00
|
|
|
require.Equal(t, sdk.Coins{
|
2019-02-15 07:33:23 -08:00
|
|
|
sdk.NewCoin("mytoken", sdk.NewInt(1)),
|
|
|
|
sdk.NewCoin("stake", expTokens.AddRaw(1)),
|
2019-02-05 21:30:48 -08:00
|
|
|
}, balance)
|
2019-01-16 13:38:05 -08:00
|
|
|
|
|
|
|
// check remainder
|
|
|
|
remainder := keeper.GetValidatorAccumulatedCommission(ctx, valOpAddr3)
|
2019-02-05 21:30:48 -08:00
|
|
|
require.Equal(t, sdk.DecCoins{
|
2019-02-15 07:33:23 -08:00
|
|
|
sdk.NewDecCoinFromDec("mytoken", sdk.NewDec(1).Quo(sdk.NewDec(4))),
|
|
|
|
sdk.NewDecCoinFromDec("stake", sdk.NewDec(1).Quo(sdk.NewDec(2))),
|
2019-02-05 21:30:48 -08:00
|
|
|
}, remainder)
|
2019-01-16 13:38:05 -08:00
|
|
|
|
|
|
|
require.True(t, true)
|
2018-10-10 19:53:25 -07:00
|
|
|
}
|