dht_test.go 581 Bytes
Newer Older
Jeromy's avatar
Jeromy committed
1 2 3 4 5 6
package commands

import (
	"testing"

	"github.com/ipfs/go-ipfs/namesys"
7

Jakub Sztandera's avatar
Jakub Sztandera committed
8
	ipns "github.com/ipfs/go-ipns"
Raúl Kripalani's avatar
Raúl Kripalani committed
9
	"github.com/libp2p/go-libp2p-core/test"
Jeromy's avatar
Jeromy committed
10 11 12
)

func TestKeyTranslation(t *testing.T) {
Raúl Kripalani's avatar
Raúl Kripalani committed
13
	pid := test.RandPeerIDFatal(t)
14 15
	pkname := namesys.PkKeyForID(pid)
	ipnsname := ipns.RecordKey(pid)
Jeromy's avatar
Jeromy committed
16 17 18 19 20 21 22 23 24 25 26

	pkk, err := escapeDhtKey("/pk/" + pid.Pretty())
	if err != nil {
		t.Fatal(err)
	}

	ipnsk, err := escapeDhtKey("/ipns/" + pid.Pretty())
	if err != nil {
		t.Fatal(err)
	}

27
	if pkk != pkname {
Jeromy's avatar
Jeromy committed
28 29 30
		t.Fatal("keys didnt match!")
	}

31
	if ipnsk != ipnsname {
Jeromy's avatar
Jeromy committed
32 33 34
		t.Fatal("keys didnt match!")
	}
}