Better logging and much faster initial balance transactions

This commit is contained in:
benbierens 2023-04-19 09:19:06 +02:00
parent 48ca6f41fa
commit 7e6de4146e
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
6 changed files with 40 additions and 21 deletions

View File

@ -28,12 +28,12 @@ namespace DistTestCore
protected void Log(string msg) protected void Log(string msg)
{ {
lifecycle.Log.Log($"{GetClassName} {msg}"); lifecycle.Log.Log($"{GetClassName()} {msg}");
} }
private string GetClassName() private string GetClassName()
{ {
return GetType().Name; return $"({GetType().Name})";
} }
} }
} }

View File

@ -14,6 +14,7 @@ namespace DistTestCore
public ICodexNodeGroup BringOnline(CodexSetup codexSetup) public ICodexNodeGroup BringOnline(CodexSetup codexSetup)
{ {
LogSeparator();
LogStart($"Starting {codexSetup.Describe()}..."); LogStart($"Starting {codexSetup.Describe()}...");
var gethStartResult = lifecycle.GethStarter.BringOnlineMarketplaceFor(codexSetup); var gethStartResult = lifecycle.GethStarter.BringOnlineMarketplaceFor(codexSetup);
@ -28,7 +29,8 @@ namespace DistTestCore
var codexNodeFactory = new CodexNodeFactory(lifecycle, metricAccessFactory, gethStartResult.MarketplaceAccessFactory); var codexNodeFactory = new CodexNodeFactory(lifecycle, metricAccessFactory, gethStartResult.MarketplaceAccessFactory);
var group = CreateCodexGroup(codexSetup, containers, codexNodeFactory); 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; return group;
} }
@ -72,5 +74,10 @@ namespace DistTestCore
{ {
return workflowCreator.CreateWorkflow(); return workflowCreator.CreateWorkflow();
} }
private void LogSeparator()
{
Log("----------------------------------------------------------------------------");
}
} }
} }

View File

@ -24,7 +24,9 @@ namespace DistTestCore
var marketplaceNetwork = marketplaceNetworkCache.Get(); var marketplaceNetwork = marketplaceNetworkCache.Get();
var companionNodes = StartCompanionNodes(codexSetup, marketplaceNetwork); var companionNodes = StartCompanionNodes(codexSetup, marketplaceNetwork);
LogStart("Setting up initial balance...");
TransferInitialBalance(marketplaceNetwork, codexSetup.MarketplaceConfig, companionNodes); TransferInitialBalance(marketplaceNetwork, codexSetup.MarketplaceConfig, companionNodes);
LogEnd($"Initial balance of {codexSetup.MarketplaceConfig.InitialTestTokens.Amount} TestTokens set for {codexSetup.NumberOfNodes} nodes.");
return CreateGethStartResult(marketplaceNetwork, companionNodes); return CreateGethStartResult(marketplaceNetwork, companionNodes);
} }
@ -36,9 +38,11 @@ namespace DistTestCore
foreach (var node in companionNodes) 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.MintTestTokens(node.Account, marketplaceConfig.InitialTestTokens.Amount, tokenAddress);
} }
interaction.WaitForAllTransactions();
} }
private GethStartResult CreateGethStartResult(MarketplaceNetwork marketplaceNetwork, GethCompanionNodeInfo[] companionNodes) private GethStartResult CreateGethStartResult(MarketplaceNetwork marketplaceNetwork, GethCompanionNodeInfo[] companionNodes)

View File

@ -19,9 +19,11 @@ namespace DistTestCore.Marketplace
var containers = workflow.Start(codexSetup.NumberOfNodes, Location.Unspecified, new GethContainerRecipe(), startupConfig); 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."); 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) private GethCompanionNodeInfo CreateCompanionInfo(StartupWorkflow workflow, RunningContainer container)

View File

@ -8,6 +8,7 @@ namespace DistTestCore
{ {
public interface IOnlineCodexNode public interface IOnlineCodexNode
{ {
string GetName();
CodexDebugResponse GetDebugInfo(); CodexDebugResponse GetDebugInfo();
ContentId UploadFile(TestFile file); ContentId UploadFile(TestFile file);
TestFile? DownloadContent(ContentId contentId); TestFile? DownloadContent(ContentId contentId);

View File

@ -10,6 +10,7 @@ namespace NethereumWorkflow
{ {
public class NethereumInteraction public class NethereumInteraction
{ {
private readonly List<Task> openTasks = new List<Task>();
private readonly TestLog log; private readonly TestLog log;
private readonly Web3 web3; private readonly Web3 web3;
private readonly string rootAccount; private readonly string rootAccount;
@ -21,25 +22,21 @@ namespace NethereumWorkflow
this.rootAccount = rootAccount; 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) public string GetTokenAddress(string marketplaceAddress)
{ {
var function = new GetTokenFunction(); var function = new GetTokenFunction();
var handler = web3.Eth.GetContractQueryHandler<GetTokenFunction>(); var handler = web3.Eth.GetContractQueryHandler<GetTokenFunction>();
var result = Time.Wait(handler.QueryAsync<string>(marketplaceAddress, function)); return Time.Wait(handler.QueryAsync<string>(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) public void MintTestTokens(string account, decimal amount, string tokenAddress)
@ -53,7 +50,7 @@ namespace NethereumWorkflow
}; };
var handler = web3.Eth.GetContractTransactionHandler<MintTokensFunction>(); var handler = web3.Eth.GetContractTransactionHandler<MintTokensFunction>();
Time.Wait(handler.SendRequestAndWaitForReceiptAsync(tokenAddress, function)); openTasks.Add(handler.SendRequestAndWaitForReceiptAsync(tokenAddress, function));
} }
public decimal GetBalance(string tokenAddress, string account) public decimal GetBalance(string tokenAddress, string account)
@ -66,10 +63,18 @@ namespace NethereumWorkflow
var handler = web3.Eth.GetContractQueryHandler<GetTokenBalanceFunction>(); var handler = web3.Eth.GetContractQueryHandler<GetTokenBalanceFunction>();
var result = ToDecimal(Time.Wait(handler.QueryAsync<BigInteger>(tokenAddress, function))); var result = ToDecimal(Time.Wait(handler.QueryAsync<BigInteger>(tokenAddress, function)));
Log($"Balance of {account} is {result}"); Log($"Balance of {account} is {result} TestTokens.");
return result; return result;
} }
public void WaitForAllTransactions()
{
var tasks = openTasks.ToArray();
openTasks.Clear();
Task.WaitAll(tasks);
}
private HexBigInteger ToHexBig(decimal amount) private HexBigInteger ToHexBig(decimal amount)
{ {
var bigint = ToBig(amount); var bigint = ToBig(amount);