mirror of
https://github.com/serai-dex/serai.git
synced 2024-11-17 01:17:36 +00:00
Update dockertests to new serai-client
This commit is contained in:
parent
e3e9939eaf
commit
7d4e8b59db
7 changed files with 56 additions and 58 deletions
|
@ -287,6 +287,7 @@ impl Serai {
|
|||
.map_err(SeraiError::RpcError)
|
||||
}
|
||||
|
||||
/// Create a TemporalSerai using whatever is currently the latest block.
|
||||
pub async fn with_current_latest_block(&self) -> Result<TemporalSerai, SeraiError> {
|
||||
let latest = self.latest_block_hash().await?;
|
||||
Ok(TemporalSerai(self, latest))
|
||||
|
|
|
@ -170,7 +170,7 @@ impl Processor {
|
|||
for _ in 0 .. 60 {
|
||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||
let Ok(client) = Serai::new(&serai_rpc).await else { continue };
|
||||
if client.get_latest_block_hash().await.is_err() {
|
||||
if client.latest_block_hash().await.is_err() {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -172,7 +172,7 @@ pub async fn batch(
|
|||
let batch = SignedBatch { batch, signature };
|
||||
|
||||
let serai = processors[0].serai().await;
|
||||
let mut last_serai_block = serai.get_latest_block().await.unwrap().number();
|
||||
let mut last_serai_block = serai.latest_block().await.unwrap().number();
|
||||
|
||||
for processor in processors.iter_mut() {
|
||||
processor
|
||||
|
@ -187,11 +187,11 @@ pub async fn batch(
|
|||
tokio::time::sleep(Duration::from_secs(6)).await;
|
||||
}
|
||||
|
||||
while last_serai_block <= serai.get_latest_block().await.unwrap().number() {
|
||||
while last_serai_block <= serai.latest_block().await.unwrap().number() {
|
||||
let batch_events = serai
|
||||
.get_batch_events(
|
||||
serai.get_block_by_number(last_serai_block).await.unwrap().unwrap().hash(),
|
||||
)
|
||||
.as_of(serai.block_by_number(last_serai_block).await.unwrap().unwrap().hash())
|
||||
.in_instructions()
|
||||
.batch_events()
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
@ -213,7 +213,7 @@ pub async fn batch(
|
|||
}
|
||||
|
||||
// Verify the coordinator sends SubstrateBlock to all processors
|
||||
let last_block = serai.get_block_by_number(last_serai_block).await.unwrap().unwrap();
|
||||
let last_block = serai.block_by_number(last_serai_block).await.unwrap().unwrap();
|
||||
for processor in processors.iter_mut() {
|
||||
assert_eq!(
|
||||
processor.recv_message().await,
|
||||
|
|
|
@ -106,7 +106,7 @@ pub async fn key_gen<C: Ciphersuite>(
|
|||
let network_key = (C::generator() * *network_priv_key).to_bytes().as_ref().to_vec();
|
||||
|
||||
let serai = processors[0].serai().await;
|
||||
let mut last_serai_block = serai.get_latest_block().await.unwrap().number();
|
||||
let mut last_serai_block = serai.latest_block().await.unwrap().number();
|
||||
|
||||
wait_for_tributary().await;
|
||||
for (i, processor) in processors.iter_mut().enumerate() {
|
||||
|
@ -148,11 +148,11 @@ pub async fn key_gen<C: Ciphersuite>(
|
|||
tokio::time::sleep(Duration::from_secs(6)).await;
|
||||
}
|
||||
|
||||
while last_serai_block <= serai.get_latest_block().await.unwrap().number() {
|
||||
while last_serai_block <= serai.latest_block().await.unwrap().number() {
|
||||
if !serai
|
||||
.get_key_gen_events(
|
||||
serai.get_block_by_number(last_serai_block).await.unwrap().unwrap().hash(),
|
||||
)
|
||||
.as_of(serai.block_by_number(last_serai_block).await.unwrap().unwrap().hash())
|
||||
.validator_sets()
|
||||
.key_gen_events()
|
||||
.await
|
||||
.unwrap()
|
||||
.is_empty()
|
||||
|
@ -196,7 +196,9 @@ pub async fn key_gen<C: Ciphersuite>(
|
|||
}
|
||||
assert_eq!(
|
||||
serai
|
||||
.get_keys(set, serai.get_block_by_number(last_serai_block).await.unwrap().unwrap().hash())
|
||||
.as_of(serai.block_by_number(last_serai_block).await.unwrap().unwrap().hash())
|
||||
.validator_sets()
|
||||
.keys(set)
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap(),
|
||||
|
|
|
@ -17,11 +17,12 @@ use serai_client::{
|
|||
NetworkId, Coin, Amount, Balance, BlockHash, SeraiAddress, ExternalAddress,
|
||||
insecure_pair_from_name,
|
||||
},
|
||||
tokens::{
|
||||
coins::{
|
||||
primitives::{OutInstruction, OutInstructionWithBalance},
|
||||
TokensEvent,
|
||||
},
|
||||
in_instructions::primitives::{InInstruction, InInstructionWithBalance, Batch},
|
||||
SeraiCoins,
|
||||
};
|
||||
use messages::{sign::SignId, SubstrateContext, CoordinatorMessage};
|
||||
|
||||
|
@ -210,7 +211,7 @@ async fn sign_test() {
|
|||
&serai
|
||||
.sign(
|
||||
&PairSigner::new(insecure_pair_from_name("Ferdie")),
|
||||
&Serai::transfer_sri(address, Amount(1_000_000_000)),
|
||||
&SeraiCoins::transfer_sri(address, Amount(1_000_000_000)),
|
||||
0,
|
||||
Default::default(),
|
||||
)
|
||||
|
@ -243,27 +244,21 @@ async fn sign_test() {
|
|||
)
|
||||
.await;
|
||||
|
||||
{
|
||||
let block_included_in_hash =
|
||||
serai.get_block_by_number(block_included_in).await.unwrap().unwrap().hash();
|
||||
serai.block_by_number(block_included_in).await.unwrap().unwrap().hash();
|
||||
|
||||
assert_eq!(
|
||||
serai.get_sri_balance(block_included_in_hash, serai_addr).await.unwrap(),
|
||||
1_000_000_000
|
||||
);
|
||||
let serai = serai.as_of(block_included_in_hash).coins();
|
||||
assert_eq!(serai.sri_balance(serai_addr).await.unwrap(), 1_000_000_000);
|
||||
|
||||
// Verify the mint occurred as expected
|
||||
assert_eq!(
|
||||
serai.get_mint_events(block_included_in_hash).await.unwrap(),
|
||||
serai.mint_events().await.unwrap(),
|
||||
vec![TokensEvent::Mint { address: serai_addr, balance }]
|
||||
);
|
||||
assert_eq!(
|
||||
serai.get_token_supply(block_included_in_hash, Coin::Bitcoin).await.unwrap(),
|
||||
amount
|
||||
);
|
||||
assert_eq!(
|
||||
serai.get_token_balance(block_included_in_hash, Coin::Bitcoin, serai_addr).await.unwrap(),
|
||||
amount
|
||||
);
|
||||
assert_eq!(serai.token_supply(Coin::Bitcoin).await.unwrap(), amount);
|
||||
assert_eq!(serai.token_balance(Coin::Bitcoin, serai_addr).await.unwrap(), amount);
|
||||
}
|
||||
|
||||
// Trigger a burn
|
||||
let out_instruction =
|
||||
|
@ -273,7 +268,7 @@ async fn sign_test() {
|
|||
&serai
|
||||
.sign(
|
||||
&serai_pair,
|
||||
&Serai::burn(balance, out_instruction.clone()),
|
||||
&SeraiCoins::burn(balance, out_instruction.clone()),
|
||||
0,
|
||||
Default::default(),
|
||||
)
|
||||
|
@ -290,11 +285,11 @@ async fn sign_test() {
|
|||
tokio::time::sleep(Duration::from_secs(6)).await;
|
||||
}
|
||||
|
||||
while last_serai_block <= serai.get_latest_block().await.unwrap().number() {
|
||||
while last_serai_block <= serai.latest_block().await.unwrap().number() {
|
||||
let burn_events = serai
|
||||
.get_burn_events(
|
||||
serai.get_block_by_number(last_serai_block).await.unwrap().unwrap().hash(),
|
||||
)
|
||||
.as_of(serai.block_by_number(last_serai_block).await.unwrap().unwrap().hash())
|
||||
.coins()
|
||||
.burn_events()
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
@ -314,16 +309,11 @@ async fn sign_test() {
|
|||
}
|
||||
}
|
||||
|
||||
let last_serai_block = serai.get_block_by_number(last_serai_block).await.unwrap().unwrap();
|
||||
let last_serai_block = serai.block_by_number(last_serai_block).await.unwrap().unwrap();
|
||||
let last_serai_block_hash = last_serai_block.hash();
|
||||
assert_eq!(
|
||||
serai.get_token_supply(last_serai_block_hash, Coin::Bitcoin).await.unwrap(),
|
||||
Amount(0)
|
||||
);
|
||||
assert_eq!(
|
||||
serai.get_token_balance(last_serai_block_hash, Coin::Bitcoin, serai_addr).await.unwrap(),
|
||||
Amount(0)
|
||||
);
|
||||
let serai = serai.as_of(last_serai_block_hash).coins();
|
||||
assert_eq!(serai.token_supply(Coin::Bitcoin).await.unwrap(), Amount(0));
|
||||
assert_eq!(serai.token_balance(Coin::Bitcoin, serai_addr).await.unwrap(), Amount(0));
|
||||
|
||||
let mut plan_id = [0; 32];
|
||||
OsRng.fill_bytes(&mut plan_id);
|
||||
|
|
|
@ -141,7 +141,7 @@ impl Handles {
|
|||
for _ in 0 .. 60 {
|
||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||
let Ok(client) = Serai::new(&serai_rpc).await else { continue };
|
||||
if client.get_latest_block_hash().await.is_err() {
|
||||
if client.latest_block_hash().await.is_err() {
|
||||
continue;
|
||||
}
|
||||
return client;
|
||||
|
|
|
@ -15,8 +15,8 @@ use serai_client::{
|
|||
},
|
||||
validator_sets::primitives::{Session, ValidatorSet},
|
||||
in_instructions::primitives::Shorthand,
|
||||
tokens::primitives::OutInstruction,
|
||||
PairTrait, PairSigner,
|
||||
coins::primitives::OutInstruction,
|
||||
PairTrait, PairSigner, SeraiCoins,
|
||||
};
|
||||
|
||||
use crate::tests::*;
|
||||
|
@ -196,10 +196,11 @@ async fn mint_and_burn_test() {
|
|||
let print_at = halt_at / 2;
|
||||
for i in 0 .. halt_at {
|
||||
if let Some(key_pair) = serai
|
||||
.get_keys(
|
||||
ValidatorSet { network, session: Session(0) },
|
||||
serai.get_latest_block_hash().await.unwrap(),
|
||||
)
|
||||
.with_current_latest_block()
|
||||
.await
|
||||
.unwrap()
|
||||
.validator_sets()
|
||||
.keys(ValidatorSet { network, session: Session(0) })
|
||||
.await
|
||||
.unwrap()
|
||||
{
|
||||
|
@ -240,7 +241,7 @@ async fn mint_and_burn_test() {
|
|||
&serai
|
||||
.sign(
|
||||
&PairSigner::new(insecure_pair_from_name("Ferdie")),
|
||||
&Serai::transfer_sri(address, Amount(1_000_000_000)),
|
||||
&SeraiCoins::transfer_sri(address, Amount(1_000_000_000)),
|
||||
0,
|
||||
Default::default(),
|
||||
)
|
||||
|
@ -408,7 +409,11 @@ async fn mint_and_burn_test() {
|
|||
let print_at = halt_at / 2;
|
||||
for i in 0 .. halt_at {
|
||||
if serai
|
||||
.get_last_batch_for_network(serai.get_latest_block_hash().await.unwrap(), network)
|
||||
.with_current_latest_block()
|
||||
.await
|
||||
.unwrap()
|
||||
.in_instructions()
|
||||
.last_batch_for_network(network)
|
||||
.await
|
||||
.unwrap()
|
||||
.is_some()
|
||||
|
@ -490,7 +495,7 @@ async fn mint_and_burn_test() {
|
|||
&serai
|
||||
.sign(
|
||||
serai_pair,
|
||||
&Serai::burn(Balance { coin, amount: Amount(amount) }, out_instruction),
|
||||
&SeraiCoins::burn(Balance { coin, amount: Amount(amount) }, out_instruction),
|
||||
nonce,
|
||||
Default::default(),
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue