Skip to content

Conversation

@bigspider
Copy link
Contributor

@bigspider bigspider commented Mar 12, 2025

Adds two test cases for parsing an invalid key (despite it being 32-byte long).

Perhaps the test for ZERO is redundant, as 7 also has no square root, but it felt natural to add it anyway.

@apoelstra
Copy link
Member

apoelstra commented Mar 12, 2025

The CI failures are because when you compile with cfg secp256k1_fuzz, these do parse correctly, since with fuzzer mode on we don't actually parse public keys; we parse a key-like object. (Where "key-like" means "parses super fast and behaves enough like a key that it doesn't crash downstream stuff.)

I think the best solution is to add these tests as a new unit test with #[cfg(not(secp256k1_fuzz))] marked.

@bigspider
Copy link
Contributor Author

Actually, I just saw that there is a test_pubkey_from_bad_slice a few tests below, so I think my PR is pointless.
It might be worth moving them next to each other, and perhaps delete a few redundant test cases.

@bigspider
Copy link
Contributor Author

bigspider commented Mar 12, 2025

I did the slight refactor (without deleting any test) - feel free to merge or close as you please.

@bigspider bigspider changed the title Add invalid key testcases for XOnlyPublicKey::from_slice Rearrange tests for XOnlyPublicKey::from_slice Mar 13, 2025
Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK a4cb345; successfully ran local tests; yeah, sure. I think this makes the tests a bit easier to follow

@apoelstra apoelstra merged commit b6fd763 into rust-bitcoin:master Mar 13, 2025
29 of 30 checks passed
@bigspider bigspider deleted the from_slice_missing_test branch March 13, 2025 15:45
chain-forgexcr45 added a commit to chain-forgexcr45/rust-secp256k1 that referenced this pull request Sep 28, 2025
…icKey::from_slice`

a4cb34500884721d74ce9c0111fa9ad695ed889e Reposition test_pubkey_from_bad_slice, and move failing cases from test_pubkey_from_slice (Salvatore Ingala)

Pull request description:

  Adds two test cases for parsing an invalid key (despite it being 32-byte long).

  Perhaps the test for `ZERO` is redundant, as `7` also has no square root, but it felt natural to add it anyway.

ACKs for top commit:
  apoelstra:
    ACK a4cb34500884721d74ce9c0111fa9ad695ed889e; successfully ran local tests; yeah, sure. I think this makes the tests a bit easier to follow

Tree-SHA512: f5f7f3c175c65bd9f1bb589e18246c9155d8cbed2f43ff425757222cb64fe2ec6b0e793cef500ff3e20d33135c7065fe5a835c3f4693d1b801f71fe36db25a8d
william2332-limf added a commit to william2332-limf/rust-secp256k1 that referenced this pull request Oct 2, 2025
…icKey::from_slice`

a4cb34500884721d74ce9c0111fa9ad695ed889e Reposition test_pubkey_from_bad_slice, and move failing cases from test_pubkey_from_slice (Salvatore Ingala)

Pull request description:

  Adds two test cases for parsing an invalid key (despite it being 32-byte long).

  Perhaps the test for `ZERO` is redundant, as `7` also has no square root, but it felt natural to add it anyway.

ACKs for top commit:
  apoelstra:
    ACK a4cb34500884721d74ce9c0111fa9ad695ed889e; successfully ran local tests; yeah, sure. I think this makes the tests a bit easier to follow

Tree-SHA512: f5f7f3c175c65bd9f1bb589e18246c9155d8cbed2f43ff425757222cb64fe2ec6b0e793cef500ff3e20d33135c7065fe5a835c3f4693d1b801f71fe36db25a8d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants