mirror of
https://github.com/ipfs/kubo.git
synced 2025-09-09 17:22:21 +08:00

refactor test peer creation to be deterministic and reliable a bit of cleanup trying to figure out TestGetFailure add test to verify deterministic peer creation switch put RPC over to use getClosestPeers rm 0xDEADC0DE fix queries not searching peer if its not actually closer
49 lines
1008 B
Go
49 lines
1008 B
Go
package namesys
|
|
|
|
import (
|
|
"testing"
|
|
|
|
ci "github.com/jbenet/go-ipfs/crypto"
|
|
mockrouting "github.com/jbenet/go-ipfs/routing/mock"
|
|
u "github.com/jbenet/go-ipfs/util"
|
|
testutil "github.com/jbenet/go-ipfs/util/testutil"
|
|
)
|
|
|
|
func TestRoutingResolve(t *testing.T) {
|
|
d := mockrouting.NewServer().Client(testutil.RandIdentityOrFatal(t))
|
|
|
|
resolver := NewRoutingResolver(d)
|
|
publisher := NewRoutingPublisher(d)
|
|
|
|
privk, pubk, err := ci.GenerateKeyPair(ci.RSA, 512, u.NewTimeSeededRand())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
err = publisher.Publish(privk, "Hello")
|
|
if err == nil {
|
|
t.Fatal("should have errored out when publishing a non-multihash val")
|
|
}
|
|
|
|
h := u.Key(u.Hash([]byte("Hello"))).Pretty()
|
|
err = publisher.Publish(privk, h)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
pubkb, err := pubk.Bytes()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
pkhash := u.Hash(pubkb)
|
|
res, err := resolver.Resolve(u.Key(pkhash).Pretty())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if res != h {
|
|
t.Fatal("Got back incorrect value.")
|
|
}
|
|
}
|