|
3 | 3 | """ |
4 | 4 |
|
5 | 5 | import pytest |
| 6 | +import datetime |
6 | 7 |
|
7 | 8 | from hiero_sdk_python.account.account_create_transaction import AccountCreateTransaction |
8 | 9 | from hiero_sdk_python.account.account_id import AccountId |
@@ -201,40 +202,54 @@ def test_integration_account_update_transaction_invalid_auto_renew_period(env): |
201 | 202 | f"but got {ResponseCode(receipt.status).name}" |
202 | 203 | ) |
203 | 204 |
|
| 205 | +def _apply_tiny_max_fee_if_supported(tx, client) -> bool: |
| 206 | + # Try tx-level setters |
| 207 | + for attr in ("set_max_transaction_fee", "set_max_fee", "set_transaction_fee"): |
| 208 | + if hasattr(tx, attr): |
| 209 | + getattr(tx, attr)(Hbar.from_tinybars(1)) |
| 210 | + return True |
| 211 | + # Try client-level default |
| 212 | + for attr in ("set_default_max_transaction_fee", "set_max_transaction_fee", |
| 213 | + "set_default_max_fee", "setMaxTransactionFee"): |
| 214 | + if hasattr(client, attr): |
| 215 | + getattr(client, attr)(Hbar.from_tinybars(1)) |
| 216 | + return True |
| 217 | + return False |
204 | 218 |
|
205 | 219 | @pytest.mark.integration |
206 | | -def test_integration_account_update_transaction_insufficient_fee_large_expiration(env): |
207 | | - """Test that AccountUpdateTransaction fails with insufficient fee for large expiration time.""" |
208 | | - # Create initial account |
| 220 | +def test_account_update_insufficient_fee_with_valid_expiration_bump(env): |
| 221 | + """If we can cap the fee, a small valid expiration bump should fail with INSUFFICIENT_TX_FEE; otherwise skip.""" |
| 222 | + # Create account |
209 | 223 | receipt = ( |
210 | 224 | AccountCreateTransaction() |
211 | 225 | .set_key(env.operator_key.public_key()) |
212 | 226 | .set_initial_balance(Hbar(1)) |
213 | 227 | .execute(env.client) |
214 | 228 | ) |
215 | | - assert ( |
216 | | - receipt.status == ResponseCode.SUCCESS |
217 | | - ), f"Account creation failed with status: {ResponseCode(receipt.status).name}" |
218 | | - |
| 229 | + assert receipt.status == ResponseCode.SUCCESS |
219 | 230 | account_id = receipt.account_id |
220 | | - assert account_id is not None, "Account ID should not be None" |
221 | 231 |
|
222 | | - # Try to update with a very large expiration time that would require higher fees |
223 | | - large_expiration = Timestamp(seconds=int(1e11), nanos=0) |
224 | | - receipt = ( |
| 232 | + # Use the account's *current* expiration and bump it slightly forward |
| 233 | + info = AccountInfoQuery(account_id).execute(env.client) |
| 234 | + base_expiry_secs = int(info.expiration_time.seconds) |
| 235 | + |
| 236 | + delta_seconds = 60 * 60 * 24 # +1 day; typically valid |
| 237 | + new_expiry = Timestamp(seconds=base_expiry_secs + delta_seconds, nanos=0) |
| 238 | + |
| 239 | + tx = ( |
225 | 240 | AccountUpdateTransaction() |
226 | 241 | .set_account_id(account_id) |
227 | | - .set_expiration_time(large_expiration) |
228 | | - .execute(env.client) |
| 242 | + .set_expiration_time(new_expiry) |
229 | 243 | ) |
230 | 244 |
|
231 | | - # Should fail with INSUFFICIENT_TX_FEE |
| 245 | + if not _apply_tiny_max_fee_if_supported(tx, env.client): |
| 246 | + pytest.skip("SDK lacks a max-fee API; cannot deterministically trigger INSUFFICIENT_TX_FEE.") |
| 247 | + |
| 248 | + receipt = tx.execute(env.client) |
232 | 249 | assert receipt.status == ResponseCode.INSUFFICIENT_TX_FEE, ( |
233 | | - f"Account update should have failed with status INSUFFICIENT_TX_FEE, " |
234 | | - f"but got {ResponseCode(receipt.status).name}" |
| 250 | + f"Expected INSUFFICIENT_TX_FEE but got {ResponseCode(receipt.status).name}" |
235 | 251 | ) |
236 | 252 |
|
237 | | - |
238 | 253 | @pytest.mark.integration |
239 | 254 | def test_integration_account_update_transaction_with_only_account_id(env): |
240 | 255 | """Test that AccountUpdateTransaction can execute with only account ID set.""" |
|
0 commit comments