Files
solisting/programs/solisting/tests/test_listings.rs
2026-06-14 20:31:37 +02:00

131 lines
3.7 KiB
Rust

mod common;
use common::*;
use solana_signer::Signer;
#[test]
fn seller_can_create_sol_only_listing() {
let (mut svm, seller, _) = setup();
let listing_id: u64 = 1;
let price = 100_000_000u64; // 0.1 SOL in lamports
let ix = ix_create_listing(
&seller.pubkey(),
listing_id,
Currency::Sol,
price,
None,
vec![],
vec![],
10,
"ipfs://test".to_string(),
);
send(&mut svm, &[ix], &[&seller]);
let listing = read_listing(&svm, &seller.pubkey(), listing_id);
assert_eq!(listing.canonical_currency, Currency::Sol);
assert_eq!(listing.price, price);
assert_eq!(listing.alt_currencies.len(), 0);
assert_eq!(listing.canonical_oracle, None);
assert_eq!(listing.quantity, 10);
assert_eq!(listing.quantity_reserved, 0);
assert!(listing.is_active);
}
#[test]
fn seller_can_create_listing_with_usdc_alt_stablecoin() {
let (mut svm, seller, _) = setup();
let usdc_mint = Pubkey::new_unique();
let sol_usd_feed = Pubkey::new_unique();
let ix = ix_create_listing(
&seller.pubkey(),
10,
Currency::Sol,
1_000_000_000,
Some(sol_usd_feed),
vec![AltCurrencyConfig {
currency: Currency::Spl { mint: usdc_mint, decimals: 6 },
usd_oracle: None,
}],
vec![],
5,
"ipfs://x".to_string(),
);
send(&mut svm, &[ix], &[&seller]);
let listing = read_listing(&svm, &seller.pubkey(), 10);
assert_eq!(listing.canonical_oracle, Some(sol_usd_feed));
assert_eq!(listing.alt_currencies[0].usd_oracle, None);
}
#[test]
fn seller_can_create_listing_with_bonk_alt_oracle() {
let (mut svm, seller, _) = setup();
let bonk_mint = Pubkey::new_unique();
let sol_usd_feed = Pubkey::new_unique();
let bonk_usd_feed = Pubkey::new_unique();
let ix = ix_create_listing(
&seller.pubkey(),
11,
Currency::Sol,
1_000_000_000,
Some(sol_usd_feed),
vec![AltCurrencyConfig {
currency: Currency::Spl { mint: bonk_mint, decimals: 5 },
usd_oracle: Some(bonk_usd_feed),
}],
vec![],
5,
"".to_string(),
);
send(&mut svm, &[ix], &[&seller]);
let listing = read_listing(&svm, &seller.pubkey(), 11);
assert_eq!(listing.canonical_oracle, Some(sol_usd_feed));
assert_eq!(listing.alt_currencies[0].usd_oracle, Some(bonk_usd_feed));
}
#[test]
fn seller_can_update_listing() {
let (mut svm, seller, _) = setup();
let listing_id: u64 = 2;
let ix = ix_create_listing(
&seller.pubkey(), listing_id, Currency::Sol, 1_000_000_000,
None, vec![], vec![], 10, "".to_string(),
);
send(&mut svm, &[ix], &[&seller]);
let ix_update = ix_update_listing(
&seller.pubkey(),
listing_id,
Currency::Sol,
2_000_000_000,
None,
vec![],
vec![],
20,
"ipfs://new".to_string(),
);
send(&mut svm, &[ix_update], &[&seller]);
let listing = read_listing(&svm, &seller.pubkey(), listing_id);
assert_eq!(listing.price, 2_000_000_000);
assert_eq!(listing.quantity, 20);
}
#[test]
fn seller_can_close_listing() {
let (mut svm, seller, _) = setup();
let listing_id: u64 = 3;
let ix = ix_create_listing(
&seller.pubkey(), listing_id, Currency::Sol, 1_000_000_000,
None, vec![], vec![], 5, "".to_string(),
);
send(&mut svm, &[ix], &[&seller]);
let ix_close = ix_close_listing(&seller.pubkey(), listing_id);
send(&mut svm, &[ix_close], &[&seller]);
let pda = listing_pda(&seller.pubkey(), listing_id);
assert!(svm.get_account(&pda).is_none());
}