records_test.go 575 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 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")
	}
}