-
-
Notifications
You must be signed in to change notification settings - Fork 330
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* return the numeric values in /eth/v1/node/syncing as string to confirm to spec. Fixes #3846 * use query name as specified in beacon node api for filtering validators. Fixes #3852 * minor cleaning up in tests
- Loading branch information
Showing
11 changed files
with
199 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
packages/lodestar/test/e2e/api/impl/beacon/state/endpoint.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import chaiAsPromised from "chai-as-promised"; | ||
import chai, {expect} from "chai"; | ||
import {initBLS} from "@chainsafe/lodestar-cli/src/util"; | ||
import {createIBeaconConfig, IChainConfig} from "@chainsafe/lodestar-config"; | ||
import {chainConfig as chainConfigDef} from "@chainsafe/lodestar-config/default"; | ||
import {getClient} from "@chainsafe/lodestar-api"; | ||
import {toHexString} from "@chainsafe/ssz"; | ||
import {LogLevel, testLogger, TestLoggerOpts} from "../../../../../utils/logger"; | ||
import {getDevBeaconNode} from "../../../../../utils/node/beacon"; | ||
import {getAndInitDevValidators} from "../../../../../utils/node/validator"; | ||
|
||
chai.use(chaiAsPromised); | ||
|
||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
describe("lodestar / api / impl / state", function () { | ||
const SECONDS_PER_SLOT = 2; | ||
const ALTAIR_FORK_EPOCH = 0; | ||
const restPort = 9596; | ||
const chainConfig: IChainConfig = {...chainConfigDef, SECONDS_PER_SLOT, ALTAIR_FORK_EPOCH}; | ||
const genesisValidatorsRoot = Buffer.alloc(32, 0xaa); | ||
const config = createIBeaconConfig(chainConfig, genesisValidatorsRoot); | ||
const testLoggerOpts: TestLoggerOpts = {logLevel: LogLevel.info}; | ||
const loggerNodeA = testLogger("Node-A", testLoggerOpts); | ||
|
||
describe("eth/v1/beacon/states/{status_id}/validators", function () { | ||
this.timeout("10 min"); | ||
const testParams: Pick<IChainConfig, "SECONDS_PER_SLOT"> = { | ||
SECONDS_PER_SLOT: 2, | ||
}; | ||
|
||
const afterEachCallbacks: (() => Promise<unknown> | void)[] = []; | ||
afterEach(async () => { | ||
while (afterEachCallbacks.length > 0) { | ||
const callback = afterEachCallbacks.pop(); | ||
if (callback) await callback(); | ||
} | ||
}); | ||
|
||
before(async function () { | ||
await initBLS(); | ||
}); | ||
|
||
it("should return all validators when getStateValidators called without filters", async function () { | ||
const validatorCount = 2; | ||
const bn = await getDevBeaconNode({ | ||
params: testParams, | ||
options: { | ||
sync: {isSingleNode: true}, | ||
api: {rest: {enabled: true, port: restPort}}, | ||
}, | ||
validatorCount, | ||
logger: loggerNodeA, | ||
}); | ||
afterEachCallbacks.push(() => bn.close()); | ||
|
||
const {validators} = await getAndInitDevValidators({ | ||
node: bn, | ||
validatorsPerClient: validatorCount, | ||
validatorClientCount: 1, | ||
startIndex: 0, | ||
useRestApi: false, | ||
testLoggerOpts, | ||
}); | ||
afterEachCallbacks.push(() => Promise.all(validators.map((validator) => validator.stop()))); | ||
|
||
await Promise.all(validators.map((validator) => validator.start())); | ||
|
||
const client = getClient(config, {baseUrl: `http://127.0.0.1:${restPort}`}).beacon; | ||
|
||
const response = await client.getStateValidators("head"); | ||
expect(response.data.length).to.be.equal(validatorCount); | ||
expect(response.data[0].index).to.be.equal(0); | ||
expect(response.data[1].index).to.be.equal(1); | ||
}); | ||
|
||
it("should return filtered validators when getStateValidators called with filters", async function () { | ||
const validatorCount = 2; | ||
const filterPubKey = | ||
"0xa99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c"; | ||
|
||
const bn = await getDevBeaconNode({ | ||
params: testParams, | ||
options: { | ||
sync: {isSingleNode: true}, | ||
api: {rest: {enabled: true, port: restPort}}, | ||
}, | ||
validatorCount, | ||
logger: loggerNodeA, | ||
}); | ||
afterEachCallbacks.push(() => bn.close()); | ||
|
||
const {validators} = await getAndInitDevValidators({ | ||
node: bn, | ||
validatorsPerClient: validatorCount, | ||
validatorClientCount: 1, | ||
startIndex: 0, | ||
useRestApi: false, | ||
testLoggerOpts, | ||
}); | ||
afterEachCallbacks.push(() => Promise.all(validators.map((validator) => validator.stop()))); | ||
|
||
await Promise.all(validators.map((validator) => validator.start())); | ||
|
||
const client = getClient(config, {baseUrl: `http://127.0.0.1:${restPort}`}).beacon; | ||
|
||
const response = await client.getStateValidators("head", { | ||
id: [filterPubKey], | ||
}); | ||
|
||
expect(response.data.length).to.be.equal(1); | ||
expect(toHexString(response.data[0].validator.pubkey)).to.be.equal(filterPubKey); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import chaiAsPromised from "chai-as-promised"; | ||
import chai, {expect} from "chai"; | ||
import {initBLS} from "@chainsafe/lodestar-cli/src/util"; | ||
import {createIBeaconConfig, IChainConfig} from "@chainsafe/lodestar-config"; | ||
import {chainConfig as chainConfigDef} from "@chainsafe/lodestar-config/default"; | ||
import {getClient} from "@chainsafe/lodestar-api"; | ||
import {getDevBeaconNode} from "../../utils/node/beacon"; | ||
import {LogLevel, testLogger, TestLoggerOpts} from "../../utils/logger"; | ||
|
||
chai.use(chaiAsPromised); | ||
|
||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
describe("lodestar / sync", function () { | ||
const SECONDS_PER_SLOT = 2; | ||
const ALTAIR_FORK_EPOCH = 0; | ||
const validatorCount = 1; | ||
const restPort = 9596; | ||
const chainConfig: IChainConfig = {...chainConfigDef, SECONDS_PER_SLOT, ALTAIR_FORK_EPOCH}; | ||
const genesisValidatorsRoot = Buffer.alloc(32, 0xaa); | ||
const config = createIBeaconConfig(chainConfig, genesisValidatorsRoot); | ||
const testLoggerOpts: TestLoggerOpts = {logLevel: LogLevel.info}; | ||
const loggerNodeA = testLogger("Node-A", testLoggerOpts); | ||
|
||
describe("/eth/v1/node/syncing", function () { | ||
const testParams: Pick<IChainConfig, "SECONDS_PER_SLOT"> = { | ||
SECONDS_PER_SLOT: 2, | ||
}; | ||
|
||
const afterEachCallbacks: (() => Promise<unknown> | void)[] = []; | ||
afterEach(async () => { | ||
while (afterEachCallbacks.length > 0) { | ||
const callback = afterEachCallbacks.pop(); | ||
if (callback) await callback(); | ||
} | ||
}); | ||
|
||
before(async function () { | ||
await initBLS(); | ||
}); | ||
|
||
it("getSyncingStatus", async function () { | ||
this.timeout("10 min"); | ||
const bn = await getDevBeaconNode({ | ||
params: testParams, | ||
options: { | ||
sync: {isSingleNode: true}, | ||
api: {rest: {enabled: true, port: restPort}}, | ||
}, | ||
validatorCount, | ||
logger: loggerNodeA, | ||
}); | ||
|
||
afterEachCallbacks.push(() => bn.close()); | ||
|
||
const client = getClient(config, {baseUrl: "http://127.0.0.1:9596"}).node; | ||
|
||
// expect headSlot and syncDistance to be string | ||
await expect(client.getSyncingStatus()).to.eventually.be.deep.equal({ | ||
data: {headSlot: "0", syncDistance: "0", isSyncing: false}, | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters