cs-codex-dist-tests/ProjectPlugins/GethPlugin/GethStarter.cs

56 lines
2.1 KiB
C#
Raw Normal View History

2023-09-15 13:52:02 +00:00
using Core;
using KubernetesWorkflow;
namespace GethPlugin
2023-09-15 10:36:35 +00:00
{
public class GethStarter
{
2023-09-15 13:52:02 +00:00
private readonly IPluginTools tools;
public GethStarter(IPluginTools tools)
2023-09-15 10:36:35 +00:00
{
2023-09-15 13:52:02 +00:00
this.tools = tools;
2023-09-15 10:36:35 +00:00
}
2023-09-20 08:13:29 +00:00
public GethDeployment StartGeth(GethStartupConfig gethStartupConfig)
2023-09-15 10:36:35 +00:00
{
2023-09-22 05:43:46 +00:00
Log("Starting Geth node...");
2023-09-15 10:36:35 +00:00
2023-09-15 13:52:02 +00:00
var startupConfig = new StartupConfig();
startupConfig.Add(gethStartupConfig);
startupConfig.NameOverride = gethStartupConfig.NameOverride;
2023-09-15 10:36:35 +00:00
2023-09-15 13:52:02 +00:00
var workflow = tools.CreateWorkflow();
2023-09-25 06:47:19 +00:00
var containers = workflow.Start(1, new GethContainerRecipe(), startupConfig);
2023-09-15 13:52:02 +00:00
if (containers.Containers.Length != 1) throw new InvalidOperationException("Expected 1 Geth bootstrap node to be created. Test infra failure.");
var container = containers.Containers[0];
2023-09-15 10:36:35 +00:00
2023-09-15 14:27:08 +00:00
var extractor = new GethContainerInfoExtractor(tools.GetLog(), workflow, container);
2023-10-23 11:36:20 +00:00
var account = extractor.ExtractAccounts().Accounts.First();
2023-09-15 13:52:02 +00:00
var pubKey = extractor.ExtractPubKey();
2023-09-19 09:51:59 +00:00
2023-09-15 13:52:02 +00:00
var discoveryPort = container.Recipe.GetPortByTag(GethContainerRecipe.DiscoveryPortTag);
if (discoveryPort == null) throw new Exception("Expected discovery port to be created.");
2023-09-15 14:27:08 +00:00
var httpPort = container.Recipe.GetPortByTag(GethContainerRecipe.HttpPortTag);
if (httpPort == null) throw new Exception("Expected http port to be created.");
var wsPort = container.Recipe.GetPortByTag(GethContainerRecipe.WsPortTag);
2023-09-15 14:27:08 +00:00
if (wsPort == null) throw new Exception("Expected ws port to be created.");
2023-09-19 09:51:59 +00:00
Log($"Geth node started.");
2023-09-15 10:36:35 +00:00
2023-11-06 15:10:19 +00:00
return new GethDeployment(containers, discoveryPort, httpPort, wsPort, account, pubKey);
2023-09-19 09:51:59 +00:00
}
2023-09-15 10:36:35 +00:00
2023-09-20 08:13:29 +00:00
public IGethNode WrapGethContainer(GethDeployment startResult)
2023-09-19 09:51:59 +00:00
{
2023-09-20 08:13:29 +00:00
startResult = SerializeGate.Gate(startResult);
return new GethNode(tools.GetLog(), startResult);
2023-09-15 10:36:35 +00:00
}
2023-09-15 13:52:02 +00:00
private void Log(string msg)
2023-09-15 10:36:35 +00:00
{
2023-09-15 13:52:02 +00:00
tools.GetLog().Log(msg);
2023-09-15 10:36:35 +00:00
}
}
}