@@ -29,6 +29,7 @@ import {
2929 RocketStorage ,
3030 RocketTokenRETH ,
3131 RocketVault ,
32+ StorageHelper ,
3233} from '../_utils/artifacts' ;
3334import assert from 'assert' ;
3435import { stakeMegapoolValidator } from './scenario-stake' ;
@@ -72,6 +73,12 @@ async function getValidPrestakeValidator(megapool, index) {
7273 } ;
7374}
7475
76+ async function mockExpressTickets ( nodeAddress , count ) {
77+ const helper = await StorageHelper . deployed ( ) ;
78+ const key = ethers . solidityPackedKeccak256 ( [ 'string' , 'address' ] , [ 'node.express.tickets' , nodeAddress ] ) ;
79+ await helper . setUint ( key , count ) ;
80+ }
81+
7582export default function ( ) {
7683 describe ( 'Megapools' , ( ) => {
7784 let owner ,
@@ -291,6 +298,7 @@ export default function() {
291298
292299 it ( printTitle ( 'node' , 'can deposit multi with mixed express ticket usage' ) , async ( ) => {
293300 await deployMegapool ( { from : node } ) ;
301+ await mockExpressTickets ( node . address , 2 )
294302
295303 const deposits = [
296304 {
@@ -316,6 +324,7 @@ export default function() {
316324
317325 it ( printTitle ( 'node' , 'can deposit multi with mixed bond amounts' ) , async ( ) => {
318326 await deployMegapool ( { from : node } ) ;
327+ await mockExpressTickets ( node . address , 2 )
319328
320329 await setDAOProtocolBootstrapSetting ( RocketDAOProtocolSettingsNode , 'reduced.bond' , '2' . ether , { from : owner } ) ;
321330
@@ -510,6 +519,8 @@ export default function() {
510519
511520 it ( printTitle ( 'misc' , 'calculates position in queue correctly' ) , async ( ) => {
512521 const rocketDepositPool = await RocketDepositPool . deployed ( ) ;
522+ await mockExpressTickets ( node . address , 2 )
523+ await mockExpressTickets ( node2 . address , 2 )
513524
514525 /**
515526 * We will add 5 validators to the queue, 2 of which using an express ticket.
@@ -574,17 +585,17 @@ export default function() {
574585 * Therefore, the queue should now look like:
575586 *
576587 * 0: node-2 (express)
577- * 1: node-0
578- * 2: node2-0 (express)
579- * 3: node2-1 (express)
588+ * 1: node2-0 (express)
589+ * 2: node2-1 (express)
590+ * 3: node-0
580591 * 4: node-3
581592 * 5: node-4
582593 */
583594
584595 assertBN . equal ( await calculatePositionInQueue ( megapool , 2n ) , 0n ) ;
585- assertBN . equal ( await calculatePositionInQueue ( megapool , 0n ) , 1n ) ;
586- assertBN . equal ( await calculatePositionInQueue ( megapool2 , 0n ) , 2n ) ;
587- assertBN . equal ( await calculatePositionInQueue ( megapool2 , 1n ) , 3n ) ;
596+ assertBN . equal ( await calculatePositionInQueue ( megapool2 , 0n ) , 1n ) ;
597+ assertBN . equal ( await calculatePositionInQueue ( megapool2 , 1n ) , 2n ) ;
598+ assertBN . equal ( await calculatePositionInQueue ( megapool , 0n ) , 3n ) ;
588599 assertBN . equal ( await calculatePositionInQueue ( megapool , 3n ) , 4n ) ;
589600 assertBN . equal ( await calculatePositionInQueue ( megapool , 4n ) , 5n ) ;
590601
@@ -595,16 +606,16 @@ export default function() {
595606 /**
596607 * The queue should now look like:
597608 *
598- * 0: node-0
599- * 1: node2-0 (express)
600- * 2: node2-1 (express)
609+ * 0: node2-0 (express)
610+ * 1: node2-1 (express)
611+ * 2: node-0
601612 * 3: node-3
602613 * 4: node-4
603614 */
604615
605- assertBN . equal ( await calculatePositionInQueue ( megapool , 0n ) , 0n ) ;
606- assertBN . equal ( await calculatePositionInQueue ( megapool2 , 0n ) , 1n ) ;
607- assertBN . equal ( await calculatePositionInQueue ( megapool2 , 1n ) , 2n ) ;
616+ assertBN . equal ( await calculatePositionInQueue ( megapool2 , 0n ) , 0n ) ;
617+ assertBN . equal ( await calculatePositionInQueue ( megapool2 , 1n ) , 1n ) ;
618+ assertBN . equal ( await calculatePositionInQueue ( megapool , 0n ) , 2n ) ;
608619 assertBN . equal ( await calculatePositionInQueue ( megapool , 3n ) , 3n ) ;
609620 assertBN . equal ( await calculatePositionInQueue ( megapool , 4n ) , 4n ) ;
610621 } ) ;
@@ -970,7 +981,7 @@ export default function() {
970981 // Reduce reduced.bond to 2 ETH
971982 await setDAOProtocolBootstrapSetting ( RocketDAOProtocolSettingsNode , 'reduced.bond' , '2' . ether , { from : owner } ) ;
972983 // Set penalty to 0.1 ETH
973- const dissolvePenalty = '0.1' . ether
984+ const dissolvePenalty = '0.1' . ether ;
974985 await setDAOProtocolBootstrapSetting ( RocketDAOProtocolSettingsMegapool , 'megapool.dissolve.penalty' , dissolvePenalty , { from : owner } ) ;
975986 // Deposit 56 ETH
976987 await userDeposit ( { from : random , value : '20' . ether } ) ;
@@ -988,7 +999,7 @@ export default function() {
988999 await shouldRevert (
9891000 nodeDeposit ( node , '4' . ether ) ,
9901001 'Was able to deposit with 4 ETH' ,
991- 'Bond requirement not met'
1002+ 'Bond requirement not met' ,
9921003 ) ;
9931004 // Bond requirement for 5 validators is now 20 ETH and NO has 12, so 8 ETH is required
9941005 await nodeDeposit ( node , '8' . ether ) ;
@@ -1038,7 +1049,7 @@ export default function() {
10381049 // Reduce reduced.bond to 2 ETH
10391050 await setDAOProtocolBootstrapSetting ( RocketDAOProtocolSettingsNode , 'reduced.bond' , '2' . ether , { from : owner } ) ;
10401051 // Set penalty to 0.1 ETH
1041- const dissolvePenalty = '0.1' . ether
1052+ const dissolvePenalty = '0.1' . ether ;
10421053 await setDAOProtocolBootstrapSetting ( RocketDAOProtocolSettingsMegapool , 'megapool.dissolve.penalty' , dissolvePenalty , { from : owner } ) ;
10431054 // Deposit 56 ETH
10441055 await userDeposit ( { from : random , value : '20' . ether } ) ;
@@ -1112,8 +1123,7 @@ export default function() {
11121123 }
11131124 assertBN . equal ( await megapool . getNodeBond ( ) , '0' . ether ) ;
11141125 assertBN . equal ( await megapool . getUserCapital ( ) , '0' . ether ) ;
1115- } )
1116-
1126+ } ) ;
11171127
11181128 it ( printTitle ( 'node' , 'cannot exit queue to underbonded state due to dissolves' ) , async ( ) => {
11191129 const dissolvePeriod = ( 60 * 60 * 24 * 10 ) ; // 10 Days
@@ -1156,12 +1166,12 @@ export default function() {
11561166 * Exiting the queue now would result in NO being underbonded
11571167 */
11581168 {
1159- const bondRequirement = await rocketNodeDeposit . getBondRequirement ( await megapool . getActiveValidatorCount ( ) )
1160- const nodeBond = await megapool . getNodeBond ( )
1161- const nodeQueuedBond = await megapool . getNodeQueuedBond ( )
1162- assertBN . equal ( bondRequirement , '24' . ether )
1163- assertBN . equal ( nodeBond , '0' . ether )
1164- assertBN . equal ( nodeQueuedBond , '24' . ether )
1169+ const bondRequirement = await rocketNodeDeposit . getBondRequirement ( await megapool . getActiveValidatorCount ( ) ) ;
1170+ const nodeBond = await megapool . getNodeBond ( ) ;
1171+ const nodeQueuedBond = await megapool . getNodeQueuedBond ( ) ;
1172+ assertBN . equal ( bondRequirement , '24' . ether ) ;
1173+ assertBN . equal ( nodeBond , '0' . ether ) ;
1174+ assertBN . equal ( nodeQueuedBond , '24' . ether ) ;
11651175 }
11661176 // NO cannot exit queued
11671177 await shouldRevert ( exitQueue ( node , 18n ) , 'Was able to exit queue' , 'Bond requirement not met' ) ;
@@ -1174,12 +1184,12 @@ export default function() {
11741184 * NO should now be able to exit a validator from the queue
11751185 */
11761186 {
1177- const bondRequirement = await rocketNodeDeposit . getBondRequirement ( await megapool . getActiveValidatorCount ( ) )
1178- const nodeBond = await megapool . getNodeBond ( )
1179- const nodeQueuedBond = await megapool . getNodeQueuedBond ( )
1180- assertBN . equal ( bondRequirement , '22' . ether )
1181- assertBN . equal ( nodeBond , '0' . ether )
1182- assertBN . equal ( nodeQueuedBond , '24' . ether )
1187+ const bondRequirement = await rocketNodeDeposit . getBondRequirement ( await megapool . getActiveValidatorCount ( ) ) ;
1188+ const nodeBond = await megapool . getNodeBond ( ) ;
1189+ const nodeQueuedBond = await megapool . getNodeQueuedBond ( ) ;
1190+ assertBN . equal ( bondRequirement , '22' . ether ) ;
1191+ assertBN . equal ( nodeBond , '0' . ether ) ;
1192+ assertBN . equal ( nodeQueuedBond , '24' . ether ) ;
11831193 }
11841194 await exitQueue ( node , 18n ) ;
11851195 // Disable assignments to prevent exits from performing assignments
@@ -1194,12 +1204,12 @@ export default function() {
11941204 }
11951205 // Check state
11961206 {
1197- const bondRequirement = await rocketNodeDeposit . getBondRequirement ( await megapool . getActiveValidatorCount ( ) )
1198- const nodeBond = await megapool . getNodeBond ( )
1199- const nodeQueuedBond = await megapool . getNodeQueuedBond ( )
1200- assertBN . equal ( bondRequirement , '0' . ether )
1201- assertBN . equal ( nodeBond , '0' . ether )
1202- assertBN . equal ( nodeQueuedBond , '0' . ether )
1207+ const bondRequirement = await rocketNodeDeposit . getBondRequirement ( await megapool . getActiveValidatorCount ( ) ) ;
1208+ const nodeBond = await megapool . getNodeBond ( ) ;
1209+ const nodeQueuedBond = await megapool . getNodeQueuedBond ( ) ;
1210+ assertBN . equal ( bondRequirement , '0' . ether ) ;
1211+ assertBN . equal ( nodeBond , '0' . ether ) ;
1212+ assertBN . equal ( nodeQueuedBond , '0' . ether ) ;
12031213 }
12041214 } ) ;
12051215
@@ -1315,6 +1325,7 @@ export default function() {
13151325 } ) ;
13161326
13171327 it ( printTitle ( 'node' , 'can create new validators per bond requirements' ) , async ( ) => {
1328+ await mockExpressTickets ( node . address , 2 )
13181329 await shouldRevert ( nodeDeposit ( node , '8' . ether ) , 'Created validator' , 'Bond requirement not met' ) ;
13191330 await shouldRevert ( nodeDeposit ( node , '2' . ether ) , 'Created validator' , 'Bond requirement not met' ) ;
13201331 await nodeDeposit ( node ) ;
@@ -1325,7 +1336,8 @@ export default function() {
13251336 await shouldRevert ( nodeDeposit ( node , '2' . ether ) , 'Created validator' , 'Bond requirement not met' ) ;
13261337 } ) ;
13271338
1328- it ( printTitle ( 'node' , 'can not consume more than 2 provisioned express tickets' ) , async ( ) => {
1339+ it ( printTitle ( 'node' , 'can not consume more than provisioned express tickets' ) , async ( ) => {
1340+ await mockExpressTickets ( node . address , 2 )
13291341 await nodeDeposit ( node , '4' . ether , true ) ;
13301342 await nodeDeposit ( node , '4' . ether , true ) ;
13311343 await shouldRevert ( nodeDeposit ( node , '4' . ether , true ) , 'Consumed express ticket' , 'No express tickets' ) ;
@@ -1336,6 +1348,7 @@ export default function() {
13361348 } ) ;
13371349
13381350 it ( printTitle ( 'node' , 'can create a new validator with an express ticket' ) , async ( ) => {
1351+ await mockExpressTickets ( node . address , 1 )
13391352 await nodeDeposit ( node , '4' . ether , true ) ;
13401353 } ) ;
13411354
@@ -1361,7 +1374,7 @@ export default function() {
13611374
13621375 it ( printTitle ( 'node' , 'can stake after dissolve when dusted' ) , async ( ) => {
13631376 // Set penalty to 0.1 ETH
1364- const dissolvePenalty = '0.1' . ether
1377+ const dissolvePenalty = '0.1' . ether ;
13651378 await setDAOProtocolBootstrapSetting ( RocketDAOProtocolSettingsMegapool , 'megapool.dissolve.penalty' , dissolvePenalty , { from : owner } ) ;
13661379 // Dissolve a validator
13671380 await nodeDeposit ( node ) ;
@@ -1377,7 +1390,7 @@ export default function() {
13771390 // Try to staka
13781391 await nodeDeposit ( node ) ;
13791392 await stakeMegapoolValidator ( megapool , 1n ) ;
1380- } )
1393+ } ) ;
13811394
13821395 it ( printTitle ( 'node' , 'can not exit a dissolve validator with invalid withdrawalCredentials' ) , async ( ) => {
13831396 await nodeDeposit ( node ) ;
0 commit comments