Skip to content

Commit

Permalink
Merge pull request #1 from ChainSafe/ed/setup_config
Browse files Browse the repository at this point in the history
Config params for classic network
  • Loading branch information
edwardmack authored Oct 4, 2019
2 parents 50c0764 + 6e7874b commit d84f14e
Show file tree
Hide file tree
Showing 10 changed files with 26,865 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.hyperledger.besu.cli.config;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.hyperledger.besu.ethereum.p2p.config.DiscoveryConfiguration.CLASSIC_BOOTSTRAP_NODES;
import static org.hyperledger.besu.ethereum.p2p.config.DiscoveryConfiguration.GOERLI_BOOTSTRAP_NODES;
import static org.hyperledger.besu.ethereum.p2p.config.DiscoveryConfiguration.MAINNET_BOOTSTRAP_NODES;
import static org.hyperledger.besu.ethereum.p2p.config.DiscoveryConfiguration.RINKEBY_BOOTSTRAP_NODES;
Expand All @@ -39,11 +40,13 @@ public class EthNetworkConfig {
public static final BigInteger RINKEBY_NETWORK_ID = BigInteger.valueOf(4);
public static final BigInteger GOERLI_NETWORK_ID = BigInteger.valueOf(5);
public static final BigInteger DEV_NETWORK_ID = BigInteger.valueOf(2018);
public static final BigInteger CLASSIC_NETWORK_ID = BigInteger.valueOf(1);
private static final String MAINNET_GENESIS = "/mainnet.json";
private static final String ROPSTEN_GENESIS = "/ropsten.json";
private static final String RINKEBY_GENESIS = "/rinkeby.json";
private static final String GOERLI_GENESIS = "/goerli.json";
private static final String DEV_GENESIS = "/dev.json";
private static final String CLASSIC_GENESIS = "/classic.json";
private final String genesisConfig;
private final BigInteger networkId;
private final List<EnodeURL> bootNodes;
Expand Down Expand Up @@ -113,6 +116,9 @@ public static EthNetworkConfig getNetworkConfig(final NetworkName networkName) {
jsonConfig(GOERLI_GENESIS), GOERLI_NETWORK_ID, GOERLI_BOOTSTRAP_NODES);
case DEV:
return new EthNetworkConfig(jsonConfig(DEV_GENESIS), DEV_NETWORK_ID, new ArrayList<>());
case CLASSIC:
return new EthNetworkConfig(
jsonConfig(CLASSIC_GENESIS), CLASSIC_NETWORK_ID, CLASSIC_BOOTSTRAP_NODES);
case MAINNET:
default:
return new EthNetworkConfig(
Expand Down Expand Up @@ -141,6 +147,8 @@ public static String jsonConfig(final NetworkName network) {
return jsonConfig(GOERLI_GENESIS);
case DEV:
return jsonConfig(DEV_GENESIS);
case CLASSIC:
return jsonConfig(CLASSIC_GENESIS);
default:
throw new IllegalArgumentException("Unknown network:" + network);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ public enum NetworkName {
RINKEBY,
ROPSTEN,
GOERLI,
DEV
DEV,
CLASSIC
}
22 changes: 22 additions & 0 deletions besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hyperledger.besu.cli.config.NetworkName.CLASSIC;
import static org.hyperledger.besu.cli.config.NetworkName.DEV;
import static org.hyperledger.besu.cli.config.NetworkName.GOERLI;
import static org.hyperledger.besu.cli.config.NetworkName.MAINNET;
Expand Down Expand Up @@ -2417,6 +2418,22 @@ public void goerliValuesAreUsed() throws Exception {
assertThat(commandErrorOutput.toString()).isEmpty();
}

@Test
public void classicValuesAreUsed() throws Exception {
parseCommand("--network", "classic");

final ArgumentCaptor<EthNetworkConfig> networkArg =
ArgumentCaptor.forClass(EthNetworkConfig.class);

verify(mockControllerBuilderFactory).fromEthNetworkConfig(networkArg.capture(), any());
verify(mockControllerBuilder).build();

assertThat(networkArg.getValue()).isEqualTo(EthNetworkConfig.getNetworkConfig(CLASSIC));

assertThat(commandOutput.toString()).isEmpty();
assertThat(commandErrorOutput.toString()).isEmpty();
}

@Test
public void rinkebyValuesCanBeOverridden() throws Exception {
networkValuesCanBeOverridden("rinkeby");
Expand All @@ -2437,6 +2454,11 @@ public void devValuesCanBeOverridden() throws Exception {
networkValuesCanBeOverridden("dev");
}

@Test
public void classicValuesCanBeOverridden() throws Exception {
networkValuesCanBeOverridden("classic");
}

private void networkValuesCanBeOverridden(final String network) throws Exception {
parseCommand(
"--network",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,8 @@ public interface GenesisConfigOptions {
OptionalInt getEvmStackSize();

Map<String, Object> asMap();

OptionalLong getAtlantisBlockNumber();

OptionalLong getAghartaBlockNumber();
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,16 @@ public OptionalInt getEvmStackSize() {
return getOptionalInt("evmstacksize");
}

@Override
public OptionalLong getAtlantisBlockNumber() {
return getOptionalLong("atlantisblock");
}

@Override
public OptionalLong getAghartaBlockNumber() {
return getOptionalLong("aghartablock");
}

@Override
public Map<String, Object> asMap() {
final ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
Expand Down
Loading

0 comments on commit d84f14e

Please sign in to comment.