mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-29 20:27:14 +00:00
Fix http api tests ci (#7943)
Co-Authored-By: Jimmy Chen <jchen.tc@gmail.com> Co-Authored-By: Michael Sproul <micsproul@gmail.com> Co-Authored-By: Michael Sproul <michael@sigmaprime.io> Co-Authored-By: hopinheimer <knmanas6@gmail.com>
This commit is contained in:
@@ -1,14 +1,16 @@
|
||||
use beacon_chain::test_utils::RelativeSyncCommittee;
|
||||
use beacon_chain::{
|
||||
BeaconChain, ChainConfig, StateSkipConfig, WhenSlotSkipped,
|
||||
test_utils::{AttestationStrategy, BeaconChainHarness, BlockStrategy, EphemeralHarnessType},
|
||||
test_utils::{
|
||||
AttestationStrategy, BeaconChainHarness, BlockStrategy, EphemeralHarnessType, test_spec,
|
||||
},
|
||||
};
|
||||
use eth2::{
|
||||
BeaconNodeHttpClient, Error,
|
||||
Error::ServerMessage,
|
||||
StatusCode, Timeouts,
|
||||
mixin::{RequestAccept, ResponseForkName, ResponseOptional},
|
||||
reqwest::RequestBuilder,
|
||||
reqwest::{RequestBuilder, Response},
|
||||
types::{
|
||||
BlockId as CoreBlockId, ForkChoiceNode, ProduceBlockV3Response, StateId as CoreStateId, *,
|
||||
},
|
||||
@@ -113,15 +115,11 @@ impl ApiTester {
|
||||
Self::new_from_config(ApiTesterConfig::default()).await
|
||||
}
|
||||
|
||||
pub async fn new_with_hard_forks(altair: bool, bellatrix: bool) -> Self {
|
||||
let mut config = ApiTesterConfig::default();
|
||||
// Set whether the chain has undergone each hard fork.
|
||||
if altair {
|
||||
config.spec.altair_fork_epoch = Some(Epoch::new(0));
|
||||
}
|
||||
if bellatrix {
|
||||
config.spec.bellatrix_fork_epoch = Some(Epoch::new(0));
|
||||
}
|
||||
pub async fn new_with_hard_forks() -> Self {
|
||||
let config = ApiTesterConfig {
|
||||
spec: test_spec::<E>(),
|
||||
..Default::default()
|
||||
};
|
||||
Self::new_from_config(config).await
|
||||
}
|
||||
|
||||
@@ -291,7 +289,19 @@ impl ApiTester {
|
||||
let beacon_api_port = listening_socket.port();
|
||||
let beacon_url =
|
||||
SensitiveUrl::parse(format!("http://127.0.0.1:{beacon_api_port}").as_str()).unwrap();
|
||||
let mock_builder_server = harness.set_mock_builder(beacon_url.clone());
|
||||
|
||||
// Be strict with validator registrations, but don't bother applying operations, that flag
|
||||
// is only used by mock-builder tests.
|
||||
let strict_registrations = true;
|
||||
let apply_operations = true;
|
||||
let broadcast_to_bn = true;
|
||||
|
||||
let mock_builder_server = harness.set_mock_builder(
|
||||
beacon_url.clone(),
|
||||
strict_registrations,
|
||||
apply_operations,
|
||||
broadcast_to_bn,
|
||||
);
|
||||
|
||||
// Start the mock builder service prior to building the chain out.
|
||||
harness
|
||||
@@ -334,6 +344,7 @@ impl ApiTester {
|
||||
.deterministic_keypairs(VALIDATOR_COUNT)
|
||||
.deterministic_withdrawal_keypairs(VALIDATOR_COUNT)
|
||||
.fresh_ephemeral_store()
|
||||
.mock_execution_layer()
|
||||
.build(),
|
||||
);
|
||||
|
||||
@@ -419,7 +430,7 @@ impl ApiTester {
|
||||
}
|
||||
|
||||
pub async fn new_mev_tester() -> Self {
|
||||
let tester = Self::new_with_hard_forks(true, true)
|
||||
let tester = Self::new_with_hard_forks()
|
||||
.await
|
||||
.test_post_validator_register_validator()
|
||||
.await;
|
||||
@@ -1539,7 +1550,10 @@ impl ApiTester {
|
||||
pub async fn test_post_beacon_blocks_valid(mut self) -> Self {
|
||||
let next_block = self.next_block.clone();
|
||||
|
||||
self.client.post_beacon_blocks(&next_block).await.unwrap();
|
||||
self.client
|
||||
.post_beacon_blocks_v2(&next_block, None)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert!(
|
||||
self.network_rx.network_recv.recv().await.is_some(),
|
||||
@@ -1553,7 +1567,7 @@ impl ApiTester {
|
||||
let next_block = &self.next_block;
|
||||
|
||||
self.client
|
||||
.post_beacon_blocks_ssz(next_block)
|
||||
.post_beacon_blocks_v2_ssz(next_block, None)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -1578,12 +1592,14 @@ impl ApiTester {
|
||||
.await
|
||||
.0;
|
||||
|
||||
assert!(
|
||||
self.client
|
||||
.post_beacon_blocks(&PublishBlockRequest::from(block))
|
||||
.await
|
||||
.is_err()
|
||||
);
|
||||
let response: Result<Response, Error> = self
|
||||
.client
|
||||
.post_beacon_blocks_v2(&PublishBlockRequest::from(block), None)
|
||||
.await;
|
||||
|
||||
assert!(response.is_ok());
|
||||
|
||||
assert_eq!(response.unwrap().status(), StatusCode::ACCEPTED);
|
||||
|
||||
assert!(
|
||||
self.network_rx.network_recv.recv().await.is_some(),
|
||||
@@ -1606,13 +1622,13 @@ impl ApiTester {
|
||||
.await
|
||||
.0;
|
||||
|
||||
assert!(
|
||||
self.client
|
||||
.post_beacon_blocks_ssz(&PublishBlockRequest::from(block))
|
||||
.await
|
||||
.is_err()
|
||||
);
|
||||
let response: Result<Response, Error> = self
|
||||
.client
|
||||
.post_beacon_blocks_v2(&PublishBlockRequest::from(block), None)
|
||||
.await;
|
||||
|
||||
assert!(response.is_ok());
|
||||
assert_eq!(response.unwrap().status(), StatusCode::ACCEPTED);
|
||||
assert!(
|
||||
self.network_rx.network_recv.recv().await.is_some(),
|
||||
"gossip valid blocks should be sent to network"
|
||||
@@ -1634,7 +1650,7 @@ impl ApiTester {
|
||||
|
||||
assert!(
|
||||
self.client
|
||||
.post_beacon_blocks(&block_contents)
|
||||
.post_beacon_blocks_v2(&block_contents, None)
|
||||
.await
|
||||
.is_ok()
|
||||
);
|
||||
@@ -1644,45 +1660,25 @@ impl ApiTester {
|
||||
|
||||
// Test all the POST methods in sequence, they should all behave the same.
|
||||
let responses = vec![
|
||||
self.client
|
||||
.post_beacon_blocks(&block_contents)
|
||||
.await
|
||||
.unwrap_err(),
|
||||
self.client
|
||||
.post_beacon_blocks_v2(&block_contents, None)
|
||||
.await
|
||||
.unwrap_err(),
|
||||
self.client
|
||||
.post_beacon_blocks_ssz(&block_contents)
|
||||
.await
|
||||
.unwrap_err(),
|
||||
.unwrap(),
|
||||
self.client
|
||||
.post_beacon_blocks_v2_ssz(&block_contents, None)
|
||||
.await
|
||||
.unwrap_err(),
|
||||
self.client
|
||||
.post_beacon_blinded_blocks(&blinded_block_contents)
|
||||
.await
|
||||
.unwrap_err(),
|
||||
.unwrap(),
|
||||
self.client
|
||||
.post_beacon_blinded_blocks_v2(&blinded_block_contents, None)
|
||||
.await
|
||||
.unwrap_err(),
|
||||
self.client
|
||||
.post_beacon_blinded_blocks_ssz(&blinded_block_contents)
|
||||
.await
|
||||
.unwrap_err(),
|
||||
.unwrap(),
|
||||
self.client
|
||||
.post_beacon_blinded_blocks_v2_ssz(&blinded_block_contents, None)
|
||||
.await
|
||||
.unwrap_err(),
|
||||
.unwrap(),
|
||||
];
|
||||
for (i, response) in responses.into_iter().enumerate() {
|
||||
assert_eq!(
|
||||
response.status().unwrap(),
|
||||
StatusCode::ACCEPTED,
|
||||
"response {i}"
|
||||
);
|
||||
assert_eq!(response.status(), StatusCode::ACCEPTED, "response {i}");
|
||||
}
|
||||
|
||||
self
|
||||
@@ -3405,7 +3401,7 @@ impl ApiTester {
|
||||
PublishBlockRequest::try_from(Arc::new(signed_block.clone())).unwrap();
|
||||
|
||||
self.client
|
||||
.post_beacon_blocks(&signed_block_contents)
|
||||
.post_beacon_blocks_v2(&signed_block_contents, None)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -3470,7 +3466,7 @@ impl ApiTester {
|
||||
block_contents.sign(&sk, &fork, genesis_validators_root, &self.chain.spec);
|
||||
|
||||
self.client
|
||||
.post_beacon_blocks_ssz(&signed_block_contents)
|
||||
.post_beacon_blocks_v2_ssz(&signed_block_contents, None)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -3588,7 +3584,7 @@ impl ApiTester {
|
||||
block_contents.sign(&sk, &fork, genesis_validators_root, &self.chain.spec);
|
||||
|
||||
self.client
|
||||
.post_beacon_blocks_ssz(&signed_block_contents)
|
||||
.post_beacon_blocks_v2_ssz(&signed_block_contents, None)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -6394,7 +6390,7 @@ impl ApiTester {
|
||||
});
|
||||
|
||||
self.client
|
||||
.post_beacon_blocks(&self.next_block)
|
||||
.post_beacon_blocks_v2(&self.next_block, None)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -6439,7 +6435,7 @@ impl ApiTester {
|
||||
self.harness.advance_slot();
|
||||
|
||||
self.client
|
||||
.post_beacon_blocks(&self.reorg_block)
|
||||
.post_beacon_blocks_v2(&self.reorg_block, None)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -6661,7 +6657,7 @@ impl ApiTester {
|
||||
});
|
||||
|
||||
self.client
|
||||
.post_beacon_blocks(&self.next_block)
|
||||
.post_beacon_blocks_v2(&self.next_block, None)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -7829,7 +7825,7 @@ async fn lighthouse_endpoints() {
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn optimistic_responses() {
|
||||
ApiTester::new_with_hard_forks(true, true)
|
||||
ApiTester::new_with_hard_forks()
|
||||
.await
|
||||
.test_check_optimistic_responses()
|
||||
.await;
|
||||
|
||||
Reference in New Issue
Block a user