Skip to content

Commit

Permalink
test(FindPeer): DHT can return a closer peer
Browse files Browse the repository at this point in the history
Issue #19
  • Loading branch information
richardschneider committed Nov 11, 2017
1 parent 711a920 commit 20963b9
Showing 1 changed file with 38 additions and 39 deletions.
77 changes: 38 additions & 39 deletions test/CoreApi/DhtApiTest.cs
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(""));
}

}
}

0 comments on commit 20963b9

Please sign in to comment.