diff --git a/src/loaders.rs b/src/loaders.rs index dd53166..c0b0692 100644 --- a/src/loaders.rs +++ b/src/loaders.rs @@ -423,944 +423,3 @@ pub fn load_program<'a, 'info>( Ok(()) } - -// #[cfg(test)] -// mod tests { -// use solana_program::{ -// account_info::AccountInfo, keccak::Hash as KeccakHash, program_option::COption, -// program_pack::Pack, pubkey::Pubkey, system_program, -// }; -// use spl_token::state::{AccountState, Mint}; - -// use crate::{ -// loaders::{ -// load_account, load_any_bus, load_bus, load_mint, load_proof, load_signer, load_sysvar, -// load_token_account, load_treasury, load_uninitialized_account, load_uninitialized_pda, -// }, -// state::{Bus, Proof, Treasury}, -// utils::Discriminator, -// BUS, BUS_ADDRESSES, BUS_COUNT, MINT_ADDRESS, PROOF, TOKEN_DECIMALS, TREASURY, -// TREASURY_ADDRESS, -// }; - -// use super::load_program; - -// #[test] -// pub fn test_signer_not_signer() { -// let key = Pubkey::new_unique(); -// let mut lamports = 1_000_000_000; -// let mut data = []; -// let owner = system_program::id(); -// let info = AccountInfo::new( -// &key, -// false, -// false, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_signer(&info).is_err()); -// } - -// #[test] -// pub fn test_load_bus_bad_account_owner() { -// let key = BUS_ADDRESSES[0]; -// let mut lamports = 1_000_000_000; -// let mut data = []; -// let owner = system_program::id(); -// let info = AccountInfo::new( -// &key, -// false, -// true, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_bus(&info, 0, true).is_err()); -// } - -// #[test] -// pub fn test_load_bus_bad_key() { -// let key = Pubkey::new_unique(); -// let mut lamports = 1_000_000_000; -// let mut data = []; -// let owner = crate::id(); -// let info = AccountInfo::new( -// &key, -// false, -// true, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_bus(&info, 0, true).is_err()); -// } - -// #[test] -// pub fn test_load_bus_empty_data() { -// let key = BUS_ADDRESSES[0]; -// let mut lamports = 1_000_000_000; -// let mut data = []; -// let owner = crate::id(); -// let info = AccountInfo::new( -// &key, -// false, -// true, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_bus(&info, 0, true).is_err()); -// } - -// #[test] -// pub fn test_load_bus_bad_data() { -// let key = BUS_ADDRESSES[0]; -// let mut lamports = 1_000_000_000; -// let mut data = [ -// &(Treasury::discriminator() as u64).to_le_bytes(), // Bus discriminator -// Bus { id: 0, rewards: 0 }.to_bytes(), -// ] -// .concat(); -// let owner = crate::id(); -// let info = AccountInfo::new( -// &key, -// false, -// true, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_bus(&info, 0, true).is_err()); -// } - -// #[test] -// pub fn test_load_bus_bad_id() { -// let key = BUS_ADDRESSES[0]; -// let mut lamports = 1_000_000_000; -// let mut data = [ -// &(Bus::discriminator() as u64).to_le_bytes(), // Bus discriminator -// Bus { id: 1, rewards: 0 }.to_bytes(), -// ] -// .concat(); -// let owner = crate::id(); -// let info = AccountInfo::new( -// &key, -// false, -// true, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_bus(&info, 0, true).is_err()); -// } - -// #[test] -// pub fn test_load_bus_not_writeable() { -// let key = BUS_ADDRESSES[0]; -// let mut lamports = 1_000_000_000; -// let mut data = [ -// &(Bus::discriminator() as u64).to_le_bytes(), -// Bus { id: 0, rewards: 0 }.to_bytes(), -// ] -// .concat(); -// let owner = crate::id(); -// let info = AccountInfo::new( -// &key, -// false, -// false, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_bus(&info, 0, true).is_err()); -// } - -// #[test] -// pub fn test_load_any_bus_bad_account_owner() { -// let key = BUS_ADDRESSES[0]; -// let mut lamports = 1_000_000_000; -// let mut data = []; -// let owner = system_program::id(); -// let info = AccountInfo::new( -// &key, -// false, -// true, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_any_bus(&info, true).is_err()); -// } - -// #[test] -// pub fn test_load_any_bus_bad_key() { -// let key = Pubkey::new_unique(); -// let mut lamports = 1_000_000_000; -// let mut data = []; -// let owner = crate::id(); -// let info = AccountInfo::new( -// &key, -// false, -// true, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_any_bus(&info, true).is_err()); -// } - -// #[test] -// pub fn test_load_any_bus_empty_data() { -// let key = BUS_ADDRESSES[0]; -// let mut lamports = 1_000_000_000; -// let mut data = []; -// let owner = crate::id(); -// let info = AccountInfo::new( -// &key, -// false, -// true, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_any_bus(&info, true).is_err()); -// } - -// #[test] -// pub fn test_load_any_bus_bad_data() { -// let key = BUS_ADDRESSES[0]; -// let mut lamports = 1_000_000_000; -// let mut data = [ -// &(Treasury::discriminator() as u64).to_le_bytes(), // Treasury discriminator -// Bus { id: 0, rewards: 0 }.to_bytes(), -// ] -// .concat(); -// let owner = crate::id(); -// let info = AccountInfo::new( -// &key, -// false, -// true, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_any_bus(&info, true).is_err()); -// } - -// #[test] -// pub fn test_load_any_bus_bad_id() { -// let key = BUS_ADDRESSES[0]; -// let mut lamports = 1_000_000_000; -// let mut data = [ -// &(Bus::discriminator() as u64).to_le_bytes(), -// Bus { -// id: (BUS_COUNT + 1) as u64, -// rewards: 0, -// } -// .to_bytes(), -// ] -// .concat(); -// let owner = crate::id(); -// let info = AccountInfo::new( -// &key, -// false, -// true, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_any_bus(&info, true).is_err()); -// } - -// #[test] -// pub fn test_load_any_bus_mismatch_id() { -// let key = BUS_ADDRESSES[0]; -// let mut lamports = 1_000_000_000; -// let mut data = [ -// &(Bus::discriminator() as u64).to_le_bytes(), -// Bus { -// id: 1 as u64, -// rewards: 0, -// } -// .to_bytes(), -// ] -// .concat(); -// let owner = crate::id(); -// let info = AccountInfo::new( -// &key, -// false, -// true, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_any_bus(&info, true).is_err()); -// } - -// #[test] -// pub fn test_load_any_bus_not_writeable() { -// let key = BUS_ADDRESSES[0]; -// let mut lamports = 1_000_000_000; -// let mut data = [ -// &(Bus::discriminator() as u64).to_le_bytes(), -// Bus { id: 0, rewards: 0 }.to_bytes(), -// ] -// .concat(); -// let owner = crate::id(); -// let info = AccountInfo::new( -// &key, -// false, -// false, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_any_bus(&info, true).is_err()); -// } - -// #[test] -// pub fn test_load_proof_bad_account_owner() { -// let authority = Pubkey::new_unique(); -// let pda = Pubkey::find_program_address(&[PROOF, authority.as_ref()], &crate::id()); -// let mut lamports = 1_000_000_000; -// let mut data = []; -// let owner = system_program::id(); -// let info = AccountInfo::new( -// &pda.0, -// false, -// true, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_proof(&info, &authority, true).is_err()); -// } - -// #[test] -// pub fn test_load_proof_bad_key() { -// let key = Pubkey::new_unique(); -// let mut lamports = 1_000_000_000; -// let mut data = []; -// let owner = crate::id(); -// let info = AccountInfo::new( -// &key, -// false, -// true, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_proof(&info, &Pubkey::new_unique(), true).is_err()); -// } - -// #[test] -// pub fn test_load_proof_empty_data() { -// let authority = Pubkey::new_unique(); -// let pda = Pubkey::find_program_address(&[PROOF, authority.as_ref()], &crate::id()); -// let mut lamports = 1_000_000_000; -// let mut data = []; -// let owner = crate::id(); -// let info = AccountInfo::new( -// &pda.0, -// false, -// true, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_proof(&info, &authority, true).is_err()); -// } - -// #[test] -// pub fn test_load_proof_bad_data() { -// let authority = Pubkey::new_unique(); -// let pda = Pubkey::find_program_address(&[PROOF, authority.as_ref()], &crate::id()); -// let mut lamports = 1_000_000_000; -// let mut data = [ -// &(Bus::discriminator() as u64).to_le_bytes(), // Bus discriminator -// Proof { -// authority, -// balance: 0, -// hash: KeccakHash::new_from_array([u8::MAX; 32]).into(), -// total_hashes: 0, -// total_rewards: 0, -// multiplier: 1, -// last_hash_at: 0, -// } -// .to_bytes(), -// ] -// .concat(); -// let owner = crate::id(); -// let info = AccountInfo::new( -// &pda.0, -// false, -// true, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_proof(&info, &authority, true).is_err()); -// } - -// #[test] -// pub fn test_load_proof_not_writeable() { -// let authority = Pubkey::new_unique(); -// let pda = Pubkey::find_program_address(&[PROOF, authority.as_ref()], &crate::id()); -// let mut lamports = 1_000_000_000; -// let mut data = [ -// &(Proof::discriminator() as u64).to_le_bytes(), -// Proof { -// authority, -// claimable_rewards: 0, -// hash: KeccakHash::new_from_array([u8::MAX; 32]).into(), -// total_hashes: 0, -// total_rewards: 0, -// } -// .to_bytes(), -// ] -// .concat(); -// let owner = crate::id(); -// let info = AccountInfo::new( -// &pda.0, -// false, -// false, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_proof(&info, &authority, true).is_err()); -// } - -// #[test] -// pub fn test_load_treasury_bad_account_owner() { -// let pda = Pubkey::find_program_address(&[TREASURY], &crate::id()); -// let mut lamports = 1_000_000_000; -// let mut data = []; -// let owner = system_program::id(); -// let info = AccountInfo::new( -// &pda.0, -// false, -// true, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_treasury(&info, true).is_err()); -// } - -// #[test] -// pub fn test_load_treasury_bad_key() { -// let key = Pubkey::new_unique(); -// let mut lamports = 1_000_000_000; -// let mut data = []; -// let owner = crate::id(); -// let info = AccountInfo::new( -// &key, -// false, -// true, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_treasury(&info, true).is_err()); -// } - -// #[test] -// pub fn test_load_treasury_empty_data() { -// let key = TREASURY_ADDRESS; -// let mut lamports = 1_000_000_000; -// let mut data = []; -// let owner = crate::id(); -// let info = AccountInfo::new( -// &key, -// false, -// true, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_treasury(&info, true).is_err()); -// } - -// #[test] -// pub fn test_load_treasury_bad_data() { -// let pda = Pubkey::find_program_address(&[TREASURY], &crate::id()); -// let mut lamports = 1_000_000_000; -// let mut data = [ -// &(Bus::discriminator() as u64).to_le_bytes(), // Bus discriminator -// Treasury { -// bump: pda.1 as u64, -// // admin: Pubkey::new_unique(), -// // difficulty: KeccakHash::new_from_array([u8::MAX; 32]).into(), -// last_reset_at: 0, -// reward_rate: 100, -// total_claimed_rewards: 0, -// } -// .to_bytes(), -// ] -// .concat(); -// let owner = crate::id(); -// let info = AccountInfo::new( -// &pda.0, -// false, -// true, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_treasury(&info, true).is_err()); -// } - -// #[test] -// pub fn test_load_treasury_not_writeable() { -// let pda = Pubkey::find_program_address(&[TREASURY], &crate::id()); -// let mut lamports = 1_000_000_000; -// let mut data = [ -// &(Treasury::discriminator() as u64).to_le_bytes(), -// Treasury { -// bump: pda.1 as u64, -// // admin: Pubkey::new_unique(), -// // difficulty: KeccakHash::new_from_array([u8::MAX; 32]).into(), -// last_reset_at: 0, -// reward_rate: 100, -// total_claimed_rewards: 0, -// } -// .to_bytes(), -// ] -// .concat(); -// let owner = crate::id(); -// let info = AccountInfo::new( -// &pda.0, -// false, -// false, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_treasury(&info, true).is_err()); -// } - -// #[test] -// pub fn test_load_mint_bad_account_owner() { -// let key = MINT_ADDRESS; -// let mut lamports = 1_000_000_000; -// let mut data = []; -// let owner = system_program::id(); -// let info = AccountInfo::new( -// &key, -// false, -// true, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_token_account(&info, None, &MINT_ADDRESS, true).is_err()); -// } - -// #[test] -// pub fn test_load_mint_bad_key() { -// let key = Pubkey::new_unique(); -// let mut lamports = 1_000_000_000; -// let mut data = []; -// let owner = spl_token::id(); -// let info = AccountInfo::new( -// &key, -// false, -// true, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_mint(&info, true).is_err()); -// } - -// #[test] -// pub fn test_load_mint_empty_data() { -// let key = MINT_ADDRESS; -// let mut lamports = 1_000_000_000; -// let mut data = []; -// let owner = spl_token::id(); -// let info = AccountInfo::new( -// &key, -// false, -// true, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_mint(&info, true).is_err()); -// } - -// #[test] -// pub fn test_load_mint_bad_data() { -// let key = MINT_ADDRESS; -// let mut lamports = 1_000_000_000; -// let mut data = [1]; -// let owner = spl_token::id(); -// let info = AccountInfo::new( -// &key, -// false, -// true, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_mint(&info, true).is_err()); -// } - -// #[test] -// pub fn test_load_mint_not_writeable() { -// let mut data: [u8; Mint::LEN] = [0; Mint::LEN]; -// Mint { -// mint_authority: COption::Some(TREASURY_ADDRESS), -// supply: 0, -// decimals: TOKEN_DECIMALS, -// is_initialized: true, -// freeze_authority: COption::None, -// } -// .pack_into_slice(&mut data); -// let key = MINT_ADDRESS; -// let mut lamports = 1_000_000_000; -// let owner = spl_token::id(); -// let info = AccountInfo::new( -// &key, -// false, -// false, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_mint(&info, true).is_err()); -// } - -// #[test] -// pub fn test_load_token_account_bad_account_owner() { -// let mut data: [u8; spl_token::state::Account::LEN] = [0; spl_token::state::Account::LEN]; -// spl_token::state::Account { -// mint: MINT_ADDRESS, -// owner: TREASURY_ADDRESS, -// amount: 2_000_000_000, -// delegate: COption::None, -// state: AccountState::Initialized, -// is_native: COption::None, -// delegated_amount: 0, -// close_authority: COption::None, -// } -// .pack_into_slice(&mut data); -// let key = Pubkey::new_unique(); -// let mut lamports = 1_000_000_000; -// let owner = system_program::id(); -// let info = AccountInfo::new( -// &key, -// false, -// true, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_token_account(&info, None, &MINT_ADDRESS, true).is_err()); -// } - -// #[test] -// pub fn test_load_token_account_empty_data() { -// let key = Pubkey::new_unique(); -// let mut lamports = 1_000_000_000; -// let mut data = []; -// let owner = spl_token::id(); -// let info = AccountInfo::new( -// &key, -// false, -// true, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_token_account(&info, None, &MINT_ADDRESS, true).is_err()); -// } - -// #[test] -// pub fn test_load_token_account_bad_data() { -// let key = Pubkey::new_unique(); -// let mut lamports = 1_000_000_000; -// let mut data = [1]; -// let owner = spl_token::id(); -// let info = AccountInfo::new( -// &key, -// false, -// true, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_token_account(&info, None, &MINT_ADDRESS, true).is_err()); -// } - -// #[test] -// pub fn test_load_token_account_bad_owner_mint() { -// let mut data: [u8; spl_token::state::Account::LEN] = [0; spl_token::state::Account::LEN]; -// spl_token::state::Account { -// mint: MINT_ADDRESS, -// owner: TREASURY_ADDRESS, -// amount: 2_000_000_000, -// delegate: COption::None, -// state: AccountState::Initialized, -// is_native: COption::None, -// delegated_amount: 0, -// close_authority: COption::None, -// } -// .pack_into_slice(&mut data); -// let key = Pubkey::new_unique(); -// let mut lamports = 1_000_000_000; -// let owner = spl_token::id(); -// let info = AccountInfo::new( -// &key, -// false, -// false, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_token_account(&info, Some(&key), &MINT_ADDRESS, false).is_err()); -// assert!(load_token_account(&info, None, &Pubkey::new_unique(), false).is_err()); -// assert!(load_token_account(&info, None, &MINT_ADDRESS, true).is_err()); -// } - -// #[test] -// pub fn test_load_uninitialized_pda_bad_key_bump() { -// let pda = Pubkey::find_program_address(&[TREASURY], &crate::id()); -// let mut lamports = 1_000_000_000; -// let mut data = []; -// let owner = system_program::id(); -// let info = AccountInfo::new( -// &pda.0, -// false, -// true, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_uninitialized_pda(&info, &[BUS], pda.1, &crate::id()).is_err()); -// assert!(load_uninitialized_pda(&info, &[TREASURY], 0, &crate::id()).is_err()); -// } - -// #[test] -// pub fn test_load_uninitialized_account_bad_owner() { -// let key = Pubkey::new_unique(); -// let mut lamports = 1_000_000_000; -// let mut data = []; -// let owner = spl_token::id(); -// let info = AccountInfo::new( -// &key, -// false, -// true, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_uninitialized_account(&info).is_err()); -// } - -// #[test] -// pub fn test_load_uninitialized_account_data_not_empty() { -// let key = Pubkey::new_unique(); -// let mut lamports = 1_000_000_000; -// let mut data = [0]; -// let owner = system_program::id(); -// let info = AccountInfo::new( -// &key, -// false, -// true, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_uninitialized_account(&info).is_err()); -// } - -// #[test] -// pub fn test_load_uninitialized_account_not_writeable() { -// let key = Pubkey::new_unique(); -// let mut lamports = 1_000_000_000; -// let mut data = []; -// let owner = system_program::id(); -// let info = AccountInfo::new( -// &key, -// false, -// false, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_uninitialized_account(&info).is_err()); -// } - -// #[test] -// pub fn test_load_sysvar_bad_owner() { -// let key = Pubkey::new_unique(); -// let mut lamports = 1_000_000_000; -// let mut data = []; -// let owner = system_program::id(); -// let info = AccountInfo::new( -// &key, -// false, -// false, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_sysvar(&info, key).is_err()); -// } - -// #[test] -// pub fn test_load_account_bad_key() { -// let key = Pubkey::new_unique(); -// let mut lamports = 1_000_000_000; -// let mut data = []; -// let owner = system_program::id(); -// let info = AccountInfo::new( -// &key, -// false, -// false, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_account(&info, Pubkey::new_unique(), false).is_err()); -// } - -// #[test] -// pub fn test_load_account_not_writeable() { -// let key = Pubkey::new_unique(); -// let mut lamports = 1_000_000_000; -// let mut data = []; -// let owner = system_program::id(); -// let info = AccountInfo::new( -// &key, -// false, -// false, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_account(&info, key, true).is_err()); -// } - -// #[test] -// pub fn test_load_program_bad_key() { -// let key = Pubkey::new_unique(); -// let mut lamports = 1_000_000_000; -// let mut data = []; -// let owner = system_program::id(); -// let info = AccountInfo::new( -// &key, -// false, -// false, -// &mut lamports, -// &mut data, -// &owner, -// true, -// 0, -// ); -// assert!(load_program(&info, Pubkey::new_unique()).is_err()); -// } - -// #[test] -// pub fn test_load_program_not_executable() { -// let key = Pubkey::new_unique(); -// let mut lamports = 1_000_000_000; -// let mut data = []; -// let owner = system_program::id(); -// let info = AccountInfo::new( -// &key, -// false, -// false, -// &mut lamports, -// &mut data, -// &owner, -// false, -// 0, -// ); -// assert!(load_program(&info, key).is_err()); -// } -// } diff --git a/tests/buffers/metadata_program.bpf b/tests/buffers/metadata_program.bpf deleted file mode 100644 index 3ebd1b6..0000000 Binary files a/tests/buffers/metadata_program.bpf and /dev/null differ diff --git a/tests/test_initialize.rs b/tests/test_initialize.rs deleted file mode 100644 index 9e6a840..0000000 --- a/tests/test_initialize.rs +++ /dev/null @@ -1,170 +0,0 @@ -// use mpl_token_metadata::{ -// accounts::Metadata, -// types::{Key, TokenStandard}, -// }; -// use ore::{ -// state::{Bus, Treasury}, -// utils::AccountDeserialize, -// BUS_ADDRESSES, BUS_COUNT, INITIAL_DIFFICULTY, INITIAL_REWARD_RATE, METADATA_ADDRESS, -// METADATA_NAME, METADATA_SYMBOL, METADATA_URI, MINT_ADDRESS, TREASURY, -// }; -// use solana_program::{ -// hash::Hash, program_option::COption, program_pack::Pack, pubkey::Pubkey, rent::Rent, -// }; -// use solana_program_test::{processor, read_file, BanksClient, ProgramTest}; -// use solana_sdk::{ -// account::Account, -// signature::{Keypair, Signer}, -// transaction::Transaction, -// }; -// use spl_token::state::{AccountState, Mint}; - -// #[tokio::test] -// async fn test_initialize() { -// // Setup -// let (mut banks, payer, blockhash) = setup_program_test_env().await; - -// // Pdas -// let treasury_pda = Pubkey::find_program_address(&[TREASURY], &ore::id()); -// let treasury_tokens_address = -// spl_associated_token_account::get_associated_token_address(&treasury_pda.0, &MINT_ADDRESS); - -// // Submit tx -// let ix = ore::instruction::initialize(payer.pubkey()); -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_ok()); - -// // Test bus state -// for i in 0..BUS_COUNT { -// let bus_account = banks.get_account(BUS_ADDRESSES[i]).await.unwrap().unwrap(); -// assert_eq!(bus_account.owner, ore::id()); -// let bus = Bus::try_from_bytes(&bus_account.data).unwrap(); -// assert_eq!(bus.id as u8, i as u8); -// assert_eq!(bus.rewards, 0); -// } - -// // Test treasury state -// let treasury_account = banks.get_account(treasury_pda.0).await.unwrap().unwrap(); -// assert_eq!(treasury_account.owner, ore::id()); -// let treasury = Treasury::try_from_bytes(&treasury_account.data).unwrap(); -// assert_eq!(treasury.bump as u8, treasury_pda.1); -// // assert_eq!(treasury.admin, payer.pubkey()); -// // assert_eq!(treasury.difficulty, INITIAL_DIFFICULTY.into()); -// assert_eq!(treasury.last_reset_at as u8, 0); -// assert_eq!(treasury.reward_rate, INITIAL_REWARD_RATE); -// assert_eq!(treasury.total_claimed_rewards as u8, 0); - -// // Test mint state -// let mint_account = banks.get_account(MINT_ADDRESS).await.unwrap().unwrap(); -// assert_eq!(mint_account.owner, spl_token::id()); -// let mint = Mint::unpack(&mint_account.data).unwrap(); -// assert_eq!(mint.mint_authority, COption::Some(treasury_pda.0)); -// assert_eq!(mint.supply, 0); -// assert_eq!(mint.decimals, ore::TOKEN_DECIMALS); -// assert_eq!(mint.is_initialized, true); -// assert_eq!(mint.freeze_authority, COption::None); - -// // Test metadata state -// let metadata_account = banks.get_account(METADATA_ADDRESS).await.unwrap().unwrap(); -// assert_eq!(metadata_account.owner, mpl_token_metadata::ID); -// let metadata = Metadata::from_bytes(&metadata_account.data).unwrap(); -// assert_eq!(metadata.key, Key::MetadataV1); -// assert_eq!(metadata.update_authority, payer.pubkey()); -// assert_eq!(metadata.mint, MINT_ADDRESS); -// assert_eq!(metadata.name.trim_end_matches('\0'), METADATA_NAME); -// assert_eq!(metadata.symbol.trim_end_matches('\0'), METADATA_SYMBOL); -// assert_eq!(metadata.uri.trim_end_matches('\0'), METADATA_URI); -// assert_eq!(metadata.seller_fee_basis_points, 0); -// assert_eq!(metadata.creators, None); -// assert_eq!(metadata.primary_sale_happened, false); -// assert_eq!(metadata.is_mutable, true); -// assert_eq!(metadata.token_standard, Some(TokenStandard::Fungible)); -// assert_eq!(metadata.collection, None); -// assert_eq!(metadata.uses, None); -// assert_eq!(metadata.collection_details, None); -// assert_eq!(metadata.programmable_config, None); - -// // Test treasury token state -// let treasury_tokens_account = banks -// .get_account(treasury_tokens_address) -// .await -// .unwrap() -// .unwrap(); -// assert_eq!(treasury_tokens_account.owner, spl_token::id()); -// let treasury_tokens = spl_token::state::Account::unpack(&treasury_tokens_account.data).unwrap(); -// assert_eq!(treasury_tokens.mint, MINT_ADDRESS); -// assert_eq!(treasury_tokens.owner, treasury_pda.0); -// assert_eq!(treasury_tokens.amount, 0); -// assert_eq!(treasury_tokens.delegate, COption::None); -// assert_eq!(treasury_tokens.state, AccountState::Initialized); -// assert_eq!(treasury_tokens.is_native, COption::None); -// assert_eq!(treasury_tokens.delegated_amount, 0); -// assert_eq!(treasury_tokens.close_authority, COption::None); -// } - -// #[tokio::test] -// async fn test_initialize_not_enough_accounts() { -// // Setup -// let (mut banks, payer, blockhash) = setup_program_test_env().await; - -// // Submit tx -// let mut ix = ore::instruction::initialize(payer.pubkey()); -// ix.accounts.remove(1); -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_err()); -// } - -// #[tokio::test] -// async fn test_initialize_bad_key() { -// // Setup -// let (mut banks, payer, blockhash) = setup_program_test_env().await; - -// // Bad addresses -// let bad_pda = Pubkey::find_program_address(&[b"t"], &ore::id()); -// for i in 1..12 { -// let mut ix = ore::instruction::initialize(payer.pubkey()); -// ix.accounts[i].pubkey = bad_pda.0; -// let tx = -// Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_err()); -// } -// } - -// #[tokio::test] -// async fn test_initialize_bad_programs() { -// // Setup -// let (mut banks, payer, blockhash) = setup_program_test_env().await; - -// // Bad addresses -// for i in 13..18 { -// let mut ix = ore::instruction::initialize(payer.pubkey()); -// ix.accounts[i].pubkey = Pubkey::new_unique(); -// let tx = -// Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_err()); -// } -// } - -// async fn setup_program_test_env() -> (BanksClient, Keypair, Hash) { -// let mut program_test = ProgramTest::new("ore", ore::ID, processor!(ore::process_instruction)); -// program_test.prefer_bpf(true); - -// // Setup metadata program -// let data = read_file(&"tests/buffers/metadata_program.bpf"); -// program_test.add_account( -// mpl_token_metadata::ID, -// Account { -// lamports: Rent::default().minimum_balance(data.len()).max(1), -// data, -// owner: solana_sdk::bpf_loader::id(), -// executable: true, -// rent_epoch: 0, -// }, -// ); - -// program_test.start().await -// } diff --git a/tests/test_mine.rs b/tests/test_mine.rs deleted file mode 100644 index ae10349..0000000 --- a/tests/test_mine.rs +++ /dev/null @@ -1,746 +0,0 @@ -// use std::{mem::size_of, str::FromStr}; - -// use ore::{ -// instruction::{MineArgs, OreInstruction}, -// state::{Bus, Proof, Treasury}, -// utils::{AccountDeserialize, Discriminator}, -// BUS_ADDRESSES, BUS_COUNT, EPOCH_DURATION, INITIAL_REWARD_RATE, MINT_ADDRESS, PROOF, START_AT, -// TOKEN_DECIMALS, TREASURY, TREASURY_ADDRESS, -// }; -// use rand::{distributions::Uniform, Rng}; -// use solana_program::{ -// clock::Clock, -// epoch_schedule::DEFAULT_SLOTS_PER_EPOCH, -// hash::Hash, -// instruction::{AccountMeta, Instruction}, -// keccak::{hashv, Hash as KeccakHash}, -// native_token::LAMPORTS_PER_SOL, -// program_option::COption, -// program_pack::Pack, -// pubkey::Pubkey, -// slot_hashes::SlotHash, -// system_program, sysvar, -// }; -// use solana_program_test::{processor, BanksClient, ProgramTest}; -// use solana_sdk::{ -// account::Account, -// signature::{Keypair, Signer}, -// transaction::Transaction, -// }; -// use spl_associated_token_account::{ -// get_associated_token_address, instruction::create_associated_token_account, -// }; -// use spl_token::state::{AccountState, Mint}; - -// #[tokio::test] -// async fn test_mine() { -// // Setup -// let (mut banks, payer, _, blockhash) = setup_program_test_env(true, ClockState::Normal).await; - -// // Submit register tx -// let proof_pda = Pubkey::find_program_address(&[PROOF, payer.pubkey().as_ref()], &ore::id()); -// let ix = ore::instruction::register(payer.pubkey()); -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_ok()); - -// // Assert proof state -// let proof_account = banks.get_account(proof_pda.0).await.unwrap().unwrap(); -// assert_eq!(proof_account.owner, ore::id()); -// let proof = Proof::try_from_bytes(&proof_account.data).unwrap(); -// assert_eq!(proof.authority, payer.pubkey()); -// assert_eq!(proof.claimable_rewards, 0); -// assert_eq!(proof.total_hashes, 0); -// assert_eq!(proof.total_rewards, 0); - -// // Find next hash -// let (next_hash, nonce) = find_next_hash( -// proof.hash.into(), -// KeccakHash::new_from_array([u8::MAX; 32]), -// payer.pubkey(), -// ); - -// // Submit mine tx -// let ix = ore::instruction::mine(payer.pubkey(), BUS_ADDRESSES[0], nonce); -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_ok()); - -// // Assert proof state -// let slot_hashes_account = banks -// .get_account(sysvar::slot_hashes::id()) -// .await -// .unwrap() -// .unwrap(); -// let slot_hash_bytes = &slot_hashes_account.data[0..size_of::()]; -// let proof_account = banks.get_account(proof_pda.0).await.unwrap().unwrap(); -// assert_eq!(proof_account.owner, ore::id()); -// let proof = Proof::try_from_bytes(&proof_account.data).unwrap(); -// assert_eq!(proof.authority, payer.pubkey()); -// assert_eq!(proof.claimable_rewards, INITIAL_REWARD_RATE); -// assert_eq!( -// proof.hash, -// hashv(&[&next_hash.as_ref(), slot_hash_bytes,]).into() -// ); -// assert_eq!(proof.total_hashes, 1); -// assert_eq!(proof.total_rewards, INITIAL_REWARD_RATE); - -// // Submit claim tx -// let amount = proof.claimable_rewards; -// let beneficiary_address = get_associated_token_address(&payer.pubkey(), &ore::MINT_ADDRESS); -// let token_ix = create_associated_token_account( -// &payer.pubkey(), -// &payer.pubkey(), -// &ore::MINT_ADDRESS, -// &spl_token::id(), -// ); -// let ix = ore::instruction::claim(payer.pubkey(), beneficiary_address, amount); -// let tx = Transaction::new_signed_with_payer( -// &[token_ix, ix], -// Some(&payer.pubkey()), -// &[&payer], -// blockhash, -// ); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_ok()); - -// // Assert proof state -// let proof_account = banks.get_account(proof_pda.0).await.unwrap().unwrap(); -// let proof_ = Proof::try_from_bytes(&proof_account.data).unwrap(); -// assert_eq!(proof_.authority, proof.authority); -// assert_eq!(proof_.claimable_rewards, 0); -// assert_eq!(proof_.hash, proof.hash); -// assert_eq!(proof_.total_hashes, proof.total_hashes); -// assert_eq!(proof_.total_rewards, proof.total_rewards); - -// // Assert beneficiary state -// let beneficiary_account = banks -// .get_account(beneficiary_address) -// .await -// .unwrap() -// .unwrap(); -// assert_eq!(beneficiary_account.owner, spl_token::id()); -// let beneficiary = spl_token::state::Account::unpack(&beneficiary_account.data).unwrap(); -// assert_eq!(beneficiary.mint, ore::MINT_ADDRESS); -// assert_eq!(beneficiary.owner, payer.pubkey()); -// assert_eq!(beneficiary.amount, amount); -// assert_eq!(beneficiary.delegate, COption::None); -// assert_eq!(beneficiary.state, AccountState::Initialized); -// assert_eq!(beneficiary.is_native, COption::None); -// assert_eq!(beneficiary.delegated_amount, 0); -// assert_eq!(beneficiary.close_authority, COption::None); -// } - -// #[tokio::test] -// async fn test_mine_alt_proof() { -// // Setup -// let (mut banks, payer, payer_alt, blockhash) = -// setup_program_test_env(true, ClockState::Normal).await; - -// // Submit register tx -// let proof_pda = Pubkey::find_program_address(&[PROOF, payer.pubkey().as_ref()], &ore::id()); -// let ix = ore::instruction::register(payer.pubkey()); -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_ok()); - -// // Submit register alt tx -// let proof_alt_pda = -// Pubkey::find_program_address(&[PROOF, payer_alt.pubkey().as_ref()], &ore::id()); -// let ix_alt = ore::instruction::register(payer_alt.pubkey()); -// let tx = Transaction::new_signed_with_payer( -// &[ix_alt], -// Some(&payer_alt.pubkey()), -// &[&payer_alt], -// blockhash, -// ); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_ok()); - -// // Submit mine tx with invalid proof -// let proof_account = banks.get_account(proof_pda.0).await.unwrap().unwrap(); -// let proof = Proof::try_from_bytes(&proof_account.data).unwrap(); -// let (_next_hash, nonce) = find_next_hash( -// proof.hash.into(), -// KeccakHash::new_from_array([u8::MAX; 32]), -// payer.pubkey(), -// ); -// let ix = Instruction { -// program_id: ore::id(), -// accounts: vec![ -// AccountMeta::new(payer.pubkey(), true), -// AccountMeta::new(BUS_ADDRESSES[0], false), -// AccountMeta::new(proof_alt_pda.0, false), -// AccountMeta::new(TREASURY_ADDRESS, false), -// AccountMeta::new_readonly(sysvar::slot_hashes::id(), false), -// ], -// data: [ -// OreInstruction::Mine.to_vec(), -// MineArgs { -// nonce: nonce.to_le_bytes(), -// } -// .to_bytes() -// .to_vec(), -// ] -// .concat(), -// }; -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_err()); -// } - -// #[tokio::test] -// async fn test_mine_correct_hash_alt_proof() { -// // Setup -// let (mut banks, payer, payer_alt, blockhash) = -// setup_program_test_env(true, ClockState::Normal).await; - -// // Submit register alt tx -// let proof_alt_pda = -// Pubkey::find_program_address(&[PROOF, payer_alt.pubkey().as_ref()], &ore::id()); -// let ix_alt = ore::instruction::register(payer_alt.pubkey()); -// let tx = Transaction::new_signed_with_payer( -// &[ix_alt], -// Some(&payer_alt.pubkey()), -// &[&payer_alt], -// blockhash, -// ); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_ok()); - -// // Submit with correct hash for invalid proof -// let proof_alt_account = banks.get_account(proof_alt_pda.0).await.unwrap().unwrap(); -// let proof_alt = Proof::try_from_bytes(&proof_alt_account.data).unwrap(); -// let (_next_hash, nonce) = find_next_hash( -// proof_alt.hash.into(), -// KeccakHash::new_from_array([u8::MAX; 32]), -// payer_alt.pubkey(), -// ); -// let ix = Instruction { -// program_id: ore::id(), -// accounts: vec![ -// AccountMeta::new(payer.pubkey(), true), -// AccountMeta::new(BUS_ADDRESSES[0], false), -// AccountMeta::new(proof_alt_pda.0, false), -// AccountMeta::new(TREASURY_ADDRESS, false), -// AccountMeta::new_readonly(sysvar::slot_hashes::id(), false), -// ], -// data: [ -// OreInstruction::Mine.to_vec(), -// MineArgs { -// nonce: nonce.to_le_bytes(), -// } -// .to_bytes() -// .to_vec(), -// ] -// .concat(), -// }; -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_err()); -// } - -// #[tokio::test] -// async fn test_mine_bus_rewards_insufficient() { -// // Setup -// let (mut banks, payer, _, blockhash) = setup_program_test_env(false, ClockState::Normal).await; - -// // Submit register tx -// let proof_pda = Pubkey::find_program_address(&[PROOF, payer.pubkey().as_ref()], &ore::id()); -// let ix = ore::instruction::register(payer.pubkey()); -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_ok()); - -// // Find next hash -// let proof_account = banks.get_account(proof_pda.0).await.unwrap().unwrap(); -// let proof = Proof::try_from_bytes(&proof_account.data).unwrap(); -// let (_next_hash, nonce) = find_next_hash( -// proof.hash.into(), -// KeccakHash::new_from_array([u8::MAX; 32]), -// payer.pubkey(), -// ); - -// // Submit mine tx -// let ix = ore::instruction::mine(payer.pubkey(), BUS_ADDRESSES[0], nonce); -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_err()); -// } - -// #[tokio::test] -// async fn test_claim_too_large() { -// // Setup -// let (mut banks, payer, _, blockhash) = setup_program_test_env(true, ClockState::Normal).await; - -// // Submit register tx -// let ix = ore::instruction::register(payer.pubkey()); -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_ok()); - -// // Submit claim tx -// let beneficiary = get_associated_token_address(&payer.pubkey(), &ore::MINT_ADDRESS); -// let token_ix = create_associated_token_account( -// &payer.pubkey(), -// &payer.pubkey(), -// &ore::MINT_ADDRESS, -// &spl_token::id(), -// ); -// let ix = ore::instruction::claim(payer.pubkey(), beneficiary, 1); -// let tx = Transaction::new_signed_with_payer( -// &[token_ix, ix], -// Some(&payer.pubkey()), -// &[&payer], -// blockhash, -// ); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_err()); -// } - -// #[tokio::test] -// async fn test_claim_other_proof() { -// // Setup -// let (mut banks, payer, alt_payer, blockhash) = -// setup_program_test_env(true, ClockState::Normal).await; - -// // Submit register tx -// let ix = ore::instruction::register(payer.pubkey()); -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_ok()); - -// // Submit claim tx -// let beneficiary = get_associated_token_address(&alt_payer.pubkey(), &ore::MINT_ADDRESS); -// let token_ix = create_associated_token_account( -// &alt_payer.pubkey(), -// &alt_payer.pubkey(), -// &ore::MINT_ADDRESS, -// &spl_token::id(), -// ); -// let mut ix = ore::instruction::claim(payer.pubkey(), beneficiary, 0); -// ix.accounts[0].pubkey = alt_payer.pubkey(); -// let tx = Transaction::new_signed_with_payer( -// &[token_ix, ix], -// Some(&alt_payer.pubkey()), -// &[&alt_payer], -// blockhash, -// ); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_err()); -// } - -// #[tokio::test] -// async fn test_mine_not_enough_accounts() { -// // Setup -// let (mut banks, payer, _, blockhash) = setup_program_test_env(true, ClockState::Normal).await; - -// // Submit register tx -// let proof_pda = Pubkey::find_program_address(&[PROOF, payer.pubkey().as_ref()], &ore::id()); -// let ix = ore::instruction::register(payer.pubkey()); -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_ok()); - -// // Find next hash -// let proof_account = banks.get_account(proof_pda.0).await.unwrap().unwrap(); -// let proof = Proof::try_from_bytes(&proof_account.data).unwrap(); -// let (_next_hash, nonce) = find_next_hash( -// proof.hash.into(), -// KeccakHash::new_from_array([u8::MAX; 32]), -// payer.pubkey(), -// ); - -// // Submit mine tx -// let mut ix = ore::instruction::mine(payer.pubkey(), BUS_ADDRESSES[0], nonce); -// ix.accounts.remove(1); -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_err()); -// } - -// #[tokio::test] -// async fn test_mine_too_early() { -// // Setup -// let (mut banks, payer, _, blockhash) = setup_program_test_env(true, ClockState::TooEarly).await; - -// // Submit register tx -// let proof_pda = Pubkey::find_program_address(&[PROOF, payer.pubkey().as_ref()], &ore::id()); -// let ix = ore::instruction::register(payer.pubkey()); -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_ok()); - -// // Find next hash -// let proof_account = banks.get_account(proof_pda.0).await.unwrap().unwrap(); -// let proof = Proof::try_from_bytes(&proof_account.data).unwrap(); -// let (_next_hash, nonce) = find_next_hash( -// proof.hash.into(), -// KeccakHash::new_from_array([u8::MAX; 32]), -// payer.pubkey(), -// ); - -// // Submit mine tx -// let ix = ore::instruction::mine(payer.pubkey(), BUS_ADDRESSES[0], nonce); -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_err()); -// } - -// #[tokio::test] -// async fn test_mine_needs_reset() { -// // Setup -// let (mut banks, payer, _, blockhash) = -// setup_program_test_env(true, ClockState::NeedsReset).await; - -// // Submit register tx -// let proof_pda = Pubkey::find_program_address(&[PROOF, payer.pubkey().as_ref()], &ore::id()); -// let ix = ore::instruction::register(payer.pubkey()); -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_ok()); - -// // Find next hash -// let proof_account = banks.get_account(proof_pda.0).await.unwrap().unwrap(); -// let proof = Proof::try_from_bytes(&proof_account.data).unwrap(); -// let (_next_hash, nonce) = find_next_hash( -// proof.hash.into(), -// KeccakHash::new_from_array([u8::MAX; 32]), -// payer.pubkey(), -// ); - -// // Submit mine tx -// let ix = ore::instruction::mine(payer.pubkey(), BUS_ADDRESSES[0], nonce); -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_err()); -// } - -// #[tokio::test] -// async fn test_claim_not_enough_accounts() { -// // Setup -// let (mut banks, payer, _, blockhash) = setup_program_test_env(true, ClockState::Normal).await; - -// // Submit register tx -// let ix = ore::instruction::register(payer.pubkey()); -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_ok()); - -// // Submit claim tx -// let beneficiary = get_associated_token_address(&payer.pubkey(), &ore::MINT_ADDRESS); -// let token_ix = create_associated_token_account( -// &payer.pubkey(), -// &payer.pubkey(), -// &ore::MINT_ADDRESS, -// &spl_token::id(), -// ); -// let mut ix = ore::instruction::claim(payer.pubkey(), beneficiary, 0); -// ix.accounts.remove(1); -// let tx = Transaction::new_signed_with_payer( -// &[token_ix, ix], -// Some(&payer.pubkey()), -// &[&payer], -// blockhash, -// ); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_err()); -// } - -// #[tokio::test] -// async fn test_mine_fail_bad_data() { -// // Setup -// const FUZZ: usize = 10; -// let (mut banks, payer, _, blockhash) = setup_program_test_env(true, ClockState::Normal).await; - -// // Submit register tx -// let proof_pda = Pubkey::find_program_address(&[PROOF, payer.pubkey().as_ref()], &ore::id()); -// let ix = ore::instruction::register(payer.pubkey()); -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_ok()); - -// // Get proof -// let proof_account = banks.get_account(proof_pda.0).await.unwrap().unwrap(); -// let proof = Proof::try_from_bytes(&proof_account.data).unwrap(); - -// // Shared variables for tests. -// let mut rng = rand::thread_rng(); -// let (_next_hash, nonce) = find_next_hash( -// proof.hash.into(), -// KeccakHash::new_from_array([u8::MAX; 32]), -// payer.pubkey(), -// ); -// let signer = payer.pubkey(); -// let proof_address = Pubkey::find_program_address(&[PROOF, signer.as_ref()], &ore::id()).0; - -// // Fuzz randomized instruction data -// for _ in 0..FUZZ { -// let length_range = Uniform::from(5..=256); -// let length = rng.sample(length_range); -// let random_bytes: Vec = (0..length).map(|_| rng.gen()).collect(); -// let ix = Instruction { -// program_id: ore::id(), -// accounts: vec![ -// AccountMeta::new(signer, true), -// AccountMeta::new(BUS_ADDRESSES[0], false), -// AccountMeta::new(proof_address, false), -// AccountMeta::new(TREASURY_ADDRESS, false), -// AccountMeta::new_readonly(sysvar::slot_hashes::id(), false), -// ], -// data: [OreInstruction::Mine.to_vec(), random_bytes].concat(), -// }; -// let tx = -// Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_err()); -// } - -// // Fuzz test random bus addresses -// for _ in 0..FUZZ { -// assert_mine_tx_err( -// &mut banks, -// &payer, -// blockhash, -// payer.pubkey(), -// Pubkey::new_unique(), -// proof_address, -// TREASURY_ADDRESS, -// sysvar::slot_hashes::id(), -// nonce, -// ) -// .await; -// } - -// // Fuzz test random proof addresses -// for _ in 0..FUZZ { -// assert_mine_tx_err( -// &mut banks, -// &payer, -// blockhash, -// payer.pubkey(), -// BUS_ADDRESSES[0], -// Pubkey::new_unique(), -// TREASURY_ADDRESS, -// sysvar::slot_hashes::id(), -// nonce, -// ) -// .await; -// } - -// // Mix up the proof and treasury addresses -// assert_mine_tx_err( -// &mut banks, -// &payer, -// blockhash, -// payer.pubkey(), -// BUS_ADDRESSES[0], -// TREASURY_ADDRESS, -// proof_address, -// sysvar::slot_hashes::id(), -// nonce, -// ) -// .await; - -// // Pass an invalid sysvar -// assert_mine_tx_err( -// &mut banks, -// &payer, -// blockhash, -// payer.pubkey(), -// BUS_ADDRESSES[0], -// proof_address, -// TREASURY_ADDRESS, -// sysvar::clock::id(), -// nonce, -// ) -// .await; -// } - -// async fn assert_mine_tx_err( -// banks: &mut BanksClient, -// payer: &Keypair, -// blockhash: Hash, -// signer: Pubkey, -// bus: Pubkey, -// proof: Pubkey, -// treasury: Pubkey, -// slot_hash: Pubkey, -// nonce: u64, -// ) { -// let ix = Instruction { -// program_id: ore::id(), -// accounts: vec![ -// AccountMeta::new(signer, true), -// AccountMeta::new(bus, false), -// AccountMeta::new(proof, false), -// AccountMeta::new(treasury, false), -// AccountMeta::new_readonly(slot_hash, false), -// ], -// data: [ -// OreInstruction::Mine.to_vec(), -// MineArgs { -// nonce: nonce.to_le_bytes(), -// } -// .to_bytes() -// .to_vec(), -// ] -// .concat(), -// }; -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_err()); -// } - -// fn find_next_hash(hash: KeccakHash, difficulty: KeccakHash, signer: Pubkey) -> (KeccakHash, u64) { -// let mut next_hash: KeccakHash; -// let mut nonce = 0u64; -// loop { -// next_hash = hashv(&[ -// nonce.to_le_bytes().as_slice(), -// hash.to_bytes().as_slice(), -// signer.to_bytes().as_slice(), -// ]); -// if next_hash.le(&difficulty) { -// break; -// } else { -// println!("Invalid hash: {} Nonce: {:?}", next_hash.to_string(), nonce); -// } -// nonce += 1; -// } -// (next_hash, nonce) -// } - -// enum ClockState { -// Normal, -// TooEarly, -// NeedsReset, -// } - -// async fn setup_program_test_env( -// funded_busses: bool, -// clock_state: ClockState, -// ) -> (BanksClient, Keypair, Keypair, solana_program::hash::Hash) { -// let mut program_test = ProgramTest::new("ore", ore::ID, processor!(ore::process_instruction)); -// program_test.prefer_bpf(true); - -// // Busses -// for i in 0..BUS_COUNT { -// program_test.add_account_with_base64_data( -// BUS_ADDRESSES[i], -// 1057920, -// ore::id(), -// bs64::encode( -// &[ -// &(Bus::discriminator() as u64).to_le_bytes(), -// Bus { -// id: i as u64, -// rewards: if funded_busses { 250_000_000 } else { 0 }, -// } -// .to_bytes(), -// ] -// .concat(), -// ) -// .as_str(), -// ); -// } - -// // Treasury -// let admin_address = Pubkey::from_str("AeNqnoLwFanMd3ig9WoMxQZVwQHtCtqKMMBsT1sTrvz6").unwrap(); -// let treasury_pda = Pubkey::find_program_address(&[TREASURY], &ore::id()); -// program_test.add_account_with_base64_data( -// treasury_pda.0, -// 1614720, -// ore::id(), -// bs64::encode( -// &[ -// &(Treasury::discriminator() as u64).to_le_bytes(), -// Treasury { -// bump: treasury_pda.1 as u64, -// admin: admin_address, -// difficulty: KeccakHash::new_from_array([u8::MAX; 32]).into(), -// last_reset_at: START_AT, -// reward_rate: INITIAL_REWARD_RATE, -// total_claimed_rewards: 0, -// } -// .to_bytes(), -// ] -// .concat(), -// ) -// .as_str(), -// ); - -// // Mint -// let mut mint_src: [u8; Mint::LEN] = [0; Mint::LEN]; -// Mint { -// mint_authority: COption::Some(TREASURY_ADDRESS), -// supply: 2_000_000_000, -// decimals: TOKEN_DECIMALS, -// is_initialized: true, -// freeze_authority: COption::None, -// } -// .pack_into_slice(&mut mint_src); -// program_test.add_account_with_base64_data( -// MINT_ADDRESS, -// 1461600, -// spl_token::id(), -// bs64::encode(&mint_src).as_str(), -// ); - -// // Treasury tokens -// let tokens_address = spl_associated_token_account::get_associated_token_address( -// &TREASURY_ADDRESS, -// &MINT_ADDRESS, -// ); -// let mut tokens_src: [u8; spl_token::state::Account::LEN] = [0; spl_token::state::Account::LEN]; -// spl_token::state::Account { -// mint: MINT_ADDRESS, -// owner: TREASURY_ADDRESS, -// amount: 2_000_000_000, -// delegate: COption::None, -// state: AccountState::Initialized, -// is_native: COption::None, -// delegated_amount: 0, -// close_authority: COption::None, -// } -// .pack_into_slice(&mut tokens_src); -// program_test.add_account_with_base64_data( -// tokens_address, -// 2039280, -// spl_token::id(), -// bs64::encode(&tokens_src).as_str(), -// ); - -// // Set sysvar -// let ts = match clock_state { -// ClockState::Normal => START_AT + 1, -// ClockState::TooEarly => START_AT - 1, -// ClockState::NeedsReset => START_AT + EPOCH_DURATION, -// }; -// program_test.add_sysvar_account( -// sysvar::clock::id(), -// &Clock { -// slot: 0, -// epoch_start_timestamp: 0, -// epoch: 0, -// leader_schedule_epoch: DEFAULT_SLOTS_PER_EPOCH, -// unix_timestamp: ts, -// }, -// ); - -// // Setup alt payer -// let payer_alt = Keypair::new(); -// program_test.add_account( -// payer_alt.pubkey(), -// Account { -// lamports: LAMPORTS_PER_SOL, -// data: vec![], -// owner: system_program::id(), -// executable: false, -// rent_epoch: 0, -// }, -// ); - -// let (banks, payer, blockhash) = program_test.start().await; -// (banks, payer, payer_alt, blockhash) -// } diff --git a/tests/test_register.rs b/tests/test_register.rs deleted file mode 100644 index 084b2fe..0000000 --- a/tests/test_register.rs +++ /dev/null @@ -1,188 +0,0 @@ -// use std::str::FromStr; - -// use ore::{ -// instruction::{register, OreInstruction, RegisterArgs}, -// state::{Bus, Treasury}, -// utils::Discriminator, -// BUS_ADDRESSES, BUS_COUNT, INITIAL_REWARD_RATE, MINT_ADDRESS, PROOF, TOKEN_DECIMALS, TREASURY, -// TREASURY_ADDRESS, -// }; -// use solana_program::{ -// clock::Clock, -// epoch_schedule::DEFAULT_SLOTS_PER_EPOCH, -// instruction::{AccountMeta, Instruction}, -// keccak::Hash as KeccakHash, -// program_option::COption, -// program_pack::Pack, -// pubkey::Pubkey, -// rent::Rent, -// sysvar, -// }; -// use solana_program_test::{processor, BanksClient, ProgramTest}; -// use solana_sdk::{ -// signature::{Keypair, Signer}, -// system_transaction::transfer, -// transaction::Transaction, -// }; -// use spl_token::state::{AccountState, Mint}; - -// #[tokio::test] -// async fn test_register_account_with_lamports() { -// let (mut banks, payer, blockhash) = setup_program_test_env().await; - -// // Send lamports to the proof pda -// let proof_pda = Pubkey::find_program_address(&[PROOF, payer.pubkey().as_ref()], &ore::id()); -// let lamports = Rent::default().minimum_balance(0); -// let tx = transfer(&payer, &proof_pda.0, lamports, blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_ok()); - -// // Assert register succeeds -// let ix = register(payer.pubkey()); -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_ok()); -// } - -// #[tokio::test] -// async fn test_register_not_enough_accounts() { -// let (mut banks, payer, blockhash) = setup_program_test_env().await; - -// // Assert register fails -// let mut ix = register(payer.pubkey()); -// ix.accounts.remove(1); -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_err()); -// } - -// #[tokio::test] -// async fn test_register_fail_other() { -// let (mut banks, payer, blockhash) = setup_program_test_env().await; - -// // Try register for another keypair -// let other = Keypair::new(); -// let proof_pda = Pubkey::find_program_address(&[PROOF, other.pubkey().as_ref()], &ore::id()); -// let ix = Instruction { -// program_id: ore::id(), -// accounts: vec![ -// AccountMeta::new(payer.pubkey(), true), -// AccountMeta::new(proof_pda.0, false), -// AccountMeta::new_readonly(solana_program::system_program::id(), false), -// ], -// data: [ -// OreInstruction::Register.to_vec(), -// RegisterArgs { bump: proof_pda.1 }.to_bytes().to_vec(), -// ] -// .concat(), -// }; -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_err()); -// } - -// async fn setup_program_test_env() -> (BanksClient, Keypair, solana_program::hash::Hash) { -// let mut program_test = ProgramTest::new("ore", ore::ID, processor!(ore::process_instruction)); -// program_test.prefer_bpf(true); - -// // Busses -// for i in 0..BUS_COUNT { -// program_test.add_account_with_base64_data( -// BUS_ADDRESSES[i], -// 1057920, -// ore::id(), -// bs64::encode( -// &[ -// &(Bus::discriminator() as u64).to_le_bytes(), -// Bus { -// id: i as u64, -// rewards: 250_000_000, -// } -// .to_bytes(), -// ] -// .concat(), -// ) -// .as_str(), -// ); -// } - -// // Treasury -// let admin_address = Pubkey::from_str("AeNqnoLwFanMd3ig9WoMxQZVwQHtCtqKMMBsT1sTrvz6").unwrap(); -// let treasury_pda = Pubkey::find_program_address(&[TREASURY], &ore::id()); -// program_test.add_account_with_base64_data( -// treasury_pda.0, -// 1614720, -// ore::id(), -// bs64::encode( -// &[ -// &(Treasury::discriminator() as u64).to_le_bytes(), -// Treasury { -// bump: treasury_pda.1 as u64, -// admin: admin_address, -// difficulty: KeccakHash::new_from_array([u8::MAX; 32]).into(), -// last_reset_at: 100, -// reward_rate: INITIAL_REWARD_RATE, -// total_claimed_rewards: 0, -// } -// .to_bytes(), -// ] -// .concat(), -// ) -// .as_str(), -// ); - -// // Mint -// let mut mint_src: [u8; Mint::LEN] = [0; Mint::LEN]; -// Mint { -// mint_authority: COption::Some(TREASURY_ADDRESS), -// supply: 2_000_000_000, -// decimals: TOKEN_DECIMALS, -// is_initialized: true, -// freeze_authority: COption::None, -// } -// .pack_into_slice(&mut mint_src); -// program_test.add_account_with_base64_data( -// MINT_ADDRESS, -// 1461600, -// spl_token::id(), -// bs64::encode(&mint_src).as_str(), -// ); - -// // Treasury tokens -// let tokens_address = spl_associated_token_account::get_associated_token_address( -// &TREASURY_ADDRESS, -// &MINT_ADDRESS, -// ); -// let mut tokens_src: [u8; spl_token::state::Account::LEN] = [0; spl_token::state::Account::LEN]; -// spl_token::state::Account { -// mint: MINT_ADDRESS, -// owner: TREASURY_ADDRESS, -// amount: 2_000_000_000, -// delegate: COption::None, -// state: AccountState::Initialized, -// is_native: COption::None, -// delegated_amount: 0, -// close_authority: COption::None, -// } -// .pack_into_slice(&mut tokens_src); -// program_test.add_account_with_base64_data( -// tokens_address, -// 2039280, -// spl_token::id(), -// bs64::encode(&tokens_src).as_str(), -// ); - -// // Set sysvar -// program_test.add_sysvar_account( -// sysvar::clock::id(), -// &Clock { -// slot: 0, -// epoch_start_timestamp: 0, -// epoch: 0, -// leader_schedule_epoch: DEFAULT_SLOTS_PER_EPOCH, -// unix_timestamp: 0, -// }, -// ); - -// program_test.start().await -// } diff --git a/tests/test_reset.rs b/tests/test_reset.rs deleted file mode 100644 index 3f0a774..0000000 --- a/tests/test_reset.rs +++ /dev/null @@ -1,440 +0,0 @@ -// use std::str::FromStr; - -// use ore::{ -// instruction::OreInstruction, -// state::{Bus, Treasury}, -// utils::{AccountDeserialize, Discriminator}, -// BUS, BUS_ADDRESSES, BUS_COUNT, BUS_EPOCH_REWARDS, INITIAL_DIFFICULTY, INITIAL_REWARD_RATE, -// MAX_EPOCH_REWARDS, MINT_ADDRESS, START_AT, TOKEN_DECIMALS, TREASURY, TREASURY_ADDRESS, -// }; -// use rand::seq::SliceRandom; -// use solana_program::{ -// clock::Clock, -// epoch_schedule::DEFAULT_SLOTS_PER_EPOCH, -// hash::Hash, -// instruction::{AccountMeta, Instruction}, -// native_token::LAMPORTS_PER_SOL, -// program_option::COption, -// program_pack::Pack, -// pubkey::Pubkey, -// system_program, sysvar, -// }; -// use solana_program_test::{processor, BanksClient, ProgramTest}; -// use solana_sdk::{ -// account::Account, -// signature::{Keypair, Signer}, -// transaction::Transaction, -// }; -// use spl_token::state::{AccountState, Mint}; - -// #[tokio::test] -// async fn test_reset() { -// // Setup -// let (mut banks, payer, _, blockhash) = setup_program_test_env(ClockState::Normal).await; - -// // Pdas -// let bus_pdas = vec![ -// Pubkey::find_program_address(&[BUS, &[0]], &ore::id()), -// Pubkey::find_program_address(&[BUS, &[1]], &ore::id()), -// Pubkey::find_program_address(&[BUS, &[2]], &ore::id()), -// Pubkey::find_program_address(&[BUS, &[3]], &ore::id()), -// Pubkey::find_program_address(&[BUS, &[4]], &ore::id()), -// Pubkey::find_program_address(&[BUS, &[5]], &ore::id()), -// Pubkey::find_program_address(&[BUS, &[6]], &ore::id()), -// Pubkey::find_program_address(&[BUS, &[7]], &ore::id()), -// ]; -// // let mint_pda = Pubkey::find_program_address(&[MINT], &ore::id()); -// let treasury_tokens_address = spl_associated_token_account::get_associated_token_address( -// &TREASURY_ADDRESS, -// &MINT_ADDRESS, -// ); - -// // Submit tx -// let ix = ore::instruction::reset(payer.pubkey()); -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_ok()); - -// // Test bus state -// for i in 0..BUS_COUNT { -// let bus_account = banks.get_account(bus_pdas[i].0).await.unwrap().unwrap(); -// assert_eq!(bus_account.owner, ore::id()); -// let bus = Bus::try_from_bytes(&bus_account.data).unwrap(); -// assert_eq!(bus.id as u8, i as u8); -// assert_eq!(bus.rewards, BUS_EPOCH_REWARDS); -// } - -// // Test treasury state -// let treasury_account = banks.get_account(TREASURY_ADDRESS).await.unwrap().unwrap(); -// assert_eq!(treasury_account.owner, ore::id()); -// let treasury = Treasury::try_from_bytes(&treasury_account.data).unwrap(); -// assert_eq!( -// treasury.admin, -// Pubkey::from_str("AeNqnoLwFanMd3ig9WoMxQZVwQHtCtqKMMBsT1sTrvz6").unwrap() -// ); -// assert_eq!(treasury.difficulty, INITIAL_DIFFICULTY.into()); -// assert_eq!(treasury.last_reset_at, START_AT + 1); -// assert_eq!(treasury.reward_rate, INITIAL_REWARD_RATE.saturating_div(2)); -// assert_eq!(treasury.total_claimed_rewards as u8, 0); - -// // Test mint state -// let mint_account = banks.get_account(MINT_ADDRESS).await.unwrap().unwrap(); -// assert_eq!(mint_account.owner, spl_token::id()); -// let mint = Mint::unpack(&mint_account.data).unwrap(); -// assert_eq!(mint.mint_authority, COption::Some(TREASURY_ADDRESS)); -// assert_eq!(mint.supply, MAX_EPOCH_REWARDS); -// assert_eq!(mint.decimals, ore::TOKEN_DECIMALS); -// assert_eq!(mint.is_initialized, true); -// assert_eq!(mint.freeze_authority, COption::None); - -// // Test treasury token state -// let treasury_tokens_account = banks -// .get_account(treasury_tokens_address) -// .await -// .unwrap() -// .unwrap(); -// assert_eq!(treasury_tokens_account.owner, spl_token::id()); -// let treasury_tokens = spl_token::state::Account::unpack(&treasury_tokens_account.data).unwrap(); -// assert_eq!(treasury_tokens.mint, MINT_ADDRESS); -// assert_eq!(treasury_tokens.owner, TREASURY_ADDRESS); -// assert_eq!(treasury_tokens.amount, MAX_EPOCH_REWARDS); -// assert_eq!(treasury_tokens.delegate, COption::None); -// assert_eq!(treasury_tokens.state, AccountState::Initialized); -// assert_eq!(treasury_tokens.is_native, COption::None); -// assert_eq!(treasury_tokens.delegated_amount, 0); -// assert_eq!(treasury_tokens.close_authority, COption::None); -// } - -// #[tokio::test] -// async fn test_reset_bad_key() { -// // Setup -// let (mut banks, payer, _, blockhash) = setup_program_test_env(ClockState::Normal).await; - -// // Bad addresses -// let bad_pda = Pubkey::find_program_address(&[b"t"], &ore::id()); -// for i in 1..13 { -// let mut ix = ore::instruction::reset(payer.pubkey()); -// ix.accounts[i].pubkey = bad_pda.0; -// let tx = -// Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_err()); -// } -// } - -// #[tokio::test] -// async fn test_reset_busses_out_of_order_fail() { -// // Setup -// let (mut banks, payer, _, blockhash) = setup_program_test_env(ClockState::Normal).await; - -// // Pdas -// let signer = payer.pubkey(); -// let bus_pdas = vec![ -// Pubkey::find_program_address(&[BUS, &[5]], &ore::id()), -// Pubkey::find_program_address(&[BUS, &[0]], &ore::id()), -// Pubkey::find_program_address(&[BUS, &[6]], &ore::id()), -// Pubkey::find_program_address(&[BUS, &[2]], &ore::id()), -// Pubkey::find_program_address(&[BUS, &[3]], &ore::id()), -// Pubkey::find_program_address(&[BUS, &[7]], &ore::id()), -// Pubkey::find_program_address(&[BUS, &[1]], &ore::id()), -// Pubkey::find_program_address(&[BUS, &[4]], &ore::id()), -// ]; -// let treasury_tokens = spl_associated_token_account::get_associated_token_address( -// &TREASURY_ADDRESS, -// &MINT_ADDRESS, -// ); - -// // Submit tx -// let ix = Instruction { -// program_id: ore::id(), -// accounts: vec![ -// AccountMeta::new(signer, true), -// AccountMeta::new(bus_pdas[0].0, false), -// AccountMeta::new(bus_pdas[1].0, false), -// AccountMeta::new(bus_pdas[2].0, false), -// AccountMeta::new(bus_pdas[3].0, false), -// AccountMeta::new(bus_pdas[4].0, false), -// AccountMeta::new(bus_pdas[5].0, false), -// AccountMeta::new(bus_pdas[6].0, false), -// AccountMeta::new(bus_pdas[7].0, false), -// AccountMeta::new(MINT_ADDRESS, false), -// AccountMeta::new(TREASURY_ADDRESS, false), -// AccountMeta::new(treasury_tokens, false), -// AccountMeta::new_readonly(spl_token::id(), false), -// ], -// data: OreInstruction::Reset.to_vec(), -// }; -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_err()); -// } - -// #[tokio::test] -// async fn test_reset_race() { -// // Setup -// let (mut banks, payer, payer_alt, blockhash) = setup_program_test_env(ClockState::Normal).await; - -// // Reset one passes -// let ix = ore::instruction::reset(payer.pubkey()); -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_ok()); - -// // Reset two fails -// let ix = ore::instruction::reset(payer_alt.pubkey()); -// let tx = Transaction::new_signed_with_payer( -// &[ix], -// Some(&payer_alt.pubkey()), -// &[&payer_alt], -// blockhash, -// ); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_err()); -// } - -// #[tokio::test] -// async fn test_reset_too_early() { -// // Setup -// let (mut banks, payer, _, blockhash) = setup_program_test_env(ClockState::TooEarly).await; - -// // Reset one passes -// let ix = ore::instruction::reset(payer.pubkey()); -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_err()); -// } - -// #[tokio::test] -// async fn test_reset_not_enough_keys() { -// // Setup -// let (mut banks, payer, _, blockhash) = setup_program_test_env(ClockState::Normal).await; - -// // Reset with missing account -// let mut ix = ore::instruction::reset(payer.pubkey()); -// ix.accounts.remove(1); -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_err()); -// } - -// #[tokio::test] -// async fn test_reset_busses_duplicate_fail() { -// // Setup -// let (mut banks, payer, _, blockhash) = setup_program_test_env(ClockState::Normal).await; - -// // Pdas -// let signer = payer.pubkey(); -// let bus_pda = Pubkey::find_program_address(&[BUS, &[0]], &ore::id()); -// let treasury_tokens = spl_associated_token_account::get_associated_token_address( -// &TREASURY_ADDRESS, -// &MINT_ADDRESS, -// ); - -// // Submit tx -// let ix = Instruction { -// program_id: ore::id(), -// accounts: vec![ -// AccountMeta::new(signer, true), -// AccountMeta::new(bus_pda.0, false), -// AccountMeta::new(bus_pda.0, false), -// AccountMeta::new(bus_pda.0, false), -// AccountMeta::new(bus_pda.0, false), -// AccountMeta::new(bus_pda.0, false), -// AccountMeta::new(bus_pda.0, false), -// AccountMeta::new(bus_pda.0, false), -// AccountMeta::new(bus_pda.0, false), -// AccountMeta::new(MINT_ADDRESS, false), -// AccountMeta::new(TREASURY_ADDRESS, false), -// AccountMeta::new(treasury_tokens, false), -// AccountMeta::new_readonly(spl_token::id(), false), -// ], -// data: OreInstruction::Reset.to_vec(), -// }; -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_err()); -// } - -// #[tokio::test] -// async fn test_reset_shuffle_error() { -// // Setup -// const FUZZ: u64 = 100; -// let (mut banks, payer, _, blockhash) = setup_program_test_env(ClockState::Normal).await; - -// // Pdas -// let signer = payer.pubkey(); -// let bus_pdas = vec![ -// Pubkey::find_program_address(&[BUS, &[5]], &ore::id()), -// Pubkey::find_program_address(&[BUS, &[0]], &ore::id()), -// Pubkey::find_program_address(&[BUS, &[6]], &ore::id()), -// Pubkey::find_program_address(&[BUS, &[2]], &ore::id()), -// Pubkey::find_program_address(&[BUS, &[3]], &ore::id()), -// Pubkey::find_program_address(&[BUS, &[7]], &ore::id()), -// Pubkey::find_program_address(&[BUS, &[1]], &ore::id()), -// Pubkey::find_program_address(&[BUS, &[4]], &ore::id()), -// ]; -// let treasury_tokens = spl_associated_token_account::get_associated_token_address( -// &TREASURY_ADDRESS, -// &MINT_ADDRESS, -// ); - -// // Fuzz test shuffled accounts. -// // Note some shuffles may still be valid if signer and non-bus accounts are all in correct positions. -// let mut rng = rand::thread_rng(); -// for _ in 0..FUZZ { -// let mut accounts = vec![ -// AccountMeta::new(signer, true), -// AccountMeta::new(bus_pdas[0].0, false), -// AccountMeta::new(bus_pdas[1].0, false), -// AccountMeta::new(bus_pdas[2].0, false), -// AccountMeta::new(bus_pdas[3].0, false), -// AccountMeta::new(bus_pdas[4].0, false), -// AccountMeta::new(bus_pdas[5].0, false), -// AccountMeta::new(bus_pdas[6].0, false), -// AccountMeta::new(bus_pdas[7].0, false), -// AccountMeta::new(MINT_ADDRESS, false), -// AccountMeta::new(TREASURY_ADDRESS, false), -// AccountMeta::new(treasury_tokens, false), -// AccountMeta::new_readonly(spl_token::id(), false), -// ]; -// accounts.shuffle(&mut rng); -// let ix = Instruction { -// program_id: ore::id(), -// accounts, -// data: OreInstruction::Reset.to_vec(), -// }; -// let tx = -// Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_err()); -// } -// } - -// enum ClockState { -// Normal, -// TooEarly, -// } - -// async fn setup_program_test_env(clock_state: ClockState) -> (BanksClient, Keypair, Keypair, Hash) { -// let mut program_test = ProgramTest::new("ore", ore::ID, processor!(ore::process_instruction)); -// program_test.prefer_bpf(true); - -// // Busses -// for i in 0..BUS_COUNT { -// program_test.add_account_with_base64_data( -// BUS_ADDRESSES[i], -// 1057920, -// ore::id(), -// bs64::encode( -// &[ -// &(Bus::discriminator() as u64).to_le_bytes(), -// Bus { -// id: i as u64, -// rewards: 0, -// } -// .to_bytes(), -// ] -// .concat(), -// ) -// .as_str(), -// ); -// } - -// // Treasury -// let admin_address = Pubkey::from_str("AeNqnoLwFanMd3ig9WoMxQZVwQHtCtqKMMBsT1sTrvz6").unwrap(); -// let treasury_pda = Pubkey::find_program_address(&[TREASURY], &ore::id()); -// program_test.add_account_with_base64_data( -// treasury_pda.0, -// 1614720, -// ore::id(), -// bs64::encode( -// &[ -// &(Treasury::discriminator() as u64).to_le_bytes(), -// Treasury { -// bump: treasury_pda.1 as u64, -// admin: admin_address, -// difficulty: INITIAL_DIFFICULTY.into(), -// last_reset_at: 0, -// reward_rate: INITIAL_REWARD_RATE, -// total_claimed_rewards: 0, -// } -// .to_bytes(), -// ] -// .concat(), -// ) -// .as_str(), -// ); - -// // Mint -// let mut mint_src: [u8; Mint::LEN] = [0; Mint::LEN]; -// Mint { -// mint_authority: COption::Some(TREASURY_ADDRESS), -// supply: 0, -// decimals: TOKEN_DECIMALS, -// is_initialized: true, -// freeze_authority: COption::None, -// } -// .pack_into_slice(&mut mint_src); -// program_test.add_account_with_base64_data( -// MINT_ADDRESS, -// 1461600, -// spl_token::id(), -// bs64::encode(&mint_src).as_str(), -// ); - -// // Treasury tokens -// let tokens_address = spl_associated_token_account::get_associated_token_address( -// &TREASURY_ADDRESS, -// &MINT_ADDRESS, -// ); -// let mut tokens_src: [u8; spl_token::state::Account::LEN] = [0; spl_token::state::Account::LEN]; -// spl_token::state::Account { -// mint: MINT_ADDRESS, -// owner: TREASURY_ADDRESS, -// amount: 0, -// delegate: COption::None, -// state: AccountState::Initialized, -// is_native: COption::None, -// delegated_amount: 0, -// close_authority: COption::None, -// } -// .pack_into_slice(&mut tokens_src); -// program_test.add_account_with_base64_data( -// tokens_address, -// 2039280, -// spl_token::id(), -// bs64::encode(&tokens_src).as_str(), -// ); - -// // Set sysvar -// let ts = match clock_state { -// ClockState::Normal => START_AT + 1, -// ClockState::TooEarly => START_AT - 1, -// }; -// program_test.add_sysvar_account( -// sysvar::clock::id(), -// &Clock { -// slot: 0, -// epoch_start_timestamp: 0, -// epoch: 0, -// leader_schedule_epoch: DEFAULT_SLOTS_PER_EPOCH, -// unix_timestamp: ts, -// }, -// ); - -// // Setup alt payer -// let payer_alt = Keypair::new(); -// program_test.add_account( -// payer_alt.pubkey(), -// Account { -// lamports: LAMPORTS_PER_SOL, -// data: vec![], -// owner: system_program::id(), -// executable: false, -// rent_epoch: 0, -// }, -// ); - -// let (banks, payer, blockhash) = program_test.start().await; -// (banks, payer, payer_alt, blockhash) -// } diff --git a/tests/test_update_admin.rs b/tests/test_update_admin.rs deleted file mode 100644 index cd00ccd..0000000 --- a/tests/test_update_admin.rs +++ /dev/null @@ -1,128 +0,0 @@ -// use ore::{state::Treasury, utils::AccountDeserialize, TREASURY_ADDRESS}; -// use solana_program::{ -// hash::Hash, native_token::LAMPORTS_PER_SOL, pubkey::Pubkey, rent::Rent, system_program, -// }; -// use solana_program_test::{processor, read_file, BanksClient, ProgramTest}; -// use solana_sdk::{ -// account::Account, -// signature::{Keypair, Signer}, -// transaction::Transaction, -// }; - -// #[tokio::test] -// async fn test_update_admin() { -// // Setup -// let (mut banks, payer, _, blockhash) = setup_program_test_env().await; - -// // Submit tx -// let ix = ore::instruction::initialize(payer.pubkey()); -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_ok()); - -// // Get treasury account -// let treasury_account = banks.get_account(TREASURY_ADDRESS).await.unwrap().unwrap(); -// let treasury = Treasury::try_from_bytes(&treasury_account.data).unwrap(); - -// // Submit update admin ix -// let new_admin = Pubkey::new_unique(); -// let ix = ore::instruction::update_admin(payer.pubkey(), new_admin); -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_ok()); - -// // Assert treasury state -// let treasury_account = banks.get_account(TREASURY_ADDRESS).await.unwrap().unwrap(); -// let treasury_ = Treasury::try_from_bytes(&treasury_account.data).unwrap(); -// assert_eq!(treasury_.bump, treasury.bump); -// assert_eq!(treasury_.admin, new_admin); -// assert_eq!(treasury_.difficulty, treasury.difficulty); -// assert_eq!(treasury_.last_reset_at, treasury.last_reset_at); -// assert_eq!(treasury_.reward_rate, treasury.reward_rate); -// assert_eq!( -// treasury_.total_claimed_rewards, -// treasury.total_claimed_rewards -// ); - -// // Submit another update admin ix -// let ix = ore::instruction::update_admin(payer.pubkey(), payer.pubkey()); -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_err()); -// } - -// #[tokio::test] -// async fn test_update_admin_bad_signer() { -// // Setup -// let (mut banks, payer, alt_payer, blockhash) = setup_program_test_env().await; - -// // Submit tx -// let ix = ore::instruction::initialize(payer.pubkey()); -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_ok()); - -// // Submit ix -// let ix = ore::instruction::update_admin(alt_payer.pubkey(), Pubkey::new_unique()); -// let tx = Transaction::new_signed_with_payer( -// &[ix], -// Some(&alt_payer.pubkey()), -// &[&alt_payer], -// blockhash, -// ); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_err()); -// } - -// #[tokio::test] -// async fn test_update_admin_not_enough_accounts() { -// // Setup -// let (mut banks, payer, _, blockhash) = setup_program_test_env().await; - -// // Submit tx -// let ix = ore::instruction::initialize(payer.pubkey()); -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_ok()); - -// // Submit ix without enough accounts -// let mut ix = ore::instruction::update_admin(payer.pubkey(), Pubkey::new_unique()); -// ix.accounts.remove(1); -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_err()); -// } - -// async fn setup_program_test_env() -> (BanksClient, Keypair, Keypair, Hash) { -// let mut program_test = ProgramTest::new("ore", ore::ID, processor!(ore::process_instruction)); -// program_test.prefer_bpf(true); - -// // Setup metadata program -// let data = read_file(&"tests/buffers/metadata_program.bpf"); -// program_test.add_account( -// mpl_token_metadata::ID, -// Account { -// lamports: Rent::default().minimum_balance(data.len()).max(1), -// data, -// owner: solana_sdk::bpf_loader::id(), -// executable: true, -// rent_epoch: 0, -// }, -// ); - -// // Setup alt payer -// let payer_alt = Keypair::new(); -// program_test.add_account( -// payer_alt.pubkey(), -// Account { -// lamports: LAMPORTS_PER_SOL, -// data: vec![], -// owner: system_program::id(), -// executable: false, -// rent_epoch: 0, -// }, -// ); - -// let (banks, payer, blockhash) = program_test.start().await; -// (banks, payer, payer_alt, blockhash) -// } diff --git a/tests/test_update_difficulty.rs b/tests/test_update_difficulty.rs deleted file mode 100644 index 4666a8a..0000000 --- a/tests/test_update_difficulty.rs +++ /dev/null @@ -1,125 +0,0 @@ -// use ore::{state::Treasury, utils::AccountDeserialize, TREASURY_ADDRESS}; -// use solana_program::{ -// hash::Hash, keccak::Hash as KeccakHash, native_token::LAMPORTS_PER_SOL, rent::Rent, -// system_program, -// }; -// use solana_program_test::{processor, read_file, BanksClient, ProgramTest}; -// use solana_sdk::{ -// account::Account, -// signature::{Keypair, Signer}, -// transaction::Transaction, -// }; - -// #[tokio::test] -// async fn test_update_difficulty() { -// // Setup -// let (mut banks, payer, _, blockhash) = setup_program_test_env().await; - -// // Submit tx -// let ix = ore::instruction::initialize(payer.pubkey()); -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_ok()); - -// // Get treasury account -// let treasury_account = banks.get_account(TREASURY_ADDRESS).await.unwrap().unwrap(); -// let treasury = Treasury::try_from_bytes(&treasury_account.data).unwrap(); - -// // Submit update difficulty ix -// let new_difficulty = KeccakHash::new_unique(); -// let ix = ore::instruction::update_difficulty(payer.pubkey(), new_difficulty.into()); -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_ok()); - -// // Assert treasury state -// let treasury_account = banks.get_account(TREASURY_ADDRESS).await.unwrap().unwrap(); -// let treasury_ = Treasury::try_from_bytes(&treasury_account.data).unwrap(); -// assert_eq!(treasury_.bump, treasury.bump); -// assert_eq!(treasury_.admin, treasury.admin); -// assert_eq!(treasury_.difficulty, new_difficulty.into()); -// assert_eq!(treasury_.last_reset_at, treasury.last_reset_at); -// assert_eq!(treasury_.reward_rate, treasury.reward_rate); -// assert_eq!( -// treasury_.total_claimed_rewards, -// treasury.total_claimed_rewards -// ); -// } - -// #[tokio::test] -// async fn test_update_difficulty_bad_signer() { -// // Setup -// let (mut banks, payer, alt_payer, blockhash) = setup_program_test_env().await; - -// // Submit tx -// let ix = ore::instruction::initialize(payer.pubkey()); -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_ok()); - -// // Submit update difficulty ix -// let new_difficulty = KeccakHash::new_unique(); -// let ix = ore::instruction::update_difficulty(alt_payer.pubkey(), new_difficulty.into()); -// let tx = Transaction::new_signed_with_payer( -// &[ix], -// Some(&alt_payer.pubkey()), -// &[&alt_payer], -// blockhash, -// ); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_err()); -// } - -// #[tokio::test] -// async fn test_update_difficulty_not_enough_accounts() { -// // Setup -// let (mut banks, payer, _, blockhash) = setup_program_test_env().await; - -// // Submit tx -// let ix = ore::instruction::initialize(payer.pubkey()); -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_ok()); - -// // Submit ix without enough accounts -// let new_difficulty = KeccakHash::new_unique(); -// let mut ix = ore::instruction::update_difficulty(payer.pubkey(), new_difficulty.into()); -// ix.accounts.remove(1); -// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); -// let res = banks.process_transaction(tx).await; -// assert!(res.is_err()); -// } - -// async fn setup_program_test_env() -> (BanksClient, Keypair, Keypair, Hash) { -// let mut program_test = ProgramTest::new("ore", ore::ID, processor!(ore::process_instruction)); -// program_test.prefer_bpf(true); - -// // Setup metadata program -// let data = read_file(&"tests/buffers/metadata_program.bpf"); -// program_test.add_account( -// mpl_token_metadata::ID, -// Account { -// lamports: Rent::default().minimum_balance(data.len()).max(1), -// data, -// owner: solana_sdk::bpf_loader::id(), -// executable: true, -// rent_epoch: 0, -// }, -// ); - -// // Setup alt payer -// let payer_alt = Keypair::new(); -// program_test.add_account( -// payer_alt.pubkey(), -// Account { -// lamports: LAMPORTS_PER_SOL, -// data: vec![], -// owner: system_program::id(), -// executable: false, -// rent_epoch: 0, -// }, -// ); - -// let (banks, payer, blockhash) = program_test.start().await; -// (banks, payer, payer_alt, blockhash) -// }