connects blockCaches from test lifecycle

This commit is contained in:
Ben 2024-12-17 16:06:06 +01:00
parent 459cb2e981
commit 70622cf923
No known key found for this signature in database
GPG Key ID: 0F16E812E736C24B
23 changed files with 85 additions and 46 deletions

View File

@ -1,4 +1,5 @@
using CodexContractsPlugin;
using BlockchainUtils;
using CodexContractsPlugin;
using CodexContractsPlugin.Marketplace;
using GethPlugin;
using Logging;
@ -19,7 +20,7 @@ namespace GethConnector
return null;
}
var gethNode = new CustomGethNode(log, GethInput.GethHost, GethInput.GethPort, GethInput.PrivateKey);
var gethNode = new CustomGethNode(log, new BlockCache(), GethInput.GethHost, GethInput.GethPort, GethInput.PrivateKey);
var config = GetCodexMarketplaceConfig(gethNode, GethInput.MarketplaceAddress);

View File

@ -10,15 +10,16 @@ namespace NethereumWorkflow
{
public class NethereumInteraction
{
private readonly static BlockCache blockCache = new BlockCache(); // WRONG: parallel environments!
private readonly BlockCache blockCache;
private readonly ILog log;
private readonly Web3 web3;
internal NethereumInteraction(ILog log, Web3 web3)
internal NethereumInteraction(ILog log, Web3 web3, BlockCache blockCache)
{
this.log = log;
this.web3 = web3;
this.blockCache = blockCache;
}
public string SendEth(string toAddress, decimal ethAmount)

View File

@ -1,4 +1,5 @@
using Logging;
using BlockchainUtils;
using Logging;
using Nethereum.Web3;
namespace NethereumWorkflow
@ -6,13 +7,15 @@ namespace NethereumWorkflow
public class NethereumInteractionCreator
{
private readonly ILog log;
private readonly BlockCache blockCache;
private readonly string ip;
private readonly int port;
private readonly string privateKey;
public NethereumInteractionCreator(ILog log, string ip, int port, string privateKey)
public NethereumInteractionCreator(ILog log, BlockCache blockCache, string ip, int port, string privateKey)
{
this.log = log;
this.blockCache = blockCache;
this.ip = ip;
this.port = port;
this.privateKey = privateKey;
@ -21,7 +24,7 @@ namespace NethereumWorkflow
public NethereumInteraction CreateWorkflow()
{
log.Debug("Starting interaction to " + ip + ":" + port);
return new NethereumInteraction(log, CreateWeb3());
return new NethereumInteraction(log, CreateWeb3(), blockCache);
}
private Web3 CreateWeb3()

View File

@ -1,7 +1,7 @@
using CodexContractsPlugin.Marketplace;
using BlockchainUtils;
using CodexContractsPlugin.Marketplace;
using GethPlugin;
using Logging;
using NethereumWorkflow.BlockUtils;
using System.Numerics;
using Utils;

View File

@ -1,4 +1,5 @@
using CodexContractsPlugin.Marketplace;
using BlockchainUtils;
using CodexContractsPlugin.Marketplace;
using GethPlugin;
using Logging;
using Nethereum.ABI;

View File

@ -1,9 +1,9 @@
using CodexContractsPlugin.Marketplace;
using BlockchainUtils;
using CodexContractsPlugin.Marketplace;
using GethPlugin;
using Logging;
using Nethereum.Contracts;
using Nethereum.Hex.HexTypes;
using NethereumWorkflow.BlockUtils;
using Utils;
namespace CodexContractsPlugin

View File

@ -1,4 +1,5 @@
using CodexContractsPlugin.Marketplace;
using BlockchainUtils;
using CodexContractsPlugin.Marketplace;
using GethPlugin;
using Logging;
using Nethereum.ABI.FunctionEncoding.Attributes;

View File

@ -1,6 +1,6 @@
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
using BlockchainUtils;
using GethPlugin;
using NethereumWorkflow.BlockUtils;
using Newtonsoft.Json;
namespace CodexContractsPlugin.Marketplace

View File

@ -1,4 +1,5 @@
using Core;
using BlockchainUtils;
using Core;
namespace GethPlugin
{
@ -9,15 +10,15 @@ namespace GethPlugin
return Plugin(ci).DeployGeth(setup);
}
public static IGethNode WrapGethDeployment(this CoreInterface ci, GethDeployment deployment)
public static IGethNode WrapGethDeployment(this CoreInterface ci, GethDeployment deployment, BlockCache blockCache)
{
return Plugin(ci).WrapGethDeployment(deployment);
return Plugin(ci).WrapGethDeployment(deployment, blockCache);
}
public static IGethNode StartGethNode(this CoreInterface ci, Action<IGethSetup> setup)
public static IGethNode StartGethNode(this CoreInterface ci, BlockCache blockCache, Action<IGethSetup> setup)
{
var deploy = DeployGeth(ci, setup);
return WrapGethDeployment(ci, deploy);
return WrapGethDeployment(ci, deploy, blockCache);
}
private static GethPlugin Plugin(CoreInterface ci)

View File

@ -1,11 +1,11 @@
using Core;
using BlockchainUtils;
using Core;
using KubernetesWorkflow.Types;
using Logging;
using Nethereum.ABI.FunctionEncoding.Attributes;
using Nethereum.Contracts;
using Nethereum.RPC.Eth.DTOs;
using NethereumWorkflow;
using NethereumWorkflow.BlockUtils;
using Utils;
namespace GethPlugin
@ -34,10 +34,12 @@ namespace GethPlugin
public class DeploymentGethNode : BaseGethNode, IGethNode
{
private readonly ILog log;
private readonly BlockCache blockCache;
public DeploymentGethNode(ILog log, GethDeployment startResult)
public DeploymentGethNode(ILog log, BlockCache blockCache, GethDeployment startResult)
{
this.log = log;
this.blockCache = blockCache;
StartResult = startResult;
}
@ -60,7 +62,7 @@ namespace GethPlugin
var address = StartResult.Container.GetAddress(GethContainerRecipe.HttpPortTag);
var account = StartResult.Account;
var creator = new NethereumInteractionCreator(log, address.Host, address.Port, account.PrivateKey);
var creator = new NethereumInteractionCreator(log, blockCache, address.Host, address.Port, account.PrivateKey);
return creator.CreateWorkflow();
}
}
@ -68,6 +70,7 @@ namespace GethPlugin
public class CustomGethNode : BaseGethNode, IGethNode
{
private readonly ILog log;
private readonly BlockCache blockCache;
private readonly string gethHost;
private readonly int gethPort;
private readonly string privateKey;
@ -75,9 +78,10 @@ namespace GethPlugin
public GethDeployment StartResult => throw new NotImplementedException();
public RunningContainer Container => throw new NotImplementedException();
public CustomGethNode(ILog log, string gethHost, int gethPort, string privateKey)
public CustomGethNode(ILog log, BlockCache blockCache, string gethHost, int gethPort, string privateKey)
{
this.log = log;
this.blockCache = blockCache;
this.gethHost = gethHost;
this.gethPort = gethPort;
this.privateKey = privateKey;
@ -90,7 +94,7 @@ namespace GethPlugin
protected override NethereumInteraction StartInteraction()
{
var creator = new NethereumInteractionCreator(log, gethHost, gethPort, privateKey);
var creator = new NethereumInteractionCreator(log, blockCache, gethHost, gethPort, privateKey);
return creator.CreateWorkflow();
}
}

View File

@ -1,4 +1,5 @@
using Core;
using BlockchainUtils;
using Core;
namespace GethPlugin
{
@ -36,10 +37,10 @@ namespace GethPlugin
return starter.StartGeth(startupConfig);
}
public IGethNode WrapGethDeployment(GethDeployment startResult)
public IGethNode WrapGethDeployment(GethDeployment startResult, BlockCache blockCache)
{
startResult = SerializeGate.Gate(startResult);
return starter.WrapGethContainer(startResult);
return starter.WrapGethContainer(startResult, blockCache);
}
}
}

View File

@ -1,4 +1,5 @@
using Core;
using BlockchainUtils;
using Core;
using KubernetesWorkflow;
namespace GethPlugin
@ -41,10 +42,10 @@ namespace GethPlugin
return new GethDeployment(containers, discoveryPort, httpPort, wsPort, account, pubKey);
}
public IGethNode WrapGethContainer(GethDeployment startResult)
public IGethNode WrapGethContainer(GethDeployment startResult, BlockCache blockCache)
{
startResult = SerializeGate.Gate(startResult);
return new DeploymentGethNode(tools.GetLog(), startResult);
return new DeploymentGethNode(tools.GetLog(), blockCache, startResult);
}
private void Log(string msg)

View File

@ -21,8 +21,11 @@ namespace CodexReleaseTests.MarketTests
private readonly TestToken pricePerSlotPerSecond = 10.TstWei();
[Test]
[Ignore("TODO - Test in which hosts are punished for failing a contract")]
public void ContractFailed()
[Combinatorial]
public void ContractFailed(
[Values(0, 1, 2, 3)] int a,
[Values(0, 1, 2, 3)] int b
)
{
var hosts = StartHosts();
var client = StartClients().Single();

View File

@ -18,7 +18,11 @@ namespace CodexReleaseTests.MarketTests
private readonly TestToken pricePerSlotPerSecond = 10.TstWei();
[Test]
public void ContractSuccessful()
[Combinatorial]
public void ContractSuccessful(
[Values(0, 1, 2, 3)] int a,
[Values(0, 1, 2, 3)] int b
)
{
var hosts = StartHosts();
var client = StartClients().Single();

View File

@ -19,7 +19,7 @@ namespace CodexReleaseTests.MarketTests
protected override void LifecycleStart(TestLifecycle lifecycle)
{
base.LifecycleStart(lifecycle);
var geth = Ci.StartGethNode(s => s.IsMiner());
var geth = StartGethNode(s => s.IsMiner());
var contracts = Ci.StartCodexContracts(geth);
handles.Add(lifecycle, new MarketplaceHandle(geth, contracts));
}

View File

@ -53,9 +53,9 @@ namespace CodexTests.BasicTests
[Test]
public void GethBootstrapTest()
{
var boot = Ci.StartGethNode(s => s.WithName("boot").IsMiner());
var disconnected = Ci.StartGethNode(s => s.WithName("disconnected"));
var follow = Ci.StartGethNode(s => s.WithBootstrapNode(boot).WithName("follow"));
var boot = StartGethNode(s => s.WithName("boot").IsMiner());
var disconnected = StartGethNode(s => s.WithName("disconnected"));
var follow = StartGethNode(s => s.WithBootstrapNode(boot).WithName("follow"));
Thread.Sleep(12000);

View File

@ -28,7 +28,7 @@ namespace CodexTests.BasicTests
plusSizeBytes
);
var geth = Ci.StartGethNode(s => s.IsMiner().WithName("disttest-geth"));
var geth = StartGethNode(s => s.IsMiner().WithName("disttest-geth"));
var contracts = Ci.StartCodexContracts(geth);
var numberOfHosts = 5;

View File

@ -1,4 +1,5 @@
using CodexContractsPlugin;
using BlockchainUtils;
using CodexContractsPlugin;
using CodexNetDeployer;
using CodexPlugin;
using CodexPlugin.OverwatchSupport;
@ -7,6 +8,7 @@ using Core;
using DistTestCore;
using DistTestCore.Helpers;
using DistTestCore.Logs;
using GethPlugin;
using Logging;
using MetricsPlugin;
using Newtonsoft.Json;
@ -19,6 +21,7 @@ namespace CodexTests
public class CodexDistTest : DistTest
{
private static readonly Dictionary<TestLifecycle, CodexTranscriptWriter> writers = new Dictionary<TestLifecycle, CodexTranscriptWriter>();
private static readonly Dictionary<TestLifecycle, BlockCache> blockCaches = new Dictionary<TestLifecycle, BlockCache>();
public CodexDistTest()
{
@ -73,6 +76,11 @@ namespace CodexTests
return group;
}
public IGethNode StartGethNode(Action<IGethSetup> setup)
{
return Ci.StartGethNode(GetBlockCache(), setup);
}
public PeerConnectionTestHelpers CreatePeerConnectionTestHelpers()
{
return new PeerConnectionTestHelpers(GetTestLog());
@ -223,6 +231,16 @@ namespace CodexTests
if (!outputFile.EndsWith(".owts")) outputFile += ".owts";
return outputFile;
}
private BlockCache GetBlockCache()
{
var lifecycle = Get();
if (!blockCaches.ContainsKey(lifecycle))
{
blockCaches[lifecycle] = new BlockCache();
}
return blockCaches[lifecycle];
}
}
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]

View File

@ -20,7 +20,7 @@ namespace CodexTests.DownloadConnectivityTests
[Test]
public void MarketplaceDoesNotInterfereWithPeerDownload()
{
var geth = Ci.StartGethNode(s => s.IsMiner());
var geth = StartGethNode(s => s.IsMiner());
var contracts = Ci.StartCodexContracts(geth);
var nodes = StartCodex(2, s => s.EnableMarketplace(geth, contracts, m => m
.WithInitial(10.Eth(), 1000.TstWei())));

View File

@ -29,7 +29,7 @@ namespace CodexTests.PeerDiscoveryTests
[Test]
public void MarketplaceDoesNotInterfereWithPeerDiscovery()
{
var geth = Ci.StartGethNode(s => s.IsMiner());
var geth = StartGethNode(s => s.IsMiner());
var contracts = Ci.StartCodexContracts(geth);
var nodes = StartCodex(2, s => s.EnableMarketplace(geth, contracts, m => m
.WithInitial(10.Eth(), 1000.TstWei())));

View File

@ -30,7 +30,7 @@ namespace CodexTests.UtilityTests
[Ignore("Used to debug testnet bots.")]
public void BotRewardTest()
{
var geth = Ci.StartGethNode(s => s.IsMiner().WithName("disttest-geth"));
var geth = StartGethNode(s => s.IsMiner().WithName("disttest-geth"));
var contracts = Ci.StartCodexContracts(geth);
var gethInfo = CreateGethInfo(geth, contracts);

View File

@ -2,7 +2,6 @@
using Logging;
using Moq;
using NethereumWorkflow;
using NethereumWorkflow.BlockUtils;
using NUnit.Framework;
namespace FrameworkTests.NethereumWorkflow

View File

@ -1,4 +1,5 @@
using CodexContractsPlugin;
using BlockchainUtils;
using CodexContractsPlugin;
using CodexDiscordBotPlugin;
using CodexPlugin;
using Core;
@ -59,7 +60,7 @@ namespace CodexNetDeployer
Log("Deploying Geth instance...");
var gethDeployment = DeployGeth(ci);
var gethNode = ci.WrapGethDeployment(gethDeployment);
var gethNode = ci.WrapGethDeployment(gethDeployment, new BlockCache());
Log("Geth started. Deploying Codex contracts...");
var contractsDeployment = ci.DeployCodexContracts(gethNode);