diff --git a/tests/wrappers_tests/test_channel_lifecycle.py b/tests/wrappers_tests/test_channel_lifecycle.py index 7448934cd..5f9beee40 100644 --- a/tests/wrappers_tests/test_channel_lifecycle.py +++ b/tests/wrappers_tests/test_channel_lifecycle.py @@ -1,10 +1,13 @@ import pytest from src.node.wrappers_manager import WrapperManager +from src.node.wrapper_helpers import EventCollector, create_message_bindings CHANNEL_ID = "rc01-channel" CONTENT_TOPIC = "/test/1/channel/proto" SENDER_ID = "rc01-sender" +UNKNOWN_CHANNEL_ID = "rc02-unknown-channel" + @pytest.mark.smoke class TestChannelLifecycle: @@ -16,7 +19,8 @@ class TestChannelLifecycle: """ node_config.update({"mode": "Core"}) - create_node_result = WrapperManager.create_and_start(config=node_config) + collector = EventCollector() + create_node_result = WrapperManager.create_and_start(config=node_config, event_cb=collector.event_callback) assert create_node_result.is_ok(), f"Failed to create and start node: {create_node_result.err()}" node = create_node_result.ok_value @@ -28,5 +32,28 @@ class TestChannelLifecycle: duplicate_result = node.channel_create(CHANNEL_ID, CONTENT_TOPIC, SENDER_ID) assert duplicate_result.is_err(), f"duplicate channel_create must fail, got Ok({duplicate_result.ok_value!r})" assert f"channel already exists: {CHANNEL_ID}" in duplicate_result.err(), f"unexpected error message: {duplicate_result.err()!r}" + + assert collector.events == [], f"expected no events, got: {collector.events}" + finally: + node.stop_and_destroy() + + def test_rc02_send_on_unknown_channel_rejected(self, node_config): + """RC02: channel_send() to an id that was never created is rejected. + + The send must Err with "unknown channel: " and emit no events. + """ + node_config.update({"mode": "Core"}) + + collector = EventCollector() + create_node_result = WrapperManager.create_and_start(config=node_config, event_cb=collector.event_callback) + assert create_node_result.is_ok(), f"Failed to create and start node: {create_node_result.err()}" + node = create_node_result.ok_value + + try: + send_result = node.channel_send(UNKNOWN_CHANNEL_ID, create_message_bindings()) + assert send_result.is_err(), f"channel_send on unknown channel must fail, got Ok({send_result.ok_value!r})" + assert f"unknown channel: {UNKNOWN_CHANNEL_ID}" in send_result.err(), f"unexpected error message: {send_result.err()!r}" + + assert collector.events == [], f"expected no events, got: {collector.events}" finally: node.stop_and_destroy()