Skip to content

Commit

Permalink
Add ValidatorTestWrapper and fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
Andriian Chestnykh committed Dec 13, 2023
1 parent 0c33bc0 commit cbbf6ec
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
37 changes: 37 additions & 0 deletions contracts/test-helpers/ValidatorTestWrapper.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

Check failure on line 2 in contracts/test-helpers/ValidatorTestWrapper.sol

View workflow job for this annotation

GitHub Actions / solhint

Compiler version ^0.8.0 does not satisfy the >=0.8.4 semver requirement

import {ICircuitValidator} from "../interfaces/ICircuitValidator.sol";

contract ValidatorTestWrapper {
ICircuitValidator public validator;

constructor(address _verifier) {
validator = ICircuitValidator(_verifier);
}

/// @return r bool true if proof is valid
function verify(
uint256[] calldata inputs,
uint256[2] calldata a,
uint256[2][2] calldata b,
uint256[2] calldata c,
bytes calldata data
) public returns (bool r) {
bytes4 selector = validator.verify.selector;
bytes memory data = abi.encodePacked(selector, abi.encode(inputs, a, b, c, data), msg.sender);

Check failure on line 22 in contracts/test-helpers/ValidatorTestWrapper.sol

View workflow job for this annotation

GitHub Actions / solhint

Replace selector,·abi.encode(inputs,·a,·b,·c,·data),·msg.sender with ⏎············selector,⏎············abi.encode(inputs,·a,·b,·c,·data),⏎············msg.sender⏎········
(bool success, bytes memory returnData) = address(validator).call(data);
if (!success) {
if (returnData.length > 0) {
// Extract revert reason from returnData
assembly {
let returnDataSize := mload(returnData)
revert(add(32, returnData), returnDataSize)
}
} else {
revert("Failed to verify proof without revert reason");
}
}
return success;
}
}
8 changes: 5 additions & 3 deletions test/validators/v3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ const testCases: any[] = [
authEnabled: 0,
isMtpProof: true
},
// Issuer Genesis State
// Issuer Genesis State
{
name: "Validate First User State, Issuer Genesis. BJJ Proof",
stateTransitions: [
Expand All @@ -239,7 +239,7 @@ function delay(ms: number) {
}

describe("Atomic V3 Validator", function () {
let state: any, v3: any, verifierWrapper: any;
let state: any, v3, v3testWrapper: any, verifierWrapper: any;

beforeEach(async () => {
const deployHelper = await DeployHelper.initialize(null, true);
Expand All @@ -251,6 +251,8 @@ describe("Atomic V3 Validator", function () {
state = contracts.state;
v3 = contracts.validator;
verifierWrapper = contracts.verifierWrapper;

v3testWrapper = await ethers.deployContract("ValidatorTestWrapper", [v3.address]);
});

for (const test of testCases) {
Expand Down Expand Up @@ -318,7 +320,7 @@ describe("Atomic V3 Validator", function () {
v3.verify(inputs, pi_a, pi_b, pi_c, packV3ValidatorParams(query, test.allowedIssuers))
).to.be.reverted;
} else {
await v3.verify(
await v3testWrapper.verify(
inputs,
pi_a,
pi_b,
Expand Down

0 comments on commit cbbf6ec

Please sign in to comment.