From 760d0211c6b05b182f3b4c5f25de36b716247f05 Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 21 Mar 2024 08:31:00 +0100 Subject: [PATCH] wip: setting up access to geth and contracts for transient nodes --- ProjectPlugins/CodexPlugin/CodexDeployment.cs | 4 +- Tests/CodexContinuousTests/ContinuousTest.cs | 29 ++++- .../ContinuousTestRunner.cs | 17 --- .../CodexContinuousTests/EntryPointFactory.cs | 1 - Tests/CodexContinuousTests/NodeRunner.cs | 42 +++---- .../Tests/MarketplaceTest.cs | 110 +++++++++--------- 6 files changed, 101 insertions(+), 102 deletions(-) diff --git a/ProjectPlugins/CodexPlugin/CodexDeployment.cs b/ProjectPlugins/CodexPlugin/CodexDeployment.cs index ccf5ef2..8c16321 100644 --- a/ProjectPlugins/CodexPlugin/CodexDeployment.cs +++ b/ProjectPlugins/CodexPlugin/CodexDeployment.cs @@ -9,7 +9,7 @@ namespace CodexPlugin public CodexDeployment(CodexInstance[] codexInstances, GethDeployment gethDeployment, CodexContractsDeployment codexContractsDeployment, RunningContainers? prometheusContainer, RunningContainers? discordBotContainer, DeploymentMetadata metadata, - String id) + string id) { Id = id; CodexInstances = codexInstances; @@ -20,7 +20,7 @@ namespace CodexPlugin Metadata = metadata; } - public String Id { get; } + public string Id { get; } public CodexInstance[] CodexInstances { get; } public GethDeployment GethDeployment { get; } public CodexContractsDeployment CodexContractsDeployment { get; } diff --git a/Tests/CodexContinuousTests/ContinuousTest.cs b/Tests/CodexContinuousTests/ContinuousTest.cs index c8cb168..7b71b89 100644 --- a/Tests/CodexContinuousTests/ContinuousTest.cs +++ b/Tests/CodexContinuousTests/ContinuousTest.cs @@ -1,6 +1,8 @@ -using CodexPlugin; +using CodexContractsPlugin; +using CodexPlugin; using Core; using FileUtils; +using GethPlugin; using Logging; using MetricsPlugin; @@ -31,7 +33,7 @@ namespace ContinuousTests if (nodes != null) { - NodeRunner = new NodeRunner(Nodes, configuration, Log, CustomK8sNamespace); + NodeRunner = new NodeRunner(Nodes, configuration, Log); } else { @@ -56,15 +58,23 @@ namespace ContinuousTests { if (Configuration.CodexDeployment.PrometheusContainer == null) throw new Exception("Expected prometheus to be part of Codex deployment."); - var entryPointFactory = new EntryPointFactory(); - var entryPoint = entryPointFactory.CreateEntryPoint(Configuration.KubeConfigFile, Configuration.DataPath, Configuration.CodexDeployment.Metadata.KubeNamespace, Log); - return entryPoint.CreateInterface().WrapMetricsCollector(Configuration.CodexDeployment.PrometheusContainer, target); + var ci = CreateCi(); + return ci.WrapMetricsCollector(Configuration.CodexDeployment.PrometheusContainer, target); + } + + public (IGethNode, ICodexContracts) CreateMarketplaceAccess() + { + var ci = CreateCi(); + + var geth = ci.WrapGethDeployment(Configuration.CodexDeployment.GethDeployment); + var contracts = ci.WrapCodexContractsDeployment(geth, Configuration.CodexDeployment.CodexContractsDeployment); + + return (geth, contracts); } public abstract int RequiredNumberOfNodes { get; } public abstract TimeSpan RunTestEvery { get; } public abstract TestFailMode TestFailMode { get; } - public virtual string CustomK8sNamespace { get { return string.Empty; } } public string Name { @@ -73,6 +83,13 @@ namespace ContinuousTests return GetType().Name; } } + + private CoreInterface CreateCi() + { + var entryPointFactory = new EntryPointFactory(); + var entryPoint = entryPointFactory.CreateEntryPoint(Configuration.KubeConfigFile, Configuration.DataPath, Configuration.CodexDeployment.Metadata.KubeNamespace, Log); + return entryPoint.CreateInterface(); + } } public enum TestFailMode diff --git a/Tests/CodexContinuousTests/ContinuousTestRunner.cs b/Tests/CodexContinuousTests/ContinuousTestRunner.cs index b860c86..c2790a6 100644 --- a/Tests/CodexContinuousTests/ContinuousTestRunner.cs +++ b/Tests/CodexContinuousTests/ContinuousTestRunner.cs @@ -51,8 +51,6 @@ namespace ContinuousTests overviewLog.Log(""); var allTests = testFactory.CreateTests(); - ClearAllCustomNamespaces(allTests, overviewLog); - var filteredTests = FilterTests(allTests, overviewLog); if (!filteredTests.Any()) { @@ -136,21 +134,6 @@ namespace ContinuousTests return result; } - private void ClearAllCustomNamespaces(ContinuousTest[] allTests, ILog log) - { - foreach (var test in allTests) ClearAllCustomNamespaces(test, log); - } - - private void ClearAllCustomNamespaces(ContinuousTest test, ILog log) - { - if (string.IsNullOrEmpty(test.CustomK8sNamespace)) return; - - log.Log($"Clearing namespace '{test.CustomK8sNamespace}'..."); - - var entryPoint = entryPointFactory.CreateEntryPoint(config.KubeConfigFile, config.DataPath, test.CustomK8sNamespace, log); - entryPoint.Tools.CreateWorkflow().DeleteNamespacesStartingWith(test.CustomK8sNamespace); - } - private void PerformCleanup(ILog log) { if (!config.Cleanup) return; diff --git a/Tests/CodexContinuousTests/EntryPointFactory.cs b/Tests/CodexContinuousTests/EntryPointFactory.cs index 9f4388e..e63551d 100644 --- a/Tests/CodexContinuousTests/EntryPointFactory.cs +++ b/Tests/CodexContinuousTests/EntryPointFactory.cs @@ -25,7 +25,6 @@ namespace ContinuousTests ); return new EntryPoint(log, lifecycleConfig, dataFilePath); - //DefaultContainerRecipe.TestsType = "continuous-tests"; } private static string? GetKubeConfig(string kubeConfigFile) diff --git a/Tests/CodexContinuousTests/NodeRunner.cs b/Tests/CodexContinuousTests/NodeRunner.cs index 488e47a..10040d8 100644 --- a/Tests/CodexContinuousTests/NodeRunner.cs +++ b/Tests/CodexContinuousTests/NodeRunner.cs @@ -13,14 +13,12 @@ namespace ContinuousTests private readonly ICodexNode[] nodes; private readonly Configuration config; private readonly ILog log; - private readonly string customNamespace; - public NodeRunner(ICodexNode[] nodes, Configuration config, ILog log, string customNamespace) + public NodeRunner(ICodexNode[] nodes, Configuration config, ILog log) { this.nodes = nodes; this.config = config; this.log = log; - this.customNamespace = customNamespace; } public IDownloadedLog DownloadLog(RunningContainer container, int? tailLines = null) @@ -41,36 +39,34 @@ namespace ContinuousTests // Therefore, we use the image of the bootstrap node. CodexContainerRecipe.DockerImageOverride = bootstrapNode.Container.Recipe.Image; + var debugInfo = bootstrapNode.GetDebugInfo(); + Assert.That(!string.IsNullOrEmpty(debugInfo.spr)); + + var node = entryPoint.CreateInterface().StartCodexNode(s => + { + setup(s); + s.WithBootstrapNode(bootstrapNode); + }); + try { - var debugInfo = bootstrapNode.GetDebugInfo(); - Assert.That(!string.IsNullOrEmpty(debugInfo.spr)); - - var node = entryPoint.CreateInterface().StartCodexNode(s => - { - setup(s); - s.WithBootstrapNode(bootstrapNode); - }); - - try - { - operation(node); - } - catch - { - DownloadLog(node.Container); - throw; - } + operation(node); + } + catch + { + DownloadLog(node.Container); + node.Stop(); + throw; } finally { - entryPoint.Tools.CreateWorkflow().DeleteNamespace(); + node.Stop(); } } private EntryPoint CreateEntryPoint() { - return entryPointFactory.CreateEntryPoint(config.KubeConfigFile, config.DataPath, customNamespace, log); + return entryPointFactory.CreateEntryPoint(config.KubeConfigFile, config.DataPath, config.CodexDeployment.Metadata.KubeNamespace, log); } } } diff --git a/Tests/CodexContinuousTests/Tests/MarketplaceTest.cs b/Tests/CodexContinuousTests/Tests/MarketplaceTest.cs index 09170f7..e846353 100644 --- a/Tests/CodexContinuousTests/Tests/MarketplaceTest.cs +++ b/Tests/CodexContinuousTests/Tests/MarketplaceTest.cs @@ -1,64 +1,68 @@ -//using DistTestCore; -//using DistTestCore.Codex; -//using Newtonsoft.Json; -//using NUnit.Framework; -//using Utils; +using CodexContractsPlugin; +using CodexPlugin; +using FileUtils; +using NUnit.Framework; +using Utils; -//namespace ContinuousTests.Tests -//{ -// public class MarketplaceTest : ContinuousTest -// { -// public override int RequiredNumberOfNodes => 1; -// public override TimeSpan RunTestEvery => TimeSpan.FromMinutes(10); -// public override TestFailMode TestFailMode => TestFailMode.StopAfterFirstFailure; -// public override int EthereumAccountIndex => 200; -// public override string CustomK8sNamespace => "codex-continuous-marketplace"; -// private readonly uint numberOfSlots = 3; -// private readonly ByteSize fileSize = 10.MB(); -// private readonly TestToken pricePerSlotPerSecond = 10.TestTokens(); +/// manual test locally. -// private TestFile file = null!; -// private ContentId? cid; -// private string purchaseId = string.Empty; -// [TestMoment(t: Zero)] -// public void NodePostsStorageRequest() -// { -// var contractDuration = TimeSpan.FromMinutes(8); -// decimal totalDurationSeconds = Convert.ToDecimal(contractDuration.TotalSeconds); -// var expectedTotalCost = numberOfSlots * pricePerSlotPerSecond.Amount * (totalDurationSeconds + 1) * 1000000; +namespace ContinuousTests.Tests +{ + public class MarketplaceTest : ContinuousTest + { + public override int RequiredNumberOfNodes => 1; + public override TimeSpan RunTestEvery => TimeSpan.FromMinutes(10); + public override TestFailMode TestFailMode => TestFailMode.StopAfterFirstFailure; -// file = FileManager.GenerateTestFile(fileSize); + private readonly uint numberOfSlots = 3; + private readonly ByteSize fileSize = 10.MB(); + private readonly TestToken pricePerSlotPerSecond = 10.TestTokens(); -// NodeRunner.RunNode((codexAccess, marketplaceAccess) => -// { -// cid = UploadFile(codexAccess.Node, file); -// Assert.That(cid, Is.Not.Null); + private TrackedFile file = null!; + private ContentId? cid; + private string purchaseId = string.Empty; -// purchaseId = marketplaceAccess.RequestStorage( -// contentId: cid!, -// pricePerSlotPerSecond: pricePerSlotPerSecond, -// requiredCollateral: 100.TestTokens(), -// minRequiredNumberOfNodes: numberOfSlots, -// proofProbability: 10, -// duration: contractDuration); + [TestMoment(t: Zero)] + public void NodePostsStorageRequest() + { + var contractDuration = TimeSpan.FromMinutes(8); + decimal totalDurationSeconds = Convert.ToDecimal(contractDuration.TotalSeconds); + var expectedTotalCost = numberOfSlots * pricePerSlotPerSecond.Amount * (totalDurationSeconds + 1) * 1000000; -// Assert.That(!string.IsNullOrEmpty(purchaseId)); + file = FileManager.GenerateFile(fileSize); -// WaitForContractToStart(codexAccess, purchaseId); -// }); -// } + NodeRunner.RunNode( + s => s.WithName("Buyer"), + node => + { + cid = node.UploadFile(file); + Assert.That(cid, Is.Not.Null); -// [TestMoment(t: MinuteFive + MinuteOne)] -// public void StoredDataIsAvailableAfterThreeDays() -// { -// NodeRunner.RunNode((codexAccess, marketplaceAccess) => -// { -// var result = DownloadFile(codexAccess.Node, cid!); + purchaseId = node.Marketplace.RequestStorage( + contentId: cid!, + pricePerSlotPerSecond: pricePerSlotPerSecond, + requiredCollateral: 100.TestTokens(), + minRequiredNumberOfNodes: numberOfSlots, + proofProbability: 10, + duration: contractDuration); -// file.AssertIsEqual(result); -// }); -// } -// } -//} + Assert.That(!string.IsNullOrEmpty(purchaseId)); + + WaitForContractToStart(codexAccess, purchaseId); + }); + } + + [TestMoment(t: MinuteFive + MinuteOne)] + public void StoredDataIsAvailableAfterThreeDays() + { + NodeRunner.RunNode((codexAccess, marketplaceAccess) => + { + var result = DownloadFile(codexAccess.Node, cid!); + + file.AssertIsEqual(result); + }); + } + } +}