Skip to content

Commit

Permalink
Merge branch 'main' into feature/rmrk-pallet
Browse files Browse the repository at this point in the history
  • Loading branch information
sudipghimire533 committed Mar 28, 2023
2 parents ca39ade + 20b5869 commit 69c15ef
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 167 deletions.
58 changes: 29 additions & 29 deletions pallets/reward-campaign/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ benchmarks! {
);
}

add_contributer {
let contributer = make_account::<T>(22);
add_contributor {
let contributor = make_account::<T>(22);
let caller = make_account::<T>(1);
let campaign_id: types::CampaignIdOf<T> = 2_u32.into();
let amount: types::BalanceOf<T> = Bounded::max_value();
Expand All @@ -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::<T>::get_contribution(campaign_id, contributer).is_some()
CampaignReward::<T>::get_contribution(campaign_id, contributor).is_some()
);
}

remove_contributer {
let contributer = make_account::<T>(22);
remove_contributor {
let contributor = make_account::<T>(22);
let caller = make_account::<T>(1);
let campaign_id: types::CampaignIdOf<T> = 2_u32.into();
let params = types::CreateCampaignParamFor::<T> {
Expand All @@ -138,25 +138,25 @@ benchmarks! {
)
);
assert_ok!(
CampaignReward::<T>::add_contributer(RawOrigin::Signed(caller.clone()).into(),
CampaignReward::<T>::add_contributor(RawOrigin::Signed(caller.clone()).into(),
campaign_id,
contributer.clone(),
contributor.clone(),
Bounded::max_value(),
)
);
assert!(
CampaignReward::<T>::get_contribution::<_, types::AccountIdOf<T>>(campaign_id, contributer.clone()).is_some(),
CampaignReward::<T>::get_contribution::<_, types::AccountIdOf<T>>(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::<T>::get_contribution::<_, types::AccountIdOf<T>>(campaign_id, contributer.clone()),
CampaignReward::<T>::get_contribution::<_, types::AccountIdOf<T>>(campaign_id, contributor.clone()),
None,
);
}

get_instant_reward {
let contributer = make_account::<T>(22);
let contributor = make_account::<T>(22);
let caller = make_account::<T>(1);
let campaign_id: types::CampaignIdOf<T> = 10_u32.into();
let params = types::CreateCampaignParamFor::<T> {
Expand All @@ -175,26 +175,26 @@ benchmarks! {
)
);
assert_ok!(
CampaignReward::<T>::add_contributer(RawOrigin::Signed(caller.clone()).into(),
CampaignReward::<T>::add_contributor(RawOrigin::Signed(caller.clone()).into(),
campaign_id,
contributer.clone(),
contributor.clone(),
( DHX_UNIT * 5 ).into(),
)
);
assert_ok!(
CampaignReward::<T>::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::<T>::get_contribution(campaign_id, contributer.clone())
CampaignReward::<T>::get_contribution(campaign_id, contributor.clone())
.map(|p| p.status),
Some(types::ClaimerStatus::DoneInstant)
);
}

get_vested_reward {
let contributer = make_account::<T>(22);
let contributor = make_account::<T>(22);
let caller = make_account::<T>(1);
let campaign_id: types::CampaignIdOf<T> = 10_u32.into();
let params = types::CreateCampaignParamFor::<T> {
Expand All @@ -213,19 +213,19 @@ benchmarks! {
)
);
assert_ok!(
CampaignReward::<T>::add_contributer(RawOrigin::Signed(caller.clone()).into(),
CampaignReward::<T>::add_contributor(RawOrigin::Signed(caller.clone()).into(),
campaign_id,
contributer.clone(),
contributor.clone(),
<types::BalanceOf<T> as Bounded>::max_value() - 10_000_000_u32.into(),
)
);
assert_ok!(
CampaignReward::<T>::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::<T>::get_contribution(campaign_id, contributer.clone())
CampaignReward::<T>::get_contribution(campaign_id, contributor.clone())
.map(|p| p.status),
Some(types::ClaimerStatus::DoneVesting)
);
Expand All @@ -248,11 +248,11 @@ benchmarks! {
)
);

for contributer in 0_u32 .. 10_u32 {
for contributor in 0_u32 .. 10_u32 {
assert_ok!(
CampaignReward::<T>::add_contributer(RawOrigin::Signed(caller.clone()).into(),
CampaignReward::<T>::add_contributor(RawOrigin::Signed(caller.clone()).into(),
campaign_id.into(),
make_account::<T>(contributer),
make_account::<T>(contributor),
( DHX_UNIT * 5 ).into()
)
);
Expand All @@ -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<T> = 3_u32.into();
Expand All @@ -285,8 +285,8 @@ benchmarks! {
)
);

for contributer in 0_u32 .. 10_u32 {
crate::Contribution::<T>::insert(campaign_id.clone(), make_account::<T>(contributer), types::RewardUnitOf::<T> {
for contributor in 0_u32 .. 10_u32 {
crate::Contribution::<T>::insert(campaign_id.clone(), make_account::<T>(contributor), types::RewardUnitOf::<T> {
instant_amount: 10_000_u32.into(),
vesting_amount: 10_000_u32.into(),
per_block: 100_000_u32.into(),
Expand Down Expand Up @@ -320,8 +320,8 @@ benchmarks! {
)
);

for contributer in 0_u32 .. 10_u32 {
crate::Contribution::<T>::insert(campaign_id.clone(), make_account::<T>(contributer), types::RewardUnitOf::<T> {
for contributor in 0_u32 .. 10_u32 {
crate::Contribution::<T>::insert(campaign_id.clone(), make_account::<T>(contributor), types::RewardUnitOf::<T> {
instant_amount: 10_000_u32.into(),
vesting_amount: 10_000_u32.into(),
per_block: 100_000_u32.into(),
Expand Down
8 changes: 4 additions & 4 deletions pallets/reward-campaign/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BlockNumber, Balance> {
Expand All @@ -32,7 +32,7 @@ pub struct SplitableAmount<BlockNumber, Balance> {
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<Balance> {
Expand Down Expand Up @@ -144,8 +144,8 @@ pub fn do_vesting_reward<T: crate::Config>(
let vesting_info = types::VestingInfoOf::<T>::new(vesting_amount, per_block, starts_from);

let creditor_origin = <T as frame_system::Config>::Origin::from(frame_system::RawOrigin::Signed(reward_source));
let contributer_lookup = <T::Lookup as StaticLookup>::unlookup(user);
let contributor_lookup = <T::Lookup as StaticLookup>::unlookup(user);

pallet_vesting::Pallet::<T>::vested_transfer(creditor_origin, contributer_lookup, vesting_info)
pallet_vesting::Pallet::<T>::vested_transfer(creditor_origin, contributor_lookup, vesting_info)
}
}
Loading

0 comments on commit 69c15ef

Please sign in to comment.