Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak 0.23 notes and add another test for events #618

Merged
merged 2 commits into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,11 @@ while let Some(events) = event_sub.next().await {
}
```

Note that when working with a single event, the method `event.bytes()` previously returned just the bytes associated with the event fields. Now, `event.bytes()` returns _all_ of the bytes associated with the event. There is a separate method, `event.field_bytes()`, that returns the bytes for just the fields in the event. This change will **not** lead to a compile error, and so it's worth keeping an eye out for any uses of `.bytes()` to update them to `.field_bytes()`.

See the `examples/examples/subscribe_all_events.rs` example for more.


The general pattern, as seen above, is that we break apart constructing a query/address and using it. You can now construct queries dynamically instead and forego all static codegen by using the functionality exposed in the `subxt::dynamic` module instead.

Other smaller breaking changes have happened, but they should be easier to address by following compile errors.
Expand Down
43 changes: 43 additions & 0 deletions testing/integration-tests/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,49 @@ async fn subscription_produces_events_each_block() -> Result<(), subxt::Error> {
Ok(())
}

// Iterate all of the events in a few blocks to ensure we can decode them properly.
#[tokio::test]
async fn decoding_all_events_in_a_block_works() -> Result<(), subxt::Error> {
let ctx = test_context().await;
let api = ctx.client();

wait_for_blocks(&api).await;

let mut event_sub = api.events().subscribe().await?;

tokio::spawn(async move {
let alice = pair_signer(AccountKeyring::Alice.pair());
let bob = AccountKeyring::Bob.to_account_id();
let transfer_tx = node_runtime::tx()
.balances()
.transfer(bob.clone().into(), 10_000);

// Make a load of transfers to get lots of events going.
for _i in 0..10 {
api.tx()
.sign_and_submit_then_watch_default(&transfer_tx, &alice)
.await
.expect("can submit_transaction");
}
});

for _ in 0..4 {
let events = event_sub
.next()
.await
.expect("events expected each block")?;

for event in events.iter() {
// make sure that we can get every event properly.
let event = event.expect("valid event decoded");
// make sure that we can decode the field values from every event.
event.field_values().expect("can decode fields");
}
}

Ok(())
}

// Check that our subscription receives events, and we can filter them based on
// it's Stream impl, and ultimately see the event we expect.
#[tokio::test]
Expand Down