[NC-1394] Add shortcut --rinkeby command line to use clique on rinkeby test network (#16)

Jason Frame 6 years ago committed by GitHub
parent e5a17733cf
commit 28094cee58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      acceptance-tests/src/test/java/net/consensys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java
  2. 8
      ethereum/p2p/src/main/java/net/consensys/pantheon/ethereum/p2p/config/DiscoveryConfiguration.java
  3. 124
      pantheon/src/main/java/net/consensys/pantheon/cli/EthNetworkConfig.java
  4. 41
      pantheon/src/main/java/net/consensys/pantheon/cli/PantheonCommand.java
  5. 26
      pantheon/src/main/java/net/consensys/pantheon/cli/PantheonControllerBuilder.java
  6. 2
      pantheon/src/main/java/net/consensys/pantheon/controller/CliquePantheonController.java
  7. 5
      pantheon/src/test/java/net/consensys/pantheon/cli/CommandTestAbstract.java
  8. 99
      pantheon/src/test/java/net/consensys/pantheon/cli/PantheonCommandTest.java

@ -1,7 +1,10 @@
package net.consensys.pantheon.tests.acceptance.dsl.node; package net.consensys.pantheon.tests.acceptance.dsl.node;
import static net.consensys.pantheon.cli.EthNetworkConfig.mainnet;
import net.consensys.pantheon.Runner; import net.consensys.pantheon.Runner;
import net.consensys.pantheon.RunnerBuilder; import net.consensys.pantheon.RunnerBuilder;
import net.consensys.pantheon.cli.EthNetworkConfig;
import net.consensys.pantheon.cli.PantheonControllerBuilder; import net.consensys.pantheon.cli.PantheonControllerBuilder;
import net.consensys.pantheon.controller.PantheonController; import net.consensys.pantheon.controller.PantheonController;
import net.consensys.pantheon.ethereum.eth.sync.SynchronizerConfiguration.Builder; import net.consensys.pantheon.ethereum.eth.sync.SynchronizerConfiguration.Builder;
@ -33,17 +36,18 @@ public class ThreadPantheonNodeRunner implements PantheonNodeRunner {
} }
final PantheonControllerBuilder builder = new PantheonControllerBuilder(); final PantheonControllerBuilder builder = new PantheonControllerBuilder();
final EthNetworkConfig ethNetworkConfig =
new EthNetworkConfig.Builder(mainnet()).setNetworkId(NETWORK_ID).build();
PantheonController<?, ?> pantheonController; PantheonController<?, ?> pantheonController;
try { try {
pantheonController = pantheonController =
builder.build( builder.build(
new Builder().build(), new Builder().build(),
null,
node.homeDirectory(), node.homeDirectory(),
ethNetworkConfig,
false, false,
node.getMiningParameters(), node.getMiningParameters(),
true, true);
NETWORK_ID);
} catch (final IOException e) { } catch (final IOException e) {
throw new RuntimeException("Error building PantheonController", e); throw new RuntimeException("Error building PantheonController", e);
} }

@ -24,6 +24,14 @@ public class DiscoveryConfiguration {
"enode://979b7fa28feeb35a4741660a16076f1943202cb72b6af70d327f053e248bab9ba81760f39d0701ef1d8f89cc1fbd2cacba0710a12cd5314d5e0c9021aa3637f9@5.1.83.226:30303") "enode://979b7fa28feeb35a4741660a16076f1943202cb72b6af70d327f053e248bab9ba81760f39d0701ef1d8f89cc1fbd2cacba0710a12cd5314d5e0c9021aa3637f9@5.1.83.226:30303")
.map(DefaultPeer::fromURI) .map(DefaultPeer::fromURI)
.collect(toList())); .collect(toList()));
public static List<Peer> RINKEBY_BOOTSTRAP_NODES =
Collections.unmodifiableList(
Stream.of(
"enode://a24ac7c5484ef4ed0c5eb2d36620ba4e4aa13b8c84684e1b4aab0cebea2ae45cb4d375b77eab56516d34bfbd3c1a833fc51296ff084b770b94fb9028c4d25ccf@52.169.42.101:30303",
"enode://343149e4feefa15d882d9fe4ac7d88f885bd05ebb735e547f12e12080a9fa07c8014ca6fd7f373123488102fe5e34111f8509cf0b7de3f5b44339c9f25e87cb8@52.3.158.184:30303",
"enode://b6b28890b006743680c52e64e0d16db57f28124885595fa03a562be1d2bf0f3a1da297d56b13da25fb992888fd556d4c1a27b1f39d531bde7de1921c90061cc6@159.89.28.211:30303")
.map(DefaultPeer::fromURI)
.collect(toList()));
private boolean active = true; private boolean active = true;
private String bindHost = "0.0.0.0"; private String bindHost = "0.0.0.0";

@ -0,0 +1,124 @@
package net.consensys.pantheon.cli;
import static net.consensys.pantheon.controller.CliquePantheonController.RINKEBY_NETWORK_ID;
import static net.consensys.pantheon.controller.MainnetPantheonController.MAINNET_NETWORK_ID;
import static net.consensys.pantheon.ethereum.p2p.config.DiscoveryConfiguration.MAINNET_BOOTSTRAP_NODES;
import static net.consensys.pantheon.ethereum.p2p.config.DiscoveryConfiguration.RINKEBY_BOOTSTRAP_NODES;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collection;
import java.util.Objects;
import com.google.common.base.Preconditions;
import com.google.common.io.Resources;
public class EthNetworkConfig {
private static final String MAINNET_GENESIS = "mainnet.json";
private static final String RINKEBY_GENESIS = "rinkeby.json";
private final URI genesisConfig;
private final int networkId;
private final Collection<?> bootNodes;
public EthNetworkConfig(
final URI genesisConfig, final int networkId, final Collection<?> bootNodes) {
Preconditions.checkNotNull(genesisConfig);
Preconditions.checkNotNull(bootNodes);
this.genesisConfig = genesisConfig;
this.networkId = networkId;
this.bootNodes = bootNodes;
}
public URI getGenesisConfig() {
return genesisConfig;
}
public int getNetworkId() {
return networkId;
}
public Collection<?> getBootNodes() {
return bootNodes;
}
@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
EthNetworkConfig that = (EthNetworkConfig) o;
return networkId == that.networkId
&& Objects.equals(genesisConfig, that.genesisConfig)
&& Objects.equals(bootNodes, that.bootNodes);
}
@Override
public int hashCode() {
return Objects.hash(genesisConfig, networkId, bootNodes);
}
@Override
public String toString() {
return "EthNetworkConfig{"
+ "genesisConfig="
+ genesisConfig
+ ", networkId="
+ networkId
+ ", bootNodes="
+ bootNodes
+ '}';
}
public static EthNetworkConfig mainnet() {
final URI genesisConfig = jsonConfigURI(MAINNET_GENESIS);
return new EthNetworkConfig(genesisConfig, MAINNET_NETWORK_ID, MAINNET_BOOTSTRAP_NODES);
}
public static EthNetworkConfig rinkeby() {
final URI genesisConfig = jsonConfigURI(RINKEBY_GENESIS);
return new EthNetworkConfig(genesisConfig, RINKEBY_NETWORK_ID, RINKEBY_BOOTSTRAP_NODES);
}
private static URI jsonConfigURI(final String resourceName) {
try {
return Resources.getResource(resourceName).toURI();
} catch (URISyntaxException e) {
throw new IllegalStateException(e);
}
}
public static class Builder {
private URI genesisConfig;
private int networkId;
private Collection<?> bootNodes;
public Builder(final EthNetworkConfig ethNetworkConfig) {
this.genesisConfig = ethNetworkConfig.genesisConfig;
this.networkId = ethNetworkConfig.networkId;
this.bootNodes = ethNetworkConfig.bootNodes;
}
public Builder setGenesisConfig(final URI genesisConfig) {
this.genesisConfig = genesisConfig;
return this;
}
public Builder setNetworkId(final int networkId) {
this.networkId = networkId;
return this;
}
public Builder setBootNodes(final Collection<?> bootNodes) {
this.bootNodes = bootNodes;
return this;
}
public EthNetworkConfig build() {
return new EthNetworkConfig(genesisConfig, networkId, bootNodes);
}
}
}

@ -5,7 +5,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
import net.consensys.pantheon.Runner; import net.consensys.pantheon.Runner;
import net.consensys.pantheon.RunnerBuilder; import net.consensys.pantheon.RunnerBuilder;
import net.consensys.pantheon.cli.custom.CorsAllowedOriginsProperty; import net.consensys.pantheon.cli.custom.CorsAllowedOriginsProperty;
import net.consensys.pantheon.controller.MainnetPantheonController;
import net.consensys.pantheon.controller.PantheonController; import net.consensys.pantheon.controller.PantheonController;
import net.consensys.pantheon.ethereum.blockcreation.MiningParameters; import net.consensys.pantheon.ethereum.blockcreation.MiningParameters;
import net.consensys.pantheon.ethereum.core.Address; import net.consensys.pantheon.ethereum.core.Address;
@ -202,6 +201,14 @@ public class PantheonCommand implements Runnable {
) )
private final Boolean syncWithOttoman = false; private final Boolean syncWithOttoman = false;
@Option(
names = {"--rinkeby"},
description =
"Use the Rinkeby test network"
+ "- see https://github.com/ethereum/EIPs/issues/225 (default: ${DEFAULT-VALUE})"
)
private final Boolean rinkeby = false;
@Option( @Option(
names = {"--p2p-listen"}, names = {"--p2p-listen"},
paramLabel = MANDATORY_HOST_AND_PORT_FORMAT_HELP, paramLabel = MANDATORY_HOST_AND_PORT_FORMAT_HELP,
@ -216,7 +223,7 @@ public class PantheonCommand implements Runnable {
description = "P2P network identifier (default: ${DEFAULT-VALUE})", description = "P2P network identifier (default: ${DEFAULT-VALUE})",
arity = "1" arity = "1"
) )
private final Integer networkId = MainnetPantheonController.MAINNET_NETWORK_ID; private final Integer networkId = null;
@Option( @Option(
names = {"--rpc-enabled"}, names = {"--rpc-enabled"},
@ -367,10 +374,11 @@ public class PantheonCommand implements Runnable {
+ "or specify the beneficiary of mining (via --miner-coinbase <Address>)"); + "or specify the beneficiary of mining (via --miner-coinbase <Address>)");
return; return;
} }
final EthNetworkConfig ethNetworkConfig = ethNetworkConfig();
synchronize( synchronize(
buildController(), buildController(),
noPeerDiscovery, noPeerDiscovery,
bootstrapNodes, ethNetworkConfig.getBootNodes(),
maxPeers, maxPeers,
p2pHostAndPort, p2pHostAndPort,
jsonRpcConfiguration(), jsonRpcConfiguration(),
@ -381,12 +389,11 @@ public class PantheonCommand implements Runnable {
try { try {
return controllerBuilder.build( return controllerBuilder.build(
buildSyncConfig(syncMode), buildSyncConfig(syncMode),
genesisFile,
dataDir, dataDir,
ethNetworkConfig(),
syncWithOttoman, syncWithOttoman,
new MiningParameters(coinbase, minTransactionGasPrice, extraData, isMiningEnabled), new MiningParameters(coinbase, minTransactionGasPrice, extraData, isMiningEnabled),
isDevMode, isDevMode);
networkId);
} catch (final IOException e) { } catch (final IOException e) {
throw new ExecutionException(new CommandLine(this), "Invalid path", e); throw new ExecutionException(new CommandLine(this), "Invalid path", e);
} }
@ -422,7 +429,7 @@ public class PantheonCommand implements Runnable {
private void synchronize( private void synchronize(
final PantheonController<?, ?> controller, final PantheonController<?, ?> controller,
final boolean noPeerDiscovery, final boolean noPeerDiscovery,
final Collection<String> bootstrapNodes, final Collection<?> bootstrapNodes,
final int maxPeers, final int maxPeers,
final HostAndPort discoveryHostAndPort, final HostAndPort discoveryHostAndPort,
final JsonRpcConfiguration jsonRpcConfiguration, final JsonRpcConfiguration jsonRpcConfiguration,
@ -515,4 +522,24 @@ public class PantheonCommand implements Runnable {
} }
return pantheonHome; return pantheonHome;
} }
private EthNetworkConfig ethNetworkConfig() {
final EthNetworkConfig predefinedNetworkConfig =
rinkeby ? EthNetworkConfig.rinkeby() : EthNetworkConfig.mainnet();
return updateNetworkConfig(predefinedNetworkConfig);
}
private EthNetworkConfig updateNetworkConfig(final EthNetworkConfig ethNetworkConfig) {
EthNetworkConfig.Builder builder = new EthNetworkConfig.Builder(ethNetworkConfig);
if (genesisFile != null) {
builder.setGenesisConfig(genesisFile.toPath().toUri());
}
if (networkId != null) {
builder.setNetworkId(networkId);
}
if (bootstrapNodes != null) {
builder.setBootNodes(bootstrapNodes);
}
return builder.build();
}
} }

@ -1,5 +1,6 @@
package net.consensys.pantheon.cli; package net.consensys.pantheon.cli;
import static java.nio.charset.StandardCharsets.UTF_8;
import static net.consensys.pantheon.controller.KeyPairUtil.loadKeyPair; import static net.consensys.pantheon.controller.KeyPairUtil.loadKeyPair;
import net.consensys.pantheon.controller.MainnetPantheonController; import net.consensys.pantheon.controller.MainnetPantheonController;
@ -9,44 +10,41 @@ import net.consensys.pantheon.ethereum.blockcreation.MiningParameters;
import net.consensys.pantheon.ethereum.chain.GenesisConfig; import net.consensys.pantheon.ethereum.chain.GenesisConfig;
import net.consensys.pantheon.ethereum.eth.sync.SynchronizerConfiguration; import net.consensys.pantheon.ethereum.eth.sync.SynchronizerConfiguration;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import com.google.common.io.Resources;
public class PantheonControllerBuilder { public class PantheonControllerBuilder {
public PantheonController<?, ?> build( public PantheonController<?, ?> build(
final SynchronizerConfiguration synchronizerConfiguration, final SynchronizerConfiguration synchronizerConfiguration,
final File genesisFile,
final Path homePath, final Path homePath,
final EthNetworkConfig ethNetworkConfig,
final boolean syncWithOttoman, final boolean syncWithOttoman,
final MiningParameters miningParameters, final MiningParameters miningParameters,
final boolean isDevMode, final boolean isDevMode)
final int networkId)
throws IOException { throws IOException {
// instantiate a controller with mainnet config if no genesis file is defined // instantiate a controller with mainnet config if no genesis file is defined
// otherwise use the indicated genesis file // otherwise use the indicated genesis file
final KeyPair nodeKeys = loadKeyPair(homePath); final KeyPair nodeKeys = loadKeyPair(homePath);
if (genesisFile == null) { if (isDevMode) {
final GenesisConfig<Void> genesisConfig =
isDevMode ? GenesisConfig.development() : GenesisConfig.mainnet();
return MainnetPantheonController.init( return MainnetPantheonController.init(
homePath, homePath,
genesisConfig, GenesisConfig.development(),
synchronizerConfiguration, synchronizerConfiguration,
miningParameters, miningParameters,
networkId, ethNetworkConfig.getNetworkId(),
nodeKeys); nodeKeys);
} else { } else {
final String genesisConfig =
Resources.toString(ethNetworkConfig.getGenesisConfig().toURL(), UTF_8);
return PantheonController.fromConfig( return PantheonController.fromConfig(
synchronizerConfiguration, synchronizerConfiguration,
new String(Files.readAllBytes(genesisFile.toPath()), StandardCharsets.UTF_8), genesisConfig,
homePath, homePath,
syncWithOttoman, syncWithOttoman,
networkId, ethNetworkConfig.getNetworkId(),
miningParameters, miningParameters,
nodeKeys); nodeKeys);
} }

@ -50,7 +50,7 @@ import org.apache.logging.log4j.Logger;
public class CliquePantheonController public class CliquePantheonController
implements PantheonController<CliqueContext, CliqueBlockMiner> { implements PantheonController<CliqueContext, CliqueBlockMiner> {
public static int RINKEBY_NETWORK_ID = 4;
private static final Logger LOG = getLogger(); private static final Logger LOG = getLogger();
private final GenesisConfig<CliqueContext> genesisConfig; private final GenesisConfig<CliqueContext> genesisConfig;
private final ProtocolContext<CliqueContext> context; private final ProtocolContext<CliqueContext> context;

@ -2,7 +2,6 @@ package net.consensys.pantheon.cli;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import net.consensys.pantheon.Runner; import net.consensys.pantheon.Runner;
@ -14,7 +13,6 @@ import net.consensys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration;
import net.consensys.pantheon.util.BlockImporter; import net.consensys.pantheon.util.BlockImporter;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.PrintStream; import java.io.PrintStream;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Collection; import java.util.Collection;
@ -55,7 +53,6 @@ public abstract class CommandTestAbstract {
@Captor ArgumentCaptor<Collection<String>> stringListArgumentCaptor; @Captor ArgumentCaptor<Collection<String>> stringListArgumentCaptor;
@Captor ArgumentCaptor<Path> pathArgumentCaptor; @Captor ArgumentCaptor<Path> pathArgumentCaptor;
@Captor ArgumentCaptor<File> fileArgumentCaptor;
@Captor ArgumentCaptor<String> stringArgumentCaptor; @Captor ArgumentCaptor<String> stringArgumentCaptor;
@Captor ArgumentCaptor<Integer> intArgumentCaptor; @Captor ArgumentCaptor<Integer> intArgumentCaptor;
@Captor ArgumentCaptor<JsonRpcConfiguration> jsonRpcConfigArgumentCaptor; @Captor ArgumentCaptor<JsonRpcConfiguration> jsonRpcConfigArgumentCaptor;
@ -66,7 +63,7 @@ public abstract class CommandTestAbstract {
// doReturn used because of generic PantheonController // doReturn used because of generic PantheonController
Mockito.doReturn(mockController) Mockito.doReturn(mockController)
.when(mockControllerBuilder) .when(mockControllerBuilder)
.build(any(), any(), any(), anyBoolean(), any(), anyBoolean(), anyInt()); .build(any(), any(), any(), anyBoolean(), any(), anyBoolean());
when(mockSyncConfBuilder.build()).thenReturn(mockSyncConf); when(mockSyncConfBuilder.build()).thenReturn(mockSyncConf);
} }

@ -1,6 +1,8 @@
package net.consensys.pantheon.cli; package net.consensys.pantheon.cli;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Arrays.asList;
import static net.consensys.pantheon.ethereum.p2p.config.DiscoveryConfiguration.MAINNET_BOOTSTRAP_NODES;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyBoolean;
@ -8,12 +10,12 @@ import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNotNull; import static org.mockito.ArgumentMatchers.isNotNull;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import net.consensys.pantheon.PantheonInfo; import net.consensys.pantheon.PantheonInfo;
import net.consensys.pantheon.cli.EthNetworkConfig.Builder;
import net.consensys.pantheon.ethereum.blockcreation.MiningParameters; import net.consensys.pantheon.ethereum.blockcreation.MiningParameters;
import net.consensys.pantheon.ethereum.core.Address; import net.consensys.pantheon.ethereum.core.Address;
import net.consensys.pantheon.ethereum.core.Wei; import net.consensys.pantheon.ethereum.core.Wei;
@ -28,6 +30,8 @@ import java.io.Writer;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Optional; import java.util.Optional;
@ -89,7 +93,7 @@ public class PantheonCommandTest extends CommandTestAbstract {
any(), any(),
any(), any(),
eq(true), eq(true),
isNull(), eq(MAINNET_BOOTSTRAP_NODES),
eq("127.0.0.1"), eq("127.0.0.1"),
eq(30303), eq(30303),
eq(25), eq(25),
@ -99,8 +103,10 @@ public class PantheonCommandTest extends CommandTestAbstract {
final ArgumentCaptor<MiningParameters> miningArg = final ArgumentCaptor<MiningParameters> miningArg =
ArgumentCaptor.forClass(MiningParameters.class); ArgumentCaptor.forClass(MiningParameters.class);
final ArgumentCaptor<EthNetworkConfig> networkArg =
ArgumentCaptor.forClass(EthNetworkConfig.class);
verify(mockControllerBuilder) verify(mockControllerBuilder)
.build(any(), isNull(), isNotNull(), eq(false), miningArg.capture(), eq(false), anyInt()); .build(any(), isNotNull(), networkArg.capture(), eq(false), miningArg.capture(), eq(false));
verify(mockSyncConfBuilder).syncMode(ArgumentMatchers.eq(SyncMode.FULL)); verify(mockSyncConfBuilder).syncMode(ArgumentMatchers.eq(SyncMode.FULL));
@ -108,6 +114,9 @@ public class PantheonCommandTest extends CommandTestAbstract {
assertThat(miningArg.getValue().getCoinbase()).isEqualTo(Optional.empty()); assertThat(miningArg.getValue().getCoinbase()).isEqualTo(Optional.empty());
assertThat(miningArg.getValue().getMinTransactionGasPrice()).isEqualTo(Wei.of(1000)); assertThat(miningArg.getValue().getMinTransactionGasPrice()).isEqualTo(Wei.of(1000));
assertThat(miningArg.getValue().getExtraData()).isEqualTo(BytesValue.EMPTY); assertThat(miningArg.getValue().getExtraData()).isEqualTo(BytesValue.EMPTY);
assertThat(networkArg.getValue().getNetworkId()).isEqualTo(1);
assertThat(networkArg.getValue().getGenesisConfig().toString()).endsWith("mainnet.json");
assertThat(networkArg.getValue().getBootNodes()).isEqualTo(MAINNET_BOOTSTRAP_NODES);
} }
// Testing each option // Testing each option
@ -215,18 +224,23 @@ public class PantheonCommandTest extends CommandTestAbstract {
eq(webSocketConfiguration), eq(webSocketConfiguration),
any()); any());
final String[] nodes = {"enode://001@123:4567", "enode://002@123:4567", "enode://003@123:4567"}; final Collection<String> nodes =
assertThat(stringListArgumentCaptor.getValue().toArray()).isEqualTo(nodes); asList("enode://001@123:4567", "enode://002@123:4567", "enode://003@123:4567");
assertThat(stringListArgumentCaptor.getValue()).isEqualTo(nodes);
EthNetworkConfig networkConfig =
new Builder(EthNetworkConfig.mainnet())
.setGenesisConfig(new File("~/genesys.json").toPath().toUri())
.setBootNodes(nodes)
.build();
verify(mockControllerBuilder) verify(mockControllerBuilder)
.build( .build(
any(), any(),
eq(new File("~/genesys.json")),
eq(Paths.get("~/pantheondata")), eq(Paths.get("~/pantheondata")),
eq(networkConfig),
eq(false), eq(false),
any(), any(),
anyBoolean(), anyBoolean());
anyInt());
// TODO: Re-enable as per NC-1057/NC-1681 // TODO: Re-enable as per NC-1057/NC-1681
// verify(mockSyncConfBuilder).syncMode(ArgumentMatchers.eq(SyncMode.FAST)); // verify(mockSyncConfBuilder).syncMode(ArgumentMatchers.eq(SyncMode.FAST));
@ -248,7 +262,7 @@ public class PantheonCommandTest extends CommandTestAbstract {
any(), any(),
any(), any(),
eq(true), eq(true),
isNull(), eq(MAINNET_BOOTSTRAP_NODES),
eq("127.0.0.1"), eq("127.0.0.1"),
eq(30303), eq(30303),
eq(25), eq(25),
@ -256,8 +270,7 @@ public class PantheonCommandTest extends CommandTestAbstract {
eq(WebSocketConfiguration.createDefault()), eq(WebSocketConfiguration.createDefault()),
any()); any());
verify(mockControllerBuilder) verify(mockControllerBuilder).build(any(), any(), any(), eq(false), any(), eq(false));
.build(any(), eq(null), any(), eq(false), any(), eq(false), anyInt());
// TODO: Re-enable as per NC-1057/NC-1681 // TODO: Re-enable as per NC-1057/NC-1681
// verify(mockSyncConfBuilder).syncMode(ArgumentMatchers.eq(SyncMode.FULL)); // verify(mockSyncConfBuilder).syncMode(ArgumentMatchers.eq(SyncMode.FULL));
@ -275,14 +288,7 @@ public class PantheonCommandTest extends CommandTestAbstract {
parseCommand("--datadir", path.toString()); parseCommand("--datadir", path.toString());
verify(mockControllerBuilder) verify(mockControllerBuilder)
.build( .build(any(), pathArgumentCaptor.capture(), any(), eq(false), any(), anyBoolean());
any(),
isNull(),
pathArgumentCaptor.capture(),
anyBoolean(),
any(),
anyBoolean(),
anyInt());
assertThat(pathArgumentCaptor.getValue()).isEqualByComparingTo(path); assertThat(pathArgumentCaptor.getValue()).isEqualByComparingTo(path);
@ -293,20 +299,15 @@ public class PantheonCommandTest extends CommandTestAbstract {
@Test @Test
public void genesisPathOptionMustBeUsed() throws Exception { public void genesisPathOptionMustBeUsed() throws Exception {
final Path path = Paths.get("."); final Path path = Paths.get(".");
final ArgumentCaptor<EthNetworkConfig> networkArg =
ArgumentCaptor.forClass(EthNetworkConfig.class);
parseCommand("--genesis", path.toString()); parseCommand("--genesis", path.toString());
verify(mockControllerBuilder) verify(mockControllerBuilder)
.build( .build(any(), any(), networkArg.capture(), anyBoolean(), any(), anyBoolean());
any(),
fileArgumentCaptor.capture(),
any(),
anyBoolean(),
any(),
anyBoolean(),
anyInt());
assertThat(fileArgumentCaptor.getValue().toPath()).isEqualByComparingTo(path); assertThat(networkArg.getValue().getGenesisConfig()).isEqualTo(path.toUri());
assertThat(commandOutput.toString()).isEmpty(); assertThat(commandOutput.toString()).isEmpty();
assertThat(commandErrorOutput.toString()).isEmpty(); assertThat(commandErrorOutput.toString()).isEmpty();
@ -745,7 +746,7 @@ public class PantheonCommandTest extends CommandTestAbstract {
ArgumentCaptor.forClass(MiningParameters.class); ArgumentCaptor.forClass(MiningParameters.class);
verify(mockControllerBuilder) verify(mockControllerBuilder)
.build(any(), any(), any(), anyBoolean(), miningArg.capture(), anyBoolean(), anyInt()); .build(any(), any(), any(), anyBoolean(), miningArg.capture(), anyBoolean());
assertThat(commandOutput.toString()).isEmpty(); assertThat(commandOutput.toString()).isEmpty();
assertThat(commandErrorOutput.toString()).isEmpty(); assertThat(commandErrorOutput.toString()).isEmpty();
assertThat(miningArg.getValue().isMiningEnabled()).isTrue(); assertThat(miningArg.getValue().isMiningEnabled()).isTrue();
@ -767,7 +768,7 @@ public class PantheonCommandTest extends CommandTestAbstract {
ArgumentCaptor.forClass(MiningParameters.class); ArgumentCaptor.forClass(MiningParameters.class);
verify(mockControllerBuilder) verify(mockControllerBuilder)
.build(any(), any(), any(), anyBoolean(), miningArg.capture(), anyBoolean(), anyInt()); .build(any(), any(), any(), anyBoolean(), miningArg.capture(), anyBoolean());
assertThat(commandOutput.toString()).isEmpty(); assertThat(commandOutput.toString()).isEmpty();
assertThat(commandErrorOutput.toString()).isEmpty(); assertThat(commandErrorOutput.toString()).isEmpty();
assertThat(miningArg.getValue().getCoinbase()).isEqualTo(Optional.of(requestedCoinbase)); assertThat(miningArg.getValue().getCoinbase()).isEqualTo(Optional.of(requestedCoinbase));
@ -779,9 +780,45 @@ public class PantheonCommandTest extends CommandTestAbstract {
@Test @Test
public void devModeOptionMustBeUsed() throws Exception { public void devModeOptionMustBeUsed() throws Exception {
parseCommand("--dev-mode"); parseCommand("--dev-mode");
verify(mockControllerBuilder).build(any(), any(), any(), anyBoolean(), any(), eq(true));
assertThat(commandOutput.toString()).isEmpty();
assertThat(commandErrorOutput.toString()).isEmpty();
}
@Test
public void rinkebyValuesAreUsed() throws Exception {
parseCommand("--rinkeby");
final ArgumentCaptor<EthNetworkConfig> networkArg =
ArgumentCaptor.forClass(EthNetworkConfig.class);
verify(mockControllerBuilder)
.build(any(), any(), networkArg.capture(), anyBoolean(), any(), anyBoolean());
assertThat(commandOutput.toString()).isEmpty();
assertThat(commandErrorOutput.toString()).isEmpty();
assertThat(networkArg.getValue()).isEqualTo(EthNetworkConfig.rinkeby());
}
@Test
public void rinkebyValuesCanBeOverridden() throws Exception {
final String[] nodes = {"enode://001@123:4567", "enode://002@123:4567", "enode://003@123:4567"};
final Path path = Paths.get(".");
parseCommand(
"--rinkeby",
"--network-id",
"1",
"--bootnodes",
String.join(",", nodes),
"--genesis",
path.toString());
final ArgumentCaptor<EthNetworkConfig> networkArg =
ArgumentCaptor.forClass(EthNetworkConfig.class);
verify(mockControllerBuilder) verify(mockControllerBuilder)
.build(any(), any(), any(), anyBoolean(), any(), eq(true), anyInt()); .build(any(), any(), networkArg.capture(), anyBoolean(), any(), anyBoolean());
assertThat(commandOutput.toString()).isEmpty(); assertThat(commandOutput.toString()).isEmpty();
assertThat(commandErrorOutput.toString()).isEmpty(); assertThat(commandErrorOutput.toString()).isEmpty();
assertThat(networkArg.getValue().getGenesisConfig()).isEqualTo(path.toUri());
assertThat(networkArg.getValue().getBootNodes()).isEqualTo(Arrays.asList(nodes));
assertThat(networkArg.getValue().getNetworkId()).isEqualTo(1);
} }
} }

Loading…
Cancel
Save