2023-04-17 14:28:07 +00:00
|
|
|
|
using KubernetesWorkflow;
|
|
|
|
|
using Utils;
|
|
|
|
|
|
|
|
|
|
namespace DistTestCore.Marketplace
|
|
|
|
|
{
|
2023-04-18 11:22:41 +00:00
|
|
|
|
public class CodexContractsStarter : BaseStarter
|
2023-04-17 14:28:07 +00:00
|
|
|
|
{
|
|
|
|
|
private const string readyString = "Done! Sleeping indefinitely...";
|
|
|
|
|
|
|
|
|
|
public CodexContractsStarter(TestLifecycle lifecycle, WorkflowCreator workflowCreator)
|
2023-04-18 11:22:41 +00:00
|
|
|
|
: base(lifecycle, workflowCreator)
|
2023-04-17 14:28:07 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-18 13:33:12 +00:00
|
|
|
|
public MarketplaceInfo Start(GethBootstrapNodeInfo bootstrapNode)
|
2023-04-17 14:28:07 +00:00
|
|
|
|
{
|
2023-04-18 11:22:41 +00:00
|
|
|
|
LogStart("Deploying Codex contracts...");
|
|
|
|
|
|
2023-04-17 14:28:07 +00:00
|
|
|
|
var workflow = workflowCreator.CreateWorkflow();
|
2023-04-18 13:33:12 +00:00
|
|
|
|
var startupConfig = CreateStartupConfig(bootstrapNode.RunningContainers.Containers[0]);
|
2023-04-17 14:28:07 +00:00
|
|
|
|
|
|
|
|
|
var containers = workflow.Start(1, Location.Unspecified, new CodexContractsContainerRecipe(), startupConfig);
|
|
|
|
|
if (containers.Containers.Length != 1) throw new InvalidOperationException("Expected 1 Codex contracts container to be created. Test infra failure.");
|
|
|
|
|
var container = containers.Containers[0];
|
|
|
|
|
|
|
|
|
|
WaitUntil(() =>
|
|
|
|
|
{
|
|
|
|
|
var logHandler = new ContractsReadyLogHandler(readyString);
|
|
|
|
|
workflow.DownloadContainerLog(container, logHandler);
|
|
|
|
|
return logHandler.Found;
|
|
|
|
|
});
|
|
|
|
|
|
2023-04-18 08:22:11 +00:00
|
|
|
|
var extractor = new ContainerInfoExtractor(workflow, container);
|
|
|
|
|
var marketplaceAddress = extractor.ExtractMarketplaceAddress();
|
|
|
|
|
|
2023-04-18 13:33:12 +00:00
|
|
|
|
var interaction = bootstrapNode.StartInteraction(lifecycle.Log);
|
|
|
|
|
var tokenAddress = interaction.GetTokenAddress(marketplaceAddress);
|
|
|
|
|
|
2023-04-18 11:22:41 +00:00
|
|
|
|
LogEnd("Contracts deployed.");
|
2023-04-18 08:22:11 +00:00
|
|
|
|
|
2023-04-18 13:33:12 +00:00
|
|
|
|
return new MarketplaceInfo(marketplaceAddress, tokenAddress);
|
2023-04-17 14:28:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void WaitUntil(Func<bool> predicate)
|
|
|
|
|
{
|
|
|
|
|
Time.WaitUntil(predicate, TimeSpan.FromMinutes(2), TimeSpan.FromSeconds(1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private StartupConfig CreateStartupConfig(RunningContainer bootstrapContainer)
|
|
|
|
|
{
|
|
|
|
|
var startupConfig = new StartupConfig();
|
|
|
|
|
var contractsConfig = new CodexContractsContainerConfig(bootstrapContainer.Pod.Ip, bootstrapContainer.Recipe.GetPortByTag(GethContainerRecipe.HttpPortTag));
|
|
|
|
|
startupConfig.Add(contractsConfig);
|
|
|
|
|
return startupConfig;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-18 08:22:11 +00:00
|
|
|
|
public class MarketplaceInfo
|
|
|
|
|
{
|
2023-04-18 13:33:12 +00:00
|
|
|
|
public MarketplaceInfo(string address, string tokenAddress)
|
2023-04-18 08:22:11 +00:00
|
|
|
|
{
|
|
|
|
|
Address = address;
|
2023-04-18 13:33:12 +00:00
|
|
|
|
TokenAddress = tokenAddress;
|
2023-04-18 08:22:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Address { get; }
|
2023-04-18 13:33:12 +00:00
|
|
|
|
public string TokenAddress { get; }
|
2023-04-18 08:22:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-17 14:28:07 +00:00
|
|
|
|
public class ContractsReadyLogHandler : LogHandler
|
|
|
|
|
{
|
|
|
|
|
private readonly string targetString;
|
|
|
|
|
|
|
|
|
|
public ContractsReadyLogHandler(string targetString)
|
|
|
|
|
{
|
|
|
|
|
this.targetString = targetString;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Found { get; private set; }
|
|
|
|
|
|
|
|
|
|
protected override void ProcessLine(string line)
|
|
|
|
|
{
|
|
|
|
|
if (line.Contains(targetString)) Found = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|