-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Petr Ivanov
committed
Dec 15, 2023
1 parent
6b1fba8
commit 7754d04
Showing
1 changed file
with
111 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,102 +1,113 @@ | ||
package keeper_test | ||
|
||
//func (suite *KeeperTestSuite) TestBalances() { | ||
// var ( | ||
// req *types.QueryBalancesRequest | ||
// expRes *types.QueryBalancesResponse | ||
// ) | ||
// addr := sdk.AccAddress(tests.GenerateAddress().Bytes()) | ||
// | ||
// testCases := []struct { | ||
// name string | ||
// malleate func() | ||
// expPass bool | ||
// }{ | ||
// { | ||
// "empty req", | ||
// func() { | ||
// req = &types.QueryBalancesRequest{} | ||
// }, | ||
// false, | ||
// }, | ||
// { | ||
// "invalid address", | ||
// func() { | ||
// req = &types.QueryBalancesRequest{ | ||
// Address: "haqq1", | ||
// } | ||
// }, | ||
// false, | ||
// }, | ||
// { | ||
// "invalid account - not found", | ||
// func() { | ||
// req = &types.QueryBalancesRequest{ | ||
// Address: addr.String(), | ||
// } | ||
// }, | ||
// false, | ||
// }, | ||
// { | ||
// "invalid account - not clawback vesting account", | ||
// func() { | ||
// baseAccount := authtypes.NewBaseAccountWithAddress(addr) | ||
// acc := suite.app.AccountKeeper.NewAccount(suite.ctx, baseAccount) | ||
// suite.app.AccountKeeper.SetAccount(suite.ctx, acc) | ||
// | ||
// req = &types.QueryBalancesRequest{ | ||
// Address: addr.String(), | ||
// } | ||
// }, | ||
// false, | ||
// }, | ||
// { | ||
// "valid", | ||
// func() { | ||
// vestingStart := s.ctx.BlockTime() | ||
// funder := sdk.AccAddress(types.ModuleName) | ||
// err := testutil.FundAccount(suite.ctx, suite.app.BankKeeper, funder, balances) | ||
// suite.Require().NoError(err) | ||
// | ||
// msg := types.NewMsgCreateClawbackVestingAccount( | ||
// funder, | ||
// addr, | ||
// vestingStart, | ||
// lockupPeriods, | ||
// vestingPeriods, | ||
// false, | ||
// ) | ||
// ctx := sdk.WrapSDKContext(suite.ctx) | ||
// _, err = suite.app.VestingKeeper.CreateClawbackVestingAccount(ctx, msg) | ||
// suite.Require().NoError(err) | ||
// | ||
// req = &types.QueryBalancesRequest{ | ||
// Address: addr.String(), | ||
// } | ||
// expRes = &types.QueryBalancesResponse{ | ||
// Locked: balances, | ||
// Unvested: balances, | ||
// Vested: nil, | ||
// } | ||
// }, | ||
// true, | ||
// }, | ||
// } | ||
// | ||
// for _, tc := range testCases { | ||
// suite.Run(fmt.Sprintf("Case %s", tc.name), func() { | ||
// suite.SetupTest() // reset | ||
// ctx := sdk.WrapSDKContext(suite.ctx) | ||
// tc.malleate() | ||
// suite.Commit() | ||
// | ||
// res, err := suite.queryClient.Balances(ctx, req) | ||
// if tc.expPass { | ||
// suite.Require().NoError(err) | ||
// suite.Require().Equal(expRes, res) | ||
// } else { | ||
// suite.Require().Error(err) | ||
// } | ||
// }) | ||
// } | ||
//} | ||
import ( | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" | ||
|
||
"github.com/haqq-network/haqq/tests" | ||
"github.com/haqq-network/haqq/testutil" | ||
"github.com/haqq-network/haqq/x/vesting/types" | ||
) | ||
|
||
func (suite *KeeperTestSuite) TestBalances() { | ||
var ( | ||
req *types.QueryBalancesRequest | ||
expRes *types.QueryBalancesResponse | ||
) | ||
addr := sdk.AccAddress(tests.GenerateAddress().Bytes()) | ||
|
||
testCases := []struct { | ||
name string | ||
malleate func() | ||
expPass bool | ||
}{ | ||
{ | ||
"empty req", | ||
func() { | ||
req = &types.QueryBalancesRequest{} | ||
}, | ||
false, | ||
}, | ||
{ | ||
"invalid address", | ||
func() { | ||
req = &types.QueryBalancesRequest{ | ||
Address: "haqq1", | ||
} | ||
}, | ||
false, | ||
}, | ||
{ | ||
"invalid account - not found", | ||
func() { | ||
req = &types.QueryBalancesRequest{ | ||
Address: addr.String(), | ||
} | ||
}, | ||
false, | ||
}, | ||
{ | ||
"invalid account - not clawback vesting account", | ||
func() { | ||
baseAccount := authtypes.NewBaseAccountWithAddress(addr) | ||
acc := suite.app.AccountKeeper.NewAccount(suite.ctx, baseAccount) | ||
suite.app.AccountKeeper.SetAccount(suite.ctx, acc) | ||
|
||
req = &types.QueryBalancesRequest{ | ||
Address: addr.String(), | ||
} | ||
}, | ||
false, | ||
}, | ||
{ | ||
"valid", | ||
func() { | ||
vestingStart := s.ctx.BlockTime() | ||
funder := sdk.AccAddress(types.ModuleName) | ||
err := testutil.FundAccount(suite.ctx, suite.app.BankKeeper, funder, balances) | ||
suite.Require().NoError(err) | ||
|
||
msg := types.NewMsgCreateClawbackVestingAccount( | ||
funder, | ||
addr, | ||
vestingStart, | ||
lockupPeriods, | ||
vestingPeriods, | ||
false, | ||
) | ||
ctx := sdk.WrapSDKContext(suite.ctx) | ||
_, err = suite.app.VestingKeeper.CreateClawbackVestingAccount(ctx, msg) | ||
suite.Require().NoError(err) | ||
|
||
req = &types.QueryBalancesRequest{ | ||
Address: addr.String(), | ||
} | ||
expRes = &types.QueryBalancesResponse{ | ||
Locked: balances, | ||
Unvested: balances, | ||
Vested: nil, | ||
} | ||
}, | ||
true, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
suite.Run(fmt.Sprintf("Case %s", tc.name), func() { | ||
suite.SetupTest() // reset | ||
ctx := sdk.WrapSDKContext(suite.ctx) | ||
tc.malleate() | ||
suite.Commit() | ||
|
||
res, err := suite.queryClient.Balances(ctx, req) | ||
if tc.expPass { | ||
suite.Require().NoError(err) | ||
suite.Require().Equal(expRes, res) | ||
} else { | ||
suite.Require().Error(err) | ||
} | ||
}) | ||
} | ||
} |