Skip to content

Commit

Permalink
dedir: Add dedir tests and mock
Browse files Browse the repository at this point in the history
Signed-off-by: Shreevatsa N <[email protected]>
  • Loading branch information
vatsa287 committed Aug 23, 2024
1 parent 5a29e9b commit aa242e5
Show file tree
Hide file tree
Showing 3 changed files with 753 additions and 4 deletions.
7 changes: 3 additions & 4 deletions pallets/dedir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
//!
//! ### Dispatchable Functions
//!
//! * `create_registry` - Create a registry, with states supported and entry types.
//! * `create_registry` - Create a registry, with blob and digest.
//! * `create_registry_entry` - Create a registry entry for the created registry.
//! * `registry_entry_state_change` - Change the status of the registry entry.
//! * `add_delegate` - Add a account as a delegate with specific permission.
Expand Down Expand Up @@ -259,7 +259,7 @@ pub mod pallet {
///
/// This function allows a user to submit a new create registry request.
/// The Registry is created along with various metadata, including the
/// attributes, creator and other data.
/// blob, digest.
///
/// # Arguments
/// * `origin` - The origin of the call, which should be a signed user in most cases.
Expand Down Expand Up @@ -352,8 +352,7 @@ pub mod pallet {
/// This function allows a user to submit a new create registry entry request
/// for a existing Registry.
/// The Registry Entry is created along with various metadata, including the
/// attributes with the Registry Entry Key and its associated type-data,
/// current-state of the registry-entry and other information.
/// blob, digest, and the state of the Registry Entry.
///
/// # Arguments
/// * `origin` - The origin of the call, which should be a signed user in most cases.
Expand Down
101 changes: 101 additions & 0 deletions pallets/dedir/src/mock.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// This file is part of CORD – https://cord.network

// Copyright (C) Dhiway Networks Pvt. Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later

// CORD is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// CORD is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with CORD. If not, see <https://www.gnu.org/licenses/>.

use super::*;
use crate as pallet_dedir;
use cord_utilities::mock::{mock_origin, SubjectId};
use frame_support::{derive_impl, parameter_types};

//use frame_system::EnsureRoot;
use sp_runtime::{
traits::{IdentifyAccount, IdentityLookup, Verify},
BuildStorage, MultiSignature,
};

type Signature = MultiSignature;
type AccountPublic = <Signature as Verify>::Signer;
pub type AccountId = <AccountPublic as IdentifyAccount>::AccountId;
pub(crate) type Block = frame_system::mocking::MockBlock<Test>;

frame_support::construct_runtime!(
pub enum Test {
System: frame_system,
Identifier: identifier,
MockOrigin: mock_origin,
DeDir: pallet_dedir,
}
);

parameter_types! {
pub const SS58Prefix: u8 = 29;
}

#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for Test {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Block = Block;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type SS58Prefix = SS58Prefix;
}

impl mock_origin::Config for Test {
type RuntimeOrigin = RuntimeOrigin;
type AccountId = AccountId;
type SubjectId = SubjectId;
}

parameter_types! {
pub const MaxRegistryDelegates: u32 = 25;
pub const MaxEncodedInputLength: u32 = 32;
pub const MaxRegistryBlobSize: u32 = 16 * 1024; // 16KB in bytes
}

impl pallet_dedir::Config for Test {
type RuntimeEvent = RuntimeEvent;
type MaxRegistryBlobSize = MaxRegistryBlobSize;
type MaxRegistryDelegates = MaxRegistryDelegates;
type MaxEncodedInputLength = MaxEncodedInputLength;
type WeightInfo = ();
}

parameter_types! {
pub const MaxEventsHistory: u32 = 6u32;
}

impl identifier::Config for Test {
type MaxEventsHistory = MaxEventsHistory;
}

parameter_types! {
storage SpaceEvents: u32 = 0;
}

#[allow(dead_code)]
pub(crate) fn new_test_ext() -> sp_io::TestExternalities {
let t: sp_runtime::Storage =
frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
let mut ext = sp_io::TestExternalities::new(t);
#[cfg(feature = "runtime-benchmarks")]
let keystore = sp_keystore::testing::MemoryKeystore::new();
#[cfg(feature = "runtime-benchmarks")]
ext.register_extension(sp_keystore::KeystoreExt(sp_std::sync::Arc::new(keystore)));
ext.execute_with(|| System::set_block_number(1));
ext
}
Loading

0 comments on commit aa242e5

Please sign in to comment.