From 7819a0b397b831461d9a086ea70d5f94406dc6da Mon Sep 17 00:00:00 2001 From: daveroga Date: Fri, 17 Jan 2025 20:30:55 +0100 Subject: [PATCH] increase coverage --- .../RequestDisableableTestWrapper.sol | 5 +++++ .../ValidatorWhitelistTestWrapper.sol | 7 +++++++ test/verifier/requestDisableable.test.ts | 5 +++++ test/verifier/validatorWhitelist.test.ts | 21 +++++++++++++++++++ 4 files changed, 38 insertions(+) diff --git a/contracts/test-helpers/RequestDisableableTestWrapper.sol b/contracts/test-helpers/RequestDisableableTestWrapper.sol index fb680646..b9329aed 100644 --- a/contracts/test-helpers/RequestDisableableTestWrapper.sol +++ b/contracts/test-helpers/RequestDisableableTestWrapper.sol @@ -3,6 +3,7 @@ pragma solidity ^0.8.10; import {RequestDisableable} from "../verifiers/RequestDisableable.sol"; import {IState} from "../interfaces/IState.sol"; +import {IVerifier} from "../interfaces/IVerifier.sol"; contract RequestDisableableTestWrapper is RequestDisableable { function initialize(IState state) public initializer { @@ -18,4 +19,8 @@ contract RequestDisableableTestWrapper is RequestDisableable { } function testModifier(uint256 requestId) public view onlyEnabledRequest(requestId) {} + + function getRequestIfCanBeVerified(uint256 requestId) public view returns (IVerifier.RequestData memory) { + return _getRequestIfCanBeVerified(requestId); + } } diff --git a/contracts/test-helpers/ValidatorWhitelistTestWrapper.sol b/contracts/test-helpers/ValidatorWhitelistTestWrapper.sol index 8a47bcd8..db2a9839 100644 --- a/contracts/test-helpers/ValidatorWhitelistTestWrapper.sol +++ b/contracts/test-helpers/ValidatorWhitelistTestWrapper.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.10; import {ValidatorWhitelist} from "../verifiers/ValidatorWhitelist.sol"; import {IState} from "../interfaces/IState.sol"; import {IRequestValidator} from "../interfaces/IRequestValidator.sol"; +import {IVerifier} from "../interfaces/IVerifier.sol"; contract ValidatorWhitelistTestWrapper is ValidatorWhitelist { function initialize(IState state) public initializer { @@ -21,4 +22,10 @@ contract ValidatorWhitelistTestWrapper is ValidatorWhitelist { function testModifier( IRequestValidator validator ) public view onlyWhitelistedValidator(validator) {} + + function getRequestIfCanBeVerified( + uint256 requestId + ) public view returns (IVerifier.RequestData memory) { + return _getRequestIfCanBeVerified(requestId); + } } diff --git a/test/verifier/requestDisableable.test.ts b/test/verifier/requestDisableable.test.ts index 1cec335b..5b2bd487 100644 --- a/test/verifier/requestDisableable.test.ts +++ b/test/verifier/requestDisableable.test.ts @@ -47,6 +47,7 @@ describe("RequestDisableable tests", function () { expect(isRequestEnabled).to.be.true; await expect(verifier.testModifier(request.requestId)).not.to.be.reverted; + await expect(verifier.getRequestIfCanBeVerified(request.requestId)).not.to.be.reverted; await verifier.disableRequest(request.requestId); @@ -57,6 +58,10 @@ describe("RequestDisableable tests", function () { .to.be.revertedWithCustomError(verifier, "RequestIsDisabled") .withArgs(request.requestId); + await expect(verifier.getRequestIfCanBeVerified(request.requestId)) + .to.be.revertedWithCustomError(verifier, "RequestIsDisabled") + .withArgs(request.requestId); + await verifier.enableRequest(request.requestId); isRequestEnabled = await verifier.isRequestEnabled(request.requestId); diff --git a/test/verifier/validatorWhitelist.test.ts b/test/verifier/validatorWhitelist.test.ts index cc0b19c7..794d2bd1 100644 --- a/test/verifier/validatorWhitelist.test.ts +++ b/test/verifier/validatorWhitelist.test.ts @@ -6,6 +6,7 @@ import { expect } from "chai"; describe("ValidatorWhitelist tests", function () { let verifier, validator: any; let signer1, signer2: any; + let request, paramsFromValidator: any; async function deployContractsFixture() { [signer1, signer2] = await ethers.getSigners(); @@ -25,6 +26,19 @@ describe("ValidatorWhitelist tests", function () { beforeEach(async function () { ({ verifier, validator, signer1, signer2 } = await deployContractsFixture()); + + request = { + requestId: 1, + metadata: "0x", + validator: await validator.getAddress(), + params: "0x", + }; + + paramsFromValidator = { + groupID: 0, + verifierID: 0, + nullifierSessionID: 0, + }; }); it("whitelist/remove Validators and modifier onlyWhitelistedValidator", async function () { @@ -40,7 +54,11 @@ describe("ValidatorWhitelist tests", function () { await verifier.addValidatorToWhitelist(await validator.getAddress()); + await validator.stub_setRequestParams([request.params], [paramsFromValidator]); + await verifier.setRequests([request]); + await expect(verifier.testModifier(await validator.getAddress())).not.to.be.reverted; + await expect(verifier.getRequestIfCanBeVerified(request.requestId)).not.to.be.reverted; isWhitelistedValidator = await verifier.isWhitelistedValidator(await validator.getAddress()); expect(isWhitelistedValidator).to.be.true; @@ -51,6 +69,9 @@ describe("ValidatorWhitelist tests", function () { verifier, "ValidatorIsNotWhitelisted", ); + await expect( + verifier.getRequestIfCanBeVerified(request.requestId), + ).to.be.revertedWithCustomError(verifier, "ValidatorIsNotWhitelisted"); isWhitelistedValidator = await verifier.isWhitelistedValidator(await validator.getAddress()); expect(isWhitelistedValidator).to.be.false;