Skip to content

Commit 4dbc83a

Browse files
chong-heeserilev
authored andcommitted
Add version to the response of beacon API client side (sigp#8326)
Co-Authored-By: Tan Chee Keong <[email protected]>
1 parent 344b8f6 commit 4dbc83a

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

beacon_node/http_api/tests/tests.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,12 +1316,14 @@ impl ApiTester {
13161316
.ok()
13171317
.map(|(state, _execution_optimistic, _finalized)| state);
13181318

1319-
let result = self
1319+
let result = match self
13201320
.client
13211321
.get_beacon_states_pending_deposits(state_id.0)
13221322
.await
1323-
.unwrap()
1324-
.map(|res| res.data);
1323+
{
1324+
Ok(response) => response,
1325+
Err(e) => panic!("query failed incorrectly: {e:?}"),
1326+
};
13251327

13261328
if result.is_none() && state_opt.is_none() {
13271329
continue;
@@ -1330,7 +1332,12 @@ impl ApiTester {
13301332
let state = state_opt.as_mut().expect("result should be none");
13311333
let expected = state.pending_deposits().unwrap();
13321334

1333-
assert_eq!(result.unwrap(), expected.to_vec());
1335+
let response = result.unwrap();
1336+
assert_eq!(response.data(), &expected.to_vec());
1337+
1338+
// Check that the version header is returned in the response
1339+
let fork_name = state.fork_name(&self.chain.spec).unwrap();
1340+
assert_eq!(response.version(), Some(fork_name),);
13341341
}
13351342

13361343
self
@@ -1343,12 +1350,14 @@ impl ApiTester {
13431350
.ok()
13441351
.map(|(state, _execution_optimistic, _finalized)| state);
13451352

1346-
let result = self
1353+
let result = match self
13471354
.client
13481355
.get_beacon_states_pending_partial_withdrawals(state_id.0)
13491356
.await
1350-
.unwrap()
1351-
.map(|res| res.data);
1357+
{
1358+
Ok(response) => response,
1359+
Err(e) => panic!("query failed incorrectly: {e:?}"),
1360+
};
13521361

13531362
if result.is_none() && state_opt.is_none() {
13541363
continue;
@@ -1357,7 +1366,12 @@ impl ApiTester {
13571366
let state = state_opt.as_mut().expect("result should be none");
13581367
let expected = state.pending_partial_withdrawals().unwrap();
13591368

1360-
assert_eq!(result.unwrap(), expected.to_vec());
1369+
let response = result.unwrap();
1370+
assert_eq!(response.data(), &expected.to_vec());
1371+
1372+
// Check that the version header is returned in the response
1373+
let fork_name = state.fork_name(&self.chain.spec).unwrap();
1374+
assert_eq!(response.version(), Some(fork_name),);
13611375
}
13621376

13631377
self

common/eth2/src/lib.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,8 @@ impl BeaconNodeHttpClient {
827827
pub async fn get_beacon_states_pending_deposits(
828828
&self,
829829
state_id: StateId,
830-
) -> Result<Option<ExecutionOptimisticFinalizedResponse<Vec<PendingDeposit>>>, Error> {
830+
) -> Result<Option<ExecutionOptimisticFinalizedBeaconResponse<Vec<PendingDeposit>>>, Error>
831+
{
831832
let mut path = self.eth_path(V1)?;
832833

833834
path.path_segments_mut()
@@ -837,7 +838,9 @@ impl BeaconNodeHttpClient {
837838
.push(&state_id.to_string())
838839
.push("pending_deposits");
839840

840-
self.get_opt(path).await
841+
self.get_fork_contextual(path, |fork| fork)
842+
.await
843+
.map(|opt| opt.map(BeaconResponse::ForkVersioned))
841844
}
842845

843846
/// `GET beacon/states/{state_id}/pending_partial_withdrawals`
@@ -846,8 +849,10 @@ impl BeaconNodeHttpClient {
846849
pub async fn get_beacon_states_pending_partial_withdrawals(
847850
&self,
848851
state_id: StateId,
849-
) -> Result<Option<ExecutionOptimisticFinalizedResponse<Vec<PendingPartialWithdrawal>>>, Error>
850-
{
852+
) -> Result<
853+
Option<ExecutionOptimisticFinalizedBeaconResponse<Vec<PendingPartialWithdrawal>>>,
854+
Error,
855+
> {
851856
let mut path = self.eth_path(V1)?;
852857

853858
path.path_segments_mut()
@@ -857,7 +862,9 @@ impl BeaconNodeHttpClient {
857862
.push(&state_id.to_string())
858863
.push("pending_partial_withdrawals");
859864

860-
self.get_opt(path).await
865+
self.get_fork_contextual(path, |fork| fork)
866+
.await
867+
.map(|opt| opt.map(BeaconResponse::ForkVersioned))
861868
}
862869

863870
/// `GET beacon/states/{state_id}/pending_consolidations`

0 commit comments

Comments
 (0)