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
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
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-06-01 12:18:09 +00:00
|
|
|
|
LogStart("Deploying Codex Marketplace...");
|
2023-04-18 11:22:41 +00:00
|
|
|
|
|
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(() =>
|
|
|
|
|
{
|
2023-06-01 13:20:21 +00:00
|
|
|
|
var logHandler = new ContractsReadyLogHandler(Debug);
|
2023-04-17 14:28:07 +00:00
|
|
|
|
workflow.DownloadContainerLog(container, logHandler);
|
|
|
|
|
return logHandler.Found;
|
|
|
|
|
});
|
2023-06-01 12:18:09 +00:00
|
|
|
|
Log("Contracts deployed. Extracting addresses...");
|
2023-04-17 14:28:07 +00:00
|
|
|
|
|
2023-04-25 11:38:26 +00:00
|
|
|
|
var extractor = new ContainerInfoExtractor(lifecycle.Log, workflow, container);
|
2023-04-18 08:22:11 +00:00
|
|
|
|
var marketplaceAddress = extractor.ExtractMarketplaceAddress();
|
2023-04-24 12:09:23 +00:00
|
|
|
|
var abi = extractor.ExtractMarketplaceAbi();
|
2023-04-18 08:22:11 +00:00
|
|
|
|
|
2023-06-01 07:35:18 +00:00
|
|
|
|
var interaction = bootstrapNode.StartInteraction(lifecycle);
|
2023-04-18 13:33:12 +00:00
|
|
|
|
var tokenAddress = interaction.GetTokenAddress(marketplaceAddress);
|
|
|
|
|
|
2023-06-01 12:18:09 +00:00
|
|
|
|
LogEnd("Extract completed. Marketplace deployed.");
|
2023-04-18 08:22:11 +00:00
|
|
|
|
|
2023-04-24 12:09:23 +00:00
|
|
|
|
return new MarketplaceInfo(marketplaceAddress, abi, tokenAddress);
|
2023-04-17 14:28:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void WaitUntil(Func<bool> predicate)
|
|
|
|
|
{
|
2023-06-01 12:18:09 +00:00
|
|
|
|
Time.WaitUntil(predicate, TimeSpan.FromMinutes(3), TimeSpan.FromSeconds(2));
|
2023-04-17 14:28:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private StartupConfig CreateStartupConfig(RunningContainer bootstrapContainer)
|
|
|
|
|
{
|
|
|
|
|
var startupConfig = new StartupConfig();
|
2023-06-02 08:04:07 +00:00
|
|
|
|
var contractsConfig = new CodexContractsContainerConfig(bootstrapContainer.Pod.PodInfo.Ip, bootstrapContainer.Recipe.GetPortByTag(GethContainerRecipe.HttpPortTag));
|
2023-04-17 14:28:07 +00:00
|
|
|
|
startupConfig.Add(contractsConfig);
|
|
|
|
|
return startupConfig;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-18 08:22:11 +00:00
|
|
|
|
public class MarketplaceInfo
|
|
|
|
|
{
|
2023-04-24 12:09:23 +00:00
|
|
|
|
public MarketplaceInfo(string address, string abi, string tokenAddress)
|
2023-04-18 08:22:11 +00:00
|
|
|
|
{
|
|
|
|
|
Address = address;
|
2023-04-24 12:09:23 +00:00
|
|
|
|
Abi = abi;
|
2023-04-18 13:33:12 +00:00
|
|
|
|
TokenAddress = tokenAddress;
|
2023-04-18 08:22:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Address { get; }
|
2023-04-24 12:09:23 +00:00
|
|
|
|
public string Abi { 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
|
|
|
|
|
{
|
2023-06-01 13:04:04 +00:00
|
|
|
|
// Log should contain 'Compiled 15 Solidity files successfully' at some point.
|
|
|
|
|
private const string RequiredCompiledString = "Solidity files successfully";
|
|
|
|
|
// When script is done, it prints the ready-string.
|
|
|
|
|
private const string ReadyString = "Done! Sleeping indefinitely...";
|
2023-06-01 13:20:21 +00:00
|
|
|
|
private readonly Action<string> debug;
|
|
|
|
|
|
|
|
|
|
public ContractsReadyLogHandler(Action<string> debug)
|
|
|
|
|
{
|
|
|
|
|
this.debug = debug;
|
|
|
|
|
debug($"Looking for '{RequiredCompiledString}' and '{ReadyString}' in container logs...");
|
|
|
|
|
}
|
2023-04-17 14:28:07 +00:00
|
|
|
|
|
2023-06-01 13:04:04 +00:00
|
|
|
|
public bool SeenCompileString { get; private set; }
|
2023-04-17 14:28:07 +00:00
|
|
|
|
public bool Found { get; private set; }
|
|
|
|
|
|
|
|
|
|
protected override void ProcessLine(string line)
|
|
|
|
|
{
|
2023-06-01 13:20:21 +00:00
|
|
|
|
debug(line);
|
2023-06-01 13:04:04 +00:00
|
|
|
|
if (line.Contains(RequiredCompiledString)) SeenCompileString = true;
|
|
|
|
|
|
|
|
|
|
if (SeenCompileString && line.Contains(ReadyString)) Found = true;
|
2023-04-17 14:28:07 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|