diff --git a/integration-tests/src/kusama_test_net.rs b/integration-tests/src/kusama_test_net.rs index 35111d42b0..d2a3b3bd73 100644 --- a/integration-tests/src/kusama_test_net.rs +++ b/integration-tests/src/kusama_test_net.rs @@ -307,6 +307,10 @@ pub mod basilisk { get_account_id_from_seed::("Bob"), get_from_seed::("Bob"), ), + ( + get_account_id_from_seed::("Charlie"), + get_from_seed::("Charlie"), + ), ] } diff --git a/integration-tests/src/lib.rs b/integration-tests/src/lib.rs index 7ae33ebae0..cec3dbd118 100644 --- a/integration-tests/src/lib.rs +++ b/integration-tests/src/lib.rs @@ -10,6 +10,7 @@ mod nft_marketplace; mod non_native_fee; mod oracle; mod router; +mod sessions; mod transact_call_filter; mod vesting; mod xyk; diff --git a/integration-tests/src/sessions.rs b/integration-tests/src/sessions.rs new file mode 100644 index 0000000000..d078598450 --- /dev/null +++ b/integration-tests/src/sessions.rs @@ -0,0 +1,53 @@ +#![cfg(test)] +use crate::kusama_test_net::*; +use basilisk_runtime::CollatorRewards; +use basilisk_runtime::Runtime; +use frame_support::traits::Contains; +use pallet_session::SessionManager; +use polkadot_xcm::v3::prelude::*; +use polkadot_xcm::VersionedXcm; +use xcm_emulator::TestExt; + +#[test] +fn new_session_should_rotate_collators_list() { + TestNet::reset(); + + Basilisk::execute_with(|| { + let collator1 = basilisk::invulnerables()[0].0.clone(); //d435... + let collator2 = basilisk::invulnerables()[1].0.clone(); //8eaf... + let collator3 = basilisk::invulnerables()[2].0.clone(); //90b5... + + let collators = CollatorRewards::new_session(0).unwrap(); + assert_eq!(collators, vec![collator2.clone(), collator3.clone(), collator1.clone()]); + + let collators = CollatorRewards::new_session(1).unwrap(); + assert_eq!(collators, vec![collator2.clone(), collator3.clone(), collator1.clone()]); + + let collators = CollatorRewards::new_session(2).unwrap(); + assert_eq!(collators, vec![collator2.clone(), collator3.clone(), collator1.clone()]); + + let collators = CollatorRewards::new_session(3).unwrap(); + assert_eq!(collators, vec![collator3.clone(), collator1.clone(), collator2.clone()]); + + let collators = CollatorRewards::new_session(4).unwrap(); + assert_eq!(collators, vec![collator3.clone(), collator1.clone(), collator2.clone()]); + + let collators = CollatorRewards::new_session(5).unwrap(); + assert_eq!(collators, vec![collator3.clone(), collator1.clone(), collator2.clone()]); + + let collators = CollatorRewards::new_session(6).unwrap(); + assert_eq!(collators, vec![collator1.clone(), collator2.clone(), collator3.clone()]); + + let collators = CollatorRewards::new_session(7).unwrap(); + assert_eq!(collators, vec![collator1.clone(), collator2.clone(), collator3.clone()]); + + let collators = CollatorRewards::new_session(8).unwrap(); + assert_eq!(collators, vec![collator1.clone(), collator2.clone(), collator3.clone()]); + + let collators = CollatorRewards::new_session(9).unwrap(); + assert_eq!(collators, vec![collator2.clone(), collator3.clone(), collator1.clone()]); + + let collators = CollatorRewards::new_session(10).unwrap(); + assert_eq!(collators, vec![collator2.clone(), collator3.clone(), collator1.clone()]); + }); +} diff --git a/runtime/basilisk/src/system.rs b/runtime/basilisk/src/system.rs index 87ded44ea3..e6f9d7fb03 100644 --- a/runtime/basilisk/src/system.rs +++ b/runtime/basilisk/src/system.rs @@ -17,7 +17,6 @@ use super::*; use crate::governance::{origins::GeneralAdmin, TechCommitteeMajority, TechnicalCollective, TreasuryAccount}; -use sp_io::transaction_index::index; use pallet_transaction_multi_payment::{DepositAll, TransferFees}; use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment}; @@ -551,11 +550,10 @@ impl SessionManager for RotatingCollatorManager { // We wrap the ` SessionManager` implementation of `CollatorSelection` to get the collators that // we hand out rewards to, // then we rotate the collators to have a regular distribution for block production - let mut collators = CollatorSelection::new_session(new_index)?; - if !collators.is_empty() { - collators.rotate_left(1); + if let Some(amount) = (new_index as usize).checked_div(collators.len()) { + collators.rotate_left(amount); } Some(collators)