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
|
||||
{
|
||||
private readonly MarketplaceStarter marketplaceStarter = new MarketplaceStarter();
|
||||
|
||||
private const string DefaultDockerImage = "codexstorage/nim-codex:sha-c219a5f-dist-tests";
|
||||
public const string ApiPortTag = "codex_api_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_MARKETPLACE_ADDRESS", marketplaceAddress);
|
||||
|
||||
var marketplaceSetup = config.MarketplaceConfig.MarketplaceSetup;
|
||||
|
||||
// Custom scripting in the Codex test image will write this variable to a private-key file,
|
||||
// and pass the correct filename to Codex.
|
||||
var mStart = marketplaceStarter.Start();
|
||||
AddEnvVar("PRIV_KEY", mStart.PrivateKey);
|
||||
Additional(mStart);
|
||||
AddEnvVar("PRIV_KEY", marketplaceSetup.EthAccount.PrivateKey);
|
||||
Additional(marketplaceSetup.EthAccount);
|
||||
|
||||
var marketplaceSetup = config.MarketplaceConfig.MarketplaceSetup;
|
||||
SetCommandOverride(marketplaceSetup);
|
||||
if (marketplaceSetup.IsValidator)
|
||||
{
|
||||
|
|
|
@ -35,9 +35,9 @@ namespace CodexPlugin
|
|||
|
||||
private EthAddress? GetEthAddress(CodexAccess access)
|
||||
{
|
||||
var mStart = access.Container.Recipe.Additionals.Get<MarketplaceStartResults>();
|
||||
if (mStart == null) return null;
|
||||
return mStart.EthAddress;
|
||||
var ethAccount = access.Container.Recipe.Additionals.Get<EthAccount>();
|
||||
if (ethAccount == null) return null;
|
||||
return ethAccount.EthAddress;
|
||||
}
|
||||
|
||||
public CrashWatcher CreateCrashWatcher(RunningContainer c)
|
||||
|
|
|
@ -52,8 +52,8 @@ namespace CodexPlugin
|
|||
var mconfig = codexSetup.MarketplaceConfig;
|
||||
foreach (var node in result)
|
||||
{
|
||||
mconfig.GethNode.SendEth(node, mconfig.InitialEth);
|
||||
mconfig.CodexContracts.MintTestTokens(node, mconfig.InitialTokens);
|
||||
mconfig.GethNode.SendEth(node, mconfig.MarketplaceSetup.InitialEth);
|
||||
mconfig.CodexContracts.MintTestTokens(node, mconfig.MarketplaceSetup.InitialTestTokens);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,8 +17,7 @@ namespace CodexPlugin
|
|||
ICodexSetup WithBlockMaintenanceInterval(TimeSpan duration);
|
||||
ICodexSetup WithBlockMaintenanceNumber(int numberOfBlocks);
|
||||
ICodexSetup EnableMetrics();
|
||||
ICodexSetup EnableMarketplace(IGethNode gethNode, ICodexContracts codexContracts, Ether initialEth, TestToken initialTokens);
|
||||
ICodexSetup EnableMarketplace(IGethNode gethNode, ICodexContracts codexContracts, Ether initialEth, TestToken initialTokens, Action<IMarketplaceSetup> marketplaceSetup);
|
||||
ICodexSetup EnableMarketplace(IGethNode gethNode, ICodexContracts codexContracts, Action<IMarketplaceSetup> marketplaceSetup);
|
||||
/// <summary>
|
||||
/// Provides an invalid proof every N proofs
|
||||
/// </summary>
|
||||
|
@ -28,6 +27,8 @@ namespace CodexPlugin
|
|||
|
||||
public interface IMarketplaceSetup
|
||||
{
|
||||
IMarketplaceSetup WithInitial(Ether eth, TestToken tokens);
|
||||
IMarketplaceSetup WithAccount(EthAccount account);
|
||||
IMarketplaceSetup AsStorageNode();
|
||||
IMarketplaceSetup AsValidator();
|
||||
}
|
||||
|
@ -122,17 +123,12 @@ namespace CodexPlugin
|
|||
return this;
|
||||
}
|
||||
|
||||
public ICodexSetup EnableMarketplace(IGethNode gethNode, ICodexContracts codexContracts, Ether initialEth, TestToken initialTokens)
|
||||
{
|
||||
return EnableMarketplace(gethNode, codexContracts, initialEth, initialTokens, s => { });
|
||||
}
|
||||
|
||||
public ICodexSetup EnableMarketplace(IGethNode gethNode, ICodexContracts codexContracts, Ether initialEth, TestToken initialTokens, Action<IMarketplaceSetup> marketplaceSetup)
|
||||
public ICodexSetup EnableMarketplace(IGethNode gethNode, ICodexContracts codexContracts, Action<IMarketplaceSetup> marketplaceSetup)
|
||||
{
|
||||
var ms = new MarketplaceSetup();
|
||||
marketplaceSetup(ms);
|
||||
|
||||
MarketplaceConfig = new MarketplaceInitialConfig(ms, gethNode, codexContracts, initialEth, initialTokens);
|
||||
MarketplaceConfig = new MarketplaceInitialConfig(ms, gethNode, codexContracts);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -169,6 +165,9 @@ namespace CodexPlugin
|
|||
{
|
||||
public bool IsStorageNode { 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()
|
||||
{
|
||||
|
@ -182,14 +181,28 @@ namespace CodexPlugin
|
|||
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()
|
||||
{
|
||||
var result = "[(clientNode)"; // When marketplace is enabled, being a clientNode is implicit.
|
||||
result += IsStorageNode ? "(storageNode)" : "()";
|
||||
result += IsValidator ? "(validator)" : "()";
|
||||
result += "]";
|
||||
result += IsValidator ? "(validator)" : "() ";
|
||||
result += $"Address: '{EthAccount.EthAddress}' ";
|
||||
result += $"InitialEth/TT({InitialEth.Eth}/{InitialTestTokens.Amount})";
|
||||
result += "] ";
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,19 +5,15 @@ namespace CodexPlugin
|
|||
{
|
||||
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;
|
||||
GethNode = gethNode;
|
||||
CodexContracts = codexContracts;
|
||||
InitialEth = initialEth;
|
||||
InitialTokens = initialTokens;
|
||||
}
|
||||
|
||||
public MarketplaceSetup MarketplaceSetup { get; }
|
||||
public IGethNode GethNode { 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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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; }
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class EthAddress
|
||||
{
|
||||
public EthAddress(string address)
|
||||
|
|
|
@ -21,7 +21,8 @@ namespace CodexTests.BasicTests
|
|||
|
||||
var group = AddCodex(5, o => o
|
||||
.EnableMetrics()
|
||||
.EnableMarketplace(geth, contract, 10.Eth(), 100000.TestTokens(), s => s
|
||||
.EnableMarketplace(geth, contract, s => s
|
||||
.WithInitial(10.Eth(), 100000.TestTokens())
|
||||
.AsStorageNode()
|
||||
.AsValidator())
|
||||
.WithBlockTTL(TimeSpan.FromMinutes(5))
|
||||
|
|
|
@ -64,7 +64,8 @@ namespace CodexTests.BasicTests
|
|||
.WithName("Seller")
|
||||
.WithLogLevel(CodexLogLevel.Trace, new CodexLogCustomTopics(CodexLogLevel.Error, CodexLogLevel.Error, CodexLogLevel.Warn))
|
||||
.WithStorageQuota(11.GB())
|
||||
.EnableMarketplace(geth, contracts, initialEth: 10.Eth(), initialTokens: sellerInitialBalance, s => s
|
||||
.EnableMarketplace(geth, contracts, m => m
|
||||
.WithInitial(10.Eth(), sellerInitialBalance)
|
||||
.AsStorageNode()
|
||||
.AsValidator()));
|
||||
|
||||
|
@ -83,7 +84,8 @@ namespace CodexTests.BasicTests
|
|||
var buyer = AddCodex(s => s
|
||||
.WithName("Buyer")
|
||||
.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));
|
||||
|
||||
|
|
|
@ -21,7 +21,8 @@ namespace CodexTests.DownloadConnectivityTests
|
|||
{
|
||||
var geth = Ci.StartGethNode(s => s.IsMiner());
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -31,7 +31,8 @@ namespace CodexTests.PeerDiscoveryTests
|
|||
{
|
||||
var geth = Ci.StartGethNode(s => s.IsMiner());
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -41,10 +41,11 @@ namespace CodexNetDeployer
|
|||
|
||||
if (config.ShouldMakeStorageAvailable)
|
||||
{
|
||||
s.EnableMarketplace(gethNode, contracts, 100.Eth(), config.InitialTestTokens.TestTokens(), s =>
|
||||
s.EnableMarketplace(gethNode, contracts, m =>
|
||||
{
|
||||
if (validatorsLeft > 0) s.AsValidator();
|
||||
if (config.ShouldMakeStorageAvailable) s.AsStorageNode();
|
||||
m.WithInitial(100.Eth(), config.InitialTestTokens.TestTokens());
|
||||
if (validatorsLeft > 0) m.AsValidator();
|
||||
if (config.ShouldMakeStorageAvailable) m.AsStorageNode();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue