From 617b08995e9ee2c348d7fbe83f583dc648fc7b2b Mon Sep 17 00:00:00 2001 From: nflaig Date: Tue, 14 Mar 2023 14:22:38 +0100 Subject: [PATCH] Add unit test for running attestation tasks per committee --- .../validator/src/services/attestation.ts | 2 +- .../test/unit/services/attestation.test.ts | 30 +++++++++++++++---- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/packages/validator/src/services/attestation.ts b/packages/validator/src/services/attestation.ts index e2b8d61bdff5..707c2605e642 100644 --- a/packages/validator/src/services/attestation.ts +++ b/packages/validator/src/services/attestation.ts @@ -12,7 +12,7 @@ import {groupAttDutiesByCommitteeIndex} from "./utils.js"; import {ChainHeaderTracker} from "./chainHeaderTracker.js"; import {ValidatorEventEmitter} from "./emitter.js"; -type AttestationServiceOpts = { +export type AttestationServiceOpts = { afterBlockDelaySlotFraction?: number; disableAttestationGrouping?: boolean; }; diff --git a/packages/validator/test/unit/services/attestation.test.ts b/packages/validator/test/unit/services/attestation.test.ts index e154f05d9761..a53314dd359e 100644 --- a/packages/validator/test/unit/services/attestation.test.ts +++ b/packages/validator/test/unit/services/attestation.test.ts @@ -4,7 +4,7 @@ import bls from "@chainsafe/bls"; import {toHexString} from "@chainsafe/ssz"; import {ssz} from "@lodestar/types"; import {HttpStatusCode} from "@lodestar/api"; -import {AttestationService} from "../../../src/services/attestation.js"; +import {AttestationService, AttestationServiceOpts} from "../../../src/services/attestation.js"; import {AttDutyAndProof} from "../../../src/services/attestationDuties.js"; import {ValidatorStore} from "../../../src/services/validatorStore.js"; import {getApiClientStub} from "../../utils/apiStub.js"; @@ -37,9 +37,28 @@ describe("AttestationService", function () { let controller: AbortController; // To stop clock beforeEach(() => (controller = new AbortController())); - afterEach(() => controller.abort()); + afterEach(() => { + controller.abort(); + sandbox.resetHistory(); + }); + + context("With attestation grouping enabled", () => { + const opts: AttestationServiceOpts = {disableAttestationGrouping: false}; + + it("Should produce, sign, and publish an attestation + aggregate", async () => { + await testAttestationTasks(opts); + }); + }); - it("Should produce, sign, and publish an attestation + aggregate", async () => { + context("With attestation grouping disabled", () => { + const opts: AttestationServiceOpts = {disableAttestationGrouping: true}; + + it("Should produce, sign, and publish an attestation + aggregate", async () => { + await testAttestationTasks(opts); + }); + }); + + async function testAttestationTasks(opts?: AttestationServiceOpts): Promise { const clock = new ClockMock(); const attestationService = new AttestationService( loggerVc, @@ -48,7 +67,8 @@ describe("AttestationService", function () { validatorStore, emitter, chainHeadTracker, - null + null, + opts ); const attestation = ssz.phase0.Attestation.defaultValue(); @@ -121,5 +141,5 @@ describe("AttestationService", function () { [[aggregate]], // 1 arg, = aggregate[] "wrong publishAggregateAndProofs() args" ); - }); + } });