This repository was archived by the owner on Jun 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
test: basic routing interface test #103
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"version": "v0.10.0" | ||
"version": "v0.11.0" | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 thenget
, you won't get the same result. For example, if you put random data on yourself
key, you'll just get the latestipns
key. So I think there's some DHT verification somewhere to avoid invalid data to getting added.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hacdias yes https://grep.app/search?q=validator&filter[repo][0]=libp2p/go-libp2p-kad-dht