diff --git a/pallets/subspace/tests/delegate_staking.rs b/pallets/subspace/tests/delegate_staking.rs index 7cebdbac9..5a523298c 100644 --- a/pallets/subspace/tests/delegate_staking.rs +++ b/pallets/subspace/tests/delegate_staking.rs @@ -3,7 +3,6 @@ mod mock; use frame_support::assert_ok; use mock::*; use sp_core::U256; -use substrate_fixed::types::I64F64; // /*********************************************************** // staking::add_stake() tests @@ -39,20 +38,24 @@ fn test_ownership_ratio() { let num_modules: u16 = 10; let tempo = 1; let stake_per_module: u64 = 1_000_000_000; + register_n_modules(netuid, num_modules, stake_per_module); SubspaceModule::set_tempo(netuid, tempo); let keys = SubspaceModule::get_keys(netuid); let voter_key = keys[0]; let miner_keys = keys[1..].to_vec(); - let miner_uids: Vec = - miner_keys.iter().map(|k| SubspaceModule::get_uid_for_key(netuid, k)).collect(); + let delegate_keys = (0..num_modules) + .map(|key| U256::from(key + num_modules + 1)) + .collect::>(); + let miner_uids = miner_keys + .iter() + .map(|key| SubspaceModule::get_uid_for_key(netuid, key)) + .collect::>(); let miner_weights = vec![1; miner_uids.len()]; - let delegate_keys: Vec = - (0..num_modules).map(|i| U256::from(i + num_modules + 1)).collect(); - for d in delegate_keys.iter() { - add_balance(*d, stake_per_module + 1); + for key in delegate_keys.iter() { + add_balance(*key, stake_per_module + 1); } let pre_delegate_stake_from_vector = @@ -60,38 +63,22 @@ fn test_ownership_ratio() { assert_eq!(pre_delegate_stake_from_vector.len(), 1); // +1 for the module itself, +1 for the delegate key on for (i, d) in delegate_keys.iter().enumerate() { - println!("DELEGATE KEY: {}", d); assert_ok!(SubspaceModule::add_stake( get_origin(*d), netuid, voter_key, stake_per_module )); + let stake_from_vector = SubspaceModule::get_stake_from_vector(netuid, &voter_key); assert_eq!( stake_from_vector.len(), pre_delegate_stake_from_vector.len() + i + 1 ); } - let ownership_ratios: Vec<(U256, I64F64)> = - SubspaceModule::get_ownership_ratios(netuid, &voter_key); + let ownership_ratios = SubspaceModule::get_ownership_ratios(netuid, &voter_key); assert_eq!(ownership_ratios.len(), delegate_keys.len() + 1); - let founder_tokens_before = SubspaceModule::get_balance(&voter_key) - + SubspaceModule::get_stake_to_module(netuid, &voter_key, &voter_key); - - let delegate_balances_before = - delegate_keys.iter().map(SubspaceModule::get_balance).collect::>(); - let delegate_stakes_before = delegate_keys - .iter() - .map(|k| SubspaceModule::get_stake_to_module(netuid, k, &voter_key)) - .collect::>(); - let delegate_total_tokens_before = delegate_balances_before - .iter() - .zip(delegate_stakes_before.clone()) - .map(|(a, x)| a + x) - .sum::(); - let total_balance = keys .iter() .map(SubspaceModule::get_balance) @@ -118,68 +105,19 @@ fn test_ownership_ratio() { .sum::(); let total_tokens_before = total_balance + total_stake + total_delegate_stake + total_delegate_balance; - println!("total_tokens_before: {:?}", total_tokens_before); - - println!("delegate_balances before: {:?}", delegate_balances_before); - println!("delegate_stakes before: {:?}", delegate_stakes_before); - println!( - "delegate_total_tokens before: {:?}", - delegate_total_tokens_before - ); - let result = SubspaceModule::set_weights( + assert_ok!(SubspaceModule::set_weights( get_origin(voter_key), netuid, miner_uids.clone(), miner_weights.clone(), - ); - - assert_ok!(result); + )); step_epoch(netuid); - let dividends = SubspaceModule::get_dividends(netuid); - let incentives = SubspaceModule::get_incentives(netuid); let emissions = SubspaceModule::get_emissions(netuid); - - println!("dividends: {:?}", dividends); - println!("incentives: {:?}", incentives); - println!("emissions: {:?}", emissions); let total_emissions = emissions.iter().sum::(); - println!("total_emissions: {:?}", total_emissions); - - let delegate_balances = - delegate_keys.iter().map(SubspaceModule::get_balance).collect::>(); - let delegate_stakes = delegate_keys - .iter() - .map(|k| SubspaceModule::get_stake_to_module(netuid, k, &voter_key)) - .collect::>(); - let delegate_total_tokens = delegate_balances - .iter() - .zip(delegate_stakes.clone()) - .map(|(a, x)| a + x) - .sum::(); - let founder_tokens = SubspaceModule::get_balance(&voter_key) - + SubspaceModule::get_stake_to_module(netuid, &voter_key, &voter_key); - let founder_new_tokens = founder_tokens - founder_tokens_before; - let delegate_new_tokens: Vec = delegate_stakes - .iter() - .zip(delegate_stakes_before.clone()) - .map(|(a, x)| a - x) - .collect::>(); - - let total_new_tokens = founder_new_tokens + delegate_new_tokens.iter().sum::(); - - println!("owner_ratios: {:?}", ownership_ratios); - println!("total_new_tokens: {:?}", total_new_tokens); - println!("founder_tokens: {:?}", founder_tokens); - println!("delegate_balances: {:?}", delegate_balances); - println!("delegate_stakes: {:?}", delegate_stakes); - println!("delegate_total_tokens: {:?}", delegate_total_tokens); - println!("founder_new_tokens: {:?}", founder_new_tokens); - println!("delegate_new_tokens: {:?}", delegate_new_tokens); - let total_balance = keys .iter() .map(SubspaceModule::get_balance) @@ -207,14 +145,6 @@ fn test_ownership_ratio() { let total_tokens_after = total_balance + total_stake + total_delegate_stake + total_delegate_balance; let total_new_tokens = total_tokens_after - total_tokens_before; - println!("total_tokens_after: {:?}", total_tokens_before); - println!("total_new_tokens: {:?}", total_new_tokens); assert_eq!(total_new_tokens, total_emissions); - - let stake_from_vector = SubspaceModule::get_stake_from_vector(netuid, &voter_key); - let _stake: u64 = SubspaceModule::get_stake(netuid, &voter_key); - let _sumed_stake: u64 = stake_from_vector.iter().fold(0, |acc, (_a, x)| acc + x); - let _total_stake: u64 = SubspaceModule::get_total_subnet_stake(netuid); - println!("stake_from_vector: {:?}", stake_from_vector); }); }