Skip to content

Commit

Permalink
test: add smoke test (#149)
Browse files Browse the repository at this point in the history
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?
---

<!-- Checklist -->
<!-- 1. Is the title of your PR in the form that would make nice release
notes? The title, excluding the conventional commit
tag, will be included exactly as is in the CHANGELOG, so please think
about it carefully. -->


Breaking Changes
---

- [x] None
- [ ] Requires data directory on base node to be deleted
- [ ] Requires hard fork
- [ ] Other - Please specify

<!-- Does this include a breaking change? If so, include this line as a
footer -->
<!-- BREAKING CHANGE: Description what the user should do, e.g. delete a
database, resync the chain -->
  • Loading branch information
karczuRF authored Nov 29, 2024
1 parent 661beb9 commit b9f82e9
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
1 change: 1 addition & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ mod fs;
mod download_utils;
mod progress_tracker;
mod utils;
mod tests;

use commands::{
call_wallet,
Expand Down
8 changes: 5 additions & 3 deletions src-tauri/src/rpc.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -53,19 +54,20 @@ pub async fn account_create(account_name: Option<String>, permissions_token: Str
Ok(())
}

pub async fn free_coins(account_name: Option<String>, permissions_token: String) -> Result<(), anyhow::Error> {
pub async fn free_coins(account_name: Option<String>, permissions_token: String) -> Result<Value, anyhow::Error> {
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(
Expand Down
37 changes: 37 additions & 0 deletions src-tauri/src/tests/account_test.rs
Original file line number Diff line number Diff line change
@@ -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!"),
}
}
}
1 change: 1 addition & 0 deletions src-tauri/src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod account_test;

0 comments on commit b9f82e9

Please sign in to comment.