* init * Fix bank proto messages * missing conversions * remove casttype for addresses * Fix tests * Fix consaddress * more test fixes * Fix tests * fixed tests * migrate missing proto declarations * format * Fix format * Fix alignment * Fix more tests * Fix ibc merge issue * Fix fmt * Fix more tests * Fix missing address declarations * Fix staking tests * Fix more tests * Fix config * fixed tests * Fix more tests * Update staking grpc tests * Fix merge issue * fixed failing tests in x/distr * fixed sim tests * fixed failing tests * Fix bugs * Add logs * fixed slashing issue * Fix staking grpc tests * Fix all bank tests :) * Fix tests in distribution * Fix more tests in distr * Fix slashing tests * Fix statking tests * Fix evidence tests * Fix gov tests * Fix bug in create vesting account * Fix test * remove fmt * fixed gov tests * fixed x/ibc tests * fixed x/ibc-transfer tests * fixed staking tests * fixed staking tests * fixed test * fixed distribution issue * fix pagination test * fmt * lint * fix build * fix format * revert tally tests * revert tally tests * lint * Fix sim test * revert * revert * fixed tally issue * fix tests * revert * fmt * refactor * remove `GetAddress()` * remove fmt * revert fmt.Striger usage * Fix tests * Fix rest test * disable interfacer lint check * make proto-format * add nolint rule * remove stray println Co-authored-by: aleem1314 <aleem.md789@gmail.com> Co-authored-by: atheesh <atheesh@vitwit.com>
97 lines
2.8 KiB
Go
97 lines
2.8 KiB
Go
package vesting_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/simapp"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
|
|
"github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
|
|
)
|
|
|
|
type HandlerTestSuite struct {
|
|
suite.Suite
|
|
|
|
handler sdk.Handler
|
|
app *simapp.SimApp
|
|
}
|
|
|
|
func (suite *HandlerTestSuite) SetupTest() {
|
|
checkTx := false
|
|
app := simapp.Setup(checkTx)
|
|
|
|
suite.handler = vesting.NewHandler(app.AccountKeeper, app.BankKeeper)
|
|
suite.app = app
|
|
}
|
|
|
|
func (suite *HandlerTestSuite) TestMsgCreateVestingAccount() {
|
|
ctx := suite.app.BaseApp.NewContext(false, tmproto.Header{Height: suite.app.LastBlockHeight() + 1})
|
|
|
|
balances := sdk.NewCoins(sdk.NewInt64Coin("test", 1000))
|
|
addr1 := sdk.AccAddress([]byte("addr1_______________"))
|
|
addr2 := sdk.AccAddress([]byte("addr2_______________"))
|
|
addr3 := sdk.AccAddress([]byte("addr3_______________"))
|
|
|
|
acc1 := suite.app.AccountKeeper.NewAccountWithAddress(ctx, addr1)
|
|
suite.app.AccountKeeper.SetAccount(ctx, acc1)
|
|
suite.Require().NoError(suite.app.BankKeeper.SetBalances(ctx, addr1, balances))
|
|
|
|
testCases := []struct {
|
|
name string
|
|
msg *types.MsgCreateVestingAccount
|
|
expectErr bool
|
|
}{
|
|
{
|
|
name: "create delayed vesting account",
|
|
msg: types.NewMsgCreateVestingAccount(addr1, addr2, sdk.NewCoins(sdk.NewInt64Coin("test", 100)), ctx.BlockTime().Unix()+10000, true),
|
|
expectErr: false,
|
|
},
|
|
{
|
|
name: "create continuous vesting account",
|
|
msg: types.NewMsgCreateVestingAccount(addr1, addr3, sdk.NewCoins(sdk.NewInt64Coin("test", 100)), ctx.BlockTime().Unix()+10000, false),
|
|
expectErr: false,
|
|
},
|
|
{
|
|
name: "continuous vesting account already exists",
|
|
msg: types.NewMsgCreateVestingAccount(addr1, addr3, sdk.NewCoins(sdk.NewInt64Coin("test", 100)), ctx.BlockTime().Unix()+10000, false),
|
|
expectErr: true,
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
tc := tc
|
|
|
|
suite.Run(tc.name, func() {
|
|
res, err := suite.handler(ctx, tc.msg)
|
|
if tc.expectErr {
|
|
suite.Require().Error(err)
|
|
} else {
|
|
suite.Require().NoError(err)
|
|
suite.Require().NotNil(res)
|
|
|
|
toAddr, err := sdk.AccAddressFromBech32(tc.msg.ToAddress)
|
|
suite.Require().NoError(err)
|
|
accI := suite.app.AccountKeeper.GetAccount(ctx, toAddr)
|
|
suite.Require().NotNil(accI)
|
|
|
|
if tc.msg.Delayed {
|
|
acc, ok := accI.(*types.DelayedVestingAccount)
|
|
suite.Require().True(ok)
|
|
suite.Require().Equal(tc.msg.Amount, acc.GetVestingCoins(ctx.BlockTime()))
|
|
} else {
|
|
acc, ok := accI.(*types.ContinuousVestingAccount)
|
|
suite.Require().True(ok)
|
|
suite.Require().Equal(tc.msg.Amount, acc.GetVestingCoins(ctx.BlockTime()))
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestHandlerTestSuite(t *testing.T) {
|
|
suite.Run(t, new(HandlerTestSuite))
|
|
}
|