mirror of
https://github.com/serai-dex/serai.git
synced 2024-12-29 15:09:22 +00:00
4d9c2df38c
Some checks failed
Coordinator Tests / build (push) Has been cancelled
Full Stack Tests / build (push) Has been cancelled
Lint / clippy (macos-13) (push) Has been cancelled
Lint / clippy (macos-14) (push) Has been cancelled
Lint / clippy (ubuntu-latest) (push) Has been cancelled
Lint / clippy (windows-latest) (push) Has been cancelled
Lint / deny (push) Has been cancelled
Lint / fmt (push) Has been cancelled
Lint / machete (push) Has been cancelled
Reproducible Runtime / build (push) Has been cancelled
Tests / test-infra (push) Has been cancelled
Tests / test-substrate (push) Has been cancelled
Tests / test-serai-client (push) Has been cancelled
* add node side unit test * complete rotation test for all networks * set up the fast-epoch docker file * fix pr comments * add coordinator side rotation test * bug fixes * Remove EPOCH_INTERVAL * Minor nits * Add note on origin of publish_tx function in tests/coordinator * Correct ThresholdParams assert_eq * fmt * Correct detection of handover completion * Restore key gen message match from develop It was modified in response to the handover completion bug, which has now been resolved. * bug fixes * Correct invalid constant * Typo fixes * remove selecting participant to remove at random --------- Co-authored-by: Luke Parker <lukeparker5132@gmail.com>
87 lines
2.2 KiB
Rust
87 lines
2.2 KiB
Rust
use rand_core::{RngCore, OsRng};
|
|
use blake2::{
|
|
digest::{consts::U32, Digest},
|
|
Blake2b,
|
|
};
|
|
|
|
use scale::Encode;
|
|
|
|
use sp_core::Pair;
|
|
|
|
use serai_client::{
|
|
primitives::{insecure_pair_from_name, BlockHash, NetworkId, Balance, SeraiAddress},
|
|
validator_sets::primitives::{Session, ValidatorSet, KeyPair},
|
|
in_instructions::{
|
|
primitives::{Batch, SignedBatch, batch_message, InInstruction, InInstructionWithBalance},
|
|
InInstructionsEvent,
|
|
},
|
|
SeraiInInstructions, Serai,
|
|
};
|
|
|
|
use crate::common::{tx::publish_tx, validator_sets::set_keys};
|
|
|
|
#[allow(dead_code)]
|
|
pub async fn provide_batch(serai: &Serai, batch: Batch) -> [u8; 32] {
|
|
// 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.as_of_latest_finalized_block().await.unwrap().validator_sets().keys(set).await.unwrap()
|
|
{
|
|
keys
|
|
} else {
|
|
let keys = KeyPair(pair.public(), vec![].try_into().unwrap());
|
|
set_keys(serai, set, keys.clone(), &[insecure_pair_from_name("Alice")]).await;
|
|
keys
|
|
};
|
|
assert_eq!(keys.0, pair.public());
|
|
|
|
let block = publish_tx(
|
|
serai,
|
|
&SeraiInInstructions::execute_batch(SignedBatch {
|
|
batch: batch.clone(),
|
|
signature: pair.sign(&batch_message(&batch)),
|
|
}),
|
|
)
|
|
.await;
|
|
|
|
let batches = serai.as_of(block).in_instructions().batch_events().await.unwrap();
|
|
// TODO: impl From<Batch> for BatchEvent?
|
|
assert_eq!(
|
|
batches,
|
|
vec![InInstructionsEvent::Batch {
|
|
network: batch.network,
|
|
id: batch.id,
|
|
block: batch.block,
|
|
instructions_hash: Blake2b::<U32>::digest(batch.instructions.encode()).into(),
|
|
}],
|
|
);
|
|
|
|
// TODO: Check the tokens events
|
|
|
|
block
|
|
}
|
|
|
|
#[allow(dead_code)]
|
|
pub async fn mint_coin(
|
|
serai: &Serai,
|
|
balance: Balance,
|
|
network: NetworkId,
|
|
batch_id: u32,
|
|
address: SeraiAddress,
|
|
) -> [u8; 32] {
|
|
let mut block_hash = BlockHash([0; 32]);
|
|
OsRng.fill_bytes(&mut block_hash.0);
|
|
|
|
let batch = Batch {
|
|
network,
|
|
id: batch_id,
|
|
block: block_hash,
|
|
instructions: vec![InInstructionWithBalance {
|
|
instruction: InInstruction::Transfer(address),
|
|
balance,
|
|
}],
|
|
};
|
|
|
|
provide_batch(serai, batch).await
|
|
}
|