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

Function test_sub

bitvm/src/bigint/sub.rs:106–162  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

104
105 #[test]
106 fn test_sub() {
107 let mut prng = ChaCha20Rng::seed_from_u64(0);
108
109 for _ in 0..100 {
110 let a: BigUint = prng.sample(RandomBits::new(254));
111 let b: BigUint = prng.sample(RandomBits::new(254));
112 let mut c: BigUint = BigUint::one().shl(254) + &a - &b;
113 c = c.rem(BigUint::one().shl(254));
114
115 let script = script! {
116 { U254::push_u32_le(&a.to_u32_digits()) }
117 { U254::push_u32_le(&b.to_u32_digits()) }
118 { U254::sub(1, 0) }
119 { U254::push_u32_le(&c.to_u32_digits()) }
120 { U254::equalverify(1, 0) }
121 OP_TRUE
122 };
123 run(script);
124
125 let script = script! {
126 { U254::push_u32_le(&b.to_u32_digits()) }
127 { U254::push_u32_le(&a.to_u32_digits()) }
128 { U254::sub(0, 1) }
129 { U254::push_u32_le(&c.to_u32_digits()) }
130 { U254::equalverify(1, 0) }
131 OP_TRUE
132 };
133 run(script);
134 }
135
136 for _ in 0..100 {
137 let a: BigUint = prng.sample(RandomBits::new(64));
138 let b: BigUint = prng.sample(RandomBits::new(64));
139 let mut c: BigUint = BigUint::one().shl(64) + &a - &b;
140 c = c.rem(BigUint::one().shl(64));
141
142 let script = script! {
143 { U64::push_u32_le(&a.to_u32_digits()) }
144 { U64::push_u32_le(&b.to_u32_digits()) }
145 { U64::sub(1, 0) }
146 { U64::push_u32_le(&c.to_u32_digits()) }
147 { U64::equalverify(1, 0) }
148 OP_TRUE
149 };
150 run(script);
151
152 let script = script! {
153 { U64::push_u32_le(&b.to_u32_digits()) }
154 { U64::push_u32_le(&a.to_u32_digits()) }
155 { U64::sub(0, 1) }
156 { U64::push_u32_le(&c.to_u32_digits()) }
157 { U64::equalverify(1, 0) }
158 OP_TRUE
159 };
160 run(script);
161 }
162 }
163

Callers

nothing calls this directly

Calls 1

runFunction · 0.85

Tested by

no test coverage detected