Skip to content

Commit

Permalink
Add unit test for running attestation tasks per committee
Browse files Browse the repository at this point in the history
  • Loading branch information
nflaig committed Mar 14, 2023
1 parent ccdf9f9 commit 617b089
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/validator/src/services/attestation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
30 changes: 25 additions & 5 deletions packages/validator/test/unit/services/attestation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<void> {
const clock = new ClockMock();
const attestationService = new AttestationService(
loggerVc,
Expand All @@ -48,7 +67,8 @@ describe("AttestationService", function () {
validatorStore,
emitter,
chainHeadTracker,
null
null,
opts
);

const attestation = ssz.phase0.Attestation.defaultValue();
Expand Down Expand Up @@ -121,5 +141,5 @@ describe("AttestationService", function () {
[[aggregate]], // 1 arg, = aggregate[]
"wrong publishAggregateAndProofs() args"
);
});
}
});

0 comments on commit 617b089

Please sign in to comment.