Skip to content

Commit aded743

Browse files
committed
fix: mock crate.
1 parent e3946ce commit aded743

File tree

11 files changed

+721
-0
lines changed

11 files changed

+721
-0
lines changed

Cargo.lock

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
resolver = "2"
44

55
members = [
6+
"protocol-units/mcr/util/*",
7+
"protocol-units/mcr/clients/*",
68
"protocol-units/mcr/client",
79
"protocol-units/mcr/manager",
810
"protocol-units/post-confirmations/*",
@@ -64,6 +66,9 @@ tokio = { version = "1.35.1", features = ["full", "tracing"] }
6466
tokio-stream = "0.1.15"
6567

6668
# internal
69+
## mcr
70+
mcr-types = { path = "protocol-units/mcr/util/types" }
71+
mcr-client-util = { path = "protocol-units/mcr/clients/util" }
6772
mcr-settlement-client = { path = "protocol-units/mcr/client" }
6873

6974
[workspace.lints.clippy]
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
[package]
2+
name = "mcr-client-eth"
3+
version = { workspace = true }
4+
edition = { workspace = true }
5+
license = { workspace = true }
6+
authors = { workspace = true }
7+
homepage = { workspace = true }
8+
publish = { workspace = true }
9+
rust-version = { workspace = true }
10+
11+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
12+
# [[bin]]
13+
# name = "test-mcr-settlement-client"
14+
# path = "src/bin/e2e/test_client_settlement.rs"
15+
16+
17+
[dependencies]
18+
alloy = { workspace = true, features = [
19+
"node-bindings",
20+
"rpc-types-trace",
21+
"json-rpc",
22+
"rpc-client",
23+
"signers",
24+
"signer-yubihsm",
25+
"pubsub",
26+
"providers",
27+
] }
28+
alloy-contract = { workspace = true }
29+
alloy-network = { workspace = true }
30+
alloy-primitives = { workspace = true }
31+
alloy-provider = { workspace = true, features = [] }
32+
alloy-signer = { workspace = true }
33+
alloy-sol-types = { workspace = true }
34+
alloy-transport = { workspace = true }
35+
alloy-transport-ws = { workspace = true }
36+
37+
anyhow = { workspace = true }
38+
async-stream = { workspace = true }
39+
async-trait = { workspace = true }
40+
serde_json = { workspace = true }
41+
thiserror = { workspace = true }
42+
tokio = { workspace = true }
43+
tokio-stream = { workspace = true }
44+
tracing = { workspace = true }
45+
serde = { workspace = true }
46+
47+
48+
alloy-rpc-types = { workspace = true }
49+
futures = { workspace = true }
50+
tracing-subscriber = { workspace = true }
51+
mcr-types = { workspace = true }
52+
53+
[features]
54+
default = ["eth"]
55+
e2e = ["eth"]
56+
eth = []
57+
mock = []
58+
59+
[lints]
60+
workspace = true
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
use mcr_types::block_commitment::Commitment as BlockCommitment;
2+
use tokio_stream::Stream;
3+
4+
/// Errors thrown by the McrClient.
5+
#[derive(Debug, thiserror::Error)]
6+
pub enum McrClientError {
7+
#[error("failed to post block commitment: {0}")]
8+
PostBlockCommitment(#[source] Box<dyn std::error::Error + Send + Sync>),
9+
#[error("failed to invoke admin function: {0}")]
10+
AdminFunction(#[source] Box<dyn std::error::Error + Send + Sync>),
11+
#[error("failed to stream block commitments: {0}")]
12+
StreamBlockCommitments(#[source] Box<dyn std::error::Error + Send + Sync>),
13+
#[error("failed to get commitment: {0}")]
14+
GetCommitment(#[source] Box<dyn std::error::Error + Send + Sync>),
15+
#[error("internal error: {0}")]
16+
Internal(#[source] Box<dyn std::error::Error + Send + Sync>),
17+
}
18+
19+
type CommitmentStream =
20+
std::pin::Pin<Box<dyn Stream<Item = Result<BlockCommitment, anyhow::Error>> + Send>>;
21+
22+
#[async_trait::async_trait]
23+
pub trait McrClientOperations {
24+
/// Posts a block commitment to the settlement client.
25+
async fn post_block_commitment(
26+
&self,
27+
block_commitment: BlockCommitment,
28+
) -> Result<(), McrClientError>;
29+
30+
/// Posts a batch of block commitments to the settlement client.
31+
async fn post_block_commitment_batch(
32+
&self,
33+
block_commitment: Vec<BlockCommitment>,
34+
) -> Result<(), McrClientError>;
35+
36+
/// Forces a block commitment
37+
/// This will only work in admin mode
38+
async fn force_block_commitment(
39+
&self,
40+
block_commitment: BlockCommitment,
41+
) -> Result<(), McrClientError>;
42+
43+
/// Streams block commitments from the settlement client.
44+
async fn stream_block_commitments(&self) -> Result<CommitmentStream, McrClientError>;
45+
46+
/// Gets the accepted commitment at the given height.
47+
async fn get_commitment_at_height(
48+
&self,
49+
height: u64,
50+
) -> Result<Option<BlockCommitment>, McrClientError>;
51+
52+
/// Gets the commitment this validator has made at a given height
53+
async fn get_posted_commitment_at_height(
54+
&self,
55+
height: u64,
56+
) -> Result<Option<BlockCommitment>, McrClientError>;
57+
58+
/// Gets the max tolerable block height.
59+
async fn get_max_tolerable_block_height(&self) -> Result<u64, McrClientError>;
60+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[package]
2+
name = "mcr-client-mock"
3+
version = { workspace = true }
4+
edition = { workspace = true }
5+
license = { workspace = true }
6+
authors = { workspace = true }
7+
homepage = { workspace = true }
8+
publish = { workspace = true }
9+
rust-version = { workspace = true }
10+
11+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
12+
# [[bin]]
13+
# name = "test-mcr-settlement-client"
14+
# path = "src/bin/e2e/test_client_settlement.rs"
15+
16+
17+
[dependencies]
18+
thiserror = { workspace = true }
19+
tokio = { workspace = true }
20+
tokio-stream = { workspace = true }
21+
tracing = { workspace = true }
22+
serde = { workspace = true, features = ["derive"] }
23+
mcr-types = { workspace = true }
24+
mcr-client-util = { workspace = true }
25+
anyhow = { workspace = true }
26+
futures = { workspace = true}
27+
28+
[features]
29+
default = ["eth"]
30+
e2e = ["eth"]
31+
eth = []
32+
mock = []
33+
34+
[lints]
35+
workspace = true

0 commit comments

Comments
 (0)