mirror of
https://github.com/AtHeartEngineering/lodestar.git
synced 2026-01-09 22:28:28 -05:00
* Add validator metrics in code * Update test types * Wire validator metrics * Wire validator metrics in cli * Add HTTP client metrics * Rename metrics prefix * Metrics for attester steps * Metrics for sync committee steps * Metrics for proposer steps * Fix vc journey metrics times * De-duplicate log from vc metrics server * Add validator target to local metrics * Fix metrics for vc http client * PR comments * Fix option types * Fix attestationNoCommittee property merging
60 lines
2.0 KiB
TypeScript
60 lines
2.0 KiB
TypeScript
import {toBufferBE} from "bigint-buffer";
|
|
import {expect} from "chai";
|
|
import sinon from "sinon";
|
|
import bls from "@chainsafe/bls";
|
|
import {toHexString} from "@chainsafe/ssz";
|
|
import {ValidatorStore} from "../../../src/services/validatorStore";
|
|
import {getApiClientStub} from "../../utils/apiStub";
|
|
import {testLogger} from "../../utils/logger";
|
|
import {IndicesService} from "../../../src/services/indices";
|
|
|
|
describe("IndicesService", function () {
|
|
const sandbox = sinon.createSandbox();
|
|
const logger = testLogger();
|
|
const api = getApiClientStub(sandbox);
|
|
const validatorStore = sinon.createStubInstance(ValidatorStore) as ValidatorStore &
|
|
sinon.SinonStubbedInstance<ValidatorStore>;
|
|
|
|
let pubkeys: Uint8Array[]; // Initialize pubkeys in before() so bls is already initialized
|
|
|
|
before(() => {
|
|
const secretKeys = [
|
|
bls.SecretKey.fromBytes(toBufferBE(BigInt(98), 32)),
|
|
bls.SecretKey.fromBytes(toBufferBE(BigInt(99), 32)),
|
|
];
|
|
pubkeys = secretKeys.map((sk) => sk.toPublicKey().toBytes());
|
|
});
|
|
|
|
it("Should remove pubkey", async function () {
|
|
const indicesService = new IndicesService(logger, api, validatorStore, null);
|
|
const firstValidatorIndex = 0;
|
|
const secondValidatorIndex = 1;
|
|
|
|
const pubkey1 = toHexString(pubkeys[firstValidatorIndex]);
|
|
const pubkey2 = toHexString(pubkeys[secondValidatorIndex]);
|
|
|
|
indicesService.index2pubkey.set(firstValidatorIndex, pubkey1);
|
|
indicesService.index2pubkey.set(secondValidatorIndex, pubkey2);
|
|
|
|
indicesService.pubkey2index.set(pubkey1, firstValidatorIndex);
|
|
indicesService.pubkey2index.set(pubkey2, secondValidatorIndex);
|
|
|
|
// remove pubkey2
|
|
indicesService.removeDutiesForKey(pubkey2);
|
|
|
|
expect(Object.fromEntries(indicesService.index2pubkey)).to.deep.equal(
|
|
{
|
|
"0": `${pubkey1}`,
|
|
},
|
|
"Wrong indicesService.index2pubkey Map"
|
|
);
|
|
|
|
expect(Object.fromEntries(indicesService.pubkey2index)).to.deep.equal(
|
|
{
|
|
[`${pubkey1}`]: 0,
|
|
},
|
|
"Wrong indicesService.pubkey2index Map"
|
|
);
|
|
});
|
|
});
|