Skip to content
This repository was archived by the owner on Jun 26, 2023. It is now read-only.

Commit a753fe9

Browse files
committed
🧪 Fix the compliance test for peer-id to avoid undefined check
1 parent 8239ba0 commit a753fe9

File tree

1 file changed

+11
-11
lines changed
  • packages/libp2p-interfaces-compliance-tests/src/peer-id

1 file changed

+11
-11
lines changed

packages/libp2p-interfaces-compliance-tests/src/peer-id/index.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ export default (common: TestSetup<PeerIdFactory>) => {
5858

5959
it('can be created for a Secp256k1 key', async () => {
6060
const id = await factory.create({ keyType: 'secp256k1', bits: 256 })
61-
const expB58 = base58btc.encode((await identity.digest(id.pubKey.bytes)).bytes).slice(1)
61+
const expB58 = base58btc.encode((await identity.digest(id.pubKey!.bytes)).bytes).slice(1)
6262
expect(id.toB58String()).to.equal(expB58)
6363
})
6464

6565
it('can get the public key from a Secp256k1 key', async () => {
6666
const original = await factory.create({ keyType: 'secp256k1', bits: 256 })
6767
const newId = factory.createFromB58String(original.toB58String())
68-
expect(original.pubKey.bytes).to.eql(newId.pubKey.bytes)
68+
expect(original.pubKey!.bytes).to.eql(newId.pubKey!.bytes)
6969
})
7070

7171
it('isPeerId', async () => {
@@ -194,15 +194,15 @@ export default (common: TestSetup<PeerIdFactory>) => {
194194
const key = '12D3KooWRm8J3iL796zPFi2EtGGtUJn58AG67gcqzMFHZnnsTzqD'
195195
const id = await factory.parse(key)
196196
expect(id.toB58String()).to.equal(key)
197-
const expB58 = base58btc.encode((await identity.digest(id.pubKey.bytes)).bytes).slice(1)
197+
const expB58 = base58btc.encode((await identity.digest(id.pubKey!.bytes)).bytes).slice(1)
198198
expect(id.toB58String()).to.equal(expB58)
199199
})
200200

201201
it('recreate from embedded secp256k1 key', async () => {
202202
const key = '16Uiu2HAm5qw8UyXP2RLxQUx5KvtSN8DsTKz8quRGqGNC3SYiaB8E'
203203
const id = await factory.parse(key)
204204
expect(id.toB58String()).to.equal(key)
205-
const expB58 = base58btc.encode((await identity.digest(id.pubKey.bytes)).bytes).slice(1)
205+
const expB58 = base58btc.encode((await identity.digest(id.pubKey!.bytes)).bytes).slice(1)
206206
expect(id.toB58String()).to.equal(expB58)
207207
})
208208

@@ -215,20 +215,20 @@ export default (common: TestSetup<PeerIdFactory>) => {
215215
it('can be created from a Secp256k1 public key', async () => {
216216
const privKey = await crypto.keys.generateKeyPair('secp256k1', 256)
217217
const id = await factory.createFromPubKey(privKey.public.bytes)
218-
const expB58 = base58btc.encode((await identity.digest(id.pubKey.bytes)).bytes).slice(1)
218+
const expB58 = base58btc.encode((await identity.digest(id.pubKey!.bytes)).bytes).slice(1)
219219
expect(id.toB58String()).to.equal(expB58)
220220
})
221221

222222
it('can be created from a Secp256k1 private key', async () => {
223223
const privKey = await crypto.keys.generateKeyPair('secp256k1', 256)
224224
const id = await factory.createFromPrivKey(privKey.bytes)
225-
const expB58 = base58btc.encode((await identity.digest(id.pubKey.bytes)).bytes).slice(1)
225+
const expB58 = base58btc.encode((await identity.digest(id.pubKey!.bytes)).bytes).slice(1)
226226
expect(id.toB58String()).to.equal(expB58)
227227
})
228228

229229
it('Compare generated ID with one created from PubKey', async () => {
230230
const id1 = await factory.create(testOpts)
231-
const id2 = await factory.createFromPubKey(id1.marshalPubKey())
231+
const id2 = await factory.createFromPubKey(id1.marshalPubKey()!)
232232
expect(id1.id).to.be.eql(id2.id)
233233
})
234234

@@ -242,7 +242,7 @@ export default (common: TestSetup<PeerIdFactory>) => {
242242
this.timeout(1000 * 60)
243243
const shortId = await factory.create(testOpts)
244244
const longId = await factory.create({ bits: 1024 })
245-
expect(shortId.privKey.bytes.length).is.below(longId.privKey.bytes.length)
245+
expect(shortId.privKey!.bytes.length).is.below(longId.privKey!.bytes.length)
246246
})
247247

248248
it('Pretty printing', async () => {
@@ -292,8 +292,8 @@ export default (common: TestSetup<PeerIdFactory>) => {
292292
const id = await factory.create(testOpts)
293293
const other = await factory.createFromJSON(id.toJSON())
294294
expect(id.toB58String()).to.equal(other.toB58String())
295-
expect(id.privKey.bytes).to.eql(other.privKey.bytes)
296-
expect(id.pubKey.bytes).to.eql(other.pubKey.bytes)
295+
expect(id.privKey!.bytes).to.eql(other.privKey!.bytes)
296+
expect(id.pubKey!.bytes).to.eql(other.pubKey!.bytes)
297297
})
298298

299299
it('only id', async () => {
@@ -308,7 +308,7 @@ export default (common: TestSetup<PeerIdFactory>) => {
308308

309309
it('go interop', async () => {
310310
const id = await factory.createFromJSON(goId)
311-
const digest = await id.privKey.public.hash()
311+
const digest = await id.privKey!.public.hash()
312312
expect(base58btc.encode(digest).slice(1)).to.eql(goId.id)
313313
})
314314
})

0 commit comments

Comments
 (0)