@@ -5532,7 +5532,7 @@ describe("BondingManager", () => {
55325532 it ( "should fail if caller is not a transcoder" , async ( ) => {
55335533 await expect (
55345534 bondingManager . connect ( nonTranscoder ) . reward ( )
5535- ) . to . be . revertedWith ( "caller must be an active transcoder " )
5535+ ) . to . be . revertedWith ( "transcoder must be active" )
55365536 } )
55375537
55385538 it ( "should fail if caller is registered but not an active transcoder yet in the current round" , async ( ) => {
@@ -5542,7 +5542,7 @@ describe("BondingManager", () => {
55425542 )
55435543 await expect (
55445544 bondingManager . connect ( transcoder ) . reward ( )
5545- ) . to . be . revertedWith ( "caller must be an active transcoder " )
5545+ ) . to . be . revertedWith ( "transcoder must be active" )
55465546 } )
55475547
55485548 it ( "should fail if caller already called reward during the current round" , async ( ) => {
@@ -6158,6 +6158,130 @@ describe("BondingManager", () => {
61586158 atCeilingTest ( "when above limit" , 1500 )
61596159 } )
61606160 } )
6161+
6162+ describe ( "reward delegation" , ( ) => {
6163+ const transcoderRewards = 1000
6164+
6165+ it ( "should allow a transcoder to call reward even if RewardCaller is set" , async ( ) => {
6166+ const setRewardCallerTx = bondingManager
6167+ . connect ( transcoder )
6168+ . setRewardCaller ( nonTranscoder . address )
6169+ await expect ( setRewardCallerTx )
6170+ . to . emit ( bondingManager , "RewardCallerSet" )
6171+ . withArgs ( transcoder . address , nonTranscoder . address )
6172+
6173+ const rewardTx = bondingManager . connect ( transcoder ) . reward ( )
6174+ await expect ( rewardTx )
6175+ . to . emit ( bondingManager , "Reward" )
6176+ . withArgs ( transcoder . address , transcoderRewards )
6177+
6178+ await fixture . roundsManager . setMockUint256 (
6179+ functionSig ( "currentRound()" ) ,
6180+ currentRound + 3
6181+ )
6182+
6183+ const unsetRewardCallerTx = bondingManager
6184+ . connect ( transcoder )
6185+ . setRewardCaller ( ZERO_ADDRESS )
6186+ await expect ( unsetRewardCallerTx )
6187+ . to . emit ( bondingManager , "RewardCallerSet" )
6188+ . withArgs ( transcoder . address , ZERO_ADDRESS )
6189+
6190+ const rewardTx2 = bondingManager . connect ( transcoder ) . reward ( )
6191+ await expect ( rewardTx2 )
6192+ . to . emit ( bondingManager , "Reward" )
6193+ . withArgs ( transcoder . address , transcoderRewards )
6194+ } )
6195+
6196+ it ( "should allow a RewardCaller to call reward" , async ( ) => {
6197+ const setRewardCallerTx = bondingManager
6198+ . connect ( transcoder )
6199+ . setRewardCaller ( nonTranscoder . address )
6200+ await expect ( setRewardCallerTx )
6201+ . to . emit ( bondingManager , "RewardCallerSet" )
6202+ . withArgs ( transcoder . address , nonTranscoder . address )
6203+
6204+ const rewardTx = bondingManager
6205+ . connect ( nonTranscoder )
6206+ . rewardForTranscoder ( transcoder . address )
6207+ await expect ( rewardTx )
6208+ . to . emit ( bondingManager , "Reward" )
6209+ . withArgs ( transcoder . address , transcoderRewards )
6210+
6211+ await fixture . roundsManager . setMockUint256 (
6212+ functionSig ( "currentRound()" ) ,
6213+ currentRound + 3
6214+ )
6215+
6216+ const unsetRewardCallerTx = bondingManager
6217+ . connect ( transcoder )
6218+ . setRewardCaller ( ZERO_ADDRESS )
6219+ await expect ( unsetRewardCallerTx )
6220+ . to . emit ( bondingManager , "RewardCallerSet" )
6221+ . withArgs ( transcoder . address , ZERO_ADDRESS )
6222+
6223+ const rewardTx2 = bondingManager
6224+ . connect ( nonTranscoder )
6225+ . rewardForTranscoder ( transcoder . address )
6226+ await expect ( rewardTx2 ) . to . be . revertedWith (
6227+ "caller must be a reward caller set by the transcoder"
6228+ )
6229+ } )
6230+
6231+ it ( "should fail if system is paused" , async ( ) => {
6232+ await bondingManager
6233+ . connect ( transcoder )
6234+ . setRewardCaller ( nonTranscoder . address )
6235+
6236+ await fixture . controller . pause ( )
6237+ const setRewardCallerTx = bondingManager
6238+ . connect ( transcoder )
6239+ . setRewardCaller ( nonTranscoder . address )
6240+ await expect ( setRewardCallerTx ) . to . be . revertedWith (
6241+ "system is paused"
6242+ )
6243+
6244+ const rewardTx = bondingManager
6245+ . connect ( nonTranscoder )
6246+ . rewardForTranscoder ( transcoder . address )
6247+ await expect ( rewardTx ) . to . be . revertedWith ( "system is paused" )
6248+ } )
6249+
6250+ it ( "should fail if current round is not initialized" , async ( ) => {
6251+ await bondingManager
6252+ . connect ( transcoder )
6253+ . setRewardCaller ( nonTranscoder . address )
6254+ await fixture . roundsManager . setMockBool (
6255+ functionSig ( "currentRoundInitialized()" ) ,
6256+ false
6257+ )
6258+ const rewardTx = bondingManager
6259+ . connect ( nonTranscoder )
6260+ . rewardForTranscoder ( transcoder . address )
6261+ await expect ( rewardTx ) . to . be . revertedWith (
6262+ "current round is not initialized"
6263+ )
6264+ } )
6265+
6266+ it ( "should always checkpoint the reward recipient, not the RewardCaller" , async ( ) => {
6267+ await bondingManager
6268+ . connect ( transcoder )
6269+ . setRewardCaller ( nonTranscoder . address )
6270+ const rewardCallerTx = await bondingManager
6271+ . connect ( nonTranscoder )
6272+ . rewardForTranscoder ( transcoder . address )
6273+
6274+ await expectCheckpoints ( fixture , rewardCallerTx , {
6275+ account : transcoder . address ,
6276+ startRound : currentRound + 2 ,
6277+ bondedAmount : 1000 ,
6278+ delegateAddress : transcoder . address ,
6279+ delegatedAmount : 2000 ,
6280+ lastClaimRound : currentRound ,
6281+ lastRewardRound : currentRound + 1
6282+ } )
6283+ } )
6284+ } )
61616285 } )
61626286
61636287 describe ( "updateTranscoderWithFees" , ( ) => {
0 commit comments