cs-codex-dist-tests/DistTestCore/Marketplace/GethCompanionNodeStarter.cs

56 lines
2.3 KiB
C#
Raw Normal View History

2023-04-14 07:54:07 +00:00
using KubernetesWorkflow;
namespace DistTestCore.Marketplace
{
2023-04-18 11:45:48 +00:00
public class GethCompanionNodeStarter : BaseStarter
2023-04-14 07:54:07 +00:00
{
public GethCompanionNodeStarter(TestLifecycle lifecycle, WorkflowCreator workflowCreator)
2023-04-18 11:45:48 +00:00
: base(lifecycle, workflowCreator)
2023-04-14 07:54:07 +00:00
{
}
public GethCompanionNodeInfo[] StartCompanionNodesFor(CodexSetup codexSetup, MarketplaceNetwork marketplace)
2023-04-14 07:54:07 +00:00
{
2023-04-18 11:45:48 +00:00
LogStart($"Initializing companions for {codexSetup.NumberOfNodes} Codex nodes.");
2023-04-14 07:54:07 +00:00
var startupConfig = CreateCompanionNodeStartupConfig(marketplace.Bootstrap);
2023-04-14 07:54:07 +00:00
var workflow = workflowCreator.CreateWorkflow();
var containers = workflow.Start(codexSetup.NumberOfNodes, Location.Unspecified, new GethContainerRecipe(), startupConfig);
if (containers.Containers.Length != codexSetup.NumberOfNodes) throw new InvalidOperationException("Expected a Geth companion node to be created for each Codex node. Test infra failure.");
var result = containers.Containers.Select(c => CreateCompanionInfo(workflow, c)).ToArray();
2023-04-14 07:54:07 +00:00
foreach (var node in result)
{
EnsureCompanionNodeIsSynced(node, marketplace);
}
LogEnd($"Initialized {codexSetup.NumberOfNodes} companion nodes. Their accounts: [{string.Join(",", result.Select(c => c.Account))}]");
return result;
2023-04-14 07:54:07 +00:00
}
private GethCompanionNodeInfo CreateCompanionInfo(StartupWorkflow workflow, RunningContainer container)
{
var extractor = new ContainerInfoExtractor(workflow, container);
2023-04-14 07:54:07 +00:00
var account = extractor.ExtractAccount();
var privKey = extractor.ExtractPrivateKey();
return new GethCompanionNodeInfo(container, account, privKey);
}
private void EnsureCompanionNodeIsSynced(GethCompanionNodeInfo node, MarketplaceNetwork marketplace)
{
var interaction = node.StartInteraction(lifecycle.Log);
interaction.EnsureSynced(marketplace.Marketplace.Address, marketplace.Marketplace.Abi);
2023-04-14 07:54:07 +00:00
}
private StartupConfig CreateCompanionNodeStartupConfig(GethBootstrapNodeInfo bootstrapNode)
{
var config = new StartupConfig();
2023-04-19 05:59:28 +00:00
config.Add(new GethStartupConfig(false, bootstrapNode));
2023-04-14 07:54:07 +00:00
return config;
}
}
}