diff --git a/DistTestCore/BaseStarter.cs b/DistTestCore/BaseStarter.cs index e4f7fde..7d259e7 100644 --- a/DistTestCore/BaseStarter.cs +++ b/DistTestCore/BaseStarter.cs @@ -28,12 +28,12 @@ namespace DistTestCore protected void Log(string msg) { - lifecycle.Log.Log($"{GetClassName} {msg}"); + lifecycle.Log.Log($"{GetClassName()} {msg}"); } private string GetClassName() { - return GetType().Name; + return $"({GetType().Name})"; } } } diff --git a/DistTestCore/CodexStarter.cs b/DistTestCore/CodexStarter.cs index 54342c7..84da9b9 100644 --- a/DistTestCore/CodexStarter.cs +++ b/DistTestCore/CodexStarter.cs @@ -14,6 +14,7 @@ namespace DistTestCore public ICodexNodeGroup BringOnline(CodexSetup codexSetup) { + LogSeparator(); LogStart($"Starting {codexSetup.Describe()}..."); var gethStartResult = lifecycle.GethStarter.BringOnlineMarketplaceFor(codexSetup); @@ -28,7 +29,8 @@ namespace DistTestCore var codexNodeFactory = new CodexNodeFactory(lifecycle, metricAccessFactory, gethStartResult.MarketplaceAccessFactory); var group = CreateCodexGroup(codexSetup, containers, codexNodeFactory); - LogEnd($"Started at '{group.Containers.RunningPod.Ip}'"); + LogEnd($"Started {codexSetup.NumberOfNodes} nodes at '{group.Containers.RunningPod.Ip}'. They are: [{string.Join(",", group.Select(n => n.GetName()))}]"); + LogSeparator(); return group; } @@ -72,5 +74,10 @@ namespace DistTestCore { return workflowCreator.CreateWorkflow(); } + + private void LogSeparator() + { + Log("----------------------------------------------------------------------------"); + } } } diff --git a/DistTestCore/GethStarter.cs b/DistTestCore/GethStarter.cs index 2b2cbb3..e4b5b37 100644 --- a/DistTestCore/GethStarter.cs +++ b/DistTestCore/GethStarter.cs @@ -24,7 +24,9 @@ namespace DistTestCore var marketplaceNetwork = marketplaceNetworkCache.Get(); var companionNodes = StartCompanionNodes(codexSetup, marketplaceNetwork); + LogStart("Setting up initial balance..."); TransferInitialBalance(marketplaceNetwork, codexSetup.MarketplaceConfig, companionNodes); + LogEnd($"Initial balance of {codexSetup.MarketplaceConfig.InitialTestTokens.Amount} TestTokens set for {codexSetup.NumberOfNodes} nodes."); return CreateGethStartResult(marketplaceNetwork, companionNodes); } @@ -36,9 +38,11 @@ namespace DistTestCore foreach (var node in companionNodes) { - interaction.TransferTo(node.Account, marketplaceConfig.InitialEth.Wei); + interaction.TransferWeiTo(node.Account, marketplaceConfig.InitialEth.Wei); interaction.MintTestTokens(node.Account, marketplaceConfig.InitialTestTokens.Amount, tokenAddress); } + + interaction.WaitForAllTransactions(); } private GethStartResult CreateGethStartResult(MarketplaceNetwork marketplaceNetwork, GethCompanionNodeInfo[] companionNodes) diff --git a/DistTestCore/Marketplace/GethCompanionNodeStarter.cs b/DistTestCore/Marketplace/GethCompanionNodeStarter.cs index e9cd37b..047af28 100644 --- a/DistTestCore/Marketplace/GethCompanionNodeStarter.cs +++ b/DistTestCore/Marketplace/GethCompanionNodeStarter.cs @@ -19,9 +19,11 @@ namespace DistTestCore.Marketplace var containers = workflow.Start(codexSetup.NumberOfNodes, Location.Unspecified, new GethContainerRecipe(), startupConfig); if (containers.Containers.Length != codexSetup.NumberOfNodes) throw new InvalidOperationException("Expected a Geth companion node to be created for each Codex node. Test infra failure."); - LogEnd("Initialized companion nodes."); + var result = containers.Containers.Select(c => CreateCompanionInfo(workflow, c)).ToArray(); - return containers.Containers.Select(c => CreateCompanionInfo(workflow, c)).ToArray(); + LogEnd($"Initialized {codexSetup.NumberOfNodes} companion nodes. Their accounts: [{string.Join(",", result.Select(c => c.Account))}]"); + + return result; } private GethCompanionNodeInfo CreateCompanionInfo(StartupWorkflow workflow, RunningContainer container) diff --git a/DistTestCore/OnlineCodexNode.cs b/DistTestCore/OnlineCodexNode.cs index a12de9f..0750ee3 100644 --- a/DistTestCore/OnlineCodexNode.cs +++ b/DistTestCore/OnlineCodexNode.cs @@ -8,6 +8,7 @@ namespace DistTestCore { public interface IOnlineCodexNode { + string GetName(); CodexDebugResponse GetDebugInfo(); ContentId UploadFile(TestFile file); TestFile? DownloadContent(ContentId contentId); diff --git a/Nethereum/NethereumInteraction.cs b/Nethereum/NethereumInteraction.cs index 0388bd0..adce008 100644 --- a/Nethereum/NethereumInteraction.cs +++ b/Nethereum/NethereumInteraction.cs @@ -10,6 +10,7 @@ namespace NethereumWorkflow { public class NethereumInteraction { + private readonly List openTasks = new List(); private readonly TestLog log; private readonly Web3 web3; private readonly string rootAccount; @@ -21,25 +22,21 @@ namespace NethereumWorkflow this.rootAccount = rootAccount; } - public void TransferTo(string account, decimal amount) - { - if (amount < 1 || string.IsNullOrEmpty(account)) throw new ArgumentException("Invalid arguments for AddToBalance"); - - var value = ToHexBig(amount); - var transactionId = Time.Wait(web3.Eth.TransactionManager.SendTransactionAsync(rootAccount, account, value)); - Time.Wait(web3.Eth.TransactionManager.TransactionReceiptService.PollForReceiptAsync(transactionId)); - - Log($"Transferred {amount} to {account}"); - } - public string GetTokenAddress(string marketplaceAddress) { var function = new GetTokenFunction(); var handler = web3.Eth.GetContractQueryHandler(); - var result = Time.Wait(handler.QueryAsync(marketplaceAddress, function)); + return Time.Wait(handler.QueryAsync(marketplaceAddress, function)); + } - return result; + public void TransferWeiTo(string account, decimal amount) + { + if (amount < 1 || string.IsNullOrEmpty(account)) throw new ArgumentException("Invalid arguments for AddToBalance"); + + var value = ToHexBig(amount); + var transactionId = Time.Wait(web3.Eth.TransactionManager.SendTransactionAsync(rootAccount, account, value)); + openTasks.Add(web3.Eth.TransactionManager.TransactionReceiptService.PollForReceiptAsync(transactionId)); } public void MintTestTokens(string account, decimal amount, string tokenAddress) @@ -53,7 +50,7 @@ namespace NethereumWorkflow }; var handler = web3.Eth.GetContractTransactionHandler(); - Time.Wait(handler.SendRequestAndWaitForReceiptAsync(tokenAddress, function)); + openTasks.Add(handler.SendRequestAndWaitForReceiptAsync(tokenAddress, function)); } public decimal GetBalance(string tokenAddress, string account) @@ -66,10 +63,18 @@ namespace NethereumWorkflow var handler = web3.Eth.GetContractQueryHandler(); var result = ToDecimal(Time.Wait(handler.QueryAsync(tokenAddress, function))); - Log($"Balance of {account} is {result}"); + Log($"Balance of {account} is {result} TestTokens."); return result; } + public void WaitForAllTransactions() + { + var tasks = openTasks.ToArray(); + openTasks.Clear(); + + Task.WaitAll(tasks); + } + private HexBigInteger ToHexBig(decimal amount) { var bigint = ToBig(amount);