serai/substrate/client/tests/batch.rs
Luke Parker 695d1f0ecf
Remove subxt (#460)
* Remove subxt

Removes ~20 crates from our Cargo.lock.

Removes downloading the metadata and enables removing the getMetadata RPC route
(relevant to #379).

Moves forward #337.

Done now due to distinctions in the subxt 0.32 API surface which make it
justifiable to not update.

* fmt, update due to deny triggering on a yanked crate

* Correct the handling of substrate_block_notifier now that it's ephemeral, not long-lived

* Correct URL in tests/coordinator from ws to http
2023-11-28 02:29:50 -05:00

75 lines
1.9 KiB
Rust

use rand_core::{RngCore, OsRng};
use blake2::{
digest::{consts::U32, Digest},
Blake2b,
};
use scale::Encode;
use serai_client::{
primitives::{Amount, NetworkId, Coin, Balance, BlockHash, SeraiAddress},
in_instructions::{
primitives::{InInstruction, InInstructionWithBalance, Batch},
InInstructionsEvent,
},
coins::CoinsEvent,
Serai,
};
mod common;
use common::in_instructions::provide_batch;
serai_test!(
publish_batch: (|serai: Serai| async move {
let network = NetworkId::Bitcoin;
let id = 0;
let mut block_hash = BlockHash([0; 32]);
OsRng.fill_bytes(&mut block_hash.0);
let mut address = SeraiAddress::new([0; 32]);
OsRng.fill_bytes(&mut address.0);
let coin = Coin::Bitcoin;
let amount = Amount(OsRng.next_u64().saturating_add(1));
let balance = Balance { coin, amount };
let batch = Batch {
network,
id,
block: block_hash,
instructions: vec![InInstructionWithBalance {
instruction: InInstruction::Transfer(address),
balance,
}],
};
let block = provide_batch(&serai, batch.clone()).await;
let serai = serai.as_of(block);
{
let serai = serai.in_instructions();
let latest_finalized = serai.latest_block_for_network(network).await.unwrap();
assert_eq!(latest_finalized, Some(block_hash));
let batches = serai.batch_events().await.unwrap();
assert_eq!(
batches,
vec![InInstructionsEvent::Batch {
network,
id,
block: block_hash,
instructions_hash: Blake2b::<U32>::digest(batch.instructions.encode()).into(),
}]
);
}
let serai = serai.coins();
assert_eq!(
serai.mint_events().await.unwrap(),
vec![CoinsEvent::Mint { to: address.into(), balance }]
);
assert_eq!(serai.coin_supply(coin).await.unwrap(), amount);
assert_eq!(serai.coin_balance(coin, address).await.unwrap(), amount);
})
);