MCPcopy Create free account
hub / github.com/BitVM/BitVM / test_is_zero

Function test_is_zero

bitvm/src/bigint/cmp.rs:281–365  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

279
280 #[test]
281 fn test_is_zero() {
282 let mut prng = ChaCha20Rng::seed_from_u64(2);
283
284 for _ in 0..100 {
285 let a: BigUint = prng.sample(RandomBits::new(254));
286 // assume that it would never be a zero when sampling a random element
287
288 let script = script! {
289 { U254::push_u32_le(&a.to_u32_digits()) }
290 { U254::is_zero_keep_element(0) }
291 OP_NOT OP_TOALTSTACK
292 { U254::drop() }
293 OP_FROMALTSTACK
294 };
295 run(script);
296 }
297
298 for _ in 0..100 {
299 let a: BigUint = prng.sample(RandomBits::new(254));
300 // assume that it would never be a zero when sampling a random element
301
302 let script = script! {
303 { U254::push_u32_le(&a.to_u32_digits()) }
304 { U254::is_zero(0) }
305 OP_NOT
306 };
307 run(script);
308 }
309
310 for _ in 0..100 {
311 let a: BigUint = prng.sample(RandomBits::new(64));
312 // assume that it would never be a zero when sampling a random element
313
314 let script = script! {
315 { U64::push_u32_le(&a.to_u32_digits()) }
316 { U64::is_zero_keep_element(0) }
317 OP_NOT OP_TOALTSTACK
318 { U64::drop() }
319 OP_FROMALTSTACK
320 };
321 run(script);
322 }
323
324 for _ in 0..100 {
325 let a: BigUint = prng.sample(RandomBits::new(64));
326 // assume that it would never be a zero when sampling a random element
327
328 let script = script! {
329 { U64::push_u32_le(&a.to_u32_digits()) }
330 { U64::is_zero(0) }
331 OP_NOT
332 };
333 run(script);
334 }
335
336 let script = script! {
337 { U254::push_u32_le(&[0]) }
338 { U254::is_zero_keep_element(0) }

Callers

nothing calls this directly

Calls 1

runFunction · 0.85

Tested by

no test coverage detected