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

Update test values #90

Merged
merged 17 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 52 additions & 36 deletions stellar_rust_sdk/src/accounts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,26 @@ pub mod test {
use super::prelude::*;
use crate::horizon_client::HorizonClient;

static SEQUENCE: &str = "131988639973376";
static ACCOUNT_ID: &str = "GCAHCEGRUI7FFAQE3DBQWV7ULMQHFBUIVRZC4R2VISREAY6D52Z2NODN";
static LAST_MODIFIED_TIME: &str = "2024-02-08T14:25:14Z";
static LAST_MODIFIED_LEDGER: u64 = 30731;
static ACCOUNT_ID: &str = "GDIGRW2H37U3O5WPMQFWGN35DDVZAYYTIMGLYVQI4XTATZBW4FXEATRE";
static LAST_MODIFIED_TIME: &str = "2024-06-12T17:21:23Z";
static SEQUENCE: &str = "5471788335106";
static SUBENTRY_COUNT: &u32 = &0;
static LAST_MODIFIED_LEDGER: u64 = 14055;
static LOW_THRESHOLD: &u32 = &0;
static MID_THRESOLD: &u32 = &0;
static HIGH_THRESOLD: &u32 = &0;
static AUTH_REQUIRED: &bool = &true;
static AUTH_REVOCABLE: &bool = &true;
static AUTH_IMMUTABLE: &bool = &false;
static AUTH_CLAWBACK_ENABLED: &bool = &false;
static BALANCE: &str = "4.9999600";
static ASSET_TYPE: &str = "native";
static BUYING_LIABILITY: &str = "0.0000000";
static SELLING_LIABILITY: &str = "0.0000000";
static WEIGHT: &u32 = &1;
static SIGNER_TYPE: &str = "ed25519_public_key";
static NUM_SPONSORING: &u32 = &0;
static NUM_SPONSORED: &u32 = &0;

#[tokio::test]
async fn test_get_account_list() {
Expand All @@ -106,25 +122,25 @@ pub mod test {
assert_eq!(response.account_id(), ACCOUNT_ID);
assert_eq!(response.id(), ACCOUNT_ID);
assert_eq!(response.sequence(), SEQUENCE);
assert_eq!(response.subentry_count(), &0);
assert_eq!(response.subentry_count(), SUBENTRY_COUNT);
assert_eq!(response.last_modified_ledger(), &LAST_MODIFIED_LEDGER);
assert_eq!(response.last_modified_time(), LAST_MODIFIED_TIME);
assert_eq!(response.thresholds().low_threshold(), &0);
assert_eq!(response.thresholds().med_threshold(), &0);
assert_eq!(response.thresholds().high_threshold(), &0);
assert_eq!(response.flags().auth_required(), &false);
assert_eq!(response.flags().auth_revocable(), &false);
assert_eq!(response.flags().auth_immutable(), &false);
assert_eq!(response.flags().auth_clawback_enabled(), &false);
assert_eq!(response.balances()[0].balance(), "10000.0000000");
assert_eq!(response.balances()[0].asset_type(), "native");
assert_eq!(response.balances()[0].buying_liabilities(), "0.0000000");
assert_eq!(response.balances()[0].selling_liabilities(), "0.0000000");
assert_eq!(response.thresholds().low_threshold(), LOW_THRESHOLD);
assert_eq!(response.thresholds().med_threshold(), MID_THRESOLD);
assert_eq!(response.thresholds().high_threshold(), HIGH_THRESOLD);
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.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.signers()[0].key(), ACCOUNT_ID);
assert_eq!(response.signers()[0].weight(), &1);
assert_eq!(response.signers()[0].singer_type(), "ed25519_public_key");
assert_eq!(response.num_sponsoring(), &0);
assert_eq!(response.num_sponsored(), &0);
assert_eq!(response.signers()[0].weight(), WEIGHT);
assert_eq!(response.signers()[0].singer_type(), SIGNER_TYPE);
assert_eq!(response.num_sponsoring(), NUM_SPONSORING);
assert_eq!(response.num_sponsored(), NUM_SPONSORED);
assert_eq!(response.paging_token(), ACCOUNT_ID);
}

Expand All @@ -147,25 +163,25 @@ pub mod test {
let response = single_account_response.unwrap();
assert_eq!(response.account_id().to_string(), ACCOUNT_ID);
assert_eq!(response.sequence().to_string(), SEQUENCE);
assert_eq!(response.subentry_count(), &0);
assert_eq!(response.subentry_count(), SUBENTRY_COUNT);
assert_eq!(response.last_modified_ledger(), &LAST_MODIFIED_LEDGER);
assert_eq!(response.last_modified_time(), LAST_MODIFIED_TIME);
assert_eq!(response.thresholds().low_threshold(), &0);
assert_eq!(response.thresholds().med_threshold(), &0);
assert_eq!(response.thresholds().high_threshold(), &0);
assert_eq!(response.flags().auth_required(), &false);
assert_eq!(response.flags().auth_revocable(), &false);
assert_eq!(response.flags().auth_immutable(), &false);
assert_eq!(response.flags().auth_clawback_enabled(), &false);
assert_eq!(response.balances()[0].balance(), "10000.0000000");
assert_eq!(response.balances()[0].asset_type(), "native");
assert_eq!(response.balances()[0].buying_liabilities(), "0.0000000");
assert_eq!(response.balances()[0].selling_liabilities(), "0.0000000");
assert_eq!(response.thresholds().low_threshold(), LOW_THRESHOLD);
assert_eq!(response.thresholds().med_threshold(), MID_THRESOLD);
assert_eq!(response.thresholds().high_threshold(), HIGH_THRESOLD);
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.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.signers()[0].key(), ACCOUNT_ID);
assert_eq!(response.signers()[0].weight(), &1);
assert_eq!(response.signers()[0].singer_type(), "ed25519_public_key");
assert_eq!(response.num_sponsoring(), &0);
assert_eq!(response.num_sponsored(), &0);
assert_eq!(response.signers()[0].weight(), WEIGHT);
assert_eq!(response.signers()[0].singer_type(), SIGNER_TYPE);
assert_eq!(response.num_sponsoring(), NUM_SPONSORING);
assert_eq!(response.num_sponsored(), NUM_SPONSORED);
assert_eq!(response.paging_token(), ACCOUNT_ID);
}
}
82 changes: 44 additions & 38 deletions stellar_rust_sdk/src/assets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,29 @@ pub mod test {

#[tokio::test]
async fn test_get_all_assets() {
let asset_type = "credit_alphanum4";
let asset_code = "0";
let asset_issuer = "GAGNEED7RUE6PNAB3AKXFU6QZF4EUSVTICHE7YRHB53KDOEHGKWBL6BE";
let paging_token =
"0_GAGNEED7RUE6PNAB3AKXFU6QZF4EUSVTICHE7YRHB53KDOEHGKWBL6BE_credit_alphanum4";
let num_accounts = 0;
let amount = "0.0000000";
let num_authorized = 0;
let num_unauthorized = 0;
let balances_authorized = "0.0000000";
let balances_unauthorized = "0.0000000";
static ASSET_TYPE: &str = "credit_alphanum4";
static ASSET_CODE: &str = "006";
static ASSET_ISSUER: &str = "GCN4ALWVHURX3D64AQ3PD7VFOLLKHMEFOG3Y4A4DKOTV256IZNJG3IKB";
static PAGING_TOKEN: &str =
"006_GCN4ALWVHURX3D64AQ3PD7VFOLLKHMEFOG3Y4A4DKOTV256IZNJG3IKB_credit_alphanum4";
static NUM_ACCOUNTS: &u32 = &1;
static NUM_CLAIMABLE_BALANCES: &u32 = &0;
static NUM_LIQUIDITY_POOLS: &u32 = &0;

static AMOUNT: &str = "999.0000000";
static AUTHORIZED: &u32 = &1;
static AUTHORIZED_TO_MAINTAIN_LIABILITIES: &u32 = &0;
static UNAUTHORIZED: &u32 = &0;
static CLAIMABLE_BALANCES_AMOUNT: &str = "0.0000000";
static LIQUIDITY_POOLS_AMOUNT: &str = "0.0000000";
static CONTRACTS_AMOUNT: &str = "0.0000000";
static BALANCES_AUTHORIZED: &str = "999.0000000";
static BALANCES_UNAUTHORIZED: &str = "0.0000000";
static AUTH_REQUIRED: &bool = &false;
static AUTH_REVOCABLE: &bool = &false;
static AUTH_IMMUTABLE: &bool = &false;
static AUTH_CLAWBACK_ENABLED: &bool = &false;


// Initialize horizon client
let horizon_client =
Expand All @@ -104,35 +116,29 @@ pub mod test {
assert!(response.is_ok());
let binding = response.unwrap();
let response = &binding.embedded().records()[0];
assert_eq!(response.asset_type(), asset_type);
assert_eq!(response.asset_code(), asset_code);
assert_eq!(response.asset_issuer(), asset_issuer);
assert_eq!(response.paging_token(), paging_token);
assert_eq!(response.asset_type(), ASSET_TYPE);
assert_eq!(response.asset_code(), ASSET_CODE);
assert_eq!(response.asset_issuer(), ASSET_ISSUER);
assert_eq!(response.paging_token(), PAGING_TOKEN);
assert_eq!(
response.paging_token(),
&format!("{}_{}_{}", asset_code, asset_issuer, asset_type)
&format!("{}_{}_{}", ASSET_CODE, ASSET_ISSUER, ASSET_TYPE)
);
assert_eq!(response.num_accounts(), &num_accounts);
assert_eq!(response.num_claimable_balances(), &0);
assert_eq!(response.num_liquidity_pools(), &0);
assert_eq!(response.amount(), amount);
assert_eq!(response.accounts().authorized(), &num_authorized);
assert_eq!(response.accounts().authorized_to_maintain_liabilities(), &2);
assert_eq!(response.accounts().unauthorized(), &num_unauthorized);
assert_eq!(response.claimable_balances_amount(), "0.0000000");
assert_eq!(response.liquidity_pools_amount(), "0.0000000");
assert_eq!(response.contracts_amount(), "0.0000000");
assert_eq!(response.balances().authorized(), balances_authorized);
assert_eq!(
response.balances().authorized_to_maintain_liabilities(),
"1.0000000"
);
assert_eq!(response.balances().unauthorized(), balances_unauthorized);

let auth_required = true;
assert_eq!(response.flags().auth_required(), &auth_required);
assert_eq!(response.flags().auth_revocable(), &true);
assert_eq!(response.flags().auth_immutable(), &false);
assert_eq!(response.flags().auth_clawback_enabled(), &true);
assert_eq!(response.num_accounts(), NUM_ACCOUNTS);
assert_eq!(response.num_claimable_balances(), NUM_CLAIMABLE_BALANCES);
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().unauthorized(), UNAUTHORIZED);
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);
}
}
60 changes: 35 additions & 25 deletions stellar_rust_sdk/src/claimable_balances/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ mod tests {

#[tokio::test]
async fn test_get_all_claimable_balances() {
static ID: &str = "0000000010a8f6991f79df306f22a2032f6007ad594dd30f966b21556f7d75658ec1c4e9";
static ASSET: &str = "native";
static AMOUNT: &str = "3.0000000";
static SPONSOR: &str = "GCRHSLTKEPLLRLC4MB5OJPO4DJYIMYHYBDHX4TET3XKUKFAYMWERHXVG";
static LAST_MODIFIED_LEDGER: &i64 = &2170;
static LAST_MODIFIED_TIME: &str = "2024-06-11T23:59:46Z";
static CLAWBACK_ENABLED: &bool = &false;

// Initialize horizon client
let horizon_client =
HorizonClient::new("https://horizon-testnet.stellar.org".to_string()).unwrap();
Expand All @@ -177,40 +185,49 @@ mod tests {

assert_eq!(
record.id(),
"000000000a12cd57c169a34e7794bdcdf2d093fab135c59ea599e2d1233d7a53f26c1464"
ID
);

assert_eq!(
record.asset(),
"USDC:GAKNDFRRWA3RPWNLTI3G4EBSD3RGNZZOY5WKWYMQ6CQTG3KIEKPYWAYC"
ASSET
);

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

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

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

assert_eq!(
record.last_modified_time().to_string(),
"2024-02-06T18:25:07Z"
LAST_MODIFIED_TIME
);

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

#[tokio::test]
async fn test_get_single_claimable_balance() {
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";

// Initialize horizon client
let horizon_client =
HorizonClient::new("https://horizon-testnet.stellar.org".to_string()).unwrap();

let single_claimable_balance_request = SingleClaimableBalanceRequest::new()
.set_claimable_balance_id(
"000000000a12cd57c169a34e7794bdcdf2d093fab135c59ea599e2d1233d7a53f26c1464"
"00000000fe3d8209ed9662e92f0d3a5c55068e18bd5e0697c3c6db6ac4c0870c6f3e0b38"
kevin-pease marked this conversation as resolved.
Show resolved Hide resolved
.to_string(),
);

Expand All @@ -223,53 +240,46 @@ mod tests {
let binding = single_claimable_balance_response.clone().unwrap();
let predicate = binding.claimants()[0].predicate();

let jan_first_2024 = Utc::with_ymd_and_hms(&Utc, 2024, 1, 1, 0, 0, 0).unwrap();
let valid_date = Utc::with_ymd_and_hms(&Utc, 2024, 2, 10, 0, 0, 0).unwrap();
let jan_first_2024 = Utc::with_ymd_and_hms(&Utc, 2021, 1, 1, 0, 0, 0).unwrap();
let valid_date = Utc::with_ymd_and_hms(&Utc, 2021, 1, 1, 0, 0, 0).unwrap();

assert_eq!(predicate.is_valid(jan_first_2024), true);
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(),
"000000000a12cd57c169a34e7794bdcdf2d093fab135c59ea599e2d1233d7a53f26c1464"
ID
);

assert_eq!(
single_claimable_balance_response.asset().to_string(),
"USDC:GAKNDFRRWA3RPWNLTI3G4EBSD3RGNZZOY5WKWYMQ6CQTG3KIEKPYWAYC"
);
ASSET);

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

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

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

assert_eq!(
single_claimable_balance_response
.last_modified_time()
.to_string(),
"2024-02-06T18:25:07Z"
);
LAST_MODIFIED_TIME);

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

assert_eq!(
single_claimable_balance_response.paging_token().to_string(),
"591-000000000a12cd57c169a34e7794bdcdf2d093fab135c59ea599e2d1233d7a53f26c1464"
);
PAGING_TOKEN);
}
}
8 changes: 4 additions & 4 deletions stellar_rust_sdk/src/effects/effects_for_ledger_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use stellar_rust_sdk_derive::Pagination;
/// # use stellar_rs::Paginatable;
///
/// let mut request = EffectsForLedgerRequest::new()
/// .set_sequence(125)
/// .set_sequence(&1000)
/// .set_limit(2);
///
/// // The request is now ready to be used with a Horizon client to fetch effects for the specified ledger.
Expand Down Expand Up @@ -51,9 +51,9 @@ impl EffectsForLedgerRequest {
/// # Arguments
/// * `sequence` - A `String` value representing the ledger sequence.
///
pub fn set_sequence(self, sequence: u32) -> EffectsForLedgerRequest {
pub fn set_sequence(self, sequence: &u32) -> EffectsForLedgerRequest {
EffectsForLedgerRequest {
sequence: Some(sequence),
sequence: Some(*sequence),
..self
}
}
Expand Down Expand Up @@ -94,7 +94,7 @@ mod tests {
fn test_effects_for_ledger_request_build_url() {
let sequence: u32 = 125;

let request = EffectsForLedgerRequest::new().set_sequence(sequence);
let request = EffectsForLedgerRequest::new().set_sequence(&sequence);

let url = request.build_url("https://horizon-testnet.stellar.org");

Expand Down
Loading