Skip to content

Commit 4f23206

Browse files
update Boolean type and tests
1 parent 415d497 commit 4f23206

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

sdk/tests/arithmetic.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ describe('Field and Group Arithmetic Tests', () => {
4545
});
4646

4747
it('Check boolean creation and serialization', () => {
48-
const t = Boolean.one();
49-
const f = Boolean.zero();
48+
const t = Boolean.fromString("true");
49+
const f = Boolean.fromString("false");
5050

5151
expect(t.toString()).equals("true");
5252
expect(f.toString()).equals("false");
@@ -71,8 +71,8 @@ describe('Field and Group Arithmetic Tests', () => {
7171
});
7272

7373
it('Check boolean logical operations', () => {
74-
const t = Boolean.one();
75-
const f = Boolean.zero();
74+
const t = new Boolean(true);
75+
const f = new Boolean(false);
7676

7777
expect(t.not().toString()).equals("false");
7878
expect(f.not().toString()).equals("true");

wasm/src/types/boolean.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::{
2020
to_bits_array_le,
2121
types::native::{BooleanNative, LiteralNative, PlaintextNative},
2222
};
23-
use snarkvm_console::prelude::{Double, FromBits, FromBytes, One, Pow, ToBits, ToBytes, Zero};
23+
use snarkvm_console::prelude::{FromBits, FromBytes, ToBits, ToBytes, Zero};
2424
use snarkvm_wasm::utilities::Uniform;
2525

2626
use js_sys::{Array, Uint8Array};
@@ -36,6 +36,12 @@ pub struct Boolean(BooleanNative);
3636

3737
#[wasm_bindgen]
3838
impl Boolean {
39+
/// Creates a Boolean from a native JS bool.
40+
#[wasm_bindgen(constructor)]
41+
pub fn new(value: bool) -> Boolean {
42+
Boolean(BooleanNative::new(value))
43+
}
44+
3945
/// Creates a boolean object from a string representation ("true"/"false").
4046
#[wasm_bindgen(js_name = "fromString")]
4147
#[allow(clippy::should_implement_trait)]
@@ -135,15 +141,6 @@ impl Boolean {
135141
self.0 == BooleanNative::from(other)
136142
}
137143

138-
/// `false`
139-
pub fn zero() -> Boolean {
140-
Boolean(BooleanNative::zero())
141-
}
142-
143-
/// `true`
144-
pub fn one() -> Boolean {
145-
Boolean(BooleanNative::one())
146-
}
147144
}
148145

149146
impl Deref for Boolean {

0 commit comments

Comments
 (0)