mirror of
https://github.com/fluencelabs/go-libp2p-kad-dht
synced 2025-04-24 22:32:13 +00:00
add test for ed25519 pubkey extraction
This commit is contained in:
parent
0b9c5e8a3e
commit
95a3e5dae2
34
records_test.go
Normal file
34
records_test.go
Normal file
@ -0,0 +1,34 @@
|
||||
package dht
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"testing"
|
||||
|
||||
ci "github.com/libp2p/go-libp2p-crypto"
|
||||
peer "github.com/libp2p/go-libp2p-peer"
|
||||
)
|
||||
|
||||
func TestPubkeyExtract(t *testing.T) {
|
||||
_, pk, err := ci.GenerateEd25519Key(rand.Reader)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
pid, err := peer.IDFromEd25519PublicKey(pk)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// no need to actually construct one
|
||||
d := new(IpfsDHT)
|
||||
|
||||
pk_out, err := d.GetPublicKey(context.Background(), pid)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !pk_out.Equals(pk) {
|
||||
t.Fatal("got incorrect public key out")
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user