2023-04-12 14:06:04 +00:00
|
|
|
|
using DistTestCore.Codex;
|
2023-04-14 08:51:35 +00:00
|
|
|
|
using DistTestCore.Marketplace;
|
2023-04-12 14:12:04 +00:00
|
|
|
|
using KubernetesWorkflow;
|
2023-09-08 08:21:40 +00:00
|
|
|
|
using Utils;
|
2023-04-12 14:06:04 +00:00
|
|
|
|
|
|
|
|
|
namespace DistTestCore
|
|
|
|
|
{
|
2023-04-13 07:33:10 +00:00
|
|
|
|
public interface ICodexSetup
|
2023-04-12 14:06:04 +00:00
|
|
|
|
{
|
2023-04-30 08:56:19 +00:00
|
|
|
|
ICodexSetup WithName(string name);
|
2023-04-13 07:33:10 +00:00
|
|
|
|
ICodexSetup At(Location location);
|
2023-09-14 05:03:09 +00:00
|
|
|
|
ICodexSetup WithLogLevel(CodexLogLevel level);
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the log level for codex. The default level is INFO and the
|
|
|
|
|
/// log level is applied only to the supplied topics.
|
|
|
|
|
/// </summary>
|
|
|
|
|
ICodexSetup WithLogLevel(CodexLogLevel level, params string[] topics);
|
2023-04-19 12:57:00 +00:00
|
|
|
|
ICodexSetup WithBootstrapNode(IOnlineCodexNode node);
|
2023-04-13 07:33:10 +00:00
|
|
|
|
ICodexSetup WithStorageQuota(ByteSize storageQuota);
|
2023-08-10 07:44:23 +00:00
|
|
|
|
ICodexSetup WithBlockTTL(TimeSpan duration);
|
2023-08-14 13:51:03 +00:00
|
|
|
|
ICodexSetup WithBlockMaintenanceInterval(TimeSpan duration);
|
2023-08-14 14:37:31 +00:00
|
|
|
|
ICodexSetup WithBlockMaintenanceNumber(int numberOfBlocks);
|
2023-04-13 07:33:10 +00:00
|
|
|
|
ICodexSetup EnableMetrics();
|
2023-04-18 08:22:11 +00:00
|
|
|
|
ICodexSetup EnableMarketplace(TestToken initialBalance);
|
|
|
|
|
ICodexSetup EnableMarketplace(TestToken initialBalance, Ether initialEther);
|
2023-06-22 13:58:18 +00:00
|
|
|
|
ICodexSetup EnableMarketplace(TestToken initialBalance, Ether initialEther, bool isValidator);
|
2023-09-14 05:02:53 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Provides an invalid proof every N proofs
|
|
|
|
|
/// </summary>
|
|
|
|
|
ICodexSetup WithSimulateProofFailures(uint failEveryNProofs);
|
2023-04-12 14:06:04 +00:00
|
|
|
|
}
|
2023-09-14 05:02:53 +00:00
|
|
|
|
|
2023-04-13 07:33:10 +00:00
|
|
|
|
public class CodexSetup : CodexStartupConfig, ICodexSetup
|
2023-04-12 14:06:04 +00:00
|
|
|
|
{
|
|
|
|
|
public int NumberOfNodes { get; }
|
|
|
|
|
|
2023-05-31 11:34:12 +00:00
|
|
|
|
public CodexSetup(int numberOfNodes, CodexLogLevel logLevel)
|
|
|
|
|
: base(logLevel)
|
2023-04-12 14:06:04 +00:00
|
|
|
|
{
|
|
|
|
|
NumberOfNodes = numberOfNodes;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-30 08:56:19 +00:00
|
|
|
|
public ICodexSetup WithName(string name)
|
|
|
|
|
{
|
|
|
|
|
NameOverride = name;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-13 07:33:10 +00:00
|
|
|
|
public ICodexSetup At(Location location)
|
2023-04-12 14:06:04 +00:00
|
|
|
|
{
|
|
|
|
|
Location = location;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-19 12:57:00 +00:00
|
|
|
|
public ICodexSetup WithBootstrapNode(IOnlineCodexNode node)
|
|
|
|
|
{
|
2023-04-24 12:09:23 +00:00
|
|
|
|
BootstrapSpr = node.GetDebugInfo().spr;
|
2023-04-19 12:57:00 +00:00
|
|
|
|
return this;
|
|
|
|
|
}
|
2023-04-12 14:06:04 +00:00
|
|
|
|
|
2023-09-14 05:03:09 +00:00
|
|
|
|
public ICodexSetup WithLogLevel(CodexLogLevel level)
|
|
|
|
|
{
|
|
|
|
|
LogLevel = level;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ICodexSetup WithLogLevel(CodexLogLevel level, params string[] topics)
|
|
|
|
|
{
|
|
|
|
|
LogLevel = level;
|
|
|
|
|
LogTopics = topics;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-13 07:33:10 +00:00
|
|
|
|
public ICodexSetup WithStorageQuota(ByteSize storageQuota)
|
2023-04-12 14:06:04 +00:00
|
|
|
|
{
|
|
|
|
|
StorageQuota = storageQuota;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-10 07:44:23 +00:00
|
|
|
|
public ICodexSetup WithBlockTTL(TimeSpan duration)
|
|
|
|
|
{
|
|
|
|
|
BlockTTL = Convert.ToInt32(duration.TotalSeconds);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-14 13:51:03 +00:00
|
|
|
|
public ICodexSetup WithBlockMaintenanceInterval(TimeSpan duration)
|
|
|
|
|
{
|
|
|
|
|
BlockMaintenanceInterval = duration;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-14 14:37:31 +00:00
|
|
|
|
public ICodexSetup WithBlockMaintenanceNumber(int numberOfBlocks)
|
|
|
|
|
{
|
|
|
|
|
BlockMaintenanceNumber = numberOfBlocks;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-13 07:33:10 +00:00
|
|
|
|
public ICodexSetup EnableMetrics()
|
2023-04-12 14:06:04 +00:00
|
|
|
|
{
|
2023-08-13 07:07:23 +00:00
|
|
|
|
MetricsMode = Metrics.MetricsMode.Record;
|
2023-04-12 14:06:04 +00:00
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-18 08:22:11 +00:00
|
|
|
|
public ICodexSetup EnableMarketplace(TestToken initialBalance)
|
2023-04-14 08:51:35 +00:00
|
|
|
|
{
|
2023-04-18 08:22:11 +00:00
|
|
|
|
return EnableMarketplace(initialBalance, 1000.Eth());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ICodexSetup EnableMarketplace(TestToken initialBalance, Ether initialEther)
|
|
|
|
|
{
|
2023-09-14 05:11:04 +00:00
|
|
|
|
return EnableMarketplace(initialBalance, initialEther, false);
|
2023-06-22 13:58:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ICodexSetup EnableMarketplace(TestToken initialBalance, Ether initialEther, bool isValidator)
|
|
|
|
|
{
|
|
|
|
|
MarketplaceConfig = new MarketplaceInitialConfig(initialEther, initialBalance, isValidator);
|
2023-04-14 08:51:35 +00:00
|
|
|
|
return this;
|
|
|
|
|
}
|
2023-04-12 14:06:04 +00:00
|
|
|
|
|
2023-09-14 05:02:53 +00:00
|
|
|
|
public ICodexSetup WithSimulateProofFailures(uint failEveryNProofs)
|
|
|
|
|
{
|
|
|
|
|
SimulateProofFailures = failEveryNProofs;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-12 14:06:04 +00:00
|
|
|
|
public string Describe()
|
|
|
|
|
{
|
|
|
|
|
var args = string.Join(',', DescribeArgs());
|
2023-04-19 12:57:00 +00:00
|
|
|
|
return $"({NumberOfNodes} CodexNodes with args:[{args}])";
|
2023-04-12 14:06:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerable<string> DescribeArgs()
|
|
|
|
|
{
|
2023-09-14 05:04:37 +00:00
|
|
|
|
yield return $"LogLevel={LogLevelWithTopics()}";
|
2023-04-24 12:09:23 +00:00
|
|
|
|
if (BootstrapSpr != null) yield return $"BootstrapNode={BootstrapSpr}";
|
2023-09-14 05:02:53 +00:00
|
|
|
|
if (StorageQuota != null) yield return $"StorageQuota={StorageQuota}";
|
|
|
|
|
if (SimulateProofFailures != null) yield return $"SimulateProofFailures={SimulateProofFailures}";
|
2023-09-14 05:04:37 +00:00
|
|
|
|
if (MarketplaceConfig != null) yield return $"IsValidator={MarketplaceConfig.IsValidator}";
|
2023-04-12 14:06:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|