1111from hiero_sdk_python .tokens .token_id import TokenId
1212from hiero_sdk_python .query .transaction_record_query import TransactionRecordQuery
1313from tests .integration .utils_for_test import env , create_fungible_token , create_nft_token
14+ from typing import List
1415
1516pytestmark = pytest .mark .integration
1617
@@ -60,23 +61,35 @@ def has_immediate_credit(record, token_id: TokenId, account_id: AccountId, amoun
6061def has_new_pending (record ):
6162 return bool (record .new_pending_airdrops )
6263
63- def extract_pending_ids (record ):
64- ids = []
64+ def extract_pending_ids (record ) -> List [PendingAirdropId ]:
65+ """
66+ Extract a list of SDK PendingAirdropId objects from a transaction record.
67+ Handles both protobuf objects and already instantiated SDK objects.
68+ """
69+ sdk_ids : List [PendingAirdropId ] = []
70+
6571 for item in record .new_pending_airdrops :
66- # If it's already a PendingAirdropId object, just append
6772 if isinstance (item , PendingAirdropId ):
68- ids .append (item )
69- else :
70- # Attempt to extract the protobuf field
71- pid_proto = getattr (item , "pending_airdrop_id" , None )
72- if pid_proto is None and hasattr (item , "_to_proto" ):
73- pid_proto = item ._to_proto ().pending_airdrop_id
73+ # Already an SDK object
74+ sdk_ids .append (item )
75+ continue
7476
75- if pid_proto is None :
76- raise AssertionError (f"Cannot extract pending_airdrop_id from { type (item )} " )
77+ # Try to get protobuf object
78+ pid_proto = getattr (item , "pending_airdrop_id" , None )
79+ if pid_proto is None and hasattr (item , "_to_proto" ):
80+ pid_proto = item ._to_proto ().pending_airdrop_id
7781
78- ids .append (PendingAirdropId ._from_proto (pid_proto ))
79- return ids
82+ if pid_proto is None :
83+ raise AssertionError (f"Cannot extract pending_airdrop_id from { type (item )} " )
84+
85+ # Convert protobuf to SDK object
86+ if hasattr (pid_proto , "HasField" ):
87+ sdk_ids .append (PendingAirdropId ._from_proto (pid_proto ))
88+ else :
89+ # Already SDK object
90+ sdk_ids .append (pid_proto )
91+
92+ return sdk_ids
8093
8194def claim_pending (env , pending_ids , receiver_key ):
8295 tx = TokenClaimAirdropTransaction ().add_pending_airdrop_ids (pending_ids )
@@ -87,6 +100,17 @@ def claim_pending(env, pending_ids, receiver_key):
87100# --- Integration Tests ---
88101# ======================
89102
103+ def test_airdrop_becomes_pending_if_not_associated_no_sig_required (env ):
104+ receiver = env .create_account (initial_hbar = 2.0 )
105+ token_id = create_fungible_token (env )
106+
107+ set_receiver_signature_required (env , receiver .id , receiver .key , False )
108+
109+ record = submit_airdrop (env , receiver .id , token_id )
110+ # ✅ Expect it to be pending but not airdropped
111+ assert has_new_pending (record )
112+ assert not has_immediate_credit (record , token_id , receiver .id )
113+
90114def test_immediate_airdrop_if_associated_and_no_sig_required (env ):
91115 receiver = env .create_account (initial_hbar = 2.0 )
92116 token_id = create_fungible_token (env )
@@ -104,7 +128,9 @@ def test_pending_airdrop_if_unassociated_and_no_sig_required(env):
104128
105129 set_receiver_signature_required (env , receiver .id , receiver .key , False )
106130 record = submit_airdrop (env , receiver .id , token_id )
131+ # Becomes pending as not associated
107132 assert has_new_pending (record )
133+ # Can't auto claim because not associated
108134 assert not has_immediate_credit (record , token_id , receiver .id )
109135
110136def test_pending_airdrop_if_sig_required_even_if_associated (env ):
0 commit comments