From 20b5869357524b7cee14d9e6ab009bf071d4c7eb Mon Sep 17 00:00:00 2001 From: Sudip Ghimire <39845901+sudipghimire533@users.noreply.github.com> Date: Fri, 24 Mar 2023 14:37:17 +0100 Subject: [PATCH] Change contributer to contributor (#61) --- pallets/reward-campaign/src/benchmarking.rs | 58 ++++---- pallets/reward-campaign/src/functions.rs | 8 +- pallets/reward-campaign/src/lib.rs | 102 ++++++------- pallets/reward-campaign/src/tests.rs | 154 ++++++++++---------- pallets/reward-campaign/src/weights.rs | 12 +- 5 files changed, 167 insertions(+), 167 deletions(-) diff --git a/pallets/reward-campaign/src/benchmarking.rs b/pallets/reward-campaign/src/benchmarking.rs index cc43745..9465605 100644 --- a/pallets/reward-campaign/src/benchmarking.rs +++ b/pallets/reward-campaign/src/benchmarking.rs @@ -92,8 +92,8 @@ benchmarks! { ); } - add_contributer { - let contributer = make_account::(22); + add_contributor { + let contributor = make_account::(22); let caller = make_account::(1); let campaign_id: types::CampaignIdOf = 2_u32.into(); let amount: types::BalanceOf = Bounded::max_value(); @@ -112,15 +112,15 @@ benchmarks! { ) ); - }: _(RawOrigin::Signed(caller.clone()), campaign_id, contributer.clone(), amount) + }: _(RawOrigin::Signed(caller.clone()), campaign_id, contributor.clone(), amount) verify { assert!( - CampaignReward::::get_contribution(campaign_id, contributer).is_some() + CampaignReward::::get_contribution(campaign_id, contributor).is_some() ); } - remove_contributer { - let contributer = make_account::(22); + remove_contributor { + let contributor = make_account::(22); let caller = make_account::(1); let campaign_id: types::CampaignIdOf = 2_u32.into(); let params = types::CreateCampaignParamFor:: { @@ -138,25 +138,25 @@ benchmarks! { ) ); assert_ok!( - CampaignReward::::add_contributer(RawOrigin::Signed(caller.clone()).into(), + CampaignReward::::add_contributor(RawOrigin::Signed(caller.clone()).into(), campaign_id, - contributer.clone(), + contributor.clone(), Bounded::max_value(), ) ); assert!( - CampaignReward::::get_contribution::<_, types::AccountIdOf>(campaign_id, contributer.clone()).is_some(), + CampaignReward::::get_contribution::<_, types::AccountIdOf>(campaign_id, contributor.clone()).is_some(), ); - }: _(RawOrigin::Signed(caller.clone()), campaign_id, contributer.clone()) + }: _(RawOrigin::Signed(caller.clone()), campaign_id, contributor.clone()) verify { assert_eq!( - CampaignReward::::get_contribution::<_, types::AccountIdOf>(campaign_id, contributer.clone()), + CampaignReward::::get_contribution::<_, types::AccountIdOf>(campaign_id, contributor.clone()), None, ); } get_instant_reward { - let contributer = make_account::(22); + let contributor = make_account::(22); let caller = make_account::(1); let campaign_id: types::CampaignIdOf = 10_u32.into(); let params = types::CreateCampaignParamFor:: { @@ -175,26 +175,26 @@ benchmarks! { ) ); assert_ok!( - CampaignReward::::add_contributer(RawOrigin::Signed(caller.clone()).into(), + CampaignReward::::add_contributor(RawOrigin::Signed(caller.clone()).into(), campaign_id, - contributer.clone(), + contributor.clone(), ( DHX_UNIT * 5 ).into(), ) ); assert_ok!( CampaignReward::::lock_campaign(RawOrigin::Signed(caller.clone()).into(), campaign_id.clone()) ); - }: _(RawOrigin::Signed(contributer.clone()), campaign_id) + }: _(RawOrigin::Signed(contributor.clone()), campaign_id) verify { assert_eq!( - CampaignReward::::get_contribution(campaign_id, contributer.clone()) + CampaignReward::::get_contribution(campaign_id, contributor.clone()) .map(|p| p.status), Some(types::ClaimerStatus::DoneInstant) ); } get_vested_reward { - let contributer = make_account::(22); + let contributor = make_account::(22); let caller = make_account::(1); let campaign_id: types::CampaignIdOf = 10_u32.into(); let params = types::CreateCampaignParamFor:: { @@ -213,19 +213,19 @@ benchmarks! { ) ); assert_ok!( - CampaignReward::::add_contributer(RawOrigin::Signed(caller.clone()).into(), + CampaignReward::::add_contributor(RawOrigin::Signed(caller.clone()).into(), campaign_id, - contributer.clone(), + contributor.clone(), as Bounded>::max_value() - 10_000_000_u32.into(), ) ); assert_ok!( CampaignReward::::lock_campaign(RawOrigin::Signed(caller.clone()).into(), campaign_id.clone()) ); - }: _(RawOrigin::Signed(contributer.clone()), campaign_id) + }: _(RawOrigin::Signed(contributor.clone()), campaign_id) verify { assert_eq!( - CampaignReward::::get_contribution(campaign_id, contributer.clone()) + CampaignReward::::get_contribution(campaign_id, contributor.clone()) .map(|p| p.status), Some(types::ClaimerStatus::DoneVesting) ); @@ -248,11 +248,11 @@ benchmarks! { ) ); - for contributer in 0_u32 .. 10_u32 { + for contributor in 0_u32 .. 10_u32 { assert_ok!( - CampaignReward::::add_contributer(RawOrigin::Signed(caller.clone()).into(), + CampaignReward::::add_contributor(RawOrigin::Signed(caller.clone()).into(), campaign_id.into(), - make_account::(contributer), + make_account::(contributor), ( DHX_UNIT * 5 ).into() ) ); @@ -266,7 +266,7 @@ benchmarks! { } // TODO: - // make weight dependent on number of contributer + // make weight dependent on number of contributor // that exists in this campaign wipe_campaign { let campaign_id: types::CampaignIdOf = 3_u32.into(); @@ -285,8 +285,8 @@ benchmarks! { ) ); - for contributer in 0_u32 .. 10_u32 { - crate::Contribution::::insert(campaign_id.clone(), make_account::(contributer), types::RewardUnitOf:: { + for contributor in 0_u32 .. 10_u32 { + crate::Contribution::::insert(campaign_id.clone(), make_account::(contributor), types::RewardUnitOf:: { instant_amount: 10_000_u32.into(), vesting_amount: 10_000_u32.into(), per_block: 100_000_u32.into(), @@ -320,8 +320,8 @@ benchmarks! { ) ); - for contributer in 0_u32 .. 10_u32 { - crate::Contribution::::insert(campaign_id.clone(), make_account::(contributer), types::RewardUnitOf:: { + for contributor in 0_u32 .. 10_u32 { + crate::Contribution::::insert(campaign_id.clone(), make_account::(contributor), types::RewardUnitOf:: { instant_amount: 10_000_u32.into(), vesting_amount: 10_000_u32.into(), per_block: 100_000_u32.into(), diff --git a/pallets/reward-campaign/src/functions.rs b/pallets/reward-campaign/src/functions.rs index 72d7f0e..a1d949b 100644 --- a/pallets/reward-campaign/src/functions.rs +++ b/pallets/reward-campaign/src/functions.rs @@ -22,7 +22,7 @@ use sp_runtime::{ use crate::types; -/// input details of how a contributer is supposed to receive his reward +/// input details of how a contributor is supposed to receive his reward /// this will output `SplittedAmount` #[cfg_attr(test, derive(Clone, Debug))] pub struct SplitableAmount { @@ -32,7 +32,7 @@ pub struct SplitableAmount { pub instant_percentage: types::SmallRational, } -/// output of how a contributer is supposed to receive his reward +/// output of how a contributor is supposed to receive his reward /// this will be the output generated from `SplittableAmount` #[cfg_attr(test, derive(Eq, PartialEq, Debug, Clone))] pub struct SplittedAmount { @@ -144,8 +144,8 @@ pub fn do_vesting_reward( let vesting_info = types::VestingInfoOf::::new(vesting_amount, per_block, starts_from); let creditor_origin = ::Origin::from(frame_system::RawOrigin::Signed(reward_source)); - let contributer_lookup = ::unlookup(user); + let contributor_lookup = ::unlookup(user); - pallet_vesting::Pallet::::vested_transfer(creditor_origin, contributer_lookup, vesting_info) + pallet_vesting::Pallet::::vested_transfer(creditor_origin, contributor_lookup, vesting_info) } } diff --git a/pallets/reward-campaign/src/lib.rs b/pallets/reward-campaign/src/lib.rs index 004375b..0cd356e 100644 --- a/pallets/reward-campaign/src/lib.rs +++ b/pallets/reward-campaign/src/lib.rs @@ -107,8 +107,8 @@ pub mod pallet { #[pallet::getter(fn get_reward_info)] pub type RewardInfo = StorageMap<_, Blake2_128Concat, CampaignIdOf, CampaignRewardFor>; - /// Map the pair of campaign_id and contributer accountId to - /// the details of how much and how this contributer is to be rewarded + /// Map the pair of campaign_id and contributor accountId to + /// the details of how much and how this contributor is to be rewarded #[pallet::storage] #[pallet::getter(fn get_contribution)] pub type Contribution = @@ -128,26 +128,26 @@ pub mod pallet { CampaignWiped(CampaignIdOf), /// Campaign have been discarded CampaignDiscarded(CampaignIdOf), - /// A contributer received instant amount of reward + /// A contributor received instant amount of reward InstantRewarded { campaign_id: CampaignIdOf, - contributer: AccountIdOf, + contributor: AccountIdOf, }, /// Vesting schdule of vesting amount have been applied to user VestingScheduleApplied { campaign_id: CampaignIdOf, - contributer: AccountIdOf, + contributor: AccountIdOf, }, - /// A contributer have been added as rewardee + /// A contributor have been added as rewardee ContributerAdded { campaign_id: CampaignIdOf, - contributer: AccountIdOf, + contributor: AccountIdOf, amount: BalanceOf, }, - /// A contributer have been removed from campaign + /// A contributor have been removed from campaign ContributerKicked { campaign_id: CampaignIdOf, - contributer: AccountIdOf, + contributor: AccountIdOf, }, } @@ -162,7 +162,7 @@ pub mod pallet { RewardCampaignExists, /// This user have made no contribution NoContribution, - /// This contributer already exists + /// This contributor already exists ContributerExists, /// Campaign have been locked CampaignLocked, @@ -172,16 +172,16 @@ pub mod pallet { CampaignWiped, /// This crowdloan is in one of read-only state ReadOnlyCampaign, - /// This campaign is not yet in claimable state for contributers + /// This campaign is not yet in claimable state for contributors CampaignNotLocked, /// This campaign cannot be locked NonLockableCampaign, - /// This Reward have been taken by this contributer + /// This Reward have been taken by this contributor RewardTaken, CanotSplitAmount, - /// This campaign is not empty. i.e some contributers exists + /// This campaign is not empty. i.e some contributors exists NonEmptyCampaign, - /// Some contributer have not claimed their reward yet + /// Some contributor have not claimed their reward yet UnclaimedContribution, /// Campaign is not in claimable state NonClaimableCampaign, @@ -269,19 +269,19 @@ pub mod pallet { Ok(()) } - /// Add a user `contributer` as a rewardee of writeable campaign `campaign_id` + /// Add a user `contributor` as a rewardee of writeable campaign `campaign_id` /// with the total reward amount of `amount` - #[pallet::weight(::WeightInfo::add_contributer())] - pub fn add_contributer( + #[pallet::weight(::WeightInfo::add_contributor())] + pub fn add_contributor( origin: OriginFor, campaign_id: CampaignIdOf, - contributer: AccountIdOf, + contributor: AccountIdOf, amount: BalanceOf, ) -> DispatchResult { Self::ensure_hoster(origin, campaign_id)?; Self::ensure_campaign_writable(&campaign_id)?; - ensure!(!>::contains_key(&campaign_id, &contributer), >::ContributerExists); + ensure!(!>::contains_key(&campaign_id, &contributor), >::ContributerExists); let campaign_info = Self::get_reward_info(&campaign_id).ok_or(>::NoRewardCampaign)?; let reward_unit = functions::construct_reward_unit::( @@ -291,33 +291,33 @@ pub mod pallet { campaign_info.end_target, )?; - >::insert(&campaign_id, &contributer, reward_unit); + >::insert(&campaign_id, &contributor, reward_unit); Self::deposit_event(Event::::ContributerAdded { campaign_id, - contributer, + contributor, amount, }); Ok(()) } - /// remove user `contributer` under unlocked campaign `campaign_id` - #[pallet::weight(::WeightInfo::remove_contributer())] - pub fn remove_contributer( + /// remove user `contributor` under unlocked campaign `campaign_id` + #[pallet::weight(::WeightInfo::remove_contributor())] + pub fn remove_contributor( origin: OriginFor, campaign_id: CampaignIdOf, - contributer: AccountIdOf, + contributor: AccountIdOf, ) -> DispatchResult { Self::ensure_hoster(origin, campaign_id)?; Self::ensure_campaign_writable(&campaign_id)?; - ensure!(>::contains_key(&campaign_id, &contributer), >::NoContribution); + ensure!(>::contains_key(&campaign_id, &contributor), >::NoContribution); - >::remove(&campaign_id, &contributer); + >::remove(&campaign_id, &contributor); Self::deposit_event(Event::::ContributerKicked { campaign_id, - contributer, + contributor, }); Ok(()) } @@ -335,7 +335,7 @@ pub mod pallet { } /// discard the in-progress campaign information of `campaign_id` - /// and remove all the contributers and reward details from chain + /// and remove all the contributors and reward details from chain #[pallet::weight(10_0000)] pub fn discard_campaign(origin: OriginFor, campaign_id: CampaignIdOf) -> DispatchResult { Self::ensure_hoster(origin, campaign_id)?; @@ -351,7 +351,7 @@ pub mod pallet { } /// wipe the campaign under `campaign_id` after all the - /// contributers have claimed their reward + /// contributors have claimed their reward /// this will still keep the status as `Wiped` #[pallet::weight(::WeightInfo::wipe_campaign())] pub fn wipe_campaign(origin: OriginFor, campaign_id: CampaignIdOf) -> DispatchResult { @@ -371,22 +371,22 @@ pub mod pallet { /// they are entitled to receive in campaign `campaign_id` #[pallet::weight(::WeightInfo::get_instant_reward())] pub fn get_instant_reward(origin: OriginFor, campaign_id: CampaignIdOf) -> DispatchResult { - let contributer = ensure_signed(origin)?; + let contributor = ensure_signed(origin)?; Self::ensure_campaign_claimable(&campaign_id)?; let InstantEnsuredResultOf:: { new_status, instant_amount, - } = Self::ensure_instant_claimable(&campaign_id, &contributer)?; + } = Self::ensure_instant_claimable(&campaign_id, &contributor)?; let reward_info = Self::get_reward_info(&campaign_id).ok_or(>::NoRewardCampaign)?; - functions::do_instant_reward::(&reward_info.reward_source, &contributer, instant_amount)?; + functions::do_instant_reward::(&reward_info.reward_source, &contributor, instant_amount)?; - Self::update_contributer_status(&campaign_id, &contributer, new_status); + Self::update_contributor_status(&campaign_id, &contributor, new_status); Self::deposit_event(Event::::InstantRewarded { campaign_id, - contributer, + contributor, }); Ok(()) } @@ -395,29 +395,29 @@ pub mod pallet { /// they are entitled to receive in campaign `campaign_id` #[pallet::weight(::WeightInfo::get_vested_reward())] pub fn get_vested_reward(origin: OriginFor, campaign_id: CampaignIdOf) -> DispatchResult { - let contributer = ensure_signed(origin)?; + let contributor = ensure_signed(origin)?; Self::ensure_campaign_claimable(&campaign_id)?; let VestedEnsuredResultOf:: { new_status, vesting_amount, per_block, - } = Self::ensure_vested_claimable(&campaign_id, &contributer)?; + } = Self::ensure_vested_claimable(&campaign_id, &contributor)?; let reward_info = Self::get_reward_info(&campaign_id).ok_or(>::NoRewardCampaign)?; functions::do_vesting_reward::( reward_info.reward_source.clone(), reward_info.starts_from, - contributer.clone(), + contributor.clone(), vesting_amount, per_block, )?; - Self::update_contributer_status(&campaign_id, &contributer, new_status); + Self::update_contributor_status(&campaign_id, &contributor, new_status); Self::deposit_event(Event::::VestingScheduleApplied { campaign_id, - contributer, + contributor, }); Ok(()) } @@ -449,7 +449,7 @@ pub mod pallet { } /// ensure campaign `campaign_id` is in state - /// where contributer can claim the reward they are entitled to + /// where contributor can claim the reward they are entitled to fn ensure_campaign_claimable(campaign_id: &CampaignIdOf) -> DispatchResult { ensure!( Self::get_campaign_status(campaign_id).ok_or(>::NoRewardCampaign)? == @@ -500,12 +500,12 @@ pub mod pallet { Ok(()) } - /// ensure `contributer` can claim instant_reward under `campaign_id` + /// ensure `contributor` can claim instant_reward under `campaign_id` fn ensure_instant_claimable( campaign_id: &CampaignIdOf, - contributer: &AccountIdOf, + contributor: &AccountIdOf, ) -> Result, DispatchError> { - let info = Self::get_contribution(campaign_id, contributer).ok_or(Error::::NoContribution)?; + let info = Self::get_contribution(campaign_id, contributor).ok_or(Error::::NoContribution)?; let new_status = match info.status { ClaimerStatus::Unprocessed => Ok(ClaimerStatus::DoneInstant), @@ -519,12 +519,12 @@ pub mod pallet { }) } - /// ensure `contributer` can claim instant_reward under `campaign_id` + /// ensure `contributor` can claim instant_reward under `campaign_id` fn ensure_vested_claimable( campaign_id: &CampaignIdOf, - contributer: &AccountIdOf, + contributor: &AccountIdOf, ) -> Result, DispatchError> { - let info = Self::get_contribution(campaign_id, contributer).ok_or(Error::::NoContribution)?; + let info = Self::get_contribution(campaign_id, contributor).ok_or(Error::::NoContribution)?; let new_status = match info.status { ClaimerStatus::Unprocessed => Ok(ClaimerStatus::DoneVesting), @@ -539,13 +539,13 @@ pub mod pallet { }) } - /// update `contributer` status under `campaign_id` to `new_status` - fn update_contributer_status( + /// update `contributor` status under `campaign_id` to `new_status` + fn update_contributor_status( campaign_id: &CampaignIdOf, - contributer: &AccountIdOf, + contributor: &AccountIdOf, new_status: ClaimerStatus, ) { - >::mutate(&campaign_id, &contributer, |state| { + >::mutate(&campaign_id, &contributor, |state| { state.as_mut().map(|state| { state.status = new_status; }); diff --git a/pallets/reward-campaign/src/tests.rs b/pallets/reward-campaign/src/tests.rs index b19f1ff..6f435ae 100644 --- a/pallets/reward-campaign/src/tests.rs +++ b/pallets/reward-campaign/src/tests.rs @@ -56,7 +56,7 @@ fn campaign_creation_success() { }) ); - // Data of a usual contributer + // Data of a usual contributor let user_a = (11u32.into(), 1_000_000_u128); let user_b = (12u32.into(), 2_100_004_u128); let user_a_reward = types::RewardUnitOf:: { @@ -76,10 +76,10 @@ fn campaign_creation_success() { assert_eq!(user_b_reward.instant_amount + user_b_reward.vesting_amount, user_b.1); // add users - assert_ok!(Reward::add_contributer(Origin::signed(hoster), campaign_id, user_a.0, user_a.1)); - assert_ok!(Reward::add_contributer(Origin::signed(hoster), campaign_id, user_b.0, user_b.1)); + assert_ok!(Reward::add_contributor(Origin::signed(hoster), campaign_id, user_a.0, user_a.1)); + assert_ok!(Reward::add_contributor(Origin::signed(hoster), campaign_id, user_b.0, user_b.1)); - // Check contributers are added properly + // Check contributors are added properly assert_eq!(Reward::get_contribution(campaign_id, user_a.0).as_ref(), Some(&user_a_reward)); assert_eq!(Reward::get_contribution(campaign_id, user_b.0).as_ref(), Some(&user_b_reward)); @@ -259,9 +259,9 @@ fn campaign_status() { }; // With in-progress status - // - contributer can be added - // - contributer can be removed - // - contributer cannot claim instant reward + // - contributor can be added + // - contributor can be removed + // - contributor cannot claim instant reward // - contributr cannot claim vesting reward // - campaign can be locked // - campaign can be discarded @@ -275,10 +275,10 @@ fn campaign_status() { assert_ok!(new_quick_campaign(hoster, campaign_id)); assert_eq!(Reward::get_campaign_status(campaign_id), Some(types::RewardCampaignStatus::InProgress)); - // cann add contributer - assert_ok!(Reward::add_contributer(Origin::signed(hoster), campaign_id, 5_u32.into(), 10000_u128.into())); - // can remove contributer - assert_ok!(Reward::remove_contributer(Origin::signed(hoster), campaign_id, 5_u32.into())); + // cann add contributor + assert_ok!(Reward::add_contributor(Origin::signed(hoster), campaign_id, 5_u32.into(), 10000_u128.into())); + // can remove contributor + assert_ok!(Reward::remove_contributor(Origin::signed(hoster), campaign_id, 5_u32.into())); // cannot wipe campaign assert_noop!(Reward::wipe_campaign(Origin::signed(hoster), campaign_id), RewardError::CampaignNotLocked,); // cannot claim instant reward @@ -304,38 +304,38 @@ fn campaign_status() { }); // With Locked status - // - contributer cannot be added - // - contributer cannot be removed - // - contributer can claim instant reward - // - contributer can claim vesting reward + // - contributor cannot be added + // - contributor cannot be removed + // - contributor can claim instant reward + // - contributor can claim vesting reward // - campaign cannot be discarded // - campaign cannot be locked - // - campaign can be wiped ( only if all contributer are rewarded) + // - campaign can be wiped ( only if all contributor are rewarded) new_test_ext().execute_with(|| { run_to_block(1); let hoster = 1_u32.into(); let campaign_id = 10_u32.into(); - let contributer_a = 1_u32.into(); - let contributer_b = 2_u32.into(); + let contributor_a = 1_u32.into(); + let contributor_b = 2_u32.into(); // initilize the campaign assert_ok!(new_quick_campaign(hoster, campaign_id)); - assert_ok!(Reward::add_contributer(Origin::signed(hoster), campaign_id, contributer_a, 100_000_u32.into())); - assert_ok!(Reward::add_contributer(Origin::signed(hoster), campaign_id, contributer_b, 200_000_u32.into())); + assert_ok!(Reward::add_contributor(Origin::signed(hoster), campaign_id, contributor_a, 100_000_u32.into())); + assert_ok!(Reward::add_contributor(Origin::signed(hoster), campaign_id, contributor_b, 200_000_u32.into())); let reward_source = Reward::get_reward_info(campaign_id).unwrap().reward_source; credit_account::(&reward_source, 1_000_000_u32.into()); // lock the campaign assert_ok!(Reward::lock_campaign(Origin::signed(hoster), campaign_id)); - // cannot add contributer + // cannot add contributor assert_noop!( - Reward::add_contributer(Origin::signed(hoster), campaign_id, 33_u32.into(), 100_000_u32.into()), + Reward::add_contributor(Origin::signed(hoster), campaign_id, 33_u32.into(), 100_000_u32.into()), RewardError::ReadOnlyCampaign, ); - // Cannot remove contributer + // Cannot remove contributor assert_noop!( - Reward::remove_contributer(Origin::signed(hoster), campaign_id, contributer_a), + Reward::remove_contributor(Origin::signed(hoster), campaign_id, contributor_a), RewardError::ReadOnlyCampaign, ); // Cannot lock campaign @@ -343,25 +343,25 @@ fn campaign_status() { // cannot discard the campaign assert_noop!(Reward::discard_campaign(Origin::signed(hoster), campaign_id), RewardError::CampaignLocked,); // can call get instant reward - assert_ok!(Reward::get_instant_reward(Origin::signed(contributer_a), campaign_id)); - assert_ok!(Reward::get_instant_reward(Origin::signed(contributer_b), campaign_id)); + assert_ok!(Reward::get_instant_reward(Origin::signed(contributor_a), campaign_id)); + assert_ok!(Reward::get_instant_reward(Origin::signed(contributor_b), campaign_id)); // can call get vesting reward - assert_ok!(Reward::get_vested_reward(Origin::signed(contributer_a), campaign_id)); - // since there is still unclaimed contribution ( vesting reward of contributer_b) + assert_ok!(Reward::get_vested_reward(Origin::signed(contributor_a), campaign_id)); + // since there is still unclaimed contribution ( vesting reward of contributor_b) // cannot wipe campaign assert_noop!(Reward::wipe_campaign(Origin::signed(hoster), campaign_id), RewardError::UnclaimedContribution,); - assert_ok!(Reward::get_vested_reward(Origin::signed(contributer_b), campaign_id)); + assert_ok!(Reward::get_vested_reward(Origin::signed(contributor_b), campaign_id)); // can wipe campaign assert_ok!(Reward::wipe_campaign(Origin::signed(hoster), campaign_id)); }); // With Wiped status - // - cannot add contributer - // - cannot remove contributer + // - cannot add contributor + // - cannot remove contributor // - cannot lock campaign // - cannot discard campaign - // - contributer cannot claim instant reward - // - contributer cannot claim vesting reward + // - contributor cannot claim instant reward + // - contributor cannot claim vesting reward new_test_ext().execute_with(|| { run_to_block(1); let hoster = 10_u32.into(); @@ -371,21 +371,21 @@ fn campaign_status() { assert_ok!(new_quick_campaign(hoster, campaign_id)); let reward_source = Reward::get_reward_info(campaign_id).unwrap().reward_source; credit_account::(&reward_source, 1_000_000_u32.into()); - assert_ok!(Reward::add_contributer(Origin::signed(hoster), campaign_id, 100_u32.into(), 100_000_u32.into())); + assert_ok!(Reward::add_contributor(Origin::signed(hoster), campaign_id, 100_u32.into(), 100_000_u32.into())); assert_ok!(Reward::lock_campaign(Origin::signed(hoster), campaign_id)); assert_ok!(Reward::get_vested_reward(Origin::signed(100_u32.into()), campaign_id)); assert_ok!(Reward::get_instant_reward(Origin::signed(100_u32.into()), campaign_id)); assert_ok!(Reward::wipe_campaign(Origin::signed(hoster), campaign_id)); assert_eq!(Reward::get_campaign_status(campaign_id), Some(types::RewardCampaignStatus::Wiped)); - // cannot add contributer + // cannot add contributor assert_noop!( - Reward::add_contributer(Origin::signed(hoster), campaign_id, 33_u32.into(), 100_000_u32.into()), + Reward::add_contributor(Origin::signed(hoster), campaign_id, 33_u32.into(), 100_000_u32.into()), RewardError::NoRewardCampaign, ); - // Cannot remove contributer + // Cannot remove contributor assert_noop!( - Reward::remove_contributer(Origin::signed(hoster), campaign_id, 33_u32.into()), + Reward::remove_contributor(Origin::signed(hoster), campaign_id, 33_u32.into()), RewardError::NoRewardCampaign, ); // Cannot lock campaign @@ -423,7 +423,7 @@ fn claimer_status() { run_to_block(1); let hoster = 1_u32.into(); let campaign_id = 3_u32.into(); - let contributer = 4_u32.into(); + let contributor = 4_u32.into(); assert_ok!(Reward::start_new_campaign( Origin::signed(hoster), @@ -435,22 +435,22 @@ fn claimer_status() { end_target: 10_u32.into(), }, )); - assert_ok!(Reward::add_contributer(Origin::signed(hoster), campaign_id, contributer, 100_000_u32.into())); + assert_ok!(Reward::add_contributor(Origin::signed(hoster), campaign_id, contributor, 100_000_u32.into())); assert_ok!(Reward::lock_campaign(Origin::signed(hoster), campaign_id)); assert_eq!( - Reward::get_contribution(campaign_id, contributer).map(|p| p.status), + Reward::get_contribution(campaign_id, contributor).map(|p| p.status), Some(types::ClaimerStatus::Unprocessed) ); credit_account::(&hoster, 10_000_000_u32.into()); // can claim vesting reward - assert_ok!(Reward::get_vested_reward(Origin::signed(contributer), campaign_id)); + assert_ok!(Reward::get_vested_reward(Origin::signed(contributor), campaign_id)); // cannot call again vesting reward - assert_noop!(Reward::get_vested_reward(Origin::signed(contributer), campaign_id), RewardError::RewardTaken); + assert_noop!(Reward::get_vested_reward(Origin::signed(contributor), campaign_id), RewardError::RewardTaken); // can call instant reward - assert_ok!(Reward::get_instant_reward(Origin::signed(contributer), campaign_id)); + assert_ok!(Reward::get_instant_reward(Origin::signed(contributor), campaign_id)); // cannot call again instant reward - assert_noop!(Reward::get_instant_reward(Origin::signed(contributer), campaign_id), RewardError::RewardTaken); + assert_noop!(Reward::get_instant_reward(Origin::signed(contributor), campaign_id), RewardError::RewardTaken); }); } @@ -545,7 +545,7 @@ fn new_crowdloan_update_sucess() { } #[test] -fn contributer_addition_removal_success() { +fn contributor_addition_removal_success() { new_test_ext().execute_with(|| { run_to_block(1); let campaign_id = 22_u32.into(); @@ -563,46 +563,46 @@ fn contributer_addition_removal_success() { } )); - let contributer_a = 101_u32.into(); - let contributer_b = 102_u32.into(); - let contributer_amount = 1_000_000_u32.into(); - let contributer_unit = types::RewardUnitOf:: { + let contributor_a = 101_u32.into(); + let contributor_b = 102_u32.into(); + let contributor_amount = 1_000_000_u32.into(); + let contributor_unit = types::RewardUnitOf:: { instant_amount: 300_000_u32.into(), vesting_amount: 700_000_u32.into(), per_block: 7_000_u32.into(), status: types::ClaimerStatus::Unprocessed, }; - // add contributer a - assert_ok!(Reward::add_contributer(Origin::signed(hoster), campaign_id, contributer_a, contributer_amount)); - assert_eq!(Reward::get_contribution(campaign_id, contributer_a), Some(contributer_unit.clone())); + // add contributor a + assert_ok!(Reward::add_contributor(Origin::signed(hoster), campaign_id, contributor_a, contributor_amount)); + assert_eq!(Reward::get_contribution(campaign_id, contributor_a), Some(contributor_unit.clone())); assert_eq!( reward_events().last(), Some(&RewardEvent::ContributerAdded { campaign_id, - contributer: contributer_a, - amount: contributer_amount + contributor: contributor_a, + amount: contributor_amount }) ); - // add contributer b - assert_ok!(Reward::add_contributer(Origin::signed(hoster), campaign_id, contributer_b, contributer_amount)); - assert_eq!(Reward::get_contribution(campaign_id, contributer_b), Some(contributer_unit.clone())); + // add contributor b + assert_ok!(Reward::add_contributor(Origin::signed(hoster), campaign_id, contributor_b, contributor_amount)); + assert_eq!(Reward::get_contribution(campaign_id, contributor_b), Some(contributor_unit.clone())); assert_eq!( reward_events().last(), Some(&RewardEvent::ContributerAdded { campaign_id, - contributer: contributer_b, - amount: contributer_amount + contributor: contributor_b, + amount: contributor_amount }) ); - // remove contributer a - assert_ok!(Reward::remove_contributer(Origin::signed(hoster), campaign_id, contributer_a)); - assert_eq!(Reward::get_contribution(campaign_id, contributer_a), None); + // remove contributor a + assert_ok!(Reward::remove_contributor(Origin::signed(hoster), campaign_id, contributor_a)); + assert_eq!(Reward::get_contribution(campaign_id, contributor_a), None); assert_eq!( reward_events().last(), Some(&RewardEvent::ContributerKicked { campaign_id, - contributer: contributer_a + contributor: contributor_a }) ); }); @@ -627,8 +627,8 @@ fn discard_campaign_success() { } )); - // add a contributers - assert_ok!(Reward::add_contributer(Origin::signed(hoster), campaign_id, 22_u32.into(), 100_000)); + // add a contributors + assert_ok!(Reward::add_contributor(Origin::signed(hoster), campaign_id, 22_u32.into(), 100_000)); // attempt to discard assert_ok!(Reward::discard_campaign(Origin::signed(hoster), campaign_id)); @@ -663,15 +663,15 @@ fn lock_campaign_success() { } )); - // add contributers - assert_ok!(Reward::add_contributer(Origin::signed(hoster), campaign_id, 101_u32.into(), 100_000)); - assert_ok!(Reward::add_contributer(Origin::signed(hoster), campaign_id, 102_u32.into(), 100_000)); + // add contributors + assert_ok!(Reward::add_contributor(Origin::signed(hoster), campaign_id, 101_u32.into(), 100_000)); + assert_ok!(Reward::add_contributor(Origin::signed(hoster), campaign_id, 102_u32.into(), 100_000)); // lock the campaign assert_ok!(Reward::lock_campaign(Origin::signed(hoster), campaign_id)); // status should be locked assert_eq!(Reward::get_campaign_status(campaign_id), Some(types::RewardCampaignStatus::Locked)); - // contributer should be as-is + // contributor should be as-is assert_eq!(crate::Contribution::::iter_key_prefix(campaign_id).collect::>(), vec![102, 101]); // event must be deposited assert_eq!(reward_events().last(), Some(&RewardEvent::CampaignLocked(campaign_id))); @@ -697,7 +697,7 @@ fn wipe_campaign_success() { } )); credit_account::(&hoster, 100_000_u32.into()); - assert_ok!(Reward::add_contributer(Origin::signed(hoster), campaign_id, 101_u32.into(), 10_000)); + assert_ok!(Reward::add_contributor(Origin::signed(hoster), campaign_id, 101_u32.into(), 10_000)); assert_ok!(Reward::lock_campaign(Origin::signed(hoster), campaign_id)); assert_ok!(Reward::get_instant_reward(Origin::signed(101_u32.into()), campaign_id)); assert_ok!(Reward::get_vested_reward(Origin::signed(101_u32.into()), campaign_id)); @@ -708,7 +708,7 @@ fn wipe_campaign_success() { assert_eq!(Reward::get_campaign_status(campaign_id), Some(types::RewardCampaignStatus::Wiped)); // should be no info in rewardInfo assert_eq!(Reward::get_reward_info(campaign_id), None); - // contributers should be cleared + // contributors should be cleared assert_eq!(crate::Contribution::::iter_key_prefix(campaign_id).next(), None); // event should be deposited assert_eq!(reward_events().last(), Some(&RewardEvent::CampaignWiped(campaign_id))); @@ -738,9 +738,9 @@ fn hoster_access_control() { // - cannot update the campaign // - cannot discard the campaign // - cannot lock the campaign - // - cannot add contributer - // - cannot remove contributer - // - cannot wipe contributer + // - cannot add contributor + // - cannot remove contributor + // - cannot wipe contributor assert_noop!( Reward::update_campaign(Origin::signed(not_hoster), campaign_id, Default::default()), RewardError::PermissionDenied, @@ -749,11 +749,11 @@ fn hoster_access_control() { assert_noop!(Reward::lock_campaign(Origin::signed(not_hoster), campaign_id), RewardError::PermissionDenied,); assert_noop!(Reward::discard_campaign(Origin::signed(not_hoster), campaign_id), RewardError::PermissionDenied,); assert_noop!( - Reward::add_contributer(Origin::signed(not_hoster), campaign_id, 99_u32.into(), 10_000_u32.into()), + Reward::add_contributor(Origin::signed(not_hoster), campaign_id, 99_u32.into(), 10_000_u32.into()), RewardError::PermissionDenied, ); assert_noop!( - Reward::remove_contributer(Origin::signed(not_hoster), campaign_id, 99_u32.into()), + Reward::remove_contributor(Origin::signed(not_hoster), campaign_id, 99_u32.into()), RewardError::PermissionDenied, ); assert_noop!(Reward::wipe_campaign(Origin::signed(not_hoster), campaign_id), RewardError::PermissionDenied,); diff --git a/pallets/reward-campaign/src/weights.rs b/pallets/reward-campaign/src/weights.rs index e984982..9c492f8 100644 --- a/pallets/reward-campaign/src/weights.rs +++ b/pallets/reward-campaign/src/weights.rs @@ -37,8 +37,8 @@ use sp_std::marker::PhantomData; pub trait WeightInfo { fn start_new_campaign() -> Weight; fn update_campaign() -> Weight; - fn add_contributer() -> Weight; - fn remove_contributer() -> Weight; + fn add_contributor() -> Weight; + fn remove_contributor() -> Weight; fn get_instant_reward() -> Weight; fn get_vested_reward() -> Weight; fn lock_campaign() -> Weight; @@ -70,7 +70,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Reward RewardInfo (r:1 w:0) // Storage: Reward CampaignStatus (r:1 w:0) // Storage: Reward Contribution (r:1 w:1) - fn add_contributer() -> Weight { + fn add_contributor() -> Weight { // Minimum execution time: nanoseconds. Weight::from_ref_time(72_551_000_u64) .saturating_add(T::DbWeight::get().reads(3_u64)) @@ -79,7 +79,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Reward RewardInfo (r:1 w:0) // Storage: Reward CampaignStatus (r:1 w:0) // Storage: Reward Contribution (r:1 w:1) - fn remove_contributer() -> Weight { + fn remove_contributor() -> Weight { // Minimum execution time: nanoseconds. Weight::from_ref_time(71_797_000_u64) .saturating_add(T::DbWeight::get().reads(3_u64)) @@ -157,7 +157,7 @@ impl WeightInfo for () { // Storage: Reward RewardInfo (r:1 w:0) // Storage: Reward CampaignStatus (r:1 w:0) // Storage: Reward Contribution (r:1 w:1) - fn add_contributer() -> Weight { + fn add_contributor() -> Weight { // Minimum execution time: nanoseconds. Weight::from_ref_time(72_551_000_u64) .saturating_add(RocksDbWeight::get().reads(3_u64)) @@ -166,7 +166,7 @@ impl WeightInfo for () { // Storage: Reward RewardInfo (r:1 w:0) // Storage: Reward CampaignStatus (r:1 w:0) // Storage: Reward Contribution (r:1 w:1) - fn remove_contributer() -> Weight { + fn remove_contributor() -> Weight { // Minimum execution time: nanoseconds. Weight::from_ref_time(71_797_000_u64) .saturating_add(RocksDbWeight::get().reads(3_u64))