diff --git a/CodexContractsPlugin/CodexContractsAccess.cs b/CodexContractsPlugin/CodexContractsAccess.cs index c807c40..b432121 100644 --- a/CodexContractsPlugin/CodexContractsAccess.cs +++ b/CodexContractsPlugin/CodexContractsAccess.cs @@ -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(); } } diff --git a/CodexContractsPlugin/CodexContractsDeployment.cs b/CodexContractsPlugin/CodexContractsDeployment.cs new file mode 100644 index 0000000..3784865 --- /dev/null +++ b/CodexContractsPlugin/CodexContractsDeployment.cs @@ -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; } + } +} diff --git a/CodexContractsPlugin/CodexContractsPlugin.cs b/CodexContractsPlugin/CodexContractsPlugin.cs index 6dadfe7..6b15721 100644 --- a/CodexContractsPlugin/CodexContractsPlugin.cs +++ b/CodexContractsPlugin/CodexContractsPlugin.cs @@ -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)); } } } diff --git a/CodexContractsPlugin/CodexContractsStarter.cs b/CodexContractsPlugin/CodexContractsStarter.cs index 92085bb..081bb6b 100644 --- a/CodexContractsPlugin/CodexContractsStarter.cs +++ b/CodexContractsPlugin/CodexContractsStarter.cs @@ -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) diff --git a/CodexContractsPlugin/CoreInterfaceExtensions.cs b/CodexContractsPlugin/CoreInterfaceExtensions.cs index 20c4645..34b50e3 100644 --- a/CodexContractsPlugin/CoreInterfaceExtensions.cs +++ b/CodexContractsPlugin/CoreInterfaceExtensions.cs @@ -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(); diff --git a/CodexPlugin/CodexContainerRecipe.cs b/CodexPlugin/CodexContainerRecipe.cs index e173fc6..986a1d0 100644 --- a/CodexPlugin/CodexContainerRecipe.cs +++ b/CodexPlugin/CodexContainerRecipe.cs @@ -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(); @@ -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); diff --git a/CodexPlugin/CodexPlugin.cs b/CodexPlugin/CodexPlugin.cs index b2ae282..4619636 100644 --- a/CodexPlugin/CodexPlugin.cs +++ b/CodexPlugin/CodexPlugin.cs @@ -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 setup) diff --git a/Core/SerializeGate.cs b/Core/SerializeGate.cs new file mode 100644 index 0000000..762d1c1 --- /dev/null +++ b/Core/SerializeGate.cs @@ -0,0 +1,13 @@ +using Newtonsoft.Json; + +namespace Core +{ + public static class SerializeGate + { + public static T Gate(T anything) + { + var json = JsonConvert.SerializeObject(anything); + return JsonConvert.DeserializeObject(json)!; + } + } +} diff --git a/GethPlugin/CoreInterfaceExtensions.cs b/GethPlugin/CoreInterfaceExtensions.cs index b486c5c..e07eca2 100644 --- a/GethPlugin/CoreInterfaceExtensions.cs +++ b/GethPlugin/CoreInterfaceExtensions.cs @@ -4,10 +4,20 @@ namespace GethPlugin { public static class CoreInterfaceExtensions { + public static IGethDeployment DeployGeth(this CoreInterface ci, Action 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 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) diff --git a/GethPlugin/GethStartResult.cs b/GethPlugin/GethDeployment.cs similarity index 76% rename from GethPlugin/GethStartResult.cs rename to GethPlugin/GethDeployment.cs index 90bb895..62a9fad 100644 --- a/GethPlugin/GethStartResult.cs +++ b/GethPlugin/GethDeployment.cs @@ -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; diff --git a/GethPlugin/GethNode.cs b/GethPlugin/GethNode.cs index 170896b..6388b08 100644 --- a/GethPlugin/GethNode.cs +++ b/GethPlugin/GethNode.cs @@ -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() diff --git a/GethPlugin/GethPlugin.cs b/GethPlugin/GethPlugin.cs index 9c2f0bb..1dff3e6 100644 --- a/GethPlugin/GethPlugin.cs +++ b/GethPlugin/GethPlugin.cs @@ -29,16 +29,16 @@ namespace GethPlugin { } - public IGethStartResult StartGeth(Action setup) + public IGethDeployment DeployGeth(Action 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)); } } } diff --git a/GethPlugin/GethStarter.cs b/GethPlugin/GethStarter.cs index dc9246e..541e75a 100644 --- a/GethPlugin/GethStarter.cs +++ b/GethPlugin/GethStarter.cs @@ -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) diff --git a/MetricsPlugin/CoreInterfaceExtensions.cs b/MetricsPlugin/CoreInterfaceExtensions.cs index 98d36f0..0c32007 100644 --- a/MetricsPlugin/CoreInterfaceExtensions.cs +++ b/MetricsPlugin/CoreInterfaceExtensions.cs @@ -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) diff --git a/MetricsPlugin/MetricsPlugin.cs b/MetricsPlugin/MetricsPlugin.cs index 0a7c7d0..431aea9 100644 --- a/MetricsPlugin/MetricsPlugin.cs +++ b/MetricsPlugin/MetricsPlugin.cs @@ -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) diff --git a/Tests/BasicTests/ExampleTests.cs b/Tests/BasicTests/ExampleTests.cs index 40609a8..2858c6e 100644 --- a/Tests/BasicTests/ExampleTests.cs +++ b/Tests/BasicTests/ExampleTests.cs @@ -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())