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

124 lines
5.3 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-19 09:51:59 +00:00
public IGethStartResult StartGeth(GethStartupConfig gethStartupConfig)
2023-09-15 10:36:35 +00:00
{
2023-09-15 13:52:02 +00:00
Log("Starting Geth bootstrap 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();
var containers = workflow.Start(1, Location.Unspecified, new GethContainerRecipe(), startupConfig);
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-09-15 13:52:02 +00:00
var accounts = extractor.ExtractAccounts();
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);
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-09-19 09:51:59 +00:00
return new GethStartResult(container, discoveryPort, httpPort, wsPort, accounts, pubKey);
}
2023-09-15 10:36:35 +00:00
2023-09-19 09:51:59 +00:00
public IGethNode WrapGethContainer(IGethStartResult 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
}
2023-09-15 13:52:02 +00:00
//public GethStartResult BringOnlineMarketplaceFor(CodexSetup codexSetup)
//{
// if (codexSetup.MarketplaceConfig == null) return CreateMarketplaceUnavailableResult();
2023-09-15 10:36:35 +00:00
2023-09-15 13:52:02 +00:00
// var marketplaceNetwork = marketplaceNetworkCache.Get();
// var companionNode = StartCompanionNode(codexSetup, marketplaceNetwork);
2023-09-15 10:36:35 +00:00
2023-09-15 13:52:02 +00:00
// LogStart("Setting up initial balance...");
// TransferInitialBalance(marketplaceNetwork, codexSetup.MarketplaceConfig, companionNode);
// LogEnd($"Initial balance of {codexSetup.MarketplaceConfig.InitialTestTokens} set for {codexSetup.NumberOfNodes} nodes.");
2023-09-15 10:36:35 +00:00
2023-09-15 13:52:02 +00:00
// return CreateGethStartResult(marketplaceNetwork, companionNode);
//}
2023-09-15 10:36:35 +00:00
2023-09-15 13:52:02 +00:00
//private void TransferInitialBalance(MarketplaceNetwork marketplaceNetwork, MarketplaceInitialConfig marketplaceConfig, GethCompanionNodeInfo companionNode)
//{
// if (marketplaceConfig.InitialTestTokens.Amount == 0) return;
2023-09-15 10:36:35 +00:00
2023-09-15 13:52:02 +00:00
// var interaction = marketplaceNetwork.StartInteraction(lifecycle);
// var tokenAddress = marketplaceNetwork.Marketplace.TokenAddress;
// var accounts = companionNode.Accounts.Select(a => a.Account).ToArray();
// interaction.MintTestTokens(accounts, marketplaceConfig.InitialTestTokens.Amount, tokenAddress);
//}
//private GethStartResult CreateGethStartResult(MarketplaceNetwork marketplaceNetwork, GethCompanionNodeInfo companionNode)
//{
// return new GethStartResult(CreateMarketplaceAccessFactory(marketplaceNetwork), marketplaceNetwork, companionNode);
//}
//private GethStartResult CreateMarketplaceUnavailableResult()
//{
// return new GethStartResult(new MarketplaceUnavailableAccessFactory(), null!, null!);
//}
//private IMarketplaceAccessFactory CreateMarketplaceAccessFactory(MarketplaceNetwork marketplaceNetwork)
//{
// return new GethMarketplaceAccessFactory(lifecycle, marketplaceNetwork);
//}
//private GethCompanionNodeInfo StartCompanionNode(CodexSetup codexSetup, MarketplaceNetwork marketplaceNetwork)
//{
// return companionNodeStarter.StartCompanionNodeFor(codexSetup, marketplaceNetwork);
//}
2023-09-15 10:36:35 +00:00
}
2023-09-15 13:52:02 +00:00
//public class MarketplaceNetworkCache
//{
// private readonly GethBootstrapNodeStarter bootstrapNodeStarter;
// private readonly CodexContractsStarter codexContractsStarter;
// private MarketplaceNetwork? network;
// public MarketplaceNetworkCache(GethBootstrapNodeStarter bootstrapNodeStarter, CodexContractsStarter codexContractsStarter)
// {
// this.bootstrapNodeStarter = bootstrapNodeStarter;
// this.codexContractsStarter = codexContractsStarter;
// }
// public MarketplaceNetwork Get()
// {
// if (network == null)
// {
// var bootstrapInfo = bootstrapNodeStarter.StartGethBootstrapNode();
// var marketplaceInfo = codexContractsStarter.Start(bootstrapInfo);
// network = new MarketplaceNetwork(bootstrapInfo, marketplaceInfo);
// }
// return network;
// }
//}
2023-09-15 10:36:35 +00:00
}