cs-codex-dist-tests/CodexPlugin/CodexSetup.cs

125 lines
3.9 KiB
C#
Raw Normal View History

2023-09-19 08:24:43 +00:00
using CodexContractsPlugin;
using GethPlugin;
using KubernetesWorkflow;
2023-09-08 08:21:40 +00:00
using Utils;
2023-04-12 14:06:04 +00:00
namespace CodexPlugin
2023-04-12 14:06:04 +00:00
{
2023-04-13 07:33:10 +00:00
public interface ICodexSetup
2023-04-12 14:06:04 +00:00
{
ICodexSetup WithLogLevel(CodexLogLevel logLevel);
ICodexSetup WithName(string name);
2023-04-13 07:33:10 +00:00
ICodexSetup At(Location location);
2023-04-19 12:57:00 +00:00
ICodexSetup WithBootstrapNode(IOnlineCodexNode node);
2023-04-13 07:33:10 +00:00
ICodexSetup WithStorageQuota(ByteSize storageQuota);
ICodexSetup WithBlockTTL(TimeSpan duration);
ICodexSetup WithBlockMaintenanceInterval(TimeSpan duration);
ICodexSetup WithBlockMaintenanceNumber(int numberOfBlocks);
2023-09-13 09:59:21 +00:00
ICodexSetup EnableMetrics();
2023-09-19 08:24:43 +00:00
ICodexSetup EnableMarketplace(IGethNode gethNode, ICodexContracts codexContracts, bool isValidator = false);
//ICodexSetup EnableMarketplace(TestToken initialBalance);
//ICodexSetup EnableMarketplace(TestToken initialBalance, Ether initialEther);
//ICodexSetup EnableMarketplace(TestToken initialBalance, Ether initialEther, bool isValidator);
2023-04-12 14:06:04 +00:00
}
2023-04-12 14:12:04 +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; }
public CodexSetup(int numberOfNodes)
2023-04-12 14:06:04 +00:00
{
NumberOfNodes = numberOfNodes;
}
public ICodexSetup WithLogLevel(CodexLogLevel logLevel)
{
LogLevel = logLevel;
return this;
}
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)
{
BootstrapSpr = node.GetDebugInfo().spr;
2023-04-19 12:57:00 +00:00
return this;
}
2023-04-12 14:06:04 +00:00
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;
}
public ICodexSetup WithBlockTTL(TimeSpan duration)
{
BlockTTL = Convert.ToInt32(duration.TotalSeconds);
return this;
}
public ICodexSetup WithBlockMaintenanceInterval(TimeSpan duration)
{
BlockMaintenanceInterval = duration;
return this;
}
public ICodexSetup WithBlockMaintenanceNumber(int numberOfBlocks)
{
BlockMaintenanceNumber = numberOfBlocks;
return this;
}
2023-09-13 09:59:21 +00:00
public ICodexSetup EnableMetrics()
{
MetricsEnabled = true;
return this;
}
2023-04-12 14:06:04 +00:00
2023-09-19 08:24:43 +00:00
public ICodexSetup EnableMarketplace(IGethNode gethNode, ICodexContracts codexContracts, bool isValidator = false)
{
MarketplaceConfig = new MarketplaceInitialConfig(gethNode, codexContracts, isValidator);
return this;
}
//public ICodexSetup EnableMarketplace(TestToken initialBalance)
//{
// return EnableMarketplace(initialBalance, 1000.Eth());
//}
//public ICodexSetup EnableMarketplace(TestToken initialBalance, Ether initialEther)
//{
// 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);
// 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-05-31 11:34:12 +00:00
yield return $"LogLevel={LogLevel}";
if (BootstrapSpr != null) yield return $"BootstrapNode={BootstrapSpr}";
2023-04-19 07:57:37 +00:00
if (StorageQuota != null) yield return $"StorageQuote={StorageQuota}";
2023-04-12 14:06:04 +00:00
}
}
}