|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from hiero_sdk_python.account.account_id import AccountId |
| 4 | +from hiero_sdk_python.crypto.private_key import PrivateKey |
| 5 | +from hiero_sdk_python.tokens.token_mint_transaction import TokenMintTransaction |
| 6 | +from hiero_sdk_python.transaction.transaction_id import TransactionId |
| 7 | + |
| 8 | + |
| 9 | +def test_duplicate_signature_not_added(): |
| 10 | + tx = TokenMintTransaction() |
| 11 | + |
| 12 | + tx.set_transaction_id(TransactionId.generate(AccountId(0, 0, 1234))) |
| 13 | + tx.set_node_account_id(AccountId(0, 0, 3)) |
| 14 | + |
| 15 | + key = PrivateKey.generate_ed25519() |
| 16 | + |
| 17 | + tx.freeze() |
| 18 | + |
| 19 | + tx.sign(key) |
| 20 | + tx.sign(key) |
| 21 | + |
| 22 | + body_bytes = next(iter(tx._signature_map.keys())) |
| 23 | + sig_pairs = tx._signature_map[body_bytes].sigPair |
| 24 | + |
| 25 | + assert len(sig_pairs) == 1, "Expected 1 signature for duplicate key" |
| 26 | + |
| 27 | + |
| 28 | +def test_multiple_keys_still_work(): |
| 29 | + tx = TokenMintTransaction() |
| 30 | + |
| 31 | + tx.set_transaction_id(TransactionId.generate(AccountId(0, 0, 1234))) |
| 32 | + tx.set_node_account_id(AccountId(0, 0, 3)) |
| 33 | + |
| 34 | + key1 = PrivateKey.generate_ed25519() |
| 35 | + key2 = PrivateKey.generate_ed25519() |
| 36 | + |
| 37 | + tx.freeze() |
| 38 | + |
| 39 | + tx.sign(key1) |
| 40 | + tx.sign(key2) |
| 41 | + |
| 42 | + body_bytes = next(iter(tx._signature_map.keys())) |
| 43 | + sig_pairs = tx._signature_map[body_bytes].sigPair |
| 44 | + |
| 45 | + assert len(sig_pairs) == 2, "Expected 2 signatures for different keys" |
0 commit comments