Skip to content

Commit

Permalink
Updated overview builder to consider networkId and custom network gen…
Browse files Browse the repository at this point in the history
…esis. (hyperledger#4957)

* Updated overview builder to consider networkId and custom network genesis.

Signed-off-by: mark-terry <mark.terry@consensys.net>

* get network id from ethNetworkConfig

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>

Signed-off-by: mark-terry <mark.terry@consensys.net>
Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>
Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
  • Loading branch information
mark-terry and macfarla authored Jan 22, 2023
1 parent 0626acd commit db4f50d
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
3 changes: 3 additions & 0 deletions besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3582,6 +3582,9 @@ private String generateConfigurationOverview() {
builder.setNetwork(network.normalize());
}

builder.setHasCustomGenesis(genesisFile != null);
builder.setNetworkId(ethNetworkConfig.getNetworkId());

builder
.setDataStorage(dataStorageOptions.normalizeDataStorageFormat())
.setSyncMode(syncMode.normalize());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.hyperledger.besu.util.log.FramedLogMessage;
import org.hyperledger.besu.util.platform.PlatformDetector;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand All @@ -29,6 +30,8 @@
/** The Configuration overview builder. */
public class ConfigurationOverviewBuilder {
private String network;
private BigInteger networkId;
private boolean hasCustomGenesis;
private String dataStorage;
private String syncMode;
private Integer rpcPort;
Expand All @@ -48,6 +51,28 @@ public ConfigurationOverviewBuilder setNetwork(final String network) {
return this;
}

/**
* Sets whether a networkId has been specified
*
* @param networkId the specified networkId
* @return the builder
*/
public ConfigurationOverviewBuilder setNetworkId(final BigInteger networkId) {
this.networkId = networkId;
return this;
}

/**
* Sets whether a custom genesis has been specified.
*
* @param hasCustomGenesis a boolean representing whether a custom genesis file was specified
* @return the builder
*/
public ConfigurationOverviewBuilder setHasCustomGenesis(final boolean hasCustomGenesis) {
this.hasCustomGenesis = hasCustomGenesis;
return this;
}

/**
* Sets data storage.
*
Expand Down Expand Up @@ -135,10 +160,19 @@ public String build() {
lines.add("");
lines.add("Configuration:");

if (network != null) {
// Don't include the default network if a genesis file has been supplied
if (network != null && !hasCustomGenesis) {
lines.add("Network: " + network);
}

if (hasCustomGenesis) {
lines.add("Network: Custom genesis file specified");
}

if (networkId != null) {
lines.add("Network Id: " + networkId);
}

if (dataStorage != null) {
lines.add("Data storage: " + dataStorage);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import static org.assertj.core.api.Assertions.assertThat;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;

Expand All @@ -40,6 +41,31 @@ void setNetwork() {
assertThat(networkSet).contains("Network: foobar");
}

@Test
void setGenesisFile() {
final String noGenesisSet = builder.build();
assertThat(noGenesisSet).doesNotContain("Network: Custom genesis file specified");

builder.setNetwork("foobar");
final String networkSet = builder.build();
assertThat(networkSet).contains("Network: foobar");

builder.setHasCustomGenesis(true);
final String genesisSet = builder.build();
assertThat(genesisSet).contains("Network: Custom genesis file specified");
assertThat(genesisSet).doesNotContain("Network: foobar");
}

@Test
void setNetworkId() {
final String noNetworkIdSet = builder.build();
assertThat(noNetworkIdSet).doesNotContain("Network Id:");

builder.setNetworkId(BigInteger.ONE);
final String networkIdSet = builder.build();
assertThat(networkIdSet).contains("Network Id: 1");
}

@Test
void setDataStorage() {
final String noDataStorageSet = builder.build();
Expand Down

0 comments on commit db4f50d

Please sign in to comment.