Skip to content

Commit

Permalink
increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
daveroga committed Jan 17, 2025
1 parent 39d67f5 commit 7819a0b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions contracts/test-helpers/RequestDisableableTestWrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {

Check failure on line 23 in contracts/test-helpers/RequestDisableableTestWrapper.sol

View workflow job for this annotation

GitHub Actions / solhint

Replace uint256·requestId with ⏎········uint256·requestId⏎····
return _getRequestIfCanBeVerified(requestId);
}
}
7 changes: 7 additions & 0 deletions contracts/test-helpers/ValidatorWhitelistTestWrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}
}
5 changes: 5 additions & 0 deletions test/verifier/requestDisableable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand Down
21 changes: 21 additions & 0 deletions test/verifier/validatorWhitelist.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 () {
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 7819a0b

Please sign in to comment.