mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 17:31:05 +00:00
Events sub (#126)
* Make event subscription logic more generic. * Fix build. * Add test-node. * Update deps. * Address review comments.
This commit is contained in:
@@ -114,10 +114,12 @@ mod tests {
|
||||
Error,
|
||||
RuntimeError,
|
||||
},
|
||||
events::EventsDecoder,
|
||||
signer::{
|
||||
PairSigner,
|
||||
Signer,
|
||||
},
|
||||
subscription::EventSubscription,
|
||||
system::AccountStoreExt,
|
||||
tests::{
|
||||
test_client,
|
||||
@@ -201,4 +203,28 @@ mod tests {
|
||||
panic!("expected an error");
|
||||
}
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
async fn test_transfer_subscription() {
|
||||
env_logger::try_init().ok();
|
||||
let alice = PairSigner::new(AccountKeyring::Alice.pair());
|
||||
let bob = AccountKeyring::Bob.to_account_id();
|
||||
let (client, _) = test_client().await;
|
||||
let sub = client.subscribe_events().await.unwrap();
|
||||
let mut decoder = EventsDecoder::<TestRuntime>::new(client.metadata().clone());
|
||||
decoder.with_balances();
|
||||
let mut sub = EventSubscription::<TestRuntime>::new(sub, decoder);
|
||||
sub.filter_event::<TransferEvent<_>>();
|
||||
client.transfer(&alice, &bob, 10_000).await.unwrap();
|
||||
let raw = sub.next().await.unwrap().unwrap();
|
||||
let event = TransferEvent::<TestRuntime>::decode(&mut &raw.data[..]).unwrap();
|
||||
assert_eq!(
|
||||
event,
|
||||
TransferEvent {
|
||||
from: alice.account_id().clone(),
|
||||
to: bob.clone(),
|
||||
amount: 10_000,
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user