|
9 | 9 | Dict, |
10 | 10 | Generator, |
11 | 11 | List, |
| 12 | + Sequence, |
12 | 13 | Tuple, |
13 | 14 | Union, |
14 | 15 | cast, |
|
44 | 45 | LogReceipt, |
45 | 46 | Nonce, |
46 | 47 | RPCEndpoint, |
| 48 | + TopicFilter, |
47 | 49 | TxData, |
48 | 50 | Wei, |
49 | 51 | ) |
@@ -580,6 +582,112 @@ async def test_async_eth_subscribe_creates_and_handles_logs_subscription_type( |
580 | 582 | sub_manager.total_handler_calls = 0 |
581 | 583 | await clean_up_task(emit_event_task) |
582 | 584 |
|
| 585 | + @pytest.mark.asyncio |
| 586 | + @pytest.mark.parametrize( |
| 587 | + "topics", |
| 588 | + [ |
| 589 | + pytest.param( |
| 590 | + [ |
| 591 | + HexStr( |
| 592 | + "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef" # noqa: E501 |
| 593 | + ) |
| 594 | + ], |
| 595 | + id="Single specific topic at position 0", |
| 596 | + ), |
| 597 | + pytest.param( |
| 598 | + [ |
| 599 | + None, |
| 600 | + HexStr( |
| 601 | + "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890" # noqa: E501 |
| 602 | + ), |
| 603 | + ], |
| 604 | + id="Wildcard at position 0, specific topic at position 1", |
| 605 | + ), |
| 606 | + pytest.param( |
| 607 | + [ |
| 608 | + [ |
| 609 | + HexStr( |
| 610 | + "0x1111111111111111111111111111111111111111111111111111111111111111" # noqa: E501 |
| 611 | + ), |
| 612 | + HexStr( |
| 613 | + "0x2222222222222222222222222222222222222222222222222222222222222222" # noqa: E501 |
| 614 | + ), |
| 615 | + ] |
| 616 | + ], |
| 617 | + id="OR pattern: topic A or B at position 0", |
| 618 | + ), |
| 619 | + pytest.param( |
| 620 | + [ |
| 621 | + [ |
| 622 | + HexStr( |
| 623 | + "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" # noqa: E501 |
| 624 | + ), |
| 625 | + HexStr( |
| 626 | + "0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" # noqa: E501 |
| 627 | + ), |
| 628 | + ], |
| 629 | + HexStr( |
| 630 | + "0xcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" # noqa: E501 |
| 631 | + ), |
| 632 | + ], |
| 633 | + id="Complex: (A or B) at position 0 AND C at position 1", |
| 634 | + ), |
| 635 | + pytest.param( |
| 636 | + [ |
| 637 | + HexBytes( |
| 638 | + "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef" # noqa: E501 |
| 639 | + ) |
| 640 | + ], |
| 641 | + id="Single specific topic at position 0 with HexBytes", |
| 642 | + ), |
| 643 | + pytest.param( |
| 644 | + [ |
| 645 | + [ |
| 646 | + HexBytes( |
| 647 | + "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" # noqa: E501 |
| 648 | + ), |
| 649 | + HexStr( |
| 650 | + "0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" # noqa: E501 |
| 651 | + ), |
| 652 | + b"\xcc" * 32, |
| 653 | + ] |
| 654 | + ], |
| 655 | + id="OR pattern with mixed HexBytes, HexStr, and bytes at position 0", |
| 656 | + ), |
| 657 | + ], |
| 658 | + ) |
| 659 | + async def test_async_logs_subscription_with_and_or_topic_patterns( |
| 660 | + self, |
| 661 | + async_w3: AsyncWeb3, |
| 662 | + async_emitter_contract: "AsyncContract", |
| 663 | + topics: Sequence[TopicFilter], |
| 664 | + ) -> None: |
| 665 | + """Test that LogsSubscription properly handles AND/OR topic patterns.""" |
| 666 | + sub_manager = async_w3.subscription_manager |
| 667 | + |
| 668 | + subscription = LogsSubscription( |
| 669 | + address=async_emitter_contract.address, |
| 670 | + topics=topics, |
| 671 | + handler=idle_handler, |
| 672 | + ) |
| 673 | + |
| 674 | + await sub_manager.subscribe(subscription) |
| 675 | + assert len(sub_manager.subscriptions) == 1 |
| 676 | + assert isinstance(sub_manager.subscriptions[0], LogsSubscription) |
| 677 | + assert sub_manager.subscriptions[0].topics == topics |
| 678 | + |
| 679 | + assert subscription.subscription_params == ( |
| 680 | + "logs", |
| 681 | + { |
| 682 | + "address": async_emitter_contract.address, |
| 683 | + "topics": topics, |
| 684 | + }, |
| 685 | + ) |
| 686 | + |
| 687 | + # clean up |
| 688 | + await sub_manager.unsubscribe(subscription) |
| 689 | + assert len(sub_manager.subscriptions) == 0 |
| 690 | + |
583 | 691 | @pytest.mark.asyncio |
584 | 692 | async def test_async_extradata_poa_middleware_on_eth_subscription( |
585 | 693 | self, |
|
0 commit comments