Skip to content

Commit

Permalink
Additional Test for Remove Bucket feature (#323)
Browse files Browse the repository at this point in the history
### Description
<!-- Describe what change this PR is implementing -->

### Types of Changes
<!--- What types of changes does your code introduce? -->
- [X] Tech Debt (Code improvements)
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Dependency upgrade (A change in substrate or any 3rd party crate
version)

### Migrations and Hooks
<!--- Check the following box with an x if the following applies: -->
- [ ] This change requires a runtime migration.
- [ ] Modifies `on_initialize`
- [ ] Modifies `on_finalize`

### Checklist
<!--- All boxes need to be checked. Follow this checklist before
requiring PR review -->
- [X] Change has been tested locally.
- [X] Change adds / updates tests.
- [ ] Changelog doc updated.
  • Loading branch information
ayushmishra2005 authored May 3, 2024
1 parent 5ebcec8 commit c181722
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 6 deletions.
8 changes: 3 additions & 5 deletions pallets/ddc-customers/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
//! Test utilities
use ddc_primitives::{
traits::cluster::{
ClusterCreator, ClusterManager, ClusterManagerError, ClusterVisitor, ClusterVisitorError,
},
ClusterBondingParams, ClusterFeesParams, ClusterGovParams, ClusterId, ClusterParams,
ClusterPricingParams, NodePubKey, NodeType,
traits::cluster::{ClusterManager, ClusterManagerError, ClusterVisitorError},
ClusterBondingParams, ClusterFeesParams, ClusterGovParams, ClusterParams, ClusterPricingParams,
NodePubKey, NodeType,
};
use frame_support::{
construct_runtime, parameter_types,
Expand Down
82 changes: 81 additions & 1 deletion pallets/ddc-customers/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Tests for the module.
use ddc_primitives::ClusterId;
use frame_support::{assert_noop, assert_ok};

use super::{mock::*, *};
Expand Down Expand Up @@ -496,3 +495,84 @@ fn remove_bucket_works() {
);
})
}

#[test]
fn remove_bucket_checks_with_multiple_buckets_works() {
ExtBuilder.build_and_execute(|| {
let cluster_id = ClusterId::from([1; 20]);
let account_1 = 1;
let account_2 = 2;
let bucket_id_1 = 1;
let bucket_id_2 = 2;
let private_bucket_params = BucketParams { is_public: false };
let public_bucket_params = BucketParams { is_public: true };

// Fail to remove non-existing buckets
assert_noop!(
DdcCustomers::remove_bucket(RuntimeOrigin::signed(account_1), bucket_id_1),
Error::<Test>::NoBucketWithId
);

assert_noop!(
DdcCustomers::remove_bucket(RuntimeOrigin::signed(account_1), bucket_id_2),
Error::<Test>::NoBucketWithId
);

// Bucket created
assert_ok!(DdcCustomers::create_bucket(
RuntimeOrigin::signed(account_1),
cluster_id,
private_bucket_params.clone()
));

// Bucket created
assert_ok!(DdcCustomers::create_bucket(
RuntimeOrigin::signed(account_2),
cluster_id,
public_bucket_params.clone()
));

// Fail to remove bucket with different owner
assert_noop!(
DdcCustomers::remove_bucket(RuntimeOrigin::signed(account_1), bucket_id_2),
Error::<Test>::NotBucketOwner
);

assert_noop!(
DdcCustomers::remove_bucket(RuntimeOrigin::signed(account_2), bucket_id_1),
Error::<Test>::NotBucketOwner
);

// Remove bucket with correct owner
assert_ok!(DdcCustomers::remove_bucket(RuntimeOrigin::signed(account_1), bucket_id_1));

// Verify whether bucket has been removed
assert_eq!(
DdcCustomers::buckets(bucket_id_1),
Some(Bucket {
bucket_id: bucket_id_1,
owner_id: account_1,
cluster_id,
is_public: private_bucket_params.is_public,
is_removed: true,
})
);

assert_eq!(
DdcCustomers::buckets(bucket_id_2),
Some(Bucket {
bucket_id: bucket_id_2,
owner_id: account_2,
cluster_id,
is_public: public_bucket_params.is_public,
is_removed: false,
})
);

// Fail to remove already removed bucket
assert_noop!(
DdcCustomers::remove_bucket(RuntimeOrigin::signed(account_1), bucket_id_1),
Error::<Test>::AlreadyRemoved
);
})
}

0 comments on commit c181722

Please sign in to comment.