@@ -208,34 +208,18 @@ describe('Protocol Staking', function () {
208208
209209 it ( 'should not transfer instantly' , async function ( ) {
210210 await this . mock . connect ( this . manager ) . setUnstakeCooldownPeriod ( 60 ) ; // 1 minute
211- await expect ( this . mock . connect ( this . staker1 ) . unstake ( this . staker1 , ethers . parseEther ( '50' ) ) )
211+ await expect ( this . mock . connect ( this . staker1 ) . unstake ( ethers . parseEther ( '50' ) ) )
212212 . to . emit ( this . mock , 'Transfer' )
213213 . withArgs ( this . staker1 , ethers . ZeroAddress , ethers . parseEther ( '50' ) )
214- . to . not . emit ( this . token , 'Transfer' ) ;
215- } ) ;
216-
217- it ( 'should be able to unstake to someone else' , async function ( ) {
218- const currentTime = BigInt ( await time . latest ( ) ) ;
219- const cooldownPeriod = BigInt ( await this . mock . unstakeCooldownPeriod ( ) ) ;
220- await expect ( this . mock . connect ( this . staker1 ) . unstake ( this . staker2 , ethers . parseEther ( '50' ) ) )
221214 . to . emit ( this . mock , 'TokensUnstaked' )
222- . withArgs ( this . staker1 , this . staker2 , ethers . parseEther ( '50' ) , currentTime + cooldownPeriod + 1n ) ;
223- await mine ( ) ;
224- await expect ( this . mock . release ( this . staker2 ) )
225- . to . emit ( this . token , 'Transfer' )
226- . withArgs ( this . mock , this . staker2 , ethers . parseEther ( '50' ) ) ;
227- } ) ;
228-
229- it ( 'should not unstake to zero address' , async function ( ) {
230- await expect (
231- this . mock . connect ( this . staker1 ) . unstake ( ethers . ZeroAddress , ethers . parseEther ( '50' ) ) ,
232- ) . to . be . revertedWithCustomError ( this . mock , 'InvalidUnstakeRecipient' ) ;
215+ . withArgs ( this . staker1 , ethers . parseEther ( '50' ) , anyValue )
216+ . to . not . emit ( this . token , 'Transfer' ) ;
233217 } ) ;
234218
235219 describe ( 'Release' , function ( ) {
236220 it ( 'should transfer after cooldown complete' , async function ( ) {
237221 await this . mock . connect ( this . manager ) . setUnstakeCooldownPeriod ( 60 ) ; // 1 minute
238- await this . mock . connect ( this . staker1 ) . unstake ( this . staker1 , ethers . parseEther ( '50' ) ) ;
222+ await this . mock . connect ( this . staker1 ) . unstake ( ethers . parseEther ( '50' ) ) ;
239223 await expect ( this . mock . awaitingRelease ( this . staker1 ) ) . to . eventually . eq ( ethers . parseEther ( '50' ) ) ;
240224
241225 await timeIncreaseNoMine ( 60 ) ;
@@ -248,7 +232,7 @@ describe('Protocol Staking', function () {
248232
249233 it ( 'should only release once' , async function ( ) {
250234 await this . mock . connect ( this . manager ) . setUnstakeCooldownPeriod ( 60 ) ; // 1 minute
251- await this . mock . connect ( this . staker1 ) . unstake ( this . staker1 , ethers . parseEther ( '50' ) ) ;
235+ await this . mock . connect ( this . staker1 ) . unstake ( ethers . parseEther ( '50' ) ) ;
252236
253237 await timeIncreaseNoMine ( 60 ) ;
254238
@@ -262,18 +246,18 @@ describe('Protocol Staking', function () {
262246
263247 it ( "should not release if cooldown isn't complete" , async function ( ) {
264248 await this . mock . connect ( this . manager ) . setUnstakeCooldownPeriod ( 60 ) ;
265- await this . mock . connect ( this . staker1 ) . unstake ( this . staker1 , ethers . parseEther ( '50' ) ) ;
249+ await this . mock . connect ( this . staker1 ) . unstake ( ethers . parseEther ( '50' ) ) ;
266250
267251 await timeIncreaseNoMine ( 30 ) ;
268252 await expect ( this . mock . release ( this . staker1 ) ) . to . not . emit ( this . token , 'Transfer' ) ;
269253 } ) ;
270254
271255 it ( 'should combine multiple complete withdrawals' , async function ( ) {
272256 await this . mock . connect ( this . manager ) . setUnstakeCooldownPeriod ( 60 ) ; // 1 minute
273- await this . mock . connect ( this . staker1 ) . unstake ( this . staker1 , ethers . parseEther ( '50' ) ) ;
257+ await this . mock . connect ( this . staker1 ) . unstake ( ethers . parseEther ( '50' ) ) ;
274258
275259 await timeIncreaseNoMine ( 30 ) ;
276- await this . mock . connect ( this . staker1 ) . unstake ( this . staker1 , ethers . parseEther ( '50' ) ) ;
260+ await this . mock . connect ( this . staker1 ) . unstake ( ethers . parseEther ( '50' ) ) ;
277261 await expect ( this . mock . awaitingRelease ( this . staker1 ) ) . to . eventually . eq ( ethers . parseEther ( '100' ) ) ;
278262
279263 await timeIncreaseNoMine ( 60 ) ;
@@ -285,13 +269,13 @@ describe('Protocol Staking', function () {
285269
286270 it ( 'should only release completed cooldowns in batch' , async function ( ) {
287271 await this . mock . connect ( this . manager ) . setUnstakeCooldownPeriod ( 60 ) ; // 1 minute
288- await this . mock . connect ( this . staker1 ) . unstake ( this . staker1 , ethers . parseEther ( '25' ) ) ;
272+ await this . mock . connect ( this . staker1 ) . unstake ( ethers . parseEther ( '25' ) ) ;
289273
290274 await timeIncreaseNoMine ( 20 ) ;
291- await this . mock . connect ( this . staker1 ) . unstake ( this . staker1 , ethers . parseEther ( '25' ) ) ;
275+ await this . mock . connect ( this . staker1 ) . unstake ( ethers . parseEther ( '25' ) ) ;
292276
293277 await timeIncreaseNoMine ( 20 ) ;
294- await this . mock . connect ( this . staker1 ) . unstake ( this . staker1 , ethers . parseEther ( '25' ) ) ;
278+ await this . mock . connect ( this . staker1 ) . unstake ( ethers . parseEther ( '25' ) ) ;
295279
296280 await timeIncreaseNoMine ( 40 ) ;
297281 await expect ( this . mock . release ( this . staker1 ) )
@@ -301,11 +285,11 @@ describe('Protocol Staking', function () {
301285
302286 it ( 'should handle decrease in cooldown period gracefully' , async function ( ) {
303287 await this . mock . connect ( this . manager ) . setUnstakeCooldownPeriod ( 120 ) ;
304- await this . mock . connect ( this . staker1 ) . unstake ( this . staker1 , ethers . parseEther ( '25' ) ) ;
288+ await this . mock . connect ( this . staker1 ) . unstake ( ethers . parseEther ( '25' ) ) ;
305289
306290 await timeIncreaseNoMine ( 30 ) ;
307291 await this . mock . connect ( this . manager ) . setUnstakeCooldownPeriod ( 30 ) ;
308- await this . mock . connect ( this . staker1 ) . unstake ( this . staker1 , ethers . parseEther ( '25' ) ) ;
292+ await this . mock . connect ( this . staker1 ) . unstake ( ethers . parseEther ( '25' ) ) ;
309293
310294 // advance 30 seconds. Still need to wait another 60 seconds for the original unstake request to complete.
311295 await timeIncreaseNoMine ( 30 ) ;
@@ -323,7 +307,7 @@ describe('Protocol Staking', function () {
323307
324308 const beforetotalStakedWeight = await this . mock . totalStakedWeight ( ) ;
325309 const beforeStaker1Log = await this . mock . weight ( await this . mock . balanceOf ( this . staker1 ) ) ;
326- await this . mock . connect ( this . staker1 ) . unstake ( this . staker1 , ethers . parseEther ( '75' ) ) ;
310+ await this . mock . connect ( this . staker1 ) . unstake ( ethers . parseEther ( '75' ) ) ;
327311 const afterStaker1Log = await this . mock . weight ( await this . mock . balanceOf ( this . staker1 ) ) ;
328312 const aftertotalStakedWeight = await this . mock . totalStakedWeight ( ) ;
329313 expect ( beforetotalStakedWeight - aftertotalStakedWeight ) . to . equal ( beforeStaker1Log - afterStaker1Log ) ;
@@ -375,7 +359,7 @@ describe('Protocol Staking', function () {
375359
376360 await timeIncreaseNoMine ( 10 ) ;
377361
378- await this . mock . connect ( this . staker1 ) . unstake ( this . staker1 , ethers . parseEther ( '100' ) ) ;
362+ await this . mock . connect ( this . staker1 ) . unstake ( ethers . parseEther ( '100' ) ) ;
379363
380364 // time passes (10 seconds) while no one is staked
381365 await timeIncreaseNoMine ( 10 ) ;
@@ -400,9 +384,9 @@ describe('Protocol Staking', function () {
400384 await timeIncreaseNoMine ( 10 ) ;
401385
402386 // 3 in rewards for 1 (since 1 block at the beginning alone)
403- await this . mock . connect ( this . staker1 ) . unstake ( this . staker1 , ethers . parseEther ( '100' ) ) ;
387+ await this . mock . connect ( this . staker1 ) . unstake ( ethers . parseEther ( '100' ) ) ;
404388 // 3 in rewards for 2 (since 1 block at the end alone)
405- await this . mock . connect ( this . staker2 ) . unstake ( this . staker2 , ethers . parseEther ( '100' ) ) ;
389+ await this . mock . connect ( this . staker2 ) . unstake ( ethers . parseEther ( '100' ) ) ;
406390
407391 await timeIncreaseNoMine ( 10 ) ;
408392
@@ -431,7 +415,7 @@ describe('Protocol Staking', function () {
431415
432416 await timeIncreaseNoMine ( 10 ) ;
433417
434- await this . mock . connect ( this . staker1 ) . unstake ( this . staker1 , ethers . parseEther ( '100' ) ) ;
418+ await this . mock . connect ( this . staker1 ) . unstake ( ethers . parseEther ( '100' ) ) ;
435419
436420 // time passes (10 seconds) while no one is staked
437421 await timeIncreaseNoMine ( 10 ) ;
@@ -456,9 +440,9 @@ describe('Protocol Staking', function () {
456440 await timeIncreaseNoMine ( 10 ) ;
457441
458442 // 3 in rewards for 1 (since 1 block at the beginning alone)
459- await this . mock . connect ( this . staker1 ) . unstake ( this . staker1 , ethers . parseEther ( '100' ) ) ;
443+ await this . mock . connect ( this . staker1 ) . unstake ( ethers . parseEther ( '100' ) ) ;
460444 // 3 in rewards for 2 (since 1 block at the end alone)
461- await this . mock . connect ( this . staker2 ) . unstake ( this . staker2 , ethers . parseEther ( '100' ) ) ;
445+ await this . mock . connect ( this . staker2 ) . unstake ( ethers . parseEther ( '100' ) ) ;
462446
463447 await timeIncreaseNoMine ( 10 ) ;
464448
@@ -487,7 +471,7 @@ describe('Protocol Staking', function () {
487471
488472 await timeIncreaseNoMine ( 10 ) ;
489473
490- await this . mock . connect ( this . staker1 ) . unstake ( this . staker1 , ethers . parseEther ( '100' ) ) ;
474+ await this . mock . connect ( this . staker1 ) . unstake ( ethers . parseEther ( '100' ) ) ;
491475
492476 // time passes (10 seconds) while no one is staked
493477 await timeIncreaseNoMine ( 10 ) ;
@@ -512,9 +496,9 @@ describe('Protocol Staking', function () {
512496 await timeIncreaseNoMine ( 10 ) ;
513497
514498 // 3 in rewards for 1 (since 1 block at the beginning alone)
515- await this . mock . connect ( this . staker1 ) . unstake ( this . staker1 , ethers . parseEther ( '100' ) ) ;
499+ await this . mock . connect ( this . staker1 ) . unstake ( ethers . parseEther ( '100' ) ) ;
516500 // 3 in rewards for 2 (since 1 block at the end alone)
517- await this . mock . connect ( this . staker2 ) . unstake ( this . staker2 , ethers . parseEther ( '100' ) ) ;
501+ await this . mock . connect ( this . staker2 ) . unstake ( ethers . parseEther ( '100' ) ) ;
518502
519503 await timeIncreaseNoMine ( 10 ) ;
520504
@@ -543,7 +527,7 @@ describe('Protocol Staking', function () {
543527
544528 await timeIncreaseNoMine ( 10 ) ;
545529
546- await this . mock . connect ( this . staker1 ) . unstake ( this . staker1 , ethers . parseEther ( '100' ) ) ;
530+ await this . mock . connect ( this . staker1 ) . unstake ( ethers . parseEther ( '100' ) ) ;
547531
548532 // time passes (10 seconds) while no one is staked
549533 await timeIncreaseNoMine ( 10 ) ;
@@ -568,9 +552,9 @@ describe('Protocol Staking', function () {
568552 await timeIncreaseNoMine ( 10 ) ;
569553
570554 // 3 in rewards for 1 (since 1 block at the beginning alone)
571- await this . mock . connect ( this . staker1 ) . unstake ( this . staker1 , ethers . parseEther ( '100' ) ) ;
555+ await this . mock . connect ( this . staker1 ) . unstake ( ethers . parseEther ( '100' ) ) ;
572556 // 3 in rewards for 2 (since 1 block at the end alone)
573- await this . mock . connect ( this . staker2 ) . unstake ( this . staker2 , ethers . parseEther ( '100' ) ) ;
557+ await this . mock . connect ( this . staker2 ) . unstake ( ethers . parseEther ( '100' ) ) ;
574558
575559 await timeIncreaseNoMine ( 10 ) ;
576560
@@ -595,6 +579,15 @@ describe('Protocol Staking', function () {
595579 . withArgs ( eligibleAccountRole , this . staker1 , this . manager ) ;
596580 } ) ;
597581
582+ it ( 'should not update total staked amount if no balance' , async function ( ) {
583+ await this . mock . connect ( this . manager ) . addEligibleAccount ( this . staker1 ) ;
584+ await this . mock . connect ( this . staker1 ) . stake ( ethers . parseEther ( '1' ) ) ;
585+
586+ const weightBefore = await this . mock . totalStakedWeight ( ) ;
587+ await this . mock . connect ( this . manager ) . addEligibleAccount ( this . staker2 ) ;
588+ await expect ( this . mock . totalStakedWeight ( ) ) . to . eventually . eq ( weightBefore ) ;
589+ } ) ;
590+
598591 it ( 'should reflect in eligible account storage' , async function ( ) {
599592 await this . mock . connect ( this . manager ) . addEligibleAccount ( this . staker1 ) ;
600593 await this . mock . connect ( this . manager ) . addEligibleAccount ( this . staker2 ) ;
0 commit comments