Browse Source

Merge pull request #3064 from shamil-gadelshin/bounty-oracle-rationale

Olympia runtime: add oracle rationale on bounty judgments.
shamil-gadelshin 3 years ago
parent
commit
1e723d0ec3

+ 26 - 11
runtime-modules/bounty/src/benchmarking.rs

@@ -673,6 +673,7 @@ benchmarks! {
         let funding_amount: BalanceOf<T> = 10000000u32.into();
         let oracle = BountyActor::Council;
         let entrant_stake: BalanceOf<T> = T::MinWorkEntrantStake::get();
+        let rationale = b"text".to_vec();
 
         let params = BountyCreationParameters::<T> {
             work_period,
@@ -709,7 +710,12 @@ benchmarks! {
 
         run_to_block::<T>((work_period + One::one()).into());
 
-    }: submit_oracle_judgment(RawOrigin::Root, oracle.clone(), bounty_id, judgment.clone())
+    }: submit_oracle_judgment(
+        RawOrigin::Root,
+        oracle.clone(),
+        bounty_id,
+        judgment.clone(),
+        rationale.clone())
     verify {
         for entry_id in entry_ids {
             let entry = Bounty::<T>::entries(entry_id);
@@ -724,7 +730,7 @@ benchmarks! {
             );
         }
         assert_last_event::<T>(
-            Event::<T>::OracleJudgmentSubmitted(bounty_id, oracle, judgment).into()
+            Event::<T>::OracleJudgmentSubmitted(bounty_id, oracle, judgment, rationale).into()
         );
     }
 
@@ -736,6 +742,7 @@ benchmarks! {
         let funding_amount: BalanceOf<T> = 100u32.into();
         let oracle = BountyActor::Council;
         let entrant_stake: BalanceOf<T> = T::MinWorkEntrantStake::get();
+        let rationale = b"text".to_vec();
 
         let params = BountyCreationParameters::<T> {
             work_period,
@@ -761,13 +768,18 @@ benchmarks! {
 
         run_to_block::<T>((work_period + One::one()).into());
 
-    }: submit_oracle_judgment(RawOrigin::Root, oracle.clone(), bounty_id, judgment.clone())
+    }: submit_oracle_judgment(
+        RawOrigin::Root,
+        oracle.clone(),
+        bounty_id,
+        judgment.clone(),
+        rationale.clone())
     verify {
         for entry_id in entry_ids {
             assert!(!<Entries<T>>::contains_key(entry_id));
         }
         assert_last_event::<T>(
-            Event::<T>::OracleJudgmentSubmitted(bounty_id, oracle, judgment).into()
+            Event::<T>::OracleJudgmentSubmitted(bounty_id, oracle, judgment, rationale).into()
         );
     }
 
@@ -781,6 +793,7 @@ benchmarks! {
         let (oracle_account_id, oracle_member_id) = member_funded_account::<T>("oracle", 1);
         let oracle = BountyActor::Member(oracle_member_id);
         let entrant_stake: BalanceOf<T> = T::MinWorkEntrantStake::get();
+        let rationale = b"text".to_vec();
 
         let params = BountyCreationParameters::<T> {
             work_period,
@@ -821,8 +834,8 @@ benchmarks! {
         RawOrigin::Signed(oracle_account_id),
         oracle.clone(),
         bounty_id,
-        judgment.clone()
-    )
+        judgment.clone(),
+        rationale.clone())
     verify {
         for entry_id in entry_ids {
             let entry = Bounty::<T>::entries(entry_id);
@@ -837,7 +850,7 @@ benchmarks! {
             );
         }
         assert_last_event::<T>(
-            Event::<T>::OracleJudgmentSubmitted(bounty_id, oracle, judgment).into()
+            Event::<T>::OracleJudgmentSubmitted(bounty_id, oracle, judgment, rationale).into()
         );
     }
 
@@ -851,6 +864,7 @@ benchmarks! {
         let (oracle_account_id, oracle_member_id) = member_funded_account::<T>("oracle", 1);
         let oracle = BountyActor::Member(oracle_member_id);
         let entrant_stake: BalanceOf<T> = T::MinWorkEntrantStake::get();
+        let rationale = b"text".to_vec();
 
         let params = BountyCreationParameters::<T> {
             work_period,
@@ -880,14 +894,14 @@ benchmarks! {
         RawOrigin::Signed(oracle_account_id),
         oracle.clone(),
         bounty_id,
-        judgment.clone()
-    )
+        judgment.clone(),
+        rationale.clone())
     verify {
         for entry_id in entry_ids {
             assert!(!<Entries<T>>::contains_key(entry_id));
         }
         assert_last_event::<T>(
-            Event::<T>::OracleJudgmentSubmitted(bounty_id, oracle, judgment).into()
+            Event::<T>::OracleJudgmentSubmitted(bounty_id, oracle, judgment, rationale).into()
         );
     }
 
@@ -947,7 +961,8 @@ benchmarks! {
             RawOrigin::Signed(oracle_account_id).into(),
             oracle.clone(),
             bounty_id,
-            judgment.clone()
+            judgment.clone(),
+            Vec::new(),
         ).unwrap();
 
     }: _ (RawOrigin::Signed(work_account_id), work_member_id, bounty_id, entry_id)

+ 10 - 3
runtime-modules/bounty/src/lib.rs

@@ -571,7 +571,8 @@ decl_event! {
         /// - bounty ID
         /// - oracle
         /// - judgment data
-        OracleJudgmentSubmitted(BountyId, BountyActor<MemberId>, OracleJudgment),
+        /// - rationale
+        OracleJudgmentSubmitted(BountyId, BountyActor<MemberId>, OracleJudgment, Vec<u8>),
 
         /// Work entry was slashed.
         /// Params:
@@ -1123,7 +1124,8 @@ decl_module! {
             origin,
             oracle: BountyActor<MemberId<T>>,
             bounty_id: T::BountyId,
-            judgment: OracleJudgment<T::EntryId, BalanceOf<T>>
+            judgment: OracleJudgment<T::EntryId, BalanceOf<T>>,
+            rationale: Vec<u8>,
         ) {
             let bounty_oracle_manager = BountyActorManager::<T>::ensure_bounty_actor_manager(
                 origin,
@@ -1180,7 +1182,12 @@ decl_module! {
             }
 
             // Fire a judgment event.
-            Self::deposit_event(RawEvent::OracleJudgmentSubmitted(bounty_id, oracle, judgment));
+            Self::deposit_event(RawEvent::OracleJudgmentSubmitted(
+                bounty_id,
+                oracle,
+                judgment,
+                rationale,
+            ));
         }
 
         /// Withdraw work entrant funds.

+ 7 - 0
runtime-modules/bounty/src/tests/fixtures.rs

@@ -700,6 +700,7 @@ pub struct SubmitJudgmentFixture {
     bounty_id: u64,
     oracle: BountyActor<u64>,
     judgment: OracleJudgmentOf<Test>,
+    rationale: Vec<u8>,
 }
 
 impl SubmitJudgmentFixture {
@@ -709,6 +710,7 @@ impl SubmitJudgmentFixture {
             bounty_id: 1,
             oracle: BountyActor::Council,
             judgment: Default::default(),
+            rationale: Default::default(),
         }
     }
 
@@ -731,6 +733,10 @@ impl SubmitJudgmentFixture {
         Self { judgment, ..self }
     }
 
+    pub fn with_rationale(self, rationale: Vec<u8>) -> Self {
+        Self { rationale, ..self }
+    }
+
     pub fn call_and_assert(&self, expected_result: DispatchResult) {
         let old_bounty = Bounty::bounties(self.bounty_id);
         let actual_result = Bounty::submit_oracle_judgment(
@@ -738,6 +744,7 @@ impl SubmitJudgmentFixture {
             self.oracle.clone(),
             self.bounty_id,
             self.judgment.clone(),
+            self.rationale.clone(),
         );
 
         assert_eq!(actual_result, expected_result);

+ 6 - 0
runtime-modules/bounty/src/tests/mod.rs

@@ -2453,6 +2453,7 @@ fn submit_judgment_by_council_succeeded_with_complex_judgment() {
         let entrant_stake = 37;
         let working_period = 10;
         let judging_period = 10;
+        let rationale = b"text".to_vec();
 
         set_council_budget(initial_balance);
 
@@ -2560,6 +2561,7 @@ fn submit_judgment_by_council_succeeded_with_complex_judgment() {
         SubmitJudgmentFixture::default()
             .with_bounty_id(bounty_id)
             .with_judgment(judgment.clone())
+            .with_rationale(rationale.clone())
             .call_and_assert(Ok(()));
 
         assert_eq!(
@@ -2578,6 +2580,7 @@ fn submit_judgment_by_council_succeeded_with_complex_judgment() {
             bounty_id,
             BountyActor::Council,
             judgment,
+            rationale,
         ));
     });
 }
@@ -2760,6 +2763,7 @@ fn submit_judgment_by_member_succeeded() {
         let judging_period = 10;
         let oracle_member_id = 1;
         let oracle_account_id = 1;
+        let rationale = b"text".to_vec();
 
         set_council_budget(initial_balance);
 
@@ -2818,12 +2822,14 @@ fn submit_judgment_by_member_succeeded() {
             .with_origin(RawOrigin::Signed(oracle_account_id))
             .with_oracle_member_id(oracle_member_id)
             .with_judgment(judgment.clone())
+            .with_rationale(rationale.clone())
             .call_and_assert(Ok(()));
 
         EventFixture::assert_last_crate_event(RawEvent::OracleJudgmentSubmitted(
             bounty_id,
             BountyActor::Member(oracle_member_id),
             judgment,
+            rationale,
         ));
     });
 }