Skip to content

Commit e498e78

Browse files
tlaclocdidiermis
andauthored
update pallets (#12)
* - Updated the Fund Admin Records' list of dependencies in Cargo.toml,… (#10) * - Updated the Fund Admin Records' list of dependencies in Cargo.toml, bumping versions of 'frame support', 'frame system', 'frame benchmarking', 'sp runtime', 'pallet timestamp', 'sp core' and 'sp io' to be compatible with 'polkadot-v0.9.40' from 'polkadot-v0.9.38', aligning with the latest Substrate version. This ensures our pallets stay up-to-date with the latest turnkey infrastructure enabling efficient blockchain development. - Amended the weight ranges for three different calls - 'set_signer_account', 'add_record', and 'kill_storage' - within the Fund Admin Records pallet. We've changed the implementation to 'from_parts', explicitly setting the 'compute' part of the weight to 10,000 and 'io' part to 0. This provides a more specific weight range, optimizing on-chain resource use when these calls are processed. * DEVELOPMENT AND TROUBLESHOOTING - Updated the `pallet` macro for the Fund Admin Records pallet, specifying `STORAGE_VERSION` for better versioning control of the storage data. This ensures proper migration handling in future updates. - Commented out certain test function bodies in the Fund Admin Records pallet. This indicates an ongoing refactoring process and tests will be revisited to ensure they align with the new implementation specifics. - Updated the `pallet_rbac` configuration in the mock file of the Fund Admin pallet, adding `RemoveOrigin` set to `EnsureRoot<Self::AccountId>` to ensure that function calls, specific to the RBAC functionality, are executed by verified roots. - Carried out codebase clean-up in the Gated Marketplace pallet, removing unneeded imports and fixing an incorrect closing tag on the `Config` implementation block. - Updated the test suite for the Gated Marketplace pallet. Ensured that the `mint` function placing assets in the marketplace is correctly unwrapped using `assert_ok`. Commented out certain test cases, indicating a significant refactoring process which the tests will be revisited to align with. - Adjusted the properties order in the pallet-rbac dependency within the Mapped Assets pallet's Cargo.toml for consistency and readability. - Set up RBAC pallet in the test environment for the Mapped Assets pallet, implementing specific parameter types and configuring RBAC pallet for the test setup. - Updated the test suite for the RBAC pallet. Several test cases were commented out indicating an ongoing refactoring process which the tests will be revisited to align with. * update kill storage and bug fixes (#11) * 🐛 fix(afloat): modify `kill_storage` function to accept `args` parameter for more granular control over storage deletion ✨ feat(afloat): add `KillStorageArgs` enum to specify different types of storage to be deleted in `kill_storage` function * 🐛 fix(functions.rs): add authorization check in do_cancel_offer function to ensure only admin or offer creator can cancel the offer 🐛 fix(lib.rs): remove redundant authorization check in cancel_offer function --------- Co-authored-by: Didier Mis <[email protected]>
1 parent 36dcdf0 commit e498e78

File tree

13 files changed

+396
-1325
lines changed

13 files changed

+396
-1325
lines changed

Cargo.lock

Lines changed: 219 additions & 1100 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pallets/afloat/src/functions.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,11 +859,14 @@ impl<T: Config> Pallet<T> {
859859
Ok(())
860860
}
861861

862-
pub fn do_cancel_offer(order_id: StorageId) -> DispatchResult {
862+
pub fn do_cancel_offer(who: T::AccountId, order_id: StorageId) -> DispatchResult {
863863
// ensure offer exists
864864
ensure!(<AfloatOffers<T>>::contains_key(order_id), Error::<T>::OfferNotFound);
865865
//get offer details
866866
let offer = <AfloatOffers<T>>::get(order_id).unwrap();
867+
let is_admin_or_owner = Self::is_admin_or_owner(who.clone())?;
868+
ensure!(is_admin_or_owner || offer.creator_id == who, Error::<T>::Unauthorized);
869+
867870
match offer.status {
868871
OfferStatus::CREATED => {
869872
<AfloatOffers<T>>::try_mutate(order_id, |offer| -> DispatchResult {

pallets/afloat/src/lib.rs

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,40 @@ pub mod pallet {
255255

256256
#[pallet::call_index(1)]
257257
#[pallet::weight(Weight::from_parts(10_000,0) + T::DbWeight::get().reads_writes(1,1))]
258-
pub fn kill_storage(origin: OriginFor<T>) -> DispatchResult {
258+
pub fn kill_storage(origin: OriginFor<T>, args: KillStorageArgs) -> DispatchResult {
259259
// ensure sudo origin
260260
T::RemoveOrigin::ensure_origin(origin.clone())?;
261-
Self::do_delete_all_users()?;
262-
Ok(())
261+
match args {
262+
KillStorageArgs::All => {
263+
Self::do_delete_all_users()?;
264+
<AfloatMarketPlaceId<T>>::kill();
265+
<AfloatCollectionId<T>>::kill();
266+
<AfloatAssetId<T>>::kill();
267+
let _ = <AfloatOffers<T>>::clear(1000, None);
268+
let _ = <AfloatTransactions<T>>::clear(1000, None);
269+
},
270+
KillStorageArgs::UserInfo => {
271+
Self::do_delete_all_users()?;
272+
}
273+
KillStorageArgs::AfloatMarketPlaceId => {
274+
<AfloatMarketPlaceId<T>>::kill();
275+
},
276+
KillStorageArgs::AfloatCollectionId => {
277+
<AfloatCollectionId<T>>::kill();
278+
},
279+
KillStorageArgs::AfloatAssetId => {
280+
<AfloatAssetId<T>>::kill();
281+
},
282+
KillStorageArgs::AfloatOffers => {
283+
let _ = <AfloatOffers<T>>::clear(1000, None);
284+
},
285+
KillStorageArgs::AfloatTransactions => {
286+
let _ = <AfloatTransactions<T>>::clear(1000, None);
287+
},
288+
289+
}
290+
291+
Ok(())
263292
}
264293

265294
#[pallet::call_index(2)]
@@ -404,9 +433,7 @@ pub mod pallet {
404433
#[pallet::weight(Weight::from_parts(10_000,0) + T::DbWeight::get().reads_writes(1,1))]
405434
pub fn cancel_offer(origin: OriginFor<T>, order_id: StorageId) -> DispatchResult {
406435
let who = ensure_signed(origin.clone())?;
407-
let is_admin_or_owner = Self::is_admin_or_owner(who.clone())?;
408-
ensure!(is_admin_or_owner, Error::<T>::Unauthorized);
409-
Self::do_cancel_offer(order_id)
436+
Self::do_cancel_offer(who, order_id)
410437
}
411438
}
412439
}

pallets/afloat/src/types.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,17 @@ pub enum CreateOfferArgs<T: Config> {
161161
},
162162
}
163163

164+
#[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebugNoBound, TypeInfo)]
165+
pub enum KillStorageArgs {
166+
All,
167+
UserInfo,
168+
AfloatMarketPlaceId,
169+
AfloatCollectionId,
170+
AfloatAssetId,
171+
AfloatOffers,
172+
AfloatTransactions,
173+
}
174+
164175
// ! Transaction structures
165176

166177
#[derive(CloneNoBound, Encode, Decode, RuntimeDebugNoBound, TypeInfo, MaxEncodedLen, PartialEq)]

pallets/fund-admin-records/Cargo.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ codec = { package = "parity-scale-codec", version = "3.0.0", default-features =
2020
scale-info = { version = "2.0.1", default-features = false, features = [
2121
"derive"
2222
] }
23-
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.38" }
24-
frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.38" }
25-
frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.38", optional = true }
26-
sp-runtime = { default-features = false, version = "7.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.38" }
27-
pallet-timestamp = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.38" }
23+
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40" }
24+
frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40" }
25+
frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40", optional = true }
26+
sp-runtime = { default-features = false, version = "7.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40" }
27+
pallet-timestamp = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40" }
2828

2929
[dev-dependencies]
30-
sp-core = { default-features = false, version = "7.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.38" }
31-
sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.38" }
30+
sp-core = { default-features = false, version = "7.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40" }
31+
sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40" }
3232

3333
[features]
3434
default = ["std"]

pallets/fund-admin-records/src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub mod pallet {
2222
use frame_support::traits::Time;
2323

2424
use crate::types::*;
25+
const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
2526

2627
#[pallet::config]
2728
pub trait Config: frame_system::Config {
@@ -45,7 +46,7 @@ pub mod pallet {
4546
}
4647

4748
#[pallet::pallet]
48-
#[pallet::generate_store(pub(super) trait Store)]
49+
#[pallet::storage_version(STORAGE_VERSION)]
4950
pub struct Pallet<T>(_);
5051

5152
/*--- Onchain storage section ---*/
@@ -113,7 +114,7 @@ pub mod pallet {
113114
/// * `signer_account` - The account id of the signer
114115
/// Returns `Ok` if the operation is successful, `Err` otherwise.
115116
#[pallet::call_index(1)]
116-
#[pallet::weight(Weight::from_ref_time(10_000) + T::DbWeight::get().writes(10))]
117+
#[pallet::weight(Weight::from_parts(10_000,0) + T::DbWeight::get().writes(10))]
117118
pub fn set_signer_account(
118119
origin: OriginFor<T>,
119120
account: T::AccountId,
@@ -136,7 +137,7 @@ pub mod pallet {
136137
/// If the function executes successfully without any error, it will return `Ok(())`.
137138
/// If there is an error, it will return `Err(error)`, where `error` is an instance of the `DispatchError` class.
138139
#[pallet::call_index(2)]
139-
#[pallet::weight(Weight::from_ref_time(10_000) + T::DbWeight::get().writes(10))]
140+
#[pallet::weight(Weight::from_parts(10_000,0) + T::DbWeight::get().writes(10))]
140141
pub fn add_record(
141142
origin: OriginFor<T>,
142143
records: RecordCollection<T>,
@@ -163,7 +164,7 @@ pub mod pallet {
163164
/// ### Considerations:
164165
/// - This function is only available to the `admin` with sudo access.
165166
#[pallet::call_index(3)]
166-
#[pallet::weight(Weight::from_ref_time(10_000) + T::DbWeight::get().writes(10))]
167+
#[pallet::weight(Weight::from_parts(10_000,0) + T::DbWeight::get().writes(10))]
167168
pub fn kill_storage(
168169
origin: OriginFor<T>,
169170
) -> DispatchResult{

pallets/fund-admin-records/src/tests.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{mock::*, types::*, Records, Error};
2-
use frame_support::{assert_ok, assert_noop, bounded_vec, BoundedVec, traits::ConstU32};
2+
use frame_support::{assert_ok, assert_noop, bounded_vec};
33

44

55
fn make_project_id(v: &str) -> ProjectId {
@@ -28,27 +28,27 @@ fn make_record_collection(
2828
record_collection
2929
}
3030

31-
fn make_default_record_collection() -> RecordCollection<Test> {
32-
make_record_collection(
33-
make_project_id("project_id"),
34-
make_hashed_info("hashed_info"),
35-
TableType::Drawdown,
36-
RecordType::Creation,
37-
)
38-
}
31+
// fn make_default_record_collection() -> RecordCollection<Test> {
32+
// make_record_collection(
33+
// make_project_id("project_id"),
34+
// make_hashed_info("hashed_info"),
35+
// TableType::Drawdown,
36+
// RecordType::Creation,
37+
// )
38+
// }
3939

40-
fn make_array_record_collection(num: u16) -> RecordCollection<Test> {
41-
let mut record_collection: RecordCollection<Test> = bounded_vec![];
42-
for i in 0..num {
43-
record_collection.try_push((
44-
make_project_id(&format!("project_id_{}", i)),
45-
make_hashed_info(&format!("hashed_info_{}", i)),
46-
TableType::Drawdown,
47-
RecordType::Creation,
48-
)).unwrap_or_default();
49-
}
50-
record_collection
51-
}
40+
// fn make_array_record_collection(num: u16) -> RecordCollection<Test> {
41+
// let mut record_collection: RecordCollection<Test> = bounded_vec![];
42+
// for i in 0..num {
43+
// record_collection.try_push((
44+
// make_project_id(&format!("project_id_{}", i)),
45+
// make_hashed_info(&format!("hashed_info_{}", i)),
46+
// TableType::Drawdown,
47+
// RecordType::Creation,
48+
// )).unwrap_or_default();
49+
// }
50+
// record_collection
51+
// }
5252

5353
#[test]
5454
fn set_signer_account_works() {

pallets/fund-admin/src/mock.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ parameter_types! {
148148
}
149149
impl pallet_rbac::Config for Test {
150150
type RuntimeEvent = RuntimeEvent;
151+
type RemoveOrigin = EnsureRoot<Self::AccountId>;
151152
type MaxScopesPerPallet = MaxScopesPerPallet;
152153
type MaxRolesPerPallet = MaxRolesPerPallet;
153154
type RoleMaxLen = RoleMaxLen;

pallets/gated-marketplace/src/mock.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate as pallet_gated_marketplace;
22
use frame_support::{
3-
construct_runtime, parameter_types,
3+
parameter_types,
44
traits::{AsEnsureOriginWithArg, ConstU32, ConstU64, GenesisBuild},
55
};
66
use frame_system as system;
@@ -253,4 +253,4 @@ impl pallet_mapped_assets::Config for Test {
253253
type RemoveItemsLimit = ConstU32<5>;
254254
type MaxReserves = MaxReserves;
255255
type ReserveIdentifier = u32;
256-
}
256+
C}

0 commit comments

Comments
 (0)