Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate bft and clique ATs to junit 5 #6249

Closed
wants to merge 14 commits into from
2 changes: 0 additions & 2 deletions acceptance-tests/tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ task acceptanceTest(type: Test) {
}
task acceptanceTestMainnet(type: Test) {
inputs.property "integration.date", LocalTime.now() // so it runs at every invocation
exclude '**/bft/**'
exclude '**/clique/**'
exclude '**/permissioning/**'
exclude '**/privacy/**'
Expand Down Expand Up @@ -157,7 +156,6 @@ task acceptanceTestMainnet(type: Test) {

task acceptanceTestCliqueBft(type: Test) {
inputs.property "integration.date", LocalTime.now() // so it runs at every invocation
include '**/bft/**'
include '**/clique/**'

useJUnitPlatform {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,8 @@
import org.apache.commons.compress.utils.IOUtils;

public class AbstractPreexistingNodeTest extends AcceptanceTestBase {
protected final String testName;
protected final String dataPath;
protected Path hostDataPath;

public AbstractPreexistingNodeTest(final String testName, final String dataPath) {
this.testName = testName;
this.dataPath = dataPath;
}

protected static void extract(final Path path, final String destDirectory) throws IOException {
try (final TarArchiveInputStream fin =
new TarArchiveInputStream(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import java.io.IOException;

import org.junit.Test;
import org.junit.jupiter.api.Test;

public class LoggingTest extends AcceptanceTestBase {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,72 +29,49 @@
import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode;
import org.hyperledger.besu.tests.acceptance.dsl.node.configuration.BesuNodeConfigurationBuilder;

import java.io.IOException;
import java.math.BigInteger;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.function.UnaryOperator;
import java.util.stream.Stream;
import javax.annotation.Nonnull;

import com.fasterxml.jackson.databind.node.ObjectNode;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

@RunWith(Parameterized.class)
public class BackupRoundTripAcceptanceTest extends AbstractPreexistingNodeTest {

private final Path backupPath;
private final Path restorePath;
private final Path rebackupPath;

@SuppressWarnings({"unused", "FieldCanBeLocal"})
private final List<AccountData> testAccounts;

@SuppressWarnings({"unused", "FieldCanBeLocal"})
private final long expectedChainHeight;
private Path backupPath;
private Path restorePath;
private Path rebackupPath;

public static Stream<Arguments> getParameters() {
// First 10 blocks of ropsten
return Stream.of(
Arguments.of(
"After versioning was enabled and using multiple RocksDB columns",
"version1",
0xA,
singletonList(
new AccountData(
"0xd1aeb42885a43b72b518182ef893125814811048",
BigInteger.valueOf(0xA),
Wei.fromHexString("0x2B5E3AF16B1880000")))));
}

public BackupRoundTripAcceptanceTest(
final String testName,
final String dataPath,
final long expectedChainHeight,
final List<AccountData> testAccounts)
throws IOException {
super(testName, dataPath);
this.expectedChainHeight = expectedChainHeight;
this.testAccounts = testAccounts;
public void setUp(final String testName, final String dataPath) throws Exception {
backupPath = Files.createTempDirectory("backup");
backupPath.toFile().deleteOnExit();
restorePath = Files.createTempDirectory("restore");
restorePath.toFile().deleteOnExit();
rebackupPath = Files.createTempDirectory("rebackup");
rebackupPath.toFile().deleteOnExit();
}

@Parameters(name = "{0}")
public static Object[][] getParameters() {
return new Object[][] {
// First 10 blocks of ropsten
new Object[] {
"After versioning was enabled and using multiple RocksDB columns",
"version1",
0xA,
singletonList(
new AccountData(
"0xd1aeb42885a43b72b518182ef893125814811048",
BigInteger.valueOf(0xA),
Wei.fromHexString("0x2B5E3AF16B1880000")))
}
};
}

@Before
public void setUp() throws Exception {
final URL rootURL = DatabaseMigrationAcceptanceTest.class.getResource(dataPath);
hostDataPath = copyDataDir(rootURL);
final Path databaseArchive =
Expand All @@ -105,8 +82,16 @@ public void setUp() throws Exception {
extract(databaseArchive, hostDataPath.toAbsolutePath().toString());
}

@Test
public void backupRoundtripAndBack() throws IOException {
@ParameterizedTest(name = "{index}: {0}")
@MethodSource("getParameters")
public void backupRoundtripAndBack(
final String testName,
final String dataPath,
final long expectedChainHeight,
final List<AccountData> testAccounts)
throws Exception {

setUp(testName, dataPath);

// backup from existing files
final BesuNode backupNode =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,23 @@
import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode;
import org.hyperledger.besu.tests.acceptance.dsl.node.configuration.BesuNodeFactory;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

import org.junit.jupiter.params.provider.Arguments;

public class BftAcceptanceTestParameterization {

public static List<Object[]> getFactories() {
final List<Object[]> ret = new ArrayList<>();
ret.addAll(
List.of(
new Object[] {
"ibft2",
new BftAcceptanceTestParameterization(
BesuNodeFactory::createIbft2Node, BesuNodeFactory::createIbft2NodeWithValidators)
},
new Object[] {
"qbft",
new BftAcceptanceTestParameterization(
BesuNodeFactory::createQbftNode, BesuNodeFactory::createQbftNodeWithValidators)
}));
return ret;
public static Stream<Arguments> getFactories() {
return Stream.of(
Arguments.of(
"ibft2",
new BftAcceptanceTestParameterization(
BesuNodeFactory::createIbft2Node, BesuNodeFactory::createIbft2NodeWithValidators),
Arguments.of(
"qbft",
new BftAcceptanceTestParameterization(
BesuNodeFactory::createQbftNode,
BesuNodeFactory::createQbftNodeWithValidators))));
}

@FunctionalInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,18 @@
import java.util.Optional;
import java.util.TreeMap;

import org.junit.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

public class BftBlockRewardPaymentAcceptanceTest extends ParameterizedBftTestBase {

private static final Amount BLOCK_REWARD = Amount.wei(new BigInteger("5000000000000000000", 10));

public BftBlockRewardPaymentAcceptanceTest(
final String testName, final BftAcceptanceTestParameterization nodeFactory) {
super(testName, nodeFactory);
}

@Test
public void validatorsArePaidBlockReward() throws Exception {
@ParameterizedTest(name = "{0} bft node factory type")
@MethodSource("factoryFunctions")
public void validatorsArePaidBlockReward(
final String testName, final BftAcceptanceTestParameterization nodeFactory) throws Exception {
setUp(testName, nodeFactory);
final String[] validators = {"validator"};
final BesuNode validator = nodeFactory.createNodeWithValidators(besu, "validator", validators);
final BesuNode nonValidator =
Expand All @@ -61,8 +60,11 @@ public void validatorsArePaidBlockReward() throws Exception {
Amount.ether(blockRewardEth * blockToCheck), BigInteger.valueOf(blockToCheck)));
}

@Test
public void payBlockRewardToConfiguredNode() throws Exception {
@ParameterizedTest(name = "{0} bft node factory type")
@MethodSource("factoryFunctions")
public void payBlockRewardToConfiguredNode(
final String testName, final BftAcceptanceTestParameterization nodeFactory) throws Exception {
setUp(testName, nodeFactory);
final String[] validators = {"validator1"};
final BesuNode validator1 =
nodeFactory.createNodeWithValidators(besu, "validator1", validators);
Expand Down Expand Up @@ -90,9 +92,11 @@ public void payBlockRewardToConfiguredNode() throws Exception {
Amount.ether(blockRewardEth * blockToCheck), BigInteger.valueOf(blockToCheck)));
}

@Test
public void payBlockRewardAccordingToTransitions_defaultInitialMiningBeneficiary()
throws Exception {
@ParameterizedTest(name = "{0} bft node factory type")
@MethodSource("factoryFunctions")
public void payBlockRewardAccordingToTransitions_defaultInitialMiningBeneficiary(
final String testName, final BftAcceptanceTestParameterization nodeFactory) throws Exception {
setUp(testName, nodeFactory);
final List<Address> addresses = generateAddresses(2);
final Map<Long, Optional<Address>> transitions =
Map.of(
Expand All @@ -103,9 +107,11 @@ public void payBlockRewardAccordingToTransitions_defaultInitialMiningBeneficiary
testMiningBeneficiaryTransitions(Optional.empty(), transitions);
}

@Test
public void payBlockRewardAccordingToTransitions_customInitialMiningBeneficiary()
throws Exception {
@ParameterizedTest(name = "{0} bft node factory type")
@MethodSource("factoryFunctions")
public void payBlockRewardAccordingToTransitions_customInitialMiningBeneficiary(
final String testName, final BftAcceptanceTestParameterization nodeFactory) throws Exception {
setUp(testName, nodeFactory);
final List<Address> addresses = generateAddresses(4);
final Map<Long, Optional<Address>> transitions =
Map.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,16 @@

import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode;

import org.junit.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

public class BftDiscardRpcAcceptanceTest extends ParameterizedBftTestBase {

public BftDiscardRpcAcceptanceTest(
final String testName, final BftAcceptanceTestParameterization nodeFactory) {
super(testName, nodeFactory);
}

@Test
public void shouldDiscardVotes() throws Exception {
@ParameterizedTest(name = "{index}: {0}")
@MethodSource("factoryFunctions")
public void shouldDiscardVotes(
final String testName, final BftAcceptanceTestParameterization nodeFactory) throws Exception {
setUp(testName, nodeFactory);
final String[] validators = {"validator1", "validator3"};
final BesuNode validator1 =
nodeFactory.createNodeWithValidators(besu, "validator1", validators);
Expand Down
Loading
Loading