Sets serialization gate between each deploy and wrap to ensure application lifecycle invariance.
This commit is contained in:
parent
cedaf84740
commit
5fa4e0ff9f
|
@ -5,7 +5,7 @@ namespace CodexContractsPlugin
|
|||
{
|
||||
public interface ICodexContracts
|
||||
{
|
||||
string MarketplaceAddress { get; }
|
||||
ICodexContractsDeployment Deployment { get; }
|
||||
|
||||
void MintTestTokens(IGethNode gethNode, IHasEthAddress owner, TestToken testTokens);
|
||||
void MintTestTokens(IGethNode gethNode, IEthAddress ethAddress, TestToken testTokens);
|
||||
|
@ -17,17 +17,13 @@ namespace CodexContractsPlugin
|
|||
{
|
||||
private readonly ILog log;
|
||||
|
||||
public CodexContractsAccess(ILog log, string marketplaceAddress, string abi, string tokenAddress)
|
||||
public CodexContractsAccess(ILog log, ICodexContractsDeployment deployment)
|
||||
{
|
||||
this.log = log;
|
||||
MarketplaceAddress = marketplaceAddress;
|
||||
Abi = abi;
|
||||
TokenAddress = tokenAddress;
|
||||
Deployment = deployment;
|
||||
}
|
||||
|
||||
public string MarketplaceAddress { get; }
|
||||
public string Abi { get; }
|
||||
public string TokenAddress { get; }
|
||||
public ICodexContractsDeployment Deployment { get; }
|
||||
|
||||
public void MintTestTokens(IGethNode gethNode, IHasEthAddress owner, TestToken testTokens)
|
||||
{
|
||||
|
@ -37,7 +33,7 @@ namespace CodexContractsPlugin
|
|||
public void MintTestTokens(IGethNode gethNode, IEthAddress ethAddress, TestToken testTokens)
|
||||
{
|
||||
var interaction = new ContractInteractions(log, gethNode);
|
||||
interaction.MintTestTokens(ethAddress, testTokens.Amount, TokenAddress);
|
||||
interaction.MintTestTokens(ethAddress, testTokens.Amount, Deployment.TokenAddress);
|
||||
}
|
||||
|
||||
public TestToken GetTestTokenBalance(IGethNode gethNode, IHasEthAddress owner)
|
||||
|
@ -48,7 +44,7 @@ namespace CodexContractsPlugin
|
|||
public TestToken GetTestTokenBalance(IGethNode gethNode, IEthAddress ethAddress)
|
||||
{
|
||||
var interaction = new ContractInteractions(log, gethNode);
|
||||
var balance = interaction.GetBalance(TokenAddress, ethAddress.Address);
|
||||
var balance = interaction.GetBalance(Deployment.TokenAddress, ethAddress.Address);
|
||||
return balance.TestTokens();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
namespace CodexContractsPlugin
|
||||
{
|
||||
public interface ICodexContractsDeployment
|
||||
{
|
||||
string MarketplaceAddress { get; }
|
||||
string Abi { get; }
|
||||
string TokenAddress { get; }
|
||||
}
|
||||
|
||||
public class CodexContractsDeployment : ICodexContractsDeployment
|
||||
{
|
||||
public CodexContractsDeployment(string marketplaceAddress, string abi, string tokenAddress)
|
||||
{
|
||||
MarketplaceAddress = marketplaceAddress;
|
||||
Abi = abi;
|
||||
TokenAddress = tokenAddress;
|
||||
}
|
||||
|
||||
public string MarketplaceAddress { get; }
|
||||
public string Abi { get; }
|
||||
public string TokenAddress { get; }
|
||||
}
|
||||
}
|
|
@ -30,9 +30,14 @@ namespace CodexContractsPlugin
|
|||
{
|
||||
}
|
||||
|
||||
public ICodexContracts DeployContracts(IGethNode gethNode)
|
||||
public ICodexContractsDeployment DeployContracts(IGethNode gethNode)
|
||||
{
|
||||
return starter.Start(gethNode);
|
||||
return starter.Deploy(gethNode);
|
||||
}
|
||||
|
||||
public ICodexContracts WrapDeploy(ICodexContractsDeployment deployment)
|
||||
{
|
||||
return starter.Wrap(SerializeGate.Gate(deployment));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace CodexContractsPlugin
|
|||
this.tools = tools;
|
||||
}
|
||||
|
||||
public ICodexContracts Start(IGethNode gethNode)
|
||||
public ICodexContractsDeployment Deploy(IGethNode gethNode)
|
||||
{
|
||||
Log("Deploying Codex SmartContracts...");
|
||||
|
||||
|
@ -47,7 +47,12 @@ namespace CodexContractsPlugin
|
|||
|
||||
Log("Synced. Codex SmartContracts deployed.");
|
||||
|
||||
return new CodexContractsAccess(tools.GetLog(), marketplaceAddress, abi, tokenAddress);
|
||||
return new CodexContractsDeployment(marketplaceAddress, abi, tokenAddress);
|
||||
}
|
||||
|
||||
public ICodexContracts Wrap(ICodexContractsDeployment deployment)
|
||||
{
|
||||
return new CodexContractsAccess(tools.GetLog(), deployment);
|
||||
}
|
||||
|
||||
private void Log(string msg)
|
||||
|
|
|
@ -5,11 +5,22 @@ namespace CodexContractsPlugin
|
|||
{
|
||||
public static class CoreInterfaceExtensions
|
||||
{
|
||||
public static ICodexContracts DeployCodexContracts(this CoreInterface ci, IGethNode gethNode)
|
||||
public static ICodexContractsDeployment DeployCodexContracts(this CoreInterface ci, IGethNode gethNode)
|
||||
{
|
||||
return Plugin(ci).DeployContracts(gethNode);
|
||||
}
|
||||
|
||||
public static ICodexContracts WrapCodexContractsDeployment(this CoreInterface ci, ICodexContractsDeployment deployment)
|
||||
{
|
||||
return Plugin(ci).WrapDeploy(deployment);
|
||||
}
|
||||
|
||||
public static ICodexContracts StartCodexContracts(this CoreInterface ci, IGethNode gethNode)
|
||||
{
|
||||
var deployment = DeployCodexContracts(ci, gethNode);
|
||||
return WrapCodexContractsDeployment(ci, deployment);
|
||||
}
|
||||
|
||||
private static CodexContractsPlugin Plugin(CoreInterface ci)
|
||||
{
|
||||
return ci.GetPlugin<CodexContractsPlugin>();
|
||||
|
|
|
@ -26,8 +26,8 @@ namespace CodexPlugin
|
|||
|
||||
protected override void Initialize(StartupConfig startupConfig)
|
||||
{
|
||||
SetResourcesRequest(milliCPUs: 1000, memory: 6.GB());
|
||||
SetResourceLimits(milliCPUs: 4000, memory: 12.GB());
|
||||
//SetResourcesRequest(milliCPUs: 1000, memory: 6.GB());
|
||||
//SetResourceLimits(milliCPUs: 4000, memory: 12.GB());
|
||||
|
||||
var config = startupConfig.Get<CodexStartupConfig>();
|
||||
|
||||
|
@ -83,7 +83,7 @@ namespace CodexPlugin
|
|||
var gethStart = mconfig.GethNode.StartResult;
|
||||
var ip = gethStart.RunningContainer.Pod.PodInfo.Ip;
|
||||
var port = gethStart.WsPort.Number;
|
||||
var marketplaceAddress = mconfig.CodexContracts.MarketplaceAddress;
|
||||
var marketplaceAddress = mconfig.CodexContracts.Deployment.MarketplaceAddress;
|
||||
|
||||
AddEnvVar("CODEX_ETH_PROVIDER", $"ws://{ip}:{port}");
|
||||
AddEnvVar("CODEX_MARKETPLACE_ADDRESS", marketplaceAddress);
|
||||
|
|
|
@ -39,7 +39,8 @@ namespace CodexPlugin
|
|||
|
||||
public ICodexNodeGroup WrapCodexContainers(CoreInterface coreInterface, RunningContainers[] containers)
|
||||
{
|
||||
return codexStarter.WrapCodexContainers(coreInterface, containers);
|
||||
var cs = containers.Select(c => SerializeGate.Gate(c)).ToArray();
|
||||
return codexStarter.WrapCodexContainers(coreInterface, cs);
|
||||
}
|
||||
|
||||
public void WireUpMarketplace(ICodexNodeGroup result, Action<ICodexSetup> setup)
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
using Newtonsoft.Json;
|
||||
|
||||
namespace Core
|
||||
{
|
||||
public static class SerializeGate
|
||||
{
|
||||
public static T Gate<T>(T anything)
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(anything);
|
||||
return JsonConvert.DeserializeObject<T>(json)!;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,10 +4,20 @@ namespace GethPlugin
|
|||
{
|
||||
public static class CoreInterfaceExtensions
|
||||
{
|
||||
public static IGethDeployment DeployGeth(this CoreInterface ci, Action<IGethSetup> setup)
|
||||
{
|
||||
return Plugin(ci).DeployGeth(setup);
|
||||
}
|
||||
|
||||
public static IGethNode WrapGethDeployment(this CoreInterface ci, IGethDeployment deployment)
|
||||
{
|
||||
return Plugin(ci).WrapGethDeployment(deployment);
|
||||
}
|
||||
|
||||
public static IGethNode StartGethNode(this CoreInterface ci, Action<IGethSetup> setup)
|
||||
{
|
||||
var p = Plugin(ci);
|
||||
return p.WrapGethContainer(p.StartGeth(setup));
|
||||
var deploy = DeployGeth(ci, setup);
|
||||
return WrapGethDeployment(ci, deploy);
|
||||
}
|
||||
|
||||
private static GethPlugin Plugin(CoreInterface ci)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace GethPlugin
|
||||
{
|
||||
public interface IGethStartResult
|
||||
public interface IGethDeployment
|
||||
{
|
||||
RunningContainer RunningContainer { get; }
|
||||
Port DiscoveryPort { get; }
|
||||
|
@ -12,9 +12,9 @@ namespace GethPlugin
|
|||
string PubKey { get; }
|
||||
}
|
||||
|
||||
public class GethStartResult : IGethStartResult
|
||||
public class GethDeployment : IGethDeployment
|
||||
{
|
||||
public GethStartResult(RunningContainer runningContainer, Port discoveryPort, Port httpPort, Port wsPort, AllGethAccounts allAccounts, string pubKey)
|
||||
public GethDeployment(RunningContainer runningContainer, Port discoveryPort, Port httpPort, Port wsPort, AllGethAccounts allAccounts, string pubKey)
|
||||
{
|
||||
RunningContainer = runningContainer;
|
||||
DiscoveryPort = discoveryPort;
|
|
@ -6,7 +6,7 @@ namespace GethPlugin
|
|||
{
|
||||
public interface IGethNode
|
||||
{
|
||||
IGethStartResult StartResult { get; }
|
||||
IGethDeployment StartResult { get; }
|
||||
|
||||
Ether GetEthBalance();
|
||||
Ether GetEthBalance(IHasEthAddress address);
|
||||
|
@ -23,14 +23,14 @@ namespace GethPlugin
|
|||
{
|
||||
private readonly ILog log;
|
||||
|
||||
public GethNode(ILog log, IGethStartResult startResult)
|
||||
public GethNode(ILog log, IGethDeployment startResult)
|
||||
{
|
||||
this.log = log;
|
||||
StartResult = startResult;
|
||||
Account = startResult.AllAccounts.Accounts.First();
|
||||
}
|
||||
|
||||
public IGethStartResult StartResult { get; }
|
||||
public IGethDeployment StartResult { get; }
|
||||
public GethAccount Account { get; }
|
||||
|
||||
public Ether GetEthBalance()
|
||||
|
|
|
@ -29,16 +29,16 @@ namespace GethPlugin
|
|||
{
|
||||
}
|
||||
|
||||
public IGethStartResult StartGeth(Action<IGethSetup> setup)
|
||||
public IGethDeployment DeployGeth(Action<IGethSetup> setup)
|
||||
{
|
||||
var startupConfig = new GethStartupConfig();
|
||||
setup(startupConfig);
|
||||
return starter.StartGeth(startupConfig);
|
||||
}
|
||||
|
||||
public IGethNode WrapGethContainer(IGethStartResult startResult)
|
||||
public IGethNode WrapGethDeployment(IGethDeployment startResult)
|
||||
{
|
||||
return starter.WrapGethContainer(startResult);
|
||||
return starter.WrapGethContainer(SerializeGate.Gate(startResult));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace GethPlugin
|
|||
this.tools = tools;
|
||||
}
|
||||
|
||||
public IGethStartResult StartGeth(GethStartupConfig gethStartupConfig)
|
||||
public IGethDeployment StartGeth(GethStartupConfig gethStartupConfig)
|
||||
{
|
||||
Log("Starting Geth bootstrap node...");
|
||||
|
||||
|
@ -38,12 +38,12 @@ namespace GethPlugin
|
|||
|
||||
Log($"Geth node started.");
|
||||
|
||||
return new GethStartResult(container, discoveryPort, httpPort, wsPort, accounts, pubKey);
|
||||
return new GethDeployment(container, discoveryPort, httpPort, wsPort, accounts, pubKey);
|
||||
}
|
||||
|
||||
public IGethNode WrapGethContainer(IGethStartResult startResult)
|
||||
public IGethNode WrapGethContainer(IGethDeployment startResult)
|
||||
{
|
||||
return new GethNode(tools.GetLog(), startResult);
|
||||
return new GethNode(tools.GetLog(), SerializeGate.Gate(startResult));
|
||||
}
|
||||
|
||||
private void Log(string msg)
|
||||
|
|
|
@ -6,19 +6,19 @@ namespace MetricsPlugin
|
|||
{
|
||||
public static class CoreInterfaceExtensions
|
||||
{
|
||||
public static RunningContainer StartMetricsCollector(this CoreInterface ci, params IHasMetricsScrapeTarget[] scrapeTargets)
|
||||
public static RunningContainer DeployMetricsCollector(this CoreInterface ci, params IHasMetricsScrapeTarget[] scrapeTargets)
|
||||
{
|
||||
return Plugin(ci).StartMetricsCollector(scrapeTargets.Select(t => t.MetricsScrapeTarget).ToArray());
|
||||
return Plugin(ci).DeployMetricsCollector(scrapeTargets.Select(t => t.MetricsScrapeTarget).ToArray());
|
||||
}
|
||||
|
||||
public static RunningContainer StartMetricsCollector(this CoreInterface ci, params IMetricsScrapeTarget[] scrapeTargets)
|
||||
public static RunningContainer DeployMetricsCollector(this CoreInterface ci, params IMetricsScrapeTarget[] scrapeTargets)
|
||||
{
|
||||
return Plugin(ci).StartMetricsCollector(scrapeTargets);
|
||||
return Plugin(ci).DeployMetricsCollector(scrapeTargets);
|
||||
}
|
||||
|
||||
public static IMetricsAccess GetMetricsFor(this CoreInterface ci, RunningContainer metricsContainer, IMetricsScrapeTarget scrapeTarget)
|
||||
public static IMetricsAccess WrapMetricsCollector(this CoreInterface ci, RunningContainer metricsContainer, IMetricsScrapeTarget scrapeTarget)
|
||||
{
|
||||
return Plugin(ci).CreateAccessForTarget(metricsContainer, scrapeTarget);
|
||||
return Plugin(ci).WrapMetricsCollectorDeployment(metricsContainer, scrapeTarget);
|
||||
}
|
||||
|
||||
public static IMetricsAccess[] GetMetricsFor(this CoreInterface ci, params IHasManyMetricScrapeTargets[] manyScrapeTargets)
|
||||
|
@ -33,8 +33,8 @@ namespace MetricsPlugin
|
|||
|
||||
public static IMetricsAccess[] GetMetricsFor(this CoreInterface ci, params IMetricsScrapeTarget[] scrapeTargets)
|
||||
{
|
||||
var rc = ci.StartMetricsCollector(scrapeTargets);
|
||||
return scrapeTargets.Select(t => ci.GetMetricsFor(rc, t)).ToArray();
|
||||
var rc = ci.DeployMetricsCollector(scrapeTargets);
|
||||
return scrapeTargets.Select(t => ci.WrapMetricsCollector(rc, t)).ToArray();
|
||||
}
|
||||
|
||||
public static LogFile? DownloadAllMetrics(this CoreInterface ci, IMetricsAccess metricsAccess, string targetName)
|
||||
|
|
|
@ -31,14 +31,14 @@ namespace MetricsPlugin
|
|||
{
|
||||
}
|
||||
|
||||
public RunningContainer StartMetricsCollector(IMetricsScrapeTarget[] scrapeTargets)
|
||||
public RunningContainer DeployMetricsCollector(IMetricsScrapeTarget[] scrapeTargets)
|
||||
{
|
||||
return starter.CollectMetricsFor(scrapeTargets);
|
||||
}
|
||||
|
||||
public MetricsAccess CreateAccessForTarget(RunningContainer runningContainer, IMetricsScrapeTarget target)
|
||||
public IMetricsAccess WrapMetricsCollectorDeployment(RunningContainer runningContainer, IMetricsScrapeTarget target)
|
||||
{
|
||||
return starter.CreateAccessForTarget(runningContainer, target);
|
||||
return starter.CreateAccessForTarget(SerializeGate.Gate(runningContainer), target);
|
||||
}
|
||||
|
||||
public LogFile? DownloadAllMetrics(IMetricsAccess metricsAccess, string targetName)
|
||||
|
|
|
@ -52,7 +52,7 @@ namespace Tests.BasicTests
|
|||
var fileSize = 10.MB();
|
||||
|
||||
var geth = Ci.StartGethNode(s => s.IsMiner().WithName("disttest-geth"));
|
||||
var contracts = Ci.DeployCodexContracts(geth);
|
||||
var contracts = Ci.StartCodexContracts(geth);
|
||||
|
||||
var seller = AddCodex(s => s
|
||||
.WithStorageQuota(11.GB())
|
||||
|
|
Loading…
Reference in New Issue