Skip to content

Commit

Permalink
Merge pull request #272 from jurteam/staging
Browse files Browse the repository at this point in the history
Staging -> Main
  • Loading branch information
mtmsuhail authored Jan 19, 2024
2 parents a8c59c2 + 460fb95 commit 017497b
Show file tree
Hide file tree
Showing 18 changed files with 433 additions and 178 deletions.
219 changes: 107 additions & 112 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "jur-node"
version = "3.4.0"
version = "3.5.0"
edition = "2021"
license = "Unlicense"
publish = false
Expand All @@ -13,9 +13,9 @@ targets = ["x86_64-unknown-linux-gnu"]
name = "jur-node"

[dependencies]
clap = { version = "4.4.11", features = ["derive"] }
clap = { version = "4.4.15", features = ["derive"] }
hex-literal = '0.4.1'
serde = { version = "1.0.192", features = ["derive"] }
serde = { version = "1.0.195", features = ["derive"] }
futures = { version = "0.3.30", features = ["thread-pool"]}
sc-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" }
sp-core = { version = "21.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" }
Expand Down Expand Up @@ -58,7 +58,7 @@ frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", bran
frame-benchmarking-cli = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.2.0" }

# Local Dependencies
jur-node-runtime = { version = "3.4.0", path = "../runtime" }
jur-node-runtime = { version = "3.5.0", path = "../runtime" }
primitives = { package = 'jur-primitives', path = '../primitives' }

# CLI-specific dependencies
Expand Down
3 changes: 2 additions & 1 deletion pallets/bounties/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"]
codec = { package = "parity-scale-codec", version = "3.6.1", features = ["derive"], default-features = false }
primitives = { package = 'jur-primitives', path = '../../primitives', default-features = false }
scale-info = { version = "2.9.0", default-features = false, features = ["derive"] }
pallet-balances = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" }

# Substrate
frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, optional = true, branch = "release-polkadot-v1.2.0" }
Expand All @@ -31,7 +32,7 @@ pallet-passport = { package = 'pallet-passport', path = '../passport', default-f
pallet-whitelist = { package = 'pallet-whitelist', path = '../whitelist', default-features = false }

[dev-dependencies]
serde = { version = "1.0.132" }
serde = { version = "1.0.195" }

# Substrate
sp-core = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.2.0" }
Expand Down
25 changes: 24 additions & 1 deletion pallets/bounties/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use frame_support::{
traits::{AsEnsureOriginWithArg, ConstU16, ConstU32, ConstU64},
};
use frame_system as system;
use primitives::Balance;
use sp_core::H256;
use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup},
Expand All @@ -23,6 +24,7 @@ frame_support::construct_runtime!(
BountyPallet: pallet_bounties,
Passport: pallet_passport,
Whitelist: pallet_whitelist,
Balances: pallet_balances,
}
);

Expand All @@ -48,7 +50,7 @@ impl system::Config for Test {
type DbWeight = ();
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = ();
type AccountData = pallet_balances::AccountData<u128>;
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
Expand Down Expand Up @@ -104,6 +106,27 @@ impl pallet_bounties::Config for Test {
type WeightInfo = ();
}

parameter_types! {
pub const ExistentialDeposit: Balance = 1;
pub const MaxLocks: u32 = 50;
}

impl pallet_balances::Config for Test {
type MaxLocks = MaxLocks;
type Balance = u128;
type RuntimeEvent = RuntimeEvent;
type DustRemoval = ();
type MaxReserves = ();
type ReserveIdentifier = [u8; 8];
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = ();
type FreezeIdentifier = ();
type MaxFreezes = ();
type RuntimeHoldReason = ();
type MaxHolds = ();
}

// Build genesis storage according to the mock runtime.
pub fn new_test_ext() -> sp_io::TestExternalities {
let mut ext: sp_io::TestExternalities = system::GenesisConfig::<Test>::default()
Expand Down
4 changes: 3 additions & 1 deletion pallets/community/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ log = { version = "0.4" }
codec = { package = "parity-scale-codec", version = "3.6.1", features = ["derive"], default-features = false }
primitives = { package = 'jur-primitives', path = '../../primitives', default-features = false }
scale-info = { version = "2.9.0", default-features = false, features = ["derive"] }
pallet-balances = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" }

# Substrate
frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, optional = true, branch = "release-polkadot-v1.2.0" }
Expand All @@ -30,7 +31,7 @@ sp-std = { git = "https://github.com/paritytech/polkadot-sdk", default-features
pallet-whitelist = { package = 'pallet-whitelist', path = '../whitelist', default-features = false }

[dev-dependencies]
serde = { version = "1.0.132" }
serde = { version = "1.0.195" }

# Substrate
sp-core = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.2.0" }
Expand All @@ -51,5 +52,6 @@ std = [
"sp-std/std",
"sp-runtime/std",
"pallet-whitelist/std",
"pallet-balances/std",
]
try-runtime = [ "frame-support/try-runtime" ]
10 changes: 10 additions & 0 deletions pallets/community/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,5 +335,15 @@ benchmarks! {
assert_last_event::<T>(Event::<T>::UpdatedTagAndColors(T::Helper::community(1)).into());
}

update_required_founder_balance {
let required_founder_balance: T::Balance = 1000u32.into();
}: _(
RawOrigin::Root, required_founder_balance
)

verify {
assert_last_event::<T>(Event::<T>::UpdatedRequiredFounderBalance(required_founder_balance).into());
}

impl_benchmark_test_suite!(Community, crate::mock::new_test_ext(), crate::mock::Test);
}
45 changes: 40 additions & 5 deletions pallets/community/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ pub mod pallet {
/// Configure the pallet by specifying the parameters and types on which it
/// depends.
#[pallet::config]
pub trait Config: frame_system::Config + pallet_whitelist::Config {
pub trait Config:
frame_system::Config + pallet_whitelist::Config + pallet_balances::Config
{
/// Because this pallet emits events, it depends on the runtime's
/// definition of an event.
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
Expand Down Expand Up @@ -168,6 +170,11 @@ pub mod pallet {
#[pallet::storage]
pub type NextCommunityId<T: Config> = StorageValue<_, T::CommunityId, OptionQuery>;

/// Stores the Required balance to become a founder
#[pallet::storage]
#[pallet::getter(fn required_founder_balance)]
pub type RequiredFounderBalance<T: Config> = StorageValue<_, T::Balance, ValueQuery>;

#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
Expand All @@ -187,6 +194,8 @@ pub mod pallet {
RemovedMember(T::AccountId),
/// Updated Tag And Colors [community]
UpdatedTagAndColors(T::CommunityId),
/// Updated Required Founder Balance [balance]
UpdatedRequiredFounderBalance(T::Balance),
}

// Errors inform users that something went wrong.
Expand Down Expand Up @@ -219,6 +228,8 @@ pub mod pallet {
BadLogo,
/// Community already exist
CommunityAlreadyExist,
/// Insufficient balance to become a founder
InsufficientBalanceToBecomeFounder,
}

#[pallet::hooks]
Expand Down Expand Up @@ -261,10 +272,11 @@ pub mod pallet {

let founder = T::CreateOrigin::ensure_origin(origin, &community_id)?;

pallet_whitelist::Founders::<T>::get()
.binary_search(&founder)
.ok()
.ok_or(Error::<T>::FounderNotExist)?;
let balance = pallet_balances::Pallet::<T>::free_balance(&founder);

let required_balance = RequiredFounderBalance::<T>::get();

ensure!(balance >= required_balance, Error::<T>::InsufficientBalanceToBecomeFounder);

Self::do_create_community(
community_id,
Expand Down Expand Up @@ -588,6 +600,29 @@ pub mod pallet {
Ok(())
})
}

/// Update required balance to become a founder
///
/// The origin must be root.
///
/// Parameters:
/// - `balance`: Required balance to become a founder
/// Emits `UpdatedRequiredFounderBalance` event when successful.
///
#[pallet::call_index(8)]
#[pallet::weight(<T as pallet::Config>::WeightInfo::update_required_founder_balance())]
pub fn update_required_founder_balance(
origin: OriginFor<T>,
balance: T::Balance,
) -> DispatchResult {
ensure_root(origin)?;

RequiredFounderBalance::<T>::set(balance);

Self::deposit_event(Event::UpdatedRequiredFounderBalance(balance));

Ok(())
}
}
}

Expand Down
37 changes: 33 additions & 4 deletions pallets/community/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ use crate::{
Category, CommunityMetaData, CommunityType, Customs, Languages, Religions, Territories,
Traditions, Values,
};
use frame_support::traits::fungible::Mutate;
use frame_support::{
parameter_types,
traits::{AsEnsureOriginWithArg, ConstU16, ConstU32, ConstU64},
};
use frame_support_test::TestRandomness;
use frame_system as system;
use primitives::Balance;
use sp_core::H256;
use sp_runtime::{
traits::{BlakeTwo256, Header as _, IdentityLookup},
Expand All @@ -24,6 +26,7 @@ frame_support::construct_runtime!(
System: frame_system,
Community: pallet_community,
Whitelist: pallet_whitelist,
Balances: pallet_balances,
}
);

Expand All @@ -49,7 +52,7 @@ impl system::Config for Test {
type BlockHashCount = ConstU64<250>;
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = ();
type AccountData = pallet_balances::AccountData<u128>;
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
Expand All @@ -58,6 +61,11 @@ impl system::Config for Test {
type MaxConsumers = frame_support::traits::ConstU32<16>;
}

parameter_types! {
pub const ExistentialDeposit: Balance = 1;
pub const MaxLocks: u32 = 50;
}

impl pallet_community::Config for Test {
type RuntimeEvent = RuntimeEvent;
type CommunityId = u32;
Expand All @@ -80,6 +88,22 @@ impl pallet_whitelist::Config for Test {
type WeightInfo = ();
}

impl pallet_balances::Config for Test {
type MaxLocks = MaxLocks;
type Balance = u128;
type RuntimeEvent = RuntimeEvent;
type DustRemoval = ();
type MaxReserves = ();
type ReserveIdentifier = [u8; 8];
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = ();
type FreezeIdentifier = ();
type MaxFreezes = ();
type RuntimeHoldReason = ();
type MaxHolds = ();
}

// Build genesis storage according to the mock runtime.
pub fn new_test_ext() -> sp_io::TestExternalities {
let mut ext: sp_io::TestExternalities = system::GenesisConfig::<Test>::default()
Expand Down Expand Up @@ -151,9 +175,6 @@ pub fn get_metadata() -> CommunityMetaData<ConstU32<250>> {
community_metadata
}

pub fn add_founder() {
Whitelist::add_founder(RuntimeOrigin::root(), 1).unwrap();
}
pub fn create_community() {
Community::create_community(
RuntimeOrigin::signed(1),
Expand All @@ -174,3 +195,11 @@ pub fn create_community() {
)
.unwrap();
}

pub fn set_balance(amount: u128) {
Balances::set_balance(&1, amount);
}

pub fn set_required_balance_to_create_community(amount: u128) {
Community::update_required_founder_balance(RuntimeOrigin::root(), amount).unwrap();
}
Loading

0 comments on commit 017497b

Please sign in to comment.