diff --git a/substrate/client/src/serai/mod.rs b/substrate/client/src/serai/mod.rs index e07651b82..bbe24bcd8 100644 --- a/substrate/client/src/serai/mod.rs +++ b/substrate/client/src/serai/mod.rs @@ -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 { let latest = self.latest_block_hash().await?; Ok(TemporalSerai(self, latest)) diff --git a/tests/coordinator/src/lib.rs b/tests/coordinator/src/lib.rs index afad025e2..1995776c3 100644 --- a/tests/coordinator/src/lib.rs +++ b/tests/coordinator/src/lib.rs @@ -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; diff --git a/tests/coordinator/src/tests/batch.rs b/tests/coordinator/src/tests/batch.rs index caa567333..75b732dc9 100644 --- a/tests/coordinator/src/tests/batch.rs +++ b/tests/coordinator/src/tests/batch.rs @@ -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, diff --git a/tests/coordinator/src/tests/key_gen.rs b/tests/coordinator/src/tests/key_gen.rs index 81a6aa15f..c7d801fbc 100644 --- a/tests/coordinator/src/tests/key_gen.rs +++ b/tests/coordinator/src/tests/key_gen.rs @@ -106,7 +106,7 @@ pub async fn key_gen( 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( 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( } 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(), diff --git a/tests/coordinator/src/tests/sign.rs b/tests/coordinator/src/tests/sign.rs index 4c9903386..c7a61e911 100644 --- a/tests/coordinator/src/tests/sign.rs +++ b/tests/coordinator/src/tests/sign.rs @@ -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(); - - assert_eq!( - serai.get_sri_balance(block_included_in_hash, 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(), - 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 - ); + { + let block_included_in_hash = + serai.block_by_number(block_included_in).await.unwrap().unwrap().hash(); + + 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.mint_events().await.unwrap(), + vec![TokensEvent::Mint { address: serai_addr, balance }] + ); + 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); diff --git a/tests/full-stack/src/lib.rs b/tests/full-stack/src/lib.rs index e2f850c22..a9b6c4523 100644 --- a/tests/full-stack/src/lib.rs +++ b/tests/full-stack/src/lib.rs @@ -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; diff --git a/tests/full-stack/src/tests/mint_and_burn.rs b/tests/full-stack/src/tests/mint_and_burn.rs index 098feb40f..e2236c858 100644 --- a/tests/full-stack/src/tests/mint_and_burn.rs +++ b/tests/full-stack/src/tests/mint_and_burn.rs @@ -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(), )