Moves ethAccount to Geth plugin. Enables setting ethAccount when Codex starts.
This commit is contained in:
parent
e8213b9515
commit
a53d2de13b
@ -7,8 +7,6 @@ namespace CodexPlugin
|
|||||||
{
|
{
|
||||||
public class CodexContainerRecipe : ContainerRecipeFactory
|
public class CodexContainerRecipe : ContainerRecipeFactory
|
||||||
{
|
{
|
||||||
private readonly MarketplaceStarter marketplaceStarter = new MarketplaceStarter();
|
|
||||||
|
|
||||||
private const string DefaultDockerImage = "codexstorage/nim-codex:sha-c219a5f-dist-tests";
|
private const string DefaultDockerImage = "codexstorage/nim-codex:sha-c219a5f-dist-tests";
|
||||||
public const string ApiPortTag = "codex_api_port";
|
public const string ApiPortTag = "codex_api_port";
|
||||||
public const string ListenPortTag = "codex_listen_port";
|
public const string ListenPortTag = "codex_listen_port";
|
||||||
@ -106,13 +104,13 @@ namespace CodexPlugin
|
|||||||
AddEnvVar("CODEX_ETH_PROVIDER", $"{wsAddress.Host.Replace("http://", "ws://")}:{wsAddress.Port}");
|
AddEnvVar("CODEX_ETH_PROVIDER", $"{wsAddress.Host.Replace("http://", "ws://")}:{wsAddress.Port}");
|
||||||
AddEnvVar("CODEX_MARKETPLACE_ADDRESS", marketplaceAddress);
|
AddEnvVar("CODEX_MARKETPLACE_ADDRESS", marketplaceAddress);
|
||||||
|
|
||||||
|
var marketplaceSetup = config.MarketplaceConfig.MarketplaceSetup;
|
||||||
|
|
||||||
// Custom scripting in the Codex test image will write this variable to a private-key file,
|
// Custom scripting in the Codex test image will write this variable to a private-key file,
|
||||||
// and pass the correct filename to Codex.
|
// and pass the correct filename to Codex.
|
||||||
var mStart = marketplaceStarter.Start();
|
AddEnvVar("PRIV_KEY", marketplaceSetup.EthAccount.PrivateKey);
|
||||||
AddEnvVar("PRIV_KEY", mStart.PrivateKey);
|
Additional(marketplaceSetup.EthAccount);
|
||||||
Additional(mStart);
|
|
||||||
|
|
||||||
var marketplaceSetup = config.MarketplaceConfig.MarketplaceSetup;
|
|
||||||
SetCommandOverride(marketplaceSetup);
|
SetCommandOverride(marketplaceSetup);
|
||||||
if (marketplaceSetup.IsValidator)
|
if (marketplaceSetup.IsValidator)
|
||||||
{
|
{
|
||||||
|
@ -35,9 +35,9 @@ namespace CodexPlugin
|
|||||||
|
|
||||||
private EthAddress? GetEthAddress(CodexAccess access)
|
private EthAddress? GetEthAddress(CodexAccess access)
|
||||||
{
|
{
|
||||||
var mStart = access.Container.Recipe.Additionals.Get<MarketplaceStartResults>();
|
var ethAccount = access.Container.Recipe.Additionals.Get<EthAccount>();
|
||||||
if (mStart == null) return null;
|
if (ethAccount == null) return null;
|
||||||
return mStart.EthAddress;
|
return ethAccount.EthAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CrashWatcher CreateCrashWatcher(RunningContainer c)
|
public CrashWatcher CreateCrashWatcher(RunningContainer c)
|
||||||
|
@ -52,8 +52,8 @@ namespace CodexPlugin
|
|||||||
var mconfig = codexSetup.MarketplaceConfig;
|
var mconfig = codexSetup.MarketplaceConfig;
|
||||||
foreach (var node in result)
|
foreach (var node in result)
|
||||||
{
|
{
|
||||||
mconfig.GethNode.SendEth(node, mconfig.InitialEth);
|
mconfig.GethNode.SendEth(node, mconfig.MarketplaceSetup.InitialEth);
|
||||||
mconfig.CodexContracts.MintTestTokens(node, mconfig.InitialTokens);
|
mconfig.CodexContracts.MintTestTokens(node, mconfig.MarketplaceSetup.InitialTestTokens);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,8 +17,7 @@ namespace CodexPlugin
|
|||||||
ICodexSetup WithBlockMaintenanceInterval(TimeSpan duration);
|
ICodexSetup WithBlockMaintenanceInterval(TimeSpan duration);
|
||||||
ICodexSetup WithBlockMaintenanceNumber(int numberOfBlocks);
|
ICodexSetup WithBlockMaintenanceNumber(int numberOfBlocks);
|
||||||
ICodexSetup EnableMetrics();
|
ICodexSetup EnableMetrics();
|
||||||
ICodexSetup EnableMarketplace(IGethNode gethNode, ICodexContracts codexContracts, Ether initialEth, TestToken initialTokens);
|
ICodexSetup EnableMarketplace(IGethNode gethNode, ICodexContracts codexContracts, Action<IMarketplaceSetup> marketplaceSetup);
|
||||||
ICodexSetup EnableMarketplace(IGethNode gethNode, ICodexContracts codexContracts, Ether initialEth, TestToken initialTokens, Action<IMarketplaceSetup> marketplaceSetup);
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides an invalid proof every N proofs
|
/// Provides an invalid proof every N proofs
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -28,6 +27,8 @@ namespace CodexPlugin
|
|||||||
|
|
||||||
public interface IMarketplaceSetup
|
public interface IMarketplaceSetup
|
||||||
{
|
{
|
||||||
|
IMarketplaceSetup WithInitial(Ether eth, TestToken tokens);
|
||||||
|
IMarketplaceSetup WithAccount(EthAccount account);
|
||||||
IMarketplaceSetup AsStorageNode();
|
IMarketplaceSetup AsStorageNode();
|
||||||
IMarketplaceSetup AsValidator();
|
IMarketplaceSetup AsValidator();
|
||||||
}
|
}
|
||||||
@ -122,17 +123,12 @@ namespace CodexPlugin
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICodexSetup EnableMarketplace(IGethNode gethNode, ICodexContracts codexContracts, Ether initialEth, TestToken initialTokens)
|
public ICodexSetup EnableMarketplace(IGethNode gethNode, ICodexContracts codexContracts, Action<IMarketplaceSetup> marketplaceSetup)
|
||||||
{
|
|
||||||
return EnableMarketplace(gethNode, codexContracts, initialEth, initialTokens, s => { });
|
|
||||||
}
|
|
||||||
|
|
||||||
public ICodexSetup EnableMarketplace(IGethNode gethNode, ICodexContracts codexContracts, Ether initialEth, TestToken initialTokens, Action<IMarketplaceSetup> marketplaceSetup)
|
|
||||||
{
|
{
|
||||||
var ms = new MarketplaceSetup();
|
var ms = new MarketplaceSetup();
|
||||||
marketplaceSetup(ms);
|
marketplaceSetup(ms);
|
||||||
|
|
||||||
MarketplaceConfig = new MarketplaceInitialConfig(ms, gethNode, codexContracts, initialEth, initialTokens);
|
MarketplaceConfig = new MarketplaceInitialConfig(ms, gethNode, codexContracts);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,6 +165,9 @@ namespace CodexPlugin
|
|||||||
{
|
{
|
||||||
public bool IsStorageNode { get; private set; }
|
public bool IsStorageNode { get; private set; }
|
||||||
public bool IsValidator { get; private set; }
|
public bool IsValidator { get; private set; }
|
||||||
|
public Ether InitialEth { get; private set; } = 0.Eth();
|
||||||
|
public TestToken InitialTestTokens { get; private set; } = 0.TestTokens();
|
||||||
|
public EthAccount EthAccount { get; private set; } = EthAccount.GenerateNew();
|
||||||
|
|
||||||
public IMarketplaceSetup AsStorageNode()
|
public IMarketplaceSetup AsStorageNode()
|
||||||
{
|
{
|
||||||
@ -182,14 +181,28 @@ namespace CodexPlugin
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IMarketplaceSetup WithAccount(EthAccount account)
|
||||||
|
{
|
||||||
|
EthAccount = account;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IMarketplaceSetup WithInitial(Ether eth, TestToken tokens)
|
||||||
|
{
|
||||||
|
InitialEth = eth;
|
||||||
|
InitialTestTokens = tokens;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
var result = "[(clientNode)"; // When marketplace is enabled, being a clientNode is implicit.
|
var result = "[(clientNode)"; // When marketplace is enabled, being a clientNode is implicit.
|
||||||
result += IsStorageNode ? "(storageNode)" : "()";
|
result += IsStorageNode ? "(storageNode)" : "()";
|
||||||
result += IsValidator ? "(validator)" : "()";
|
result += IsValidator ? "(validator)" : "() ";
|
||||||
result += "]";
|
result += $"Address: '{EthAccount.EthAddress}' ";
|
||||||
|
result += $"InitialEth/TT({InitialEth.Eth}/{InitialTestTokens.Amount})";
|
||||||
|
result += "] ";
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,19 +5,15 @@ namespace CodexPlugin
|
|||||||
{
|
{
|
||||||
public class MarketplaceInitialConfig
|
public class MarketplaceInitialConfig
|
||||||
{
|
{
|
||||||
public MarketplaceInitialConfig(MarketplaceSetup marketplaceSetup, IGethNode gethNode, ICodexContracts codexContracts, Ether initialEth, TestToken initialTokens)
|
public MarketplaceInitialConfig(MarketplaceSetup marketplaceSetup, IGethNode gethNode, ICodexContracts codexContracts)
|
||||||
{
|
{
|
||||||
MarketplaceSetup = marketplaceSetup;
|
MarketplaceSetup = marketplaceSetup;
|
||||||
GethNode = gethNode;
|
GethNode = gethNode;
|
||||||
CodexContracts = codexContracts;
|
CodexContracts = codexContracts;
|
||||||
InitialEth = initialEth;
|
|
||||||
InitialTokens = initialTokens;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MarketplaceSetup MarketplaceSetup { get; }
|
public MarketplaceSetup MarketplaceSetup { get; }
|
||||||
public IGethNode GethNode { get; }
|
public IGethNode GethNode { get; }
|
||||||
public ICodexContracts CodexContracts { get; }
|
public ICodexContracts CodexContracts { get; }
|
||||||
public Ether InitialEth { get; }
|
|
||||||
public TestToken InitialTokens { get; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
using GethPlugin;
|
|
||||||
|
|
||||||
namespace CodexPlugin
|
|
||||||
{
|
|
||||||
[Serializable]
|
|
||||||
public class MarketplaceStartResults
|
|
||||||
{
|
|
||||||
public MarketplaceStartResults(EthAddress ethAddress, string privateKey)
|
|
||||||
{
|
|
||||||
EthAddress = ethAddress;
|
|
||||||
PrivateKey = privateKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EthAddress EthAddress { get; }
|
|
||||||
public string PrivateKey { get; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
using GethPlugin;
|
|
||||||
using Nethereum.Hex.HexConvertors.Extensions;
|
|
||||||
using Nethereum.Web3.Accounts;
|
|
||||||
|
|
||||||
namespace CodexPlugin
|
|
||||||
{
|
|
||||||
public class MarketplaceStarter
|
|
||||||
{
|
|
||||||
public MarketplaceStartResults Start()
|
|
||||||
{
|
|
||||||
var ecKey = Nethereum.Signer.EthECKey.GenerateKey();
|
|
||||||
var privateKey = ecKey.GetPrivateKeyAsBytes().ToHex();
|
|
||||||
var account = new Account(privateKey);
|
|
||||||
var ethAddress = new EthAddress(account.Address);
|
|
||||||
|
|
||||||
return new MarketplaceStartResults(ethAddress, account.PrivateKey);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
28
ProjectPlugins/GethPlugin/EthAccount.cs
Normal file
28
ProjectPlugins/GethPlugin/EthAccount.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using Nethereum.Hex.HexConvertors.Extensions;
|
||||||
|
using Nethereum.Web3.Accounts;
|
||||||
|
|
||||||
|
namespace GethPlugin
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
public class EthAccount
|
||||||
|
{
|
||||||
|
public EthAccount(EthAddress ethAddress, string privateKey)
|
||||||
|
{
|
||||||
|
EthAddress = ethAddress;
|
||||||
|
PrivateKey = privateKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EthAddress EthAddress { get; }
|
||||||
|
public string PrivateKey { get; }
|
||||||
|
|
||||||
|
public static EthAccount GenerateNew()
|
||||||
|
{
|
||||||
|
var ecKey = Nethereum.Signer.EthECKey.GenerateKey();
|
||||||
|
var privateKey = ecKey.GetPrivateKeyAsBytes().ToHex();
|
||||||
|
var account = new Account(privateKey);
|
||||||
|
var ethAddress = new EthAddress(account.Address);
|
||||||
|
|
||||||
|
return new EthAccount(ethAddress, account.PrivateKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -5,6 +5,7 @@
|
|||||||
EthAddress EthAddress { get; }
|
EthAddress EthAddress { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
public class EthAddress
|
public class EthAddress
|
||||||
{
|
{
|
||||||
public EthAddress(string address)
|
public EthAddress(string address)
|
||||||
|
@ -21,7 +21,8 @@ namespace CodexTests.BasicTests
|
|||||||
|
|
||||||
var group = AddCodex(5, o => o
|
var group = AddCodex(5, o => o
|
||||||
.EnableMetrics()
|
.EnableMetrics()
|
||||||
.EnableMarketplace(geth, contract, 10.Eth(), 100000.TestTokens(), s => s
|
.EnableMarketplace(geth, contract, s => s
|
||||||
|
.WithInitial(10.Eth(), 100000.TestTokens())
|
||||||
.AsStorageNode()
|
.AsStorageNode()
|
||||||
.AsValidator())
|
.AsValidator())
|
||||||
.WithBlockTTL(TimeSpan.FromMinutes(5))
|
.WithBlockTTL(TimeSpan.FromMinutes(5))
|
||||||
|
@ -64,7 +64,8 @@ namespace CodexTests.BasicTests
|
|||||||
.WithName("Seller")
|
.WithName("Seller")
|
||||||
.WithLogLevel(CodexLogLevel.Trace, new CodexLogCustomTopics(CodexLogLevel.Error, CodexLogLevel.Error, CodexLogLevel.Warn))
|
.WithLogLevel(CodexLogLevel.Trace, new CodexLogCustomTopics(CodexLogLevel.Error, CodexLogLevel.Error, CodexLogLevel.Warn))
|
||||||
.WithStorageQuota(11.GB())
|
.WithStorageQuota(11.GB())
|
||||||
.EnableMarketplace(geth, contracts, initialEth: 10.Eth(), initialTokens: sellerInitialBalance, s => s
|
.EnableMarketplace(geth, contracts, m => m
|
||||||
|
.WithInitial(10.Eth(), sellerInitialBalance)
|
||||||
.AsStorageNode()
|
.AsStorageNode()
|
||||||
.AsValidator()));
|
.AsValidator()));
|
||||||
|
|
||||||
@ -81,9 +82,10 @@ namespace CodexTests.BasicTests
|
|||||||
var testFile = GenerateTestFile(fileSize);
|
var testFile = GenerateTestFile(fileSize);
|
||||||
|
|
||||||
var buyer = AddCodex(s => s
|
var buyer = AddCodex(s => s
|
||||||
.WithName("Buyer")
|
.WithName("Buyer")
|
||||||
.WithBootstrapNode(seller)
|
.WithBootstrapNode(seller)
|
||||||
.EnableMarketplace(geth, contracts, initialEth: 10.Eth(), initialTokens: buyerInitialBalance));
|
.EnableMarketplace(geth, contracts, m => m
|
||||||
|
.WithInitial(10.Eth(), buyerInitialBalance)));
|
||||||
|
|
||||||
AssertBalance(contracts, buyer, Is.EqualTo(buyerInitialBalance));
|
AssertBalance(contracts, buyer, Is.EqualTo(buyerInitialBalance));
|
||||||
|
|
||||||
|
@ -21,7 +21,8 @@ namespace CodexTests.DownloadConnectivityTests
|
|||||||
{
|
{
|
||||||
var geth = Ci.StartGethNode(s => s.IsMiner());
|
var geth = Ci.StartGethNode(s => s.IsMiner());
|
||||||
var contracts = Ci.StartCodexContracts(geth);
|
var contracts = Ci.StartCodexContracts(geth);
|
||||||
AddCodex(2, s => s.EnableMarketplace(geth, contracts, 10.Eth(), 1000.TestTokens()));
|
AddCodex(2, s => s.EnableMarketplace(geth, contracts, m => m
|
||||||
|
.WithInitial(10.Eth(), 1000.TestTokens())));
|
||||||
|
|
||||||
AssertAllNodesConnected();
|
AssertAllNodesConnected();
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,8 @@ namespace CodexTests.PeerDiscoveryTests
|
|||||||
{
|
{
|
||||||
var geth = Ci.StartGethNode(s => s.IsMiner());
|
var geth = Ci.StartGethNode(s => s.IsMiner());
|
||||||
var contracts = Ci.StartCodexContracts(geth);
|
var contracts = Ci.StartCodexContracts(geth);
|
||||||
AddCodex(2, s => s.EnableMarketplace(geth, contracts, 10.Eth(), 1000.TestTokens()));
|
AddCodex(2, s => s.EnableMarketplace(geth, contracts, m => m
|
||||||
|
.WithInitial(10.Eth(), 1000.TestTokens())));
|
||||||
|
|
||||||
AssertAllNodesConnected();
|
AssertAllNodesConnected();
|
||||||
}
|
}
|
||||||
|
@ -41,10 +41,11 @@ namespace CodexNetDeployer
|
|||||||
|
|
||||||
if (config.ShouldMakeStorageAvailable)
|
if (config.ShouldMakeStorageAvailable)
|
||||||
{
|
{
|
||||||
s.EnableMarketplace(gethNode, contracts, 100.Eth(), config.InitialTestTokens.TestTokens(), s =>
|
s.EnableMarketplace(gethNode, contracts, m =>
|
||||||
{
|
{
|
||||||
if (validatorsLeft > 0) s.AsValidator();
|
m.WithInitial(100.Eth(), config.InitialTestTokens.TestTokens());
|
||||||
if (config.ShouldMakeStorageAvailable) s.AsStorageNode();
|
if (validatorsLeft > 0) m.AsValidator();
|
||||||
|
if (config.ShouldMakeStorageAvailable) m.AsStorageNode();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user