@@ -14,6 +14,78 @@ import (
1414 "github.com/stretchr/testify/require"
1515)
1616
17+ func TestCancelVest_CompleteAmount (t * testing.T ) {
18+ app := app .InitElysTestApp (true , t )
19+
20+ ctx := app .BaseApp .NewContext (true )
21+ // Create a test context and keeper
22+ keeper := app .CommitmentKeeper
23+
24+ msgServer := commitmentkeeper .NewMsgServerImpl (* keeper )
25+
26+ vestingInfos := []types.VestingInfo {
27+ {
28+ BaseDenom : ptypes .Eden ,
29+ VestingDenom : ptypes .Elys ,
30+ NumBlocks : 10 ,
31+ VestNowFactor : sdkmath .NewInt (90 ),
32+ NumMaxVestings : 10 ,
33+ },
34+ }
35+
36+ params := types.Params {
37+ VestingInfos : vestingInfos ,
38+ }
39+
40+ keeper .SetParams (ctx , params )
41+
42+ // Create a new account
43+ creator , _ := sdk .AccAddressFromBech32 ("cosmos1xv9tklw7d82sezh9haa573wufgy59vmwe6xxe5" )
44+ acc := app .AccountKeeper .GetAccount (ctx , creator )
45+ if acc == nil {
46+ acc = app .AccountKeeper .NewAccountWithAddress (ctx , creator )
47+ app .AccountKeeper .SetAccount (ctx , acc )
48+ }
49+ // Create a cancel vesting message
50+ cancelVestMsg := & types.MsgCancelVest {
51+ Creator : creator .String (),
52+ Denom : ptypes .Eden ,
53+ Amount : sdkmath .NewInt (100 ),
54+ }
55+
56+ // Set up the commitments for the creator
57+ commitments := types.Commitments {
58+ Creator : creator .String (),
59+ VestingTokens : []* types.VestingTokens {
60+ {
61+ Denom : ptypes .Elys ,
62+ TotalAmount : sdkmath .NewInt (100 ),
63+ ClaimedAmount : sdkmath .NewInt (0 ),
64+ NumBlocks : 100 ,
65+ StartBlock : 0 ,
66+ },
67+ },
68+ }
69+ keeper .SetCommitments (ctx , commitments )
70+
71+ // Increase the block height
72+ ctx = ctx .WithBlockHeight (ctx .BlockHeight () + 25 )
73+
74+ // From 100 tokens, some of tokens are already vested and that will be claimed,
75+ // so CancelVest should cancel the remaining amount without any issue
76+ // Execute the CancelVest function
77+ _ , err := msgServer .CancelVest (ctx , cancelVestMsg )
78+ require .NoError (t , err )
79+
80+ newCommitments := keeper .GetCommitments (ctx , creator )
81+ require .Len (t , newCommitments .VestingTokens , 0 , "vesting tokens should be empty after cancelling all remaining amount" )
82+
83+ // No vesting tokens, so should throw an error
84+ _ , err = msgServer .CancelVest (ctx , cancelVestMsg )
85+ require .Error (t , err )
86+ require .True (t , types .ErrInsufficientVestingTokens .Is (err ), "Error should be insufficient vesting tokens" )
87+ }
88+
1789func TestCancelVest (t * testing.T ) {
1890 app := app .InitElysTestApp (true , t )
1991
@@ -83,11 +155,12 @@ func TestCancelVest(t *testing.T) {
83155 // check if the unclaimed tokens were updated correctly
84156 require .Equal (t , sdkmath .NewInt (25 ), newCommitments .GetClaimedForDenom (ptypes .Eden ))
85157
86- // Try to cancel an amount that exceeds the unvested amount
158+ // Try to cancel an amount that exceeds the unvested amount, should cancel all the remaining amount
87159 cancelVestMsg .Amount = sdkmath .NewInt (100 )
88160 _ , err = msgServer .CancelVest (ctx , cancelVestMsg )
89- require .Error (t , err , "should throw an error when trying to cancel more tokens than available" )
90- require .True (t , types .ErrInsufficientVestingTokens .Is (err ), "error should be insufficient vesting tokens" )
161+ require .NoError (t , err )
162+ newCommitments = keeper .GetCommitments (ctx , creator )
163+ require .Len (t , newCommitments .VestingTokens , 0 , "vesting tokens should be empty after cancelling all remaining amount" )
91164}
92165
93166func TestCancelVest_WithPreviousClaimed (t * testing.T ) {
@@ -246,5 +319,5 @@ func TestCancelVestNoVestingInfo(t *testing.T) {
246319 _ , err := msgServer .CancelVest (ctx , cancelVestMsg )
247320 require .Error (t , err , "should throw an error when trying to cancel tokens with no vesting info" )
248321 fmt .Println (err .Error ())
249- require .True (t , types .ErrInsufficientVestingTokens .Is (err ), "error should be invalid denom " )
322+ require .True (t , types .ErrInsufficientVestingTokens .Is (err ), "Error should be insufficient vesting tokens " )
250323}
0 commit comments