Skip to content

Commit

Permalink
Fix clippy.
Browse files Browse the repository at this point in the history
  • Loading branch information
kukabi committed Aug 1, 2022
1 parent 96a2f2e commit 530adda
Show file tree
Hide file tree
Showing 19 changed files with 116 additions and 137 deletions.
10 changes: 5 additions & 5 deletions subvt-telegram-bot/src/test/basic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{MessengerImpl, TelegramBot, DEFAULT_RULES};
async fn test_save_new_chat() {
let chat_id = get_random_chat_id();
let bot = new_test_bot(MockMessenger::new()).await.unwrap();
assert!(bot.save_or_restore_chat(chat_id).await.is_ok());
bot.save_or_restore_chat(chat_id).await.unwrap();
assert!(bot
.network_postgres
.chat_exists_by_id(chat_id)
Expand Down Expand Up @@ -41,18 +41,18 @@ async fn test_save_new_chat() {
async fn test_restore_chat_and_user() {
let bot: TelegramBot<MessengerImpl> = TelegramBot::<MessengerImpl>::new().await.unwrap();
let chat_id = 2;
assert!(bot.save_or_restore_chat(chat_id).await.is_ok());
bot.save_or_restore_chat(chat_id).await.unwrap();
let user_id = bot
.network_postgres
.get_chat_app_user_id(chat_id)
.await
.unwrap();
assert!(!bot.network_postgres.chat_is_deleted(chat_id).await.unwrap());
assert!(bot.network_postgres.delete_chat(chat_id).await.is_ok());
assert!(bot.app_postgres.delete_user(user_id).await.is_ok());
bot.network_postgres.delete_chat(chat_id).await.unwrap();
bot.app_postgres.delete_user(user_id).await.unwrap();
assert!(bot.network_postgres.chat_is_deleted(chat_id).await.unwrap());
assert!(!bot.app_postgres.user_exists_by_id(user_id).await.unwrap());
assert!(bot.save_or_restore_chat(chat_id).await.is_ok());
bot.save_or_restore_chat(chat_id).await.unwrap();
assert!(bot
.network_postgres
.chat_exists_by_id(chat_id)
Expand Down
4 changes: 2 additions & 2 deletions subvt-telegram-bot/src/test/command/about.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ async fn test_about() {
})
.returning(|_, _, _, _| Ok(get_telegram_message_response()));
let bot = new_test_bot(messenger).await.unwrap();
assert!(bot.save_or_restore_chat(chat_id).await.is_ok());
assert!(bot.process_command(chat_id, "/about", &[]).await.is_ok());
bot.save_or_restore_chat(chat_id).await.unwrap();
bot.process_command(chat_id, "/about", &[]).await.unwrap();
}
32 changes: 14 additions & 18 deletions subvt-telegram-bot/src/test/command/add_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ async fn test_add_validator_no_address() {
})
.returning(|_, _, _, _| Ok(get_telegram_message_response()));
let bot = new_test_bot(messenger).await.unwrap();
assert!(bot.save_or_restore_chat(chat_id).await.is_ok());
assert!(bot.process_command(chat_id, "/add", &[]).await.is_ok());
bot.save_or_restore_chat(chat_id).await.unwrap();
bot.process_command(chat_id, "/add", &[]).await.unwrap();
}

/// Tests the case when the user enters an invalid SS58 address following the /add command.
Expand All @@ -38,11 +38,10 @@ async fn test_add_validator_invalid_address() {
)
.returning(|_, _, _, _| Ok(get_telegram_message_response()));
let bot = new_test_bot(messenger).await.unwrap();
assert!(bot.save_or_restore_chat(chat_id).await.is_ok());
assert!(bot
.process_command(chat_id, "/add", &[invalid_address.to_string()])
bot.save_or_restore_chat(chat_id).await.unwrap();
bot.process_command(chat_id, "/add", &[invalid_address.to_string()])
.await
.is_ok());
.unwrap();
}

/// Tests when the user tries to add a validator that doesn't exist in the Redis database,
Expand All @@ -64,11 +63,10 @@ async fn test_add_non_existent_validator() {
)
.returning(|_, _, _, _| Ok(get_telegram_message_response()));
let bot = new_test_bot(messenger).await.unwrap();
assert!(bot.save_or_restore_chat(chat_id).await.is_ok());
assert!(bot
.process_command(chat_id, "/add", &command_args)
bot.save_or_restore_chat(chat_id).await.unwrap();
bot.process_command(chat_id, "/add", &command_args)
.await
.is_ok());
.unwrap();
}

/// Tests the case of trying to add a validator that already exists in the chat.
Expand All @@ -90,18 +88,17 @@ async fn test_add_validator_duplicate() {
})
.returning(|_, _, _, _| Ok(get_telegram_message_response()));
let bot = new_test_bot(messenger).await.unwrap();
assert!(bot.save_or_restore_chat(chat_id).await.is_ok());
bot.save_or_restore_chat(chat_id).await.unwrap();
add_validator_to_redis(&bot.redis, &account_id)
.await
.unwrap();
bot.network_postgres
.add_validator_to_chat(chat_id, &account_id, &account_id.to_ss58_check(), &None)
.await
.unwrap();
assert!(bot
.process_command(chat_id, "/add", &command_args)
bot.process_command(chat_id, "/add", &command_args)
.await
.is_ok());
.unwrap();
}

/// Test the successful addition of a validator to a chat.
Expand Down Expand Up @@ -135,9 +132,8 @@ async fn test_add_validator_successful() {
add_validator_to_redis(&bot.redis, &account_id)
.await
.unwrap();
assert!(bot.save_or_restore_chat(chat_id).await.is_ok());
assert!(bot
.process_command(chat_id, "/add", &command_args)
bot.save_or_restore_chat(chat_id).await.unwrap();
bot.process_command(chat_id, "/add", &command_args)
.await
.is_ok());
.unwrap();
}
26 changes: 11 additions & 15 deletions subvt-telegram-bot/src/test/command/broadcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ async fn test_broadcasttest() {
})
.returning(|_, _, _, _| Ok(get_telegram_message_response()));
let bot = new_test_bot(messenger).await.unwrap();
assert!(bot.save_or_restore_chat(ADMIN_CHAT_ID).await.is_ok());
assert!(bot
.process_command(ADMIN_CHAT_ID, "/broadcasttest", &[])
bot.save_or_restore_chat(ADMIN_CHAT_ID).await.unwrap();
bot.process_command(ADMIN_CHAT_ID, "/broadcasttest", &[])
.await
.is_ok());
.unwrap();
}

/// Tests the case of calling the /broadcast and /broadcasttest commands from an
Expand All @@ -40,15 +39,13 @@ async fn test_broadcast_and_broadcasttest_non_admin() {
.times(2)
.returning(|_, _, _, _| Ok(get_telegram_message_response()));
let bot = new_test_bot(messenger).await.unwrap();
assert!(bot.save_or_restore_chat(chat_id).await.is_ok());
assert!(bot
.process_command(chat_id, "/broadcast", &[])
bot.save_or_restore_chat(chat_id).await.unwrap();
bot.process_command(chat_id, "/broadcast", &[])
.await
.is_ok());
assert!(bot
.process_command(chat_id, "/broadcasttest", &[])
.unwrap();
bot.process_command(chat_id, "/broadcasttest", &[])
.await
.is_ok());
.unwrap();
}

/// Test the calling of the /broadcast command by an authorized chat. This command is replied
Expand All @@ -65,9 +62,8 @@ async fn test_broadcast() {
})
.returning(|_, _, _, _| Ok(get_telegram_message_response()));
let bot = new_test_bot(messenger).await.unwrap();
assert!(bot.save_or_restore_chat(ADMIN_CHAT_ID).await.is_ok());
assert!(bot
.process_command(ADMIN_CHAT_ID, "/broadcast", &[])
bot.save_or_restore_chat(ADMIN_CHAT_ID).await.unwrap();
bot.process_command(ADMIN_CHAT_ID, "/broadcast", &[])
.await
.is_ok());
.unwrap();
}
4 changes: 2 additions & 2 deletions subvt-telegram-bot/src/test/command/cancel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ async fn test_cancel() {
.withf(|_, _, _, message_type: &Box<MessageType>| matches!(**message_type, MessageType::Ok))
.returning(|_, _, _, _| Ok(get_telegram_message_response()));
let bot = new_test_bot(messenger).await.unwrap();
assert!(bot.save_or_restore_chat(chat_id).await.is_ok());
assert!(bot.process_command(chat_id, "/cancel", &[]).await.is_ok());
bot.save_or_restore_chat(chat_id).await.unwrap();
bot.process_command(chat_id, "/cancel", &[]).await.unwrap();
}
4 changes: 2 additions & 2 deletions subvt-telegram-bot/src/test/command/contact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ async fn test_contact() {
})
.returning(|_, _, _, _| Ok(get_telegram_message_response()));
let bot = new_test_bot(messenger).await.unwrap();
assert!(bot.save_or_restore_chat(chat_id).await.is_ok());
assert!(bot.process_command(chat_id, "/contact", &[]).await.is_ok());
bot.save_or_restore_chat(chat_id).await.unwrap();
bot.process_command(chat_id, "/contact", &[]).await.unwrap();
}
12 changes: 5 additions & 7 deletions subvt-telegram-bot/src/test/command/democracy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ async fn test_democracy() {
.times(2)
.returning(|_, _, _, _| Ok(get_telegram_message_response()));
let bot = new_test_bot(messenger).await.unwrap();
assert!(bot.save_or_restore_chat(chat_id).await.is_ok());
assert!(bot
.process_command(chat_id, "/democracy", &[])
bot.save_or_restore_chat(chat_id).await.unwrap();
bot.process_command(chat_id, "/democracy", &[])
.await
.is_ok());
assert!(bot
.process_command(chat_id, "/referenda", &[])
.unwrap();
bot.process_command(chat_id, "/referenda", &[])
.await
.is_ok());
.unwrap();
}
4 changes: 2 additions & 2 deletions subvt-telegram-bot/src/test/command/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ async fn test_help() {
})
.returning(|_, _, _, _| Ok(get_telegram_message_response()));
let bot = new_test_bot(messenger).await.unwrap();
assert!(bot.save_or_restore_chat(chat_id).await.is_ok());
assert!(bot.process_command(chat_id, "/help", &[]).await.is_ok());
bot.save_or_restore_chat(chat_id).await.unwrap();
bot.process_command(chat_id, "/help", &[]).await.unwrap();
}
7 changes: 3 additions & 4 deletions subvt-telegram-bot/src/test/command/invalid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ async fn test_invalid_command() {
})
.returning(|_, _, _, _| Ok(get_telegram_message_response()));
let bot = new_test_bot(messenger).await.unwrap();
assert!(bot.save_or_restore_chat(chat_id).await.is_ok());
assert!(bot
.process_command(chat_id, "/xyz23wefergknt", &[])
bot.save_or_restore_chat(chat_id).await.unwrap();
bot.process_command(chat_id, "/xyz23wefergknt", &[])
.await
.is_ok());
.unwrap();
}
9 changes: 4 additions & 5 deletions subvt-telegram-bot/src/test/command/network_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ async fn test_get_network_status_success() {
.set_network_status(&NetworkStatus::default())
.await
.unwrap();
assert!(bot.save_or_restore_chat(chat_id).await.is_ok());
assert!(bot.process_command(chat_id, "/network", &[]).await.is_ok());
assert!(bot
.process_command(chat_id, "/networkstatus", &[])
bot.save_or_restore_chat(chat_id).await.unwrap();
bot.process_command(chat_id, "/network", &[]).await.unwrap();
bot.process_command(chat_id, "/networkstatus", &[])
.await
.is_ok());
.unwrap();
}
12 changes: 6 additions & 6 deletions subvt-telegram-bot/src/test/command/nfts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ async fn test_nfts_no_validator() {
})
.returning(|_, _, _, _| Ok(get_telegram_message_response()));
let bot = new_test_bot(messenger).await.unwrap();
assert!(bot.save_or_restore_chat(chat_id).await.is_ok());
assert!(bot.process_command(chat_id, "/nfts", &[]).await.is_ok());
bot.save_or_restore_chat(chat_id).await.unwrap();
bot.process_command(chat_id, "/nfts", &[]).await.unwrap();
}

/// User has called the /nfts command, and has a single validator added to the chat,
Expand Down Expand Up @@ -47,12 +47,12 @@ async fn test_nfts_single_validator_no_nfts() {
})
.returning(|_, _, _, _| Ok(get_telegram_message_response()));
let bot = new_test_bot(messenger).await.unwrap();
assert!(bot.save_or_restore_chat(chat_id).await.is_ok());
bot.save_or_restore_chat(chat_id).await.unwrap();
bot.network_postgres
.add_validator_to_chat(chat_id, &account_id, &account_id.to_ss58_check(), &None)
.await
.unwrap();
assert!(bot.process_command(chat_id, "/nfts", &[]).await.is_ok());
bot.process_command(chat_id, "/nfts", &[]).await.unwrap();
}

/// Tests the successful result of the /nfts command with a validator stash address with NFTs.
Expand Down Expand Up @@ -80,10 +80,10 @@ async fn test_nfts_single_validator_with_nfts() {
})
.returning(|_, _, _, _| Ok(get_telegram_message_response()));
let bot = new_test_bot(messenger).await.unwrap();
assert!(bot.save_or_restore_chat(chat_id).await.is_ok());
bot.save_or_restore_chat(chat_id).await.unwrap();
bot.network_postgres
.add_validator_to_chat(chat_id, &account_id, &account_id.to_ss58_check(), &None)
.await
.unwrap();
assert!(bot.process_command(chat_id, "/nfts", &[]).await.is_ok());
bot.process_command(chat_id, "/nfts", &[]).await.unwrap();
}
30 changes: 13 additions & 17 deletions subvt-telegram-bot/src/test/command/nomination_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ async fn test_nomination_details_no_validator() {
.times(2)
.returning(|_, _, _, _| Ok(get_telegram_message_response()));
let bot = new_test_bot(messenger).await.unwrap();
assert!(bot.save_or_restore_chat(chat_id).await.is_ok());
assert!(bot
.process_command(chat_id, "/nominationdetails", &[])
bot.save_or_restore_chat(chat_id).await.unwrap();
bot.process_command(chat_id, "/nominationdetails", &[])
.await
.is_ok());
assert!(bot.process_command(chat_id, "/nd", &[]).await.is_ok());
.unwrap();
bot.process_command(chat_id, "/nd", &[]).await.unwrap();
}

/// Tests /nominationdetails command for a chat with a single validator.
Expand All @@ -48,18 +47,17 @@ async fn test_nomination_details_single_validator() {
)
.returning(|_, _, _, _| Ok(get_telegram_message_response()));
let bot = new_test_bot(messenger).await.unwrap();
assert!(bot.save_or_restore_chat(chat_id).await.is_ok());
bot.save_or_restore_chat(chat_id).await.unwrap();
add_validator_to_redis(&bot.redis, &account_id)
.await
.unwrap();
bot.network_postgres
.add_validator_to_chat(chat_id, &account_id, &account_id.to_ss58_check(), &None)
.await
.unwrap();
assert!(bot
.process_command(chat_id, "/nominationdetails", &[])
bot.process_command(chat_id, "/nominationdetails", &[])
.await
.is_ok());
.unwrap();
}

/// Tests /nominationdetails for a single validator that doesn't exist in the Redis database.
Expand All @@ -76,15 +74,14 @@ async fn test_nomination_details_single_non_existent_validator() {
})
.returning(|_, _, _, _| Ok(get_telegram_message_response()));
let bot = new_test_bot(messenger).await.unwrap();
assert!(bot.save_or_restore_chat(chat_id).await.is_ok());
bot.save_or_restore_chat(chat_id).await.unwrap();
bot.network_postgres
.add_validator_to_chat(chat_id, &account_id, &account_id.to_ss58_check(), &None)
.await
.unwrap();
assert!(bot
.process_command(chat_id, "/nominationdetails", &[])
bot.process_command(chat_id, "/nominationdetails", &[])
.await
.is_ok());
.unwrap();
}

/// Tests /nominationdetails where the user has multiple validators added to the chat - should
Expand Down Expand Up @@ -112,16 +109,15 @@ async fn test_nomination_details_multiple_validators() {
)
.returning(|_, _, _, _| Ok(get_telegram_message_response()));
let bot = new_test_bot(messenger).await.unwrap();
assert!(bot.save_or_restore_chat(chat_id).await.is_ok());
bot.save_or_restore_chat(chat_id).await.unwrap();
for _ in 0..validator_count {
let account_id = get_random_account_id();
bot.network_postgres
.add_validator_to_chat(chat_id, &account_id, &account_id.to_ss58_check(), &None)
.await
.unwrap();
}
assert!(bot
.process_command(chat_id, "/nominationdetails", &[])
bot.process_command(chat_id, "/nominationdetails", &[])
.await
.is_ok());
.unwrap();
}
Loading

0 comments on commit 530adda

Please sign in to comment.