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

Function test_add

bitvm/src/bigint/add.rs:551–585  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

549
550 #[test]
551 fn test_add() {
552 println!("U254.add: {} bytes", U254::add(1, 0).len());
553 let mut prng = ChaCha20Rng::seed_from_u64(0);
554 for _ in 0..100 {
555 let a: BigUint = prng.sample(RandomBits::new(254));
556 let b: BigUint = prng.sample(RandomBits::new(254));
557 let c: BigUint = (a.clone() + b.clone()).rem(BigUint::one().shl(254));
558
559 let script = script! {
560 { U254::push_u32_le(&a.to_u32_digits()) }
561 { U254::push_u32_le(&b.to_u32_digits()) }
562 { U254::add(1, 0) }
563 { U254::push_u32_le(&c.to_u32_digits()) }
564 { U254::equalverify(1, 0) }
565 OP_TRUE
566 };
567 run(script);
568 }
569
570 for _ in 0..100 {
571 let a: u64 = prng.gen();
572 let b: u64 = prng.gen();
573 let c = a.wrapping_add(b);
574
575 let script = script! {
576 { U64::push_u64_le(&[a]) }
577 { U64::push_u64_le(&[b]) }
578 { U64::add(1, 0) }
579 { U64::push_u64_le(&[c]) }
580 { U64::equalverify(1, 0) }
581 OP_TRUE
582 };
583 run(script);
584 }
585 }
586
587 #[test]
588 fn test_add1() {

Callers

nothing calls this directly

Calls 2

runFunction · 0.85
cloneMethod · 0.80

Tested by

no test coverage detected