diff --git a/DistTestCore/Codex/CodexContainerRecipe.cs b/DistTestCore/Codex/CodexContainerRecipe.cs index 50d6441..ab3dbee 100644 --- a/DistTestCore/Codex/CodexContainerRecipe.cs +++ b/DistTestCore/Codex/CodexContainerRecipe.cs @@ -41,13 +41,12 @@ namespace DistTestCore.Codex var companionNode = gethConfig.CompanionNodes[Index]; Additional(companionNode); - // Bootstrap node access from within the cluster: - //var ip = gethConfig.BootstrapNode.RunningContainers.RunningPod.Ip; - //var port = gethConfig.BootstrapNode.RunningContainers.Containers[0].Recipe.GetPortByTag(GethContainerRecipe.HttpPortTag); + var ip = companionNode.RunningContainer.Pod.Ip; + var port = companionNode.RunningContainer.Recipe.GetPortByTag(GethContainerRecipe.WsPortTag).Number; - //AddEnvVar("ETH_PROVIDER", "todo"); - //AddEnvVar("ETH_ACCOUNT", companionNode.Account); - //AddEnvVar("ETH_DEPLOYMENT", "todo"); + AddEnvVar("ETH_PROVIDER", $"ws://{ip}:{port}"); + AddEnvVar("ETH_ACCOUNT", companionNode.Account); + AddEnvVar("ETH_MARKETPLACE_ADDRESS", gethConfig.MarketplaceNetwork.Marketplace.Address); } } } diff --git a/DistTestCore/CodexStarter.cs b/DistTestCore/CodexStarter.cs index 9dead26..54342c7 100644 --- a/DistTestCore/CodexStarter.cs +++ b/DistTestCore/CodexStarter.cs @@ -3,22 +3,18 @@ using KubernetesWorkflow; namespace DistTestCore { - public class CodexStarter // basestarter + public class CodexStarter : BaseStarter { - private readonly TestLifecycle lifecycle; - private readonly WorkflowCreator workflowCreator; - public CodexStarter(TestLifecycle lifecycle, WorkflowCreator workflowCreator) + : base(lifecycle, workflowCreator) { - this.lifecycle = lifecycle; - this.workflowCreator = workflowCreator; } public List RunningGroups { get; } = new List(); public ICodexNodeGroup BringOnline(CodexSetup codexSetup) { - Log($"Starting {codexSetup.Describe()}..."); + LogStart($"Starting {codexSetup.Describe()}..."); var gethStartResult = lifecycle.GethStarter.BringOnlineMarketplaceFor(codexSetup); var startupConfig = new StartupConfig(); @@ -32,17 +28,17 @@ namespace DistTestCore var codexNodeFactory = new CodexNodeFactory(lifecycle, metricAccessFactory, gethStartResult.MarketplaceAccessFactory); var group = CreateCodexGroup(codexSetup, containers, codexNodeFactory); - Log($"Started at '{group.Containers.RunningPod.Ip}'"); + LogEnd($"Started at '{group.Containers.RunningPod.Ip}'"); return group; } public void BringOffline(CodexNodeGroup group) { - Log($"Stopping {group.Describe()}..."); + LogStart($"Stopping {group.Describe()}..."); var workflow = CreateWorkflow(); workflow.Stop(group.Containers); RunningGroups.Remove(group); - Log("Stopped."); + LogEnd("Stopped."); } public void DeleteAllResources() @@ -76,10 +72,5 @@ namespace DistTestCore { return workflowCreator.CreateWorkflow(); } - - private void Log(string msg) - { - lifecycle.Log.Log(msg); - } } } diff --git a/DistTestCore/GethStarter.cs b/DistTestCore/GethStarter.cs index 0618078..50a2d86 100644 --- a/DistTestCore/GethStarter.cs +++ b/DistTestCore/GethStarter.cs @@ -3,19 +3,18 @@ using KubernetesWorkflow; namespace DistTestCore { - public class GethStarter // basestarter + public class GethStarter : BaseStarter { private readonly MarketplaceNetworkCache marketplaceNetworkCache; private readonly GethCompanionNodeStarter companionNodeStarter; - private readonly TestLifecycle lifecycle; public GethStarter(TestLifecycle lifecycle, WorkflowCreator workflowCreator) + : base(lifecycle, workflowCreator) { marketplaceNetworkCache = new MarketplaceNetworkCache( new GethBootstrapNodeStarter(lifecycle, workflowCreator), new CodexContractsStarter(lifecycle, workflowCreator)); companionNodeStarter = new GethCompanionNodeStarter(lifecycle, workflowCreator); - this.lifecycle = lifecycle; } public GethStartResult BringOnlineMarketplaceFor(CodexSetup codexSetup) @@ -33,12 +32,11 @@ namespace DistTestCore private void TransferInitialBalance(MarketplaceNetwork marketplaceNetwork, MarketplaceInitialConfig marketplaceConfig, GethCompanionNodeInfo[] companionNodes) { var interaction = marketplaceNetwork.StartInteraction(lifecycle.Log); + var tokenAddress = interaction.GetTokenAddress(marketplaceNetwork.Marketplace.Address); + foreach (var node in companionNodes) { interaction.TransferTo(node.Account, marketplaceConfig.InitialEth.Wei); - - var tokenAddress = interaction.GetTokenAddress(marketplaceNetwork.Marketplace.Address); - interaction.MintTestTokens(node.Account, marketplaceConfig.InitialTestTokens.Amount, tokenAddress); } } diff --git a/DistTestCore/Marketplace/GethCompanionNodeStarter.cs b/DistTestCore/Marketplace/GethCompanionNodeStarter.cs index 20844d2..7e20c4b 100644 --- a/DistTestCore/Marketplace/GethCompanionNodeStarter.cs +++ b/DistTestCore/Marketplace/GethCompanionNodeStarter.cs @@ -2,20 +2,16 @@ namespace DistTestCore.Marketplace { - public class GethCompanionNodeStarter + public class GethCompanionNodeStarter : BaseStarter { - private readonly TestLifecycle lifecycle; - private readonly WorkflowCreator workflowCreator; - public GethCompanionNodeStarter(TestLifecycle lifecycle, WorkflowCreator workflowCreator) + : base(lifecycle, workflowCreator) { - this.lifecycle = lifecycle; - this.workflowCreator = workflowCreator; } public GethCompanionNodeInfo[] StartCompanionNodesFor(CodexSetup codexSetup, GethBootstrapNodeInfo bootstrapNode) { - Log($"Initializing companions for {codexSetup.NumberOfNodes} Codex nodes."); + LogStart($"Initializing companions for {codexSetup.NumberOfNodes} Codex nodes."); var startupConfig = CreateCompanionNodeStartupConfig(bootstrapNode); @@ -23,7 +19,7 @@ namespace DistTestCore.Marketplace 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."); - Log("Initialized companion nodes."); + LogEnd("Initialized companion nodes."); return containers.Containers.Select(c => CreateCompanionInfo(workflow, c)).ToArray(); } @@ -41,10 +37,5 @@ namespace DistTestCore.Marketplace config.Add(new GethStartupConfig(false, bootstrapNode.GenesisJsonBase64, bootstrapNode)); return config; } - - private void Log(string msg) - { - lifecycle.Log.Log(msg); - } } } diff --git a/DistTestCore/Marketplace/GethContainerRecipe.cs b/DistTestCore/Marketplace/GethContainerRecipe.cs index 959daf8..6706901 100644 --- a/DistTestCore/Marketplace/GethContainerRecipe.cs +++ b/DistTestCore/Marketplace/GethContainerRecipe.cs @@ -6,6 +6,7 @@ namespace DistTestCore.Marketplace { public const string DockerImage = "thatbenbierens/geth-confenv:latest"; public const string HttpPortTag = "http_port"; + public const string WsPortTag = "ws_port"; public const string DiscoveryPortTag = "disc_port"; public const string AccountFilename = "account_string.txt"; public const string GenesisFilename = "genesis.json"; @@ -37,14 +38,14 @@ namespace DistTestCore.Marketplace var port = AddInternalPort(); var authRpc = AddInternalPort(); var httpPort = AddInternalPort(tag: HttpPortTag); + var wsPort = AddInternalPort(tag: WsPortTag); var bootPubKey = config.BootstrapNode.PubKey; var bootIp = config.BootstrapNode.RunningContainers.Containers[0].Pod.Ip; var bootPort = config.BootstrapNode.DiscoveryPort.Number; var bootstrapArg = $"--bootnodes enode://{bootPubKey}@{bootIp}:{bootPort}"; - // geth --bootnodes enode://pubkey1@ip1:port1 - return $"--port {port.Number} --discovery.port {discovery.Number} --authrpc.port {authRpc.Number} --http.port {httpPort.Number} --nodiscover {bootstrapArg}"; + return $"--port {port.Number} --discovery.port {discovery.Number} --authrpc.port {authRpc.Number} --http.port {httpPort.Number} --ws --ws.port {wsPort.Number} --nodiscover {bootstrapArg}"; } } } diff --git a/DistTestCore/PrometheusStarter.cs b/DistTestCore/PrometheusStarter.cs index bd375b8..936c876 100644 --- a/DistTestCore/PrometheusStarter.cs +++ b/DistTestCore/PrometheusStarter.cs @@ -5,22 +5,18 @@ using System.Text; namespace DistTestCore { - public class PrometheusStarter // basestarter + public class PrometheusStarter : BaseStarter { - private readonly TestLifecycle lifecycle; - private readonly WorkflowCreator workflowCreator; - public PrometheusStarter(TestLifecycle lifecycle, WorkflowCreator workflowCreator) + : base(lifecycle, workflowCreator) { - this.lifecycle = lifecycle; - this.workflowCreator = workflowCreator; } public IMetricsAccessFactory CollectMetricsFor(CodexSetup codexSetup, RunningContainers containers) { if (!codexSetup.MetricsEnabled) return new MetricsUnavailableAccessFactory(); - Log($"Starting metrics server for {containers.Describe()}"); + LogStart($"Starting metrics server for {containers.Describe()}"); var startupConfig = new StartupConfig(); startupConfig.Add(new PrometheusStartupConfig(GeneratePrometheusConfig(containers.Containers))); @@ -28,7 +24,7 @@ namespace DistTestCore var runningContainers = workflow.Start(1, Location.Unspecified, new PrometheusContainerRecipe(), startupConfig); if (runningContainers.Containers.Length != 1) throw new InvalidOperationException("Expected only 1 Prometheus container to be created."); - Log("Metrics server started."); + LogEnd("Metrics server started."); return new CodexNodeMetricsAccessFactory(runningContainers); } @@ -56,10 +52,5 @@ namespace DistTestCore var bytes = Encoding.ASCII.GetBytes(config); return Convert.ToBase64String(bytes); } - - private void Log(string msg) - { - lifecycle.Log.Log(msg); - } } }