diff --git a/packages/kad-dht/test/rpc/handlers/get-value.spec.ts b/packages/kad-dht/test/rpc/handlers/get-value.spec.ts index 0e5c590aa2..1b3c537b99 100644 --- a/packages/kad-dht/test/rpc/handlers/get-value.spec.ts +++ b/packages/kad-dht/test/rpc/handlers/get-value.spec.ts @@ -52,7 +52,7 @@ describe('rpc - handlers - GetValue', () => { handler = new GetValueHandler(components, { peerRouting, - logPrefix: '' + logPrefix: 'dht' }) }) @@ -79,7 +79,7 @@ describe('rpc - handlers - GetValue', () => { const value = uint8ArrayFromString('world') const record = new Libp2pRecord(key, value, new Date()) - await datastore.put(utils.bufferToRecordKey('//record', key), record.serialize().subarray()) + await datastore.put(utils.bufferToRecordKey('/dht/record', key), record.serialize().subarray()) const msg: Message = { type: T, diff --git a/packages/kad-dht/test/rpc/handlers/put-value.spec.ts b/packages/kad-dht/test/rpc/handlers/put-value.spec.ts index 98459b2984..46ecf678c1 100644 --- a/packages/kad-dht/test/rpc/handlers/put-value.spec.ts +++ b/packages/kad-dht/test/rpc/handlers/put-value.spec.ts @@ -35,7 +35,7 @@ describe('rpc - handlers - PutValue', () => { handler = new PutValueHandler(components, { validators, - logPrefix: '' + logPrefix: 'dht' }) }) @@ -75,7 +75,7 @@ describe('rpc - handlers - PutValue', () => { const response = await handler.handle(sourcePeer, msg) expect(response).to.deep.equal(msg) - const key = utils.bufferToRecordKey('//record', uint8ArrayFromString('hello')) + const key = utils.bufferToRecordKey('/dht/record', uint8ArrayFromString('hello')) const res = await datastore.get(key) const rec = Libp2pRecord.deserialize(res) diff --git a/packages/kad-dht/test/utils/create-peer-id.ts b/packages/kad-dht/test/utils/create-peer-id.ts index ccf1892e12..542a9d0ec9 100644 --- a/packages/kad-dht/test/utils/create-peer-id.ts +++ b/packages/kad-dht/test/utils/create-peer-id.ts @@ -7,10 +7,7 @@ import type { PeerId, PrivateKey } from '@libp2p/interface' */ export async function createPeerIds (length: number): Promise { return Promise.all( - new Array(length).fill(0).map(async () => { - const privateKey = await generateKeyPair('Ed25519') - return peerIdFromPrivateKey(privateKey) - }) + new Array(length).fill(0).map(async () => createPeerId()) ) } @@ -18,9 +15,8 @@ export async function createPeerIds (length: number): Promise { * Creates a PeerId */ export async function createPeerId (): Promise { - const ids = await createPeerIds(1) - - return ids[0] + const privateKey = await generateKeyPair('Ed25519') + return peerIdFromPrivateKey(privateKey) } export type PeerIdWithPrivateKey = PeerId & { @@ -32,13 +28,7 @@ export type PeerIdWithPrivateKey = PeerId & { */ export async function createPeerIdsWithPrivateKey (length: number): Promise { return Promise.all( - new Array(length).fill(0).map(async () => { - const privateKey = await generateKeyPair('Ed25519') - const peerId = peerIdFromPrivateKey(privateKey) as unknown as PeerIdWithPrivateKey - peerId.privateKey = privateKey - - return peerId - }) + new Array(length).fill(0).map(async () => createPeerIdWithPrivateKey()) ) } @@ -46,7 +36,9 @@ export async function createPeerIdsWithPrivateKey (length: number): Promise { - const ids = await createPeerIdsWithPrivateKey(1) + const privateKey = await generateKeyPair('Ed25519') + const peerId = peerIdFromPrivateKey(privateKey) as unknown as PeerIdWithPrivateKey + peerId.privateKey = privateKey - return ids[0] + return peerId }