2023-04-14 07:54:07 +00:00
|
|
|
|
using DistTestCore.Marketplace;
|
|
|
|
|
|
|
|
|
|
namespace DistTestCore
|
|
|
|
|
{
|
2023-04-18 11:45:48 +00:00
|
|
|
|
public class GethStarter : BaseStarter
|
2023-04-14 07:54:07 +00:00
|
|
|
|
{
|
2023-04-18 08:22:11 +00:00
|
|
|
|
private readonly MarketplaceNetworkCache marketplaceNetworkCache;
|
2023-04-14 08:51:35 +00:00
|
|
|
|
private readonly GethCompanionNodeStarter companionNodeStarter;
|
2023-04-14 07:54:07 +00:00
|
|
|
|
|
2023-08-10 08:58:18 +00:00
|
|
|
|
public GethStarter(TestLifecycle lifecycle)
|
|
|
|
|
: base(lifecycle)
|
2023-04-14 07:54:07 +00:00
|
|
|
|
{
|
2023-04-18 08:22:11 +00:00
|
|
|
|
marketplaceNetworkCache = new MarketplaceNetworkCache(
|
2023-08-10 08:58:18 +00:00
|
|
|
|
new GethBootstrapNodeStarter(lifecycle),
|
|
|
|
|
new CodexContractsStarter(lifecycle));
|
|
|
|
|
companionNodeStarter = new GethCompanionNodeStarter(lifecycle);
|
2023-04-14 07:54:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-14 08:51:35 +00:00
|
|
|
|
public GethStartResult BringOnlineMarketplaceFor(CodexSetup codexSetup)
|
2023-04-14 07:54:07 +00:00
|
|
|
|
{
|
2023-04-14 08:51:35 +00:00
|
|
|
|
if (codexSetup.MarketplaceConfig == null) return CreateMarketplaceUnavailableResult();
|
|
|
|
|
|
2023-04-18 08:22:11 +00:00
|
|
|
|
var marketplaceNetwork = marketplaceNetworkCache.Get();
|
2023-04-26 09:12:33 +00:00
|
|
|
|
var companionNode = StartCompanionNode(codexSetup, marketplaceNetwork);
|
2023-04-14 08:51:35 +00:00
|
|
|
|
|
2023-04-19 07:19:06 +00:00
|
|
|
|
LogStart("Setting up initial balance...");
|
2023-04-26 09:12:33 +00:00
|
|
|
|
TransferInitialBalance(marketplaceNetwork, codexSetup.MarketplaceConfig, companionNode);
|
2023-04-19 07:57:37 +00:00
|
|
|
|
LogEnd($"Initial balance of {codexSetup.MarketplaceConfig.InitialTestTokens} set for {codexSetup.NumberOfNodes} nodes.");
|
2023-04-14 10:37:05 +00:00
|
|
|
|
|
2023-04-26 09:12:33 +00:00
|
|
|
|
return CreateGethStartResult(marketplaceNetwork, companionNode);
|
2023-04-14 10:37:05 +00:00
|
|
|
|
}
|
2023-04-14 08:51:35 +00:00
|
|
|
|
|
2023-05-05 05:59:56 +00:00
|
|
|
|
public GethStartResult BringOnlineValidatorFor(CodexSetup codexSetup, GethStartResult previousResult)
|
|
|
|
|
{
|
|
|
|
|
// allow marketplace and validator to be enabled on the same Codex node
|
|
|
|
|
if (previousResult.CompanionNode != null || (codexSetup.EnableValidator ?? false) == false) return previousResult;
|
|
|
|
|
|
|
|
|
|
var marketplaceNetwork = marketplaceNetworkCache.Get();
|
|
|
|
|
var companionNode = StartCompanionNode(codexSetup, marketplaceNetwork);
|
|
|
|
|
|
|
|
|
|
return CreateGethStartResult(marketplaceNetwork, companionNode);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-26 09:12:33 +00:00
|
|
|
|
private void TransferInitialBalance(MarketplaceNetwork marketplaceNetwork, MarketplaceInitialConfig marketplaceConfig, GethCompanionNodeInfo companionNode)
|
2023-04-14 10:37:05 +00:00
|
|
|
|
{
|
2023-06-22 12:37:37 +00:00
|
|
|
|
if (marketplaceConfig.InitialTestTokens.Amount == 0) return;
|
|
|
|
|
|
2023-06-01 07:35:18 +00:00
|
|
|
|
var interaction = marketplaceNetwork.StartInteraction(lifecycle);
|
2023-04-18 13:33:12 +00:00
|
|
|
|
var tokenAddress = marketplaceNetwork.Marketplace.TokenAddress;
|
2023-04-18 11:45:48 +00:00
|
|
|
|
|
2023-05-03 08:21:15 +00:00
|
|
|
|
var accounts = companionNode.Accounts.Select(a => a.Account).ToArray();
|
|
|
|
|
interaction.MintTestTokens(accounts, marketplaceConfig.InitialTestTokens.Amount, tokenAddress);
|
2023-04-14 07:54:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-26 09:12:33 +00:00
|
|
|
|
private GethStartResult CreateGethStartResult(MarketplaceNetwork marketplaceNetwork, GethCompanionNodeInfo companionNode)
|
2023-04-14 07:54:07 +00:00
|
|
|
|
{
|
2023-04-26 09:12:33 +00:00
|
|
|
|
return new GethStartResult(CreateMarketplaceAccessFactory(marketplaceNetwork), marketplaceNetwork, companionNode);
|
2023-04-14 07:54:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-14 08:51:35 +00:00
|
|
|
|
private GethStartResult CreateMarketplaceUnavailableResult()
|
|
|
|
|
{
|
2023-04-26 09:12:33 +00:00
|
|
|
|
return new GethStartResult(new MarketplaceUnavailableAccessFactory(), null!, null!);
|
2023-04-14 08:51:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-18 08:22:11 +00:00
|
|
|
|
private IMarketplaceAccessFactory CreateMarketplaceAccessFactory(MarketplaceNetwork marketplaceNetwork)
|
2023-04-14 07:54:07 +00:00
|
|
|
|
{
|
2023-06-01 07:35:18 +00:00
|
|
|
|
return new GethMarketplaceAccessFactory(lifecycle, marketplaceNetwork);
|
2023-04-14 07:54:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-26 09:12:33 +00:00
|
|
|
|
private GethCompanionNodeInfo StartCompanionNode(CodexSetup codexSetup, MarketplaceNetwork marketplaceNetwork)
|
2023-04-14 10:37:05 +00:00
|
|
|
|
{
|
2023-04-26 09:12:33 +00:00
|
|
|
|
return companionNodeStarter.StartCompanionNodeFor(codexSetup, marketplaceNetwork);
|
2023-04-14 10:37:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-18 08:22:11 +00:00
|
|
|
|
public class MarketplaceNetworkCache
|
2023-04-14 10:37:05 +00:00
|
|
|
|
{
|
|
|
|
|
private readonly GethBootstrapNodeStarter bootstrapNodeStarter;
|
2023-04-18 08:22:11 +00:00
|
|
|
|
private readonly CodexContractsStarter codexContractsStarter;
|
|
|
|
|
private MarketplaceNetwork? network;
|
2023-04-14 10:37:05 +00:00
|
|
|
|
|
2023-04-18 08:22:11 +00:00
|
|
|
|
public MarketplaceNetworkCache(GethBootstrapNodeStarter bootstrapNodeStarter, CodexContractsStarter codexContractsStarter)
|
2023-04-14 08:51:35 +00:00
|
|
|
|
{
|
2023-04-14 10:37:05 +00:00
|
|
|
|
this.bootstrapNodeStarter = bootstrapNodeStarter;
|
2023-04-18 08:22:11 +00:00
|
|
|
|
this.codexContractsStarter = codexContractsStarter;
|
2023-04-14 08:51:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-18 08:22:11 +00:00
|
|
|
|
public MarketplaceNetwork Get()
|
2023-04-14 07:54:07 +00:00
|
|
|
|
{
|
2023-04-18 08:22:11 +00:00
|
|
|
|
if (network == null)
|
2023-04-14 10:37:05 +00:00
|
|
|
|
{
|
2023-04-18 08:22:11 +00:00
|
|
|
|
var bootstrapInfo = bootstrapNodeStarter.StartGethBootstrapNode();
|
2023-04-18 13:33:12 +00:00
|
|
|
|
var marketplaceInfo = codexContractsStarter.Start(bootstrapInfo);
|
2023-04-18 08:22:11 +00:00
|
|
|
|
network = new MarketplaceNetwork(bootstrapInfo, marketplaceInfo );
|
2023-04-14 10:37:05 +00:00
|
|
|
|
}
|
2023-04-18 08:22:11 +00:00
|
|
|
|
return network;
|
2023-04-14 07:54:07 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|