@@ -94,6 +94,19 @@ contract("FullyBackedSortitionPool", (accounts) => {
9494
9595 assert . isTrue ( await pool . isOperatorInitialized ( alice ) )
9696 } )
97+
98+ it ( "reverts when operator gets banned in the pool" , async ( ) => {
99+ await prepareOperator ( alice , bond )
100+
101+ await mineBlocks ( operatorInitBlocks . addn ( 1 ) )
102+
103+ await pool . ban ( alice , { from : owner } )
104+
105+ expectRevert (
106+ pool . isOperatorInitialized ( alice ) ,
107+ "Operator is not in the pool" ,
108+ )
109+ } )
97110 } )
98111
99112 describe ( "selectSetGroup" , async ( ) => {
@@ -160,7 +173,7 @@ contract("FullyBackedSortitionPool", (accounts) => {
160173
161174 await expectRevert (
162175 pool . selectSetGroup ( 3 , seed , minimumBondableValue , { from : alice } ) ,
163- "Only owner may select groups " ,
176+ "Caller is not the owner " ,
164177 )
165178 } )
166179
@@ -221,6 +234,34 @@ contract("FullyBackedSortitionPool", (accounts) => {
221234 await pool . selectSetGroup ( 3 , seed , minimumBondableValue , { from : owner } )
222235 } )
223236
237+ it ( "reverts when operator gets banned in the sortition pool" , async ( ) => {
238+ // Register three operators.
239+ await prepareOperator ( alice , bond )
240+ await prepareOperator ( bob , bond )
241+ await prepareOperator ( carol , bond )
242+
243+ assert . equal ( await pool . operatorsInPool ( ) , 3 )
244+
245+ // Initialization period passed.
246+ await mineBlocks ( operatorInitBlocks . addn ( 1 ) )
247+
248+ await pool . selectSetGroup ( 2 , seed , minimumBondableValue , { from : owner } )
249+
250+ // Ban an operator.
251+ await pool . ban ( carol , { from : owner } )
252+
253+ assert . equal (
254+ await pool . operatorsInPool ( ) ,
255+ 2 ,
256+ "incorrect number of operators after operator ban" ,
257+ )
258+
259+ await expectRevert (
260+ pool . selectSetGroup ( 3 , seed , minimumBondableValue , { from : owner } ) ,
261+ "Not enough operators in pool" ,
262+ )
263+ } )
264+
224265 it ( "removes minimum-bond-ineligible operators and still works afterwards" , async ( ) => {
225266 await prepareOperator ( alice , bond )
226267 await prepareOperator ( bob , bond )
@@ -382,5 +423,57 @@ contract("FullyBackedSortitionPool", (accounts) => {
382423 "Operator is already registered in the pool" ,
383424 )
384425 } )
426+
427+ it ( "fails for banned operator" , async ( ) => {
428+ await pool . ban ( alice , { from : owner } )
429+
430+ await bonding . setBondableValue ( alice , minimumBondableValue )
431+ await bonding . setInitialized ( alice , true )
432+
433+ await expectRevert ( pool . joinPool ( alice ) , "Operator not eligible" )
434+ } )
435+ } )
436+
437+ describe ( "ban" , async ( ) => {
438+ it ( "adds operator to banned operators" , async ( ) => {
439+ expect ( await pool . bannedOperators ( alice ) ) . to . be . false
440+
441+ await pool . ban ( alice , { from : owner } )
442+
443+ expect ( await pool . bannedOperators ( alice ) ) . to . be . true
444+ } )
445+
446+ it ( "does not revert when called multiple times" , async ( ) => {
447+ expect ( await pool . bannedOperators ( alice ) ) . to . be . false
448+
449+ await pool . ban ( alice , { from : owner } )
450+ await pool . ban ( alice , { from : owner } )
451+
452+ expect ( await pool . bannedOperators ( alice ) ) . to . be . true
453+ } )
454+
455+ it ( "does not revert when operator is not registered" , async ( ) => {
456+ expect ( await pool . isOperatorRegistered ( alice ) ) . to . be . false
457+
458+ await pool . ban ( alice , { from : owner } )
459+ } )
460+
461+ it ( "removes operator from the pool" , async ( ) => {
462+ await bonding . setBondableValue ( alice , minimumBondableValue )
463+ await bonding . setInitialized ( alice , true )
464+ await pool . joinPool ( alice )
465+
466+ expect ( await pool . isOperatorRegistered ( alice ) ) . to . be . true
467+
468+ await pool . ban ( alice , { from : owner } )
469+
470+ expect ( await pool . isOperatorRegistered ( alice ) ) . to . be . false
471+ expect ( await pool . isOperatorInPool ( alice ) ) . to . be . false
472+ expect ( await pool . getPoolWeight ( alice ) ) . to . eq . BN ( 0 )
473+ } )
474+
475+ it ( "reverts when called by non-owner" , async ( ) => {
476+ await expectRevert ( pool . ban ( alice ) , "Caller is not the owner" )
477+ } )
385478 } )
386479} )
0 commit comments