Skip to content

Commit 70622cf

Browse files
committed
connects blockCaches from test lifecycle
1 parent 459cb2e commit 70622cf

File tree

23 files changed

+85
-46
lines changed

23 files changed

+85
-46
lines changed

Framework/GethConnector/GethConnector.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using CodexContractsPlugin;
1+
using BlockchainUtils;
2+
using CodexContractsPlugin;
23
using CodexContractsPlugin.Marketplace;
34
using GethPlugin;
45
using Logging;
@@ -19,7 +20,7 @@ public class GethConnector
1920
return null;
2021
}
2122

22-
var gethNode = new CustomGethNode(log, GethInput.GethHost, GethInput.GethPort, GethInput.PrivateKey);
23+
var gethNode = new CustomGethNode(log, new BlockCache(), GethInput.GethHost, GethInput.GethPort, GethInput.PrivateKey);
2324

2425
var config = GetCodexMarketplaceConfig(gethNode, GethInput.MarketplaceAddress);
2526

Framework/NethereumWorkflow/NethereumInteraction.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ namespace NethereumWorkflow
1010
{
1111
public class NethereumInteraction
1212
{
13-
private readonly static BlockCache blockCache = new BlockCache(); // WRONG: parallel environments!
13+
private readonly BlockCache blockCache;
1414

1515
private readonly ILog log;
1616
private readonly Web3 web3;
1717

18-
internal NethereumInteraction(ILog log, Web3 web3)
18+
internal NethereumInteraction(ILog log, Web3 web3, BlockCache blockCache)
1919
{
2020
this.log = log;
2121
this.web3 = web3;
22+
this.blockCache = blockCache;
2223
}
2324

2425
public string SendEth(string toAddress, decimal ethAmount)

Framework/NethereumWorkflow/NethereumInteractionCreator.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
using Logging;
1+
using BlockchainUtils;
2+
using Logging;
23
using Nethereum.Web3;
34

45
namespace NethereumWorkflow
56
{
67
public class NethereumInteractionCreator
78
{
89
private readonly ILog log;
10+
private readonly BlockCache blockCache;
911
private readonly string ip;
1012
private readonly int port;
1113
private readonly string privateKey;
1214

13-
public NethereumInteractionCreator(ILog log, string ip, int port, string privateKey)
15+
public NethereumInteractionCreator(ILog log, BlockCache blockCache, string ip, int port, string privateKey)
1416
{
1517
this.log = log;
18+
this.blockCache = blockCache;
1619
this.ip = ip;
1720
this.port = port;
1821
this.privateKey = privateKey;
@@ -21,7 +24,7 @@ public NethereumInteractionCreator(ILog log, string ip, int port, string private
2124
public NethereumInteraction CreateWorkflow()
2225
{
2326
log.Debug("Starting interaction to " + ip + ":" + port);
24-
return new NethereumInteraction(log, CreateWeb3());
27+
return new NethereumInteraction(log, CreateWeb3(), blockCache);
2528
}
2629

2730
private Web3 CreateWeb3()

ProjectPlugins/CodexContractsPlugin/ChainMonitor/ChainState.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using CodexContractsPlugin.Marketplace;
1+
using BlockchainUtils;
2+
using CodexContractsPlugin.Marketplace;
23
using GethPlugin;
34
using Logging;
4-
using NethereumWorkflow.BlockUtils;
55
using System.Numerics;
66
using Utils;
77

ProjectPlugins/CodexContractsPlugin/CodexContractsAccess.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using CodexContractsPlugin.Marketplace;
1+
using BlockchainUtils;
2+
using CodexContractsPlugin.Marketplace;
23
using GethPlugin;
34
using Logging;
45
using Nethereum.ABI;

ProjectPlugins/CodexContractsPlugin/CodexContractsEvents.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
using CodexContractsPlugin.Marketplace;
1+
using BlockchainUtils;
2+
using CodexContractsPlugin.Marketplace;
23
using GethPlugin;
34
using Logging;
45
using Nethereum.Contracts;
56
using Nethereum.Hex.HexTypes;
6-
using NethereumWorkflow.BlockUtils;
77
using Utils;
88

99
namespace CodexContractsPlugin

ProjectPlugins/CodexContractsPlugin/ContractInteractions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using CodexContractsPlugin.Marketplace;
1+
using BlockchainUtils;
2+
using CodexContractsPlugin.Marketplace;
23
using GethPlugin;
34
using Logging;
45
using Nethereum.ABI.FunctionEncoding.Attributes;

ProjectPlugins/CodexContractsPlugin/Marketplace/Customizations.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
2+
using BlockchainUtils;
23
using GethPlugin;
3-
using NethereumWorkflow.BlockUtils;
44
using Newtonsoft.Json;
55

66
namespace CodexContractsPlugin.Marketplace

ProjectPlugins/GethPlugin/CoreInterfaceExtensions.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Core;
1+
using BlockchainUtils;
2+
using Core;
23

34
namespace GethPlugin
45
{
@@ -9,15 +10,15 @@ public static GethDeployment DeployGeth(this CoreInterface ci, Action<IGethSetup
910
return Plugin(ci).DeployGeth(setup);
1011
}
1112

12-
public static IGethNode WrapGethDeployment(this CoreInterface ci, GethDeployment deployment)
13+
public static IGethNode WrapGethDeployment(this CoreInterface ci, GethDeployment deployment, BlockCache blockCache)
1314
{
14-
return Plugin(ci).WrapGethDeployment(deployment);
15+
return Plugin(ci).WrapGethDeployment(deployment, blockCache);
1516
}
1617

17-
public static IGethNode StartGethNode(this CoreInterface ci, Action<IGethSetup> setup)
18+
public static IGethNode StartGethNode(this CoreInterface ci, BlockCache blockCache, Action<IGethSetup> setup)
1819
{
1920
var deploy = DeployGeth(ci, setup);
20-
return WrapGethDeployment(ci, deploy);
21+
return WrapGethDeployment(ci, deploy, blockCache);
2122
}
2223

2324
private static GethPlugin Plugin(CoreInterface ci)

ProjectPlugins/GethPlugin/GethNode.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
using Core;
1+
using BlockchainUtils;
2+
using Core;
23
using KubernetesWorkflow.Types;
34
using Logging;
45
using Nethereum.ABI.FunctionEncoding.Attributes;
56
using Nethereum.Contracts;
67
using Nethereum.RPC.Eth.DTOs;
78
using NethereumWorkflow;
8-
using NethereumWorkflow.BlockUtils;
99
using Utils;
1010

1111
namespace GethPlugin
@@ -34,10 +34,12 @@ public interface IGethNode : IHasContainer
3434
public class DeploymentGethNode : BaseGethNode, IGethNode
3535
{
3636
private readonly ILog log;
37+
private readonly BlockCache blockCache;
3738

38-
public DeploymentGethNode(ILog log, GethDeployment startResult)
39+
public DeploymentGethNode(ILog log, BlockCache blockCache, GethDeployment startResult)
3940
{
4041
this.log = log;
42+
this.blockCache = blockCache;
4143
StartResult = startResult;
4244
}
4345

@@ -60,24 +62,26 @@ protected override NethereumInteraction StartInteraction()
6062
var address = StartResult.Container.GetAddress(GethContainerRecipe.HttpPortTag);
6163
var account = StartResult.Account;
6264

63-
var creator = new NethereumInteractionCreator(log, address.Host, address.Port, account.PrivateKey);
65+
var creator = new NethereumInteractionCreator(log, blockCache, address.Host, address.Port, account.PrivateKey);
6466
return creator.CreateWorkflow();
6567
}
6668
}
6769

6870
public class CustomGethNode : BaseGethNode, IGethNode
6971
{
7072
private readonly ILog log;
73+
private readonly BlockCache blockCache;
7174
private readonly string gethHost;
7275
private readonly int gethPort;
7376
private readonly string privateKey;
7477

7578
public GethDeployment StartResult => throw new NotImplementedException();
7679
public RunningContainer Container => throw new NotImplementedException();
7780

78-
public CustomGethNode(ILog log, string gethHost, int gethPort, string privateKey)
81+
public CustomGethNode(ILog log, BlockCache blockCache, string gethHost, int gethPort, string privateKey)
7982
{
8083
this.log = log;
84+
this.blockCache = blockCache;
8185
this.gethHost = gethHost;
8286
this.gethPort = gethPort;
8387
this.privateKey = privateKey;
@@ -90,7 +94,7 @@ public GethBootstrapNode GetBootstrapRecord()
9094

9195
protected override NethereumInteraction StartInteraction()
9296
{
93-
var creator = new NethereumInteractionCreator(log, gethHost, gethPort, privateKey);
97+
var creator = new NethereumInteractionCreator(log, blockCache, gethHost, gethPort, privateKey);
9498
return creator.CreateWorkflow();
9599
}
96100
}

ProjectPlugins/GethPlugin/GethPlugin.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Core;
1+
using BlockchainUtils;
2+
using Core;
23

34
namespace GethPlugin
45
{
@@ -36,10 +37,10 @@ public GethDeployment DeployGeth(Action<IGethSetup> setup)
3637
return starter.StartGeth(startupConfig);
3738
}
3839

39-
public IGethNode WrapGethDeployment(GethDeployment startResult)
40+
public IGethNode WrapGethDeployment(GethDeployment startResult, BlockCache blockCache)
4041
{
4142
startResult = SerializeGate.Gate(startResult);
42-
return starter.WrapGethContainer(startResult);
43+
return starter.WrapGethContainer(startResult, blockCache);
4344
}
4445
}
4546
}

ProjectPlugins/GethPlugin/GethStarter.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Core;
1+
using BlockchainUtils;
2+
using Core;
23
using KubernetesWorkflow;
34

45
namespace GethPlugin
@@ -41,10 +42,10 @@ public GethDeployment StartGeth(GethStartupConfig gethStartupConfig)
4142
return new GethDeployment(containers, discoveryPort, httpPort, wsPort, account, pubKey);
4243
}
4344

44-
public IGethNode WrapGethContainer(GethDeployment startResult)
45+
public IGethNode WrapGethContainer(GethDeployment startResult, BlockCache blockCache)
4546
{
4647
startResult = SerializeGate.Gate(startResult);
47-
return new DeploymentGethNode(tools.GetLog(), startResult);
48+
return new DeploymentGethNode(tools.GetLog(), blockCache, startResult);
4849
}
4950

5051
private void Log(string msg)

Tests/CodexReleaseTests/MarketTests/ContractFailedTest.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ public class ContractFailedTest : MarketplaceAutoBootstrapDistTest
2121
private readonly TestToken pricePerSlotPerSecond = 10.TstWei();
2222

2323
[Test]
24-
[Ignore("TODO - Test in which hosts are punished for failing a contract")]
25-
public void ContractFailed()
24+
[Combinatorial]
25+
public void ContractFailed(
26+
[Values(0, 1, 2, 3)] int a,
27+
[Values(0, 1, 2, 3)] int b
28+
)
2629
{
2730
var hosts = StartHosts();
2831
var client = StartClients().Single();

Tests/CodexReleaseTests/MarketTests/ContractSuccessfulTest.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ public class ContractSuccessfulTest : MarketplaceAutoBootstrapDistTest
1818
private readonly TestToken pricePerSlotPerSecond = 10.TstWei();
1919

2020
[Test]
21-
public void ContractSuccessful()
21+
[Combinatorial]
22+
public void ContractSuccessful(
23+
[Values(0, 1, 2, 3)] int a,
24+
[Values(0, 1, 2, 3)] int b
25+
)
2226
{
2327
var hosts = StartHosts();
2428
var client = StartClients().Single();

Tests/CodexReleaseTests/MarketTests/MarketplaceAutoBootstrapDistTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public abstract class MarketplaceAutoBootstrapDistTest : AutoBootstrapDistTest
1919
protected override void LifecycleStart(TestLifecycle lifecycle)
2020
{
2121
base.LifecycleStart(lifecycle);
22-
var geth = Ci.StartGethNode(s => s.IsMiner());
22+
var geth = StartGethNode(s => s.IsMiner());
2323
var contracts = Ci.StartCodexContracts(geth);
2424
handles.Add(lifecycle, new MarketplaceHandle(geth, contracts));
2525
}

Tests/ExperimentalTests/BasicTests/ExampleTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ public void TwoMetricsExample()
5353
[Test]
5454
public void GethBootstrapTest()
5555
{
56-
var boot = Ci.StartGethNode(s => s.WithName("boot").IsMiner());
57-
var disconnected = Ci.StartGethNode(s => s.WithName("disconnected"));
58-
var follow = Ci.StartGethNode(s => s.WithBootstrapNode(boot).WithName("follow"));
56+
var boot = StartGethNode(s => s.WithName("boot").IsMiner());
57+
var disconnected = StartGethNode(s => s.WithName("disconnected"));
58+
var follow = StartGethNode(s => s.WithBootstrapNode(boot).WithName("follow"));
5959

6060
Thread.Sleep(12000);
6161

Tests/ExperimentalTests/BasicTests/MarketplaceTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void MarketplaceExample(
2828
plusSizeBytes
2929
);
3030

31-
var geth = Ci.StartGethNode(s => s.IsMiner().WithName("disttest-geth"));
31+
var geth = StartGethNode(s => s.IsMiner().WithName("disttest-geth"));
3232
var contracts = Ci.StartCodexContracts(geth);
3333

3434
var numberOfHosts = 5;

Tests/ExperimentalTests/CodexDistTest.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using CodexContractsPlugin;
1+
using BlockchainUtils;
2+
using CodexContractsPlugin;
23
using CodexNetDeployer;
34
using CodexPlugin;
45
using CodexPlugin.OverwatchSupport;
@@ -7,6 +8,7 @@
78
using DistTestCore;
89
using DistTestCore.Helpers;
910
using DistTestCore.Logs;
11+
using GethPlugin;
1012
using Logging;
1113
using MetricsPlugin;
1214
using Newtonsoft.Json;
@@ -19,6 +21,7 @@ namespace CodexTests
1921
public class CodexDistTest : DistTest
2022
{
2123
private static readonly Dictionary<TestLifecycle, CodexTranscriptWriter> writers = new Dictionary<TestLifecycle, CodexTranscriptWriter>();
24+
private static readonly Dictionary<TestLifecycle, BlockCache> blockCaches = new Dictionary<TestLifecycle, BlockCache>();
2225

2326
public CodexDistTest()
2427
{
@@ -73,6 +76,11 @@ public ICodexNodeGroup StartCodex(int numberOfNodes, Action<ICodexSetup> setup)
7376
return group;
7477
}
7578

79+
public IGethNode StartGethNode(Action<IGethSetup> setup)
80+
{
81+
return Ci.StartGethNode(GetBlockCache(), setup);
82+
}
83+
7684
public PeerConnectionTestHelpers CreatePeerConnectionTestHelpers()
7785
{
7886
return new PeerConnectionTestHelpers(GetTestLog());
@@ -223,6 +231,16 @@ private string GetOutputFullPath(TestLifecycle lifecycle, CreateTranscriptAttrib
223231
if (!outputFile.EndsWith(".owts")) outputFile += ".owts";
224232
return outputFile;
225233
}
234+
235+
private BlockCache GetBlockCache()
236+
{
237+
var lifecycle = Get();
238+
if (!blockCaches.ContainsKey(lifecycle))
239+
{
240+
blockCaches[lifecycle] = new BlockCache();
241+
}
242+
return blockCaches[lifecycle];
243+
}
226244
}
227245

228246
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]

Tests/ExperimentalTests/DownloadConnectivityTests/FullyConnectedDownloadTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public void MetricsDoesNotInterfereWithPeerDownload()
2020
[Test]
2121
public void MarketplaceDoesNotInterfereWithPeerDownload()
2222
{
23-
var geth = Ci.StartGethNode(s => s.IsMiner());
23+
var geth = StartGethNode(s => s.IsMiner());
2424
var contracts = Ci.StartCodexContracts(geth);
2525
var nodes = StartCodex(2, s => s.EnableMarketplace(geth, contracts, m => m
2626
.WithInitial(10.Eth(), 1000.TstWei())));

Tests/ExperimentalTests/PeerDiscoveryTests/PeerDiscoveryTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void MetricsDoesNotInterfereWithPeerDiscovery()
2929
[Test]
3030
public void MarketplaceDoesNotInterfereWithPeerDiscovery()
3131
{
32-
var geth = Ci.StartGethNode(s => s.IsMiner());
32+
var geth = StartGethNode(s => s.IsMiner());
3333
var contracts = Ci.StartCodexContracts(geth);
3434
var nodes = StartCodex(2, s => s.EnableMarketplace(geth, contracts, m => m
3535
.WithInitial(10.Eth(), 1000.TstWei())));

Tests/ExperimentalTests/UtilityTests/DiscordBotTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class DiscordBotTests : AutoBootstrapDistTest
3030
[Ignore("Used to debug testnet bots.")]
3131
public void BotRewardTest()
3232
{
33-
var geth = Ci.StartGethNode(s => s.IsMiner().WithName("disttest-geth"));
33+
var geth = StartGethNode(s => s.IsMiner().WithName("disttest-geth"));
3434
var contracts = Ci.StartCodexContracts(geth);
3535
var gethInfo = CreateGethInfo(geth, contracts);
3636

Tests/FrameworkTests/NethereumWorkflow/BlockTimeFinderTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using Logging;
33
using Moq;
44
using NethereumWorkflow;
5-
using NethereumWorkflow.BlockUtils;
65
using NUnit.Framework;
76

87
namespace FrameworkTests.NethereumWorkflow

0 commit comments

Comments
 (0)