Skip to content

Commit 6b1bc8c

Browse files
committed
fix: prevent duplicate signatures in _signature_map
Signed-off-by: Mohit Yadav <ymohit799057@gmail.com>
1 parent 25c7d60 commit 6b1bc8c

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# RENAME FILE TO: tests/unit/signature_deduplication_test.py
2+
3+
from __future__ import annotations
4+
5+
from hiero_sdk_python.account.account_id import AccountId
6+
from hiero_sdk_python.crypto.private_key import PrivateKey
7+
from hiero_sdk_python.tokens.token_id import TokenId
8+
from hiero_sdk_python.tokens.token_mint_transaction import TokenMintTransaction
9+
from hiero_sdk_python.transaction.transaction_id import TransactionId
10+
11+
12+
def test_duplicate_signature_not_added():
13+
tx = TokenMintTransaction()
14+
tx.set_transaction_id(TransactionId.generate(AccountId(0, 0, 1234)))
15+
tx.set_node_account_id(AccountId(0, 0, 3))
16+
tx.set_token_id(TokenId(0, 0, 1))
17+
key = PrivateKey.generate_ed25519()
18+
tx.freeze()
19+
tx.sign(key)
20+
tx.sign(key)
21+
body_bytes = next(iter(tx._signature_map.keys()))
22+
sig_pairs = tx._signature_map[body_bytes].sigPair
23+
assert len(sig_pairs) == 1, "Expected 1 signature for duplicate key"
24+
25+
26+
def test_multiple_keys_still_work():
27+
tx = TokenMintTransaction()
28+
tx.set_transaction_id(TransactionId.generate(AccountId(0, 0, 1234)))
29+
tx.set_node_account_id(AccountId(0, 0, 3))
30+
tx.set_token_id(TokenId(0, 0, 1))
31+
key1 = PrivateKey.generate_ed25519()
32+
key2 = PrivateKey.generate_ed25519()
33+
tx.freeze()
34+
tx.sign(key1)
35+
tx.sign(key2)
36+
body_bytes = next(iter(tx._signature_map.keys()))
37+
sig_pairs = tx._signature_map[body_bytes].sigPair
38+
assert len(sig_pairs) == 2, "Expected 2 signatures for different keys"
39+
pubkey_prefixes = {sp.pubKeyPrefix for sp in sig_pairs}
40+
expected_prefixes = {
41+
key1.public_key().to_bytes(),
42+
key2.public_key().to_bytes(),
43+
}
44+
assert pubkey_prefixes == expected_prefixes, "Signatures should match key1 and key2 exactly"

0 commit comments

Comments
 (0)