-
-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Allow preset overrides * Apply review comments * Update packages/params/README.md * Update overridePresetError.ts * Update packages/params/test/e2e/overridePresetError.ts Co-authored-by: Cayman <caymannava@gmail.com> Co-authored-by: Lion - dapplion <35266934+dapplion@users.noreply.github.com>
- Loading branch information
1 parent
081afbb
commit 1cba836
Showing
6 changed files
with
76 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import path from "node:path"; | ||
import util from "node:util"; | ||
import child from "node:child_process"; | ||
import {fileURLToPath} from "node:url"; | ||
import {expect, use} from "chai"; | ||
import chaiAsPromised from "chai-as-promised"; | ||
|
||
const scriptNames = { | ||
ok: "overridePresetOk.ts", | ||
error: "overridePresetError.ts", | ||
}; | ||
|
||
use(chaiAsPromised); | ||
|
||
const exec = util.promisify(child.exec); | ||
|
||
// Global variable __dirname no longer available in ES6 modules. | ||
// Solutions: https://stackoverflow.com/questions/46745014/alternative-for-dirname-in-node-js-when-using-es6-modules | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
const tsNodeBinary = path.join(__dirname, "../../../../node_modules/.bin/ts-node-esm"); | ||
|
||
describe("Override preset", function () { | ||
// Allow time for ts-node to compile Typescript source | ||
this.timeout(30_000); | ||
|
||
it("Should correctly override preset", async () => { | ||
await exec(`${tsNodeBinary} ${path.join(__dirname, scriptNames.ok)}`); | ||
}); | ||
|
||
it("Should throw trying to override preset in the wrong order", async () => { | ||
await expect(exec(`${tsNodeBinary} ${path.join(__dirname, scriptNames.error)}`)).to.be.rejectedWith( | ||
"Lodestar preset is already frozen" | ||
); | ||
}); | ||
}); |
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,11 @@ | ||
// This script is should be run in an e2e !! | ||
// It demostrates how NOT to change the Lodestar preset | ||
|
||
// 1. Import from not only @lodestar/params/setPreset will trigger an error | ||
import {SLOTS_PER_EPOCH} from "../../lib/index.js"; | ||
import {setActivePreset, PresetName} from "../../lib/setPreset.js"; | ||
// This line should throw | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
setActivePreset(PresetName.minimal, {SLOTS_PER_EPOCH: 2}); | ||
|
||
SLOTS_PER_EPOCH; |
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,18 @@ | ||
import assert from "node:assert"; | ||
|
||
/* eslint import/order: "off" */ | ||
// This script is should be run in an e2e !! | ||
// It demostrates how to properly change the Lodestar preset safely | ||
|
||
// 1. Import from @lodestar/params/setPreset only | ||
import {setActivePreset, PresetName} from "../../src/setPreset.js"; | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
setActivePreset(PresetName.minimal, {SLOTS_PER_EPOCH: 2}); | ||
|
||
// 2. Import from any other @lodestar/params paths | ||
|
||
const {SLOTS_PER_EPOCH, BASE_REWARD_FACTOR} = await import("../../src/index.js"); | ||
|
||
assert.equal(SLOTS_PER_EPOCH, 2, "SLOTS_PER_EPOCH should have overriden preset value"); | ||
assert.equal(BASE_REWARD_FACTOR, 64, "BASE_REWARD_FACTOR should have preset value"); | ||
assert.equal(process.env.LODESTAR_PRESET, undefined, "LODESTAR_PRESET ENV must not be set"); |