mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 06:08:00 +00:00
Enable Offchain Equalise (#5683)
* Master.into() * Remove debug stuff * Better license * Migrate away from SimpleDispatchInfo * Fix test * Revert "Migrate away from SimpleDispatchInfo" This reverts commit dbdd27fa19948f16bd17defdc01d3dd32986df11. * Move to offchain randomness * Fix tests * Fix tests more
This commit is contained in:
@@ -2901,8 +2901,8 @@ mod offchain_phragmen {
|
||||
|
||||
#[test]
|
||||
fn signed_result_can_be_submitted() {
|
||||
// should check that we have a new validator set normally,
|
||||
// event says that it comes from offchain.
|
||||
// should check that we have a new validator set normally, event says that it comes from
|
||||
// offchain.
|
||||
ExtBuilder::default()
|
||||
.offchain_phragmen_ext()
|
||||
.build()
|
||||
@@ -2989,8 +2989,8 @@ mod offchain_phragmen {
|
||||
|
||||
#[test]
|
||||
fn early_solution_submission_is_rejected() {
|
||||
// should check that we have a new validator set normally,
|
||||
// event says that it comes from offchain.
|
||||
// should check that we have a new validator set normally, event says that it comes from
|
||||
// offchain.
|
||||
ExtBuilder::default()
|
||||
.offchain_phragmen_ext()
|
||||
.build()
|
||||
@@ -3119,7 +3119,7 @@ mod offchain_phragmen {
|
||||
&inner,
|
||||
),
|
||||
TransactionValidity::Ok(ValidTransaction {
|
||||
priority: (1 << 20) + 1125, // the proposed slot stake.
|
||||
priority: UnsignedPriority::get() + 1125, // the proposed slot stake.
|
||||
requires: vec![],
|
||||
provides: vec![("StakingOffchain", current_era()).encode()],
|
||||
longevity: 3,
|
||||
@@ -3129,6 +3129,50 @@ mod offchain_phragmen {
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn offchain_worker_runs_with_equalise() {
|
||||
// Offchain worker equalises based on the number provided by randomness. See the difference
|
||||
// in the priority, which comes from the computed score.
|
||||
let mut ext = ExtBuilder::default()
|
||||
.offchain_phragmen_ext()
|
||||
.validator_count(2)
|
||||
.max_offchain_iterations(2)
|
||||
.build();
|
||||
let state = offchainify(&mut ext);
|
||||
ext.execute_with(|| {
|
||||
run_to_block(12);
|
||||
|
||||
// local key 11 is in the elected set.
|
||||
assert_eq_uvec!(Session::validators(), vec![11, 21]);
|
||||
assert_eq!(state.read().transactions.len(), 0);
|
||||
Staking::offchain_worker(12);
|
||||
assert_eq!(state.read().transactions.len(), 1);
|
||||
|
||||
let encoded = state.read().transactions[0].clone();
|
||||
let extrinsic: Extrinsic = Decode::decode(&mut &*encoded).unwrap();
|
||||
|
||||
let call = extrinsic.call;
|
||||
let inner = match call {
|
||||
mock::Call::Staking(inner) => inner,
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
<Staking as sp_runtime::traits::ValidateUnsigned>::validate_unsigned(
|
||||
TransactionSource::Local,
|
||||
&inner,
|
||||
),
|
||||
TransactionValidity::Ok(ValidTransaction {
|
||||
// the proposed slot stake, with equalize.
|
||||
priority: UnsignedPriority::get() + 1250,
|
||||
requires: vec![],
|
||||
provides: vec![("StakingOffchain", active_era()).encode()],
|
||||
longevity: 3,
|
||||
propagate: false,
|
||||
})
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mediocre_submission_from_authority_is_early_rejected() {
|
||||
let mut ext = ExtBuilder::default()
|
||||
|
||||
Reference in New Issue
Block a user