@@ -22,7 +22,7 @@ import {
2222 RocketMegapoolFactory ,
2323 RocketMegapoolManager ,
2424 RocketNodeDeposit ,
25- RocketStorage ,
25+ RocketStorage , RocketTokenRETH ,
2626} from '../_utils/artifacts' ;
2727import assert from 'assert' ;
2828import { stakeMegapoolValidator } from './scenario-stake' ;
@@ -36,6 +36,7 @@ import { votePenalty } from './scenario-apply-penalty';
3636import { reduceBond } from './scenario-reduce-bond' ;
3737import { dissolveValidator } from './scenario-dissolve' ;
3838import { challengeValidator } from './scenario-challenge' ;
39+ import { repayDebt } from './scenario-repay-debt' ;
3940
4041const helpers = require ( '@nomicfoundation/hardhat-network-helpers' ) ;
4142const hre = require ( 'hardhat' ) ;
@@ -984,9 +985,11 @@ export default function() {
984985 await setDAOProtocolBootstrapSetting ( RocketDAOProtocolSettingsNode , 'reduced.bond' , '2' . ether , { from : owner } ) ;
985986 // Notify exit in 5 epochs
986987 const currentEpoch = await getCurrentEpoch ( ) ;
987- await notifyExitValidator ( megapool , 0 , currentEpoch ) ;
988+ await notifyExitValidator ( megapool , 0 , currentEpoch + 114 ) ;
989+ // Increase time to beyond withdrawable_epoch
990+ await helpers . time . increase ( 12 * 32 * 114 ) ;
988991 const nodeBalanceBefore = await ethers . provider . getBalance ( nodeWithdrawalAddress ) ;
989- await notifyFinalBalanceValidator ( megapool , 0 , '32' . ether , owner , currentEpoch * 32 ) ;
992+ await notifyFinalBalanceValidator ( megapool , 0 , '32' . ether , owner , await getCurrentEpoch ( ) * 32 ) ;
990993 const nodeBalanceAfter = await ethers . provider . getBalance ( nodeWithdrawalAddress ) ;
991994 /*
992995 NO started with 5 validators
@@ -1002,11 +1005,13 @@ export default function() {
10021005 it ( printTitle ( 'node' , 'can bond reduce on exit with balance < 32 ETH' ) , async ( ) => {
10031006 // Adjust `reduced_bond` to 2 ETH
10041007 await setDAOProtocolBootstrapSetting ( RocketDAOProtocolSettingsNode , 'reduced.bond' , '2' . ether , { from : owner } ) ;
1005- // Notify exit in 5 epochs
1008+ // Notify exit enough into the future to avoid fine
10061009 const currentEpoch = await getCurrentEpoch ( ) ;
1007- await notifyExitValidator ( megapool , 0 , currentEpoch ) ;
1010+ await notifyExitValidator ( megapool , 0 , currentEpoch + 114 ) ;
10081011 const nodeBalanceBefore = await ethers . provider . getBalance ( nodeWithdrawalAddress ) ;
1009- await notifyFinalBalanceValidator ( megapool , 0 , '32' . ether - '7' . ether , owner , currentEpoch * 32 ) ;
1012+ // Increase time to beyond withdrawable_epoch
1013+ await helpers . time . increase ( 12 * 32 * 114 ) ;
1014+ await notifyFinalBalanceValidator ( megapool , 0 , '32' . ether - '7' . ether , owner , await getCurrentEpoch ( ) * 32 ) ;
10101015 const nodeBalanceAfter = await ethers . provider . getBalance ( nodeWithdrawalAddress ) ;
10111016 /*
10121017 NO should receive 8 ETH bond on exit, but lost 7 ETH capital so bond should reduce by 8 ETH
@@ -1046,18 +1051,21 @@ export default function() {
10461051 // Notify exit in 112 epochs (1 epoch too late)
10471052 const currentEpoch = await getCurrentEpoch ( ) ;
10481053 await notifyExitValidator ( megapool , 0 , currentEpoch + 112 ) ;
1049- // Increase time to beyond withdrawalbe_epoch
1054+ /*
1055+ NO should receive a 0.01 ETH penalty for submitting late
1056+ */
1057+ const nodeDebt = await megapool . getDebt ( ) ;
1058+ assertBN . equal ( nodeDebt , fineAmount ) ;
1059+ // Increase time to beyond withdrawable_epoch
10501060 await helpers . time . increase ( 12 * 32 * 112 ) ;
10511061 // Increase time to beyond user distribute window
10521062 await helpers . time . increase ( userDistributeTime + 1 ) ;
10531063 // Submit the final balance from a random account to prevent immediate claim
10541064 const randomMegapoolRunner = megapool . connect ( random ) ;
10551065 await notifyFinalBalanceValidator ( randomMegapoolRunner , 0 , '32' . ether , owner , await getCurrentEpoch ( ) * 32 ) ;
1056- /*
1057- NO should receive a 0.01 ETH penalty for submitting late
1058- */
1059- const nodeDebt = await megapool . getDebt ( ) ;
1060- assertBN . equal ( nodeDebt , fineAmount ) ;
1066+ // Debt should be paid on exit
1067+ const nodeDebtAfter = await megapool . getDebt ( ) ;
1068+ assertBN . equal ( nodeDebtAfter , 0n ) ;
10611069 } ) ;
10621070
10631071 snapshotDescribe ( 'With debt' , ( ) => {
@@ -1074,11 +1082,7 @@ export default function() {
10741082 } ) ;
10751083
10761084 it ( printTitle ( 'node' , 'can manually pay down debt' ) , async ( ) => {
1077- const debtBefore = await megapool . getDebt ( ) ;
1078- assertBN . isAbove ( debtBefore , 0n ) ;
1079- await megapool . repayDebt ( { value : debtBefore } ) ;
1080- const debtAfter = await megapool . getDebt ( ) ;
1081- assertBN . equal ( debtAfter , '0' . ether ) ;
1085+ await repayDebt ( megapool , '1' . ether )
10821086 } ) ;
10831087
10841088 it ( printTitle ( 'node' , 'can use rewards to partially pay down debt' ) , async ( ) => {
0 commit comments