Skip to content

Commit 63cc025

Browse files
export integer types and add testing
1 parent 689726c commit 63cc025

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

sdk/src/browser.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ export {
7373
EncryptionToolkit,
7474
Field,
7575
Group,
76+
I8,
77+
I16,
78+
I32,
7679
OfflineQuery,
7780
Pedersen64,
7881
Pedersen128,
@@ -91,6 +94,9 @@ export {
9194
Scalar,
9295
Transaction,
9396
Transition,
97+
U8,
98+
U16,
99+
U32,
94100
VerifyingKey,
95101
ViewKey,
96102
initThreadPool,

sdk/src/wasm.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ export {
1414
ExecutionResponse,
1515
Field,
1616
Group,
17+
I8,
18+
I16,
19+
I32,
1720
OfflineQuery,
1821
Metadata,
1922
Pedersen64,
@@ -33,6 +36,9 @@ export {
3336
Signature,
3437
Transaction,
3538
Transition,
39+
U8,
40+
U16,
41+
U32,
3642
VerifyingKey,
3743
ViewKey,
3844
initThreadPool,

sdk/tests/arithmetic.test.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sinon from "sinon";
22
import { expect } from "chai";
3-
import { Field, Scalar, Group, Boolean} from "../src/node.js";
3+
import { Field, Scalar, Group, Boolean, I8, I16, I32, U8, U16, U32} from "../src/node.js";
44
import { FieldGenerator, GroupGenerator, ScalarGenerator } from "./data/algebra.js";
55

66
describe('Field and Group Arithmetic Tests', () => {
@@ -96,6 +96,33 @@ describe('Field and Group Arithmetic Tests', () => {
9696
expect(t.nor(f).toString()).equals("false");
9797
});
9898

99+
it('Check integer serialization and arithmetic', () => {
100+
const i8 = I8.fromString("42i8");
101+
const i8Neg = i8.absChecked().neg();
102+
const i8Clone = i8.clone();
103+
104+
expect(i8.toString()).equals("42i8");
105+
expect(i8Clone.equals(i8)).equal(true);
106+
107+
const i8Bytes = i8.toBytesLe();
108+
const i8FromBytes = I8.fromBytesLe(i8Bytes);
109+
expect(i8.equals(i8FromBytes)).equal(true);
110+
111+
const i8Bits = i8.toBitsLe();
112+
const i8FromBits = I8.fromBitsLe(i8Bits);
113+
expect(i8.equals(i8FromBits)).equal(true);
114+
115+
const sum = i8.addWrapped(i8);
116+
const diff = i8.subWrapped(i8);
117+
const prod = i8.mulWrapped(i8);
118+
const quot = i8.divWrapped(i8);
119+
120+
expect(sum).to.not.be.undefined;
121+
expect(diff).to.not.be.undefined;
122+
expect(prod).to.not.be.undefined;
123+
expect(quot).to.not.be.undefined;
124+
});
125+
99126
it('Check scalar field arithmetic', () => {
100127
// Create the 2 scalar element.
101128
const a = Scalar.fromString("2scalar");

0 commit comments

Comments
 (0)