Skip to content

Commit caff615

Browse files
authored
chore: fix airdrop test names for pytest (#762)
Signed-off-by: exploreriii <[email protected]>
1 parent 12cee39 commit caff615

File tree

3 files changed

+40
-13
lines changed

3 files changed

+40
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
1515

1616

1717
### Fixed
18+
- chore: fixed integration test names without a test prefix or postfix
1819

1920

2021

tests/integration/token_airdrop_transaction_claim_e2e.py renamed to tests/integration/token_airdrop_transaction_claim_e2e_test.py

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from hiero_sdk_python.tokens.token_id import TokenId
1212
from hiero_sdk_python.query.transaction_record_query import TransactionRecordQuery
1313
from tests.integration.utils_for_test import env, create_fungible_token, create_nft_token
14+
from typing import List
1415

1516
pytestmark = pytest.mark.integration
1617

@@ -60,23 +61,35 @@ def has_immediate_credit(record, token_id: TokenId, account_id: AccountId, amoun
6061
def 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

8194
def 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+
90114
def 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

110136
def test_pending_airdrop_if_sig_required_even_if_associated(env):

0 commit comments

Comments
 (0)