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

Use tokio instead of async-std #495

Merged
merged 4 commits into from
Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ description = "Subxt example usage"

[dev-dependencies]
subxt = { path = "../subxt" }
async-std = { version = "1.9.0", features = ["attributes", "tokio1"] }
tokio = { version = "1.8", features = ["rt-multi-thread", "macros", "time"] }
sp-keyring = "6.0.0"
env_logger = "0.9.0"
futures = "0.3.13"
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/balance_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use subxt::{
#[subxt::subxt(runtime_metadata_path = "examples/polkadot_metadata.scale")]
pub mod polkadot {}

#[async_std::main]
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/balance_transfer_with_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use subxt::{
#[subxt::subxt(runtime_metadata_path = "examples/polkadot_metadata.scale")]
pub mod polkadot {}

#[async_std::main]
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/custom_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl Config for MyConfig {
type Extrinsic = <DefaultConfig as Config>::Extrinsic;
}

#[async_std::main]
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api = ClientBuilder::new()
.build()
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/custom_type_derives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub mod polkadot {}

use polkadot::runtime_types::frame_support::PalletId;

#[async_std::main]
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let pallet_id = PalletId([1u8; 8]);
let _ = pallet_id.clone();
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/fetch_all_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use subxt::{
#[subxt::subxt(runtime_metadata_path = "examples/polkadot_metadata.scale")]
pub mod polkadot {}

#[async_std::main]
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/fetch_staking_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use subxt::{
#[subxt::subxt(runtime_metadata_path = "examples/polkadot_metadata.scale")]
pub mod polkadot {}

#[async_std::main]
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/rpc_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use subxt::{
#[subxt::subxt(runtime_metadata_path = "examples/polkadot_metadata.scale")]
pub mod polkadot {}

#[async_std::main]
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/submit_and_watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use subxt::{
#[subxt::subxt(runtime_metadata_path = "examples/polkadot_metadata.scale")]
pub mod polkadot {}

#[async_std::main]
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();

Expand Down
6 changes: 3 additions & 3 deletions examples/examples/subscribe_all_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub mod polkadot {}

/// Subscribe to all events, and then manually look through them and
/// pluck out the events that we care about.
#[async_std::main]
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();

Expand All @@ -50,7 +50,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut event_sub = api.events().subscribe().await?;

// While this subscription is active, balance transfers are made somewhere:
async_std::task::spawn(async {
tokio::task::spawn(async {
let signer = PairSigner::new(AccountKeyring::Alice.pair());
let api =
ClientBuilder::new()
Expand All @@ -73,7 +73,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.await
.unwrap();

async_std::task::sleep(Duration::from_secs(10)).await;
tokio::time::sleep(Duration::from_secs(10)).await;
transfer_amount += 100_000_000;
}
});
Expand Down
6 changes: 3 additions & 3 deletions examples/examples/subscribe_one_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub mod polkadot {}

/// Subscribe to all events, and then manually look through them and
/// pluck out the events that we care about.
#[async_std::main]
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();

Expand All @@ -56,7 +56,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.filter_events::<(polkadot::balances::events::Transfer,)>();

// While this subscription is active, we imagine some balance transfers are made somewhere else:
async_std::task::spawn(async {
tokio::task::spawn(async {
let signer = PairSigner::new(AccountKeyring::Alice.pair());
let api =
ClientBuilder::new()
Expand All @@ -76,7 +76,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.sign_and_submit_default(&signer)
.await
.unwrap();
async_std::task::sleep(Duration::from_secs(10)).await;
tokio::time::sleep(Duration::from_secs(10)).await;
}
});

Expand Down
6 changes: 3 additions & 3 deletions examples/examples/subscribe_some_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub mod polkadot {}

/// Subscribe to all events, and then manually look through them and
/// pluck out the events that we care about.
#[async_std::main]
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();

Expand All @@ -57,7 +57,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
)>();

// While this subscription is active, we imagine some balance transfers are made somewhere else:
async_std::task::spawn(async {
tokio::task::spawn(async {
let signer = PairSigner::new(AccountKeyring::Alice.pair());
let api =
ClientBuilder::new()
Expand All @@ -77,7 +77,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.sign_and_submit_default(&signer)
.await
.unwrap();
async_std::task::sleep(Duration::from_secs(10)).await;
tokio::time::sleep(Duration::from_secs(10)).await;
}
});

Expand Down
2 changes: 1 addition & 1 deletion subxt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ derivative = "2.2.0"
[dev-dependencies]
sp-arithmetic = { version = "5.0.0", default-features = false }
assert_matches = "1.5.0"
async-std = { version = "1.9.0", features = ["attributes", "tokio1"] }
tokio = { version = "1.8", features = ["macros", "time"] }
env_logger = "0.9.0"
tempdir = "0.3.7"
wabt = "0.10.0"
Expand Down
6 changes: 3 additions & 3 deletions subxt/src/events/filter_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ mod test {
.map(Ok::<_, BasicError>)
}

#[async_std::test]
#[tokio::test]
async fn filter_one_event_from_stream() {
let metadata = metadata::<PalletEvents>();

Expand Down Expand Up @@ -358,7 +358,7 @@ mod test {
assert_eq!(actual, expected);
}

#[async_std::test]
#[tokio::test]
async fn filter_some_events_from_stream() {
let metadata = metadata::<PalletEvents>();

Expand Down Expand Up @@ -406,7 +406,7 @@ mod test {
assert_eq!(actual, expected);
}

#[async_std::test]
#[tokio::test]
async fn filter_no_events_from_stream() {
let metadata = metadata::<PalletEvents>();

Expand Down
18 changes: 9 additions & 9 deletions subxt/tests/integration/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use sp_core::storage::{
};
use sp_keyring::AccountKeyring;

#[async_std::test]
#[tokio::test]
async fn insert_key() {
let test_node_process = test_node_process_with(AccountKeyring::Bob).await;
let client = test_node_process.client();
Expand All @@ -47,21 +47,21 @@ async fn insert_key() {
.unwrap());
}

#[async_std::test]
#[tokio::test]
async fn fetch_block_hash() {
let node_process = test_node_process().await;
node_process.client().rpc().block_hash(None).await.unwrap();
}

#[async_std::test]
#[tokio::test]
async fn fetch_block() {
let node_process = test_node_process().await;
let client = node_process.client();
let block_hash = client.rpc().block_hash(None).await.unwrap();
client.rpc().block(block_hash).await.unwrap();
}

#[async_std::test]
#[tokio::test]
async fn fetch_read_proof() {
let node_process = test_node_process().await;
let client = node_process.client();
Expand All @@ -79,23 +79,23 @@ async fn fetch_read_proof() {
.unwrap();
}

#[async_std::test]
#[tokio::test]
async fn chain_subscribe_blocks() {
let node_process = test_node_process().await;
let client = node_process.client();
let mut blocks = client.rpc().subscribe_blocks().await.unwrap();
blocks.next().await.unwrap().unwrap();
}

#[async_std::test]
#[tokio::test]
async fn chain_subscribe_finalized_blocks() {
let node_process = test_node_process().await;
let client = node_process.client();
let mut blocks = client.rpc().subscribe_finalized_blocks().await.unwrap();
blocks.next().await.unwrap().unwrap();
}

#[async_std::test]
#[tokio::test]
async fn fetch_keys() {
let node_process = test_node_process().await;
let client = node_process.client();
Expand All @@ -107,7 +107,7 @@ async fn fetch_keys() {
assert_eq!(keys.len(), 4)
}

#[async_std::test]
#[tokio::test]
async fn test_iter() {
let node_process = test_node_process().await;
let client = node_process.client();
Expand All @@ -123,7 +123,7 @@ async fn test_iter() {
assert_eq!(i, 13);
}

#[async_std::test]
#[tokio::test]
async fn fetch_system_info() {
let node_process = test_node_process().await;
let client = node_process.client();
Expand Down
14 changes: 7 additions & 7 deletions subxt/tests/integration/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use futures::StreamExt;
use sp_keyring::AccountKeyring;

// Check that we can subscribe to non-finalized block events.
#[async_std::test]
#[tokio::test]
async fn non_finalized_block_subscription() -> Result<(), subxt::BasicError> {
env_logger::try_init().ok();
let ctx = test_context().await;
Expand All @@ -44,7 +44,7 @@ async fn non_finalized_block_subscription() -> Result<(), subxt::BasicError> {
}

// Check that we can subscribe to finalized block events.
#[async_std::test]
#[tokio::test]
async fn finalized_block_subscription() -> Result<(), subxt::BasicError> {
env_logger::try_init().ok();
let ctx = test_context().await;
Expand All @@ -64,7 +64,7 @@ async fn finalized_block_subscription() -> Result<(), subxt::BasicError> {

// Check that our subscription actually keeps producing events for
// a few blocks.
#[async_std::test]
#[tokio::test]
async fn subscription_produces_events_each_block() -> Result<(), subxt::BasicError> {
env_logger::try_init().ok();
let ctx = test_context().await;
Expand Down Expand Up @@ -93,7 +93,7 @@ async fn subscription_produces_events_each_block() -> Result<(), subxt::BasicErr

// Check that our subscription receives events, and we can filter them based on
// it's Stream impl, and ultimately see the event we expect.
#[async_std::test]
#[tokio::test]
async fn balance_transfer_subscription() -> Result<(), subxt::BasicError> {
env_logger::try_init().ok();
let ctx = test_context().await;
Expand Down Expand Up @@ -135,7 +135,7 @@ async fn balance_transfer_subscription() -> Result<(), subxt::BasicError> {
Ok(())
}

#[async_std::test]
#[tokio::test]
async fn missing_block_headers_will_be_filled_in() -> Result<(), subxt::BasicError> {
// This function is not publically available to use, but contains
// the key logic for filling in missing blocks, so we want to test it.
Expand Down Expand Up @@ -194,7 +194,7 @@ async fn missing_block_headers_will_be_filled_in() -> Result<(), subxt::BasicErr
#[allow(unused)]
async fn check_events_are_sendable() {
// check that EventSubscription can be used across await points.
async_std::task::spawn(async {
tokio::task::spawn(async {
let ctx = test_context().await;

let mut event_sub = ctx.api.events().subscribe().await?;
Expand All @@ -209,7 +209,7 @@ async fn check_events_are_sendable() {
});

// Check that FilterEvents can be used across await points.
async_std::task::spawn(async {
tokio::task::spawn(async {
let ctx = test_context().await;

let mut event_sub = ctx
Expand Down