mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 08:11:03 +00:00
Improve call, and usage in pallet utility (#9418)
* WIP * WIP * WIP * add some tests and limit * remove wip test * fmt * Update bin/node/runtime/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * fmt * use primitives allocation limit Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
27d4177f93
commit
38db14089b
@@ -34,7 +34,7 @@ use sp_runtime::{
|
||||
traits::TrailingZeroInput,
|
||||
DispatchError, SaturatedConversion,
|
||||
};
|
||||
use sp_std::{cmp::Ordering, convert::TryFrom, vec::Vec};
|
||||
use sp_std::{boxed::Box, cmp::Ordering, convert::TryFrom, vec::Vec};
|
||||
|
||||
/// Storage key used to store the last block number at which offchain worker ran.
|
||||
pub(crate) const OFFCHAIN_LAST_BLOCK: &[u8] = b"parity/multi-phase-unsigned-election";
|
||||
@@ -208,7 +208,7 @@ impl<T: Config> Pallet<T> {
|
||||
let (raw_solution, witness) = Self::mine_and_check(iters)?;
|
||||
|
||||
let score = raw_solution.score.clone();
|
||||
let call: Call<T> = Call::submit_unsigned(raw_solution, witness).into();
|
||||
let call: Call<T> = Call::submit_unsigned(Box::new(raw_solution), witness).into();
|
||||
|
||||
log!(
|
||||
debug,
|
||||
@@ -773,7 +773,7 @@ mod tests {
|
||||
fn validate_unsigned_retracts_wrong_phase() {
|
||||
ExtBuilder::default().desired_targets(0).build_and_execute(|| {
|
||||
let solution = RawSolution::<TestCompact> { score: [5, 0, 0], ..Default::default() };
|
||||
let call = Call::submit_unsigned(solution.clone(), witness());
|
||||
let call = Call::submit_unsigned(Box::new(solution.clone()), witness());
|
||||
|
||||
// initial
|
||||
assert_eq!(MultiPhase::current_phase(), Phase::Off);
|
||||
@@ -842,7 +842,7 @@ mod tests {
|
||||
assert!(MultiPhase::current_phase().is_unsigned());
|
||||
|
||||
let solution = RawSolution::<TestCompact> { score: [5, 0, 0], ..Default::default() };
|
||||
let call = Call::submit_unsigned(solution.clone(), witness());
|
||||
let call = Call::submit_unsigned(Box::new(solution.clone()), witness());
|
||||
|
||||
// initial
|
||||
assert!(<MultiPhase as ValidateUnsigned>::validate_unsigned(
|
||||
@@ -879,7 +879,7 @@ mod tests {
|
||||
assert!(MultiPhase::current_phase().is_unsigned());
|
||||
|
||||
let solution = RawSolution::<TestCompact> { score: [5, 0, 0], ..Default::default() };
|
||||
let call = Call::submit_unsigned(solution.clone(), witness());
|
||||
let call = Call::submit_unsigned(Box::new(solution.clone()), witness());
|
||||
assert_eq!(solution.compact.unique_targets().len(), 0);
|
||||
|
||||
// won't work anymore.
|
||||
@@ -905,7 +905,7 @@ mod tests {
|
||||
|
||||
let solution =
|
||||
RawSolution::<TestCompact> { score: [5, 0, 0], ..Default::default() };
|
||||
let call = Call::submit_unsigned(solution.clone(), witness());
|
||||
let call = Call::submit_unsigned(Box::new(solution.clone()), witness());
|
||||
|
||||
assert_eq!(
|
||||
<MultiPhase as ValidateUnsigned>::validate_unsigned(
|
||||
@@ -931,7 +931,7 @@ mod tests {
|
||||
|
||||
// This is in itself an invalid BS solution.
|
||||
let solution = RawSolution::<TestCompact> { score: [5, 0, 0], ..Default::default() };
|
||||
let call = Call::submit_unsigned(solution.clone(), witness());
|
||||
let call = Call::submit_unsigned(Box::new(solution.clone()), witness());
|
||||
let outer_call: OuterCall = call.into();
|
||||
let _ = outer_call.dispatch(Origin::none());
|
||||
})
|
||||
@@ -951,7 +951,7 @@ mod tests {
|
||||
let mut correct_witness = witness();
|
||||
correct_witness.voters += 1;
|
||||
correct_witness.targets -= 1;
|
||||
let call = Call::submit_unsigned(solution.clone(), correct_witness);
|
||||
let call = Call::submit_unsigned(Box::new(solution.clone()), correct_witness);
|
||||
let outer_call: OuterCall = call.into();
|
||||
let _ = outer_call.dispatch(Origin::none());
|
||||
})
|
||||
@@ -972,7 +972,7 @@ mod tests {
|
||||
|
||||
// ensure this solution is valid.
|
||||
assert!(MultiPhase::queued_solution().is_none());
|
||||
assert_ok!(MultiPhase::submit_unsigned(Origin::none(), solution, witness));
|
||||
assert_ok!(MultiPhase::submit_unsigned(Origin::none(), Box::new(solution), witness));
|
||||
assert!(MultiPhase::queued_solution().is_some());
|
||||
})
|
||||
}
|
||||
@@ -1054,7 +1054,11 @@ mod tests {
|
||||
};
|
||||
let (solution, witness) = MultiPhase::prepare_election_result(result).unwrap();
|
||||
assert_ok!(MultiPhase::unsigned_pre_dispatch_checks(&solution));
|
||||
assert_ok!(MultiPhase::submit_unsigned(Origin::none(), solution, witness));
|
||||
assert_ok!(MultiPhase::submit_unsigned(
|
||||
Origin::none(),
|
||||
Box::new(solution),
|
||||
witness
|
||||
));
|
||||
assert_eq!(MultiPhase::queued_solution().unwrap().score[0], 10);
|
||||
|
||||
// trial 1: a solution who's score is only 2, i.e. 20% better in the first element.
|
||||
@@ -1096,7 +1100,11 @@ mod tests {
|
||||
|
||||
// and it is fine
|
||||
assert_ok!(MultiPhase::unsigned_pre_dispatch_checks(&solution));
|
||||
assert_ok!(MultiPhase::submit_unsigned(Origin::none(), solution, witness));
|
||||
assert_ok!(MultiPhase::submit_unsigned(
|
||||
Origin::none(),
|
||||
Box::new(solution),
|
||||
witness
|
||||
));
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user