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

test: basic routing interface test #103

Merged
merged 2 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
module github.com/ipfs/interface-go-ipfs-core

require (
github.com/gogo/protobuf v1.3.2
github.com/ipfs/go-cid v0.3.2
github.com/ipfs/go-ipld-cbor v0.0.5
github.com/ipfs/go-ipld-format v0.3.0
github.com/ipfs/go-ipns v0.3.0
github.com/ipfs/go-libipfs v0.1.0
github.com/ipfs/go-merkledag v0.6.0
github.com/ipfs/go-path v0.1.1
Expand All @@ -18,7 +20,6 @@ require (
require (
github.com/crackcomm/go-gitignore v0.0.0-20170627025303-887ab5e44cc3 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/ipfs/bbloom v0.0.4 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ github.com/ipfs/go-ipld-format v0.3.0 h1:Mwm2oRLzIuUwEPewWAWyMuuBQUsn3awfFEYVb8a
github.com/ipfs/go-ipld-format v0.3.0/go.mod h1:co/SdBE8h99968X0hViiw1MNlh6fvxxnHpvVLnH7jSM=
github.com/ipfs/go-ipld-legacy v0.1.0 h1:wxkkc4k8cnvIGIjPO0waJCe7SHEyFgl+yQdafdjGrpA=
github.com/ipfs/go-ipld-legacy v0.1.0/go.mod h1:86f5P/srAmh9GcIcWQR9lfFLZPrIyyXQeVlOWeeWEuI=
github.com/ipfs/go-ipns v0.3.0 h1:ai791nTgVo+zTuq2bLvEGmWP1M0A6kGTXUsgv/Yq67A=
github.com/ipfs/go-ipns v0.3.0/go.mod h1:3cLT2rbvgPZGkHJoPO1YMJeh6LtkxopCkKFcio/wE24=
github.com/ipfs/go-libipfs v0.1.0 h1:I6CrHHp4cIiqsWJPVU3QBH4BZrRWSljS2aAbA3Eg9AY=
github.com/ipfs/go-libipfs v0.1.0/go.mod h1:qX0d9h+wu53PFtCTXxdXVBakd6ZCvGDdkZUKmdLMLx0=
github.com/ipfs/go-log v0.0.1/go.mod h1:kL1d2/hzSpI0thNYjiKfjanbVNU+IIGA/WnNESY9leM=
Expand Down
1 change: 1 addition & 0 deletions tests/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func TestApi(p Provider) func(t *testing.T) {
t.Run("Path", tp.TestPath)
t.Run("Pin", tp.TestPin)
t.Run("PubSub", tp.TestPubSub)
t.Run("Routing", tp.TestRouting)
t.Run("Unixfs", tp.TestUnixfs)

apis <- -1
Expand Down
92 changes: 92 additions & 0 deletions tests/routing.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package tests

import (
"context"
"testing"
"time"

"github.com/gogo/protobuf/proto"
ipns_pb "github.com/ipfs/go-ipns/pb"
iface "github.com/ipfs/interface-go-ipfs-core"
)

func (tp *TestSuite) TestRouting(t *testing.T) {
tp.hasApi(t, func(api iface.CoreAPI) error {
if api.Routing() == nil {
return errAPINotImplemented
}
return nil
})

t.Run("TestRoutingGet", tp.TestRoutingGet)
t.Run("TestRoutingPut", tp.TestRoutingPut)
}

func (tp *TestSuite) testRoutingPublishKey(t *testing.T, ctx context.Context, api iface.CoreAPI) iface.IpnsEntry {
p, err := addTestObject(ctx, api)
if err != nil {
t.Fatal(err)
}

entry, err := api.Name().Publish(ctx, p)
if err != nil {
t.Fatal(err)
}

time.Sleep(3 * time.Second)
return entry
}

func (tp *TestSuite) TestRoutingGet(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

apis, err := tp.MakeAPISwarm(ctx, true, 2)
if err != nil {
t.Fatal(err)
}

// Node 1: publishes an IPNS name
ipnsEntry := tp.testRoutingPublishKey(t, ctx, apis[0])

// Node 2: retrieves the best value for the IPNS name.
data, err := apis[1].Routing().Get(ctx, "/ipns/"+ipnsEntry.Name())
if err != nil {
t.Fatal(err)
}

// Checks if values match.
var entry ipns_pb.IpnsEntry
err = proto.Unmarshal(data, &entry)
if err != nil {
t.Fatal(err)
}

if string(entry.GetValue()) != ipnsEntry.Value().String() {
t.Fatalf("routing key has wrong value, expected %s, got %s", ipnsEntry.Value().String(), string(entry.GetValue()))
}
}

func (tp *TestSuite) TestRoutingPut(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
apis, err := tp.MakeAPISwarm(ctx, true, 1)
if err != nil {
t.Fatal(err)
}

// Create and publish IPNS entry.
ipnsEntry := tp.testRoutingPublishKey(t, ctx, apis[0])

// Get valid routing value.
data, err := apis[0].Routing().Get(ctx, "/ipns/"+ipnsEntry.Name())
if err != nil {
t.Fatal(err)
}

// Put routing value.
err = apis[0].Routing().Put(ctx, "/ipns/"+ipnsEntry.Name(), data)
if err != nil {
t.Fatal(err)
}
Comment on lines +87 to +91
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice if we would try to fetch the thing we stored, this would catch silent failure, with the current setup that would not work since you don't know if this was stored by the original ipns publish or the second put.

Copy link
Member Author

@hacdias hacdias Feb 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jorropo i can do that too. I didn't do it initially for illustration purposes since I didn't want to be adding random things.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jorropo actually, I think there must be some kind of internal verification afterwards. If you do ipfs routing put and then get, you won't get the same result. For example, if you put random data on your self key, you'll just get the latest ipns key. So I think there's some DHT verification somewhere to avoid invalid data to getting added.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "v0.10.0"
"version": "v0.11.0"
}