Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
phn210 committed Nov 13, 2023
1 parent c24437c commit 438446d
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@auxo-dev/auxo-libs",
"version": "0.2.5",
"version": "0.2.7",
"description": "",
"author": "",
"license": "Apache-2.0",
Expand Down
4 changes: 4 additions & 0 deletions src/CustomScalar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export class CustomScalar extends Struct({
return this.head.equals(s.head).and(this.tail.equals(s.tail));
}

assertEquals(s: CustomScalar): void {
this.equals(s).assertTrue();
}

toScalar(): Scalar {
return CustomScalar.toScalar(this);
}
Expand Down
58 changes: 52 additions & 6 deletions src/DynamicArray.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('DynamicArray', () => {
DynamicFieldArray,
() => new DynamicFieldArray(fieldValues)
);
Provable.log(fieldArray);
// Provable.log(fieldArray);

// Group
let groupValues = Provable.Array(Group, 1).fromFields(
Expand All @@ -30,19 +30,65 @@ describe('DynamicArray', () => {
DynamicGroupArray,
() => new DynamicGroupArray(groupValues)
);
Provable.log(groupArray);
// Provable.log(groupArray);

// Scalar - Not working because Scalar takes up 255 Fields => Stack overflow
// Scalar
let scalarValues = Provable.Array(CustomScalar, 1).fromFields(
CustomScalar.fromScalar(Scalar.random()).toFields()
);
Provable.log(scalarValues);
// Provable.log(scalarValues);
let scalarArray = Provable.witness(
DynamicScalarArray,
() => new DynamicScalarArray(scalarValues)
);
// Provable.log(Scalar.sizeInFields());
Provable.log(scalarArray);
// Provable.log(scalarArray);
});
});

it('Should serialize correctly', async () => {
// Field
let fieldValues = [Field(0), Field(1), Field(2), Field(1)];
let fieldArray = new DynamicFieldArray(fieldValues);
let fieldSerialized = fieldArray.toFields();
let fieldDeserialized = DynamicFieldArray.fromFields(
[fieldArray.length, fieldSerialized].flat()
);
fieldDeserialized.length.assertEquals(fieldArray.length);
for (let i = 0; i < fieldArray.values.length; i++) {
(fieldDeserialized as DynamicFieldArray)
.get(Field(i))
.assertEquals(fieldArray.get(Field(i)));
}

// Group
let groupValues = [Group.generator, Group.zero, Group.generator];
let groupArray = new DynamicGroupArray(groupValues);
let groupSerialized = groupArray.toFields();
let groupDeserialized = DynamicGroupArray.fromFields(
[groupArray.length, groupSerialized].flat()
);
groupDeserialized.length.assertEquals(groupArray.length);
for (let i = 0; i < groupArray.values.length; i++) {
(groupDeserialized as DynamicGroupArray)
.get(Field(i))
.assertEquals(groupArray.get(Field(i)));
}

// Scalar
let scalarValues = [
CustomScalar.fromScalar(Scalar.random()),
CustomScalar.fromScalar(Scalar.random()),
];
let scalarArray = new DynamicScalarArray(scalarValues);
let scalarSerialized = scalarArray.toFields();
let scalarDeserialized = DynamicScalarArray.fromFields(
[scalarArray.length, scalarSerialized].flat()
);
scalarDeserialized.length.assertEquals(scalarArray.length);
for (let i = 0; i < scalarArray.values.length; i++) {
(scalarDeserialized as DynamicScalarArray)
.get(Field(i))
.assertEquals(scalarArray.get(Field(i)));
}
});
});

0 comments on commit 438446d

Please sign in to comment.