Browse Source

runtime-modules: Fix tests and benchmarks.

Shamil Gadelshin 4 years ago
parent
commit
693c7c7054

+ 4 - 4
runtime-modules/blog/src/mock.rs

@@ -136,7 +136,7 @@ impl common::working_group::WorkingGroupBudgetHandler<Runtime> for () {
 impl common::working_group::WorkingGroupAuthenticator<Runtime> for () {
     fn ensure_worker_origin(
         _origin: <Runtime as frame_system::Trait>::Origin,
-        _worker_id: &<Runtime as common::Trait>::ActorId,
+        _worker_id: &<Runtime as common::membership::Trait>::ActorId,
     ) -> DispatchResult {
         unimplemented!()
     }
@@ -145,7 +145,7 @@ impl common::working_group::WorkingGroupAuthenticator<Runtime> for () {
         unimplemented!()
     }
 
-    fn get_leader_member_id() -> Option<<Runtime as common::Trait>::MemberId> {
+    fn get_leader_member_id() -> Option<<Runtime as common::membership::Trait>::MemberId> {
         unimplemented!()
     }
 
@@ -155,7 +155,7 @@ impl common::working_group::WorkingGroupAuthenticator<Runtime> for () {
 
     fn is_worker_account_id(
         _: &<Runtime as frame_system::Trait>::AccountId,
-        _worker_id: &<Runtime as common::Trait>::ActorId,
+        _worker_id: &<Runtime as common::membership::Trait>::ActorId,
     ) -> bool {
         unimplemented!();
     }
@@ -282,7 +282,7 @@ impl
     }
 }
 
-impl common::Trait for Runtime {
+impl common::membership::Trait for Runtime {
     type MemberId = u64;
     type ActorId = u64;
 }

+ 12 - 5
runtime-modules/bounty/src/benchmarking.rs

@@ -86,10 +86,8 @@ fn member_funded_account<T: Trait + membership::Trait>(
     let params = membership::BuyMembershipParameters {
         root_account: account_id.clone(),
         controller_account: account_id.clone(),
-        name: None,
         handle: Some(handle),
-        avatar_uri: None,
-        about: None,
+        metadata: Vec::new(),
         referrer_id: None,
     };
 
@@ -396,7 +394,11 @@ benchmarks! {
         assert!(Bounties::<T>::contains_key(bounty_id));
     }: fund_bounty (RawOrigin::Signed(account_id.clone()), BountyActor::Member(member_id), bounty_id, amount)
     verify {
-        assert_eq!(Balances::<T>::usable_balance(&account_id), initial_balance::<T>() - amount);
+        assert_eq!(
+            Balances::<T>::usable_balance(&account_id),
+            // included staking account deposit
+            initial_balance::<T>() - amount - T::CandidateStake::get()
+        );
         assert_last_event::<T>(Event::<T>::BountyMaxFundingReached(bounty_id).into());
     }
 
@@ -473,7 +475,12 @@ benchmarks! {
 
     }: withdraw_funding (RawOrigin::Signed(account_id.clone()), funder, bounty_id)
     verify {
-        assert_eq!(Balances::<T>::usable_balance(&account_id), initial_balance::<T>() + cherry);
+        assert_eq!(
+            Balances::<T>::usable_balance(&account_id),
+            // included staking account deposit
+            initial_balance::<T>() - T::CandidateStake::get() + cherry
+        );
+
         assert_last_event::<T>(Event::<T>::BountyRemoved(bounty_id).into());
     }
 

+ 16 - 5
runtime-modules/bounty/src/tests/mocks.rs

@@ -224,15 +224,22 @@ impl common::membership::MemberOriginValidator<Origin, u64, u128> for () {
 parameter_types! {
     pub const DefaultMembershipPrice: u64 = 100;
     pub const InvitedMemberLockId: [u8; 8] = [2; 8];
+    pub const ReferralCutMaximumPercent: u8 = 50;
+    pub const MinimumStakeForOpening: u32 = 50;
+    pub const MinimumApplicationStake: u32 = 50;
+    pub const LeaderOpeningStake: u32 = 20;
+    pub const StakingCandidateLockId: [u8; 8] = [3; 8];
+    pub const DefaultInitialInvitationBalance: u64 = 100;
+    pub const CandidateStake: u64 = 130;
 }
 
 // Weights info stub
 pub struct Weights;
 impl membership::WeightInfo for Weights {
-    fn buy_membership_without_referrer(_: u32, _: u32, _: u32, _: u32) -> Weight {
+    fn buy_membership_without_referrer(_: u32, _: u32) -> Weight {
         unimplemented!()
     }
-    fn buy_membership_with_referrer(_: u32, _: u32, _: u32, _: u32) -> Weight {
+    fn buy_membership_with_referrer(_: u32, _: u32) -> Weight {
         unimplemented!()
     }
     fn update_profile(_: u32) -> Weight {
@@ -256,7 +263,7 @@ impl membership::WeightInfo for Weights {
     fn transfer_invites() -> Weight {
         unimplemented!()
     }
-    fn invite_member(_: u32, _: u32, _: u32, _: u32) -> Weight {
+    fn invite_member(_: u32, _: u32) -> Weight {
         unimplemented!()
     }
     fn set_membership_price() -> Weight {
@@ -295,10 +302,14 @@ impl pallet_timestamp::Trait for Test {
 impl membership::Trait for Test {
     type Event = TestEvent;
     type DefaultMembershipPrice = DefaultMembershipPrice;
+    type ReferralCutMaximumPercent = ReferralCutMaximumPercent;
     type WorkingGroup = ();
-    type WeightInfo = Weights;
-    type DefaultInitialInvitationBalance = ();
+    type DefaultInitialInvitationBalance = DefaultInitialInvitationBalance;
     type InvitedMemberStakingHandler = staking_handler::StakingManager<Self, InvitedMemberLockId>;
+    type StakingCandidateStakingHandler =
+        staking_handler::StakingManager<Self, StakingCandidateLockId>;
+    type WeightInfo = Weights;
+    type CandidateStake = CandidateStake;
 }
 
 impl LockComparator<<Test as balances::Trait>::Balance> for Test {

+ 1 - 1
runtime-modules/forum/src/benchmarking.rs

@@ -147,7 +147,7 @@ where
     )
     .unwrap();
 
-    let actor_id = <T as common::Trait>::ActorId::from(id.try_into().unwrap());
+    let actor_id = <T as common::membership::Trait>::ActorId::from(id.try_into().unwrap());
     assert!(WorkerById::<T, ForumWorkingGroupInstance>::contains_key(
         actor_id
     ));

+ 1 - 1
runtime-modules/forum/src/mock.rs

@@ -360,7 +360,7 @@ impl Trait for Runtime {
     type WeightInfo = ();
 }
 
-impl common::membership::MemberOriginValidator<Origin, u64, u128> for () {
+impl common::membership::MemberOriginValidator<Origin, u128, u128> for () {
     fn ensure_member_controller_account_origin(
         origin: Origin,
         member_id: u128,

+ 6 - 6
runtime-modules/utility/src/tests/mocks.rs

@@ -254,7 +254,7 @@ impl common::working_group::WorkingGroupBudgetHandler<Test> for () {
 impl common::working_group::WorkingGroupAuthenticator<Test> for () {
     fn ensure_worker_origin(
         _origin: <Test as frame_system::Trait>::Origin,
-        _worker_id: &<Test as common::Trait>::ActorId,
+        _worker_id: &<Test as common::membership::Trait>::ActorId,
     ) -> DispatchResult {
         unimplemented!();
     }
@@ -263,7 +263,7 @@ impl common::working_group::WorkingGroupAuthenticator<Test> for () {
         unimplemented!()
     }
 
-    fn get_leader_member_id() -> Option<<Test as common::Trait>::MemberId> {
+    fn get_leader_member_id() -> Option<<Test as common::membership::Trait>::MemberId> {
         unimplemented!();
     }
 
@@ -273,7 +273,7 @@ impl common::working_group::WorkingGroupAuthenticator<Test> for () {
 
     fn is_worker_account_id(
         _account_id: &<Test as frame_system::Trait>::AccountId,
-        _worker_id: &<Test as common::Trait>::ActorId,
+        _worker_id: &<Test as common::membership::Trait>::ActorId,
     ) -> bool {
         unimplemented!()
     }
@@ -699,7 +699,7 @@ impl common::StakingAccountValidator<Test> for () {
     }
 }
 
-impl common::origin::MemberOriginValidator<Origin, u64, u64> for () {
+impl common::membership::MemberOriginValidator<Origin, u64, u64> for () {
     fn ensure_member_controller_account_origin(
         origin: Origin,
         _: u64,
@@ -714,7 +714,7 @@ impl common::origin::MemberOriginValidator<Origin, u64, u64> for () {
     }
 }
 
-impl common::origin::CouncilOriginValidator<Origin, u64, u64> for () {
+impl common::council::CouncilOriginValidator<Origin, u64, u64> for () {
     fn ensure_member_consulate(origin: Origin, _: u64) -> DispatchResult {
         frame_system::ensure_signed(origin)?;
 
@@ -722,7 +722,7 @@ impl common::origin::CouncilOriginValidator<Origin, u64, u64> for () {
     }
 }
 
-impl common::Trait for Test {
+impl common::membership::Trait for Test {
     type MemberId = u64;
     type ActorId = u64;
 }