Skip to content

Commit

Permalink
remove builder tests from engine integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
tbenr committed May 3, 2022
1 parent 9203f73 commit 2b86456
Showing 1 changed file with 0 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.io.Resources;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
Expand All @@ -32,35 +31,25 @@
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.TestTemplate;
import tech.pegasys.teku.bls.BLSSignature;
import tech.pegasys.teku.ethereum.executionengine.Web3JClient;
import tech.pegasys.teku.ethereum.executionengine.Web3jClientBuilder;
import tech.pegasys.teku.ethereum.executionengine.schema.Response;
import tech.pegasys.teku.ethereum.executionlayer.client.schema.ExecutionPayloadHeaderV1;
import tech.pegasys.teku.ethereum.executionlayer.client.schema.ExecutionPayloadV1;
import tech.pegasys.teku.ethereum.executionlayer.client.schema.ForkChoiceStateV1;
import tech.pegasys.teku.ethereum.executionlayer.client.schema.ForkChoiceUpdatedResult;
import tech.pegasys.teku.ethereum.executionlayer.client.schema.PayloadAttributesV1;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.infrastructure.bytes.Bytes20;
import tech.pegasys.teku.infrastructure.bytes.Bytes8;
import tech.pegasys.teku.infrastructure.json.JsonTestUtil;
import tech.pegasys.teku.infrastructure.time.StubTimeProvider;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.SpecMilestone;
import tech.pegasys.teku.spec.TestSpecContext;
import tech.pegasys.teku.spec.TestSpecInvocationContextProvider.SpecContext;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeaderSchema;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadSchema;
import tech.pegasys.teku.spec.executionengine.PayloadStatus;
import tech.pegasys.teku.spec.util.DataStructureUtil;

Expand Down Expand Up @@ -180,142 +169,6 @@ void forkChoiceUpdated_shouldRoundtripWithMockedWebServer() throws Exception {
.equals(payloadStatusResponse));
}

@TestTemplate
@SuppressWarnings("unchecked")
void proposeBlindedBlock_shouldRoundtripWithMockedWebServer() throws Exception {
final String jsonExecutionPayloadResponse =
Resources.toString(
Resources.getResource("proposeBlindedBlockResponse.json"), StandardCharsets.UTF_8);

final String bodyResponse =
"{\"jsonrpc\": \"2.0\", \"id\": 0, \"result\":" + jsonExecutionPayloadResponse + "}";

final ExecutionPayloadSchema executionPayloadSchema =
spec.getGenesisSchemaDefinitions()
.toVersionBellatrix()
.orElseThrow()
.getExecutionPayloadSchema();

final ExecutionPayload executionPayloadResponse =
objectMapper
.readValue(jsonExecutionPayloadResponse, ExecutionPayloadV1.class)
.asInternalExecutionPayload(executionPayloadSchema);

mockWebServer.enqueue(
new MockResponse()
.setBody(bodyResponse)
.setResponseCode(200)
.addHeader("Content-Type", "application/json"));

final SignedBeaconBlock signedBeaconBlockRequest =
dataStructureUtil.randomSignedBlindedBeaconBlock();

SafeFuture<Response<ExecutionPayloadV1>> futureResponseProposeBlindedBlock =
eeClient.proposeBlindedBlock(signedBeaconBlockRequest);

final RecordedRequest request = mockWebServer.takeRequest();

final Map<String, Object> data =
JsonTestUtil.parse(request.getBody().readString(StandardCharsets.UTF_8));

final String signedBeaconBlockSignature =
(String)
((Map<String, Object>) ((List<Object>) data.get("params")).get(0)).get("signature");
final Map<String, Object> beaconBlock =
(Map<String, Object>)
((Map<String, Object>) ((List<Object>) data.get("params")).get(0)).get("message");

verifyJsonRpcMethodCall(data, "builder_proposeBlindedBlockV1");

assertThat(signedBeaconBlockRequest.getSignature())
.isEqualTo(
BLSSignature.fromBytesCompressed(Bytes.fromHexString(signedBeaconBlockSignature)));

assertThat(signedBeaconBlockRequest.getSlot())
.isEqualTo(UInt64.valueOf(beaconBlock.get("slot").toString()));
assertThat(signedBeaconBlockRequest.getProposerIndex())
.isEqualTo(UInt64.valueOf(beaconBlock.get("proposer_index").toString()));
assertThat(signedBeaconBlockRequest.getParentRoot())
.isEqualTo(Bytes32.fromHexString(beaconBlock.get("parent_root").toString()));
assertThat(signedBeaconBlockRequest.getStateRoot())
.isEqualTo(Bytes32.fromHexString(beaconBlock.get("state_root").toString()));

final Map<String, Object> executionPayloadHeader =
(Map<String, Object>)
((Map<String, Object>) beaconBlock.get("body")).get("execution_payload_header");

assertThat(
signedBeaconBlockRequest
.getBeaconBlock()
.orElseThrow()
.getBody()
.getOptionalExecutionPayloadHeader()
.orElseThrow()
.getTransactionsRoot())
.isEqualTo(
Bytes32.fromHexString(executionPayloadHeader.get("transactions_root").toString()));

assertThat(futureResponseProposeBlindedBlock.join())
.matches(
executionPayloadV1Response1 ->
executionPayloadV1Response1
.getPayload()
.asInternalExecutionPayload(executionPayloadSchema)
.equals(executionPayloadResponse));
}

@TestTemplate
@SuppressWarnings("unchecked")
void getPayloadHeader_shouldRoundtripWithMockedWebServer() throws Exception {
final String jsonExecutionPayloadHeaderResponse =
Resources.toString(
Resources.getResource("getPayloadHeaderResponse.json"), StandardCharsets.UTF_8);

final String bodyResponse =
"{\"jsonrpc\": \"2.0\", \"id\": 0, \"result\":" + jsonExecutionPayloadHeaderResponse + "}";

final ExecutionPayloadHeaderSchema executionPayloadHeaderSchema =
spec.getGenesisSchemaDefinitions()
.toVersionBellatrix()
.orElseThrow()
.getExecutionPayloadHeaderSchema();

final ExecutionPayloadHeader executionPayloadHeaderResponse =
objectMapper
.readValue(jsonExecutionPayloadHeaderResponse, ExecutionPayloadHeaderV1.class)
.asInternalExecutionPayloadHeader(executionPayloadHeaderSchema);

mockWebServer.enqueue(
new MockResponse()
.setBody(bodyResponse)
.setResponseCode(200)
.addHeader("Content-Type", "application/json"));

final Bytes8 payloadIdRequest = dataStructureUtil.randomBytes8();

SafeFuture<Response<ExecutionPayloadHeaderV1>> futureResponseExecutionPayloadHeader =
eeClient.getPayloadHeader(payloadIdRequest);

final RecordedRequest request = mockWebServer.takeRequest();

final Map<String, Object> data =
JsonTestUtil.parse(request.getBody().readString(StandardCharsets.UTF_8));

final String payloadId = (String) ((List<Object>) data.get("params")).get(0);

verifyJsonRpcMethodCall(data, "builder_getPayloadHeaderV1");

assertThat(payloadIdRequest).isEqualTo(Bytes8.fromHexString(payloadId));

assertThat(futureResponseExecutionPayloadHeader.join())
.matches(
executionPayloadHeaderV1Response1 ->
executionPayloadHeaderV1Response1
.getPayload()
.asInternalExecutionPayloadHeader(executionPayloadHeaderSchema)
.equals(executionPayloadHeaderResponse));
}

private void verifyJsonRpcMethodCall(Map<String, Object> data, final String method) {
assertThat(data.get("method")).asInstanceOf(STRING).isEqualTo(method);
assertThat(data.get("id")).asInstanceOf(INTEGER).isGreaterThanOrEqualTo(0);
Expand Down

0 comments on commit 2b86456

Please sign in to comment.