-
-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: simplify bootnode enr initialization (#5945)
* feat: simplify enr initialization * chore: fix tests * chore: more cleanup
- Loading branch information
1 parent
80c001b
commit 6bdaebd
Showing
3 changed files
with
104 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import fs from "node:fs"; | ||
import tmp from "tmp"; | ||
import {expect} from "chai"; | ||
import {initPeerIdAndEnr} from "../../../src/cmds/beacon/initPeerIdAndEnr.js"; | ||
import {BeaconArgs} from "../../../src/cmds/beacon/options.js"; | ||
import {testLogger} from "../../utils.js"; | ||
|
||
describe("initPeerIdAndEnr", () => { | ||
let tmpDir: tmp.DirResult; | ||
|
||
beforeEach(() => { | ||
tmpDir = tmp.dirSync(); | ||
}); | ||
|
||
afterEach(() => { | ||
fs.rmSync(tmpDir.name, {recursive: true}); | ||
}); | ||
|
||
it("first time should create a new enr and peer id", async () => { | ||
const {enr, peerId} = await initPeerIdAndEnr( | ||
{persistNetworkIdentity: true} as unknown as BeaconArgs, | ||
tmpDir.name, | ||
testLogger(), | ||
true | ||
); | ||
expect((await enr.peerId()).toString(), "enr peer id doesn't equal the returned peer id").to.equal( | ||
peerId.toString() | ||
); | ||
expect(enr.seq).to.equal(BigInt(1)); | ||
expect(enr.tcp).to.equal(undefined); | ||
expect(enr.tcp6).to.equal(undefined); | ||
}); | ||
|
||
it("second time should use ths existing enr and peer id", async () => { | ||
const run1 = await initPeerIdAndEnr( | ||
{persistNetworkIdentity: true} as unknown as BeaconArgs, | ||
tmpDir.name, | ||
testLogger(), | ||
true | ||
); | ||
|
||
const run2 = await initPeerIdAndEnr( | ||
{persistNetworkIdentity: true} as unknown as BeaconArgs, | ||
tmpDir.name, | ||
testLogger(), | ||
true | ||
); | ||
|
||
expect(run1.peerId.toString()).to.equal(run2.peerId.toString()); | ||
expect(run1.enr.encodeTxt()).to.equal(run2.enr.encodeTxt()); | ||
}); | ||
}); |