Skip to content

Commit

Permalink
add missing files for last commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Lilyjjo committed Oct 9, 2024
1 parent 62e65b3 commit bd37417
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion charts/composer/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ data:
ASTRIA_COMPOSER_API_LISTEN_ADDR: "0.0.0.0:{{ .Values.ports.healthApi }}"
ASTRIA_COMPOSER_GRPC_ADDR: "0.0.0.0:{{ .Values.ports.grpc }}"
ASTRIA_COMPOSER_SEQUENCER_CHAIN_ID: "{{ tpl .Values.config.sequencerChainId . }}"
ASTRIA_COMPOSER_SEQUENCER_HTTP_URL: "{{ tpl .Values.config.sequencerRpc . }}"
ASTRIA_COMPOSER_COMETBFT_ENDPOINT: "{{ tpl .Values.config.sequencerRpc . }}"
ASTRIA_COMPOSER_SEQUENCER_GRPC_URL: "{{ tpl .Values.config.sequencerGrpc . }}"
ASTRIA_COMPOSER_ROLLUPS: "{{ include "composer.rollups" . }}"
ASTRIA_COMPOSER_PRIVATE_KEY_FILE: "/var/secrets/{{ .Values.config.privateKey.secret.filename }}"
Expand Down
7 changes: 7 additions & 0 deletions crates/astria-grpc-mock/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ rust-version = "1.81.0"

[dependencies]
assert-json-diff = "2.0.2"
astria-eyre = { path = "../astria-eyre" }
erased-serde = "0.4.4"
futures.workspace = true
indenter = "0.3.3"
Expand All @@ -17,3 +18,9 @@ serde_json.workspace = true
tokio.workspace = true
tonic.workspace = true
tracing.workspace = true
tokio-stream = { workspace = true, features = ["net"] }
astria-core = { path = "../astria-core", features = [
"client",
"serde",
"server",
] }
1 change: 1 addition & 0 deletions crates/astria-grpc-mock/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::any::Any;

pub mod matcher;
mod mock;
pub mod mock_grpc_sequencer;
mod mock_server;
mod mock_set;
mod mounted_mock;
Expand Down
121 changes: 121 additions & 0 deletions crates/astria-grpc-mock/src/mock_grpc_sequencer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
use std::{
net::SocketAddr,
sync::Arc,
};

use astria_core::{
self,
generated::sequencerblock::v1alpha1::{
sequencer_service_server::{
SequencerService,
SequencerServiceServer,
},
FilteredSequencerBlock as RawFilteredSequencerBlock,
GetFilteredSequencerBlockRequest,
GetPendingNonceRequest,
GetPendingNonceResponse,
GetSequencerBlockRequest,
SequencerBlock as RawSequencerBlock,
},
};
use astria_eyre::eyre::{
self,
WrapErr as _,
};
use tokio::task::JoinHandle;
use tonic::{
transport::Server,
Request,
Response,
Status,
};

use crate::{
matcher::message_type,
response::constant_response,
Mock,
MockServer,
};

const GET_PENDING_NONCE_GRPC_NAME: &str = "get_pending_nonce";

pub struct MockGrpcSequencer {
_server: JoinHandle<eyre::Result<()>>,
pub mock_server: MockServer,
pub local_addr: SocketAddr,
}

impl MockGrpcSequencer {
pub async fn spawn() -> Self {
use tokio_stream::wrappers::TcpListenerStream;

let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
let local_addr = listener.local_addr().unwrap();

let mock_server = MockServer::new();

let server = {
let sequencer_service = SequencerServiceImpl(mock_server.clone());
tokio::spawn(async move {
Server::builder()
.add_service(SequencerServiceServer::new(sequencer_service))
.serve_with_incoming(TcpListenerStream::new(listener))
.await
.wrap_err("gRPC sequencer server failed")
})
};
Self {
_server: server,
mock_server,
local_addr,
}
}

pub async fn mount_pending_nonce_response(
&self,
nonce_to_mount: u32,
debug_name: impl Into<String>,
) {
let resp = GetPendingNonceResponse {
inner: nonce_to_mount,
};
Mock::for_rpc_given(
GET_PENDING_NONCE_GRPC_NAME,
message_type::<GetPendingNonceRequest>(),
)
.respond_with(constant_response(resp))
.up_to_n_times(1)
.expect(1)
.with_name(debug_name)
.mount(&self.mock_server)
.await;
}
}

struct SequencerServiceImpl(MockServer);

#[tonic::async_trait]
impl SequencerService for SequencerServiceImpl {
async fn get_sequencer_block(
self: Arc<Self>,
_request: Request<GetSequencerBlockRequest>,
) -> Result<Response<RawSequencerBlock>, Status> {
unimplemented!()
}

async fn get_filtered_sequencer_block(
self: Arc<Self>,
_request: Request<GetFilteredSequencerBlockRequest>,
) -> Result<Response<RawFilteredSequencerBlock>, Status> {
unimplemented!()
}

async fn get_pending_nonce(
self: Arc<Self>,
request: Request<GetPendingNonceRequest>,
) -> Result<Response<GetPendingNonceResponse>, Status> {
self.0
.handle_request(GET_PENDING_NONCE_GRPC_NAME, request)
.await
}
}

0 comments on commit bd37417

Please sign in to comment.