|
|
@ -30,7 +30,7 @@ import java.net.URI; |
|
|
|
import java.net.URISyntaxException; |
|
|
|
import java.net.URISyntaxException; |
|
|
|
import java.net.URL; |
|
|
|
import java.net.URL; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Stream; |
|
|
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode; |
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode; |
|
|
@ -40,10 +40,12 @@ import okhttp3.OkHttpClient; |
|
|
|
import okhttp3.Request; |
|
|
|
import okhttp3.Request; |
|
|
|
import okhttp3.RequestBody; |
|
|
|
import okhttp3.RequestBody; |
|
|
|
import okhttp3.Response; |
|
|
|
import okhttp3.Response; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.jupiter.params.ParameterizedTest; |
|
|
|
|
|
|
|
import org.junit.jupiter.params.provider.Arguments; |
|
|
|
|
|
|
|
import org.junit.jupiter.params.provider.MethodSource; |
|
|
|
|
|
|
|
|
|
|
|
abstract class AbstractJsonRpcTest { |
|
|
|
abstract class AbstractJsonRpcTest { |
|
|
|
private static final MediaType MEDIA_TYPE_JSON = |
|
|
|
protected static final MediaType MEDIA_TYPE_JSON = |
|
|
|
MediaType.parse("application/json; charset=utf-8"); |
|
|
|
MediaType.parse("application/json; charset=utf-8"); |
|
|
|
|
|
|
|
|
|
|
|
static class JsonRpcTestsContext { |
|
|
|
static class JsonRpcTestsContext { |
|
|
@ -69,16 +71,14 @@ abstract class AbstractJsonRpcTest { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private final JsonRpcTestsContext testsContext; |
|
|
|
private final JsonRpcTestsContext testsContext; |
|
|
|
private final URI testCaseFileURI; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public AbstractJsonRpcTest( |
|
|
|
public AbstractJsonRpcTest(final JsonRpcTestsContext testsContext) { |
|
|
|
final String ignored, final JsonRpcTestsContext testsContext, final URI testCaseFileURI) { |
|
|
|
|
|
|
|
this.testCaseFileURI = testCaseFileURI; |
|
|
|
|
|
|
|
this.testsContext = testsContext; |
|
|
|
this.testsContext = testsContext; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@ParameterizedTest(name = "{index}: {0}") |
|
|
|
public void test() throws IOException { |
|
|
|
@MethodSource("testCases") |
|
|
|
|
|
|
|
public void test(final URI testCaseFileURI) throws IOException { |
|
|
|
final JsonRpcTestCase testCase = |
|
|
|
final JsonRpcTestCase testCase = |
|
|
|
testsContext.mapper.readValue(testCaseFileURI.toURL(), JsonRpcTestCase.class); |
|
|
|
testsContext.mapper.readValue(testCaseFileURI.toURL(), JsonRpcTestCase.class); |
|
|
|
|
|
|
|
|
|
|
@ -118,7 +118,7 @@ abstract class AbstractJsonRpcTest { |
|
|
|
final JsonRpcTestCase testCase, |
|
|
|
final JsonRpcTestCase testCase, |
|
|
|
final URL url) {} |
|
|
|
final URL url) {} |
|
|
|
|
|
|
|
|
|
|
|
private String getRpcUrl(final String rpcMethod) { |
|
|
|
protected String getRpcUrl(final String rpcMethod) { |
|
|
|
if (rpcMethod.contains("eth_") || rpcMethod.contains("engine_")) { |
|
|
|
if (rpcMethod.contains("eth_") || rpcMethod.contains("engine_")) { |
|
|
|
return testsContext.besuNode.engineRpcUrl().get(); |
|
|
|
return testsContext.besuNode.engineRpcUrl().get(); |
|
|
|
} |
|
|
|
} |
|
|
@ -126,14 +126,12 @@ abstract class AbstractJsonRpcTest { |
|
|
|
return testsContext.besuNode.jsonRpcBaseUrl().get(); |
|
|
|
return testsContext.besuNode.jsonRpcBaseUrl().get(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static Iterable<Object[]> testCases(final String testCasesPath) throws URISyntaxException { |
|
|
|
public static Stream<Arguments> testCasesFromPath(final String testCasesPath) |
|
|
|
|
|
|
|
throws URISyntaxException { |
|
|
|
|
|
|
|
|
|
|
|
final File[] testCasesList = |
|
|
|
final File[] testCasesList = |
|
|
|
new File(AbstractJsonRpcTest.class.getResource(testCasesPath).toURI()).listFiles(); |
|
|
|
new File(AbstractJsonRpcTest.class.getResource(testCasesPath).toURI()).listFiles(); |
|
|
|
|
|
|
|
|
|
|
|
return Arrays.stream(testCasesList) |
|
|
|
return Arrays.stream(testCasesList).sorted().map(File::toURI).map(Arguments::of); |
|
|
|
.sorted() |
|
|
|
|
|
|
|
.map(file -> new Object[] {file.getName(), file.toURI()}) |
|
|
|
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|