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

Beefy worker tests #1

Closed
wants to merge 2 commits into from
Closed
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
7 changes: 7 additions & 0 deletions Cargo.lock

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

11 changes: 9 additions & 2 deletions client/beefy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,23 @@ sp-keystore = { version = "0.11.0", path = "../../primitives/keystore" }
sp-runtime = { version = "5.0.0", path = "../../primitives/runtime" }

sc-chain-spec = { version = "4.0.0-dev", path = "../../client/chain-spec" }
sc-utils = { version = "4.0.0-dev", path = "../utils" }
sc-client-api = { version = "4.0.0-dev", path = "../api" }
sc-finality-grandpa = { version = "0.10.0-dev", path = "../../client/finality-grandpa" }
sc-keystore = { version = "4.0.0-dev", path = "../keystore" }
sc-network = { version = "0.10.0-dev", path = "../network" }
sc-network-gossip = { version = "0.10.0-dev", path = "../network-gossip" }
sc-utils = { version = "4.0.0-dev", path = "../utils" }

beefy-primitives = { version = "4.0.0-dev", path = "../../primitives/beefy" }

[dev-dependencies]
sp-tracing = { version = "4.0.0", path = "../../primitives/tracing" }
sc-consensus = { version = "0.10.0-dev", path = "../consensus/common" }
sc-network-test = { version = "0.8.0", path = "../network/test" }
sp-finality-grandpa = { version = "4.0.0-dev", path = "../../primitives/finality-grandpa" }
sp-keyring = { version = "5.0.0", path = "../../primitives/keyring" }
sp-tracing = { version = "4.0.0", path = "../../primitives/tracing" }
substrate-test-runtime-client = { version = "2.0.0", path = "../../test-utils/runtime/client" }

strum = { version = "0.23", features = ["derive"] }
tokio = "1.15"
tempfile = "3.1.0"
22 changes: 16 additions & 6 deletions client/beefy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ mod round;
mod worker;

pub mod notification;

#[cfg(test)]
mod tests;

pub use beefy_protocol_name::standard_name as protocol_standard_name;

pub(crate) mod beefy_protocol_name {
Expand Down Expand Up @@ -83,7 +87,7 @@ pub fn beefy_peers_set_config(
/// of today, Rust does not allow a type alias to be used as a trait bound. Tracking
/// issue is <https://github.com/rust-lang/rust/issues/41517>.
pub trait Client<B, BE>:
BlockchainEvents<B> + HeaderBackend<B> + Finalizer<B, BE> + ProvideRuntimeApi<B> + Send + Sync
BlockchainEvents<B> + HeaderBackend<B> + Finalizer<B, BE> + Send + Sync
where
B: Block,
BE: Backend<B>,
Expand All @@ -106,18 +110,21 @@ where
}

/// BEEFY gadget initialization parameters.
pub struct BeefyParams<B, BE, C, N>
pub struct BeefyParams<B, BE, C, N, R>
where
B: Block,
BE: Backend<B>,
C: Client<B, BE>,
C::Api: BeefyApi<B>,
R: ProvideRuntimeApi<B>,
R::Api: BeefyApi<B>,
Comment on lines +118 to +119
Copy link
Owner Author

@acatangiu acatangiu Feb 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed because test client doesn't impl ProvideRuntimeApi.

If I get these tests working I will look for a better way that avoids adding this extra generic (maybe just have test client impl some customizable ProvideRuntimeApi mock).

N: GossipNetwork<B> + Clone + Send + 'static,
{
/// BEEFY client
pub client: Arc<C>,
/// Client Backend
pub backend: Arc<BE>,
/// Runtime Api Provider
pub runtime: Arc<R>,
/// Local key store
pub key_store: Option<SyncCryptoStorePtr>,
/// Gossip network
Expand All @@ -137,17 +144,19 @@ where
/// Start the BEEFY gadget.
///
/// This is a thin shim around running and awaiting a BEEFY worker.
pub async fn start_beefy_gadget<B, BE, C, N>(beefy_params: BeefyParams<B, BE, C, N>)
pub async fn start_beefy_gadget<B, BE, C, N, R>(beefy_params: BeefyParams<B, BE, C, N, R>)
where
B: Block,
BE: Backend<B>,
C: Client<B, BE>,
C::Api: BeefyApi<B>,
R: ProvideRuntimeApi<B>,
R::Api: BeefyApi<B>,
N: GossipNetwork<B> + Clone + Send + 'static,
{
let BeefyParams {
client,
backend,
runtime,
key_store,
network,
signed_commitment_sender,
Expand Down Expand Up @@ -177,6 +186,7 @@ where
let worker_params = worker::WorkerParams {
client,
backend,
runtime,
key_store: key_store.into(),
signed_commitment_sender,
beefy_best_block_sender,
Expand All @@ -186,7 +196,7 @@ where
metrics,
};

let worker = worker::BeefyWorker::<_, _, _>::new(worker_params);
let worker = worker::BeefyWorker::<_, _, _, _>::new(worker_params);

worker.run().await
}
Loading