Skip to content

Commit 9f28a87

Browse files
authored
Expanded VC API tests (#8757)
fixes #8756 Added test cases for VC block requests, and added a validation to the Attestation request test. These were the 2 VC cases where we now require that header to be specified or we will fail. There was another case in DSL for AT, but we'll see those quickly if we use it. Signed-off-by: Paul Harris <[email protected]>
1 parent d761f5b commit 9f28a87

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

validator/remote/src/integration-test/java/tech/pegasys/teku/validator/remote/typedef/handlers/SendSignedAttestationsRequestTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,7 @@ void shouldUseV2ApiWhenUseAttestationsV2ApisEnabled()
117117
assertThat(recordedRequest.getMethod()).isEqualTo("POST");
118118
assertThat(recordedRequest.getPath())
119119
.contains(ValidatorApiMethod.SEND_SIGNED_ATTESTATION_V2.getPath(emptyMap()));
120+
assertThat(recordedRequest.getHeader(HEADER_CONSENSUS_VERSION))
121+
.isEqualTo(specMilestone.name().toLowerCase(Locale.ROOT));
120122
}
121123
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Copyright Consensys Software Inc., 2024
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
14+
package tech.pegasys.teku.validator.remote.typedef.handlers;
15+
16+
import static java.util.Collections.emptyMap;
17+
import static org.assertj.core.api.Assertions.assertThat;
18+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
19+
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_BAD_REQUEST;
20+
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_INTERNAL_SERVER_ERROR;
21+
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_OK;
22+
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.HEADER_CONSENSUS_VERSION;
23+
24+
import java.util.Locale;
25+
import okhttp3.mockwebserver.MockResponse;
26+
import okhttp3.mockwebserver.RecordedRequest;
27+
import org.junit.jupiter.api.BeforeEach;
28+
import org.junit.jupiter.api.TestTemplate;
29+
import tech.pegasys.teku.api.exceptions.RemoteServiceNotAvailableException;
30+
import tech.pegasys.teku.spec.SpecMilestone;
31+
import tech.pegasys.teku.spec.TestSpecContext;
32+
import tech.pegasys.teku.spec.datastructures.blocks.SignedBlockContainer;
33+
import tech.pegasys.teku.spec.datastructures.validator.BroadcastValidationLevel;
34+
import tech.pegasys.teku.spec.networks.Eth2Network;
35+
import tech.pegasys.teku.validator.remote.apiclient.ValidatorApiMethod;
36+
import tech.pegasys.teku.validator.remote.typedef.AbstractTypeDefRequestTestBase;
37+
38+
@TestSpecContext(
39+
milestone = {
40+
SpecMilestone.BELLATRIX,
41+
SpecMilestone.CAPELLA,
42+
SpecMilestone.DENEB,
43+
SpecMilestone.ELECTRA
44+
},
45+
network = Eth2Network.MINIMAL)
46+
public class SendSignedBlockRequestTest extends AbstractTypeDefRequestTestBase {
47+
private SignedBlockContainer block;
48+
private SendSignedBlockRequest request;
49+
50+
@BeforeEach
51+
public void setup() {
52+
request = new SendSignedBlockRequest(spec, mockWebServer.url("/"), okHttpClient, true);
53+
this.block =
54+
specMilestone.isGreaterThanOrEqualTo(SpecMilestone.DENEB)
55+
? dataStructureUtil.randomSignedBlockContents()
56+
: dataStructureUtil.randomSignedBeaconBlock();
57+
}
58+
59+
@TestTemplate
60+
public void shouldIncludeConsensusHeaderInJsonRequest() throws InterruptedException {
61+
request = new SendSignedBlockRequest(spec, mockWebServer.url("/"), okHttpClient, false);
62+
mockWebServer.enqueue(new MockResponse().setResponseCode(SC_OK));
63+
64+
request.submit(block, BroadcastValidationLevel.NOT_REQUIRED);
65+
66+
final RecordedRequest recordedRequest = mockWebServer.takeRequest();
67+
assertThat(recordedRequest.getMethod()).isEqualTo("POST");
68+
assertThat(recordedRequest.getPath())
69+
.contains(ValidatorApiMethod.SEND_SIGNED_BLOCK_V2.getPath(emptyMap()));
70+
assertThat(recordedRequest.getHeader(HEADER_CONSENSUS_VERSION))
71+
.isEqualTo(specMilestone.name().toLowerCase(Locale.ROOT));
72+
assertThat(recordedRequest.getHeader("Content-Type")).contains("json");
73+
}
74+
75+
@TestTemplate
76+
public void shouldIncludeConsensusHeaderInSszRequest() throws InterruptedException {
77+
mockWebServer.enqueue(new MockResponse().setResponseCode(SC_OK));
78+
79+
request.submit(block, BroadcastValidationLevel.NOT_REQUIRED);
80+
81+
final RecordedRequest recordedRequest = mockWebServer.takeRequest();
82+
assertThat(recordedRequest.getMethod()).isEqualTo("POST");
83+
assertThat(recordedRequest.getPath())
84+
.contains(ValidatorApiMethod.SEND_SIGNED_BLOCK_V2.getPath(emptyMap()));
85+
assertThat(recordedRequest.getHeader(HEADER_CONSENSUS_VERSION))
86+
.isEqualTo(specMilestone.name().toLowerCase(Locale.ROOT));
87+
assertThat(recordedRequest.getHeader("Content-Type")).contains("octet");
88+
}
89+
90+
@TestTemplate
91+
void handle500() {
92+
mockWebServer.enqueue(new MockResponse().setResponseCode(SC_INTERNAL_SERVER_ERROR));
93+
assertThatThrownBy(() -> request.submit(block, BroadcastValidationLevel.NOT_REQUIRED))
94+
.isInstanceOf(RemoteServiceNotAvailableException.class);
95+
}
96+
97+
@TestTemplate
98+
void handle400() {
99+
mockWebServer.enqueue(
100+
new MockResponse()
101+
.setResponseCode(SC_BAD_REQUEST)
102+
.setBody("{\"code\": 400,\"message\": \"z\"}"));
103+
assertThatThrownBy(() -> request.submit(block, BroadcastValidationLevel.NOT_REQUIRED))
104+
.isInstanceOf(IllegalArgumentException.class)
105+
.hasMessageStartingWith("Invalid params response from Beacon Node API");
106+
}
107+
}

0 commit comments

Comments
 (0)