Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(conductor): clean up chain id tests #1765

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 27 additions & 99 deletions crates/astria-conductor/tests/blackbox/firm_only.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,18 @@
use std::time::Duration;

use astria_conductor::{
config::CommitLevel,
Conductor,
Config,
};
use astria_core::generated::execution::v1::{
GetCommitmentStateRequest,
GetGenesisInfoRequest,
use std::{
mem::ManuallyDrop,
time::Duration,
};

use astria_conductor::config::CommitLevel;
use futures::future::{
join,
join4,
};
use serde_json::json;
use telemetry::metrics;
use tokio::time::timeout;
use wiremock::{
matchers::{
body_partial_json,
header,
},
Mock,
ResponseTemplate,
};

use crate::{
celestia_network_head,
commitment_state,
genesis_info,
helpers::{
make_config,
spawn_conductor,
MockGrpc,
CELESTIA_BEARER_TOKEN,
CELESTIA_CHAIN_ID,
SEQUENCER_CHAIN_ID,
},
Expand Down Expand Up @@ -408,57 +387,17 @@ async fn fetch_from_later_celestia_height() {

#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn exits_on_celestia_chain_id_mismatch() {
use astria_grpc_mock::{
matcher,
response as GrpcResponse,
Mock as GrpcMock,
};

// FIXME (https://github.com/astriaorg/astria/issues/1602)
// We have to create our own test conductor and perform mounts manually because `TestConductor`
// implements the `Drop` trait, which disallows us from taking ownership of its tasks and
// awaiting their completion.

let mock_grpc = MockGrpc::spawn().await;
let mock_http = wiremock::MockServer::start().await;

let config = Config {
celestia_node_http_url: mock_http.uri(),
execution_rpc_url: format!("http://{}", mock_grpc.local_addr),
sequencer_cometbft_url: mock_http.uri(),
sequencer_grpc_url: format!("http://{}", mock_grpc.local_addr),
execution_commit_level: CommitLevel::FirmOnly,
..make_config()
};

let (metrics, _) = metrics::ConfigBuilder::new()
.set_global_recorder(false)
.build(&())
.unwrap();
let metrics = Box::leak(Box::new(metrics));

let conductor = {
let conductor = Conductor::new(config, metrics).unwrap();
conductor.spawn()
};

GrpcMock::for_rpc_given(
"get_genesis_info",
matcher::message_type::<GetGenesisInfoRequest>(),
)
.respond_with(GrpcResponse::constant_response(
genesis_info!(sequencer_genesis_block_height: 1,
celestia_block_variance: 10,),
))
.expect(0..)
.mount(&mock_grpc.mock_server)
.await;

GrpcMock::for_rpc_given(
"get_commitment_state",
matcher::message_type::<GetCommitmentStateRequest>(),
)
.respond_with(GrpcResponse::constant_response(commitment_state!(firm: (
let test_conductor = ManuallyDrop::new(spawn_conductor(CommitLevel::FirmOnly).await);

mount_get_genesis_info!(
test_conductor,
sequencer_genesis_block_height: 1,
celestia_block_variance: 10,
);

mount_get_commitment_state!(
test_conductor,
firm: (
number: 1,
hash: [1; 64],
parent: [0; 64],
Expand All @@ -468,31 +407,20 @@ async fn exits_on_celestia_chain_id_mismatch() {
hash: [1; 64],
parent: [0; 64],
),
base_celestia_height: 1,)))
.expect(0..)
.mount(&mock_grpc.mock_server)
.await;
base_celestia_height: 1,
);

let bad_chain_id = "bad_chain_id";

Mock::given(body_partial_json(
json!({"jsonrpc": "2.0", "method": "header.NetworkHead"}),
))
.and(header(
"authorization",
&*format!("Bearer {CELESTIA_BEARER_TOKEN}"),
))
.respond_with(ResponseTemplate::new(200).set_body_json(json!({
"jsonrpc": "2.0",
"id": 0,
"result": celestia_network_head!(height: 1u32, chain_id: bad_chain_id),
})))
.expect(1..)
.mount(&mock_http)
.await;

let res = conductor.await;
match res {
mount_celestia_header_network_head!(
test_conductor,
height: 1u32,
chain_id: bad_chain_id,
);

let conductor_res = unsafe { std::ptr::read(&test_conductor.conductor).await };

match conductor_res {
Ok(()) => panic!("conductor should have exited with an error, no error received"),
Err(e) => {
let mut source = e.source();
Expand Down
22 changes: 18 additions & 4 deletions crates/astria-conductor/tests/blackbox/helpers/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,25 @@ macro_rules! mount_celestia_blobs {
macro_rules! mount_celestia_header_network_head {
(
$test_env:ident,
height: $height:expr $(,)?
height: $height:expr,
chain_id: $chain_id:expr $(,)?
) => {
$test_env
.mount_celestia_header_network_head(
$crate::celestia_network_head!(height: $height, chain_id: $crate::helpers::CELESTIA_CHAIN_ID),
$crate::celestia_network_head!(height: $height, chain_id: $chain_id),
)
.await;
}
};
(
$test_env:ident,
height: $height:expr $(,)?
) => {
mount_celestia_header_network_head!(
$test_env,
height: $height,
chain_id: $crate::helpers::CELESTIA_CHAIN_ID,
)
};
}

#[macro_export]
Expand Down Expand Up @@ -367,8 +378,11 @@ macro_rules! mount_sequencer_validator_set {

#[macro_export]
macro_rules! mount_sequencer_genesis {
($test_env:ident, chain_id: $chain_id:expr $(,)?) => {
$test_env.mount_genesis($chain_id).await;
};
($test_env:ident) => {
$test_env.mount_genesis(SEQUENCER_CHAIN_ID).await;
mount_sequencer_genesis!($test_env, chain_id: SEQUENCER_CHAIN_ID)
};
}

Expand Down
10 changes: 5 additions & 5 deletions crates/astria-conductor/tests/blackbox/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use astria_core::{
},
primitive::v1::RollupId,
};
use astria_eyre;
use astria_grpc_mock::response::error_response;
use bytes::Bytes;
use celestia_types::{
Expand All @@ -34,16 +35,15 @@ use sequencer_client::{
tendermint_proto,
tendermint_rpc,
};
use serde_json::json;
use telemetry::metrics;
use tracing::debug;
use wiremock::MockServer;

#[macro_use]
mod macros;
mod mock_grpc;
use astria_eyre;
pub use mock_grpc::MockGrpc;
use serde_json::json;
use tracing::debug;
use wiremock::MockServer;

pub const CELESTIA_BEARER_TOKEN: &str = "ABCDEFGH";

Expand Down Expand Up @@ -450,7 +450,7 @@ impl TestConductor {
}
}

pub async fn mount_genesis(mock_http: &MockServer, chain_id: &str) {
async fn mount_genesis(mock_http: &MockServer, chain_id: &str) {
use tendermint::{
consensus::{
params::{
Expand Down
103 changes: 26 additions & 77 deletions crates/astria-conductor/tests/blackbox/soft_only.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,17 @@
use std::time::Duration;

use astria_conductor::{
config::CommitLevel,
Conductor,
Config,
};
use astria_core::generated::execution::v1::{
GetCommitmentStateRequest,
GetGenesisInfoRequest,
use std::{
mem::ManuallyDrop,
time::Duration,
};

use astria_conductor::config::CommitLevel;
use futures::future::{
join,
join4,
};
use telemetry::metrics;
use tokio::time::timeout;

use crate::{
commitment_state,
genesis_info,
helpers::{
make_config,
mount_genesis,
spawn_conductor,
MockGrpc,
},
helpers::spawn_conductor,
mount_abci_info,
mount_executed_block,
mount_get_commitment_state,
Expand Down Expand Up @@ -362,57 +349,17 @@ async fn requests_from_later_genesis_height() {

#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn exits_on_sequencer_chain_id_mismatch() {
use astria_grpc_mock::{
matcher,
response as GrpcResponse,
Mock as GrpcMock,
};

// FIXME (https://github.com/astriaorg/astria/issues/1602)
// We have to create our own test conductor and perform mounts manually because `TestConductor`
// implements the `Drop` trait, which disallows us from taking ownership of its tasks and
// awaiting their completion.

let mock_grpc = MockGrpc::spawn().await;
let mock_http = wiremock::MockServer::start().await;

let config = Config {
celestia_node_http_url: mock_http.uri(),
execution_rpc_url: format!("http://{}", mock_grpc.local_addr),
sequencer_cometbft_url: mock_http.uri(),
sequencer_grpc_url: format!("http://{}", mock_grpc.local_addr),
execution_commit_level: CommitLevel::SoftOnly,
..make_config()
};

let (metrics, _) = metrics::ConfigBuilder::new()
.set_global_recorder(false)
.build(&())
.unwrap();
let metrics = Box::leak(Box::new(metrics));

let conductor = {
let conductor = Conductor::new(config, metrics).unwrap();
conductor.spawn()
};

GrpcMock::for_rpc_given(
"get_genesis_info",
matcher::message_type::<GetGenesisInfoRequest>(),
)
.respond_with(GrpcResponse::constant_response(
genesis_info!(sequencer_genesis_block_height: 1,
celestia_block_variance: 10,),
))
.expect(0..)
.mount(&mock_grpc.mock_server)
.await;

GrpcMock::for_rpc_given(
"get_commitment_state",
matcher::message_type::<GetCommitmentStateRequest>(),
)
.respond_with(GrpcResponse::constant_response(commitment_state!(firm: (
let test_conductor = ManuallyDrop::new(spawn_conductor(CommitLevel::SoftOnly).await);

mount_get_genesis_info!(
test_conductor,
sequencer_genesis_block_height: 1,
celestia_block_variance: 10,
);

mount_get_commitment_state!(
test_conductor,
firm: (
number: 1,
hash: [1; 64],
parent: [0; 64],
Expand All @@ -422,16 +369,18 @@ async fn exits_on_sequencer_chain_id_mismatch() {
hash: [1; 64],
parent: [0; 64],
),
base_celestia_height: 1,)))
.expect(0..)
.mount(&mock_grpc.mock_server)
.await;
base_celestia_height: 1,
);

let bad_chain_id = "bad_chain_id";
mount_genesis(&mock_http, bad_chain_id).await;
mount_sequencer_genesis!(
test_conductor,
chain_id: bad_chain_id,
);

let conductor_res = unsafe { std::ptr::read(&test_conductor.conductor).await };

let res = conductor.await;
match res {
match conductor_res {
Ok(()) => panic!("conductor should have exited with an error, no error received"),
Err(e) => {
let mut source = e.source();
Expand Down
Loading