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

Function test_ubigint_to_be_bits

bitvm/src/bigint/bits.rs:358–405  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

356
357 #[test]
358 fn test_ubigint_to_be_bits() {
359 let mut prng = ChaCha20Rng::seed_from_u64(0);
360
361 for _ in 0..10 {
362 let a: BigUint = prng.sample(RandomBits::new(U254::N_BITS as u64));
363
364 let mut bits = vec![];
365 let mut cur = a.clone();
366 for _ in 0..U254::N_BITS {
367 bits.push(if cur.bit(0) { 1 } else { 0 });
368 cur.shr_assign(1);
369 }
370
371 let script = script! {
372 { U254::push_u32_le(&a.to_u32_digits()) }
373 { U254::convert_to_be_bits() }
374 for i in 0..U254::N_BITS {
375 { bits[(U254::N_BITS - 1 - i) as usize] }
376 OP_EQUALVERIFY
377 }
378 OP_TRUE
379 };
380 run(script);
381 }
382
383 for _ in 0..10 {
384 let a: BigUint = prng.sample(RandomBits::new(U64::N_BITS as u64));
385
386 let mut bits = vec![];
387 let mut cur = a.clone();
388 for _ in 0..U64::N_BITS {
389 bits.push(if cur.bit(0) { 1 } else { 0 });
390 cur.shr_assign(1);
391 }
392
393 let script = script! {
394 { U64::push_u32_le(&a.to_u32_digits()) }
395 { U64::convert_to_be_bits() }
396 for i in 0..U64::N_BITS {
397 { bits[(U64::N_BITS - 1 - i) as usize] }
398 OP_EQUALVERIFY
399 }
400 OP_TRUE
401 };
402
403 run(script);
404 }
405 }
406
407 #[test]
408 fn test_ubigint_to_le_bits() {

Callers

nothing calls this directly

Calls 3

runFunction · 0.85
cloneMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected