Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,19 @@
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public abstract class AbstractJsonRpcHttpBySpecTest extends AbstractJsonRpcHttpServiceTest {

private static final boolean UPDATE_SPECS = Boolean.getBoolean("besu.test.update.specs");
private static final ObjectMapper objectMapper = new ObjectMapper();
private static final ObjectMapper prettyObjectMapper =
new ObjectMapper().configure(INDENT_OUTPUT, true);
private static final Pattern GAS_MATCH_FOR_STATE_DIFF =
Pattern.compile("\"balance\":(?!\"=\").*?},");
private static final Pattern GAS_MATCH_FOR_VM_TRACE =
Expand All @@ -62,6 +68,34 @@ public abstract class AbstractJsonRpcHttpBySpecTest extends AbstractJsonRpcHttpS
Pattern.compile("\"error\"\\s*:\\s*\"([^\"]+)\"");

private URL specURL;
private boolean initialized = false;

/**
* Subclasses implement this to perform one-time blockchain + service setup. Called the first time
* {@link #setup()} runs; skipped on subsequent parameterized test invocations.
*/
protected abstract void doSetup() throws Exception;

@Override
@BeforeEach
public void setup() throws Exception {
if (!initialized) {
initialized = true;
doSetup();
} else if (filterManager != null) {
filterManager.stop();
}
}

@AfterAll
public void teardownAll() {
super.shutdownServer();
}

@Override
public void shutdownServer() {
// Suppressed: teardown happens once in @AfterAll, not after every parameterized test case
}

@ParameterizedTest(name = "{index}: {0}")
@MethodSource("specs")
Expand Down Expand Up @@ -325,18 +359,16 @@ private void checkResponse(
expectedResult = normalizeErrorMessages(expectedResult);
actualResult = normalizeErrorMessages(actualResult);

final ObjectMapper mapper = new ObjectMapper();
mapper.configure(INDENT_OUTPUT, true);
assertThat(
mapper
prettyObjectMapper
.writerWithDefaultPrettyPrinter()
.withoutAttribute("creationMethod")
.writeValueAsString(mapper.readTree(actualResult)))
.writeValueAsString(prettyObjectMapper.readTree(actualResult)))
.isEqualTo(
mapper
prettyObjectMapper
.writerWithDefaultPrettyPrinter()
.withoutAttribute("creationMethod")
.writeValueAsString(mapper.readTree(expectedResult)));
.writeValueAsString(prettyObjectMapper.readTree(expectedResult)));
}

// Check error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil;
import org.hyperledger.besu.plugin.services.storage.DataStorageFormat;

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

public class DebugGethTraceJsonRpcHttpBySpecTest extends AbstractJsonRpcHttpBySpecTest {
@Override
@BeforeEach
public void setup() throws Exception {
protected void doSetup() throws Exception {
setupBonsaiBlockchain();
startService();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@

import org.hyperledger.besu.ethereum.api.jsonrpc.AbstractJsonRpcHttpBySpecTest;

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

public class DebugJsonRpcHttpBySpecTest extends AbstractJsonRpcHttpBySpecTest {

@Override
@BeforeEach
public void setup() throws Exception {
protected void doSetup() throws Exception {
setupBonsaiBlockchain();
startService();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@
import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil;
import org.hyperledger.besu.plugin.services.storage.DataStorageFormat;

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

public class DebugTraceJsonRpcHttpBySpecTest extends AbstractJsonRpcHttpBySpecTest {

@Override
@BeforeEach
public void setup() throws Exception {
protected void doSetup() throws Exception {
setupBonsaiBlockchain();
startService();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@
import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil;
import org.hyperledger.besu.plugin.services.storage.DataStorageFormat;

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

public class EthByzantiumJsonRpcHttpBySpecTest extends AbstractJsonRpcHttpBySpecTest {

@Override
@BeforeEach
public void setup() throws Exception {
protected void doSetup() throws Exception {
setupBonsaiBlockchain();
startService();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@
import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil;
import org.hyperledger.besu.plugin.services.storage.DataStorageFormat;

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

public class EthConfigBySpecTest extends AbstractJsonRpcHttpBySpecTest {

@Override
@BeforeEach
public void setup() throws Exception {
protected void doSetup() throws Exception {
setupBonsaiBlockchain();
startService();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@

import org.hyperledger.besu.ethereum.api.jsonrpc.AbstractJsonRpcHttpBySpecTest;

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

public class EthJsonRpcHttpBySpecTest extends AbstractJsonRpcHttpBySpecTest {

@Override
@BeforeEach
public void setup() throws Exception {
protected void doSetup() throws Exception {
setupBonsaiBlockchain();
startService();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode;
import org.hyperledger.besu.plugin.services.storage.DataStorageFormat;

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

/**
Expand All @@ -34,8 +33,7 @@
public class EthSimulateV1BySpecTest extends AbstractJsonRpcHttpBySpecTest {

@Override
@BeforeEach
public void setup() throws Exception {
protected void doSetup() throws Exception {
setupBonsaiBlockchain();
startService();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import java.util.Optional;

import org.apache.tuweni.bytes.Bytes32;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class TestingBuildBlockJsonRpcHttpBySpecTest extends AbstractJsonRpcHttpBySpecTest {
Expand All @@ -51,8 +50,7 @@ public class TestingBuildBlockJsonRpcHttpBySpecTest extends AbstractJsonRpcHttpB
Address.fromHexString("0x627306090abaB3A6e1400e9345bC60c78a8BEf57");

@Override
@BeforeEach
public void setup() throws Exception {
protected void doSetup() throws Exception {
blockchainSetupUtil = getBlockchainSetupUtil(DataStorageFormat.BONSAI);
blockchainSetupUtil.importAllBlocks();
startService();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@
import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil;
import org.hyperledger.besu.plugin.services.storage.DataStorageFormat;

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

public class TraceJsonRpcHttpBySpecTest extends AbstractJsonRpcHttpBySpecTest {

@Override
@BeforeEach
public void setup() throws Exception {
protected void doSetup() throws Exception {
setupBonsaiBlockchain();
startService();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@

import org.hyperledger.besu.ethereum.api.jsonrpc.AbstractJsonRpcHttpBySpecTest;

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

public class DebugJsonRpcHttpBySpecTest extends AbstractJsonRpcHttpBySpecTest {

@Override
@BeforeEach
public void setup() throws Exception {
protected void doSetup() throws Exception {
setupBlockchain();
startService();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@
import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil;
import org.hyperledger.besu.plugin.services.storage.DataStorageFormat;

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

public class DebugTraceJsonRpcHttpBySpecTest extends AbstractJsonRpcHttpBySpecTest {

@Override
@BeforeEach
public void setup() throws Exception {
protected void doSetup() throws Exception {
setupBlockchain();
startService();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@
import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil;
import org.hyperledger.besu.plugin.services.storage.DataStorageFormat;

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

public class EthByzantiumJsonRpcHttpBySpecTest extends AbstractJsonRpcHttpBySpecTest {

@Override
@BeforeEach
public void setup() throws Exception {
protected void doSetup() throws Exception {
setupBlockchain();
startService();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@

import org.hyperledger.besu.ethereum.api.jsonrpc.AbstractJsonRpcHttpBySpecTest;

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

public class EthJsonRpcHttpBySpecTest extends AbstractJsonRpcHttpBySpecTest {

@Override
@BeforeEach
public void setup() throws Exception {
protected void doSetup() throws Exception {
setupBlockchain();
startService();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@
import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil;
import org.hyperledger.besu.plugin.services.storage.DataStorageFormat;

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

@Disabled("Forest storage is deprecated - trace tests are covered by the Bonsai variant")
public class TraceJsonRpcHttpBySpecTest extends AbstractJsonRpcHttpBySpecTest {

@Override
@BeforeEach
public void setup() throws Exception {
protected void doSetup() throws Exception {
setupBlockchain();
startService();
}
Expand Down
Loading