diff --git a/src/contract.rs b/src/contract.rs index c4dfc6f..3aa126a 100644 --- a/src/contract.rs +++ b/src/contract.rs @@ -5,6 +5,7 @@ use cosmwasm_std::{ Uint128, }; use cw2::{get_contract_version, set_contract_version, ContractVersion}; +use cyber_std::Response; use cyber_std::{create_creat_thought_msg, Load, Trigger}; use crate::block_step::block_step; @@ -25,9 +26,9 @@ use crate::state::{ LAST_UPDATE, MAX_ALLOWED_UIDS, MAX_ALLOWED_VALIDATORS, MAX_BURN, MAX_DIFFICULTY, MAX_REGISTRATION_PER_BLOCK, MAX_WEIGHTS_LIMIT, MIN_ALLOWED_WEIGHTS, MIN_BURN, MIN_DIFFICULTY, NETWORKS_ADDED, NETWORK_IMMUNITY_PERIOD, NETWORK_LAST_LOCK_COST, NETWORK_LAST_REGISTERED, - NETWORK_LOCK_REDUCTION_INTERVAL, NETWORK_MIN_ALLOWED_UIDS, NETWORK_MIN_LOCK_COST, - NETWORK_MODALITY, NETWORK_RATE_LIMIT, NETWORK_REGISTERED_AT, NETWORK_REGISTRATION_ALLOWED, - OWNER, PENDING_EMISSION, POW_REGISTRATIONS_THIS_INTERVAL, PROMETHEUS, PRUNING_SCORES, RANK, + NETWORK_LOCK_REDUCTION_INTERVAL, NETWORK_MIN_LOCK_COST, NETWORK_MODALITY, NETWORK_RATE_LIMIT, + NETWORK_REGISTERED_AT, NETWORK_REGISTRATION_ALLOWED, OWNER, PENDING_EMISSION, + POW_REGISTRATIONS_THIS_INTERVAL, PROMETHEUS, PRUNING_SCORES, RANK, RAO_RECYCLED_FOR_REGISTRATION, REGISTRATIONS_THIS_BLOCK, REGISTRATIONS_THIS_INTERVAL, RHO, ROOT, SCALING_LAW_POWER, SERVING_RATE_LIMIT, STAKE, SUBNETWORK_N, SUBNET_LIMIT, SUBNET_LOCKED, SUBNET_OWNER, SUBNET_OWNER_CUT, TARGET_REGISTRATIONS_PER_INTERVAL, TEMPO, TOTAL_COLDKEY_STAKE, @@ -36,6 +37,7 @@ use crate::state::{ }; use crate::state_info::get_state_info; use crate::subnet_info::{get_subnet_hyperparams, get_subnet_info, get_subnets_info}; +use crate::uids::get_registered_networks_for_hotkey; use crate::utils::{ do_sudo_set_activity_cutoff, do_sudo_set_adjustment_alpha, do_sudo_set_adjustment_interval, do_sudo_set_block_emission, do_sudo_set_bonds_moving_average, do_sudo_set_default_take, @@ -55,15 +57,9 @@ use crate::utils::{ }; use crate::weights::{do_set_weights, get_network_weights, get_network_weights_sparse}; -// use cw2::set_contract_version; - -// version info for migration info const CONTRACT_NAME: &str = "cybernet"; const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); -use crate::uids::get_registered_networks_for_hotkey; -use cyber_std::Response; - #[cfg_attr(not(feature = "library"), entry_point)] pub fn instantiate( deps: DepsMut, @@ -75,7 +71,12 @@ pub fn instantiate( ROOT.save(deps.storage, &info.sender)?; ALLOW_FAUCET.save(deps.storage, &false)?; - DENOM.save(deps.storage, &"boot".to_string())?; + + if info.funds.len() > 0 { + DENOM.save(deps.storage, &info.funds[0].denom)?; + } else { + DENOM.save(deps.storage, &"boot".to_string())?; + } // TODO remove from InstantiateMsg // // Set initial total issuance from balances @@ -88,16 +89,16 @@ pub fn instantiate( NETWORK_IMMUNITY_PERIOD.save(deps.storage, &7200)?; BLOCK_EMISSION.save(deps.storage, &1_000_000_000)?; - NETWORK_MIN_ALLOWED_UIDS.save(deps.storage, &0)?; SUBNET_OWNER_CUT.save(deps.storage, &0)?; NETWORK_RATE_LIMIT.save(deps.storage, &0)?; - DEFAULT_TAKE.save(deps.storage, &11_796)?; - TX_RATE_LIMIT.save(deps.storage, &1000)?; + // 6.25% (2^12/2^16) + DEFAULT_TAKE.save(deps.storage, &4096)?; + TX_RATE_LIMIT.save(deps.storage, &0)?; NETWORK_LAST_LOCK_COST.save(deps.storage, &100_000_000_000)?; NETWORK_MIN_LOCK_COST.save(deps.storage, &100_000_000_000)?; - NETWORK_LOCK_REDUCTION_INTERVAL.save(deps.storage, &2)?; // test value, change to 14 * 7200; + NETWORK_LOCK_REDUCTION_INTERVAL.save(deps.storage, &(7 * 7200))?; // test value, change to 14 * 7200; // -- Root network initialization -- diff --git a/src/error.rs b/src/error.rs index 5d1bdf2..4591b3a 100644 --- a/src/error.rs +++ b/src/error.rs @@ -79,7 +79,7 @@ pub enum ContractError { #[error("Thrown if the vaule is invalid for MaxAllowedUids.")] MaxAllowedUIdsNotAllowed {}, - #[error("Thrown when the dispatch attempts to convert between a u64 and T::balance but the call fails.")] + #[error("Thrown when wrong denom passed to the contract as payment")] CouldNotConvertToBalance {}, #[error("Thrown when the caller requests adding stake for a hotkey to the total stake which already added.")] diff --git a/src/root.rs b/src/root.rs index ae52b89..916d91a 100644 --- a/src/root.rs +++ b/src/root.rs @@ -28,9 +28,8 @@ use crate::state::{ use crate::uids::{append_neuron, get_hotkey_for_net_and_uid, get_subnetwork_n, replace_neuron}; use crate::utils::{ get_block_emission, get_emission_value, get_max_allowed_uids, get_max_registrations_per_block, - get_registrations_this_block, get_registrations_this_interval, get_rho, - get_subnet_owner, get_target_registrations_per_interval, get_tempo, - set_subnet_locked_balance, + get_registrations_this_block, get_registrations_this_interval, get_rho, get_subnet_owner, + get_target_registrations_per_interval, get_tempo, set_subnet_locked_balance, }; use crate::ContractError; @@ -785,7 +784,6 @@ pub fn init_new_network( TARGET_REGISTRATIONS_PER_INTERVAL.save(store, netuid, &1)?; ADJUSTMENTS_ALPHA.save(store, netuid, &58000)?; IMMUNITY_PERIOD.save(store, netuid, &7200)?; - MIN_BURN.save(store, netuid, &1)?; DIFFICULTY.save(store, netuid, &10_000_000)?; MIN_DIFFICULTY.save(store, netuid, &10_000_000)?; @@ -810,9 +808,11 @@ pub fn init_new_network( BONDS_MOVING_AVERAGE.save(store, netuid, &900_000)?; LAST_ADJUSTMENT_BLOCK.save(store, netuid, &0)?; ADJUSTMENT_INTERVAL.save(store, netuid, &100)?; - BURN.save(store, netuid, &0)?; - // MIN_BURN.save(store, netuid,&0)?; - MAX_BURN.save(store, netuid, &1_000_000_000)?; + + BURN.save(store, netuid, &1_000_000_000)?; + MIN_BURN.save(store, netuid, &100_000_000)?; + MAX_BURN.save(store, netuid, &100_000_000_000)?; + REGISTRATIONS_THIS_BLOCK.save(store, netuid, &0)?; // MAX_REGISTRATION_PER_BLOCK.save(store, netuid, &3)?; KAPPA.save(store, netuid, &32_767)?; diff --git a/src/serving.rs b/src/serving.rs index cd19e69..668731a 100644 --- a/src/serving.rs +++ b/src/serving.rs @@ -114,8 +114,10 @@ pub fn do_serve_axon( AXONS.save(deps.storage, (netuid, &hotkey_id), &prev_axon)?; // --- 8. We deposit axon served event. - deps.api - .debug(&format!("๐Ÿ“ก AxonServed ( hotkey:{:?} ) ", hotkey_id.clone())); + deps.api.debug(&format!( + "๐Ÿ“ก AxonServed ( hotkey:{:?} ) ", + hotkey_id.clone() + )); // --- 9. Return is successful dispatch. Ok(Response::default() diff --git a/src/staking.rs b/src/staking.rs index 17c2aff..77d567a 100644 --- a/src/staking.rs +++ b/src/staking.rs @@ -10,7 +10,7 @@ use crate::state::{ DELEGATES, DENOM, OWNER, STAKE, TOTAL_COLDKEY_STAKE, TOTAL_HOTKEY_STAKE, TOTAL_ISSUANCE, TOTAL_STAKE, }; -use crate::utils::{exceeds_tx_rate_limit, get_last_tx_block, set_last_tx_block}; +use crate::utils::{exceeds_tx_rate_limit, get_default_take, get_last_tx_block, set_last_tx_block}; use crate::ContractError; use cyber_std::Response; @@ -47,8 +47,7 @@ pub fn do_become_delegate( hotkey_address: String, // take: u16, ) -> Result { - // TODO set get_default_take() of custom take - let take = 11_796; + let take = get_default_take(deps.storage); // --- 1. We check the coldkey signuture. let coldkey = info.sender; @@ -500,23 +499,20 @@ pub fn decrease_stake_on_coldkey_hotkey_account( Ok(()) } -#[cfg(test)] -pub fn add_balance_to_coldkey_account(_coldkey: &Addr, _amount: u64) {} - -#[cfg(test)] -pub fn can_remove_balance_from_coldkey_account(_coldkey: &Addr, _amount: u64) -> bool { - true -} +// #[cfg(test)] +// pub fn can_remove_balance_from_coldkey_account(_coldkey: &Addr, _amount: u64) -> bool { +// true +// } -#[cfg(test)] -pub fn get_coldkey_balance(_coldkey: &Addr) -> u64 { - return 0; -} +// #[cfg(test)] +// pub fn get_coldkey_balance(_coldkey: &Addr) -> u64 { +// return 0; +// } -#[cfg(test)] -pub fn remove_balance_from_coldkey_account(_coldkey: &Addr, _amount: u64) -> bool { - true -} +// #[cfg(test)] +// pub fn remove_balance_from_coldkey_account(_coldkey: &Addr, _amount: u64) -> bool { +// true +// } pub fn unstake_all_coldkeys_from_hotkey_account( store: &mut dyn Storage, diff --git a/src/state_info.rs b/src/state_info.rs index 04a3d07..4a4fcbb 100644 --- a/src/state_info.rs +++ b/src/state_info.rs @@ -10,16 +10,16 @@ use crate::state::{ LAST_TX_BLOCK, LAST_UPDATE, LOADED_EMISSION, MAX_ALLOWED_UIDS, MAX_ALLOWED_VALIDATORS, MAX_BURN, MAX_DIFFICULTY, MAX_REGISTRATION_PER_BLOCK, MAX_WEIGHTS_LIMIT, MIN_ALLOWED_WEIGHTS, MIN_BURN, MIN_DIFFICULTY, NETWORKS_ADDED, NETWORK_IMMUNITY_PERIOD, NETWORK_LAST_LOCK_COST, - NETWORK_LAST_REGISTERED, NETWORK_LOCK_REDUCTION_INTERVAL, NETWORK_MIN_ALLOWED_UIDS, - NETWORK_MIN_LOCK_COST, NETWORK_MODALITY, NETWORK_RATE_LIMIT, NETWORK_REGISTERED_AT, - NETWORK_REGISTRATION_ALLOWED, NEURONS_TO_PRUNE_AT_NEXT_EPOCH, OWNER, PENDING_EMISSION, - POW_REGISTRATIONS_THIS_INTERVAL, PROMETHEUS, PRUNING_SCORES, RANK, - RAO_RECYCLED_FOR_REGISTRATION, REGISTRATIONS_THIS_BLOCK, REGISTRATIONS_THIS_INTERVAL, RHO, - ROOT, SCALING_LAW_POWER, SERVING_RATE_LIMIT, STAKE, SUBNETWORK_N, SUBNET_LIMIT, SUBNET_LOCKED, - SUBNET_OWNER, SUBNET_OWNER_CUT, TARGET_REGISTRATIONS_PER_INTERVAL, TEMPO, TOTAL_COLDKEY_STAKE, - TOTAL_HOTKEY_STAKE, TOTAL_ISSUANCE, TOTAL_NETWORKS, TOTAL_STAKE, TRUST, TX_RATE_LIMIT, UIDS, - USED_WORK, VALIDATOR_PERMIT, VALIDATOR_PRUNE_LEN, VALIDATOR_TRUST, WEIGHTS, - WEIGHTS_SET_RATE_LIMIT, WEIGHTS_VERSION_KEY, + NETWORK_LAST_REGISTERED, NETWORK_LOCK_REDUCTION_INTERVAL, NETWORK_MIN_LOCK_COST, + NETWORK_MODALITY, NETWORK_RATE_LIMIT, NETWORK_REGISTERED_AT, NETWORK_REGISTRATION_ALLOWED, + NEURONS_TO_PRUNE_AT_NEXT_EPOCH, OWNER, PENDING_EMISSION, POW_REGISTRATIONS_THIS_INTERVAL, + PROMETHEUS, PRUNING_SCORES, RANK, RAO_RECYCLED_FOR_REGISTRATION, REGISTRATIONS_THIS_BLOCK, + REGISTRATIONS_THIS_INTERVAL, RHO, ROOT, SCALING_LAW_POWER, SERVING_RATE_LIMIT, STAKE, + SUBNETWORK_N, SUBNET_LIMIT, SUBNET_LOCKED, SUBNET_OWNER, SUBNET_OWNER_CUT, + TARGET_REGISTRATIONS_PER_INTERVAL, TEMPO, TOTAL_COLDKEY_STAKE, TOTAL_HOTKEY_STAKE, + TOTAL_ISSUANCE, TOTAL_NETWORKS, TOTAL_STAKE, TRUST, TX_RATE_LIMIT, UIDS, USED_WORK, + VALIDATOR_PERMIT, VALIDATOR_PRUNE_LEN, VALIDATOR_TRUST, WEIGHTS, WEIGHTS_SET_RATE_LIMIT, + WEIGHTS_VERSION_KEY, }; #[cw_serde] @@ -55,7 +55,6 @@ pub struct StateInfo { network_registered_at: Vec<(u16, u64)>, network_immunity_period: u64, network_last_registered: u64, - network_min_allowed_uids: u16, network_min_lock_cost: u64, network_last_lock_cost: u64, network_lock_reduction_interval: u64, @@ -212,7 +211,6 @@ pub fn get_state_info(store: &dyn Storage) -> StdResult { .unwrap(); let network_immunity_period: u64 = NETWORK_IMMUNITY_PERIOD.load(store)?; let network_last_registered: u64 = NETWORK_LAST_REGISTERED.load(store)?; - let network_min_allowed_uids: u16 = NETWORK_MIN_ALLOWED_UIDS.load(store)?; let network_min_lock_cost: u64 = NETWORK_MIN_LOCK_COST.load(store)?; let network_last_lock_cost: u64 = NETWORK_LAST_LOCK_COST.load(store)?; let network_lock_reduction_interval: u64 = NETWORK_LOCK_REDUCTION_INTERVAL.load(store)?; @@ -445,7 +443,6 @@ pub fn get_state_info(store: &dyn Storage) -> StdResult { network_registered_at, network_immunity_period, network_last_registered, - network_min_allowed_uids, network_min_lock_cost, network_last_lock_cost, network_lock_reduction_interval, diff --git a/src/test_helpers.rs b/src/test_helpers.rs index 7034b09..92baf4c 100644 --- a/src/test_helpers.rs +++ b/src/test_helpers.rs @@ -3,20 +3,20 @@ use std::fs::File; use std::io::Write; use cosmwasm_std::testing::{mock_env, mock_info, MockApi, MockQuerier}; -use cosmwasm_std::{Addr, Coin, DepsMut, Empty, Env, MemoryStorage, OwnedDeps, Storage}; -use cw_multi_test::{App, AppBuilder, BasicAppBuilder, Contract, ContractWrapper, Executor}; +use cosmwasm_std::{coin, Addr, Coin, DepsMut, Empty, Env, OwnedDeps, Storage}; +use cw_multi_test::{Contract, ContractWrapper, Executor}; use cw_storage_gas_meter::MemoryStorageWithGas; use cyber_std::CyberMsgWrapper; use cyber_std::Response; -use cyber_std_test::{CyberApp, CyberAppWrapped, CyberModule}; +use cyber_std_test::CyberApp; use crate::contract::{execute, instantiate, query}; use crate::msg::ExecuteMsg; use crate::registration::create_work_for_block_number; -use crate::root::init_new_network; +use crate::root::{get_network_lock_cost, init_new_network}; use crate::utils::{ - get_difficulty_as_u64, set_difficulty, set_network_registration_allowed, + get_burn_as_u64, get_difficulty_as_u64, set_difficulty, set_network_registration_allowed, set_weights_set_rate_limit, }; use crate::ContractError; @@ -214,7 +214,7 @@ pub fn sudo_register_ok_neuron(deps: DepsMut, env: Env, netuid: u16, hotkey: &st // TODO stake as funds let env = mock_env(); - let info = mock_info(&ROOT, &[]); + let info = mock_info(&ROOT, &[coin(1, "boot".to_string())]); let res = execute(deps, env, info, msg); assert_eq!(res.is_ok(), true); } @@ -247,7 +247,12 @@ pub fn burned_register_ok_neuron( hotkey: hotkey.to_string(), }; - let info = mock_info(coldkey, &[]); + let mut amount = get_burn_as_u64(deps.storage, netuid); + // need to send at least 1 boot + if amount == 0 { + amount = 1; + } + let info = mock_info(coldkey, &[coin(amount as u128, "boot".to_string())]); let result = execute(deps, env, info, msg); result @@ -266,16 +271,17 @@ pub fn add_stake( }; // TODO Add funds here - let info = mock_info(coldkey, &[]); + let info = mock_info(coldkey, &[coin(amount as u128, "boot".to_string())]); let result = execute(deps, env, info, msg); result } pub fn register_network(deps: DepsMut, env: Env, key: &str) -> Result { + let amount = get_network_lock_cost(deps.storage, deps.api, env.block.height).unwrap(); let msg = ExecuteMsg::RegisterNetwork {}; - let info = mock_info(key, &[]); + let info = mock_info(key, &[coin(amount as u128, "boot".to_string())]); let result = execute(deps, env, info, msg); result @@ -466,3 +472,6 @@ fn test_deps() { let after = get_difficulty_as_u64(&deps.storage, 1); assert_eq!(after, 1); } + +#[cfg(test)] +pub fn add_balance_to_coldkey_account(_coldkey: &Addr, _amount: u64) {} diff --git a/src/tests/block_step.rs b/src/tests/block_step.rs index 4f3fe15..4f9e8fd 100644 --- a/src/tests/block_step.rs +++ b/src/tests/block_step.rs @@ -16,14 +16,14 @@ use crate::math::{ }; use crate::registration::create_work_for_block_number; use crate::root::set_emission_values; -use crate::staking::{add_balance_to_coldkey_account, get_total_stake_for_hotkey}; +use crate::staking::get_total_stake_for_hotkey; use crate::state::{ ACTIVE, BONDS, CONSENSUS, DIVIDENDS, EMISSION, INCENTIVE, KEYS, PRUNING_SCORES, RANK, TRUST, VALIDATOR_PERMIT, VALIDATOR_TRUST, }; use crate::test_helpers::{ - add_network, burned_register_ok_neuron, instantiate_contract, pow_register_ok_neuron, - step_block, sudo_register_ok_neuron, + add_balance_to_coldkey_account, add_network, burned_register_ok_neuron, instantiate_contract, + pow_register_ok_neuron, step_block, sudo_register_ok_neuron, }; use crate::uids::get_subnetwork_n; use crate::utils::{ @@ -537,7 +537,7 @@ fn test_burn_adjustment() { let netuid: u16 = 2; let tempo: u16 = 13; - let burn_cost: u64 = 1000; + let burn_cost: u64 = 1000000000; let adjustment_interval = 1; let target_registrations_per_interval = 1; add_network(&mut deps.storage, netuid, tempo, 0); @@ -590,7 +590,7 @@ fn test_burn_adjustment() { step_block(deps.as_mut(), &mut env).unwrap(); // Check the adjusted burn. - assert_eq!(get_burn_as_u64(&deps.storage, netuid), 1500); + assert_eq!(get_burn_as_u64(&deps.storage, netuid), 1500000000); } #[test] @@ -599,7 +599,7 @@ fn test_burn_adjustment_with_moving_average() { let netuid: u16 = 2; let tempo: u16 = 13; - let burn_cost: u64 = 1000; + let burn_cost: u64 = 1000000000; let adjustment_interval = 1; let target_registrations_per_interval = 1; add_network(&mut deps.storage, netuid, tempo, 0); @@ -651,7 +651,8 @@ fn test_burn_adjustment_with_moving_average() { // Check the adjusted burn. // 0.5 * 1000 + 0.5 * 1500 = 1250 - assert_eq!(get_burn_as_u64(&deps.storage, netuid), 1250); + // assert_eq!(get_burn_as_u64(&deps.storage, netuid), 1250000000); + assert_eq!(get_burn_as_u64(&deps.storage, netuid), 1250001907); } #[test] @@ -665,7 +666,7 @@ fn test_burn_adjustment_case_a() { let netuid: u16 = 2; let tempo: u16 = 13; - let burn_cost: u64 = 1000; + let burn_cost: u64 = 1000000000; let adjustment_interval = 1; let target_registrations_per_interval = 1; let start_diff: u64 = 10_000; @@ -766,7 +767,7 @@ fn test_burn_adjustment_case_b() { let netuid: u16 = 2; let tempo: u16 = 13; - let burn_cost: u64 = 1000; + let burn_cost: u64 = 1000000000; let adjustment_interval = 1; let target_registrations_per_interval = 1; let start_diff: u64 = 20_000; @@ -845,7 +846,7 @@ fn test_burn_adjustment_case_b() { // and the difficulty has not changed. let adjusted_burn = get_burn_as_u64(&deps.storage, netuid); assert!(adjusted_burn > burn_cost); - assert_eq!(adjusted_burn, 2_000); + assert_eq!(adjusted_burn, 2000000000); let adjusted_diff = get_difficulty_as_u64(&deps.storage, netuid); assert_eq!(adjusted_diff, start_diff); @@ -862,7 +863,7 @@ fn test_burn_adjustment_case_c() { let netuid: u16 = 2; let tempo: u16 = 13; - let burn_cost: u64 = 1000; + let burn_cost: u64 = 1000000000; let adjustment_interval = 1; let target_registrations_per_interval = 4; // Needs registrations < 4 to trigger let start_diff: u64 = 20_000; @@ -946,7 +947,7 @@ fn test_burn_adjustment_case_c() { // and the difficulty has not changed. let adjusted_burn = get_burn_as_u64(&deps.storage, netuid); assert!(adjusted_burn < burn_cost); - assert_eq!(adjusted_burn, 875); + assert_eq!(adjusted_burn, 875000000); let adjusted_diff = get_difficulty_as_u64(&deps.storage, netuid); assert_eq!(adjusted_diff, start_diff); @@ -1059,7 +1060,7 @@ fn test_burn_adjustment_case_e() { let netuid: u16 = 2; let tempo: u16 = 13; - let burn_cost: u64 = 1000; + let burn_cost: u64 = 1000000000; let adjustment_interval = 1; let target_registrations_per_interval: u16 = 3; let start_diff: u64 = 20_000; @@ -1121,7 +1122,7 @@ fn test_burn_adjustment_case_e() { // Check the adjusted BURN has DECREASED. let adjusted_burn = get_burn_as_u64(&deps.storage, netuid); assert!(adjusted_burn < burn_cost); - assert_eq!(adjusted_burn, 833); + assert_eq!(adjusted_burn, 833333333); // Check the adjusted POW difficulty has DECREASED. let adjusted_diff = get_difficulty_as_u64(&deps.storage, netuid); @@ -1140,7 +1141,7 @@ fn test_burn_adjustment_case_f() { let netuid: u16 = 2; let tempo: u16 = 13; - let burn_cost: u64 = 1000; + let burn_cost: u64 = 1000000000; let adjustment_interval = 1; let target_registrations_per_interval: u16 = 1; let start_diff: u64 = 20_000; @@ -1202,7 +1203,7 @@ fn test_burn_adjustment_case_f() { // Check the adjusted BURN has INCREASED. let adjusted_burn = get_burn_as_u64(&deps.storage, netuid); assert!(adjusted_burn > burn_cost); - assert_eq!(adjusted_burn, 1_500); + assert_eq!(adjusted_burn, 1_500_000_000); // Check the adjusted POW difficulty has INCREASED. let adjusted_diff = get_difficulty_as_u64(&deps.storage, netuid); @@ -1223,7 +1224,7 @@ fn test_burn_adjustment_case_e_zero_registrations() { let netuid: u16 = 2; let tempo: u16 = 13; - let burn_cost: u64 = 1000; + let burn_cost: u64 = 1000000000; let adjustment_interval = 0; let target_registrations_per_interval: u16 = 1; let start_diff: u64 = 20_000; @@ -1249,7 +1250,7 @@ fn test_burn_adjustment_case_e_zero_registrations() { // Check the adjusted BURN has DECREASED. let adjusted_burn = get_burn_as_u64(&deps.storage, netuid); assert!(adjusted_burn < burn_cost); - assert_eq!(adjusted_burn, 500); + assert_eq!(adjusted_burn, 500000000); // Check the adjusted POW difficulty has DECREASED. let adjusted_diff = get_difficulty_as_u64(&deps.storage, netuid); diff --git a/src/tests/epoch.rs b/src/tests/epoch.rs index 034d0c2..32f0217 100644 --- a/src/tests/epoch.rs +++ b/src/tests/epoch.rs @@ -4,12 +4,11 @@ use crate::msg::ExecuteMsg; use crate::registration::create_work_for_block_number; use crate::root::{get_subnet_emission_value, set_emission_values}; use crate::staking::{ - add_balance_to_coldkey_account, get_total_stake, get_total_stake_for_hotkey, - increase_stake_on_coldkey_hotkey_account, + get_total_stake, get_total_stake_for_hotkey, increase_stake_on_coldkey_hotkey_account, }; use crate::test_helpers::{ - add_network, instantiate_contract, pow_register_ok_neuron, run_step_to_block, set_weights, - step_block, TestDeps, ROOT, + add_balance_to_coldkey_account, add_network, instantiate_contract, pow_register_ok_neuron, + run_step_to_block, set_weights, step_block, }; use crate::tests::block_step::epoch_dense; use crate::uids::{append_neuron, get_hotkey_for_net_and_uid, get_subnetwork_n}; @@ -22,7 +21,7 @@ use crate::utils::{ set_target_registrations_per_interval, set_weights_set_rate_limit, }; use cosmwasm_std::testing::mock_info; -use cosmwasm_std::{Addr, Api, Deps, DepsMut, Env, Storage}; +use cosmwasm_std::{Addr, Api, DepsMut, Env, Storage}; use rand::{distributions::Uniform, rngs::StdRng, seq::SliceRandom, thread_rng, Rng, SeedableRng}; use std::time::Instant; use substrate_fixed::transcendental::{cos, ln, sqrt, PI}; diff --git a/src/tests/graph.rs b/src/tests/graph.rs index b530642..1c5043f 100644 --- a/src/tests/graph.rs +++ b/src/tests/graph.rs @@ -1,6 +1,10 @@ +use crate::math::{ + col_clip_sparse, inplace_col_normalize_sparse, inplace_normalize, inplace_normalize_using_sum, + mat_ema_sparse, matmul_sparse, matmul_transpose_sparse, row_hadamard_sparse, row_sum_sparse, + vecdiv, weighted_median_col_sparse, +}; use std::collections::HashMap; use substrate_fixed::types::{I32F32, I64F64, I96F32}; -use crate::math::{col_clip_sparse, inplace_col_normalize_sparse, inplace_normalize, inplace_normalize_using_sum, mat_ema_sparse, matmul_sparse, matmul_transpose_sparse, row_hadamard_sparse, row_sum_sparse, vecdiv, weighted_median_col_sparse}; pub fn find_intersection(arr1: &[i32], arr2: &[i32]) -> Vec { let mut intersection = Vec::new(); @@ -35,6 +39,7 @@ struct UserOutLink { #[test] pub fn test() { + #[rustfmt::skip] let user_out_links = vec![ UserOutLink { user_id: 1, out_link: 1 }, UserOutLink { user_id: 1, out_link: 2 }, @@ -54,7 +59,10 @@ pub fn test() { // Create a user-outlink matrix let mut user_out_link_matrix: HashMap> = HashMap::new(); for uol in user_out_links { - user_out_link_matrix.entry(uol.user_id).or_insert_with(Vec::new).push(uol.out_link as i32); + user_out_link_matrix + .entry(uol.user_id) + .or_insert_with(Vec::new) + .push(uol.out_link as i32); } let mut sparseWeightsMatrix: Vec> = vec![vec![]; 4]; @@ -64,9 +72,12 @@ pub fn test() { for (&user_id2, out_links2) in &user_out_link_matrix { if user_id1 != user_id2 { let cosim = cosine_similarity(out_links1, out_links2); - sparseWeightsMatrix[user_id1 as usize].push( (user_id2, I32F32::from_num(cosim))); + sparseWeightsMatrix[user_id1 as usize].push((user_id2, I32F32::from_num(cosim))); - println!("Cosine similarity between user {} and user {}: {:.2}", user_id1, user_id2, cosim); + println!( + "Cosine similarity between user {} and user {}: {:.2}", + user_id1, user_id2, cosim + ); } } } @@ -148,8 +159,7 @@ pub fn test() { println!("ฮ”Bonds (norm): {:?}", &bonds_delta); // Compute bonds moving average. - let bonds_moving_average: I64F64 = - I64F64::from_num(900_000) / I64F64::from_num(1_000_000); + let bonds_moving_average: I64F64 = I64F64::from_num(900_000) / I64F64::from_num(1_000_000); let alpha: I32F32 = I32F32::from_num(1) - I32F32::from_num(bonds_moving_average); let mut ema_bonds: Vec> = mat_ema_sparse(&bonds_delta, &bonds, alpha); @@ -228,4 +238,4 @@ pub fn test() { // Set pruning scores using combined emission scores. let pruning_scores: Vec = normalized_combined_emission.clone(); println!("Psc: {:?}", &pruning_scores); -} \ No newline at end of file +} diff --git a/src/tests/mod.rs b/src/tests/mod.rs index c1aa225..913a971 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -1,10 +1,10 @@ mod block_step; mod difficulty; mod epoch; +mod graph; mod neuron_info; mod registration; mod root; mod serving; mod uids; mod weights; -mod graph; diff --git a/src/tests/registration.rs b/src/tests/registration.rs index 4e265bb..88073d0 100644 --- a/src/tests/registration.rs +++ b/src/tests/registration.rs @@ -5,11 +5,11 @@ use crate::contract::execute; use crate::msg::ExecuteMsg; use crate::registration::{create_work_for_block_number, get_neuron_to_prune}; use crate::serving::get_axon_info; -use crate::staking::{add_balance_to_coldkey_account, get_owning_coldkey_for_hotkey}; +use crate::staking::get_owning_coldkey_for_hotkey; use crate::state::AxonInfoOf; use crate::test_helpers::{ - add_network, burned_register_ok_neuron, instantiate_contract, pow_register_ok_neuron, - register_ok_neuron, run_step_to_block, step_block, + add_balance_to_coldkey_account, add_network, burned_register_ok_neuron, instantiate_contract, + pow_register_ok_neuron, register_ok_neuron, run_step_to_block, step_block, }; use crate::uids::{ get_hotkey_for_net_and_uid, get_stake_for_uid_and_subnetwork, get_subnetwork_n, @@ -172,16 +172,17 @@ fn test_burned_registration_ok() { // Give it some $$$ in his coldkey balance add_balance_to_coldkey_account(&Addr::unchecked(coldkey_account_id), 10000); - let result = execute( - deps.as_mut(), - env.clone(), - mock_info(coldkey_account_id, &[]), - ExecuteMsg::BurnedRegister { + assert_eq!( + burned_register_ok_neuron( + deps.as_mut(), + env.clone(), netuid, - hotkey: hotkey_account_id.to_string(), - }, + hotkey_account_id, + coldkey_account_id, + ) + .is_ok(), + true ); - assert!(result.is_ok()); // Check if balance has decreased to pay for the burn. // assert_eq!( @@ -221,7 +222,7 @@ fn test_burn_adjustment() { let netuid: u16 = 2; let tempo: u16 = 13; - let burn_cost: u64 = 1000; + let burn_cost: u64 = 1000000000; let adjustment_interval = 1; let target_registrations_per_interval = 1; add_network(&mut deps.storage, netuid, tempo, 0); @@ -270,7 +271,7 @@ fn test_burn_adjustment() { step_block(deps.as_mut(), &mut env).unwrap(); // Check the adjusted burn. - assert_eq!(get_burn_as_u64(&deps.storage, netuid), 1500) + assert_eq!(get_burn_as_u64(&deps.storage, netuid), 1500000000) } #[test] diff --git a/src/tests/root.rs b/src/tests/root.rs index c088f63..8487acc 100644 --- a/src/tests/root.rs +++ b/src/tests/root.rs @@ -5,13 +5,14 @@ use crate::registration::create_work_for_block_number; use crate::root::{ get_all_subnet_netuids, get_max_subnets, get_network_lock_cost, get_num_subnets, get_subnet_emission_value, if_subnet_exist, remove_network, root_epoch, - set_lock_reduction_interval, set_network_last_lock, + set_lock_reduction_interval, }; -use crate::staking::{add_balance_to_coldkey_account, hotkey_is_delegate}; +use crate::staking::hotkey_is_delegate; use crate::state_info::get_state_info; use crate::test_helpers::{ - add_network, add_stake, burned_register_ok_neuron, instantiate_contract, - pow_register_ok_neuron, register_network, root_register, set_weights, step_block, + add_balance_to_coldkey_account, add_network, add_stake, burned_register_ok_neuron, + instantiate_contract, pow_register_ok_neuron, register_network, root_register, set_weights, + step_block, }; use crate::uids::{get_subnetwork_n, get_uid_for_net_and_hotkey, is_hotkey_registered_on_network}; use crate::utils::{ diff --git a/src/utils.rs b/src/utils.rs index 54bff7b..24dea72 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -449,7 +449,6 @@ pub fn get_subnet_locked_balance(store: &mut dyn Storage, netuid: u16) -> u64 { SUBNET_LOCKED.load(store, netuid).unwrap() } -#[cfg(test)] pub fn get_default_take(store: &dyn Storage) -> u16 { DEFAULT_TAKE.load(store).unwrap() } @@ -1021,8 +1020,10 @@ pub fn do_sudo_set_rho( RHO.save(deps.storage, netuid, &rho)?; - deps.api - .debug(&format!("๐Ÿ›ธ RhoSet ( netuid: {:?} rho: {:?} ) ", netuid, rho)); + deps.api.debug(&format!( + "๐Ÿ›ธ RhoSet ( netuid: {:?} rho: {:?} ) ", + netuid, rho + )); Ok(Response::default() .add_attribute("active", "rho_set") @@ -1553,8 +1554,10 @@ pub fn do_sudo_set_subnet_limit( SUBNET_LIMIT.save(deps.storage, &max_subnets)?; - deps.api - .debug(&format!("๐Ÿ›ธ SubnetLimit ( max_subnets: {:?} ) ", max_subnets)); + deps.api.debug(&format!( + "๐Ÿ›ธ SubnetLimit ( max_subnets: {:?} ) ", + max_subnets + )); Ok(Response::default() .add_attribute("action", "subnet_limit_set") diff --git a/src/weights.rs b/src/weights.rs index 34756e2..66296f4 100644 --- a/src/weights.rs +++ b/src/weights.rs @@ -87,10 +87,7 @@ pub fn do_set_weights( let hotkey = info.sender; deps.api.debug(&format!( "๐Ÿ’ก do_set_weights ( origin:{:?} netuid:{:?}, uids:{:?}, values:{:?})", - hotkey, - netuid, - uids, - values + hotkey, netuid, uids, values )); // --- 2. Check that the length of uid list and value list are equal for this network.