-
Notifications
You must be signed in to change notification settings - Fork 298
fix: prevent duplicate signatures in _signature_map #2219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
aceppaluni
merged 12 commits into
hiero-ledger:main
from
mohityadav8:fix/signature-deduplication
May 4, 2026
Merged
Changes from 3 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
dbd9743
fix: prevent duplicate signatures in _signature_map
mohityadav8 25c7d60
Merge branch 'main' into fix/signature-deduplication
mohityadav8 6b1bc8c
fix: prevent duplicate signatures in _signature_map
mohityadav8 03023fd
fix: add amount to TokenMintTransaction in deduplication tests
mohityadav8 e368d7c
fix: guard against empty signature_map in deduplication tests
mohityadav8 a89df7e
Delete tests/unit/test_signature_deduplication.py
mohityadav8 140010a
Merge branch 'main' into fix/signature-deduplication
mohityadav8 d2705aa
Merge branch 'main' into fix/signature-deduplication
mohityadav8 5d060cf
fix: guard against empty signature_map in deduplication tests
mohityadav8 739cc99
Delete tests/unit/signature_deduplication_test.py
mohityadav8 37473f5
Merge branch 'main' into fix/signature-deduplication
mohityadav8 192591f
Merge branch 'main' into fix/signature-deduplication
mohityadav8 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # RENAME FILE TO: tests/unit/signature_deduplication_test.py | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from hiero_sdk_python.account.account_id import AccountId | ||
| from hiero_sdk_python.crypto.private_key import PrivateKey | ||
| from hiero_sdk_python.tokens.token_id import TokenId | ||
| from hiero_sdk_python.tokens.token_mint_transaction import TokenMintTransaction | ||
| from hiero_sdk_python.transaction.transaction_id import TransactionId | ||
|
|
||
|
|
||
| def test_duplicate_signature_not_added(): | ||
| tx = TokenMintTransaction() | ||
| tx.set_transaction_id(TransactionId.generate(AccountId(0, 0, 1234))) | ||
| tx.set_node_account_id(AccountId(0, 0, 3)) | ||
| tx.set_token_id(TokenId(0, 0, 1)) | ||
| key = PrivateKey.generate_ed25519() | ||
| tx.freeze() | ||
| tx.sign(key) | ||
| tx.sign(key) | ||
| body_bytes = next(iter(tx._signature_map.keys())) | ||
| sig_pairs = tx._signature_map[body_bytes].sigPair | ||
| assert len(sig_pairs) == 1, "Expected 1 signature for duplicate key" | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
|
|
||
|
|
||
| def test_multiple_keys_still_work(): | ||
| tx = TokenMintTransaction() | ||
| tx.set_transaction_id(TransactionId.generate(AccountId(0, 0, 1234))) | ||
| tx.set_node_account_id(AccountId(0, 0, 3)) | ||
| tx.set_token_id(TokenId(0, 0, 1)) | ||
| key1 = PrivateKey.generate_ed25519() | ||
| key2 = PrivateKey.generate_ed25519() | ||
| tx.freeze() | ||
| tx.sign(key1) | ||
| tx.sign(key2) | ||
| body_bytes = next(iter(tx._signature_map.keys())) | ||
| sig_pairs = tx._signature_map[body_bytes].sigPair | ||
| assert len(sig_pairs) == 2, "Expected 2 signatures for different keys" | ||
| pubkey_prefixes = {sp.pubKeyPrefix for sp in sig_pairs} | ||
| expected_prefixes = { | ||
| key1.public_key().to_bytes(), | ||
| key2.public_key().to_bytes(), | ||
| } | ||
| assert pubkey_prefixes == expected_prefixes, "Signatures should match key1 and key2 exactly" | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from hiero_sdk_python.account.account_id import AccountId | ||
| from hiero_sdk_python.crypto.private_key import PrivateKey | ||
| from hiero_sdk_python.tokens.token_mint_transaction import TokenMintTransaction | ||
| from hiero_sdk_python.transaction.transaction_id import TransactionId | ||
|
|
||
|
|
||
| def test_duplicate_signature_not_added(): | ||
| tx = TokenMintTransaction() | ||
|
|
||
| tx.set_transaction_id(TransactionId.generate(AccountId(0, 0, 1234))) | ||
| tx.set_node_account_id(AccountId(0, 0, 3)) | ||
|
|
||
| key = PrivateKey.generate_ed25519() | ||
|
|
||
| tx.freeze() | ||
|
|
||
| tx.sign(key) | ||
| tx.sign(key) | ||
|
|
||
| body_bytes = next(iter(tx._signature_map.keys())) | ||
| sig_pairs = tx._signature_map[body_bytes].sigPair | ||
|
|
||
| assert len(sig_pairs) == 1, "Expected 1 signature for duplicate key" | ||
|
|
||
|
|
||
| def test_multiple_keys_still_work(): | ||
| tx = TokenMintTransaction() | ||
|
|
||
| tx.set_transaction_id(TransactionId.generate(AccountId(0, 0, 1234))) | ||
| tx.set_node_account_id(AccountId(0, 0, 3)) | ||
|
|
||
| key1 = PrivateKey.generate_ed25519() | ||
| key2 = PrivateKey.generate_ed25519() | ||
|
|
||
| tx.freeze() | ||
|
|
||
| tx.sign(key1) | ||
| tx.sign(key2) | ||
|
|
||
| body_bytes = next(iter(tx._signature_map.keys())) | ||
| sig_pairs = tx._signature_map[body_bytes].sigPair | ||
|
|
||
| assert len(sig_pairs) == 2, "Expected 2 signatures for different keys" | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
|
|
||
| pubkey_prefixes = {sp.pubKeyPrefix for sp in sig_pairs} | ||
| expected_prefixes = { | ||
| key1.public_key().to_bytes(), | ||
| key2.public_key().to_bytes(), | ||
| } | ||
|
|
||
| assert pubkey_prefixes == expected_prefixes, "Signatures should match key1 and key2 exactly" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.