mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 17:31:03 +00:00
* Fix keystore types * Use SyncCryptoStorePtr * Borrow keystore * Fix unused imports * Fix polkadot service * Fix bitfield-distribution tests * Fix indentation * Fix backing tests * Fix tests * Fix provisioner tests * Removed SyncCryptoStorePtr * Fix services * Address PR feedback * Address PR feedback - 2 * Update CryptoStorePtr imports to be from sp_keystore * Typo * Fix CryptoStore import * Document the reason behind using filesystem keystore * Remove VALIDATORS * Fix duplicate dependency * Mark sp-keystore as optional * Fix availability distribution * Fix call to sign_with * Fix keystore usage * Remove tokio and fix parachains Cargo config * Typos * Fix keystore dereferencing * Fix CryptoStore import * Fix provisioner * Fix node backing * Update services * Cleanup dependencies * Use sync_keystore * Fix node service * Fix node service - 2 * Fix node service - 3 * Rename CryptoStorePtr to SyncCryptoStorePtr * "Update Substrate" * Apply suggestions from code review * Update node/core/backing/Cargo.toml * Update primitives/src/v0.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Fix wasm build * Update Cargo.lock Co-authored-by: parity-processbot <> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -549,36 +549,37 @@ mod tests {
|
||||
mod select_availability_bitfields {
|
||||
use super::super::*;
|
||||
use super::{default_bitvec, occupied_core};
|
||||
use lazy_static::lazy_static;
|
||||
use polkadot_primitives::v1::{SigningContext, ValidatorIndex, ValidatorPair};
|
||||
use sp_core::crypto::Pair;
|
||||
use std::sync::Mutex;
|
||||
use futures::executor::block_on;
|
||||
use std::sync::Arc;
|
||||
use polkadot_primitives::v1::{SigningContext, ValidatorIndex, ValidatorId};
|
||||
use sp_application_crypto::AppKey;
|
||||
use sp_keystore::{CryptoStore, SyncCryptoStorePtr};
|
||||
use sc_keystore::LocalKeystore;
|
||||
|
||||
lazy_static! {
|
||||
// we can use a normal mutex here, not a futures-aware one, because we don't use any futures-based
|
||||
// concurrency when accessing this. The risk of contention is that multiple tests are run in parallel,
|
||||
// in independent threads, in which case a standard mutex suffices.
|
||||
static ref VALIDATORS: Mutex<HashMap<ValidatorIndex, ValidatorPair>> = Mutex::new(HashMap::new());
|
||||
}
|
||||
|
||||
fn signed_bitfield(
|
||||
async fn signed_bitfield(
|
||||
keystore: &SyncCryptoStorePtr,
|
||||
field: CoreAvailability,
|
||||
validator_idx: ValidatorIndex,
|
||||
) -> SignedAvailabilityBitfield {
|
||||
let mut lock = VALIDATORS.lock().unwrap();
|
||||
let validator = lock
|
||||
.entry(validator_idx)
|
||||
.or_insert_with(|| ValidatorPair::generate().0);
|
||||
let public = CryptoStore::sr25519_generate_new(&**keystore, ValidatorId::ID, None)
|
||||
.await
|
||||
.expect("generated sr25519 key");
|
||||
SignedAvailabilityBitfield::sign(
|
||||
&keystore,
|
||||
field.into(),
|
||||
&<SigningContext<Hash>>::default(),
|
||||
validator_idx,
|
||||
validator,
|
||||
)
|
||||
&public.into(),
|
||||
).await.expect("Should be signed")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_more_than_one_per_validator() {
|
||||
// Configure filesystem-based keystore as generating keys without seed
|
||||
// would trigger the key to be generated on the filesystem.
|
||||
let keystore_path = tempfile::tempdir().expect("Creates keystore path");
|
||||
let keystore : SyncCryptoStorePtr = Arc::new(LocalKeystore::open(keystore_path.path(), None)
|
||||
.expect("Creates keystore"));
|
||||
let bitvec = default_bitvec();
|
||||
|
||||
let cores = vec![occupied_core(0), occupied_core(1)];
|
||||
@@ -586,9 +587,9 @@ mod tests {
|
||||
// we pass in three bitfields with two validators
|
||||
// this helps us check the postcondition that we get two bitfields back, for which the validators differ
|
||||
let bitfields = vec![
|
||||
signed_bitfield(bitvec.clone(), 0),
|
||||
signed_bitfield(bitvec.clone(), 1),
|
||||
signed_bitfield(bitvec, 1),
|
||||
block_on(signed_bitfield(&keystore, bitvec.clone(), 0)),
|
||||
block_on(signed_bitfield(&keystore, bitvec.clone(), 1)),
|
||||
block_on(signed_bitfield(&keystore, bitvec, 1)),
|
||||
];
|
||||
|
||||
let mut selected_bitfields = select_availability_bitfields(&cores, &bitfields);
|
||||
@@ -602,14 +603,19 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn each_corresponds_to_an_occupied_core() {
|
||||
// Configure filesystem-based keystore as generating keys without seed
|
||||
// would trigger the key to be generated on the filesystem.
|
||||
let keystore_path = tempfile::tempdir().expect("Creates keystore path");
|
||||
let keystore : SyncCryptoStorePtr = Arc::new(LocalKeystore::open(keystore_path.path(), None)
|
||||
.expect("Creates keystore"));
|
||||
let bitvec = default_bitvec();
|
||||
|
||||
let cores = vec![CoreState::Free, CoreState::Scheduled(Default::default())];
|
||||
|
||||
let bitfields = vec![
|
||||
signed_bitfield(bitvec.clone(), 0),
|
||||
signed_bitfield(bitvec.clone(), 1),
|
||||
signed_bitfield(bitvec, 1),
|
||||
block_on(signed_bitfield(&keystore, bitvec.clone(), 0)),
|
||||
block_on(signed_bitfield(&keystore, bitvec.clone(), 1)),
|
||||
block_on(signed_bitfield(&keystore, bitvec, 1)),
|
||||
];
|
||||
|
||||
let mut selected_bitfields = select_availability_bitfields(&cores, &bitfields);
|
||||
@@ -621,6 +627,11 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn more_set_bits_win_conflicts() {
|
||||
// Configure filesystem-based keystore as generating keys without seed
|
||||
// would trigger the key to be generated on the filesystem.
|
||||
let keystore_path = tempfile::tempdir().expect("Creates keystore path");
|
||||
let keystore : SyncCryptoStorePtr = Arc::new(LocalKeystore::open(keystore_path.path(), None)
|
||||
.expect("Creates keystore"));
|
||||
let bitvec_zero = default_bitvec();
|
||||
let bitvec_one = {
|
||||
let mut bitvec = bitvec_zero.clone();
|
||||
@@ -631,8 +642,8 @@ mod tests {
|
||||
let cores = vec![occupied_core(0)];
|
||||
|
||||
let bitfields = vec![
|
||||
signed_bitfield(bitvec_zero, 0),
|
||||
signed_bitfield(bitvec_one.clone(), 0),
|
||||
block_on(signed_bitfield(&keystore, bitvec_zero, 0)),
|
||||
block_on(signed_bitfield(&keystore, bitvec_one.clone(), 0)),
|
||||
];
|
||||
|
||||
// this test is probablistic: chances are excellent that it does what it claims to.
|
||||
|
||||
Reference in New Issue
Block a user