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

Bug/filter test termination #443

Merged
merged 3 commits into from
Aug 17, 2023
Merged

Bug/filter test termination #443

merged 3 commits into from
Aug 17, 2023

Conversation

0xJepsen
Copy link
Collaborator

This PR Closes #423 by fixing our filter watcher watcher tests that were initially commented out here:

// #[tokio::test]
// async fn filter_address() -> Result<()> {
// let (arbiter_token, _environment, client) =
// deploy_and_start().await.unwrap(); let mut default_watcher =
// client.watch(&Filter::default()).await?; let mut address_watcher = client
// .watch(&Filter::new().address(arbiter_token.address()))
// .await?;
// // Check that both watchers get this event
// let approval = arbiter_token.approve(
// client.default_sender().unwrap(),
// ethers::types::U256::from(TEST_APPROVAL_AMOUNT),
// );
// approval.send().await?.await?;
// let default_watcher_event = default_watcher.next().await.unwrap();
// let address_watcher_event = address_watcher.next().await.unwrap();
// assert!(!default_watcher_event.data.is_empty());
// assert!(!address_watcher_event.data.is_empty());
// assert_eq!(default_watcher_event, address_watcher_event);
// // Create a new token contract to check that the address watcher only
// gets // events from the correct contract Check that only the default
// watcher gets // this event
// let arbiter_token2 = ArbiterToken::deploy(
// client.clone(),
// (
// format!("new_{}", TEST_ARG_NAME),
// format!("new_{}", TEST_ARG_SYMBOL),
// TEST_ARG_DECIMALS,
// ),
// )?
// .send()
// .await?;
// let mint2 = arbiter_token2.mint(
// ethers::types::H160::from_str(TEST_MINT_TO)?,
// ethers::types::U256::from(TEST_MINT_AMOUNT),
// );
// mint2.send().await?.await?;
// let default_watcher_event = default_watcher.next().await.unwrap();
// assert!(!default_watcher_event.data.is_empty());
// println!("default_watcher_event: {:#?}", default_watcher_event);
// // Use tokio::time::timeout to await the approval_watcher for a specific
// // duration The timeout is needed because the approval_watcher is a
// stream // that will never end when the test is passing
// let timeout_duration = tokio::time::Duration::from_secs(1); // Adjust the
// duration as needed let timeout = tokio::time::timeout(timeout_duration,
// address_watcher.next()); match timeout.await {
// Result::Ok(Some(_)) => {
// // Event received
// panic!("This means the test is failing! The filter did not
// work."); }
// Result::Ok(None) => {
// // Timeout occurred, no event received
// println!("Expected result. The filter worked.")
// }
// Err(_) => {
// // Timer error (shouldn't happen in normal conditions)
// panic!("Timer error!")
// }
// }
// Ok(())
// }
// #[tokio::test]
// async fn filter_topics() -> Result<()> {
// let (arbiter_token, _environment, client) =
// deploy_and_start().await.unwrap(); let mut default_watcher =
// client.watch(&Filter::default()).await?; let mut approval_watcher =
// client .watch(&arbiter_token.approval_filter().filter)
// .await?;
// // Check that both watchers get this event
// let approval = arbiter_token.approve(
// client.default_sender().unwrap(),
// ethers::types::U256::from(TEST_APPROVAL_AMOUNT),
// );
// approval.send().await?.await?;
// let default_watcher_event = default_watcher.next().await.unwrap();
// let approval_watcher_event = approval_watcher.next().await.unwrap();
// assert!(!default_watcher_event.data.is_empty());
// assert!(!approval_watcher_event.data.is_empty());
// assert_eq!(default_watcher_event, approval_watcher_event);
// // Check that only the default watcher gets this event
// let mint = arbiter_token.mint(
// ethers::types::H160::from_str(TEST_MINT_TO)?,
// ethers::types::U256::from(TEST_MINT_AMOUNT),
// );
// mint.send().await?.await?;
// let default_watcher_event = default_watcher.next().await.unwrap();
// assert!(!default_watcher_event.data.is_empty());
// println!("default_watcher_event: {:#?}", default_watcher_event);
// // Use tokio::time::timeout to await the approval_watcher for a specific
// // duration The timeout is needed because the approval_watcher is a
// stream // that will never end when the test is passing
// let timeout_duration = tokio::time::Duration::from_secs(5); // Adjust the
// duration as needed let timeout = tokio::time::timeout(timeout_duration,
// approval_watcher.next()); match timeout.await {
// Result::Ok(Some(_)) => {
// // Event received
// panic!("This means the test is failing! The filter did not
// work."); }
// Result::Ok(None) => {
// // Timeout occurred, no event received
// println!("Expected result. The filter worked.")
// }
// Err(_) => {
// // Timer error (shouldn't happen in normal conditions)
// panic!("Timer error!")
// }
// }
// Ok(())
// }

They now pass and terminate with the expected behavior. This was done by manually polling the stream and matching on the poll.

Copy link
Collaborator

@Autoparallel Autoparallel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please help me resolve my comments!

arbiter-core/src/tests/interaction.rs Show resolved Hide resolved
arbiter-core/src/tests/interaction.rs Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Aug 17, 2023

Codecov Report

Merging #443 (d000d2c) into main (9c798a2) will not change coverage.
Report is 1 commits behind head on main.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main     #443   +/-   ##
=======================================
  Coverage   58.24%   58.24%           
=======================================
  Files          10       10           
  Lines        2996     2996           
=======================================
  Hits         1745     1745           
  Misses       1251     1251           
Files Changed Coverage Δ
arbiter-core/src/middleware.rs 84.52% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Collaborator

@Autoparallel Autoparallel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@Autoparallel Autoparallel merged commit 8c0cee1 into main Aug 17, 2023
6 checks passed
@Autoparallel Autoparallel deleted the bug/filter_test_termination branch August 28, 2023 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: filter_address() and filter_topics() tests hang forever
2 participants