2024-12-17 16:06:06 +01:00
|
|
|
|
using BlockchainUtils;
|
2025-01-16 13:51:29 +01:00
|
|
|
|
using CodexClient;
|
2024-12-17 16:06:06 +01:00
|
|
|
|
using CodexContractsPlugin;
|
2023-09-28 12:22:35 +02:00
|
|
|
|
using CodexNetDeployer;
|
2023-09-19 16:22:07 +02:00
|
|
|
|
using CodexPlugin;
|
2024-07-25 16:00:51 +02:00
|
|
|
|
using CodexPlugin.OverwatchSupport;
|
2023-11-12 10:36:48 +01:00
|
|
|
|
using CodexTests.Helpers;
|
2023-09-20 13:56:01 +02:00
|
|
|
|
using Core;
|
2023-09-13 14:24:43 +02:00
|
|
|
|
using DistTestCore;
|
|
|
|
|
|
using DistTestCore.Helpers;
|
2023-09-28 12:22:35 +02:00
|
|
|
|
using DistTestCore.Logs;
|
2024-12-17 16:06:06 +01:00
|
|
|
|
using GethPlugin;
|
2024-07-26 08:39:27 +02:00
|
|
|
|
using Logging;
|
2024-06-06 09:54:50 +02:00
|
|
|
|
using MetricsPlugin;
|
|
|
|
|
|
using Newtonsoft.Json;
|
2024-07-26 10:11:29 +02:00
|
|
|
|
using NUnit.Framework;
|
2023-09-19 16:22:07 +02:00
|
|
|
|
using NUnit.Framework.Constraints;
|
2024-07-25 16:00:51 +02:00
|
|
|
|
using OverwatchTranscript;
|
2023-09-13 14:24:43 +02:00
|
|
|
|
|
2023-10-09 16:59:52 +02:00
|
|
|
|
namespace CodexTests
|
2023-09-13 14:24:43 +02:00
|
|
|
|
{
|
|
|
|
|
|
public class CodexDistTest : DistTest
|
|
|
|
|
|
{
|
2025-04-25 15:42:13 +02:00
|
|
|
|
private readonly BlockCache blockCache = new BlockCache();
|
|
|
|
|
|
private readonly List<ICodexNode> nodes = new List<ICodexNode>();
|
|
|
|
|
|
private CodexTranscriptWriter? writer;
|
2025-01-29 14:44:19 +01:00
|
|
|
|
|
2023-09-20 13:56:01 +02:00
|
|
|
|
public CodexDistTest()
|
|
|
|
|
|
{
|
|
|
|
|
|
ProjectPlugin.Load<CodexPlugin.CodexPlugin>();
|
|
|
|
|
|
ProjectPlugin.Load<CodexContractsPlugin.CodexContractsPlugin>();
|
|
|
|
|
|
ProjectPlugin.Load<GethPlugin.GethPlugin>();
|
|
|
|
|
|
ProjectPlugin.Load<MetricsPlugin.MetricsPlugin>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-25 15:42:13 +02:00
|
|
|
|
[SetUp]
|
|
|
|
|
|
public void SetupCodexDistTest()
|
2023-09-28 12:22:35 +02:00
|
|
|
|
{
|
2025-04-25 15:42:13 +02:00
|
|
|
|
writer = SetupTranscript();
|
2023-09-28 12:22:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-25 15:42:13 +02:00
|
|
|
|
[TearDown]
|
|
|
|
|
|
public void TearDownCodexDistTest()
|
2024-07-25 16:00:51 +02:00
|
|
|
|
{
|
2025-04-25 15:42:13 +02:00
|
|
|
|
TeardownTranscript();
|
2024-07-25 16:00:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-25 15:42:13 +02:00
|
|
|
|
protected override void Initialize(FixtureLog fixtureLog)
|
2024-07-25 16:00:51 +02:00
|
|
|
|
{
|
2025-04-25 15:42:13 +02:00
|
|
|
|
var localBuilder = new LocalCodexBuilder(fixtureLog);
|
|
|
|
|
|
localBuilder.Intialize();
|
|
|
|
|
|
localBuilder.Build();
|
2025-01-29 14:44:19 +01:00
|
|
|
|
|
2025-04-25 15:42:13 +02:00
|
|
|
|
Ci.AddCodexHooksProvider(new CodexLogTrackerProvider(nodes.Add));
|
2024-07-25 16:00:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-09 09:32:48 +02:00
|
|
|
|
public ICodexNode StartCodex()
|
2023-09-13 14:24:43 +02:00
|
|
|
|
{
|
2024-05-09 09:32:48 +02:00
|
|
|
|
return StartCodex(s => { });
|
2023-09-13 14:24:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-09 09:32:48 +02:00
|
|
|
|
public ICodexNode StartCodex(Action<ICodexSetup> setup)
|
2023-09-13 14:24:43 +02:00
|
|
|
|
{
|
2024-05-09 09:32:48 +02:00
|
|
|
|
return StartCodex(1, setup)[0];
|
2023-09-13 14:24:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-09 09:32:48 +02:00
|
|
|
|
public ICodexNodeGroup StartCodex(int numberOfNodes)
|
2023-09-13 14:24:43 +02:00
|
|
|
|
{
|
2024-05-09 09:32:48 +02:00
|
|
|
|
return StartCodex(numberOfNodes, s => { });
|
2023-09-13 14:24:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-09 09:32:48 +02:00
|
|
|
|
public ICodexNodeGroup StartCodex(int numberOfNodes, Action<ICodexSetup> setup)
|
2023-09-13 14:24:43 +02:00
|
|
|
|
{
|
2023-09-20 12:02:32 +02:00
|
|
|
|
var group = Ci.StartCodexNodes(numberOfNodes, s =>
|
2023-09-13 14:24:43 +02:00
|
|
|
|
{
|
|
|
|
|
|
setup(s);
|
|
|
|
|
|
OnCodexSetup(s);
|
|
|
|
|
|
});
|
2024-06-12 15:28:08 +02:00
|
|
|
|
|
2023-09-13 14:24:43 +02:00
|
|
|
|
return group;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-12-17 16:06:06 +01:00
|
|
|
|
public IGethNode StartGethNode(Action<IGethSetup> setup)
|
|
|
|
|
|
{
|
2025-04-25 15:42:13 +02:00
|
|
|
|
return Ci.StartGethNode(blockCache, setup);
|
2024-12-17 16:06:06 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-09-13 14:24:43 +02:00
|
|
|
|
public PeerConnectionTestHelpers CreatePeerConnectionTestHelpers()
|
|
|
|
|
|
{
|
|
|
|
|
|
return new PeerConnectionTestHelpers(GetTestLog());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public PeerDownloadTestHelpers CreatePeerDownloadTestHelpers()
|
|
|
|
|
|
{
|
2025-04-25 15:42:13 +02:00
|
|
|
|
return new PeerDownloadTestHelpers(GetTestLog(), GetFileManager());
|
2023-09-13 14:24:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-29 10:59:10 +02:00
|
|
|
|
public void AssertBalance(ICodexContracts contracts, ICodexNode codexNode, Constraint constraint, string msg)
|
2023-09-19 16:22:07 +02:00
|
|
|
|
{
|
2025-03-11 15:00:27 +01:00
|
|
|
|
Assert.Fail("Depricated, use MarketplaceAutobootstrapDistTest assertBalances instead.");
|
2023-10-30 13:30:14 +01:00
|
|
|
|
AssertHelpers.RetryAssert(constraint, () => contracts.GetTestTokenBalance(codexNode), nameof(AssertBalance) + msg);
|
2023-09-19 16:22:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-12-12 14:18:26 +01:00
|
|
|
|
public void CheckLogForErrors(params ICodexNode[] nodes)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var node in nodes) CheckLogForErrors(node);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void CheckLogForErrors(ICodexNode node)
|
|
|
|
|
|
{
|
2024-03-20 11:11:59 +01:00
|
|
|
|
Log($"Checking {node.GetName()} log for errors.");
|
2025-01-16 10:15:02 +01:00
|
|
|
|
var log = node.DownloadLog();
|
2023-12-12 14:18:26 +01:00
|
|
|
|
|
|
|
|
|
|
log.AssertLogDoesNotContain("Block validation failed");
|
2024-12-04 15:57:49 +01:00
|
|
|
|
log.AssertLogDoesNotContainLinesStartingWith("ERR ");
|
2023-12-12 14:18:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-06 09:54:50 +02:00
|
|
|
|
public void LogNodeStatus(ICodexNode node, IMetricsAccess? metrics = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Log("Status for " + node.GetName() + Environment.NewLine +
|
2024-06-07 17:07:35 +02:00
|
|
|
|
GetBasicNodeStatus(node));
|
2024-06-06 09:54:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-21 10:46:11 +01:00
|
|
|
|
public void WaitAndCheckNodesStaysAlive(TimeSpan duration, ICodexNodeGroup nodes)
|
|
|
|
|
|
{
|
|
|
|
|
|
WaitAndCheckNodesStaysAlive(duration, nodes.ToArray());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void WaitAndCheckNodesStaysAlive(TimeSpan duration, params ICodexNode[] nodes)
|
|
|
|
|
|
{
|
|
|
|
|
|
var start = DateTime.UtcNow;
|
|
|
|
|
|
while ((DateTime.UtcNow - start) < duration)
|
|
|
|
|
|
{
|
|
|
|
|
|
Thread.Sleep(5000);
|
|
|
|
|
|
foreach (var node in nodes)
|
|
|
|
|
|
{
|
|
|
|
|
|
var info = node.GetDebugInfo();
|
|
|
|
|
|
Assert.That(!string.IsNullOrEmpty(info.Id));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void AssertNodesContainFile(ContentId cid, ICodexNodeGroup nodes)
|
|
|
|
|
|
{
|
|
|
|
|
|
AssertNodesContainFile(cid, nodes.ToArray());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void AssertNodesContainFile(ContentId cid, params ICodexNode[] nodes)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var node in nodes)
|
|
|
|
|
|
{
|
|
|
|
|
|
var localDatasets = node.LocalFiles();
|
|
|
|
|
|
CollectionAssert.Contains(localDatasets.Content.Select(c => c.Cid), cid);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-06 09:54:50 +02:00
|
|
|
|
private string GetBasicNodeStatus(ICodexNode node)
|
|
|
|
|
|
{
|
|
|
|
|
|
return JsonConvert.SerializeObject(node.GetDebugInfo(), Formatting.Indented) + Environment.NewLine +
|
|
|
|
|
|
node.Space().ToString() + Environment.NewLine;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-09-13 14:24:43 +02:00
|
|
|
|
protected virtual void OnCodexSetup(ICodexSetup setup)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
2024-07-26 10:11:29 +02:00
|
|
|
|
|
2024-07-31 09:50:02 +02:00
|
|
|
|
private CreateTranscriptAttribute? GetTranscriptAttributeOfCurrentTest()
|
|
|
|
|
|
{
|
|
|
|
|
|
var attrs = GetCurrentTestMethodAttribute<CreateTranscriptAttribute>();
|
|
|
|
|
|
if (attrs.Any()) return attrs.Single();
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-25 15:42:13 +02:00
|
|
|
|
private CodexTranscriptWriter? SetupTranscript()
|
2024-07-26 10:11:29 +02:00
|
|
|
|
{
|
2024-08-21 09:53:20 +02:00
|
|
|
|
var attr = GetTranscriptAttributeOfCurrentTest();
|
2025-04-25 15:42:13 +02:00
|
|
|
|
if (attr == null) return null;
|
2024-08-21 09:53:20 +02:00
|
|
|
|
|
|
|
|
|
|
var config = new CodexTranscriptWriterConfig(
|
2025-04-25 15:42:13 +02:00
|
|
|
|
attr.OutputFilename,
|
2024-08-21 09:53:20 +02:00
|
|
|
|
attr.IncludeBlockReceivedEvents
|
|
|
|
|
|
);
|
2024-07-26 10:11:29 +02:00
|
|
|
|
|
2025-04-25 15:42:13 +02:00
|
|
|
|
var log = new LogPrefixer(GetTestLog(), "(Transcript) ");
|
2024-08-21 09:53:20 +02:00
|
|
|
|
var writer = new CodexTranscriptWriter(log, config, Transcript.NewWriter(log));
|
2025-01-29 14:44:19 +01:00
|
|
|
|
Ci.AddCodexHooksProvider(writer);
|
2025-04-25 15:42:13 +02:00
|
|
|
|
return writer;
|
2024-07-26 10:11:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-25 15:42:13 +02:00
|
|
|
|
private void TeardownTranscript()
|
2024-07-26 10:11:29 +02:00
|
|
|
|
{
|
2025-04-25 15:42:13 +02:00
|
|
|
|
if (writer == null) return;
|
2024-07-26 10:11:29 +02:00
|
|
|
|
|
2025-04-25 15:42:13 +02:00
|
|
|
|
var result = GetTestResult();
|
|
|
|
|
|
var log = GetTestLog();
|
2024-07-26 10:11:29 +02:00
|
|
|
|
writer.AddResult(result.Success, result.Result);
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2025-04-25 15:42:13 +02:00
|
|
|
|
Stopwatch.Measure(log, "Transcript.ProcessLogs", () =>
|
2024-07-26 10:11:29 +02:00
|
|
|
|
{
|
2025-04-25 15:42:13 +02:00
|
|
|
|
writer.ProcessLogs(DownloadAllLogs());
|
2024-07-26 10:11:29 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
2025-04-25 15:42:13 +02:00
|
|
|
|
Stopwatch.Measure(log, $"Transcript.FinalizeWriter", () =>
|
2024-07-26 10:11:29 +02:00
|
|
|
|
{
|
2025-04-25 16:13:01 +02:00
|
|
|
|
writer.IncludeFile(log.GetFullName() + ".log");
|
2025-04-25 15:42:13 +02:00
|
|
|
|
writer.FinalizeWriter();
|
2024-07-26 10:11:29 +02:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
2025-04-25 15:42:13 +02:00
|
|
|
|
log.Error("Failure during transcript teardown: " + ex);
|
2024-12-17 16:06:06 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-07-31 09:50:02 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
|
|
|
|
|
|
public class CreateTranscriptAttribute : PropertyAttribute
|
|
|
|
|
|
{
|
2024-08-21 09:53:20 +02:00
|
|
|
|
public CreateTranscriptAttribute(string outputFilename, bool includeBlockReceivedEvents = true)
|
2024-07-31 09:50:02 +02:00
|
|
|
|
{
|
|
|
|
|
|
OutputFilename = outputFilename;
|
2024-08-21 09:53:20 +02:00
|
|
|
|
IncludeBlockReceivedEvents = includeBlockReceivedEvents;
|
2024-07-31 09:50:02 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string OutputFilename { get; }
|
2024-08-21 09:53:20 +02:00
|
|
|
|
public bool IncludeBlockReceivedEvents { get; }
|
2023-09-13 14:24:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|