Skip to content

Commit 3946719

Browse files
add tests, update variable name
1 parent 48ee270 commit 3946719

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

sdk/tests/arithmetic.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,39 @@ describe('Field and Group Arithmetic Tests', () => {
117117
const prod = i8.mulWrapped(i8);
118118
const quot = i8.divWrapped(i8);
119119

120+
expect(I8.fromString("0i8").neg().toString()).equal("0i8");
121+
expect(I8.fromString("-42i8").neg().toString()).equal("42i8");
122+
120123
expect(sum.toString()).equals("84i8");
121124
expect(diff.toString()).equals("0i8");
122125
expect(prod.toString()).equals("1764i8");
123126
expect(quot.toString()).equals("1i8");
127+
128+
const int = I8.fromString("42i8");
129+
const plaintext = int.toPlaintext();
130+
expect(plaintext.toString()).equal("42i8");
131+
132+
133+
const original = I8.fromString("12i8");
134+
const scalar = original.toScalar();
135+
const field = scalar.toField();
136+
const recreated = I8.fromField(field);
137+
expect(recreated.toString()).equal("12i8");
138+
139+
const f = Field.fromString("12field");
140+
const arr = new Array();
141+
arr.push(f.toString());
142+
const i16 = I16.fromFields(arr);
143+
expect(i16.toString()).equal("12i16");
144+
145+
const a = I8.fromString("7i8");
146+
const b = I8.fromString("3i8");
147+
148+
expect(a.rem(b).toString()).equal("1i8");
149+
expect(a.remWrapped(b).toString()).equal("1i8");
150+
151+
const base = I8.fromString("2i8");
152+
expect(base.powU8(U8.fromString("3u8")).toString()).equal("8i8");
124153
});
125154

126155
it('Check scalar field arithmetic', () => {

wasm/src/types/integer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ macro_rules! impl_integer {
163163
/// Convert to plaintext.
164164
#[wasm_bindgen(js_name = "toPlaintext")]
165165
pub fn to_plaintext(&self) -> Plaintext {
166-
Plaintext::from(PlaintextNative::Literal(LiteralNative::Integer(self.0), OnceCell::new()))
166+
Plaintext::from(PlaintextNative::Literal(LiteralNative::$name(self.0), OnceCell::new()))
167167
}
168168

169169
/// Convert from Field.

0 commit comments

Comments
 (0)