@@ -659,70 +659,75 @@ def test_ada_filter_case_insensitive(self, client, network, symbol):
659659 @allure .story ("Currency Filtering" )
660660 @pytest .mark .pruning_compatible
661661 def test_native_asset_filtering_by_ascii_symbol (self , client , network , network_data , is_pruned_instance ):
662- """Currency filter works with ASCII symbols (backwards compat in v1.3.3 )."""
662+ """Currency filter with ASCII symbols should return error (negative test for v1.4.1+ )."""
663663 asset = network_data ["assets" ][0 ]
664- hex_symbol = asset ["symbol" ].encode ().hex ().lower () # Lowercase hex
665664
666- # Search by ASCII symbol (backwards compat )
665+ # Search by ASCII symbol (should return error in v1.4.1+ )
667666 response = client .search_transactions (
668667 network = network ,
669668 currency = {"symbol" : asset ["symbol" ], "decimals" : asset ["decimals" ]},
670669 )
671- assert response .status_code == 200
672-
673- # Verify returns transactions
674- txs = response .json ()["transactions" ]
675- assert len (txs ) > 0 , "Currency filter should return transactions"
676670
677- # Verify transactions contain the asset (in metadata.tokenBundle)
678- for tx in txs :
679- found_asset = False
680- for op in tx ["transaction" ]["operations" ]:
681- # Check metadata.tokenBundle for native assets
682- if "metadata" in op and "tokenBundle" in op ["metadata" ]:
683- for bundle in op ["metadata" ]["tokenBundle" ]:
684- for token in bundle .get ("tokens" , []):
685- if token ["currency" ]["symbol" ].lower () == hex_symbol :
686- found_asset = True
687- break
671+ # API should return error for non-hex-encoded symbols
672+ assert response .status_code == 500 , (
673+ f"Expected error status code when using ASCII symbol '{ asset ['symbol' ]} '"
674+ )
688675
689- assert found_asset , (
690- f"Transaction must contain native asset with hex symbol { hex_symbol } "
691- )
676+ error_data = response .json ()
677+ assert error_data ["code" ] == 5059 , "Expected error code 5059 for non-hex symbol"
678+ assert "hex-encoded" in error_data ["message" ].lower (), (
679+ "Error message should mention hex encoding requirement"
680+ )
681+ assert asset ["symbol" ] in error_data .get ("details" , {}).get ("message" , "" ), (
682+ f"Error details should mention the invalid symbol '{ asset ['symbol' ]} '"
683+ )
692684
693685 @allure .feature ("Search Transactions" )
694686 @allure .story ("Currency Filtering" )
695- @pytest .mark .skip (
696- reason = "Currency filter + limit parameter causes timeout (#615)"
697- )
687+ # TODO: investigate and update the ticket; seems to be working now, although response time is ~2min
688+ # @pytest.mark.skip(
689+ # reason="Currency filter + limit parameter causes timeout (#615)"
690+ # )
698691 def test_currency_filter_with_limit_parameter (self , client , network , network_data ):
699692 """Currency filter with explicit limit should not cause timeout."""
700693 asset = network_data ["assets" ][0 ]
701694
702695 # This combination causes 600s+ timeout in v1.3.3
703696 response = client .search_transactions (
704697 network = network ,
705- currency = {"symbol" : asset ["symbol " ], "decimals" : asset ["decimals" ]},
698+ currency = {"symbol" : asset ["symbol_hex " ], "decimals" : asset ["decimals" ]},
706699 limit = 1 ,
707700 )
708701 assert response .status_code == 200
709702
710703 txs = response .json ()["transactions" ]
711- assert len (txs ) <= 1 , "Should respect limit parameter"
704+ assert len (txs ) == 1 , "Should respect limit parameter"
705+
706+ # Verify the returned transaction contains the filtered asset
707+ tx = txs [0 ]
708+ currencies_in_tx = []
709+ for op in tx ["transaction" ]["operations" ]:
710+ if "metadata" in op and "tokenBundle" in op ["metadata" ]:
711+ for bundle in op ["metadata" ]["tokenBundle" ]:
712+ for token in bundle .get ("tokens" , []):
713+ currencies_in_tx .append (token ["currency" ]["symbol" ].lower ())
714+
715+ assert asset ["symbol_hex" ].lower () in currencies_in_tx , (
716+ f"Transaction must contain filtered asset { asset ['symbol_hex' ]} . "
717+ f"Found currencies: { currencies_in_tx } "
718+ )
712719
713720 @allure .feature ("Search Transactions" )
714721 @allure .story ("Currency Filtering" )
715- @pytest .mark .skip (
716- reason = "Hex symbol search not working until v1.4.x (#610)"
717- )
718- def test_currency_filter_with_hex_encoded_symbol (self , client , network , network_data ):
719- """Currency filter should accept hex-encoded symbols (canonical format in v1.4.x+)."""
722+ @pytest .mark .pruning_compatible
723+ def test_currency_filter_with_hex_encoded_symbol (self , client , network , network_data , is_pruned_instance ):
724+ """Currency filter accepts hex-encoded symbols (canonical format in v1.4.x+, issue #610 fixed)."""
720725 asset = network_data ["assets" ][0 ]
721726
722- # Convert ASCII symbol to hex (canonical format)
723- hex_symbol = asset ["symbol" ]. encode (). hex (). upper () # "tTEURO" → "74544555524F "
727+ # Use hex-encoded symbol from test data (canonical format)
728+ hex_symbol = asset ["symbol_hex" ] # e.g., "74544555524f "
724729
725- # Search by hex-encoded symbol (will work in v1.4.x when #610 is fixed )
730+ # Search by hex-encoded symbol (supported in v1.4.x+ after #610 fix )
726731 response = client .search_transactions (
727732 network = network ,
728733 currency = {"symbol" : hex_symbol , "decimals" : asset ["decimals" ]},
@@ -732,49 +737,59 @@ def test_currency_filter_with_hex_encoded_symbol(self, client, network, network_
732737 txs = response .json ()["transactions" ]
733738 assert len (txs ) > 0 , "Hex symbol search should return transactions"
734739
735- # Verify transactions contain the asset
740+ # Verify ALL transactions contain the filtered asset (currency filter was applied)
736741 for tx in txs :
737- currencies = [
738- op ["amount" ]["currency" ]["symbol" ]
739- for op in tx .get ("operations" , [])
740- if "amount" in op and "currency" in op ["amount" ]
741- ]
742- # In v1.4.x+, API will return hex symbols
743- assert hex_symbol in currencies , \
744- "Currency filter with hex symbol should return matching transactions"
742+ # Collect all currency symbols from tokenBundle across all operations
743+ currencies_in_tx = []
744+ for op in tx ["transaction" ]["operations" ]:
745+ # Native assets are always in tokenBundle (they sit in UTXOs with ADA)
746+ if "metadata" in op and "tokenBundle" in op ["metadata" ]:
747+ for bundle in op ["metadata" ]["tokenBundle" ]:
748+ for token in bundle .get ("tokens" , []):
749+ currencies_in_tx .append (token ["currency" ]["symbol" ].lower ())
750+
751+ # Assert filtered currency is in this transaction
752+ assert hex_symbol .lower () in currencies_in_tx , (
753+ f"Transaction must contain native asset with hex symbol { hex_symbol } in tokenBundle. "
754+ f"Found currencies: { currencies_in_tx } "
755+ )
745756
746757 @allure .feature ("Search Transactions" )
747758 @allure .story ("Currency Filtering" )
748759 @pytest .mark .pruning_compatible
749760 def test_native_asset_filtering_with_policy_id (self , client , network , network_data , is_pruned_instance ):
750- """Test currency filtering with metadata.policyId."""
761+ """Test currency filtering with hex-encoded symbol and metadata.policyId."""
751762 asset = network_data ["assets" ][0 ]
752763
753- # Search by asset with policyId in metadata
764+ # Search by hex-encoded asset symbol with policyId in metadata
754765 response = client .search_transactions (
755766 network = network ,
756767 currency = {
757- "symbol" : asset ["symbol " ],
768+ "symbol" : asset ["symbol_hex " ],
758769 "decimals" : asset ["decimals" ],
759770 "metadata" : {"policyId" : asset ["policy_id" ]}
760771 },
761772 )
762773 assert response .status_code == 200
763774
764- # Verify all returned transactions contain this specific asset with policyId
775+ # Verify ALL transactions contain the filtered asset with matching policyId and symbol
765776 txs = response .json ()["transactions" ]
766777 assert len (txs ) > 0 , "Currency filter with policyId should return transactions"
767778
768779 for tx in txs :
769- # Check metadata. tokenBundle for matching policyId
770- found_asset = False
780+ # Collect all (policyId, symbol) pairs from tokenBundle across all operations
781+ assets_in_tx = []
771782 for op in tx ["transaction" ]["operations" ]:
772783 if "metadata" in op and "tokenBundle" in op ["metadata" ]:
773784 for bundle in op ["metadata" ]["tokenBundle" ]:
774- if bundle .get ("policyId" ) == asset ["policy_id" ]:
775- found_asset = True
776- break
777-
778- assert found_asset , (
779- f"Transaction must contain asset with policyId { asset ['policy_id' ]} "
785+ policy_id = bundle .get ("policyId" )
786+ for token in bundle .get ("tokens" , []):
787+ symbol = token ["currency" ]["symbol" ].lower ()
788+ assets_in_tx .append ((policy_id , symbol ))
789+
790+ # Assert filtered asset (policyId + symbol) is in this transaction
791+ expected_asset = (asset ["policy_id" ], asset ["symbol_hex" ].lower ())
792+ assert expected_asset in assets_in_tx , (
793+ f"Transaction must contain asset with policyId { asset ['policy_id' ]} "
794+ f"and symbol { asset ['symbol_hex' ]} . Found assets: { assets_in_tx } "
780795 )
0 commit comments