@@ -1249,3 +1249,123 @@ var _ = Describe("Clawback Vesting Account - Barberry bug", func() {
1249
1249
}
1250
1250
})
1251
1251
})
1252
+
1253
+ var _ = Describe ("Clawback Vesting Accounts - Track delegations" , func () {
1254
+ // Create test accounts with private keys for signing
1255
+ numTestAccounts := 4
1256
+ testAccounts := make ([]TestClawbackAccount , numTestAccounts )
1257
+ for i := range testAccounts {
1258
+ address , privKey := utiltx .NewAddrKey ()
1259
+ testAccounts [i ] = TestClawbackAccount {
1260
+ privKey : privKey ,
1261
+ address : address .Bytes (),
1262
+ }
1263
+ }
1264
+
1265
+ var (
1266
+ clawbackAccount * types.ClawbackVestingAccount
1267
+ isClawback bool
1268
+ )
1269
+
1270
+ // Prepare custom test amounts
1271
+ initialFreeBalance := sdk .NewCoins (sdk .NewCoin (stakeDenom , math .NewInt (1e18 ).MulRaw (10 )))
1272
+
1273
+ BeforeEach (func () {
1274
+ s .SetupTest ()
1275
+
1276
+ // Initialize all test accounts
1277
+ for _ , account := range testAccounts {
1278
+ err := testutil .FundAccount (s .ctx , s .app .BankKeeper , account .address , initialFreeBalance )
1279
+ Expect (err ).To (BeNil ())
1280
+ accBal := s .app .BankKeeper .GetBalance (s .ctx , account .address , stakeDenom )
1281
+ Expect (accBal ).To (Equal (initialFreeBalance [0 ]))
1282
+ }
1283
+
1284
+ // Add a commit to instantiate blocks
1285
+ s .Commit ()
1286
+ })
1287
+
1288
+ It ("Has delegation before conversion and free spendable coins" , func () {
1289
+ vacc := testAccounts [0 ]
1290
+ vaccAddr := vacc .address
1291
+ vaccPrivKey := vacc .privKey
1292
+
1293
+ // Add coins to be delegated
1294
+ err := testutil .FundAccount (s .ctx , s .app .BankKeeper , vaccAddr , initialFreeBalance )
1295
+ Expect (err ).To (BeNil ())
1296
+ s .Commit ()
1297
+
1298
+ // Should be doubled initialFreeBalance
1299
+ vaccBal := s .app .BankKeeper .GetBalance (s .ctx , vaccAddr , stakeDenom )
1300
+ Expect (vaccBal ).To (Equal (initialFreeBalance .Add (initialFreeBalance ... )[0 ]))
1301
+
1302
+ // should be equal to account balance
1303
+ vaccSpendableCoins := s .app .BankKeeper .SpendableCoins (s .ctx , vaccAddr )
1304
+ Expect (vaccSpendableCoins ).ToNot (BeNil ())
1305
+ Expect (vaccSpendableCoins [0 ]).To (Equal (vaccBal ))
1306
+
1307
+ // delegate half of the balance
1308
+ _ , err = testutil .Delegate (s .ctx , s .app , vaccPrivKey , initialFreeBalance [0 ], s .validator )
1309
+ Expect (err ).To (BeNil ())
1310
+ s .Commit ()
1311
+
1312
+ // Check delegation
1313
+ vaccBalAfterDelegation := s .app .BankKeeper .GetBalance (s .ctx , vaccAddr , stakeDenom )
1314
+ Expect (vaccBalAfterDelegation .IsLT (initialFreeBalance [0 ])).To (BeTrue ())
1315
+
1316
+ bondedAmt := s .app .StakingKeeper .GetDelegatorBonded (s .ctx , vaccAddr )
1317
+ unbondingAmt := s .app .StakingKeeper .GetDelegatorUnbonding (s .ctx , vaccAddr )
1318
+ delegatedAmt := bondedAmt .Add (unbondingAmt )
1319
+ Expect (delegatedAmt ).To (Equal (initialFreeBalance [0 ].Amount ))
1320
+
1321
+ vaccSpendableCoinsAfterDelegation := s .app .BankKeeper .SpendableCoins (s .ctx , vaccAddr )
1322
+ Expect (vaccSpendableCoinsAfterDelegation ).ToNot (BeNil ())
1323
+ Expect (vaccSpendableCoinsAfterDelegation [0 ].IsLT (initialFreeBalance [0 ])).To (BeTrue ())
1324
+
1325
+ // test vesting account creation
1326
+ vaccBalBeforeVesting := s .app .BankKeeper .GetBalance (s .ctx , vaccAddr , stakeDenom )
1327
+ Expect (vaccBalBeforeVesting ).To (Equal (vaccBalAfterDelegation ))
1328
+
1329
+ vaccSpendableCoinsBeforeVesting := s .app .BankKeeper .SpendableCoins (s .ctx , vaccAddr )
1330
+ Expect (vaccSpendableCoinsBeforeVesting ).To (Equal (vaccSpendableCoinsAfterDelegation ))
1331
+
1332
+ vestingStart := s .ctx .BlockTime ()
1333
+ msg := types .NewMsgConvertIntoVestingAccount (
1334
+ testAccounts [1 ].address ,
1335
+ vaccAddr ,
1336
+ vestingStart ,
1337
+ testutil .TestVestingSchedule .LockupPeriods ,
1338
+ testutil .TestVestingSchedule .VestingPeriods ,
1339
+ true , false , nil ,
1340
+ )
1341
+ _ , err = testutil .DeliverTx (s .ctx , s .app , testAccounts [1 ].privKey , nil , signing .SignMode_SIGN_MODE_DIRECT , msg )
1342
+ Expect (err ).ToNot (HaveOccurred (), "expected creating clawback vesting account to succeed" )
1343
+ s .Commit ()
1344
+
1345
+ funderAccBalAfterVesting := s .app .BankKeeper .GetBalance (s .ctx , testAccounts [1 ].address , stakeDenom )
1346
+ Expect (funderAccBalAfterVesting .IsLT (initialFreeBalance [0 ].Sub (vestingAmtTotal [0 ]))).To (BeTrue ())
1347
+
1348
+ vaccBalAfterVesting := s .app .BankKeeper .GetBalance (s .ctx , vaccAddr , stakeDenom )
1349
+ Expect (vaccBalAfterVesting ).To (Equal (vaccBalBeforeVesting .Add (vestingAmtTotal [0 ])))
1350
+
1351
+ vaccSpendableCoinsAfterVesting := s .app .BankKeeper .SpendableCoins (s .ctx , vaccAddr )
1352
+ Expect (vaccSpendableCoinsAfterVesting ).To (Equal (vaccSpendableCoinsBeforeVesting ))
1353
+
1354
+ acc := s .app .AccountKeeper .GetAccount (s .ctx , testAccounts [0 ].address )
1355
+ clawbackAccount , isClawback = acc .(* types.ClawbackVestingAccount )
1356
+ Expect (isClawback ).To (BeTrue (), "expected account to be clawback vesting account" )
1357
+
1358
+ Expect (clawbackAccount .DelegatedVesting ).To (BeNil ())
1359
+ Expect (clawbackAccount .DelegatedFree ).ToNot (BeNil ())
1360
+ Expect (clawbackAccount .DelegatedFree [0 ]).To (Equal (initialFreeBalance [0 ]))
1361
+
1362
+ // test spendable coins after vesting cliff
1363
+ s .CommitAfter (time .Duration (cliffLength )* time .Second + 1 )
1364
+
1365
+ vaccBalAfterCliff := s .app .BankKeeper .GetBalance (s .ctx , vaccAddr , stakeDenom )
1366
+ Expect (vaccBalAfterCliff ).To (Equal (vaccBalAfterVesting ))
1367
+
1368
+ vaccSpendableCoinsAfterCliff := s .app .BankKeeper .SpendableCoins (s .ctx , vaccAddr )
1369
+ Expect (vaccSpendableCoinsAfterCliff ).To (Equal (vaccSpendableCoinsAfterVesting .Add (clawbackAccount .GetLockedUpVestedCoins (s .ctx .BlockTime ())... )))
1370
+ })
1371
+ })
0 commit comments