2023-04-10 12:00:12 +00:00
|
|
|
|
using NUnit.Framework;
|
2023-04-10 12:48:16 +00:00
|
|
|
|
using System.Text;
|
2023-04-10 12:00:12 +00:00
|
|
|
|
|
|
|
|
|
namespace CodexDistTestCore.Marketplace
|
2023-04-10 08:09:41 +00:00
|
|
|
|
{
|
|
|
|
|
public class MarketplaceController
|
|
|
|
|
{
|
|
|
|
|
private readonly TestLog log;
|
|
|
|
|
private readonly K8sManager k8sManager;
|
2023-04-10 12:48:16 +00:00
|
|
|
|
private GethInfo? gethBootstrapNode;
|
2023-04-10 08:09:41 +00:00
|
|
|
|
private string bootstrapAccount = string.Empty;
|
|
|
|
|
private string bootstrapGenesisJson = string.Empty;
|
|
|
|
|
|
|
|
|
|
public MarketplaceController(TestLog log, K8sManager k8sManager)
|
|
|
|
|
{
|
|
|
|
|
this.log = log;
|
|
|
|
|
this.k8sManager = k8sManager;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-10 12:48:16 +00:00
|
|
|
|
public GethInfo BringOnlineMarketplace()
|
2023-04-10 08:09:41 +00:00
|
|
|
|
{
|
2023-04-10 12:48:16 +00:00
|
|
|
|
if (gethBootstrapNode != null) return gethBootstrapNode;
|
2023-04-10 08:09:41 +00:00
|
|
|
|
|
|
|
|
|
log.Log("Starting Geth bootstrap node...");
|
|
|
|
|
gethBootstrapNode = k8sManager.BringOnlineGethBootstrapNode();
|
|
|
|
|
ExtractAccountAndGenesisJson();
|
|
|
|
|
log.Log("Geth boothstrap node started.");
|
2023-04-10 12:48:16 +00:00
|
|
|
|
|
|
|
|
|
return gethBootstrapNode;
|
2023-04-10 08:09:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ExtractAccountAndGenesisJson()
|
|
|
|
|
{
|
2023-04-10 13:21:45 +00:00
|
|
|
|
FetchAccountAndGenesisJson();
|
|
|
|
|
if (string.IsNullOrEmpty(bootstrapAccount) || string.IsNullOrEmpty(bootstrapGenesisJson))
|
|
|
|
|
{
|
|
|
|
|
Thread.Sleep(TimeSpan.FromSeconds(15));
|
|
|
|
|
FetchAccountAndGenesisJson();
|
|
|
|
|
}
|
2023-04-10 12:00:12 +00:00
|
|
|
|
|
|
|
|
|
Assert.That(bootstrapAccount, Is.Not.Empty, "Unable to fetch account for bootstrap geth node. Test infra failure.");
|
|
|
|
|
Assert.That(bootstrapGenesisJson, Is.Not.Empty, "Unable to fetch genesis-json for bootstrap geth node. Test infra failure.");
|
2023-04-10 12:48:16 +00:00
|
|
|
|
|
|
|
|
|
gethBootstrapNode!.GenesisJsonBase64 = Convert.ToBase64String(Encoding.ASCII.GetBytes(bootstrapGenesisJson));
|
2023-04-10 08:09:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-10 13:21:45 +00:00
|
|
|
|
private void FetchAccountAndGenesisJson()
|
|
|
|
|
{
|
|
|
|
|
bootstrapAccount = ExecuteCommand("cat", "account_string.txt");
|
|
|
|
|
bootstrapGenesisJson = ExecuteCommand("cat", "genesis.json");
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-10 08:09:41 +00:00
|
|
|
|
private string ExecuteCommand(string command, params string[] arguments)
|
|
|
|
|
{
|
2023-04-10 12:48:16 +00:00
|
|
|
|
return k8sManager.ExecuteCommand(gethBootstrapNode!.Pod, K8sGethBoostrapSpecs.ContainerName, command, arguments);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class GethInfo
|
|
|
|
|
{
|
|
|
|
|
public GethInfo(K8sGethBoostrapSpecs spec, PodInfo pod)
|
|
|
|
|
{
|
|
|
|
|
Spec = spec;
|
|
|
|
|
Pod = pod;
|
2023-04-10 08:09:41 +00:00
|
|
|
|
}
|
2023-04-10 12:48:16 +00:00
|
|
|
|
|
|
|
|
|
public K8sGethBoostrapSpecs Spec { get; }
|
|
|
|
|
public PodInfo Pod { get; }
|
|
|
|
|
public string GenesisJsonBase64 { get; set; } = string.Empty;
|
2023-04-10 08:09:41 +00:00
|
|
|
|
}
|
|
|
|
|
}
|