Skip to content

Commit 30513af

Browse files
committed
Fixed tests
1 parent facc38f commit 30513af

15 files changed

+138
-121
lines changed

src/contract.rs

+15-14
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use cosmwasm_std::{
55
Uint128,
66
};
77
use cw2::{get_contract_version, set_contract_version, ContractVersion};
8+
use cyber_std::Response;
89
use cyber_std::{create_creat_thought_msg, Load, Trigger};
910

1011
use crate::block_step::block_step;
@@ -25,9 +26,9 @@ use crate::state::{
2526
LAST_UPDATE, MAX_ALLOWED_UIDS, MAX_ALLOWED_VALIDATORS, MAX_BURN, MAX_DIFFICULTY,
2627
MAX_REGISTRATION_PER_BLOCK, MAX_WEIGHTS_LIMIT, MIN_ALLOWED_WEIGHTS, MIN_BURN, MIN_DIFFICULTY,
2728
NETWORKS_ADDED, NETWORK_IMMUNITY_PERIOD, NETWORK_LAST_LOCK_COST, NETWORK_LAST_REGISTERED,
28-
NETWORK_LOCK_REDUCTION_INTERVAL, NETWORK_MIN_ALLOWED_UIDS, NETWORK_MIN_LOCK_COST,
29-
NETWORK_MODALITY, NETWORK_RATE_LIMIT, NETWORK_REGISTERED_AT, NETWORK_REGISTRATION_ALLOWED,
30-
OWNER, PENDING_EMISSION, POW_REGISTRATIONS_THIS_INTERVAL, PROMETHEUS, PRUNING_SCORES, RANK,
29+
NETWORK_LOCK_REDUCTION_INTERVAL, NETWORK_MIN_LOCK_COST, NETWORK_MODALITY, NETWORK_RATE_LIMIT,
30+
NETWORK_REGISTERED_AT, NETWORK_REGISTRATION_ALLOWED, OWNER, PENDING_EMISSION,
31+
POW_REGISTRATIONS_THIS_INTERVAL, PROMETHEUS, PRUNING_SCORES, RANK,
3132
RAO_RECYCLED_FOR_REGISTRATION, REGISTRATIONS_THIS_BLOCK, REGISTRATIONS_THIS_INTERVAL, RHO,
3233
ROOT, SCALING_LAW_POWER, SERVING_RATE_LIMIT, STAKE, SUBNETWORK_N, SUBNET_LIMIT, SUBNET_LOCKED,
3334
SUBNET_OWNER, SUBNET_OWNER_CUT, TARGET_REGISTRATIONS_PER_INTERVAL, TEMPO, TOTAL_COLDKEY_STAKE,
@@ -36,6 +37,7 @@ use crate::state::{
3637
};
3738
use crate::state_info::get_state_info;
3839
use crate::subnet_info::{get_subnet_hyperparams, get_subnet_info, get_subnets_info};
40+
use crate::uids::get_registered_networks_for_hotkey;
3941
use crate::utils::{
4042
do_sudo_set_activity_cutoff, do_sudo_set_adjustment_alpha, do_sudo_set_adjustment_interval,
4143
do_sudo_set_block_emission, do_sudo_set_bonds_moving_average, do_sudo_set_default_take,
@@ -55,15 +57,9 @@ use crate::utils::{
5557
};
5658
use crate::weights::{do_set_weights, get_network_weights, get_network_weights_sparse};
5759

58-
// use cw2::set_contract_version;
59-
60-
// version info for migration info
6160
const CONTRACT_NAME: &str = "cybernet";
6261
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
6362

64-
use crate::uids::get_registered_networks_for_hotkey;
65-
use cyber_std::Response;
66-
6763
#[cfg_attr(not(feature = "library"), entry_point)]
6864
pub fn instantiate(
6965
deps: DepsMut,
@@ -75,7 +71,12 @@ pub fn instantiate(
7571

7672
ROOT.save(deps.storage, &info.sender)?;
7773
ALLOW_FAUCET.save(deps.storage, &false)?;
78-
DENOM.save(deps.storage, &"boot".to_string())?;
74+
75+
if info.funds.len() > 0 {
76+
DENOM.save(deps.storage, &info.funds[0].denom)?;
77+
} else {
78+
DENOM.save(deps.storage, &"boot".to_string())?;
79+
}
7980

8081
// TODO remove from InstantiateMsg
8182
// // Set initial total issuance from balances
@@ -88,16 +89,16 @@ pub fn instantiate(
8889
NETWORK_IMMUNITY_PERIOD.save(deps.storage, &7200)?;
8990
BLOCK_EMISSION.save(deps.storage, &1_000_000_000)?;
9091

91-
NETWORK_MIN_ALLOWED_UIDS.save(deps.storage, &0)?;
9292
SUBNET_OWNER_CUT.save(deps.storage, &0)?;
9393
NETWORK_RATE_LIMIT.save(deps.storage, &0)?;
9494

95-
DEFAULT_TAKE.save(deps.storage, &11_796)?;
96-
TX_RATE_LIMIT.save(deps.storage, &1000)?;
95+
// 6.25% (2^12/2^16)
96+
DEFAULT_TAKE.save(deps.storage, &4096)?;
97+
TX_RATE_LIMIT.save(deps.storage, &0)?;
9798

9899
NETWORK_LAST_LOCK_COST.save(deps.storage, &100_000_000_000)?;
99100
NETWORK_MIN_LOCK_COST.save(deps.storage, &100_000_000_000)?;
100-
NETWORK_LOCK_REDUCTION_INTERVAL.save(deps.storage, &2)?; // test value, change to 14 * 7200;
101+
NETWORK_LOCK_REDUCTION_INTERVAL.save(deps.storage, &(7 * 7200))?; // test value, change to 14 * 7200;
101102

102103
// -- Root network initialization --
103104

src/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub enum ContractError {
7979
#[error("Thrown if the vaule is invalid for MaxAllowedUids.")]
8080
MaxAllowedUIdsNotAllowed {},
8181

82-
#[error("Thrown when the dispatch attempts to convert between a u64 and T::balance but the call fails.")]
82+
#[error("Thrown when wrong denom passed to the contract as payment")]
8383
CouldNotConvertToBalance {},
8484

8585
#[error("Thrown when the caller requests adding stake for a hotkey to the total stake which already added.")]

src/root.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ use crate::state::{
2828
use crate::uids::{append_neuron, get_hotkey_for_net_and_uid, get_subnetwork_n, replace_neuron};
2929
use crate::utils::{
3030
get_block_emission, get_emission_value, get_max_allowed_uids, get_max_registrations_per_block,
31-
get_registrations_this_block, get_registrations_this_interval, get_rho,
32-
get_subnet_owner, get_target_registrations_per_interval, get_tempo,
33-
set_subnet_locked_balance,
31+
get_registrations_this_block, get_registrations_this_interval, get_rho, get_subnet_owner,
32+
get_target_registrations_per_interval, get_tempo, set_subnet_locked_balance,
3433
};
3534
use crate::ContractError;
3635

@@ -785,7 +784,6 @@ pub fn init_new_network(
785784
TARGET_REGISTRATIONS_PER_INTERVAL.save(store, netuid, &1)?;
786785
ADJUSTMENTS_ALPHA.save(store, netuid, &58000)?;
787786
IMMUNITY_PERIOD.save(store, netuid, &7200)?;
788-
MIN_BURN.save(store, netuid, &1)?;
789787

790788
DIFFICULTY.save(store, netuid, &10_000_000)?;
791789
MIN_DIFFICULTY.save(store, netuid, &10_000_000)?;
@@ -810,9 +808,11 @@ pub fn init_new_network(
810808
BONDS_MOVING_AVERAGE.save(store, netuid, &900_000)?;
811809
LAST_ADJUSTMENT_BLOCK.save(store, netuid, &0)?;
812810
ADJUSTMENT_INTERVAL.save(store, netuid, &100)?;
813-
BURN.save(store, netuid, &0)?;
814-
// MIN_BURN.save(store, netuid,&0)?;
815-
MAX_BURN.save(store, netuid, &1_000_000_000)?;
811+
812+
BURN.save(store, netuid, &1_000_000_000)?;
813+
MIN_BURN.save(store, netuid, &100_000_000)?;
814+
MAX_BURN.save(store, netuid, &100_000_000_000)?;
815+
816816
REGISTRATIONS_THIS_BLOCK.save(store, netuid, &0)?;
817817
// MAX_REGISTRATION_PER_BLOCK.save(store, netuid, &3)?;
818818
KAPPA.save(store, netuid, &32_767)?;

src/serving.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,10 @@ pub fn do_serve_axon(
114114
AXONS.save(deps.storage, (netuid, &hotkey_id), &prev_axon)?;
115115

116116
// --- 8. We deposit axon served event.
117-
deps.api
118-
.debug(&format!("📡 AxonServed ( hotkey:{:?} ) ", hotkey_id.clone()));
117+
deps.api.debug(&format!(
118+
"📡 AxonServed ( hotkey:{:?} ) ",
119+
hotkey_id.clone()
120+
));
119121

120122
// --- 9. Return is successful dispatch.
121123
Ok(Response::default()

src/staking.rs

+14-18
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::state::{
1010
DELEGATES, DENOM, OWNER, STAKE, TOTAL_COLDKEY_STAKE, TOTAL_HOTKEY_STAKE, TOTAL_ISSUANCE,
1111
TOTAL_STAKE,
1212
};
13-
use crate::utils::{exceeds_tx_rate_limit, get_last_tx_block, set_last_tx_block};
13+
use crate::utils::{exceeds_tx_rate_limit, get_default_take, get_last_tx_block, set_last_tx_block};
1414
use crate::ContractError;
1515
use cyber_std::Response;
1616

@@ -47,8 +47,7 @@ pub fn do_become_delegate(
4747
hotkey_address: String,
4848
// take: u16,
4949
) -> Result<Response, ContractError> {
50-
// TODO set get_default_take() of custom take
51-
let take = 11_796;
50+
let take = get_default_take(deps.storage);
5251

5352
// --- 1. We check the coldkey signuture.
5453
let coldkey = info.sender;
@@ -500,23 +499,20 @@ pub fn decrease_stake_on_coldkey_hotkey_account(
500499
Ok(())
501500
}
502501

503-
#[cfg(test)]
504-
pub fn add_balance_to_coldkey_account(_coldkey: &Addr, _amount: u64) {}
505-
506-
#[cfg(test)]
507-
pub fn can_remove_balance_from_coldkey_account(_coldkey: &Addr, _amount: u64) -> bool {
508-
true
509-
}
502+
// #[cfg(test)]
503+
// pub fn can_remove_balance_from_coldkey_account(_coldkey: &Addr, _amount: u64) -> bool {
504+
// true
505+
// }
510506

511-
#[cfg(test)]
512-
pub fn get_coldkey_balance(_coldkey: &Addr) -> u64 {
513-
return 0;
514-
}
507+
// #[cfg(test)]
508+
// pub fn get_coldkey_balance(_coldkey: &Addr) -> u64 {
509+
// return 0;
510+
// }
515511

516-
#[cfg(test)]
517-
pub fn remove_balance_from_coldkey_account(_coldkey: &Addr, _amount: u64) -> bool {
518-
true
519-
}
512+
// #[cfg(test)]
513+
// pub fn remove_balance_from_coldkey_account(_coldkey: &Addr, _amount: u64) -> bool {
514+
// true
515+
// }
520516

521517
pub fn unstake_all_coldkeys_from_hotkey_account(
522518
store: &mut dyn Storage,

src/state_info.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ use crate::state::{
1010
LAST_TX_BLOCK, LAST_UPDATE, LOADED_EMISSION, MAX_ALLOWED_UIDS, MAX_ALLOWED_VALIDATORS,
1111
MAX_BURN, MAX_DIFFICULTY, MAX_REGISTRATION_PER_BLOCK, MAX_WEIGHTS_LIMIT, MIN_ALLOWED_WEIGHTS,
1212
MIN_BURN, MIN_DIFFICULTY, NETWORKS_ADDED, NETWORK_IMMUNITY_PERIOD, NETWORK_LAST_LOCK_COST,
13-
NETWORK_LAST_REGISTERED, NETWORK_LOCK_REDUCTION_INTERVAL, NETWORK_MIN_ALLOWED_UIDS,
14-
NETWORK_MIN_LOCK_COST, NETWORK_MODALITY, NETWORK_RATE_LIMIT, NETWORK_REGISTERED_AT,
15-
NETWORK_REGISTRATION_ALLOWED, NEURONS_TO_PRUNE_AT_NEXT_EPOCH, OWNER, PENDING_EMISSION,
16-
POW_REGISTRATIONS_THIS_INTERVAL, PROMETHEUS, PRUNING_SCORES, RANK,
17-
RAO_RECYCLED_FOR_REGISTRATION, REGISTRATIONS_THIS_BLOCK, REGISTRATIONS_THIS_INTERVAL, RHO,
18-
ROOT, SCALING_LAW_POWER, SERVING_RATE_LIMIT, STAKE, SUBNETWORK_N, SUBNET_LIMIT, SUBNET_LOCKED,
19-
SUBNET_OWNER, SUBNET_OWNER_CUT, TARGET_REGISTRATIONS_PER_INTERVAL, TEMPO, TOTAL_COLDKEY_STAKE,
20-
TOTAL_HOTKEY_STAKE, TOTAL_ISSUANCE, TOTAL_NETWORKS, TOTAL_STAKE, TRUST, TX_RATE_LIMIT, UIDS,
21-
USED_WORK, VALIDATOR_PERMIT, VALIDATOR_PRUNE_LEN, VALIDATOR_TRUST, WEIGHTS,
22-
WEIGHTS_SET_RATE_LIMIT, WEIGHTS_VERSION_KEY,
13+
NETWORK_LAST_REGISTERED, NETWORK_LOCK_REDUCTION_INTERVAL, NETWORK_MIN_LOCK_COST,
14+
NETWORK_MODALITY, NETWORK_RATE_LIMIT, NETWORK_REGISTERED_AT, NETWORK_REGISTRATION_ALLOWED,
15+
NEURONS_TO_PRUNE_AT_NEXT_EPOCH, OWNER, PENDING_EMISSION, POW_REGISTRATIONS_THIS_INTERVAL,
16+
PROMETHEUS, PRUNING_SCORES, RANK, RAO_RECYCLED_FOR_REGISTRATION, REGISTRATIONS_THIS_BLOCK,
17+
REGISTRATIONS_THIS_INTERVAL, RHO, ROOT, SCALING_LAW_POWER, SERVING_RATE_LIMIT, STAKE,
18+
SUBNETWORK_N, SUBNET_LIMIT, SUBNET_LOCKED, SUBNET_OWNER, SUBNET_OWNER_CUT,
19+
TARGET_REGISTRATIONS_PER_INTERVAL, TEMPO, TOTAL_COLDKEY_STAKE, TOTAL_HOTKEY_STAKE,
20+
TOTAL_ISSUANCE, TOTAL_NETWORKS, TOTAL_STAKE, TRUST, TX_RATE_LIMIT, UIDS, USED_WORK,
21+
VALIDATOR_PERMIT, VALIDATOR_PRUNE_LEN, VALIDATOR_TRUST, WEIGHTS, WEIGHTS_SET_RATE_LIMIT,
22+
WEIGHTS_VERSION_KEY,
2323
};
2424

2525
#[cw_serde]
@@ -55,7 +55,6 @@ pub struct StateInfo {
5555
network_registered_at: Vec<(u16, u64)>,
5656
network_immunity_period: u64,
5757
network_last_registered: u64,
58-
network_min_allowed_uids: u16,
5958
network_min_lock_cost: u64,
6059
network_last_lock_cost: u64,
6160
network_lock_reduction_interval: u64,
@@ -212,7 +211,6 @@ pub fn get_state_info(store: &dyn Storage) -> StdResult<StateInfo> {
212211
.unwrap();
213212
let network_immunity_period: u64 = NETWORK_IMMUNITY_PERIOD.load(store)?;
214213
let network_last_registered: u64 = NETWORK_LAST_REGISTERED.load(store)?;
215-
let network_min_allowed_uids: u16 = NETWORK_MIN_ALLOWED_UIDS.load(store)?;
216214
let network_min_lock_cost: u64 = NETWORK_MIN_LOCK_COST.load(store)?;
217215
let network_last_lock_cost: u64 = NETWORK_LAST_LOCK_COST.load(store)?;
218216
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<StateInfo> {
445443
network_registered_at,
446444
network_immunity_period,
447445
network_last_registered,
448-
network_min_allowed_uids,
449446
network_min_lock_cost,
450447
network_last_lock_cost,
451448
network_lock_reduction_interval,

src/test_helpers.rs

+18-9
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ use std::fs::File;
33
use std::io::Write;
44

55
use cosmwasm_std::testing::{mock_env, mock_info, MockApi, MockQuerier};
6-
use cosmwasm_std::{Addr, Coin, DepsMut, Empty, Env, MemoryStorage, OwnedDeps, Storage};
7-
use cw_multi_test::{App, AppBuilder, BasicAppBuilder, Contract, ContractWrapper, Executor};
6+
use cosmwasm_std::{coin, Addr, Coin, DepsMut, Empty, Env, OwnedDeps, Storage};
7+
use cw_multi_test::{Contract, ContractWrapper, Executor};
88
use cw_storage_gas_meter::MemoryStorageWithGas;
99
use cyber_std::CyberMsgWrapper;
1010
use cyber_std::Response;
1111

12-
use cyber_std_test::{CyberApp, CyberAppWrapped, CyberModule};
12+
use cyber_std_test::CyberApp;
1313

1414
use crate::contract::{execute, instantiate, query};
1515
use crate::msg::ExecuteMsg;
1616
use crate::registration::create_work_for_block_number;
17-
use crate::root::init_new_network;
17+
use crate::root::{get_network_lock_cost, init_new_network};
1818
use crate::utils::{
19-
get_difficulty_as_u64, set_difficulty, set_network_registration_allowed,
19+
get_burn_as_u64, get_difficulty_as_u64, set_difficulty, set_network_registration_allowed,
2020
set_weights_set_rate_limit,
2121
};
2222
use crate::ContractError;
@@ -214,7 +214,7 @@ pub fn sudo_register_ok_neuron(deps: DepsMut, env: Env, netuid: u16, hotkey: &st
214214

215215
// TODO stake as funds
216216
let env = mock_env();
217-
let info = mock_info(&ROOT, &[]);
217+
let info = mock_info(&ROOT, &[coin(1, "boot".to_string())]);
218218
let res = execute(deps, env, info, msg);
219219
assert_eq!(res.is_ok(), true);
220220
}
@@ -247,7 +247,12 @@ pub fn burned_register_ok_neuron(
247247
hotkey: hotkey.to_string(),
248248
};
249249

250-
let info = mock_info(coldkey, &[]);
250+
let mut amount = get_burn_as_u64(deps.storage, netuid);
251+
// need to send at least 1 boot
252+
if amount == 0 {
253+
amount = 1;
254+
}
255+
let info = mock_info(coldkey, &[coin(amount as u128, "boot".to_string())]);
251256
let result = execute(deps, env, info, msg);
252257

253258
result
@@ -266,16 +271,17 @@ pub fn add_stake(
266271
};
267272

268273
// TODO Add funds here
269-
let info = mock_info(coldkey, &[]);
274+
let info = mock_info(coldkey, &[coin(amount as u128, "boot".to_string())]);
270275
let result = execute(deps, env, info, msg);
271276

272277
result
273278
}
274279

275280
pub fn register_network(deps: DepsMut, env: Env, key: &str) -> Result<Response, ContractError> {
281+
let amount = get_network_lock_cost(deps.storage, deps.api, env.block.height).unwrap();
276282
let msg = ExecuteMsg::RegisterNetwork {};
277283

278-
let info = mock_info(key, &[]);
284+
let info = mock_info(key, &[coin(amount as u128, "boot".to_string())]);
279285
let result = execute(deps, env, info, msg);
280286

281287
result
@@ -466,3 +472,6 @@ fn test_deps() {
466472
let after = get_difficulty_as_u64(&deps.storage, 1);
467473
assert_eq!(after, 1);
468474
}
475+
476+
#[cfg(test)]
477+
pub fn add_balance_to_coldkey_account(_coldkey: &Addr, _amount: u64) {}

0 commit comments

Comments
 (0)