@@ -47,6 +47,10 @@ contract('KeepRandomBeaconOperator', function(accounts) {
4747
4848 entryFeeEstimate = await serviceContract . entryFeeEstimate ( 0 )
4949 await serviceContract . methods [ 'requestRelayEntry()' ] ( { value : entryFeeEstimate } )
50+
51+ await registry . setRegistryKeeper ( registryKeeper )
52+ await registry . approveOperatorContract ( anotherOperatorContract , { from : registryKeeper } )
53+ await stakingContract . authorizeOperatorContract ( operator1 , anotherOperatorContract , { from : authorizer } )
5054 } )
5155
5256 beforeEach ( async ( ) => {
@@ -58,29 +62,67 @@ contract('KeepRandomBeaconOperator', function(accounts) {
5862 } )
5963
6064 it ( "should slash token amount" , async ( ) => {
61- await registry . setRegistryKeeper ( registryKeeper )
62- await registry . approveOperatorContract ( anotherOperatorContract , { from : registryKeeper } )
63- await stakingContract . authorizeOperatorContract ( operator1 , anotherOperatorContract , { from : authorizer } )
64-
6565 let amountToSlash = web3 . utils . toBN ( 42000000 ) ;
6666 let balanceBeforeSlashing = await stakingContract . balanceOf ( operator1 )
67- await stakingContract . slash ( web3 . utils . toBN ( amountToSlash ) , [ operator1 ] , { from : anotherOperatorContract } )
67+ await stakingContract . slash ( amountToSlash , [ operator1 ] , { from : anotherOperatorContract } )
6868 let balanceAfterSlashing = await stakingContract . balanceOf ( operator1 )
6969
7070 assert . isTrue ( ( balanceBeforeSlashing . sub ( amountToSlash ) ) . eq ( balanceAfterSlashing ) , "Unexpected balance after token slasing" )
7171 } )
7272
7373 it ( "should slash no more than available operator's amount" , async ( ) => {
74- await registry . setRegistryKeeper ( registryKeeper )
75- await registry . approveOperatorContract ( anotherOperatorContract , { from : registryKeeper } )
76- await stakingContract . authorizeOperatorContract ( operator1 , anotherOperatorContract , { from : authorizer } )
77-
7874 let amountToSlash = largeStake . add ( web3 . utils . toBN ( 100 ) ) ;
79- await stakingContract . slash ( web3 . utils . toBN ( amountToSlash ) , [ operator1 ] , { from : anotherOperatorContract } )
75+ await stakingContract . slash ( amountToSlash , [ operator1 ] , { from : anotherOperatorContract } )
8076
8177 assert . isTrue ( ( await stakingContract . balanceOf ( operator1 ) ) . isZero ( ) , "Unexpected balance after token slasing" )
8278 } )
8379
80+ it ( "should seize token amount" , async ( ) => {
81+ let operatorBalanceBeforeSeizing = await stakingContract . balanceOf ( operator1 )
82+ let tattletaleBalanceBeforeSeizing = await token . balanceOf ( tattletale )
83+
84+ let amountToSeize = web3 . utils . toBN ( 42000000 ) ;
85+ let rewardMultiplier = web3 . utils . toBN ( 25 )
86+ await stakingContract . seize ( amountToSeize , rewardMultiplier , tattletale , [ operator1 ] , { from : anotherOperatorContract } )
87+
88+ let operatorBalanceAfterSeizing = await stakingContract . balanceOf ( operator1 )
89+ let tattletaleBalanceAfterSeizing = await token . balanceOf ( tattletale )
90+
91+ assert . isTrue (
92+ ( operatorBalanceBeforeSeizing . sub ( amountToSeize ) ) . eq ( operatorBalanceAfterSeizing ) ,
93+ "Unexpected balance for operator after token seizing"
94+ )
95+
96+ // 525000 = (42000000 * 5 / 100) * 25 / 100
97+ let expectedTattletaleReward = web3 . utils . toBN ( 525000 )
98+ assert . isTrue (
99+ ( tattletaleBalanceBeforeSeizing . add ( expectedTattletaleReward ) ) . eq ( tattletaleBalanceAfterSeizing ) ,
100+ "Unexpected balance for tattletale after token seizing"
101+ )
102+ } )
103+
104+ it ( "should seize no more than available operator's amount" , async ( ) => {
105+ let tattletaleBalanceBeforeSeizing = await token . balanceOf ( tattletale )
106+
107+ let amountToSeize = largeStake . add ( web3 . utils . toBN ( 100 ) ) ; // 400000000000000000000100
108+ let rewardMultiplier = web3 . utils . toBN ( 10 )
109+ await stakingContract . seize ( amountToSeize , rewardMultiplier , tattletale , [ operator1 ] , { from : anotherOperatorContract } )
110+
111+ let tattletaleBalanceAfterSeizing = await token . balanceOf ( tattletale )
112+
113+ assert . isTrue (
114+ ( await stakingContract . balanceOf ( operator1 ) ) . isZero ( ) ,
115+ "Unexpected balance for operator after token seizing"
116+ )
117+
118+ // 2000000000000000000000 = (400000000000000000000100 * 5 / 100) * 10 / 100
119+ let expectedTattletaleReward = web3 . utils . toBN ( "2000000000000000000000" )
120+ assert . isTrue (
121+ ( tattletaleBalanceBeforeSeizing . add ( expectedTattletaleReward ) ) . eq ( tattletaleBalanceAfterSeizing ) ,
122+ "Unexpected balance for tattletale after token seizing"
123+ )
124+ } )
125+
84126 it ( "should be able to report unauthorized signing" , async ( ) => {
85127 await operatorContract . reportUnauthorizedSigning (
86128 groupIndex ,
0 commit comments