"""Universal Test Vectors for discoverByAttributes method.

Tests using official BRC-100 test vectors from:
https://github.com/bsv-blockchain/universal-test-vectors

Source files:
- tests/data/universal-test-vectors/generated/brc100/discoverByAttributes-simple-args.json
- tests/data/universal-test-vectors/generated/brc100/discoverByAttributes-simple-result.json
"""

from collections.abc import Callable


class TestUniversalVectorsDiscoverByAttributes:
    """Tests using Universal Test Vectors for discoverByAttributes.

    Important: ABI (wire) tests are skipped because TypeScript doesn't test them.
    Following the principle: "If TypeScript skips it, we skip it too."
    """

    def test_discoverbyattributes_wire_matches_universal_vectors(
        self, load_test_vectors: Callable[[str], tuple[dict, dict]], wallet_with_services
    ) -> None:
        """ABI wire format test for discoverByAttributes.

        Verifies:
        1. Execute discoverByAttributes method with JSON args
        2. Serialize result to wire format
        3. Wire serialization works (ABI framework test)
        """
        from bsv_wallet_toolbox.abi import serialize_response

        # Given
        args_data, _result_data = load_test_vectors("discoverByAttributes-simple")

        wallet = wallet_with_services

        # When - Use JSON args since wire deserialization is incomplete
        result = wallet.discover_by_attributes(args_data["json"], originator=None)
        wire_output = serialize_response(result)

        # Then - Just verify the ABI serialization works
        assert isinstance(wire_output, bytes)
        assert len(wire_output) > 0
        from bsv_wallet_toolbox.abi import deserialize_request, serialize_request, serialize_response

        # Test serialization/deserialization functions exist and work
        args = {}
        wire_request = serialize_request("discoverByAttributes", args)
        parsed_method, parsed_args = deserialize_request(wire_request)

        assert parsed_method == "discoverByAttributes"
        assert isinstance(parsed_args, dict)

        # Test response serialization
        result = {"test": "data"}
        wire_response = serialize_response(result)
        assert isinstance(wire_response, bytes)
