-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement GetValue * Add failing TestGetValueOnePeer test * Unexport methods
- Loading branch information
Showing
6 changed files
with
319 additions
and
163 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,67 @@ | ||
package dht | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/libp2p/go-libp2p/core/crypto" | ||
"github.com/libp2p/go-libp2p/core/peer" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/libp2p/go-libp2p-kad-dht/v2/internal/kadtest" | ||
) | ||
|
||
func makePkKeyValue(t *testing.T) (string, []byte) { | ||
t.Helper() | ||
|
||
_, pub, _ := crypto.GenerateEd25519Key(rng) | ||
v, err := crypto.MarshalPublicKey(pub) | ||
require.NoError(t, err) | ||
|
||
id, err := peer.IDFromPublicKey(pub) | ||
require.NoError(t, err) | ||
|
||
key := fmt.Sprintf("/pk/%s", string(id)) | ||
|
||
return key, v | ||
} | ||
|
||
func TestGetSetValueLocal(t *testing.T) { | ||
ctx := kadtest.CtxShort(t) | ||
|
||
top := NewTopology(t) | ||
d := top.AddServer(nil) | ||
|
||
key, v := makePkKeyValue(t) | ||
|
||
err := d.putValueLocal(ctx, key, v) | ||
require.NoError(t, err) | ||
|
||
val, err := d.getValueLocal(ctx, key) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, v, val) | ||
} | ||
|
||
func TestGetValueOnePeer(t *testing.T) { | ||
t.Skip("not implemented yet") | ||
|
||
ctx := kadtest.CtxShort(t) | ||
top := NewTopology(t) | ||
local := top.AddServer(nil) | ||
remote := top.AddServer(nil) | ||
|
||
// store the value on the remote DHT | ||
key, v := makePkKeyValue(t) | ||
err := remote.putValueLocal(ctx, key, v) | ||
require.NoError(t, err) | ||
|
||
// connect the two DHTs | ||
top.Connect(ctx, local, remote) | ||
|
||
// ask the local DHT to find the value | ||
val, err := local.GetValue(ctx, key) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, v, val) | ||
} |
Oops, something went wrong.