2023-09-28 12:00:13 +00:00
|
|
|
|
using CodexContractsPlugin;
|
2023-11-13 08:32:10 +00:00
|
|
|
|
using CodexPlugin;
|
2023-09-28 12:00:13 +00:00
|
|
|
|
using GethPlugin;
|
|
|
|
|
using NUnit.Framework;
|
2023-09-12 13:43:30 +00:00
|
|
|
|
|
2023-11-12 09:36:48 +00:00
|
|
|
|
namespace CodexTests.PeerDiscoveryTests
|
2023-09-12 13:43:30 +00:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
public class PeerDiscoveryTests : AutoBootstrapDistTest
|
|
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public void CanReportUnknownPeerId()
|
|
|
|
|
{
|
|
|
|
|
var unknownId = "16Uiu2HAkv2CHWpff3dj5iuVNERAp8AGKGNgpGjPexJZHSqUstfsK";
|
|
|
|
|
var node = AddCodex();
|
|
|
|
|
|
|
|
|
|
var result = node.GetDebugPeer(unknownId);
|
|
|
|
|
Assert.That(result.IsPeerFound, Is.False);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void MetricsDoesNotInterfereWithPeerDiscovery()
|
|
|
|
|
{
|
2023-09-13 10:24:46 +00:00
|
|
|
|
AddCodex(2, s => s.EnableMetrics());
|
2023-09-12 13:43:30 +00:00
|
|
|
|
|
|
|
|
|
AssertAllNodesConnected();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void MarketplaceDoesNotInterfereWithPeerDiscovery()
|
|
|
|
|
{
|
2023-09-28 12:00:13 +00:00
|
|
|
|
var geth = Ci.StartGethNode(s => s.IsMiner());
|
|
|
|
|
var contracts = Ci.StartCodexContracts(geth);
|
|
|
|
|
AddCodex(2, s => s.EnableMarketplace(geth, contracts, 10.Eth(), 1000.TestTokens()));
|
2023-09-12 13:43:30 +00:00
|
|
|
|
|
|
|
|
|
AssertAllNodesConnected();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestCase(2)]
|
|
|
|
|
[TestCase(3)]
|
|
|
|
|
[TestCase(10)]
|
|
|
|
|
public void VariableNodes(int number)
|
|
|
|
|
{
|
|
|
|
|
AddCodex(number);
|
|
|
|
|
|
|
|
|
|
AssertAllNodesConnected();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AssertAllNodesConnected()
|
|
|
|
|
{
|
2023-11-13 08:32:10 +00:00
|
|
|
|
var allNodes = GetAllOnlineCodexNodes();
|
|
|
|
|
CreatePeerConnectionTestHelpers().AssertFullyConnected(allNodes);
|
|
|
|
|
CheckRoutingTable(allNodes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CheckRoutingTable(IEnumerable<ICodexNode> allNodes)
|
|
|
|
|
{
|
|
|
|
|
var allResponses = allNodes.Select(n => n.GetDebugInfo()).ToArray();
|
|
|
|
|
|
|
|
|
|
var errors = new List<string>();
|
|
|
|
|
foreach (var response in allResponses)
|
|
|
|
|
{
|
|
|
|
|
var error = AreAllPresent(response, allResponses);
|
|
|
|
|
if (!string.IsNullOrEmpty(error)) errors.Add(error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (errors.Any())
|
|
|
|
|
{
|
|
|
|
|
Assert.Fail(string.Join(Environment.NewLine, errors));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string AreAllPresent(CodexDebugResponse info, CodexDebugResponse[] allResponses)
|
|
|
|
|
{
|
|
|
|
|
var knownIds = info.table.nodes.Select(n => n.nodeId).ToArray();
|
|
|
|
|
var allOthers = GetAllOtherResponses(info, allResponses);
|
|
|
|
|
var expectedIds = allOthers.Select(i => i.table.localNode.nodeId).ToArray();
|
|
|
|
|
|
|
|
|
|
if (!expectedIds.All(ex => knownIds.Contains(ex)))
|
|
|
|
|
{
|
|
|
|
|
return $"Node {info.id}: Not all of '{string.Join(",", expectedIds)}' were present in routing table: '{string.Join(",", knownIds)}'";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private CodexDebugResponse[] GetAllOtherResponses(CodexDebugResponse exclude, CodexDebugResponse[] allResponses)
|
|
|
|
|
{
|
|
|
|
|
return allResponses.Where(r => r.id != exclude.id).ToArray();
|
2023-09-12 13:43:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|