forked from hyperledger/besu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Acceptance test for execution engine apis (hyperledger#3533)
* added acceptance test for execution engine apis * removed check of payload id length Signed-off-by: Daniel Lehrner <[email protected]> Co-authored-by: Sally MacFarlane <[email protected]>
- Loading branch information
1 parent
64ec6c7
commit 09c99c8
Showing
18 changed files
with
434 additions
and
7 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
...ts/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/engine/EngineTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright Hyperledger Besu Contributors. | ||
* | ||
* 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.dsl.engine; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
|
||
public class EngineTestCase { | ||
private final JsonNode request; | ||
private final JsonNode response; | ||
private final int statusCode; | ||
|
||
@JsonCreator | ||
public EngineTestCase( | ||
@JsonProperty("request") final JsonNode request, | ||
@JsonProperty("response") final JsonNode response, | ||
@JsonProperty("statusCode") final int statusCode) { | ||
this.request = request; | ||
this.response = response; | ||
this.statusCode = statusCode; | ||
} | ||
|
||
public JsonNode getRequest() { | ||
return request; | ||
} | ||
|
||
public JsonNode getResponse() { | ||
return response; | ||
} | ||
|
||
public int getStatusCode() { | ||
return statusCode; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
...est/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ExecutionEngineAcceptanceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* Copyright Hyperledger Besu Contributors. | ||
* | ||
* 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.jsonrpc; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.hyperledger.besu.tests.acceptance.dsl.condition.net.NetConditions; | ||
import org.hyperledger.besu.tests.acceptance.dsl.engine.EngineTestCase; | ||
import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode; | ||
import org.hyperledger.besu.tests.acceptance.dsl.node.cluster.Cluster; | ||
import org.hyperledger.besu.tests.acceptance.dsl.node.configuration.BesuNodeFactory; | ||
import org.hyperledger.besu.tests.acceptance.dsl.transaction.net.NetTransactions; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.util.Arrays; | ||
import java.util.stream.Collectors; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import okhttp3.Call; | ||
import okhttp3.MediaType; | ||
import okhttp3.OkHttpClient; | ||
import okhttp3.Request; | ||
import okhttp3.RequestBody; | ||
import okhttp3.Response; | ||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
@RunWith(Parameterized.class) | ||
public class ExecutionEngineAcceptanceTest { | ||
private static final String GENESIS_FILE = "/jsonrpc/engine/genesis.json"; | ||
private static final String TEST_CASE_PATH = "/jsonrpc/engine/test-cases/"; | ||
private static final MediaType MEDIA_TYPE_JSON = | ||
MediaType.parse("application/json; charset=utf-8"); | ||
|
||
private static Cluster cluster; | ||
private static BesuNode executionEngine; | ||
private static OkHttpClient consensusClient; | ||
private static ObjectMapper mapper; | ||
|
||
private final URI testCaseFileURI; | ||
|
||
public ExecutionEngineAcceptanceTest(final String ignored, final URI testCaseFileURI) { | ||
this.testCaseFileURI = testCaseFileURI; | ||
} | ||
|
||
@BeforeClass | ||
public static void init() throws IOException { | ||
cluster = new Cluster(new NetConditions(new NetTransactions())); | ||
|
||
executionEngine = | ||
new BesuNodeFactory().createExecutionEngineGenesisNode("executionEngine", GENESIS_FILE); | ||
cluster.start(executionEngine); | ||
consensusClient = new OkHttpClient(); | ||
|
||
mapper = new ObjectMapper(); | ||
} | ||
|
||
@Test | ||
public void test() throws IOException { | ||
final EngineTestCase testCase = mapper.readValue(testCaseFileURI.toURL(), EngineTestCase.class); | ||
|
||
final Call preparePayloadRequest = | ||
consensusClient.newCall( | ||
new Request.Builder() | ||
.url(executionEngine.engineHttpUrl().get()) | ||
.post(RequestBody.create(testCase.getRequest().toString(), MEDIA_TYPE_JSON)) | ||
.build()); | ||
final Response response = preparePayloadRequest.execute(); | ||
|
||
assertThat(response.code()).isEqualTo(testCase.getStatusCode()); | ||
assertThat(response.body().string()).isEqualTo(testCase.getResponse().toPrettyString()); | ||
} | ||
|
||
@Parameterized.Parameters(name = "{0}") | ||
public static Iterable<Object[]> testCases() throws URISyntaxException { | ||
|
||
final File testCasePath = | ||
new File(ExecutionEngineAcceptanceTest.class.getResource(TEST_CASE_PATH).toURI()); | ||
final File[] testCasesList = testCasePath.listFiles(); | ||
|
||
return Arrays.stream(testCasesList) | ||
.sorted() | ||
.map(file -> new Object[] {file.getName(), file.toURI()}) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@AfterClass | ||
public static void tearDown() { | ||
cluster.close(); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
acceptance-tests/tests/src/test/resources/jsonrpc/engine/genesis.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"config": { | ||
"chainId":1, | ||
"homesteadBlock":0, | ||
"eip150Block":0, | ||
"eip155Block":0, | ||
"eip158Block":0, | ||
"byzantiumBlock":0, | ||
"constantinopleBlock":0, | ||
"petersburgBlock":0, | ||
"istanbulBlock":0, | ||
"muirGlacierBlock":0, | ||
"berlinBlock":0, | ||
"londonBlock":0, | ||
"clique": { | ||
"period": 5, | ||
"epoch": 30000 | ||
}, | ||
"terminalTotalDifficulty":0 | ||
}, | ||
"nonce":"0x42", | ||
"timestamp":"0x0", | ||
"extraData":"0x0000000000000000000000000000000000000000000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", | ||
"gasLimit":"0x1C9C380", | ||
"difficulty":"0x400000000", | ||
"mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000", | ||
"coinbase":"0x0000000000000000000000000000000000000000", | ||
"alloc":{ | ||
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b":{"balance":"0x6d6172697573766477000000"} | ||
}, | ||
"number":"0x0", | ||
"gasUsed":"0x0", | ||
"parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000", | ||
"baseFeePerGas":"0x7" | ||
} |
32 changes: 32 additions & 0 deletions
32
acceptance-tests/tests/src/test/resources/jsonrpc/engine/test-cases/01_prepare_payload.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"request": { | ||
"jsonrpc": "2.0", | ||
"method": "engine_forkchoiceUpdatedV1", | ||
"params": [ | ||
{ | ||
"headBlockHash": "0x3b8fb240d288781d4aac94d3fd16809ee413bc99294a085798a589dae51ddd4a", | ||
"safeBlockHash": "0x3b8fb240d288781d4aac94d3fd16809ee413bc99294a085798a589dae51ddd4a", | ||
"finalizedBlockHash": "0x0000000000000000000000000000000000000000000000000000000000000000" | ||
}, | ||
{ | ||
"timestamp": "0x5", | ||
"prevRandao": "0x0000000000000000000000000000000000000000000000000000000000000000", | ||
"suggestedFeeRecipient": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b" | ||
} | ||
], | ||
"id": 67 | ||
}, | ||
"response": { | ||
"jsonrpc": "2.0", | ||
"id": 67, | ||
"result": { | ||
"payloadStatus": { | ||
"status": "VALID", | ||
"latestValidHash": "0x3b8fb240d288781d4aac94d3fd16809ee413bc99294a085798a589dae51ddd4a", | ||
"validationError": null | ||
}, | ||
"payloadId": "0x0000000021f32cc1" | ||
} | ||
}, | ||
"statusCode" : 200 | ||
} |
Oops, something went wrong.