@@ -119,7 +119,8 @@ where
119119 + Serialize
120120 + Sync
121121 + Add < Output = Epoch >
122- + Div < Output = Epoch > ,
122+ + Div < Output = Epoch >
123+ + PartialOrd ,
123124 Nonce : AddAssign
124125 + Copy
125126 + Debug
@@ -191,8 +192,7 @@ where
191192 + Serialize
192193 + Sync
193194 + Add < Output = Epoch >
194- + Div < Output = Epoch >
195- + PartialOrd ,
195+ + Div < Output = Epoch > ,
196196 Nonce : AddAssign
197197 + Copy
198198 + Debug
@@ -428,7 +428,6 @@ where
428428 let validator = validator. into ( ) ;
429429
430430 // order mining stake entries by rank, as for given current_epoch:
431- // let stakes_clone = self.clone();
432431 let by_rank = self . by_rank ( Capability :: Mining , current_epoch) ;
433432
434433 // locate first entry whose validator matches the one searched for:
@@ -446,7 +445,7 @@ where
446445 if let Some ( stake_entry) = stake_entry {
447446 let penalty_epochs = Epoch :: from ( ( 1 + winner_rank - index) as u32 ) ;
448447 log:: debug!(
449- "Resetting mining power of {} (ranked as #{}) during +{} epochs to {}" ,
448+ "Resetting mining power of {} (ranked as #{}) during +{} epochs until {}" ,
450449 key,
451450 index + 1 ,
452451 penalty_epochs,
@@ -1486,6 +1485,55 @@ mod tests {
14861485 assert_eq ! ( stakes. query_nonce( bob_david) , Ok ( 3 ) ) ;
14871486 }
14881487
1488+ #[ test]
1489+ fn test_stakes_cloneability ( ) {
1490+ // First, lets create a setup with a few stakers
1491+ let mut stakes = StakesTester :: default ( ) ;
1492+ let alice = "Alice" ;
1493+ let bob = "Bob" ;
1494+ let charlie = "Charlie" ;
1495+ let david = "David" ;
1496+
1497+ // Add some stake and verify the power
1498+ stakes
1499+ . add_stake ( ( alice, charlie) , 10 , 0 , MIN_STAKE_NANOWITS )
1500+ . unwrap ( ) ;
1501+ stakes
1502+ . add_stake ( ( bob, david) , 20 , 10 , MIN_STAKE_NANOWITS )
1503+ . unwrap ( ) ;
1504+ assert_eq ! ( stakes. query_power( alice, Capability :: Mining , 30 ) , Ok ( 300 ) ) ;
1505+ assert_eq ! ( stakes. query_power( bob, Capability :: Mining , 30 ) , Ok ( 400 ) ) ;
1506+
1507+ // Clone the stakes structure and verify the power
1508+ let cloned_stakes = stakes. clone ( ) ;
1509+ assert_eq ! (
1510+ cloned_stakes. query_power( alice, Capability :: Mining , 30 ) ,
1511+ Ok ( 300 )
1512+ ) ;
1513+ assert_eq ! (
1514+ cloned_stakes. query_power( bob, Capability :: Mining , 30 ) ,
1515+ Ok ( 400 )
1516+ ) ;
1517+
1518+ // Reset age and verify power
1519+ stakes. reset_age ( alice, Capability :: Mining , 25 , 1 ) . unwrap ( ) ;
1520+ stakes. reset_age ( bob, Capability :: Mining , 30 , 1 ) . unwrap ( ) ;
1521+
1522+ // Power of validators in stakes should have changed
1523+ assert_eq ! ( stakes. query_power( alice, Capability :: Mining , 30 ) , Ok ( 50 ) ) ;
1524+ assert_eq ! ( stakes. query_power( bob, Capability :: Mining , 30 ) , Ok ( 0 ) ) ;
1525+
1526+ // Power of validators in cloned_stakes should have changed
1527+ assert_eq ! (
1528+ cloned_stakes. query_power( alice, Capability :: Mining , 30 ) ,
1529+ Ok ( 300 )
1530+ ) ;
1531+ assert_eq ! (
1532+ cloned_stakes. query_power( bob, Capability :: Mining , 30 ) ,
1533+ Ok ( 400 )
1534+ ) ;
1535+ }
1536+
14891537 #[ test]
14901538 fn test_reset_mining_age ( ) {
14911539 // First, lets create a setup with a few stakers
0 commit comments