Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dapplion committed Jun 9, 2022
1 parent 17bfba4 commit 399eafc
Showing 1 changed file with 35 additions and 17 deletions.
52 changes: 35 additions & 17 deletions packages/validator/test/unit/services/syncCommitteDuties.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,25 @@ import {createIChainForkConfig} from "@chainsafe/lodestar-config";
import {config as mainnetConfig} from "@chainsafe/lodestar-config/default";
import {routes} from "@chainsafe/lodestar-api";
import {ssz} from "@chainsafe/lodestar-types";
import {SyncCommitteeDutiesService} from "../../../src/services/syncCommitteeDuties.js";
import {
SyncCommitteeDutiesService,
SyncDutyAndProofs,
SyncDutySubnet,
} from "../../../src/services/syncCommitteeDuties.js";
import {ValidatorStore} from "../../../src/services/validatorStore.js";
import {getApiClientStub} from "../../utils/apiStub.js";
import {loggerVc, testLogger} from "../../utils/logger.js";
import {ClockMock} from "../../utils/clock.js";
import {IndicesService} from "../../../src/services/indices.js";
import {syncCommitteeIndicesToSubnets} from "../../../src/services/utils.js";

/* eslint-disable @typescript-eslint/naming-convention */

describe("SyncCommitteeDutiesService", function () {
const sandbox = sinon.createSandbox();
const logger = testLogger();
const ZERO_HASH = Buffer.alloc(32, 0);
const ZERO_HASH_HEX = toHexString(ZERO_HASH);

const api = getApiClientStub(sandbox);
const validatorStore = sinon.createStubInstance(ValidatorStore) as ValidatorStore &
Expand Down Expand Up @@ -111,16 +117,19 @@ describe("SyncCommitteeDutiesService", function () {
Object.fromEntries(dutiesByIndex),
])
);

expect(dutiesByIndexByPeriodObj).to.deep.equal(
{
0: {[indices[0]]: {dependentRoot: ZERO_HASH, duty}},
1: {[indices[0]]: {dependentRoot: ZERO_HASH, duty}},
},
0: {[indices[0]]: {dependentRoot: ZERO_HASH_HEX, duty: toSyncDutySubnet(duty)}},
1: {[indices[0]]: {dependentRoot: ZERO_HASH_HEX, duty: toSyncDutySubnet(duty)}},
} as typeof dutiesByIndexByPeriodObj,
"Wrong dutiesService.dutiesByIndexByPeriod Map"
);

expect(await dutiesService.getDutiesAtSlot(slot)).to.deep.equal(
[{duty, selectionProofs: [{selectionProof: null, subcommitteeIndex: 0}]}],
[
{duty: toSyncDutySubnet(duty), selectionProofs: [{selectionProof: null, subcommitteeIndex: 0}]},
] as SyncDutyAndProofs[],
"Wrong getAttestersAtSlot()"
);

Expand Down Expand Up @@ -180,9 +189,9 @@ describe("SyncCommitteeDutiesService", function () {
);
expect(dutiesByIndexByPeriodObj).to.deep.equal(
{
0: {[indices[0]]: {dependentRoot: ZERO_HASH, duty}},
0: {[indices[0]]: {dependentRoot: ZERO_HASH_HEX, duty: toSyncDutySubnet(duty)}},
1: {},
},
} as typeof dutiesByIndexByPeriodObj,
"Wrong dutiesService.dutiesByIndexByPeriod Map"
);

Expand All @@ -196,9 +205,9 @@ describe("SyncCommitteeDutiesService", function () {
);
expect(dutiesByIndexByPeriodObj).to.deep.equal(
{
0: {[indices[1]]: {dependentRoot: ZERO_HASH, duty: duty2}},
0: {[indices[1]]: {dependentRoot: ZERO_HASH_HEX, duty: toSyncDutySubnet(duty2)}},
1: {},
},
} as typeof dutiesByIndexByPeriodObj,
"Wrong dutiesService.dutiesByIndexByPeriod Map"
);
});
Expand Down Expand Up @@ -245,17 +254,18 @@ describe("SyncCommitteeDutiesService", function () {
Object.fromEntries(dutiesByIndex),
])
);

expect(dutiesByIndexByPeriodObj).to.deep.equal(
{
0: {
[indices[0]]: {dependentRoot: ZERO_HASH, duty: duty1},
[indices[1]]: {dependentRoot: ZERO_HASH, duty: duty2},
[indices[0]]: {dependentRoot: ZERO_HASH_HEX, duty: toSyncDutySubnet(duty1)},
[indices[1]]: {dependentRoot: ZERO_HASH_HEX, duty: toSyncDutySubnet(duty2)},
},
1: {
[indices[0]]: {dependentRoot: ZERO_HASH, duty: duty1},
[indices[1]]: {dependentRoot: ZERO_HASH, duty: duty2},
[indices[0]]: {dependentRoot: ZERO_HASH_HEX, duty: toSyncDutySubnet(duty1)},
[indices[1]]: {dependentRoot: ZERO_HASH_HEX, duty: toSyncDutySubnet(duty2)},
},
},
} as typeof dutiesByIndexByPeriodObj,
"Wrong dutiesService.dutiesByIndexByPeriod Map"
);
// then remove signer with pubkeys[0]
Expand All @@ -270,10 +280,18 @@ describe("SyncCommitteeDutiesService", function () {
);
expect(dutiesByIndexByPeriodObjAfterRemoval).to.deep.equal(
{
0: {[indices[1]]: {dependentRoot: ZERO_HASH, duty: duty2}},
1: {[indices[1]]: {dependentRoot: ZERO_HASH, duty: duty2}},
},
0: {[indices[1]]: {dependentRoot: ZERO_HASH_HEX, duty: toSyncDutySubnet(duty2)}},
1: {[indices[1]]: {dependentRoot: ZERO_HASH_HEX, duty: toSyncDutySubnet(duty2)}},
} as typeof dutiesByIndexByPeriodObjAfterRemoval,
"Wrong dutiesService.dutiesByIndexByPeriod Map"
);
});
});

function toSyncDutySubnet(duty: routes.validator.SyncDuty): SyncDutySubnet {
return {
pubkey: toHexString(duty.pubkey),
validatorIndex: duty.validatorIndex,
subnets: syncCommitteeIndicesToSubnets(duty.validatorSyncCommitteeIndices),
};
}

0 comments on commit 399eafc

Please sign in to comment.