Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Luijken committed Aug 22, 2024
1 parent b886c76 commit a8879a7
Show file tree
Hide file tree
Showing 57 changed files with 1,018 additions and 604 deletions.
30 changes: 24 additions & 6 deletions stellar_rust_sdk/src/accounts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,20 @@ pub mod test {
assert_eq!(response.flags().auth_required(), AUTH_REQUIRED);
assert_eq!(response.flags().auth_revocable(), AUTH_REVOCABLE);
assert_eq!(response.flags().auth_immutable(), AUTH_IMMUTABLE);
assert_eq!(response.flags().auth_clawback_enabled(), AUTH_CLAWBACK_ENABLED);
assert_eq!(
response.flags().auth_clawback_enabled(),
AUTH_CLAWBACK_ENABLED
);
assert_eq!(response.balances()[0].balance(), BALANCE);
assert_eq!(response.balances()[0].asset_type(), ASSET_TYPE);
assert_eq!(response.balances()[0].buying_liabilities(), BUYING_LIABILITY);
assert_eq!(response.balances()[0].selling_liabilities(), SELLING_LIABILITY);
assert_eq!(
response.balances()[0].buying_liabilities(),
BUYING_LIABILITY
);
assert_eq!(
response.balances()[0].selling_liabilities(),
SELLING_LIABILITY
);
assert_eq!(response.signers()[0].key(), ACCOUNT_ID);
assert_eq!(response.signers()[0].weight(), WEIGHT);
assert_eq!(response.signers()[0].singer_type(), SIGNER_TYPE);
Expand Down Expand Up @@ -172,11 +181,20 @@ pub mod test {
assert_eq!(response.flags().auth_required(), AUTH_REQUIRED);
assert_eq!(response.flags().auth_revocable(), AUTH_REVOCABLE);
assert_eq!(response.flags().auth_immutable(), AUTH_IMMUTABLE);
assert_eq!(response.flags().auth_clawback_enabled(), AUTH_CLAWBACK_ENABLED);
assert_eq!(
response.flags().auth_clawback_enabled(),
AUTH_CLAWBACK_ENABLED
);
assert_eq!(response.balances()[0].balance(), BALANCE);
assert_eq!(response.balances()[0].asset_type(), ASSET_TYPE);
assert_eq!(response.balances()[0].buying_liabilities(), BUYING_LIABILITY);
assert_eq!(response.balances()[0].selling_liabilities(), SELLING_LIABILITY);
assert_eq!(
response.balances()[0].buying_liabilities(),
BUYING_LIABILITY
);
assert_eq!(
response.balances()[0].selling_liabilities(),
SELLING_LIABILITY
);
assert_eq!(response.signers()[0].key(), ACCOUNT_ID);
assert_eq!(response.signers()[0].weight(), WEIGHT);
assert_eq!(response.signers()[0].singer_type(), SIGNER_TYPE);
Expand Down
18 changes: 13 additions & 5 deletions stellar_rust_sdk/src/assets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub mod prelude {
#[cfg(test)]
pub mod test {
use super::prelude::*;
use crate::{horizon_client::HorizonClient};
use crate::horizon_client::HorizonClient;

#[tokio::test]
async fn test_get_all_assets() {
Expand All @@ -101,7 +101,6 @@ pub mod test {
static AUTH_IMMUTABLE: &bool = &false;
static AUTH_CLAWBACK_ENABLED: &bool = &false;


// Initialize horizon client
let horizon_client =
HorizonClient::new("https://horizon-testnet.stellar.org".to_string()).unwrap();
Expand All @@ -126,16 +125,25 @@ pub mod test {
assert_eq!(response.num_liquidity_pools(), NUM_LIQUIDITY_POOLS);
assert_eq!(response.amount(), AMOUNT);
assert_eq!(response.accounts().authorized(), AUTHORIZED);
assert_eq!(response.accounts().authorized_to_maintain_liabilities(), AUTHORIZED_TO_MAINTAIN_LIABILITIES);
assert_eq!(
response.accounts().authorized_to_maintain_liabilities(),
AUTHORIZED_TO_MAINTAIN_LIABILITIES
);
assert_eq!(response.accounts().unauthorized(), UNAUTHORIZED);
assert_eq!(response.claimable_balances_amount(), CLAIMABLE_BALANCES_AMOUNT);
assert_eq!(
response.claimable_balances_amount(),
CLAIMABLE_BALANCES_AMOUNT
);
assert_eq!(response.liquidity_pools_amount(), LIQUIDITY_POOLS_AMOUNT);
assert_eq!(response.contracts_amount(), CONTRACTS_AMOUNT);
assert_eq!(response.balances().authorized(), BALANCES_AUTHORIZED);
assert_eq!(response.balances().unauthorized(), BALANCES_UNAUTHORIZED);
assert_eq!(response.flags().auth_required(), AUTH_REQUIRED);
assert_eq!(response.flags().auth_revocable(), AUTH_REVOCABLE);
assert_eq!(response.flags().auth_immutable(), AUTH_IMMUTABLE);
assert_eq!(response.flags().auth_clawback_enabled(), AUTH_CLAWBACK_ENABLED);
assert_eq!(
response.flags().auth_clawback_enabled(),
AUTH_CLAWBACK_ENABLED
);
}
}
65 changes: 30 additions & 35 deletions stellar_rust_sdk/src/claimable_balances/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,16 @@ fn parse_epoch(epoch_str: &str) -> DateTime<Utc> {
}

pub mod prelude {
pub use super::{all_claimable_balances_request::*, response::*, single_claimable_balance_request::*};
pub use super::{
all_claimable_balances_request::*, response::*, single_claimable_balance_request::*,
};
}

#[cfg(test)]
mod tests {
use super::parse_epoch;
use super::prelude::*;
use crate::{horizon_client::HorizonClient};
use crate::horizon_client::HorizonClient;
use chrono::DateTime;
use chrono::{TimeZone, Utc};
use lazy_static::lazy_static;
Expand Down Expand Up @@ -151,7 +153,8 @@ mod tests {

#[tokio::test]
async fn test_get_all_claimable_balances() {
static ID: &str = "0000000010a8f6991f79df306f22a2032f6007ad594dd30f966b21556f7d75658ec1c4e9";
static ID: &str =
"0000000010a8f6991f79df306f22a2032f6007ad594dd30f966b21556f7d75658ec1c4e9";
static ASSET: &str = "native";
static AMOUNT: &str = "3.0000000";
static SPONSOR: &str = "GCRHSLTKEPLLRLC4MB5OJPO4DJYIMYHYBDHX4TET3XKUKFAYMWERHXVG";
Expand Down Expand Up @@ -183,44 +186,35 @@ mod tests {
assert_eq!(predicate.is_valid(valid_date), true);
let record = &binding.embedded().records()[0];

assert_eq!(
record.id(),
ID
);
assert_eq!(record.id(), ID);

assert_eq!(
record.asset(),
ASSET
);
assert_eq!(record.asset(), ASSET);

assert_eq!(record.amount(), AMOUNT);

assert_eq!(
record.sponsor(),
SPONSOR
);
assert_eq!(record.sponsor(), SPONSOR);

assert_eq!(record.last_modified_ledger(), LAST_MODIFIED_LEDGER);

assert_eq!(
record.last_modified_time().to_string(),
LAST_MODIFIED_TIME
);
assert_eq!(record.last_modified_time().to_string(), LAST_MODIFIED_TIME);

assert_eq!(record.flags().clawback_enabled(), CLAWBACK_ENABLED);
}

#[tokio::test]
async fn test_get_single_claimable_balance() {
static CLAIMABLE_BALANCE_ID: &str = "00000000fe3d8209ed9662e92f0d3a5c55068e18bd5e0697c3c6db6ac4c0870c6f3e0b38";
static ID: &str = "00000000fe3d8209ed9662e92f0d3a5c55068e18bd5e0697c3c6db6ac4c0870c6f3e0b38";
static CLAIMABLE_BALANCE_ID: &str =
"00000000fe3d8209ed9662e92f0d3a5c55068e18bd5e0697c3c6db6ac4c0870c6f3e0b38";
static ID: &str =
"00000000fe3d8209ed9662e92f0d3a5c55068e18bd5e0697c3c6db6ac4c0870c6f3e0b38";
static ASSET: &str = "IOM:GBSUM7J4W2IH5LAMSQGI7Y2OZBV2BJB6EOK7TIK66DXNJUU4JAY36VR2";
static AMOUNT: &str = "2.0000000";
static SPONSOR: &str = "GA7UL5DDCP6WR7KV5GXKXSHBMP577U7TBDBTBY33J57RZE2A37KW67JB";
static LAST_MODIFIED_LEDGER: &i64 = &9234;
static LAST_MODIFIED_TIME: &str = "2024-06-12T10:19:12Z";
static CLAWBACK_ENABLED: &bool = &false;
static PAGING_TOKEN: &str = "9234-00000000fe3d8209ed9662e92f0d3a5c55068e18bd5e0697c3c6db6ac4c0870c6f3e0b38";
static PAGING_TOKEN: &str =
"9234-00000000fe3d8209ed9662e92f0d3a5c55068e18bd5e0697c3c6db6ac4c0870c6f3e0b38";

// Initialize horizon client
let horizon_client =
Expand All @@ -245,39 +239,40 @@ mod tests {
assert_eq!(predicate.is_valid(valid_date), true);

let single_claimable_balance_response = single_claimable_balance_response.unwrap();
assert_eq!(
single_claimable_balance_response.id().to_string(),
ID
);
assert_eq!(single_claimable_balance_response.id().to_string(), ID);

assert_eq!(
single_claimable_balance_response.asset().to_string(),
ASSET);
assert_eq!(single_claimable_balance_response.asset().to_string(), ASSET);

assert_eq!(
single_claimable_balance_response.amount().to_string(),
AMOUNT);
AMOUNT
);

assert_eq!(
single_claimable_balance_response.sponsor().to_string(),
SPONSOR);
SPONSOR
);

assert_eq!(
single_claimable_balance_response.last_modified_ledger(),
LAST_MODIFIED_LEDGER);
LAST_MODIFIED_LEDGER
);

assert_eq!(
single_claimable_balance_response
.last_modified_time()
.to_string(),
LAST_MODIFIED_TIME);
LAST_MODIFIED_TIME
);

assert_eq!(
single_claimable_balance_response.flags().clawback_enabled(),
CLAWBACK_ENABLED);
CLAWBACK_ENABLED
);

assert_eq!(
single_claimable_balance_response.paging_token().to_string(),
PAGING_TOKEN);
PAGING_TOKEN
);
}
}
2 changes: 1 addition & 1 deletion stellar_rust_sdk/src/effects/all_effects_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@ mod tests {

assert!(request.is_err());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl Request for EffectsForLiquidityPoolRequest {
#[cfg(test)]
mod tests {
use super::*;
use crate::{BuildQueryParametersExt};
use crate::BuildQueryParametersExt;

#[test]
fn test_effects_for_liquidity_pools_request() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,4 @@ mod tests {
let url = request.build_url(base_url);
assert_eq!(url, "https://horizon-testnet.stellar.org/effects");
}
}
}
17 changes: 10 additions & 7 deletions stellar_rust_sdk/src/effects/effects_for_transaction_request.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::{models::{Order, Request}, BuildQueryParametersExt};
use crate::{
models::{Order, Request},
BuildQueryParametersExt,
};
use stellar_rust_sdk_derive::pagination;

/// Represents a request to fetch effect data from the Stellar Horizon API.
Expand Down Expand Up @@ -43,10 +46,7 @@ impl EffectForTransactionRequest {
/// # Arguments
/// * `liquidity_pool_id` - A `String` value representing the liquidity pool id.
///
pub fn set_transaction_hash(
self,
transaction_hash: String,
) -> EffectForTransactionRequest {
pub fn set_transaction_hash(self, transaction_hash: String) -> EffectForTransactionRequest {
EffectForTransactionRequest {
transaction_hash: Some(transaction_hash),
..self
Expand Down Expand Up @@ -106,6 +106,9 @@ mod tests {
url,
"https://horizon-testnet.stellar.org/effects?transaction_hash=transaction_hash&cursor=1&limit=10&order=asc"
);
assert_eq!(query_parameters, "?transaction_hash=transaction_hash&cursor=1&limit=10&order=asc");
assert_eq!(
query_parameters,
"?transaction_hash=transaction_hash&cursor=1&limit=10&order=asc"
);
}
}
}
32 changes: 9 additions & 23 deletions stellar_rust_sdk/src/effects/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// Provides the `AllEffectsRequest` struct.
///
/// This module contains the `AllEffectsRequest` struct, which is designed to create requests
/// for querying comprehensive lists of effects from the Horizon server.
/// for querying comprehensive lists of effects from the Horizon server.
///
/// The `AllEffectsRequest` struct is meant to be used in conjunction with the [`HorizonClient`](crate::horizon_client::HorizonClient)
/// to perform the actual API calls and fetch asset data. It adheres to the structure
Expand Down Expand Up @@ -119,7 +119,7 @@ pub mod prelude {
#[cfg(test)]
mod tests {
use super::prelude::*;
use crate::{horizon_client::HorizonClient};
use crate::horizon_client::HorizonClient;

#[test]
fn dummy_test() {
Expand Down Expand Up @@ -271,33 +271,19 @@ mod tests {
let binding = effects_for_ledger_response.clone().unwrap();
let record = &binding.embedded().records()[0];

assert_eq!(
record.id,
ID);
assert_eq!(record.id, ID);

assert_eq!(
record.paging_token,
PAGING_TOKEN);
assert_eq!(record.paging_token, PAGING_TOKEN);

assert_eq!(
record.account,
ACCOUNT);
assert_eq!(record.account, ACCOUNT);

assert_eq!(
record.effect_type,
RECORD_TYPE);
assert_eq!(record.effect_type, RECORD_TYPE);

assert_eq!(
record.type_i,
TYPE_I);
assert_eq!(record.type_i, TYPE_I);

assert_eq!(
record.created_at,
CREATED_AT);
assert_eq!(record.created_at, CREATED_AT);

assert_eq!(
record.starting_balance.as_ref().unwrap(),
STARTING_BALANCE);
assert_eq!(record.starting_balance.as_ref().unwrap(), STARTING_BALANCE);
}

#[tokio::test]
Expand Down
2 changes: 1 addition & 1 deletion stellar_rust_sdk/src/fee_stats/fee_stats_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ impl Request for FeeStatsRequest {
fn build_url(&self, base_url: &str) -> String {
format!("{}/{}", base_url, super::FEE_STATS_PATH)
}
}
}
2 changes: 1 addition & 1 deletion stellar_rust_sdk/src/fee_stats/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ impl Response for FeeStatsResponse {
fn from_json(json: String) -> Result<Self, String> {
serde_json::from_str(&json).map_err(|e| e.to_string())
}
}
}
8 changes: 4 additions & 4 deletions stellar_rust_sdk/src/horizon_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ use crate::{
details_request::{BuyingAsset, DetailsRequest, SellingAsset},
response::DetailsResponse,
},
payments::prelude::*,
trade_aggregations::prelude::*,
transactions::prelude::*,
trades::prelude::*,
payments::prelude::*
transactions::prelude::*,
};
use reqwest;
use url::Url;
Expand Down Expand Up @@ -1175,7 +1175,7 @@ impl HorizonClient {
) -> Result<OperationResponse, String> {
self.get::<OperationResponse>(request).await
}

/// Retrieves a list of all operations for a specific transaction from the Horizon server.
///
/// This asynchronous method fetches a list of all operations for a specific transaction from the Horizon server.
Expand Down Expand Up @@ -1225,7 +1225,7 @@ impl HorizonClient {
) -> Result<OperationResponse, String> {
self.get::<OperationResponse>(request).await
}

/// Retrieves a list of order book details from the Horizon server.
///
/// This asynchronous method fetches a list of order book details from the Horizon server.
Expand Down
2 changes: 1 addition & 1 deletion stellar_rust_sdk/src/ledgers/ledgers_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ mod tests {
"https://horizon-testnet.stellar.org/ledgers"
);
}
}
}
Loading

0 comments on commit a8879a7

Please sign in to comment.