2023-03-31 12:11:23 +00:00
|
|
|
use scale::Encode;
|
2023-03-31 10:34:09 +00:00
|
|
|
|
2023-03-31 12:11:23 +00:00
|
|
|
use sp_core::Pair;
|
|
|
|
|
|
|
|
use serai_client::{
|
|
|
|
primitives::insecure_pair_from_name,
|
|
|
|
validator_sets::primitives::{Session, ValidatorSet},
|
|
|
|
in_instructions::{
|
|
|
|
primitives::{Batch, SignedBatch},
|
|
|
|
InInstructionsEvent,
|
|
|
|
},
|
2023-05-13 06:02:47 +00:00
|
|
|
Serai,
|
2023-03-31 12:11:23 +00:00
|
|
|
};
|
|
|
|
|
2023-05-13 06:02:47 +00:00
|
|
|
use crate::common::{serai, tx::publish_tx, validator_sets::set_validator_set_keys};
|
2023-03-31 10:34:09 +00:00
|
|
|
|
|
|
|
#[allow(dead_code)]
|
2023-03-31 12:11:23 +00:00
|
|
|
pub async fn provide_batch(batch: Batch) -> [u8; 32] {
|
2023-03-31 10:34:09 +00:00
|
|
|
let serai = serai().await;
|
|
|
|
|
2023-03-31 12:11:23 +00:00
|
|
|
// TODO: Get the latest session
|
|
|
|
let set = ValidatorSet { session: Session(0), network: batch.network };
|
|
|
|
let pair = insecure_pair_from_name(&format!("ValidatorSet {:?}", set));
|
|
|
|
let keys = if let Some(keys) = serai.get_keys(set).await.unwrap() {
|
|
|
|
keys
|
|
|
|
} else {
|
|
|
|
let keys = (pair.public(), vec![].try_into().unwrap());
|
2023-05-13 06:02:47 +00:00
|
|
|
set_validator_set_keys(set, keys.clone()).await;
|
2023-03-31 12:11:23 +00:00
|
|
|
keys
|
|
|
|
};
|
|
|
|
assert_eq!(keys.0, pair.public());
|
|
|
|
|
2023-05-13 06:02:47 +00:00
|
|
|
let block = publish_tx(&Serai::execute_batch(SignedBatch {
|
|
|
|
batch: batch.clone(),
|
|
|
|
signature: pair.sign(&batch.encode()),
|
|
|
|
}))
|
2023-03-31 12:11:23 +00:00
|
|
|
.await;
|
2023-03-31 10:34:09 +00:00
|
|
|
|
|
|
|
let batches = serai.get_batch_events(block).await.unwrap();
|
|
|
|
// TODO: impl From<Batch> for BatchEvent?
|
|
|
|
assert_eq!(
|
|
|
|
batches,
|
2023-03-31 12:11:23 +00:00
|
|
|
vec![InInstructionsEvent::Batch { network: batch.network, id: batch.id, block: batch.block }],
|
2023-03-31 10:34:09 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// TODO: Check the tokens events
|
|
|
|
|
|
|
|
block
|
|
|
|
}
|