Skip to content

Commit

Permalink
Fix the formatting for easy code review
Browse files Browse the repository at this point in the history
  • Loading branch information
nazarhussain committed Oct 10, 2023
1 parent 1f207d5 commit 11ca6ef
Show file tree
Hide file tree
Showing 5 changed files with 691 additions and 701 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,55 +62,54 @@ describe("beacon node api", function () {
expect(res.response.data.elOffline).toEqual(false);
});

it(
"should return 'el_offline' as 'true' when EL not available",
async () => {
const portElOffline = 9597;
const bnElOffline = await getDevBeaconNode({
params: {
...chainConfigDef,
// eslint-disable-next-line @typescript-eslint/naming-convention
ALTAIR_FORK_EPOCH: 0,
// eslint-disable-next-line @typescript-eslint/naming-convention
BELLATRIX_FORK_EPOCH: 0,
},
options: {
sync: {isSingleNode: true},
network: {allowPublishToZeroPeers: true},
executionEngine: {mode: "http", urls: ["http://not-available-engine:9999"]},
api: {
rest: {
enabled: true,
port: portElOffline,
},
// To make the code review easy for code block below
/* prettier-ignore */
it("should return 'el_offline' as 'true' when EL not available", async () => {
const portElOffline = 9597;
const bnElOffline = await getDevBeaconNode({
params: {
...chainConfigDef,
// eslint-disable-next-line @typescript-eslint/naming-convention
ALTAIR_FORK_EPOCH: 0,
// eslint-disable-next-line @typescript-eslint/naming-convention
BELLATRIX_FORK_EPOCH: 0,
},
options: {
sync: {isSingleNode: true},
network: {allowPublishToZeroPeers: true},
executionEngine: {mode: "http", urls: ["http://not-available-engine:9999"]},
api: {
rest: {
enabled: true,
port: portElOffline,
},
chain: {blsVerifyAllMainThread: true},
},
validatorCount: 5,
logger: testLogger("Node-EL-Offline", {level: LogLevel.info}),
});
const clientElOffline = getClient({baseUrl: `http://127.0.0.1:${portElOffline}`}, {config});
// To make BN communicate with EL, it needs to produce some blocks and for that need validators
const {validators} = await getAndInitDevValidators({
node: bnElOffline,
validatorClientCount: 1,
validatorsPerClient: validatorCount,
startIndex: 0,
});

// Give node sometime to communicate with EL
await sleep(chainConfigDef.SECONDS_PER_SLOT * 2 * 1000);

const res = await clientElOffline.node.getSyncingStatus();
ApiError.assert(res);

expect(res.response.data.elOffline).toEqual(true);

await Promise.all(validators.map((v) => v.close()));
await bnElOffline.close();
},
{timeout: 60_000}
);
chain: {blsVerifyAllMainThread: true},
},
validatorCount: 5,
logger: testLogger("Node-EL-Offline", {level: LogLevel.info}),
});
const clientElOffline = getClient({baseUrl: `http://127.0.0.1:${portElOffline}`}, {config});
// To make BN communicate with EL, it needs to produce some blocks and for that need validators
const {validators} = await getAndInitDevValidators({
node: bnElOffline,
validatorClientCount: 1,
validatorsPerClient: validatorCount,
startIndex: 0,
});

// Give node sometime to communicate with EL
await sleep(chainConfigDef.SECONDS_PER_SLOT * 2 * 1000);

const res = await clientElOffline.node.getSyncingStatus();
ApiError.assert(res);

expect(res.response.data.elOffline).toEqual(true);

await Promise.all(validators.map((v) => v.close()));
await bnElOffline.close();
},
{timeout: 60_000});
});

describe("getHealth", () => {
Expand Down
113 changes: 56 additions & 57 deletions packages/beacon-node/test/e2e/api/lodestar/lodestar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,62 +74,61 @@ describe("api / impl / validator", function () {
});
});

it(
"Should return only for previous, current and next epoch",
async function () {
const chainConfig: ChainConfig = {...chainConfigDef, SECONDS_PER_SLOT, ALTAIR_FORK_EPOCH};
const genesisValidatorsRoot = Buffer.alloc(32, 0xaa);
const config = createBeaconConfig(chainConfig, genesisValidatorsRoot);

const testLoggerOpts: TestLoggerOpts = {level: LogLevel.info};
const loggerNodeA = testLogger("Node-A", testLoggerOpts);

bn = await getDevBeaconNode({
params: testParams,
options: {
sync: {isSingleNode: true},
api: {rest: {enabled: true, api: ["lodestar"], port: restPort}},
chain: {blsVerifyAllMainThread: true},
},
validatorCount,
logger: loggerNodeA,
});

await waitForEvent<phase0.Checkpoint>(bn.chain.clock, ClockEvent.epoch, timeout); // wait for epoch 1
await waitForEvent<phase0.Checkpoint>(bn.chain.clock, ClockEvent.epoch, timeout); // wait for epoch 2

bn.chain.seenBlockProposers.add(bn.chain.clock.currentEpoch, 1);

const client = getClient({baseUrl: `http://127.0.0.1:${restPort}`}, {config});

const currentEpoch = bn.chain.clock.currentEpoch;
const nextEpoch = currentEpoch + 1;
const previousEpoch = currentEpoch - 1;

// current epoch is fine
await expect(client.validator.getLiveness(currentEpoch, [1])).resolves.toBeDefined();
// next epoch is fine
await expect(client.validator.getLiveness(nextEpoch, [1])).resolves.toBeDefined();
// previous epoch is fine
await expect(client.validator.getLiveness(previousEpoch, [1])).resolves.toBeDefined();
// more than next epoch is not fine
const res1 = await client.validator.getLiveness(currentEpoch + 2, [1]);
expect(res1.ok).toBe(false);
expect(res1.error?.message).toEqual(
expect.stringContaining(
`Request epoch ${currentEpoch + 2} is more than one epoch before or after the current epoch ${currentEpoch}`
)
);
// more than previous epoch is not fine
const res2 = await client.validator.getLiveness(currentEpoch - 2, [1]);
expect(res2.ok).toBe(false);
expect(res2.error?.message).toEqual(
expect.stringContaining(
`Request epoch ${currentEpoch - 2} is more than one epoch before or after the current epoch ${currentEpoch}`
)
);
},
{timeout: 60_000}
);
// To make the code review easy for code block below
/* prettier-ignore */
it("Should return only for previous, current and next epoch", async function () {
const chainConfig: ChainConfig = {...chainConfigDef, SECONDS_PER_SLOT, ALTAIR_FORK_EPOCH};
const genesisValidatorsRoot = Buffer.alloc(32, 0xaa);
const config = createBeaconConfig(chainConfig, genesisValidatorsRoot);

const testLoggerOpts: TestLoggerOpts = {level: LogLevel.info};
const loggerNodeA = testLogger("Node-A", testLoggerOpts);

bn = await getDevBeaconNode({
params: testParams,
options: {
sync: {isSingleNode: true},
api: {rest: {enabled: true, api: ["lodestar"], port: restPort}},
chain: {blsVerifyAllMainThread: true},
},
validatorCount,
logger: loggerNodeA,
});

await waitForEvent<phase0.Checkpoint>(bn.chain.clock, ClockEvent.epoch, timeout); // wait for epoch 1
await waitForEvent<phase0.Checkpoint>(bn.chain.clock, ClockEvent.epoch, timeout); // wait for epoch 2

bn.chain.seenBlockProposers.add(bn.chain.clock.currentEpoch, 1);

const client = getClient({baseUrl: `http://127.0.0.1:${restPort}`}, {config});

const currentEpoch = bn.chain.clock.currentEpoch;
const nextEpoch = currentEpoch + 1;
const previousEpoch = currentEpoch - 1;

// current epoch is fine
await expect(client.validator.getLiveness(currentEpoch, [1])).resolves.toBeDefined();
// next epoch is fine
await expect(client.validator.getLiveness(nextEpoch, [1])).resolves.toBeDefined();
// previous epoch is fine
await expect(client.validator.getLiveness(previousEpoch, [1])).resolves.toBeDefined();
// more than next epoch is not fine
const res1 = await client.validator.getLiveness(currentEpoch + 2, [1]);
expect(res1.ok).toBe(false);
expect(res1.error?.message).toEqual(
expect.stringContaining(
`Request epoch ${currentEpoch + 2} is more than one epoch before or after the current epoch ${currentEpoch}`
)
);
// more than previous epoch is not fine
const res2 = await client.validator.getLiveness(currentEpoch - 2, [1]);
expect(res2.ok).toBe(false);
expect(res2.error?.message).toEqual(
expect.stringContaining(
`Request epoch ${currentEpoch - 2} is more than one epoch before or after the current epoch ${currentEpoch}`
)
);
},
{timeout: 60_000});
});
});
Loading

0 comments on commit 11ca6ef

Please sign in to comment.