Checking that we can bootstrap geth nodes together.
This commit is contained in:
parent
a84d6a3c22
commit
46ab3b31ca
@ -31,8 +31,11 @@ namespace GethPlugin
|
|||||||
|
|
||||||
private string CreateArgs(GethStartupConfig config)
|
private string CreateArgs(GethStartupConfig config)
|
||||||
{
|
{
|
||||||
if (config.IsMiner) AddEnvVar("ENABLE_MINER", "1");
|
if (config.IsMiner)
|
||||||
UnlockAccounts(0, 1);
|
{
|
||||||
|
AddEnvVar("ENABLE_MINER", "1");
|
||||||
|
UnlockAccounts(0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
var httpPort = CreateApiPort(config, tag: HttpPortTag);
|
var httpPort = CreateApiPort(config, tag: HttpPortTag);
|
||||||
var discovery = CreateDiscoveryPort(config);
|
var discovery = CreateDiscoveryPort(config);
|
||||||
@ -47,16 +50,12 @@ namespace GethPlugin
|
|||||||
var bootPubKey = config.BootstrapNode.PublicKey;
|
var bootPubKey = config.BootstrapNode.PublicKey;
|
||||||
var bootIp = config.BootstrapNode.IpAddress;
|
var bootIp = config.BootstrapNode.IpAddress;
|
||||||
var bootPort = config.BootstrapNode.Port;
|
var bootPort = config.BootstrapNode.Port;
|
||||||
var bootstrapArg = $" --bootnodes enode://{bootPubKey}@{bootIp}:{bootPort} --nat=extip:{bootIp}";
|
var bootstrapArg = $" --bootnodes enode://{bootPubKey}@{bootIp}:{bootPort}";
|
||||||
args += bootstrapArg;
|
args += bootstrapArg;
|
||||||
}
|
}
|
||||||
if (config.IsPublicTestNet != null)
|
if (config.IsPublicTestNet != null)
|
||||||
{
|
{
|
||||||
AddEnvVar("NAT_PUBLIC_IP_AUTO", "true");
|
AddEnvVar("NAT_PUBLIC_IP_AUTO", "https://ipinfo.io/ip");
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
AddEnvVar("NAT_PUBLIC_IP_AUTO", "false");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return args + $" --authrpc.port {authRpc.Number} --ws --ws.addr 0.0.0.0 --ws.port {wsPort.Number}";
|
return args + $" --authrpc.port {authRpc.Number} --ws --ws.addr 0.0.0.0 --ws.port {wsPort.Number}";
|
||||||
@ -65,7 +64,7 @@ namespace GethPlugin
|
|||||||
private void UnlockAccounts(int startIndex, int numberOfAccounts)
|
private void UnlockAccounts(int startIndex, int numberOfAccounts)
|
||||||
{
|
{
|
||||||
if (startIndex < 0) throw new ArgumentException();
|
if (startIndex < 0) throw new ArgumentException();
|
||||||
if (numberOfAccounts < 1) throw new ArgumentException();
|
if (numberOfAccounts < 0) throw new ArgumentException();
|
||||||
if (startIndex + numberOfAccounts > 1000) throw new ArgumentException("Out of accounts!");
|
if (startIndex + numberOfAccounts > 1000) throw new ArgumentException("Out of accounts!");
|
||||||
|
|
||||||
AddEnvVar("UNLOCK_START_INDEX", startIndex.ToString());
|
AddEnvVar("UNLOCK_START_INDEX", startIndex.ToString());
|
||||||
|
@ -19,6 +19,7 @@ namespace GethPlugin
|
|||||||
void SendTransaction<TFunction>(string contractAddress, TFunction function) where TFunction : FunctionMessage, new();
|
void SendTransaction<TFunction>(string contractAddress, TFunction function) where TFunction : FunctionMessage, new();
|
||||||
decimal? GetSyncedBlockNumber();
|
decimal? GetSyncedBlockNumber();
|
||||||
bool IsContractAvailable(string abi, string contractAddress);
|
bool IsContractAvailable(string abi, string contractAddress);
|
||||||
|
GethBootstrapNode GetBootstrapRecord();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class GethNode : IGethNode
|
public class GethNode : IGethNode
|
||||||
@ -69,6 +70,17 @@ namespace GethPlugin
|
|||||||
StartInteraction().SendTransaction(contractAddress, function);
|
StartInteraction().SendTransaction(contractAddress, function);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GethBootstrapNode GetBootstrapRecord()
|
||||||
|
{
|
||||||
|
var address = StartResult.Container.GetInternalAddress(GethContainerRecipe.ListenPortTag);
|
||||||
|
|
||||||
|
return new GethBootstrapNode(
|
||||||
|
publicKey: StartResult.PubKey,
|
||||||
|
ipAddress: address.Host.Replace("http://", ""),
|
||||||
|
port: address.Port
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private NethereumInteraction StartInteraction()
|
private NethereumInteraction StartInteraction()
|
||||||
{
|
{
|
||||||
var address = StartResult.Container.GetAddress(log, GethContainerRecipe.HttpPortTag);
|
var address = StartResult.Container.GetAddress(log, GethContainerRecipe.HttpPortTag);
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
public interface IGethSetup
|
public interface IGethSetup
|
||||||
{
|
{
|
||||||
IGethSetup IsMiner();
|
IGethSetup IsMiner();
|
||||||
|
IGethSetup WithBootstrapNode(IGethNode node);
|
||||||
IGethSetup WithBootstrapNode(GethBootstrapNode node);
|
IGethSetup WithBootstrapNode(GethBootstrapNode node);
|
||||||
IGethSetup WithName(string name);
|
IGethSetup WithName(string name);
|
||||||
IGethSetup AsPublicTestNet(GethTestNetConfig gethTestNetConfig);
|
IGethSetup AsPublicTestNet(GethTestNetConfig gethTestNetConfig);
|
||||||
@ -15,6 +16,11 @@
|
|||||||
public string? NameOverride { get; private set; }
|
public string? NameOverride { get; private set; }
|
||||||
public GethTestNetConfig? IsPublicTestNet { get; private set; }
|
public GethTestNetConfig? IsPublicTestNet { get; private set; }
|
||||||
|
|
||||||
|
public IGethSetup WithBootstrapNode(IGethNode node)
|
||||||
|
{
|
||||||
|
return WithBootstrapNode(node.GetBootstrapRecord());
|
||||||
|
}
|
||||||
|
|
||||||
public IGethSetup WithBootstrapNode(GethBootstrapNode node)
|
public IGethSetup WithBootstrapNode(GethBootstrapNode node)
|
||||||
{
|
{
|
||||||
BootstrapNode = node;
|
BootstrapNode = node;
|
||||||
|
@ -95,5 +95,22 @@ namespace CodexTests.BasicTests
|
|||||||
AssertBalance(contracts, seller, Is.GreaterThan(sellerInitialBalance), "Seller was not paid for storage.");
|
AssertBalance(contracts, seller, Is.GreaterThan(sellerInitialBalance), "Seller was not paid for storage.");
|
||||||
AssertBalance(contracts, buyer, Is.LessThan(buyerInitialBalance), "Buyer was not charged for storage.");
|
AssertBalance(contracts, buyer, Is.LessThan(buyerInitialBalance), "Buyer was not charged for storage.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void GethBootstrapTest()
|
||||||
|
{
|
||||||
|
var boot = Ci.StartGethNode(s => s.WithName("boot").IsMiner());
|
||||||
|
var disconnected = Ci.StartGethNode(s => s.WithName("disconnected"));
|
||||||
|
var follow = Ci.StartGethNode(s => s.WithBootstrapNode(boot).WithName("follow"));
|
||||||
|
|
||||||
|
Thread.Sleep(12000);
|
||||||
|
|
||||||
|
var bootN = boot.GetSyncedBlockNumber();
|
||||||
|
var discN = disconnected.GetSyncedBlockNumber();
|
||||||
|
var followN = follow.GetSyncedBlockNumber();
|
||||||
|
|
||||||
|
Assert.That(bootN, Is.EqualTo(followN));
|
||||||
|
Assert.That(discN, Is.LessThan(bootN));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user