2023-06-28 09:48:05 +00:00
|
|
|
|
using DistTestCore.Codex;
|
|
|
|
|
using DistTestCore.Marketplace;
|
|
|
|
|
using DistTestCore;
|
|
|
|
|
using KubernetesWorkflow;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using Logging;
|
2023-06-28 10:01:20 +00:00
|
|
|
|
using Utils;
|
2023-08-18 08:31:20 +00:00
|
|
|
|
using DistTestCore.Logs;
|
2023-06-28 09:48:05 +00:00
|
|
|
|
|
|
|
|
|
namespace ContinuousTests
|
|
|
|
|
{
|
|
|
|
|
public class NodeRunner
|
|
|
|
|
{
|
2023-06-28 13:11:20 +00:00
|
|
|
|
private readonly K8sFactory k8SFactory = new K8sFactory();
|
2023-06-29 14:07:49 +00:00
|
|
|
|
private readonly CodexAccess[] nodes;
|
2023-06-28 09:48:05 +00:00
|
|
|
|
private readonly Configuration config;
|
|
|
|
|
private readonly ITimeSet timeSet;
|
|
|
|
|
private readonly BaseLog log;
|
|
|
|
|
private readonly string customNamespace;
|
|
|
|
|
private readonly int ethereumAccountIndex;
|
|
|
|
|
|
2023-06-29 14:07:49 +00:00
|
|
|
|
public NodeRunner(CodexAccess[] nodes, Configuration config, ITimeSet timeSet, BaseLog log, string customNamespace, int ethereumAccountIndex)
|
2023-06-28 09:48:05 +00:00
|
|
|
|
{
|
2023-06-28 10:01:20 +00:00
|
|
|
|
this.nodes = nodes;
|
2023-06-28 09:48:05 +00:00
|
|
|
|
this.config = config;
|
|
|
|
|
this.timeSet = timeSet;
|
|
|
|
|
this.log = log;
|
|
|
|
|
this.customNamespace = customNamespace;
|
|
|
|
|
this.ethereumAccountIndex = ethereumAccountIndex;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-30 06:39:18 +00:00
|
|
|
|
public void RunNode(Action<CodexAccess, MarketplaceAccess, TestLifecycle> operation)
|
2023-06-28 09:48:05 +00:00
|
|
|
|
{
|
2023-06-28 10:01:20 +00:00
|
|
|
|
RunNode(nodes.ToList().PickOneRandom(), operation, 0.TestTokens());
|
2023-06-28 09:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-30 06:39:18 +00:00
|
|
|
|
public void RunNode(CodexAccess bootstrapNode, Action<CodexAccess, MarketplaceAccess, TestLifecycle> operation)
|
2023-06-28 10:01:20 +00:00
|
|
|
|
{
|
|
|
|
|
RunNode(bootstrapNode, operation, 0.TestTokens());
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-18 08:31:20 +00:00
|
|
|
|
public IDownloadedLog DownloadLog(RunningContainer container, int? tailLines = null)
|
|
|
|
|
{
|
|
|
|
|
var subFile = log.CreateSubfile();
|
|
|
|
|
var description = container.Name;
|
|
|
|
|
var handler = new LogDownloadHandler(container, description, subFile);
|
|
|
|
|
|
|
|
|
|
log.Log($"Downloading logs for {description} to file '{subFile.FullFilename}'");
|
|
|
|
|
|
|
|
|
|
var lifecycle = CreateTestLifecycle();
|
|
|
|
|
var flow = lifecycle.WorkflowCreator.CreateWorkflow();
|
|
|
|
|
flow.DownloadContainerLog(container, handler, tailLines);
|
|
|
|
|
|
|
|
|
|
return new DownloadedLog(subFile, description);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-30 06:39:18 +00:00
|
|
|
|
public void RunNode(CodexAccess bootstrapNode, Action<CodexAccess, MarketplaceAccess, TestLifecycle> operation, TestToken mintTestTokens)
|
2023-06-28 09:48:05 +00:00
|
|
|
|
{
|
2023-08-10 08:58:18 +00:00
|
|
|
|
var lifecycle = CreateTestLifecycle();
|
|
|
|
|
var flow = lifecycle.WorkflowCreator.CreateWorkflow();
|
2023-06-28 09:48:05 +00:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var debugInfo = bootstrapNode.GetDebugInfo();
|
|
|
|
|
Assert.That(!string.IsNullOrEmpty(debugInfo.spr));
|
|
|
|
|
|
|
|
|
|
var startupConfig = new StartupConfig();
|
2023-06-30 06:39:18 +00:00
|
|
|
|
startupConfig.NameOverride = "TransientNode";
|
2023-06-28 09:48:05 +00:00
|
|
|
|
var codexStartConfig = new CodexStartupConfig(CodexLogLevel.Trace);
|
|
|
|
|
codexStartConfig.MarketplaceConfig = new MarketplaceInitialConfig(0.Eth(), 0.TestTokens(), false);
|
|
|
|
|
codexStartConfig.MarketplaceConfig.AccountIndexOverride = ethereumAccountIndex;
|
|
|
|
|
codexStartConfig.BootstrapSpr = debugInfo.spr;
|
|
|
|
|
startupConfig.Add(codexStartConfig);
|
|
|
|
|
startupConfig.Add(config.CodexDeployment.GethStartResult);
|
|
|
|
|
var rc = flow.Start(1, Location.Unspecified, new CodexContainerRecipe(), startupConfig);
|
|
|
|
|
|
|
|
|
|
var account = config.CodexDeployment.GethStartResult.CompanionNode.Accounts[ethereumAccountIndex];
|
|
|
|
|
|
|
|
|
|
var marketplaceNetwork = config.CodexDeployment.GethStartResult.MarketplaceNetwork;
|
|
|
|
|
if (mintTestTokens.Amount > 0)
|
|
|
|
|
{
|
|
|
|
|
var tokenAddress = marketplaceNetwork.Marketplace.TokenAddress;
|
|
|
|
|
var interaction = marketplaceNetwork.Bootstrap.StartInteraction(lifecycle);
|
|
|
|
|
interaction.MintTestTokens(new[] { account.Account }, mintTestTokens.Amount, tokenAddress);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var container = rc.Containers[0];
|
2023-06-29 14:07:49 +00:00
|
|
|
|
var address = lifecycle.Configuration.GetAddress(container);
|
|
|
|
|
var codexAccess = new CodexAccess(log, container, lifecycle.TimeSet, address);
|
2023-06-28 09:48:05 +00:00
|
|
|
|
var marketAccess = new MarketplaceAccess(lifecycle, marketplaceNetwork, account, codexAccess);
|
|
|
|
|
|
2023-06-29 14:03:45 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
2023-06-30 06:39:18 +00:00
|
|
|
|
operation(codexAccess, marketAccess, lifecycle);
|
2023-06-29 14:03:45 +00:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
lifecycle.DownloadLog(container);
|
|
|
|
|
throw;
|
|
|
|
|
}
|
2023-06-28 09:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
2023-09-12 08:31:55 +00:00
|
|
|
|
flow.DeleteNamespacesStartingWith();
|
2023-06-28 09:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-10 08:58:18 +00:00
|
|
|
|
private TestLifecycle CreateTestLifecycle()
|
2023-06-28 09:48:05 +00:00
|
|
|
|
{
|
2023-08-11 06:39:51 +00:00
|
|
|
|
return k8SFactory.CreateTestLifecycle(config.KubeConfigFile, config.LogPath, config.DataPath, customNamespace, timeSet, log);
|
2023-06-28 09:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|