From b9f82e92d89db682f721523fcbf962da1b72a8fa Mon Sep 17 00:00:00 2001 From: karczuRF <88723742+karczuRF@users.noreply.github.com> Date: Fri, 29 Nov 2024 11:41:34 +0100 Subject: [PATCH] test: add smoke test (#149) Description --- Adds smoke test to check if provider works and can perform: 1. create account 2. get free coins 3. fetch balances Motivation and Context --- Test are needed to quick check basic app functionality. How Has This Been Tested? --- What process can a PR reviewer use to test or verify this change? --- Breaking Changes --- - [x] None - [ ] Requires data directory on base node to be deleted - [ ] Requires hard fork - [ ] Other - Please specify --- src-tauri/src/lib.rs | 1 + src-tauri/src/rpc.rs | 8 ++++--- src-tauri/src/tests/account_test.rs | 37 +++++++++++++++++++++++++++++ src-tauri/src/tests/mod.rs | 1 + 4 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 src-tauri/src/tests/account_test.rs create mode 100644 src-tauri/src/tests/mod.rs diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 45db87d..be20bbc 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -23,6 +23,7 @@ mod fs; mod download_utils; mod progress_tracker; mod utils; +mod tests; use commands::{ call_wallet, diff --git a/src-tauri/src/rpc.rs b/src-tauri/src/rpc.rs index 7ba2eff..abe00d4 100644 --- a/src-tauri/src/rpc.rs +++ b/src-tauri/src/rpc.rs @@ -1,5 +1,6 @@ use axum_jrpc::{ JsonRpcAnswer, JsonRpcRequest, JsonRpcResponse }; use serde::Serialize; +use serde_json::Value; use std::{ net::SocketAddr, str::FromStr }; use tari_wallet_daemon_client::{ types::{ @@ -53,19 +54,20 @@ pub async fn account_create(account_name: Option, permissions_token: Str Ok(()) } -pub async fn free_coins(account_name: Option, permissions_token: String) -> Result<(), anyhow::Error> { +pub async fn free_coins(account_name: Option, permissions_token: String) -> Result { let free_coins_params = AccountsCreateFreeTestCoinsRequest { account: account_name.map(|acc_name| ComponentAddressOrName::Name(acc_name)), amount: (100_000_000).into(), max_fee: None, key_id: None, }; - let _resp = make_request( + let resp = make_request( Some(permissions_token), "accounts.create_free_test_coins".to_string(), free_coins_params ).await?; - Ok(()) + + Ok(resp) } pub async fn balances( diff --git a/src-tauri/src/tests/account_test.rs b/src-tauri/src/tests/account_test.rs new file mode 100644 index 0000000..720214f --- /dev/null +++ b/src-tauri/src/tests/account_test.rs @@ -0,0 +1,37 @@ +#[cfg(test)] +mod tests { + use tokio::time::{ self, Duration }; + + use crate::rpc::{ balances, free_coins, permission_token }; + + #[tokio::test] + async fn get_account_balance() { + let timeout_duration = Duration::from_secs(30); + let (permission_token, _auth_token) = permission_token().await.unwrap(); + let account_name = "default".to_string(); + let get_tokens_result = time::timeout( + timeout_duration, + free_coins(Some(account_name.clone()), permission_token.clone()) + ).await; + + match get_tokens_result { + Ok(Ok(value)) => { + let resp = value.as_str().unwrap_or("").to_string(); + assert_eq!(resp, "default"); + } + Ok(Err(e)) => panic!("Function returned an error: {}", e), + Err(_) => panic!("Function 'free_coins' timed out!"), + } + + let get_balance_result = time::timeout(timeout_duration, balances(Some(account_name), permission_token)).await; + + match get_balance_result { + Ok(Ok(res)) => { + let address = res.address.is_component(); + assert_eq!(address, true); + } + Ok(Err(e)) => panic!("Function returned an error: {}", e), + Err(_) => panic!("Function 'balances' timed out!"), + } + } +} diff --git a/src-tauri/src/tests/mod.rs b/src-tauri/src/tests/mod.rs new file mode 100644 index 0000000..469356d --- /dev/null +++ b/src-tauri/src/tests/mod.rs @@ -0,0 +1 @@ +mod account_test;