adapt trait; add extra test; fix benchmarking
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
This commit is contained in:
parent
f524b01b03
commit
03262539aa
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "ghost-networks"
|
||||
version = "0.1.22"
|
||||
version = "0.1.23"
|
||||
license.workspace = true
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
|
||||
@ -85,13 +85,15 @@ benchmarks! {
|
||||
let (chain_id, network) = prepare_network::<T>(i, j, k);
|
||||
let authority = T::RegisterOrigin::try_successful_origin()
|
||||
.map_err(|_| BenchmarkError::Weightless)?;
|
||||
let prev_network = GhostNetworks::<T>::networks(chain_id.clone());
|
||||
assert_eq!(GhostNetworks::<T>::networks(chain_id.clone()), None);
|
||||
assert!(GhostNetworks::<T>::network_indexes().is_empty());
|
||||
}: _<T::RuntimeOrigin>(authority, chain_id.clone(), network.clone())
|
||||
verify {
|
||||
assert_last_event::<T>(Event::NetworkRegistered {
|
||||
chain_id: chain_id.clone(), network,
|
||||
chain_id: chain_id.clone(), network: network.clone(),
|
||||
}.into());
|
||||
assert_ne!(GhostNetworks::<T>::networks(chain_id.clone()), prev_network);
|
||||
assert_eq!(GhostNetworks::<T>::networks(chain_id.clone()), Some(network));
|
||||
assert_eq!(GhostNetworks::<T>::network_indexes(), vec![chain_id]);
|
||||
}
|
||||
|
||||
update_network_name {
|
||||
@ -251,20 +253,23 @@ benchmarks! {
|
||||
assert_last_event::<T>(Event::NetworkAvgBlockSpeedUpdated {
|
||||
chain_id: chain_id.clone(), avg_block_speed,
|
||||
}.into());
|
||||
assert_ne!(GhostNetworks::<T>::networks(chain_id.clone()), prev_network);
|
||||
assert_ne!(GhostNetworks::<T>::networks(chain_id.clone()), None);
|
||||
}
|
||||
|
||||
remove_network {
|
||||
let (chain_id, network) = prepare_network::<T>(1, 1, 1);
|
||||
let authority = T::RemoveOrigin::try_successful_origin()
|
||||
.map_err(|_| BenchmarkError::Weightless)?;
|
||||
let prev_network = create_network::<T>(chain_id.clone(), network.clone())?;
|
||||
let _ = create_network::<T>(chain_id.clone(), network.clone())?;
|
||||
assert_eq!(GhostNetworks::<T>::networks(chain_id.clone()), Some(network));
|
||||
assert_eq!(GhostNetworks::<T>::network_indexes(), vec![chain_id.clone()]);
|
||||
}: _<T::RuntimeOrigin>(authority, chain_id.clone())
|
||||
verify {
|
||||
assert_last_event::<T>(Event::NetworkRemoved {
|
||||
chain_id: chain_id.clone(),
|
||||
}.into());
|
||||
assert_ne!(GhostNetworks::<T>::networks(chain_id.clone()), prev_network);
|
||||
assert_eq!(GhostNetworks::<T>::networks(chain_id.clone()), None);
|
||||
assert!(GhostNetworks::<T>::network_indexes().is_empty());
|
||||
}
|
||||
|
||||
impl_benchmark_test_suite!(GhostNetworks, crate::mock::ExtBuilder::build(), crate::mock::Test);
|
||||
|
||||
@ -737,9 +737,7 @@ impl<T: Config> NetworkDataInspectHandler<NetworkData> for Pallet<T> {
|
||||
Networks::<T>::get(n)
|
||||
}
|
||||
|
||||
fn next_network_for_block(
|
||||
block_number: impl Into<usize>,
|
||||
) -> Option<(Self::NetworkId, NetworkData)> {
|
||||
fn network_for_block(block_number: impl Into<usize>) -> Option<(Self::NetworkId, NetworkData)> {
|
||||
let network_indexes = NetworkIndexes::<T>::get();
|
||||
block_number
|
||||
.into()
|
||||
|
||||
@ -82,6 +82,7 @@ pallet_staking_reward_curve::build! {
|
||||
|
||||
parameter_types! {
|
||||
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
|
||||
pub const MaxNetworks: u32 = 3;
|
||||
}
|
||||
|
||||
ord_parameter_types! {
|
||||
@ -98,7 +99,7 @@ impl ghost_networks::Config for Test {
|
||||
type RegisterOrigin = EnsureSignedBy<RegistererAccount, AccountId>;
|
||||
type UpdateOrigin = EnsureSignedBy<UpdaterAccount, AccountId>;
|
||||
type RemoveOrigin = EnsureSignedBy<RemoverAccount, AccountId>;
|
||||
type MaxNetworks = ConstU32<3>;
|
||||
type MaxNetworks = MaxNetworks;
|
||||
type WeightInfo = ();
|
||||
}
|
||||
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
use super::*;
|
||||
use frame_support::{assert_err, assert_ok};
|
||||
use mock::{
|
||||
ExtBuilder, GhostNetworks, RandomAccount, RegistererAccount, RemoverAccount, RewardCurve,
|
||||
RuntimeEvent, RuntimeOrigin, System, Test, UpdaterAccount,
|
||||
ExtBuilder, GhostNetworks, MaxNetworks, RandomAccount, RegistererAccount, RemoverAccount,
|
||||
RewardCurve, RuntimeEvent, RuntimeOrigin, System, Test, UpdaterAccount,
|
||||
};
|
||||
use pallet_staking::EraPayout;
|
||||
use sp_runtime::DispatchError;
|
||||
@ -1818,6 +1818,32 @@ fn migration_from_v0_to_v1_works() {
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn error_on_max_networks_overflow() {
|
||||
ExtBuilder::build().execute_with(|| {
|
||||
let (chain_id, network) = prepare_network_data();
|
||||
|
||||
let max_networks = MaxNetworks::get();
|
||||
for index in 0..max_networks {
|
||||
let other_chain_id = chain_id.saturating_add(index);
|
||||
assert_ok!(GhostNetworks::register_network(
|
||||
RuntimeOrigin::signed(RegistererAccount::get()),
|
||||
other_chain_id,
|
||||
network.clone(),
|
||||
));
|
||||
}
|
||||
|
||||
assert_err!(
|
||||
GhostNetworks::register_network(
|
||||
RuntimeOrigin::signed(RegistererAccount::get()),
|
||||
chain_id.saturating_add(max_networks),
|
||||
network.clone(),
|
||||
),
|
||||
crate::Error::<Test>::TooManyNetworks,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn migration_from_v0_to_v1_does_not_run_twice() {
|
||||
ExtBuilder::build().execute_with(|| {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user