Skip to content

Commit

Permalink
add acceptance test using keccak mining
Browse files Browse the repository at this point in the history
Signed-off-by: Antoine Toulme <[email protected]>
  • Loading branch information
atoulme committed Mar 1, 2021
1 parent db82a27 commit 2794720
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static org.apache.logging.log4j.LogManager.getLogger;
import static org.apache.tuweni.io.file.Files.copyResource;

import org.hyperledger.besu.cli.config.NetworkName;
import org.hyperledger.besu.crypto.KeyPair;
import org.hyperledger.besu.crypto.KeyPairUtil;
import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration;
Expand Down Expand Up @@ -97,6 +98,7 @@ public class BesuNode implements NodeConfiguration, RunnableNode, AutoCloseable
private Optional<PermissioningConfiguration> permissioningConfiguration;
private final GenesisConfigurationProvider genesisConfigProvider;
private final boolean devMode;
private final NetworkName network;
private final boolean discoveryEnabled;
private final List<URI> bootnodes = new ArrayList<>();
private final boolean bootnodeEligible;
Expand All @@ -123,6 +125,7 @@ public BesuNode(
final Optional<PermissioningConfiguration> permissioningConfiguration,
final Optional<String> keyfilePath,
final boolean devMode,
final NetworkName network,
final GenesisConfigurationProvider genesisConfigProvider,
final boolean p2pEnabled,
final NetworkingConfiguration networkingConfiguration,
Expand Down Expand Up @@ -156,6 +159,7 @@ public BesuNode(
this.permissioningConfiguration = permissioningConfiguration;
this.genesisConfigProvider = genesisConfigProvider;
this.devMode = devMode;
this.network = network;
this.p2pEnabled = p2pEnabled;
this.networkingConfiguration = networkingConfiguration;
this.discoveryEnabled = discoveryEnabled;
Expand Down Expand Up @@ -579,6 +583,10 @@ public boolean isDevMode() {
return devMode;
}

public NetworkName getNetwork() {
return network;
}

public boolean isSecp256k1Native() {
return secp256k1Native;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ public void startNode(final BesuNode node) {
if (node.isDevMode()) {
params.add("--network");
params.add("DEV");
} else if (node.getNetwork() != null) {
params.add("--network");
params.add(node.getNetwork().name());
}

params.add("--sync-mode");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package org.hyperledger.besu.tests.acceptance.dsl.node.configuration;

import org.hyperledger.besu.cli.config.NetworkName;
import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration;
import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration;
import org.hyperledger.besu.ethereum.core.MiningParameters;
Expand Down Expand Up @@ -52,6 +53,7 @@ public class BesuNodeConfiguration {
private final boolean isDnsEnabled;
private final Optional<PrivacyParameters> privacyParameters;
private final List<String> runCommand;
private final NetworkName network;

BesuNodeConfiguration(
final String name,
Expand All @@ -63,6 +65,7 @@ public class BesuNodeConfiguration {
final Optional<PermissioningConfiguration> permissioningConfiguration,
final Optional<String> keyFilePath,
final boolean devMode,
final NetworkName network,
final GenesisConfigurationProvider genesisConfigProvider,
final boolean p2pEnabled,
final NetworkingConfiguration networkingConfiguration,
Expand All @@ -86,6 +89,7 @@ public class BesuNodeConfiguration {
this.keyFilePath = keyFilePath;
this.dataPath = dataPath;
this.devMode = devMode;
this.network = network;
this.genesisConfigProvider = genesisConfigProvider;
this.p2pEnabled = p2pEnabled;
this.networkingConfiguration = networkingConfiguration;
Expand Down Expand Up @@ -193,4 +197,8 @@ public Optional<PrivacyParameters> getPrivacyParameters() {
public List<String> getRunCommand() {
return runCommand;
}

public NetworkName getNetwork() {
return network;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Collections.singletonList;

import org.hyperledger.besu.cli.config.NetworkName;
import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration;
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis;
import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration;
Expand Down Expand Up @@ -55,6 +56,7 @@ public class BesuNodeConfigurationBuilder {
private boolean discoveryEnabled = true;
private boolean bootnodeEligible = true;
private boolean revertReasonEnabled = false;
private NetworkName network = null;
private boolean secp256K1Native = false;
private boolean altbn128Native = false;
private final List<String> plugins = new ArrayList<>();
Expand Down Expand Up @@ -165,6 +167,11 @@ public BesuNodeConfigurationBuilder metricsConfiguration(
return this;
}

public BesuNodeConfigurationBuilder network(final NetworkName network) {
this.network = network;
return this;
}

public BesuNodeConfigurationBuilder webSocketEnabled() {
final WebSocketConfiguration config = WebSocketConfiguration.createDefault();
config.setEnabled(true);
Expand Down Expand Up @@ -295,6 +302,7 @@ public BesuNodeConfiguration build() {
permissioningConfiguration,
Optional.ofNullable(keyFilePath),
devMode,
network,
genesisConfigProvider,
p2pEnabled,
networkingConfiguration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public BesuNode create(final BesuNodeConfiguration config) throws IOException {
config.getPermissioningConfiguration(),
config.getKeyFilePath(),
config.isDevMode(),
config.getNetwork(),
config.getGenesisConfigProvider(),
config.isP2pEnabled(),
config.getNetworkingConfiguration(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public PrivacyNode(final PrivacyNodeConfiguration privacyConfiguration, final Ve
besuConfig.getPermissioningConfiguration(),
besuConfig.getKeyFilePath(),
besuConfig.isDevMode(),
besuConfig.getNetwork(),
besuConfig.getGenesisConfigProvider(),
besuConfig.isP2pEnabled(),
besuConfig.getNetworkingConfiguration(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright ConsenSys AG.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.tests.acceptance.mining;

import org.hyperledger.besu.cli.config.NetworkName;
import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBase;
import org.hyperledger.besu.tests.acceptance.dsl.account.Account;
import org.hyperledger.besu.tests.acceptance.dsl.node.Node;
import org.hyperledger.besu.tests.acceptance.dsl.node.configuration.BesuNodeConfigurationBuilder;

import org.junit.Before;
import org.junit.Test;

public class KeccakMiningAcceptanceTest extends AcceptanceTestBase {

private Node minerNode;

@Before
public void setUp() throws Exception {
minerNode =
besu.create(
new BesuNodeConfigurationBuilder()
.name("miner1")
.devMode(false)
.network(NetworkName.ECIP1049_DEV)
.miningEnabled()
.jsonRpcEnabled()
.webSocketEnabled()
.build());
cluster.start(minerNode);
}

@Test
public void shouldMineTransactions() {
final Account sender = accounts.createAccount("account1");
final Account receiver = accounts.createAccount("account2");
minerNode.execute(accountTransactions.createTransfer(sender, 50));
cluster.verify(sender.balanceEquals(50));

minerNode.execute(accountTransactions.createIncrementalTransfers(sender, receiver, 1));
cluster.verify(receiver.balanceEquals(1));

minerNode.execute(accountTransactions.createIncrementalTransfers(sender, receiver, 2));
cluster.verify(receiver.balanceEquals(3));

minerNode.execute(accountTransactions.createIncrementalTransfers(sender, receiver, 3));
cluster.verify(receiver.balanceEquals(6));

minerNode.execute(accountTransactions.createIncrementalTransfers(sender, receiver, 4));
cluster.verify(receiver.balanceEquals(10));

minerNode.execute(accountTransactions.createIncrementalTransfers(sender, receiver, 5));
cluster.verify(receiver.balanceEquals(15));
}
}

0 comments on commit 2794720

Please sign in to comment.