Skip to content

Commit

Permalink
chore: fix typescript linting errors (noir-lang#2914)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevaundray authored and Sakapoi committed Oct 19, 2023
1 parent cb39dbd commit d90faf6
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 149 deletions.
70 changes: 24 additions & 46 deletions acvm-repo/acvm_js/test/browser/black_box_solvers.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from "@esm-bundle/chai";
import { expect } from '@esm-bundle/chai';
import initACVM, {
and,
blake2s256,
Expand All @@ -8,65 +8,59 @@ import initACVM, {
keccak256,
sha256,
xor,
} from "@noir-lang/acvm_js";
} from '@noir-lang/acvm_js';

beforeEach(async () => {
await initACVM();

initLogLevel("INFO");
initLogLevel('INFO');
});

it("successfully calculates the bitwise AND of two fields", async () => {
const { and_test_cases } = await import("../shared/black_box_solvers");
it('successfully calculates the bitwise AND of two fields', async () => {
const { and_test_cases } = await import('../shared/black_box_solvers');

for (const testCase of and_test_cases) {
const [[lhs, rhs], expectedResult] = testCase;
expect(and(lhs, rhs)).to.be.eq(expectedResult);
}
});

it("successfully calculates the bitwise XOR of two fields", async () => {
const { xor_test_cases } = await import("../shared/black_box_solvers");
it('successfully calculates the bitwise XOR of two fields', async () => {
const { xor_test_cases } = await import('../shared/black_box_solvers');

for (const testCase of xor_test_cases) {
const [[lhs, rhs], expectedResult] = testCase;
expect(xor(lhs, rhs)).to.be.eq(expectedResult);
}
});

it("successfully calculates the sha256 hash", async () => {
const { sha256_test_cases } = await import("../shared/black_box_solvers");
it('successfully calculates the sha256 hash', async () => {
const { sha256_test_cases } = await import('../shared/black_box_solvers');

for (const testCase of sha256_test_cases) {
const [preimage, expectedResult] = testCase;
const hash = sha256(preimage);
hash.forEach((value, index) =>
expect(value).to.be.eq(expectedResult.at(index)),
);
hash.forEach((value, index) => expect(value).to.be.eq(expectedResult.at(index)));
}
});

it("successfully calculates the blake2s256 hash", async () => {
const { blake2s256_test_cases } = await import("../shared/black_box_solvers");
it('successfully calculates the blake2s256 hash', async () => {
const { blake2s256_test_cases } = await import('../shared/black_box_solvers');

for (const testCase of blake2s256_test_cases) {
const [preimage, expectedResult] = testCase;
const hash = blake2s256(preimage);
hash.forEach((value, index) =>
expect(value).to.be.eq(expectedResult.at(index)),
);
hash.forEach((value, index) => expect(value).to.be.eq(expectedResult.at(index)));
}
});

it("successfully calculates the keccak256 hash", async () => {
const { keccak256_test_cases } = await import("../shared/black_box_solvers");
it('successfully calculates the keccak256 hash', async () => {
const { keccak256_test_cases } = await import('../shared/black_box_solvers');

for (const testCase of keccak256_test_cases) {
const [preimage, expectedResult] = testCase;
const hash = keccak256(preimage);
hash.forEach((value, index) =>
expect(value).to.be.eq(expectedResult.at(index)),
);
hash.forEach((value, index) => expect(value).to.be.eq(expectedResult.at(index)));
}
});

Expand All @@ -82,50 +76,34 @@ it("successfully calculates the keccak256 hash", async () => {
// }
// });

it("successfully verifies secp256k1 ECDSA signatures", async () => {
const { ecdsa_secp256k1_test_cases } = await import(
"../shared/black_box_solvers"
);
it('successfully verifies secp256k1 ECDSA signatures', async () => {
const { ecdsa_secp256k1_test_cases } = await import('../shared/black_box_solvers');

for (const testCase of ecdsa_secp256k1_test_cases) {
const [[hashed_msg, pubkey_x, pubkey_y, signature], expectedResult] =
testCase;
const [[hashed_msg, pubkey_x, pubkey_y, signature], expectedResult] = testCase;

expect(hashed_msg.length).to.be.eq(32);
expect(pubkey_x.length).to.be.eq(32);
expect(pubkey_y.length).to.be.eq(32);
expect(signature.length).to.be.eq(64);

const result = ecdsa_secp256k1_verify(
hashed_msg,
pubkey_x,
pubkey_y,
signature,
);
const result = ecdsa_secp256k1_verify(hashed_msg, pubkey_x, pubkey_y, signature);
expect(result).to.be.eq(expectedResult);
}
});

it("successfully verifies secp256r1 ECDSA signatures", async () => {
const { ecdsa_secp256r1_test_cases } = await import(
"../shared/black_box_solvers"
);
it('successfully verifies secp256r1 ECDSA signatures', async () => {
const { ecdsa_secp256r1_test_cases } = await import('../shared/black_box_solvers');

for (const testCase of ecdsa_secp256r1_test_cases) {
const [[hashed_msg, pubkey_x, pubkey_y, signature], expectedResult] =
testCase;
const [[hashed_msg, pubkey_x, pubkey_y, signature], expectedResult] = testCase;

expect(hashed_msg.length).to.be.eq(32);
expect(pubkey_x.length).to.be.eq(32);
expect(pubkey_y.length).to.be.eq(32);
expect(signature.length).to.be.eq(64);

const result = ecdsa_secp256r1_verify(
hashed_msg,
pubkey_x,
pubkey_y,
signature,
);
const result = ecdsa_secp256r1_verify(hashed_msg, pubkey_x, pubkey_y, signature);
expect(result).to.be.eq(expectedResult);
}
});
68 changes: 23 additions & 45 deletions acvm-repo/acvm_js/test/node/black_box_solvers.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from "chai";
import { expect } from 'chai';
import {
and,
blake2s256,
Expand All @@ -7,59 +7,53 @@ import {
keccak256,
sha256,
xor,
} from "@noir-lang/acvm_js";
} from '@noir-lang/acvm_js';

it("successfully calculates the bitwise AND of two fields", async () => {
const { and_test_cases } = await import("../shared/black_box_solvers");
it('successfully calculates the bitwise AND of two fields', async () => {
const { and_test_cases } = await import('../shared/black_box_solvers');

for (const testCase of and_test_cases) {
const [[lhs, rhs], expectedResult] = testCase;
expect(and(lhs, rhs)).to.be.eq(expectedResult);
}
});

it("successfully calculates the bitwise XOR of two fields", async () => {
const { xor_test_cases } = await import("../shared/black_box_solvers");
it('successfully calculates the bitwise XOR of two fields', async () => {
const { xor_test_cases } = await import('../shared/black_box_solvers');

for (const testCase of xor_test_cases) {
const [[lhs, rhs], expectedResult] = testCase;
expect(xor(lhs, rhs)).to.be.eq(expectedResult);
}
});

it("successfully calculates the sha256 hash", async () => {
const { sha256_test_cases } = await import("../shared/black_box_solvers");
it('successfully calculates the sha256 hash', async () => {
const { sha256_test_cases } = await import('../shared/black_box_solvers');

for (const testCase of sha256_test_cases) {
const [preimage, expectedResult] = testCase;
const hash = sha256(preimage);
hash.forEach((value, index) =>
expect(value).to.be.eq(expectedResult.at(index)),
);
hash.forEach((value, index) => expect(value).to.be.eq(expectedResult.at(index)));
}
});

it("successfully calculates the blake2s256 hash", async () => {
const { blake2s256_test_cases } = await import("../shared/black_box_solvers");
it('successfully calculates the blake2s256 hash', async () => {
const { blake2s256_test_cases } = await import('../shared/black_box_solvers');

for (const testCase of blake2s256_test_cases) {
const [preimage, expectedResult] = testCase;
const hash = blake2s256(preimage);
hash.forEach((value, index) =>
expect(value).to.be.eq(expectedResult.at(index)),
);
hash.forEach((value, index) => expect(value).to.be.eq(expectedResult.at(index)));
}
});

it("successfully calculates the keccak256 hash", async () => {
const { keccak256_test_cases } = await import("../shared/black_box_solvers");
it('successfully calculates the keccak256 hash', async () => {
const { keccak256_test_cases } = await import('../shared/black_box_solvers');

for (const testCase of keccak256_test_cases) {
const [preimage, expectedResult] = testCase;
const hash = keccak256(preimage);
hash.forEach((value, index) =>
expect(value).to.be.eq(expectedResult.at(index)),
);
hash.forEach((value, index) => expect(value).to.be.eq(expectedResult.at(index)));
}
});

Expand All @@ -75,50 +69,34 @@ it("successfully calculates the keccak256 hash", async () => {
// }
// });

it("successfully verifies secp256k1 ECDSA signatures", async () => {
const { ecdsa_secp256k1_test_cases } = await import(
"../shared/black_box_solvers"
);
it('successfully verifies secp256k1 ECDSA signatures', async () => {
const { ecdsa_secp256k1_test_cases } = await import('../shared/black_box_solvers');

for (const testCase of ecdsa_secp256k1_test_cases) {
const [[hashed_msg, pubkey_x, pubkey_y, signature], expectedResult] =
testCase;
const [[hashed_msg, pubkey_x, pubkey_y, signature], expectedResult] = testCase;

expect(hashed_msg.length).to.be.eq(32);
expect(pubkey_x.length).to.be.eq(32);
expect(pubkey_y.length).to.be.eq(32);
expect(signature.length).to.be.eq(64);

const result = ecdsa_secp256k1_verify(
hashed_msg,
pubkey_x,
pubkey_y,
signature,
);
const result = ecdsa_secp256k1_verify(hashed_msg, pubkey_x, pubkey_y, signature);
expect(result).to.be.eq(expectedResult);
}
});

it("successfully verifies secp256r1 ECDSA signatures", async () => {
const { ecdsa_secp256r1_test_cases } = await import(
"../shared/black_box_solvers"
);
it('successfully verifies secp256r1 ECDSA signatures', async () => {
const { ecdsa_secp256r1_test_cases } = await import('../shared/black_box_solvers');

for (const testCase of ecdsa_secp256r1_test_cases) {
const [[hashed_msg, pubkey_x, pubkey_y, signature], expectedResult] =
testCase;
const [[hashed_msg, pubkey_x, pubkey_y, signature], expectedResult] = testCase;

expect(hashed_msg.length).to.be.eq(32);
expect(pubkey_x.length).to.be.eq(32);
expect(pubkey_y.length).to.be.eq(32);
expect(signature.length).to.be.eq(64);

const result = ecdsa_secp256r1_verify(
hashed_msg,
pubkey_x,
pubkey_y,
signature,
);
const result = ecdsa_secp256r1_verify(hashed_msg, pubkey_x, pubkey_y, signature);
expect(result).to.be.eq(expectedResult);
}
});
Loading

0 comments on commit d90faf6

Please sign in to comment.