-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(FindPeer): DHT can return a closer peer
Issue #19
- Loading branch information
1 parent
711a920
commit 20963b9
Showing
1 changed file
with
38 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,38 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Newtonsoft.Json.Linq; | ||
using System; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Ipfs.Api | ||
{ | ||
|
||
[TestClass] | ||
public class DhtApiTest | ||
{ | ||
const string marsId = "QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3"; | ||
const string marsPublicKey = "CAASogEwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAKGUtbRQf+a9SBHFEruNAUatS/tsGUnHuCtifGrlbYPELD3UyyhWf/FYczBCavx3i8hIPEW2jQv4ehxQxi/cg9SHswZCQblSi0ucwTBFr8d40JEiyB9CcapiMdFQxdMgGvXEOQdLz1pz+UPUDojkdKZq8qkkeiBn7KlAoGEocnmpAgMBAAE="; | ||
const string helloWorldID = "QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o"; | ||
|
||
[TestMethod] | ||
public async Task FindPeer() | ||
{ | ||
var ipfs = TestFixture.Ipfs; | ||
var mars = await ipfs.Dht.FindPeerAsync(marsId); | ||
Assert.AreEqual(marsId, mars.Id); | ||
|
||
// Sometimes the public key is not returned! | ||
if (!string.IsNullOrEmpty(mars.PublicKey)) | ||
Assert.AreEqual(marsPublicKey, mars.PublicKey); | ||
} | ||
|
||
[TestMethod] | ||
public async Task FindProviders() | ||
{ | ||
var ipfs = TestFixture.Ipfs; | ||
var providers = await ipfs.Dht.FindProvidersAsync(helloWorldID); | ||
Assert.IsFalse(providers.Take(3).Contains("")); | ||
} | ||
|
||
} | ||
} | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Newtonsoft.Json.Linq; | ||
using System; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Ipfs.Api | ||
{ | ||
|
||
[TestClass] | ||
public class DhtApiTest | ||
{ | ||
const string marsId = "QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3"; | ||
const string marsPublicKey = "CAASogEwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAKGUtbRQf+a9SBHFEruNAUatS/tsGUnHuCtifGrlbYPELD3UyyhWf/FYczBCavx3i8hIPEW2jQv4ehxQxi/cg9SHswZCQblSi0ucwTBFr8d40JEiyB9CcapiMdFQxdMgGvXEOQdLz1pz+UPUDojkdKZq8qkkeiBn7KlAoGEocnmpAgMBAAE="; | ||
const string helloWorldID = "QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o"; | ||
|
||
[TestMethod] | ||
public async Task FindPeer() | ||
{ | ||
var ipfs = TestFixture.Ipfs; | ||
var peer = await ipfs.Dht.FindPeerAsync(marsId); | ||
|
||
// If DHT can't find a peer, it will return a 'closer' peer. | ||
Assert.IsNotNull(peer); | ||
Assert.AreNotEqual(0, peer.Addresses.Count()); | ||
} | ||
|
||
[TestMethod] | ||
public async Task FindProviders() | ||
{ | ||
var ipfs = TestFixture.Ipfs; | ||
var providers = await ipfs.Dht.FindProvidersAsync(helloWorldID); | ||
Assert.IsFalse(providers.Take(3).Contains("")); | ||
} | ||
|
||
} | ||
} |