Skip to content

Commit

Permalink
Improve testing and error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Niederb committed Oct 9, 2024
1 parent b5e0b6d commit 6191cb8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/api/rpc_api/author.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ where
&self,
mut report: ExtrinsicReport<Self::Hash>,
) -> Result<ExtrinsicReport<Self::Hash>> {
if report.events.is_some() {
return Err(Error::Other("Report already contains events".into()))
}
let block_hash = report.block_hash.ok_or(Error::BlockHashNotFound)?;
let extrinsic_events =
self.fetch_events_for_extrinsic(block_hash, report.extrinsic_hash).await?;
Expand Down
7 changes: 7 additions & 0 deletions testing/async/examples/author_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ async fn test_submit_and_watch_extrinsic_until_in_block_without_events(
println!("Extrinsic got successfully included in Block!");
assert!(report.block_hash.is_some());
assert!(report.events.is_none());

// Now we fetch the events separately
let report = api.populate_events(report).await.unwrap();
assert!(report.events.is_some());

// Can populate events only once
assert!(api.populate_events(report).await.is_err());
}

fn assert_associated_events_match_expected(events: Vec<RawEventDetails<Hash>>) {
Expand Down

0 comments on commit 6191cb8

Please sign in to comment.