Skip to content

Commit

Permalink
Feature/extend clusters tests (#184)
Browse files Browse the repository at this point in the history
- improve test coverage to over 80%
- replace copy/pasted arguments with variables
- add benchmarking to tests

---------

Co-authored-by: aie0 <149175774+aie0@users.noreply.github.com>
  • Loading branch information
Raid5594 and aie0 authored Dec 4, 2023
1 parent 43ed4f4 commit eb8488d
Show file tree
Hide file tree
Showing 4 changed files with 306 additions and 89 deletions.
6 changes: 6 additions & 0 deletions pallets/ddc-clusters/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,10 @@ benchmarks! {
verify {
assert_eq!(ClustersGovParams::<T>::try_get(cluster_id).unwrap(), new_cluster_gov_params);
}

impl_benchmark_test_suite!(
DdcClusters,
crate::mock::ExtBuilder.build(),
crate::mock::Test,
);
}
39 changes: 37 additions & 2 deletions pallets/ddc-clusters/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use sp_runtime::{
traits::{
BlakeTwo256, Convert, Extrinsic as ExtrinsicT, IdentifyAccount, IdentityLookup, Verify,
},
MultiSignature,
MultiSignature, Perbill,
};

use crate::{self as pallet_ddc_clusters, *};
Expand Down Expand Up @@ -229,7 +229,7 @@ impl<T: Config> StakerCreator<T, BalanceOf<T>> for TestStaker {
pub struct ExtBuilder;

impl ExtBuilder {
fn build(self) -> TestExternalities {
pub fn build(self) -> TestExternalities {
sp_tracing::try_init_simple();
let mut storage = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();

Expand All @@ -243,6 +243,41 @@ impl ExtBuilder {
}
.assimilate_storage(&mut storage);

let cluster_gov_params = ClusterGovParams {
treasury_share: Perbill::from_float(0.05),
validators_share: Perbill::from_float(0.01),
cluster_reserve_share: Perbill::from_float(0.02),
cdn_bond_size: 100,
cdn_chill_delay: 50,
cdn_unbonding_delay: 50,
storage_bond_size: 100,
storage_chill_delay: 50,
storage_unbonding_delay: 50,
unit_per_mb_stored: 10,
unit_per_mb_streamed: 10,
unit_per_put_request: 10,
unit_per_get_request: 10,
};

let node_pub_key = NodePubKey::CDNPubKey(AccountId::from([0; 32]));

// For testing purposes only
pallet_ddc_clusters::GenesisConfig::<Test>::default().build();

if let Ok(cluster) = Cluster::new(
ClusterId::from([0; 20]),
AccountId::from([0; 32]),
AccountId::from([0; 32]),
ClusterParams { node_provider_auth_contract: Some(AccountId::from([0; 32])) },
) {
let _ = pallet_ddc_clusters::GenesisConfig::<Test> {
clusters: vec![cluster],
clusters_gov_params: vec![(ClusterId::from([0; 20]), cluster_gov_params)],
clusters_nodes: vec![(ClusterId::from([0; 20]), vec![node_pub_key])],
}
.assimilate_storage(&mut storage);
}

TestExternalities::new(storage)
}
pub fn build_and_execute(self, test: impl FnOnce()) {
Expand Down
Loading

0 comments on commit eb8488d

Please sign in to comment.