Skip to content

Commit

Permalink
chore: pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Oct 25, 2024
1 parent 71aa34d commit 084e83e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
4 changes: 2 additions & 2 deletions packages/kad-dht/test/rpc/handlers/get-value.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('rpc - handlers - GetValue', () => {

handler = new GetValueHandler(components, {
peerRouting,
logPrefix: ''
logPrefix: 'dht'
})
})

Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions packages/kad-dht/test/rpc/handlers/put-value.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('rpc - handlers - PutValue', () => {

handler = new PutValueHandler(components, {
validators,
logPrefix: ''
logPrefix: 'dht'
})
})

Expand Down Expand Up @@ -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)
Expand Down
24 changes: 8 additions & 16 deletions packages/kad-dht/test/utils/create-peer-id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,16 @@ import type { PeerId, PrivateKey } from '@libp2p/interface'
*/
export async function createPeerIds (length: number): Promise<PeerId[]> {
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())
)
}

/**
* Creates a PeerId
*/
export async function createPeerId (): Promise<PeerId> {
const ids = await createPeerIds(1)

return ids[0]
const privateKey = await generateKeyPair('Ed25519')
return peerIdFromPrivateKey(privateKey)
}

export type PeerIdWithPrivateKey = PeerId & {
Expand All @@ -32,21 +28,17 @@ export type PeerIdWithPrivateKey = PeerId & {
*/
export async function createPeerIdsWithPrivateKey (length: number): Promise<PeerIdWithPrivateKey[]> {
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())
)
}

/**
* Creates a PeerId with a private key
*/
export async function createPeerIdWithPrivateKey (): Promise<PeerIdWithPrivateKey> {
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
}

0 comments on commit 084e83e

Please sign in to comment.