diff --git a/ProjectPlugins/GethPlugin/GethContainerRecipe.cs b/ProjectPlugins/GethPlugin/GethContainerRecipe.cs index beda54c..5af9371 100644 --- a/ProjectPlugins/GethPlugin/GethContainerRecipe.cs +++ b/ProjectPlugins/GethPlugin/GethContainerRecipe.cs @@ -31,8 +31,11 @@ namespace GethPlugin private string CreateArgs(GethStartupConfig config) { - if (config.IsMiner) AddEnvVar("ENABLE_MINER", "1"); - UnlockAccounts(0, 1); + if (config.IsMiner) + { + AddEnvVar("ENABLE_MINER", "1"); + UnlockAccounts(0, 1); + } var httpPort = CreateApiPort(config, tag: HttpPortTag); var discovery = CreateDiscoveryPort(config); @@ -47,16 +50,12 @@ namespace GethPlugin var bootPubKey = config.BootstrapNode.PublicKey; var bootIp = config.BootstrapNode.IpAddress; var bootPort = config.BootstrapNode.Port; - var bootstrapArg = $" --bootnodes enode://{bootPubKey}@{bootIp}:{bootPort} --nat=extip:{bootIp}"; + var bootstrapArg = $" --bootnodes enode://{bootPubKey}@{bootIp}:{bootPort}"; args += bootstrapArg; } if (config.IsPublicTestNet != null) { - AddEnvVar("NAT_PUBLIC_IP_AUTO", "true"); - } - else - { - AddEnvVar("NAT_PUBLIC_IP_AUTO", "false"); + AddEnvVar("NAT_PUBLIC_IP_AUTO", "https://ipinfo.io/ip"); } 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) { 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!"); AddEnvVar("UNLOCK_START_INDEX", startIndex.ToString()); diff --git a/ProjectPlugins/GethPlugin/GethNode.cs b/ProjectPlugins/GethPlugin/GethNode.cs index 19c3708..050074a 100644 --- a/ProjectPlugins/GethPlugin/GethNode.cs +++ b/ProjectPlugins/GethPlugin/GethNode.cs @@ -19,6 +19,7 @@ namespace GethPlugin void SendTransaction(string contractAddress, TFunction function) where TFunction : FunctionMessage, new(); decimal? GetSyncedBlockNumber(); bool IsContractAvailable(string abi, string contractAddress); + GethBootstrapNode GetBootstrapRecord(); } public class GethNode : IGethNode @@ -69,6 +70,17 @@ namespace GethPlugin 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() { var address = StartResult.Container.GetAddress(log, GethContainerRecipe.HttpPortTag); diff --git a/ProjectPlugins/GethPlugin/GethStartupConfig.cs b/ProjectPlugins/GethPlugin/GethStartupConfig.cs index 0d6b86e..51520ca 100644 --- a/ProjectPlugins/GethPlugin/GethStartupConfig.cs +++ b/ProjectPlugins/GethPlugin/GethStartupConfig.cs @@ -3,6 +3,7 @@ public interface IGethSetup { IGethSetup IsMiner(); + IGethSetup WithBootstrapNode(IGethNode node); IGethSetup WithBootstrapNode(GethBootstrapNode node); IGethSetup WithName(string name); IGethSetup AsPublicTestNet(GethTestNetConfig gethTestNetConfig); @@ -15,6 +16,11 @@ public string? NameOverride { get; private set; } public GethTestNetConfig? IsPublicTestNet { get; private set; } + public IGethSetup WithBootstrapNode(IGethNode node) + { + return WithBootstrapNode(node.GetBootstrapRecord()); + } + public IGethSetup WithBootstrapNode(GethBootstrapNode node) { BootstrapNode = node; diff --git a/Tests/CodexTests/BasicTests/ExampleTests.cs b/Tests/CodexTests/BasicTests/ExampleTests.cs index 44c6dc6..d98156c 100644 --- a/Tests/CodexTests/BasicTests/ExampleTests.cs +++ b/Tests/CodexTests/BasicTests/ExampleTests.cs @@ -95,5 +95,22 @@ namespace CodexTests.BasicTests AssertBalance(contracts, seller, Is.GreaterThan(sellerInitialBalance), "Seller was not paid 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)); + } } }