Skip to content

Commit

Permalink
Added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KyrylR committed Oct 31, 2024
1 parent c81eef1 commit f55f88c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
32 changes: 29 additions & 3 deletions test/circom-template-inputs-visitor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ describe("Circom Template Inputs Visitor", () => {
mainComponentData,
);

const parser = getCircomParser(`test/data/curve.circom`);

visitor.visit(parser.circuit());
visitor.startParse();

expect(visitor.errors.length).to.equal(0);

Expand Down Expand Up @@ -91,4 +89,32 @@ describe("Circom Template Inputs Visitor", () => {
expect(visitor.templateInputs.pkIdentityHash.type).to.equal("output");
expect(visitor.templateInputs.pkIdentityHash.dimension).to.deep.equal([]);
});

it("should analyse the MainComponent.circom circuit", () => {
const mainComponentData: VariableContext = {
p1: 2n,
p2: 8n,
};

const data = getData("MainComponent.circom");

const visitor = new CircomTemplateInputsVisitor(
"MainComponent.circom",
data["C"].context,
mainComponentData,
);

visitor.startParse();

expect(visitor.errors.length).to.equal(0);

expect(visitor.templateInputs.in1.type).to.equal("input");
expect(visitor.templateInputs.in1.dimension).to.deep.equal([]);

expect(visitor.templateInputs.in2.type).to.equal("input");
expect(visitor.templateInputs.in2.dimension).to.deep.equal([3n, 2n]);

expect(visitor.templateInputs.out.type).to.equal("output");
expect(visitor.templateInputs.out.dimension).to.deep.equal([]);
});
});
8 changes: 8 additions & 0 deletions test/mocks/CircomTemplateInputsVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export class CircomTemplateInputsVisitor extends CircomVisitor<void> {
this._validateVariableContext();
}

startParse = () => {
this.visit(this.templateContext);
};

visitVarDeclaration = (ctx: VarDeclarationContext) => {
if (ctx.LP() && ctx.RP()) {
this.errors.push({
Expand Down Expand Up @@ -295,6 +299,10 @@ export class CircomTemplateInputsVisitor extends CircomVisitor<void> {
};

visitSubsLeftAssignment = (ctx: SubsLeftAssignmentContext) => {
if (ctx.LEFT_ASSIGNMENT() || ctx.LEFT_CONSTRAINT()) {
return;
}

const primaryExpression = ctx._lhs.primaryExpression();

if (!primaryExpression) {
Expand Down

0 comments on commit f55f88c

Please sign in to comment.