#[cfg(feature = "test-sbf")] pub mod setup; use setup::*; use chrono::{TimeZone, Utc}; use mpl_gavel::{ errors::MplGavelError, pod::Auction, types::{Configuration, Key, Mode, Tick}, }; use podded::ZeroCopy; use solana_program::native_token::LAMPORTS_PER_SOL; use solana_program_test::{tokio, ProgramTest}; use solana_sdk::{signature::Keypair, signer::Signer}; mod initialize { use super::*; #[tokio::test] async fn initialize_dutch_auction() { let program_test = ProgramTest::new("gavel_program", mpl_gavel::ID, None); let mut context = program_test.start_with_context().await; let authority = Keypair::new(); let treasury = Keypair::new(); let mut manager = AuctionManager::default(); manager .initialize( &mut context, authority, treasury.pubkey(), Configuration::DutchV1 { capacity: 10_000, start_date: Utc .with_ymd_and_hms(2023, 1, 1, 0, 0, 0) .unwrap() .timestamp(), end_date: chrono::offset::Utc::now().timestamp(), start_value: 5 * LAMPORTS_PER_SOL, minimum_value: LAMPORTS_PER_SOL, refund_fee: 0, }, ) .await .unwrap(); } #[tokio::test] async fn initialize_english_auction() { let program_test = ProgramTest::new("gavel_program", mpl_gavel::ID, None); let mut context = program_test.start_with_context().await; let authority = Keypair::new(); let treasury = Keypair::new(); let mut manager = AuctionManager::default(); manager .initialize( &mut context, authority, treasury.pubkey(), Configuration::EnglishV1 { start_date: Utc .with_ymd_and_hms(2023, 1, 1, 0, 0, 0) .unwrap() .timestamp(), end_date: chrono::offset::Utc::now().timestamp(), grace_period: 0, start_value: LAMPORTS_PER_SOL, tick: Tick::Percentage, tick_value: 500, refund_fee: 0, }, ) .await .unwrap(); } #[tokio::test] async fn initialize_dutlish_auction() { let program_test = ProgramTest::new("gavel_program", mpl_gavel::ID, None); let mut context = program_test.start_with_context().await; let authority = Keypair::new(); let treasury = Keypair::new(); let mut manager = AuctionManager::default(); manager .initialize( &mut context, authority, treasury.pubkey(), Configuration::DutlishV1 { start_date: Utc .with_ymd_and_hms(2023, 1, 1, 0, 0, 0) .unwrap() .timestamp(), end_date: chrono::offset::Utc::now().timestamp(), grace_period: 0, limit_date: chrono::offset::Utc::now().timestamp() + (1000 * 60 * 60), start_value: 5 * LAMPORTS_PER_SOL, minimum_value: LAMPORTS_PER_SOL, tick: Tick::Percentage, tick_value: 500, refund_fee: 0, }, ) .await .unwrap(); // asserts let auction_account = context .banks_client .get_account(manager.auction.pubkey()) .await .unwrap() .unwrap(); let auction = Auction::load(&auction_account.data); assert_eq!(auction.key(), Key::Auction); assert_eq!(auction.mode(), Mode::Dutlish); } #[tokio::test] async fn fail_initialize_english_auction_invalid_tick_value() { let program_test = ProgramTest::new("gavel_program", mpl_gavel::ID, None); let mut context = program_test.start_with_context().await; let authority = Keypair::new(); let treasury = Keypair::new(); let mut manager = AuctionManager::default(); let error = manager .initialize( &mut context, authority, treasury.pubkey(), Configuration::EnglishV1 { start_date: Utc .with_ymd_and_hms(2023, 1, 1, 0, 0, 0) .unwrap() .timestamp(), end_date: chrono::offset::Utc::now().timestamp(), grace_period: 0, start_value: LAMPORTS_PER_SOL, tick: Tick::Percentage, tick_value: 100_000, refund_fee: 0, }, ) .await .unwrap_err(); assert_custom_instruction_error!(1, error, MplGavelError::InvalidTickValue); } }