Merge rust-bitcoin/rust-bitcoin#2463: Add conditional check for debug_assertions

1d13020129 test: Add conditional check for debug_assertions (yancy)

Pull request description:

  Currently running `cargo test --release` blows up because of the tests that panic.  This PR adds a conditional check `debug_assertions` which causes those tests to not be run in release mode.  Besides fixing `cargo test --release` this PR sets the stage for a larger PR to test arithmetic tests that are `unchecked` (will overflow in release mode instead of panic) started here https://github.com/rust-bitcoin/rust-bitcoin/pull/2436.  Also I think we ought to add `cargo test --release` to CI.

ACKs for top commit:
  Kixunil:
    ACK 1d13020129
  apoelstra:
    ACK 1d13020129

Tree-SHA512: 8964af57d20e314f491261b280ade053de03f5cb6a2857208b3cc16a9b39fa37fa4044cec84a46e35eac2a4b2637ebbd1c250817aab397b8a30f620eb61725fc
This commit is contained in:
Andrew Poelstra 2024-02-12 00:57:21 +00:00
commit 4523034ba3
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
4 changed files with 8 additions and 0 deletions

View File

@ -489,6 +489,7 @@ mod test {
} }
#[test] #[test]
#[cfg(debug_assertions)]
#[should_panic] // 'attempt to add with overflow' in consensus_encode() #[should_panic] // 'attempt to add with overflow' in consensus_encode()
fn test_getblocktx_panic_when_encoding_u64_max() { fn test_getblocktx_panic_when_encoding_u64_max() {
serialize(&BlockTransactionsRequest { serialize(&BlockTransactionsRequest {

View File

@ -190,6 +190,7 @@ mod tests {
} }
#[test] #[test]
#[cfg(debug_assertions)]
#[should_panic] #[should_panic]
fn from_sat_per_vb_unchecked_panic_test() { FeeRate::from_sat_per_vb_unchecked(u64::MAX); } fn from_sat_per_vb_unchecked_panic_test() { FeeRate::from_sat_per_vb_unchecked(u64::MAX); }

View File

@ -182,6 +182,7 @@ mod tests {
} }
#[test] #[test]
#[cfg(debug_assertions)]
#[should_panic] #[should_panic]
fn from_vb_unchecked_panic() { Weight::from_vb_unchecked(u64::MAX); } fn from_vb_unchecked_panic() { Weight::from_vb_unchecked(u64::MAX); }

View File

@ -1692,22 +1692,27 @@ mod tests {
} }
#[test] #[test]
#[cfg(debug_assertions)]
#[should_panic] #[should_panic]
fn u256_overflowing_addition_panics() { let _ = U256::MAX + U256::ONE; } fn u256_overflowing_addition_panics() { let _ = U256::MAX + U256::ONE; }
#[test] #[test]
#[cfg(debug_assertions)]
#[should_panic] #[should_panic]
fn u256_overflowing_subtraction_panics() { let _ = U256::ZERO - U256::ONE; } fn u256_overflowing_subtraction_panics() { let _ = U256::ZERO - U256::ONE; }
#[test] #[test]
#[cfg(debug_assertions)]
#[should_panic] #[should_panic]
fn u256_multiplication_by_max_panics() { let _ = U256::MAX * U256::MAX; } fn u256_multiplication_by_max_panics() { let _ = U256::MAX * U256::MAX; }
#[test] #[test]
#[cfg(debug_assertions)]
#[should_panic] #[should_panic]
fn work_overflowing_addition_panics() { let _ = Work(U256::MAX) + Work(U256::ONE); } fn work_overflowing_addition_panics() { let _ = Work(U256::MAX) + Work(U256::ONE); }
#[test] #[test]
#[cfg(debug_assertions)]
#[should_panic] #[should_panic]
fn work_overflowing_subtraction_panics() { let _ = Work(U256::ZERO) - Work(U256::ONE); } fn work_overflowing_subtraction_panics() { let _ = Work(U256::ZERO) - Work(U256::ONE); }