2023-03-31 10:34:09 +00:00
|
|
|
use sp_core::Pair;
|
|
|
|
|
|
|
|
use serai_client::{
|
|
|
|
subxt::config::extrinsic_params::BaseExtrinsicParamsBuilder,
|
2023-03-31 12:11:23 +00:00
|
|
|
primitives::{SeraiAddress, insecure_pair_from_name},
|
2023-03-31 10:34:09 +00:00
|
|
|
validator_sets::{
|
|
|
|
primitives::{ValidatorSet, KeyPair},
|
|
|
|
ValidatorSetsEvent,
|
|
|
|
},
|
|
|
|
PairSigner, Serai,
|
|
|
|
};
|
|
|
|
|
|
|
|
use crate::common::{serai, tx::publish_tx};
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
2023-03-31 12:11:23 +00:00
|
|
|
pub async fn vote_in_keys(set: ValidatorSet, key_pair: KeyPair) -> [u8; 32] {
|
2023-03-31 10:34:09 +00:00
|
|
|
let pair = insecure_pair_from_name("Alice");
|
|
|
|
let public = pair.public();
|
|
|
|
|
|
|
|
let serai = serai().await;
|
|
|
|
|
|
|
|
// Vote in a key pair
|
2023-03-31 12:11:23 +00:00
|
|
|
let address = SeraiAddress::from(pair.public());
|
2023-03-31 10:34:09 +00:00
|
|
|
let block = publish_tx(
|
|
|
|
&serai
|
|
|
|
.sign(
|
|
|
|
&PairSigner::new(pair),
|
|
|
|
&Serai::vote(set.network, key_pair.clone()),
|
2023-03-31 12:11:23 +00:00
|
|
|
serai.get_nonce(&address).await.unwrap(),
|
2023-03-31 10:34:09 +00:00
|
|
|
BaseExtrinsicParamsBuilder::new(),
|
|
|
|
)
|
|
|
|
.unwrap(),
|
|
|
|
)
|
|
|
|
.await;
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
serai.get_vote_events(block).await.unwrap(),
|
|
|
|
vec![ValidatorSetsEvent::Vote { voter: public, set, key_pair: key_pair.clone(), votes: 1 }]
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
serai.get_key_gen_events(block).await.unwrap(),
|
|
|
|
vec![ValidatorSetsEvent::KeyGen { set, key_pair: key_pair.clone() }]
|
|
|
|
);
|
|
|
|
assert_eq!(serai.get_keys(set).await.unwrap(), Some(key_pair));
|
|
|
|
|
|
|
|
block
|
|
|
|
}
|