diff --git a/programs/tokenlock/src/test.rs b/programs/tokenlock/src/test.rs index 2d3e91d..46b9948 100644 --- a/programs/tokenlock/src/test.rs +++ b/programs/tokenlock/src/test.rs @@ -1,1194 +1,1194 @@ -use super::*; -use access_control::{AccessControl, Roles, WalletRole}; -use anchor_lang::Discriminator; -use common::PUBKEY_SIZE; -use core::result::Result; -use solana_sdk::{ - account::{create_account_for_test, Account as SolanaAccount}, - account_info::IntoAccountInfo, - program_memory::sol_memcpy, - program_pack::Pack, - system_program, - sysvar::SysvarId, -}; -use spl_token_2022::state::{Account as TokenAccount, Mint}; -use std::str::FromStr; -const TOKENLOCK_SIZE: usize = 10 * 1024 * 1024; - -struct TestFixture { - program_id: Pubkey, - tokenlock_account: (Pubkey, SolanaAccount), - timelock_account: (Pubkey, SolanaAccount), - authority_wallet_role: (Pubkey, SolanaAccount), - access_control: (Pubkey, SolanaAccount), - authority: (Pubkey, SolanaAccount), - escrow_account: (Pubkey, SolanaAccount), - mint_address: (Pubkey, SolanaAccount), - target_account: (Pubkey, SolanaAccount), - from: (Pubkey, SolanaAccount), - to: (Pubkey, SolanaAccount), - pda_account: (Pubkey, SolanaAccount), - target: (Pubkey, SolanaAccount), - reclaimer: (Pubkey, SolanaAccount), - target_assoc: (Pubkey, SolanaAccount), - token_program: (Pubkey, SolanaAccount), - system_program: (Pubkey, SolanaAccount), - rent: (Pubkey, SolanaAccount), -} - -impl Default for TestFixture { - fn default() -> Self { - let program_id = Pubkey::from_str("7CN3iHcRimZRa97M38cyMQAF68ecQYDqHfCUgBeSARG2").unwrap(); - let access_control_program_id = access_control::ID; - let key = Pubkey::from_str("11111111111111111111111111111111").unwrap(); - - let tokenlock_address = Pubkey::new_unique(); - let mint_address = key; - let mut mint_acc = SolanaAccount::new( - Self::min_balance(Mint::LEN), - Mint::LEN, - &anchor_spl::token_2022::ID, - ); - Self::pack_mint(&mut mint_acc.data, 0, None).expect("Mint pack Error"); - - let (pda, _) = Pubkey::find_program_address( - &[ - TOKENLOCK_PDA_SEED, - mint_address.as_ref(), - tokenlock_address.as_ref(), - ], - &program_id, - ); - - let mut escrow_account_acc = SolanaAccount::new( - Self::min_balance(TokenAccount::LEN), - TokenAccount::LEN, - &anchor_spl::token_2022::ID, - ); - TokenAccount::pack( - TokenAccount { - state: spl_token_2022::state::AccountState::Initialized, - amount: 0, - owner: pda, - ..Default::default() - }, - &mut escrow_account_acc.data, - ) - .unwrap(); - - let mut from = SolanaAccount::new( - Self::min_balance(TokenAccount::LEN), - TokenAccount::LEN, - &anchor_spl::token_2022::ID, - ); - Self::pack_token_account(&mut from.data, 0).expect("From address pack Error"); - - let mut to = SolanaAccount::new( - Self::min_balance(TokenAccount::LEN), - TokenAccount::LEN, - &anchor_spl::token_2022::ID, - ); - Self::pack_token_account(&mut to.data, 0).expect("To address pack Error"); - - let mut reclaimer = SolanaAccount::new( - Self::min_balance(TokenAccount::LEN), - TokenAccount::LEN, - &anchor_spl::token_2022::ID, - ); - Self::pack_token_account(&mut reclaimer.data, 0) - .expect("Reclaimer token wallet pack Error"); - - let mut target_assoc = SolanaAccount::new( - Self::min_balance(TokenAccount::LEN), - TokenAccount::LEN, - &anchor_spl::token_2022::ID, - ); - Self::pack_token_account(&mut target_assoc.data, 0) - .expect("Target token wallet pack Error"); - - let mut token_program_account = SolanaAccount::default(); - token_program_account.executable = true; - - let mut system_program_account = SolanaAccount::default(); - system_program_account.executable = true; - - let access_control_address = Pubkey::new_unique(); - - Self { - program_id, - - tokenlock_account: Self::create_tokenlock_account( - &tokenlock_address, - &program_id, - &access_control_address, - ), - timelock_account: ( - Pubkey::new_unique(), - SolanaAccount::new(Self::min_balance(10240), 10240, &program_id), - ), - access_control: Self::create_access_control_account( - &access_control_address, - &access_control_program_id, - ), - authority_wallet_role: Self::create_wallet_role_account( - &Pubkey::new_unique(), - &access_control_program_id, - ), - authority: (Pubkey::new_unique(), SolanaAccount::default()), - escrow_account: (key.clone(), escrow_account_acc), - mint_address: (mint_address, mint_acc), - target_account: (Pubkey::new_unique(), SolanaAccount::default()), - from: (Pubkey::new_unique(), from), - to: (Pubkey::new_unique(), to), - pda_account: (Pubkey::new_unique(), SolanaAccount::default()), - target: (Pubkey::new_unique(), SolanaAccount::default()), - reclaimer: (Pubkey::new_unique(), reclaimer), - target_assoc: (Pubkey::new_unique(), target_assoc), - - token_program: (spl_token_2022::id(), token_program_account), - system_program: (system_program::id(), system_program_account), - rent: (Rent::id(), create_account_for_test(&Rent::default())), - } - } -} - -impl<'a> TestFixture { - fn initialize_tokenlock( - tokenlock_account_info: &'a AccountInfo<'a>, - escrow_account_info: &'a AccountInfo<'a>, - mint_info: &'a AccountInfo<'a>, - authority_wallet_role_info: &'a AccountInfo<'a>, - access_control_info: &'a AccountInfo<'a>, - authority_info: &'a mut AccountInfo<'a>, - token_program_info: &'a AccountInfo<'a>, - ) -> Result, ProgramError> { - authority_info.is_signer = true; - let escrow_account = Box::new(InterfaceAccount::try_from(escrow_account_info)?); - let mint_address = Box::new(InterfaceAccount::try_from(mint_info)?); - - Ok(InitializeTokenLock { - tokenlock_account: Account::try_from_unchecked(tokenlock_account_info)?, - escrow_account, - mint_address, - authority_wallet_role: Account::try_from_unchecked(authority_wallet_role_info)?, - access_control: Account::try_from_unchecked(access_control_info)?, - authority: Signer::try_from(authority_info)?, - token_program: Program::try_from(token_program_info)?, - }) - } - - fn initialize_timelock( - tokenlock_account_info: AccountInfo<'a>, - timelock_account_info: &'a AccountInfo<'a>, - authority_info: &'a mut AccountInfo<'a>, - authority_wallet_role_info: &'a AccountInfo<'a>, - access_control_info: &'a AccountInfo<'a>, - target_account_info: AccountInfo<'a>, - system_program_info: &'a AccountInfo<'a>, - rent_info: &'a AccountInfo<'a>, - ) -> Result, ProgramError> { - authority_info.is_signer = true; - let mut authority_wallet_role: Account<'a, WalletRole> = - Account::try_from_unchecked(authority_wallet_role_info).unwrap(); - authority_wallet_role.role = Roles::ReserveAdmin as u8; - - Ok(InitializeTimeLock { - tokenlock_account: tokenlock_account_info, - timelock_account: Account::try_from_unchecked(timelock_account_info)?, - authority: Signer::try_from(authority_info).unwrap(), - access_control: Account::try_from_unchecked(access_control_info).unwrap(), - authority_wallet_role, - target_account: target_account_info, - system_program: Program::try_from(system_program_info)?, - rent: Sysvar::from_account_info(rent_info)?, - }) - } - - fn create_release_schedule( - tokenlock_account_info: AccountInfo<'a>, - authority_info: &'a mut AccountInfo<'a>, - authority_wallet_role_info: &'a AccountInfo<'a>, - access_control_info: &'a AccountInfo<'a>, - ) -> Result, ProgramError> { - authority_info.is_signer = true; - let mut authority_wallet_role: Account<'a, WalletRole> = - Account::try_from_unchecked(authority_wallet_role_info).unwrap(); - authority_wallet_role.role = Roles::ReserveAdmin as u8; - - Ok(ManagementTokenlock { - tokenlock_account: tokenlock_account_info, - authority: Signer::try_from(authority_info)?, - authority_wallet_role, - access_control: Account::try_from_unchecked(access_control_info)?, - }) - } - - fn fund_release_schedule( - escrow_account_info: &'a AccountInfo<'a>, - tokenlock_account_info: &'a AccountInfo<'a>, - timelock_account_info: &'a AccountInfo<'a>, - authority_info: &'a mut AccountInfo<'a>, - authority_wallet_role_info: &'a AccountInfo<'a>, - access_control_info: &'a AccountInfo<'a>, - mint_info: &'a AccountInfo<'a>, - from_info: &'a AccountInfo<'a>, - to_account_info: AccountInfo<'a>, - token_program_info: &'a AccountInfo<'a>, - ) -> Result, ProgramError> { - let escrow_account = InterfaceAccount::try_from(escrow_account_info)?; - let mut tokenlock_data: Account = - Account::try_from_unchecked(tokenlock_account_info).unwrap(); - tokenlock_data.escrow_account = escrow_account_info.key(); - authority_info.is_signer = true; - let mut authority_wallet_role: Account<'a, WalletRole> = - Account::try_from_unchecked(authority_wallet_role_info).unwrap(); - authority_wallet_role.role = Roles::ReserveAdmin as u8; - let mint_address = Box::new(InterfaceAccount::try_from(mint_info)?); - - Ok(FundReleaseSchedule { - tokenlock_account: tokenlock_data.to_account_info(), - timelock_account: Account::try_from_unchecked(&timelock_account_info).unwrap(), - authority: Signer::try_from(authority_info)?, - authority_wallet_role, - access_control: Account::try_from_unchecked(access_control_info)?, - mint_address, - escrow_account: Box::new(escrow_account), - from: Box::new(InterfaceAccount::try_from(&from_info)?), - to: to_account_info, - token_program: Program::try_from(token_program_info)?, - }) - } - - fn transfer( - escrow_account_info: &'a AccountInfo<'a>, - tokenlock_account_info: &'a AccountInfo<'a>, - timelock_account_info: &'a AccountInfo<'a>, - pda_account_info: AccountInfo<'a>, - authority_info: &'a mut AccountInfo<'a>, - to_info: &'a AccountInfo<'a>, - mint_info: &'a AccountInfo<'a>, - token_program_info: &'a AccountInfo<'a>, - ) -> Result, ProgramError> { - let escrow_account = InterfaceAccount::try_from(&escrow_account_info)?; - let mut tokenlock_data: Account = - Account::try_from_unchecked(&tokenlock_account_info).unwrap(); - tokenlock_data.escrow_account = escrow_account_info.key(); - - authority_info.is_signer = true; - Ok(TransferFrom { - tokenlock_account: tokenlock_data.to_account_info(), - timelock_account: Account::try_from_unchecked(&timelock_account_info).unwrap(), - escrow_account: Box::new(escrow_account), - pda_account: pda_account_info, - authority: Signer::try_from(authority_info)?, - to: Box::new(InterfaceAccount::try_from(&to_info)?), - mint_address: Box::new(InterfaceAccount::try_from(mint_info)?), - token_program: Program::try_from(token_program_info)?, - }) - } - - fn transfer_timelock( - escrow_account_info: &'a AccountInfo<'a>, - tokenlock_account_info: &'a AccountInfo<'a>, - timelock_account_info: &'a AccountInfo<'a>, - pda_account_info: AccountInfo<'a>, - authority_info: &'a mut AccountInfo<'a>, - to_info: &'a AccountInfo<'a>, - mint_info: &'a AccountInfo<'a>, - token_program_info: &'a AccountInfo<'a>, - ) -> Result, ProgramError> { - let escrow_account = InterfaceAccount::try_from(&escrow_account_info)?; - - let mut tokenlock_data: Account = - Account::try_from_unchecked(&tokenlock_account_info).unwrap(); - tokenlock_data.escrow_account = escrow_account_info.key(); - let timelock_data: Account = - Account::try_from_unchecked(&timelock_account_info).unwrap(); - - authority_info.is_signer = true; - - Ok(TransferTimelock { - tokenlock_account: tokenlock_data.to_account_info(), - timelock_account: timelock_data, - escrow_account: Box::new(escrow_account), - pda_account: pda_account_info, - authority: Signer::try_from(authority_info)?, - to: Box::new(InterfaceAccount::try_from(&to_info)?), - mint_address: Box::new(InterfaceAccount::try_from(mint_info)?), - token_program: Program::try_from(token_program_info)?, - }) - } - - fn cancel_timelock( - escrow_account_info: &'a AccountInfo<'a>, - tokenlock_account_info: &'a AccountInfo<'a>, - timelock_account_info: &'a AccountInfo<'a>, - target_info: AccountInfo<'a>, - pda_account_info: AccountInfo<'a>, - authority_info: &'a mut AccountInfo<'a>, - reclaimer_info: &'a AccountInfo<'a>, - target_assoc_info: &'a AccountInfo<'a>, - mint_info: &'a AccountInfo<'a>, - token_program_info: &'a AccountInfo<'a>, - ) -> Result, ProgramError> { - let escrow_account = InterfaceAccount::try_from(&escrow_account_info)?; - let mut tokenlock_data: Account = - Account::try_from_unchecked(&tokenlock_account_info).unwrap(); - tokenlock_data.escrow_account = escrow_account_info.key(); - authority_info.is_signer = true; - - Ok(CancelTimelock { - tokenlock_account: tokenlock_data.to_account_info(), - timelock_account: Account::try_from_unchecked(&timelock_account_info).unwrap(), - escrow_account: Box::new(escrow_account), - pda_account: pda_account_info, - authority: Signer::try_from(authority_info)?, - target: target_info, - reclaimer: Box::new(InterfaceAccount::try_from(&reclaimer_info)?), - target_assoc: Box::new(InterfaceAccount::try_from(&target_assoc_info)?), - mint_address: Box::new(InterfaceAccount::try_from(mint_info)?), - token_program: Program::try_from(token_program_info)?, - }) - } -} - -const UUID: [u8; 16] = [ - 255, 106, 152, 202, 209, 154, 215, 13, 87, 90, 148, 51, 113, 141, 3, 157, -]; - -impl TestFixture { - fn min_balance(size: usize) -> u64 { - Rent::default().minimum_balance(size) - } - - fn pack_mint(data: &mut [u8], supply: u64, decimals: Option) -> Result<(), ProgramError> { - Mint::pack( - Mint { - is_initialized: true, - supply: supply, - decimals: decimals.unwrap_or(6), - ..Default::default() - }, - data, - ) - } - - fn create_account( - address: &Pubkey, - program_id: &Pubkey, - discriminator: &[u8], - size: usize, - ) -> (Pubkey, SolanaAccount) { - let sol_account = SolanaAccount::new(Self::min_balance(size), size, &program_id); - let mut account: (Pubkey, SolanaAccount) = (*address, sol_account); - { - let account_info = account.into_account_info(); - let mut account_data = account_info.try_borrow_mut_data().unwrap(); - sol_memcpy(&mut account_data, &discriminator, discriminator.len()); - } - account - } - - fn create_tokenlock_account( - tokenlock_address: &Pubkey, - program_id: &Pubkey, - access_control_address: &Pubkey, - ) -> (Pubkey, SolanaAccount) { - let discriminator = TokenLockData::discriminator(); - let mut account = Self::create_account( - tokenlock_address, - program_id, - &discriminator, - TOKENLOCK_SIZE, - ); - { - let account_info = account.into_account_info(); - let mut account_data = account_info.try_borrow_mut_data().unwrap(); - sol_memcpy( - &mut account_data[discriminator.len()..], - &access_control_address.to_bytes(), - PUBKEY_SIZE, - ); - } - - account - } - - fn create_access_control_account( - access_control_address: &Pubkey, - program_id: &Pubkey, - ) -> (Pubkey, SolanaAccount) { - let discriminator = AccessControl::discriminator(); - Self::create_account( - access_control_address, - program_id, - &discriminator, - 8 + AccessControl::INIT_SPACE, - ) - } - - fn create_wallet_role_account( - wallet_role_address: &Pubkey, - program_id: &Pubkey, - ) -> (Pubkey, SolanaAccount) { - let discriminator = WalletRole::discriminator(); - Self::create_account( - wallet_role_address, - program_id, - &discriminator, - 8 + WalletRole::INIT_SPACE, - ) - } - - fn pack_token_account(data: &mut Vec, amount: u64) -> Result<(), ProgramError> { - TokenAccount::pack( - TokenAccount { - state: spl_token_2022::state::AccountState::Initialized, - amount: amount, - ..Default::default() - }, - data, - ) - } -} - -fn match_anchor_err(lh: Error, error_code: u32) -> () { - match lh { - Error::AnchorError(ae) => assert_eq!(ae.error_code_number, error_code), - Error::ProgramError(pe) => panic!( - "ProgramError {} received but expected Anchor error {}", - pe, error_code - ), - } -} - -#[test] -fn test_initialize_tokenlock() { - let mut fixture = TestFixture::default(); - let program_id = fixture.program_id; - - let tokenlock_account_info = fixture.tokenlock_account.into_account_info(); - let mint_info = fixture.mint_address.into_account_info(); - let escrow_account_info = fixture.escrow_account.into_account_info(); - let token_program_info = fixture.token_program.into_account_info(); - let authority_wallet_role_info = fixture.authority_wallet_role.into_account_info(); - let access_control_info = fixture.access_control.into_account_info(); - let mut authority_info = fixture.authority.into_account_info(); - let mut accounts = TestFixture::initialize_tokenlock( - &tokenlock_account_info, - &escrow_account_info, - &mint_info, - &authority_wallet_role_info, - &access_control_info, - &mut authority_info, - &token_program_info, - ) - .expect("Getting accounts error"); - - let bumps = InitializeTokenLockBumps::default(); - let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); - let max_release_delay = 3600; - let min_timelock_amount = 10000; - assert_eq!( - tokenlock::initialize_tokenlock(ctx, max_release_delay, min_timelock_amount).is_ok(), - true - ); - assert_eq!( - accounts.tokenlock_account.max_release_delay, - max_release_delay, - ); - assert_eq!( - accounts.tokenlock_account.min_timelock_amount, - min_timelock_amount, - ); - assert_eq!( - accounts.tokenlock_account.mint_address, - accounts.mint_address.key() - ); - assert_eq!( - accounts.tokenlock_account.escrow_account, - accounts.escrow_account.key() - ); - - let bumps = InitializeTokenLockBumps::default(); - let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); - let max_release_delay = 0; - match_anchor_err( - tokenlock::initialize_tokenlock(ctx, max_release_delay, min_timelock_amount).unwrap_err(), - 6001, - ); - - let bumps = InitializeTokenLockBumps::default(); - let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); - let max_release_delay = 3600; - let min_timelock_amount = 0; - match_anchor_err( - tokenlock::initialize_tokenlock(ctx, max_release_delay, min_timelock_amount).unwrap_err(), - 6002, - ); -} - -#[test] -fn test_initialize_timelock() { - let mut fixture = TestFixture::default(); - let program_id = fixture.program_id; - - let tokenlock_account_info = fixture.tokenlock_account.into_account_info(); - let timelock_account_info = fixture.timelock_account.into_account_info(); - let authority_wallet_role_info = fixture.authority_wallet_role.into_account_info(); - let access_control_info = fixture.access_control.into_account_info(); - let mut authority_info = fixture.authority.into_account_info(); - let target_account_info = fixture.target_account.into_account_info(); - let system_program_info = fixture.system_program.into_account_info(); - let rent_info = fixture.rent.into_account_info(); - let mut accounts = TestFixture::initialize_timelock( - tokenlock_account_info, - &timelock_account_info, - &mut authority_info, - &authority_wallet_role_info, - &access_control_info, - target_account_info, - &system_program_info, - &rent_info, - ) - .expect("Getting accounts error"); - - let bumps = InitializeTimeLockBumps::default(); - let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); - assert_eq!(tokenlock::initialize_timelock(ctx).is_ok(), true); - assert_eq!( - accounts.timelock_account.target_account, - accounts.target_account.key(), - ); - assert_eq!( - accounts.timelock_account.tokenlock_account, - accounts.tokenlock_account.key(), - ); - assert_eq!(accounts.timelock_account.cancelables.len(), 0); - assert_eq!(accounts.timelock_account.timelocks.len(), 0); -} - -#[test] -fn test_create_release_schedule() { - let mut fixture = TestFixture::default(); - let program_id = fixture.program_id; - let tokenlock_account_info = fixture.tokenlock_account.into_account_info(); - let mut authority_info = fixture.authority.into_account_info(); - let authority_wallet_role_info = fixture.authority_wallet_role.into_account_info(); - let access_control_info = fixture.access_control.into_account_info(); - let mut accounts = TestFixture::create_release_schedule( - tokenlock_account_info, - &mut authority_info, - &authority_wallet_role_info, - &access_control_info, - ) - .expect("Getting accounts error"); - - let release_count = 4; - let delay_until_first_release_in_seconds = 0; - let initial_release_portion_in_bips = 1000; - let period_between_releases_in_seconds = 3600; - - let bumps = ManagementTokenlockBumps::default(); - let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); - assert_eq!( - tokenlock::create_release_schedule( - ctx, - UUID, - release_count, - delay_until_first_release_in_seconds, - initial_release_portion_in_bips, - period_between_releases_in_seconds, - ) - .is_ok(), - true - ); - - let tokenlock_data: Account = - Account::try_from_unchecked(accounts.tokenlock_account.as_ref()).unwrap(); - assert_eq!(tokenlock_data.release_schedules.len(), 1); - let result_release_schedule = tokenlock_data.release_schedules.first().unwrap(); - assert_eq!(result_release_schedule.release_count, release_count); - assert_eq!( - result_release_schedule.delay_until_first_release_in_seconds, - delay_until_first_release_in_seconds - ); - assert_eq!( - result_release_schedule.initial_release_portion_in_bips, - initial_release_portion_in_bips - ); - assert_eq!( - result_release_schedule.period_between_releases_in_seconds, - period_between_releases_in_seconds - ); - - let delay_until_first_release_in_seconds = 1000; - let bumps = ManagementTokenlockBumps::default(); - let mut accounts = accounts.clone(); - let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); - match_anchor_err( - tokenlock::create_release_schedule( - ctx, - UUID, - release_count, - delay_until_first_release_in_seconds, - initial_release_portion_in_bips, - period_between_releases_in_seconds, - ) - .unwrap_err(), - 6019, - ); - - let delay_until_first_release_in_seconds = 0; - let release_count = 0; - let bumps = ManagementTokenlockBumps::default(); - let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); - match_anchor_err( - tokenlock::create_release_schedule( - ctx, - UUID, - release_count, - delay_until_first_release_in_seconds, - initial_release_portion_in_bips, - period_between_releases_in_seconds, - ) - .unwrap_err(), - 6020, - ); - - let release_count = 2; - let initial_release_portion_in_bips = 10001; - let bumps = ManagementTokenlockBumps::default(); - let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); - match_anchor_err( - tokenlock::create_release_schedule( - ctx, - UUID, - release_count, - delay_until_first_release_in_seconds, - initial_release_portion_in_bips, - period_between_releases_in_seconds, - ) - .unwrap_err(), - 6021, - ); - - let initial_release_portion_in_bips = 1000; - let period_between_releases_in_seconds = 0; - let bumps = ManagementTokenlockBumps::default(); - let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); - match_anchor_err( - tokenlock::create_release_schedule( - ctx, - UUID, - release_count, - delay_until_first_release_in_seconds, - initial_release_portion_in_bips, - period_between_releases_in_seconds, - ) - .unwrap_err(), - 6022, - ); - - let initial_release_portion_in_bips = 1000; - let release_count = 1; - let bumps = ManagementTokenlockBumps::default(); - let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); - match_anchor_err( - tokenlock::create_release_schedule( - ctx, - UUID, - release_count, - delay_until_first_release_in_seconds, - initial_release_portion_in_bips, - period_between_releases_in_seconds, - ) - .unwrap_err(), - 6023, - ); -} - -#[test] -fn test_fund_release_schedule() { - let mut fixture_create_release = TestFixture::default(); - let program_id = fixture_create_release.program_id; - let tokenlock_account_info = fixture_create_release.tokenlock_account.into_account_info(); - let mut authority_info = fixture_create_release.authority.into_account_info(); - let authority_wallet_role_info = fixture_create_release - .authority_wallet_role - .into_account_info(); - let access_control_info = fixture_create_release.access_control.into_account_info(); - let mut accounts_create_release = TestFixture::create_release_schedule( - tokenlock_account_info, - &mut authority_info, - &authority_wallet_role_info, - &access_control_info, - ) - .expect("Getting accounts error"); - - let release_count = 4; - let delay_until_first_release_in_seconds = 0; - let initial_release_portion_in_bips = 1000; - let period_between_releases_in_seconds = 3600; - - let bumps = ManagementTokenlockBumps::default(); - let ctx: Context = - Context::new(&program_id, &mut accounts_create_release, &[], bumps); - assert_eq!( - tokenlock::create_release_schedule( - ctx, - UUID, - release_count, - delay_until_first_release_in_seconds, - initial_release_portion_in_bips, - period_between_releases_in_seconds, - ) - .is_ok(), - true - ); - - let mut fixture = TestFixture::default(); - let program_id = fixture.program_id; - let tokenlock_account_info = fixture.tokenlock_account.into_account_info(); - let escrow_account_info = fixture.escrow_account.into_account_info(); - let timelock_account_info = fixture.timelock_account.into_account_info(); - let mut authority_info = fixture.authority.into_account_info(); - let authority_wallet_role_info = fixture.authority_wallet_role.into_account_info(); - let mint_info = fixture.mint_address.into_account_info(); - let from_info = fixture.from.into_account_info(); - let to_info = fixture.to.into_account_info(); - let token_program_info = fixture.token_program.into_account_info(); - let mut accounts = TestFixture::fund_release_schedule( - &escrow_account_info, - &tokenlock_account_info, - &timelock_account_info, - &mut authority_info, - &authority_wallet_role_info, - &access_control_info, - &mint_info, - &from_info, - to_info, - &token_program_info, - ) - .expect("Getting accounts error"); - accounts.tokenlock_account = accounts_create_release.tokenlock_account; - - let amount = 10000; - let commencement_timestamp = 0; - let schedule_id = 0; - let cancelar = Pubkey::new_unique(); - let cancelable_by = vec![cancelar, Pubkey::new_unique()]; - let bumps = FundReleaseScheduleBumps::default(); - let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); - assert_eq!( - tokenlock::fund_release_schedule( - ctx, - UUID, - amount, - commencement_timestamp, - schedule_id, - cancelable_by.clone() - ) - .is_ok(), - true - ); - - // BadCase: timelock already exists - let bumps = FundReleaseScheduleBumps::default(); - let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); - match_anchor_err( - tokenlock::fund_release_schedule( - ctx, - UUID, - amount, - commencement_timestamp, - schedule_id, - cancelable_by.clone(), - ) - .unwrap_err(), - 6027, - ); - - // BadCase: Commencement time out of range - let commencement_timestamp = utils::get_unix_timestamp() + 10; - let bumps = FundReleaseScheduleBumps::default(); - let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); - match_anchor_err( - tokenlock::fund_release_schedule( - ctx, - UUID, - amount, - commencement_timestamp, - schedule_id, - cancelable_by.clone(), - ) - .unwrap_err(), - 6008, - ); - - // BadCase: Max 10 cancelableBy addressees - let bumps = FundReleaseScheduleBumps::default(); - let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); - let cancelable_by = vec![Pubkey::new_unique(); Timelock::CANCELABLE_BY_COUNT_MAX as usize + 1]; - match_anchor_err( - tokenlock::fund_release_schedule( - ctx, - UUID, - amount, - commencement_timestamp, - schedule_id, - cancelable_by, - ) - .unwrap_err(), - 6010, - ); -} - -#[test] -fn test_transfer() { - let mut fixture_create_release = TestFixture::default(); - let program_id = fixture_create_release.program_id; - let tokenlock_account_info = fixture_create_release.tokenlock_account.into_account_info(); - let mut authority_info = fixture_create_release.authority.into_account_info(); - let authority_wallet_role_info = fixture_create_release - .authority_wallet_role - .into_account_info(); - let access_control_info = fixture_create_release.access_control.into_account_info(); - let mut accounts_create_release = TestFixture::create_release_schedule( - tokenlock_account_info, - &mut authority_info, - &authority_wallet_role_info, - &access_control_info, - ) - .expect("Getting accounts error"); - - let release_count = 2; - let delay_until_first_release_in_seconds = 0; - let initial_release_portion_in_bips = 5000; - let period_between_releases_in_seconds = 3600; - - let bumps = ManagementTokenlockBumps::default(); - let ctx: Context = - Context::new(&program_id, &mut accounts_create_release, &[], bumps); - assert_eq!( - tokenlock::create_release_schedule( - ctx, - UUID, - release_count, - delay_until_first_release_in_seconds, - initial_release_portion_in_bips, - period_between_releases_in_seconds, - ) - .is_ok(), - true - ); - - let mut fixture = TestFixture::default(); - let total_amount = 1_000_000_000; - let tokenlock_account_info = fixture.tokenlock_account.into_account_info(); - let escrow_account_info = fixture.escrow_account.into_account_info(); - let timelock_account_info = fixture.timelock_account.into_account_info(); - let mut authority_info = fixture.authority.into_account_info(); - let pda_info = fixture.pda_account.into_account_info(); - let to_info = fixture.to.into_account_info(); - let mint_info = fixture.mint_address.into_account_info(); - let token_program_info = fixture.token_program.into_account_info(); - let mut accounts = TestFixture::transfer( - &escrow_account_info, - &tokenlock_account_info, - &timelock_account_info, - pda_info, - &mut authority_info, - &to_info, - &mint_info, - &token_program_info, - ) - .expect("Getting accounts error"); - accounts.tokenlock_account = accounts_create_release.tokenlock_account; - accounts.timelock_account.timelocks.push(Timelock { - schedule_id: 0, - commencement_timestamp: 123123513, - tokens_transferred: 0, - total_amount: total_amount, - cancelable_by_count: 0, - cancelable_by: [0; 10], - signer_hash: [0; 20], - }); - - let amount = 10000; - let bumps = TransferFromBumps::default(); - let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); - assert_eq!(tokenlock::transfer(ctx, amount).is_ok(), true); - - // BadCase: Amount bigger than unlocked - let huge_amount = total_amount - amount + 1; - let bumps = TransferFromBumps::default(); - let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); - - match_anchor_err(tokenlock::transfer(ctx, huge_amount).unwrap_err(), 6014); -} - -#[test] -fn test_transfer_timelock() { - let mut fixture_create_release = TestFixture::default(); - let program_id = fixture_create_release.program_id; - let tokenlock_account_info = fixture_create_release.tokenlock_account.into_account_info(); - let mut authority_info = fixture_create_release.authority.into_account_info(); - let authority_wallet_role_info = fixture_create_release - .authority_wallet_role - .into_account_info(); - let access_control_info = fixture_create_release.access_control.into_account_info(); - let mut accounts_create_release = TestFixture::create_release_schedule( - tokenlock_account_info, - &mut authority_info, - &authority_wallet_role_info, - &access_control_info, - ) - .expect("Getting accounts error"); - - let release_count = 2; - let delay_until_first_release_in_seconds = 0; - let initial_release_portion_in_bips = 5000; - let period_between_releases_in_seconds = 3600; - - let bumps = ManagementTokenlockBumps::default(); - let ctx: Context = - Context::new(&program_id, &mut accounts_create_release, &[], bumps); - assert_eq!( - tokenlock::create_release_schedule( - ctx, - UUID, - release_count, - delay_until_first_release_in_seconds, - initial_release_portion_in_bips, - period_between_releases_in_seconds, - ) - .is_ok(), - true - ); - - let mut fixture = TestFixture::default(); - let program_id = fixture.program_id; - let tokenlock_account_info = fixture.tokenlock_account.into_account_info(); - let escrow_account_info = fixture.escrow_account.into_account_info(); - let timelock_account_info = fixture.timelock_account.into_account_info(); - let mut authority_info = fixture.authority.into_account_info(); - let pda_info = fixture.pda_account.into_account_info(); - let to_info = fixture.to.into_account_info(); - let token_program_info = fixture.token_program.into_account_info(); - let mint_info = fixture.mint_address.into_account_info(); - let mut accounts = TestFixture::transfer_timelock( - &escrow_account_info, - &tokenlock_account_info, - &timelock_account_info, - pda_info, - &mut authority_info, - &to_info, - &mint_info, - &token_program_info, - ) - .expect("Getting accounts error"); - let timelock_amount = 1_000_000_000; - accounts.tokenlock_account = accounts_create_release.tokenlock_account; - accounts.timelock_account.timelocks.push(Timelock { - schedule_id: 0, - commencement_timestamp: 123123513, - tokens_transferred: 0, - total_amount: timelock_amount, - cancelable_by_count: 0, - cancelable_by: [0; 10], - signer_hash: [0; 20], - }); - - let amount = 10000; - let timelock_id = 0; - let bumps = TransferTimelockBumps::default(); - let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); - - assert_eq!( - tokenlock::transfer_timelock(ctx, amount, timelock_id).is_ok(), - true - ); - - // BadCase: Amount bigger than unlocked - let huge_amount = timelock_amount - amount + 1; - let timelock_id = 0; - let bumps = TransferTimelockBumps::default(); - let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); - - match_anchor_err( - tokenlock::transfer_timelock(ctx, huge_amount, timelock_id).unwrap_err(), - 6014, - ); -} - -#[test] -fn test_cancel_timelock() { - let mut fixture_create_release = TestFixture::default(); - let program_id = fixture_create_release.program_id; - let tokenlock_account_info = fixture_create_release.tokenlock_account.into_account_info(); - let mut authority_info = fixture_create_release.authority.into_account_info(); - let authority_wallet_role_info = fixture_create_release - .authority_wallet_role - .into_account_info(); - let access_control_info = fixture_create_release.access_control.into_account_info(); - let mut accounts_create_release = TestFixture::create_release_schedule( - tokenlock_account_info, - &mut authority_info, - &authority_wallet_role_info, - &access_control_info, - ) - .expect("Getting accounts error"); - - let release_count = 2; - let delay_until_first_release_in_seconds = 0; - let initial_release_portion_in_bips = 5000; - let period_between_releases_in_seconds = 3600; - - let bumps = ManagementTokenlockBumps::default(); - let ctx: Context = - Context::new(&program_id, &mut accounts_create_release, &[], bumps); - assert_eq!( - tokenlock::create_release_schedule( - ctx, - UUID, - release_count, - delay_until_first_release_in_seconds, - initial_release_portion_in_bips, - period_between_releases_in_seconds, - ) - .is_ok(), - true - ); - - let mut fixture = TestFixture::default(); - let program_id = fixture.program_id; - let tokenlock_account_info = fixture.tokenlock_account.into_account_info(); - let escrow_account_info = fixture.escrow_account.into_account_info(); - let timelock_account_info = fixture.timelock_account.into_account_info(); - let from_info = fixture.from.into_account_info(); - let to_info = fixture.to.into_account_info(); - let token_program_info = fixture.token_program.into_account_info(); - let mut authority_info = fixture.authority.into_account_info(); - let authority_wallet_role_info = fixture.authority_wallet_role.into_account_info(); - let mint_info = fixture.mint_address.into_account_info(); - let mut accounts_fund_release = TestFixture::fund_release_schedule( - &escrow_account_info, - &tokenlock_account_info, - &timelock_account_info, - &mut authority_info, - &authority_wallet_role_info, - &access_control_info, - &mint_info, - &from_info, - to_info, - &token_program_info, - ) - .expect("Getting accounts error"); - accounts_fund_release.tokenlock_account = accounts_create_release.tokenlock_account; - - let amount = 10000; - let commencement_timestamp = 0; - let schedule_id = 0; - let cancelar = Pubkey::new_unique(); - let cancelable_by = vec![cancelar, Pubkey::new_unique()]; - let bumps = FundReleaseScheduleBumps::default(); - let ctx: Context = - Context::new(&program_id, &mut accounts_fund_release, &[], bumps); - assert_eq!( - tokenlock::fund_release_schedule( - ctx, - UUID, - amount, - commencement_timestamp, - schedule_id, - cancelable_by.clone() - ) - .is_ok(), - true - ); - - // BadCase: Invalid timelock id - let timelock_id = 0; - let mut fixture = TestFixture::default(); - let tokenlock_account_info = fixture.tokenlock_account.into_account_info(); - let escrow_account_info = fixture.escrow_account.into_account_info(); - let timelock_account_info = fixture.timelock_account.into_account_info(); - let mut authority_info = fixture.authority.into_account_info(); - let pda_info = fixture.pda_account.into_account_info(); - let target_info = fixture.target.into_account_info(); - let reclaimer_info = fixture.reclaimer.into_account_info(); - let target_assoc_info = fixture.target_assoc.into_account_info(); - let token_program_info = fixture.token_program.into_account_info(); - let mint_info = fixture.mint_address.into_account_info(); - let mut accounts = TestFixture::cancel_timelock( - &escrow_account_info, - &tokenlock_account_info, - &timelock_account_info, - target_info, - pda_info, - &mut authority_info, - &reclaimer_info, - &target_assoc_info, - &mint_info, - &token_program_info, - ) - .expect("Getting accounts error"); - let bumps = CancelTimelockBumps::default(); - let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); - - match_anchor_err( - tokenlock::cancel_timelock(ctx, timelock_id).unwrap_err(), - 6011, - ); - - // BadCase: You are not allowed to cancel this timelock - accounts.timelock_account.timelocks.push(Timelock { - schedule_id: 0, - commencement_timestamp: utils::get_unix_timestamp(), - tokens_transferred: 1_000_000_000, - total_amount: 1_000_000_000, - cancelable_by_count: 1, - cancelable_by: [0; 10], - signer_hash: [0; 20], - }); - let bumps = CancelTimelockBumps::default(); - let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); - - match_anchor_err( - tokenlock::cancel_timelock(ctx, timelock_id).unwrap_err(), - 6013, - ); - - // BadCase: Timelock has no value left - let mut authority_info = accounts.authority.to_account_info(); - authority_info.is_signer = true; - authority_info.key = &cancelar; - accounts.authority = Signer::try_from(&authority_info).unwrap(); - // accounts.authority.key = &cancelar; - accounts.timelock_account.cancelables.push(cancelar); - let bumps = CancelTimelockBumps::default(); - let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); - - match_anchor_err( - tokenlock::cancel_timelock(ctx, timelock_id).unwrap_err(), - 6012, - ); - - accounts.tokenlock_account = accounts_fund_release.tokenlock_account; - accounts.timelock_account.timelocks.push(Timelock { - schedule_id: 0, - commencement_timestamp: utils::get_unix_timestamp(), - tokens_transferred: 0, - total_amount: 1_000_000_000, - cancelable_by_count: 1, - cancelable_by: [0; 10], - signer_hash: [0; 20], - }); - - let timelock_id = 1; - let bumps = CancelTimelockBumps::default(); - let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); - - assert_eq!(tokenlock::cancel_timelock(ctx, timelock_id).is_ok(), true); -} +// use super::*; +// use access_control::{AccessControl, Roles, WalletRole}; +// use anchor_lang::Discriminator; +// use common::PUBKEY_SIZE; +// use core::result::Result; +// use solana_sdk::{ +// account::{create_account_for_test, Account as SolanaAccount}, +// account_info::IntoAccountInfo, +// program_memory::sol_memcpy, +// program_pack::Pack, +// system_program, +// sysvar::SysvarId, +// }; +// use spl_token_2022::state::{Account as TokenAccount, Mint}; +// use std::str::FromStr; +// const TOKENLOCK_SIZE: usize = 10 * 1024 * 1024; + +// struct TestFixture { +// program_id: Pubkey, +// tokenlock_account: (Pubkey, SolanaAccount), +// timelock_account: (Pubkey, SolanaAccount), +// authority_wallet_role: (Pubkey, SolanaAccount), +// access_control: (Pubkey, SolanaAccount), +// authority: (Pubkey, SolanaAccount), +// escrow_account: (Pubkey, SolanaAccount), +// mint_address: (Pubkey, SolanaAccount), +// target_account: (Pubkey, SolanaAccount), +// from: (Pubkey, SolanaAccount), +// to: (Pubkey, SolanaAccount), +// pda_account: (Pubkey, SolanaAccount), +// target: (Pubkey, SolanaAccount), +// reclaimer: (Pubkey, SolanaAccount), +// target_assoc: (Pubkey, SolanaAccount), +// token_program: (Pubkey, SolanaAccount), +// system_program: (Pubkey, SolanaAccount), +// rent: (Pubkey, SolanaAccount), +// } + +// impl Default for TestFixture { +// fn default() -> Self { +// let program_id = Pubkey::from_str("7CN3iHcRimZRa97M38cyMQAF68ecQYDqHfCUgBeSARG2").unwrap(); +// let access_control_program_id = access_control::ID; +// let key = Pubkey::from_str("11111111111111111111111111111111").unwrap(); + +// let tokenlock_address = Pubkey::new_unique(); +// let mint_address = key; +// let mut mint_acc = SolanaAccount::new( +// Self::min_balance(Mint::LEN), +// Mint::LEN, +// &anchor_spl::token_2022::ID, +// ); +// Self::pack_mint(&mut mint_acc.data, 0, None).expect("Mint pack Error"); + +// let (pda, _) = Pubkey::find_program_address( +// &[ +// TOKENLOCK_PDA_SEED, +// mint_address.as_ref(), +// tokenlock_address.as_ref(), +// ], +// &program_id, +// ); + +// let mut escrow_account_acc = SolanaAccount::new( +// Self::min_balance(TokenAccount::LEN), +// TokenAccount::LEN, +// &anchor_spl::token_2022::ID, +// ); +// TokenAccount::pack( +// TokenAccount { +// state: spl_token_2022::state::AccountState::Initialized, +// amount: 0, +// owner: pda, +// ..Default::default() +// }, +// &mut escrow_account_acc.data, +// ) +// .unwrap(); + +// let mut from = SolanaAccount::new( +// Self::min_balance(TokenAccount::LEN), +// TokenAccount::LEN, +// &anchor_spl::token_2022::ID, +// ); +// Self::pack_token_account(&mut from.data, 0).expect("From address pack Error"); + +// let mut to = SolanaAccount::new( +// Self::min_balance(TokenAccount::LEN), +// TokenAccount::LEN, +// &anchor_spl::token_2022::ID, +// ); +// Self::pack_token_account(&mut to.data, 0).expect("To address pack Error"); + +// let mut reclaimer = SolanaAccount::new( +// Self::min_balance(TokenAccount::LEN), +// TokenAccount::LEN, +// &anchor_spl::token_2022::ID, +// ); +// Self::pack_token_account(&mut reclaimer.data, 0) +// .expect("Reclaimer token wallet pack Error"); + +// let mut target_assoc = SolanaAccount::new( +// Self::min_balance(TokenAccount::LEN), +// TokenAccount::LEN, +// &anchor_spl::token_2022::ID, +// ); +// Self::pack_token_account(&mut target_assoc.data, 0) +// .expect("Target token wallet pack Error"); + +// let mut token_program_account = SolanaAccount::default(); +// token_program_account.executable = true; + +// let mut system_program_account = SolanaAccount::default(); +// system_program_account.executable = true; + +// let access_control_address = Pubkey::new_unique(); + +// Self { +// program_id, + +// tokenlock_account: Self::create_tokenlock_account( +// &tokenlock_address, +// &program_id, +// &access_control_address, +// ), +// timelock_account: ( +// Pubkey::new_unique(), +// SolanaAccount::new(Self::min_balance(10240), 10240, &program_id), +// ), +// access_control: Self::create_access_control_account( +// &access_control_address, +// &access_control_program_id, +// ), +// authority_wallet_role: Self::create_wallet_role_account( +// &Pubkey::new_unique(), +// &access_control_program_id, +// ), +// authority: (Pubkey::new_unique(), SolanaAccount::default()), +// escrow_account: (key.clone(), escrow_account_acc), +// mint_address: (mint_address, mint_acc), +// target_account: (Pubkey::new_unique(), SolanaAccount::default()), +// from: (Pubkey::new_unique(), from), +// to: (Pubkey::new_unique(), to), +// pda_account: (Pubkey::new_unique(), SolanaAccount::default()), +// target: (Pubkey::new_unique(), SolanaAccount::default()), +// reclaimer: (Pubkey::new_unique(), reclaimer), +// target_assoc: (Pubkey::new_unique(), target_assoc), + +// token_program: (spl_token_2022::id(), token_program_account), +// system_program: (system_program::id(), system_program_account), +// rent: (Rent::id(), create_account_for_test(&Rent::default())), +// } +// } +// } + +// impl<'a> TestFixture { +// fn initialize_tokenlock( +// tokenlock_account_info: &'a AccountInfo<'a>, +// escrow_account_info: &'a AccountInfo<'a>, +// mint_info: &'a AccountInfo<'a>, +// authority_wallet_role_info: &'a AccountInfo<'a>, +// access_control_info: &'a AccountInfo<'a>, +// authority_info: &'a mut AccountInfo<'a>, +// token_program_info: &'a AccountInfo<'a>, +// ) -> Result, ProgramError> { +// authority_info.is_signer = true; +// let escrow_account = Box::new(InterfaceAccount::try_from(escrow_account_info)?); +// let mint_address = Box::new(InterfaceAccount::try_from(mint_info)?); + +// Ok(InitializeTokenLock { +// tokenlock_account: Account::try_from_unchecked(tokenlock_account_info)?, +// escrow_account, +// mint_address, +// authority_wallet_role: Account::try_from_unchecked(authority_wallet_role_info)?, +// access_control: Account::try_from_unchecked(access_control_info)?, +// authority: Signer::try_from(authority_info)?, +// token_program: Program::try_from(token_program_info)?, +// }) +// } + +// fn initialize_timelock( +// tokenlock_account_info: AccountInfo<'a>, +// timelock_account_info: &'a AccountInfo<'a>, +// authority_info: &'a mut AccountInfo<'a>, +// authority_wallet_role_info: &'a AccountInfo<'a>, +// access_control_info: &'a AccountInfo<'a>, +// target_account_info: AccountInfo<'a>, +// system_program_info: &'a AccountInfo<'a>, +// rent_info: &'a AccountInfo<'a>, +// ) -> Result, ProgramError> { +// authority_info.is_signer = true; +// let mut authority_wallet_role: Account<'a, WalletRole> = +// Account::try_from_unchecked(authority_wallet_role_info).unwrap(); +// authority_wallet_role.role = Roles::ReserveAdmin as u8; + +// Ok(InitializeTimeLock { +// tokenlock_account: tokenlock_account_info, +// timelock_account: Account::try_from_unchecked(timelock_account_info)?, +// authority: Signer::try_from(authority_info).unwrap(), +// access_control: Account::try_from_unchecked(access_control_info).unwrap(), +// authority_wallet_role, +// target_account: target_account_info, +// system_program: Program::try_from(system_program_info)?, +// rent: Sysvar::from_account_info(rent_info)?, +// }) +// } + +// fn create_release_schedule( +// tokenlock_account_info: AccountInfo<'a>, +// authority_info: &'a mut AccountInfo<'a>, +// authority_wallet_role_info: &'a AccountInfo<'a>, +// access_control_info: &'a AccountInfo<'a>, +// ) -> Result, ProgramError> { +// authority_info.is_signer = true; +// let mut authority_wallet_role: Account<'a, WalletRole> = +// Account::try_from_unchecked(authority_wallet_role_info).unwrap(); +// authority_wallet_role.role = Roles::ReserveAdmin as u8; + +// Ok(ManagementTokenlock { +// tokenlock_account: tokenlock_account_info, +// authority: Signer::try_from(authority_info)?, +// authority_wallet_role, +// access_control: Account::try_from_unchecked(access_control_info)?, +// }) +// } + +// fn fund_release_schedule( +// escrow_account_info: &'a AccountInfo<'a>, +// tokenlock_account_info: &'a AccountInfo<'a>, +// timelock_account_info: &'a AccountInfo<'a>, +// authority_info: &'a mut AccountInfo<'a>, +// authority_wallet_role_info: &'a AccountInfo<'a>, +// access_control_info: &'a AccountInfo<'a>, +// mint_info: &'a AccountInfo<'a>, +// from_info: &'a AccountInfo<'a>, +// to_account_info: AccountInfo<'a>, +// token_program_info: &'a AccountInfo<'a>, +// ) -> Result, ProgramError> { +// let escrow_account = InterfaceAccount::try_from(escrow_account_info)?; +// let mut tokenlock_data: Account = +// Account::try_from_unchecked(tokenlock_account_info).unwrap(); +// tokenlock_data.escrow_account = escrow_account_info.key(); +// authority_info.is_signer = true; +// let mut authority_wallet_role: Account<'a, WalletRole> = +// Account::try_from_unchecked(authority_wallet_role_info).unwrap(); +// authority_wallet_role.role = Roles::ReserveAdmin as u8; +// let mint_address = Box::new(InterfaceAccount::try_from(mint_info)?); + +// Ok(FundReleaseSchedule { +// tokenlock_account: tokenlock_data.to_account_info(), +// timelock_account: Account::try_from_unchecked(&timelock_account_info).unwrap(), +// authority: Signer::try_from(authority_info)?, +// authority_wallet_role, +// access_control: Account::try_from_unchecked(access_control_info)?, +// mint_address, +// escrow_account: Box::new(escrow_account), +// from: Box::new(InterfaceAccount::try_from(&from_info)?), +// to: to_account_info, +// token_program: Program::try_from(token_program_info)?, +// }) +// } + +// fn transfer( +// escrow_account_info: &'a AccountInfo<'a>, +// tokenlock_account_info: &'a AccountInfo<'a>, +// timelock_account_info: &'a AccountInfo<'a>, +// pda_account_info: AccountInfo<'a>, +// authority_info: &'a mut AccountInfo<'a>, +// to_info: &'a AccountInfo<'a>, +// mint_info: &'a AccountInfo<'a>, +// token_program_info: &'a AccountInfo<'a>, +// ) -> Result, ProgramError> { +// let escrow_account = InterfaceAccount::try_from(&escrow_account_info)?; +// let mut tokenlock_data: Account = +// Account::try_from_unchecked(&tokenlock_account_info).unwrap(); +// tokenlock_data.escrow_account = escrow_account_info.key(); + +// authority_info.is_signer = true; +// Ok(TransferFrom { +// tokenlock_account: tokenlock_data.to_account_info(), +// timelock_account: Account::try_from_unchecked(&timelock_account_info).unwrap(), +// escrow_account: Box::new(escrow_account), +// pda_account: pda_account_info, +// authority: Signer::try_from(authority_info)?, +// to: Box::new(InterfaceAccount::try_from(&to_info)?), +// mint_address: Box::new(InterfaceAccount::try_from(mint_info)?), +// token_program: Program::try_from(token_program_info)?, +// }) +// } + +// fn transfer_timelock( +// escrow_account_info: &'a AccountInfo<'a>, +// tokenlock_account_info: &'a AccountInfo<'a>, +// timelock_account_info: &'a AccountInfo<'a>, +// pda_account_info: AccountInfo<'a>, +// authority_info: &'a mut AccountInfo<'a>, +// to_info: &'a AccountInfo<'a>, +// mint_info: &'a AccountInfo<'a>, +// token_program_info: &'a AccountInfo<'a>, +// ) -> Result, ProgramError> { +// let escrow_account = InterfaceAccount::try_from(&escrow_account_info)?; + +// let mut tokenlock_data: Account = +// Account::try_from_unchecked(&tokenlock_account_info).unwrap(); +// tokenlock_data.escrow_account = escrow_account_info.key(); +// let timelock_data: Account = +// Account::try_from_unchecked(&timelock_account_info).unwrap(); + +// authority_info.is_signer = true; + +// Ok(TransferTimelock { +// tokenlock_account: tokenlock_data.to_account_info(), +// timelock_account: timelock_data, +// escrow_account: Box::new(escrow_account), +// pda_account: pda_account_info, +// authority: Signer::try_from(authority_info)?, +// to: Box::new(InterfaceAccount::try_from(&to_info)?), +// mint_address: Box::new(InterfaceAccount::try_from(mint_info)?), +// token_program: Program::try_from(token_program_info)?, +// }) +// } + +// fn cancel_timelock( +// escrow_account_info: &'a AccountInfo<'a>, +// tokenlock_account_info: &'a AccountInfo<'a>, +// timelock_account_info: &'a AccountInfo<'a>, +// target_info: AccountInfo<'a>, +// pda_account_info: AccountInfo<'a>, +// authority_info: &'a mut AccountInfo<'a>, +// reclaimer_info: &'a AccountInfo<'a>, +// target_assoc_info: &'a AccountInfo<'a>, +// mint_info: &'a AccountInfo<'a>, +// token_program_info: &'a AccountInfo<'a>, +// ) -> Result, ProgramError> { +// let escrow_account = InterfaceAccount::try_from(&escrow_account_info)?; +// let mut tokenlock_data: Account = +// Account::try_from_unchecked(&tokenlock_account_info).unwrap(); +// tokenlock_data.escrow_account = escrow_account_info.key(); +// authority_info.is_signer = true; + +// Ok(CancelTimelock { +// tokenlock_account: tokenlock_data.to_account_info(), +// timelock_account: Account::try_from_unchecked(&timelock_account_info).unwrap(), +// escrow_account: Box::new(escrow_account), +// pda_account: pda_account_info, +// authority: Signer::try_from(authority_info)?, +// target: target_info, +// reclaimer: Box::new(InterfaceAccount::try_from(&reclaimer_info)?), +// target_assoc: Box::new(InterfaceAccount::try_from(&target_assoc_info)?), +// mint_address: Box::new(InterfaceAccount::try_from(mint_info)?), +// token_program: Program::try_from(token_program_info)?, +// }) +// } +// } + +// const UUID: [u8; 16] = [ +// 255, 106, 152, 202, 209, 154, 215, 13, 87, 90, 148, 51, 113, 141, 3, 157, +// ]; + +// impl TestFixture { +// fn min_balance(size: usize) -> u64 { +// Rent::default().minimum_balance(size) +// } + +// fn pack_mint(data: &mut [u8], supply: u64, decimals: Option) -> Result<(), ProgramError> { +// Mint::pack( +// Mint { +// is_initialized: true, +// supply: supply, +// decimals: decimals.unwrap_or(6), +// ..Default::default() +// }, +// data, +// ) +// } + +// fn create_account( +// address: &Pubkey, +// program_id: &Pubkey, +// discriminator: &[u8], +// size: usize, +// ) -> (Pubkey, SolanaAccount) { +// let sol_account = SolanaAccount::new(Self::min_balance(size), size, &program_id); +// let mut account: (Pubkey, SolanaAccount) = (*address, sol_account); +// { +// let account_info = account.into_account_info(); +// let mut account_data = account_info.try_borrow_mut_data().unwrap(); +// sol_memcpy(&mut account_data, &discriminator, discriminator.len()); +// } +// account +// } + +// fn create_tokenlock_account( +// tokenlock_address: &Pubkey, +// program_id: &Pubkey, +// access_control_address: &Pubkey, +// ) -> (Pubkey, SolanaAccount) { +// let discriminator = TokenLockData::discriminator(); +// let mut account = Self::create_account( +// tokenlock_address, +// program_id, +// &discriminator, +// TOKENLOCK_SIZE, +// ); +// { +// let account_info = account.into_account_info(); +// let mut account_data = account_info.try_borrow_mut_data().unwrap(); +// sol_memcpy( +// &mut account_data[discriminator.len()..], +// &access_control_address.to_bytes(), +// PUBKEY_SIZE, +// ); +// } + +// account +// } + +// fn create_access_control_account( +// access_control_address: &Pubkey, +// program_id: &Pubkey, +// ) -> (Pubkey, SolanaAccount) { +// let discriminator = AccessControl::discriminator(); +// Self::create_account( +// access_control_address, +// program_id, +// &discriminator, +// 8 + AccessControl::INIT_SPACE, +// ) +// } + +// fn create_wallet_role_account( +// wallet_role_address: &Pubkey, +// program_id: &Pubkey, +// ) -> (Pubkey, SolanaAccount) { +// let discriminator = WalletRole::discriminator(); +// Self::create_account( +// wallet_role_address, +// program_id, +// &discriminator, +// 8 + WalletRole::INIT_SPACE, +// ) +// } + +// fn pack_token_account(data: &mut Vec, amount: u64) -> Result<(), ProgramError> { +// TokenAccount::pack( +// TokenAccount { +// state: spl_token_2022::state::AccountState::Initialized, +// amount: amount, +// ..Default::default() +// }, +// data, +// ) +// } +// } + +// fn match_anchor_err(lh: Error, error_code: u32) -> () { +// match lh { +// Error::AnchorError(ae) => assert_eq!(ae.error_code_number, error_code), +// Error::ProgramError(pe) => panic!( +// "ProgramError {} received but expected Anchor error {}", +// pe, error_code +// ), +// } +// } + +// #[test] +// fn test_initialize_tokenlock() { +// let mut fixture = TestFixture::default(); +// let program_id = fixture.program_id; + +// let tokenlock_account_info = fixture.tokenlock_account.into_account_info(); +// let mint_info = fixture.mint_address.into_account_info(); +// let escrow_account_info = fixture.escrow_account.into_account_info(); +// let token_program_info = fixture.token_program.into_account_info(); +// let authority_wallet_role_info = fixture.authority_wallet_role.into_account_info(); +// let access_control_info = fixture.access_control.into_account_info(); +// let mut authority_info = fixture.authority.into_account_info(); +// let mut accounts = TestFixture::initialize_tokenlock( +// &tokenlock_account_info, +// &escrow_account_info, +// &mint_info, +// &authority_wallet_role_info, +// &access_control_info, +// &mut authority_info, +// &token_program_info, +// ) +// .expect("Getting accounts error"); + +// let bumps = InitializeTokenLockBumps::default(); +// let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); +// let max_release_delay = 3600; +// let min_timelock_amount = 10000; +// assert_eq!( +// tokenlock::initialize_tokenlock(ctx, max_release_delay, min_timelock_amount).is_ok(), +// true +// ); +// assert_eq!( +// accounts.tokenlock_account.max_release_delay, +// max_release_delay, +// ); +// assert_eq!( +// accounts.tokenlock_account.min_timelock_amount, +// min_timelock_amount, +// ); +// assert_eq!( +// accounts.tokenlock_account.mint_address, +// accounts.mint_address.key() +// ); +// assert_eq!( +// accounts.tokenlock_account.escrow_account, +// accounts.escrow_account.key() +// ); + +// let bumps = InitializeTokenLockBumps::default(); +// let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); +// let max_release_delay = 0; +// match_anchor_err( +// tokenlock::initialize_tokenlock(ctx, max_release_delay, min_timelock_amount).unwrap_err(), +// 6001, +// ); + +// let bumps = InitializeTokenLockBumps::default(); +// let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); +// let max_release_delay = 3600; +// let min_timelock_amount = 0; +// match_anchor_err( +// tokenlock::initialize_tokenlock(ctx, max_release_delay, min_timelock_amount).unwrap_err(), +// 6002, +// ); +// } + +// #[test] +// fn test_initialize_timelock() { +// let mut fixture = TestFixture::default(); +// let program_id = fixture.program_id; + +// let tokenlock_account_info = fixture.tokenlock_account.into_account_info(); +// let timelock_account_info = fixture.timelock_account.into_account_info(); +// let authority_wallet_role_info = fixture.authority_wallet_role.into_account_info(); +// let access_control_info = fixture.access_control.into_account_info(); +// let mut authority_info = fixture.authority.into_account_info(); +// let target_account_info = fixture.target_account.into_account_info(); +// let system_program_info = fixture.system_program.into_account_info(); +// let rent_info = fixture.rent.into_account_info(); +// let mut accounts = TestFixture::initialize_timelock( +// tokenlock_account_info, +// &timelock_account_info, +// &mut authority_info, +// &authority_wallet_role_info, +// &access_control_info, +// target_account_info, +// &system_program_info, +// &rent_info, +// ) +// .expect("Getting accounts error"); + +// let bumps = InitializeTimeLockBumps::default(); +// let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); +// assert_eq!(tokenlock::initialize_timelock(ctx).is_ok(), true); +// assert_eq!( +// accounts.timelock_account.target_account, +// accounts.target_account.key(), +// ); +// assert_eq!( +// accounts.timelock_account.tokenlock_account, +// accounts.tokenlock_account.key(), +// ); +// assert_eq!(accounts.timelock_account.cancelables.len(), 0); +// assert_eq!(accounts.timelock_account.timelocks.len(), 0); +// } + +// #[test] +// fn test_create_release_schedule() { +// let mut fixture = TestFixture::default(); +// let program_id = fixture.program_id; +// let tokenlock_account_info = fixture.tokenlock_account.into_account_info(); +// let mut authority_info = fixture.authority.into_account_info(); +// let authority_wallet_role_info = fixture.authority_wallet_role.into_account_info(); +// let access_control_info = fixture.access_control.into_account_info(); +// let mut accounts = TestFixture::create_release_schedule( +// tokenlock_account_info, +// &mut authority_info, +// &authority_wallet_role_info, +// &access_control_info, +// ) +// .expect("Getting accounts error"); + +// let release_count = 4; +// let delay_until_first_release_in_seconds = 0; +// let initial_release_portion_in_bips = 1000; +// let period_between_releases_in_seconds = 3600; + +// let bumps = ManagementTokenlockBumps::default(); +// let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); +// assert_eq!( +// tokenlock::create_release_schedule( +// ctx, +// UUID, +// release_count, +// delay_until_first_release_in_seconds, +// initial_release_portion_in_bips, +// period_between_releases_in_seconds, +// ) +// .is_ok(), +// true +// ); + +// let tokenlock_data: Account = +// Account::try_from_unchecked(accounts.tokenlock_account.as_ref()).unwrap(); +// assert_eq!(tokenlock_data.release_schedules.len(), 1); +// let result_release_schedule = tokenlock_data.release_schedules.first().unwrap(); +// assert_eq!(result_release_schedule.release_count, release_count); +// assert_eq!( +// result_release_schedule.delay_until_first_release_in_seconds, +// delay_until_first_release_in_seconds +// ); +// assert_eq!( +// result_release_schedule.initial_release_portion_in_bips, +// initial_release_portion_in_bips +// ); +// assert_eq!( +// result_release_schedule.period_between_releases_in_seconds, +// period_between_releases_in_seconds +// ); + +// let delay_until_first_release_in_seconds = 1000; +// let bumps = ManagementTokenlockBumps::default(); +// let mut accounts = accounts.clone(); +// let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); +// match_anchor_err( +// tokenlock::create_release_schedule( +// ctx, +// UUID, +// release_count, +// delay_until_first_release_in_seconds, +// initial_release_portion_in_bips, +// period_between_releases_in_seconds, +// ) +// .unwrap_err(), +// 6019, +// ); + +// let delay_until_first_release_in_seconds = 0; +// let release_count = 0; +// let bumps = ManagementTokenlockBumps::default(); +// let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); +// match_anchor_err( +// tokenlock::create_release_schedule( +// ctx, +// UUID, +// release_count, +// delay_until_first_release_in_seconds, +// initial_release_portion_in_bips, +// period_between_releases_in_seconds, +// ) +// .unwrap_err(), +// 6020, +// ); + +// let release_count = 2; +// let initial_release_portion_in_bips = 10001; +// let bumps = ManagementTokenlockBumps::default(); +// let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); +// match_anchor_err( +// tokenlock::create_release_schedule( +// ctx, +// UUID, +// release_count, +// delay_until_first_release_in_seconds, +// initial_release_portion_in_bips, +// period_between_releases_in_seconds, +// ) +// .unwrap_err(), +// 6021, +// ); + +// let initial_release_portion_in_bips = 1000; +// let period_between_releases_in_seconds = 0; +// let bumps = ManagementTokenlockBumps::default(); +// let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); +// match_anchor_err( +// tokenlock::create_release_schedule( +// ctx, +// UUID, +// release_count, +// delay_until_first_release_in_seconds, +// initial_release_portion_in_bips, +// period_between_releases_in_seconds, +// ) +// .unwrap_err(), +// 6022, +// ); + +// let initial_release_portion_in_bips = 1000; +// let release_count = 1; +// let bumps = ManagementTokenlockBumps::default(); +// let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); +// match_anchor_err( +// tokenlock::create_release_schedule( +// ctx, +// UUID, +// release_count, +// delay_until_first_release_in_seconds, +// initial_release_portion_in_bips, +// period_between_releases_in_seconds, +// ) +// .unwrap_err(), +// 6023, +// ); +// } + +// #[test] +// fn test_fund_release_schedule() { +// let mut fixture_create_release = TestFixture::default(); +// let program_id = fixture_create_release.program_id; +// let tokenlock_account_info = fixture_create_release.tokenlock_account.into_account_info(); +// let mut authority_info = fixture_create_release.authority.into_account_info(); +// let authority_wallet_role_info = fixture_create_release +// .authority_wallet_role +// .into_account_info(); +// let access_control_info = fixture_create_release.access_control.into_account_info(); +// let mut accounts_create_release = TestFixture::create_release_schedule( +// tokenlock_account_info, +// &mut authority_info, +// &authority_wallet_role_info, +// &access_control_info, +// ) +// .expect("Getting accounts error"); + +// let release_count = 4; +// let delay_until_first_release_in_seconds = 0; +// let initial_release_portion_in_bips = 1000; +// let period_between_releases_in_seconds = 3600; + +// let bumps = ManagementTokenlockBumps::default(); +// let ctx: Context = +// Context::new(&program_id, &mut accounts_create_release, &[], bumps); +// assert_eq!( +// tokenlock::create_release_schedule( +// ctx, +// UUID, +// release_count, +// delay_until_first_release_in_seconds, +// initial_release_portion_in_bips, +// period_between_releases_in_seconds, +// ) +// .is_ok(), +// true +// ); + +// let mut fixture = TestFixture::default(); +// let program_id = fixture.program_id; +// let tokenlock_account_info = fixture.tokenlock_account.into_account_info(); +// let escrow_account_info = fixture.escrow_account.into_account_info(); +// let timelock_account_info = fixture.timelock_account.into_account_info(); +// let mut authority_info = fixture.authority.into_account_info(); +// let authority_wallet_role_info = fixture.authority_wallet_role.into_account_info(); +// let mint_info = fixture.mint_address.into_account_info(); +// let from_info = fixture.from.into_account_info(); +// let to_info = fixture.to.into_account_info(); +// let token_program_info = fixture.token_program.into_account_info(); +// let mut accounts = TestFixture::fund_release_schedule( +// &escrow_account_info, +// &tokenlock_account_info, +// &timelock_account_info, +// &mut authority_info, +// &authority_wallet_role_info, +// &access_control_info, +// &mint_info, +// &from_info, +// to_info, +// &token_program_info, +// ) +// .expect("Getting accounts error"); +// accounts.tokenlock_account = accounts_create_release.tokenlock_account; + +// let amount = 10000; +// let commencement_timestamp = 0; +// let schedule_id = 0; +// let cancelar = Pubkey::new_unique(); +// let cancelable_by = vec![cancelar, Pubkey::new_unique()]; +// let bumps = FundReleaseScheduleBumps::default(); +// let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); +// assert_eq!( +// tokenlock::fund_release_schedule( +// ctx, +// UUID, +// amount, +// commencement_timestamp, +// schedule_id, +// cancelable_by.clone() +// ) +// .is_ok(), +// true +// ); + +// // BadCase: timelock already exists +// let bumps = FundReleaseScheduleBumps::default(); +// let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); +// match_anchor_err( +// tokenlock::fund_release_schedule( +// ctx, +// UUID, +// amount, +// commencement_timestamp, +// schedule_id, +// cancelable_by.clone(), +// ) +// .unwrap_err(), +// 6027, +// ); + +// // BadCase: Commencement time out of range +// let commencement_timestamp = utils::get_unix_timestamp() + 10; +// let bumps = FundReleaseScheduleBumps::default(); +// let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); +// match_anchor_err( +// tokenlock::fund_release_schedule( +// ctx, +// UUID, +// amount, +// commencement_timestamp, +// schedule_id, +// cancelable_by.clone(), +// ) +// .unwrap_err(), +// 6008, +// ); + +// // BadCase: Max 10 cancelableBy addressees +// let bumps = FundReleaseScheduleBumps::default(); +// let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); +// let cancelable_by = vec![Pubkey::new_unique(); Timelock::CANCELABLE_BY_COUNT_MAX as usize + 1]; +// match_anchor_err( +// tokenlock::fund_release_schedule( +// ctx, +// UUID, +// amount, +// commencement_timestamp, +// schedule_id, +// cancelable_by, +// ) +// .unwrap_err(), +// 6010, +// ); +// } + +// #[test] +// fn test_transfer() { +// let mut fixture_create_release = TestFixture::default(); +// let program_id = fixture_create_release.program_id; +// let tokenlock_account_info = fixture_create_release.tokenlock_account.into_account_info(); +// let mut authority_info = fixture_create_release.authority.into_account_info(); +// let authority_wallet_role_info = fixture_create_release +// .authority_wallet_role +// .into_account_info(); +// let access_control_info = fixture_create_release.access_control.into_account_info(); +// let mut accounts_create_release = TestFixture::create_release_schedule( +// tokenlock_account_info, +// &mut authority_info, +// &authority_wallet_role_info, +// &access_control_info, +// ) +// .expect("Getting accounts error"); + +// let release_count = 2; +// let delay_until_first_release_in_seconds = 0; +// let initial_release_portion_in_bips = 5000; +// let period_between_releases_in_seconds = 3600; + +// let bumps = ManagementTokenlockBumps::default(); +// let ctx: Context = +// Context::new(&program_id, &mut accounts_create_release, &[], bumps); +// assert_eq!( +// tokenlock::create_release_schedule( +// ctx, +// UUID, +// release_count, +// delay_until_first_release_in_seconds, +// initial_release_portion_in_bips, +// period_between_releases_in_seconds, +// ) +// .is_ok(), +// true +// ); + +// let mut fixture = TestFixture::default(); +// let total_amount = 1_000_000_000; +// let tokenlock_account_info = fixture.tokenlock_account.into_account_info(); +// let escrow_account_info = fixture.escrow_account.into_account_info(); +// let timelock_account_info = fixture.timelock_account.into_account_info(); +// let mut authority_info = fixture.authority.into_account_info(); +// let pda_info = fixture.pda_account.into_account_info(); +// let to_info = fixture.to.into_account_info(); +// let mint_info = fixture.mint_address.into_account_info(); +// let token_program_info = fixture.token_program.into_account_info(); +// let mut accounts = TestFixture::transfer( +// &escrow_account_info, +// &tokenlock_account_info, +// &timelock_account_info, +// pda_info, +// &mut authority_info, +// &to_info, +// &mint_info, +// &token_program_info, +// ) +// .expect("Getting accounts error"); +// accounts.tokenlock_account = accounts_create_release.tokenlock_account; +// accounts.timelock_account.timelocks.push(Timelock { +// schedule_id: 0, +// commencement_timestamp: 123123513, +// tokens_transferred: 0, +// total_amount: total_amount, +// cancelable_by_count: 0, +// cancelable_by: [0; 10], +// signer_hash: [0; 20], +// }); + +// let amount = 10000; +// let bumps = TransferFromBumps::default(); +// let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); +// assert_eq!(tokenlock::transfer(ctx, amount).is_ok(), true); + +// // BadCase: Amount bigger than unlocked +// let huge_amount = total_amount - amount + 1; +// let bumps = TransferFromBumps::default(); +// let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); + +// match_anchor_err(tokenlock::transfer(ctx, huge_amount).unwrap_err(), 6014); +// } + +// #[test] +// fn test_transfer_timelock() { +// let mut fixture_create_release = TestFixture::default(); +// let program_id = fixture_create_release.program_id; +// let tokenlock_account_info = fixture_create_release.tokenlock_account.into_account_info(); +// let mut authority_info = fixture_create_release.authority.into_account_info(); +// let authority_wallet_role_info = fixture_create_release +// .authority_wallet_role +// .into_account_info(); +// let access_control_info = fixture_create_release.access_control.into_account_info(); +// let mut accounts_create_release = TestFixture::create_release_schedule( +// tokenlock_account_info, +// &mut authority_info, +// &authority_wallet_role_info, +// &access_control_info, +// ) +// .expect("Getting accounts error"); + +// let release_count = 2; +// let delay_until_first_release_in_seconds = 0; +// let initial_release_portion_in_bips = 5000; +// let period_between_releases_in_seconds = 3600; + +// let bumps = ManagementTokenlockBumps::default(); +// let ctx: Context = +// Context::new(&program_id, &mut accounts_create_release, &[], bumps); +// assert_eq!( +// tokenlock::create_release_schedule( +// ctx, +// UUID, +// release_count, +// delay_until_first_release_in_seconds, +// initial_release_portion_in_bips, +// period_between_releases_in_seconds, +// ) +// .is_ok(), +// true +// ); + +// let mut fixture = TestFixture::default(); +// let program_id = fixture.program_id; +// let tokenlock_account_info = fixture.tokenlock_account.into_account_info(); +// let escrow_account_info = fixture.escrow_account.into_account_info(); +// let timelock_account_info = fixture.timelock_account.into_account_info(); +// let mut authority_info = fixture.authority.into_account_info(); +// let pda_info = fixture.pda_account.into_account_info(); +// let to_info = fixture.to.into_account_info(); +// let token_program_info = fixture.token_program.into_account_info(); +// let mint_info = fixture.mint_address.into_account_info(); +// let mut accounts = TestFixture::transfer_timelock( +// &escrow_account_info, +// &tokenlock_account_info, +// &timelock_account_info, +// pda_info, +// &mut authority_info, +// &to_info, +// &mint_info, +// &token_program_info, +// ) +// .expect("Getting accounts error"); +// let timelock_amount = 1_000_000_000; +// accounts.tokenlock_account = accounts_create_release.tokenlock_account; +// accounts.timelock_account.timelocks.push(Timelock { +// schedule_id: 0, +// commencement_timestamp: 123123513, +// tokens_transferred: 0, +// total_amount: timelock_amount, +// cancelable_by_count: 0, +// cancelable_by: [0; 10], +// signer_hash: [0; 20], +// }); + +// let amount = 10000; +// let timelock_id = 0; +// let bumps = TransferTimelockBumps::default(); +// let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); + +// assert_eq!( +// tokenlock::transfer_timelock(ctx, amount, timelock_id).is_ok(), +// true +// ); + +// // BadCase: Amount bigger than unlocked +// let huge_amount = timelock_amount - amount + 1; +// let timelock_id = 0; +// let bumps = TransferTimelockBumps::default(); +// let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); + +// match_anchor_err( +// tokenlock::transfer_timelock(ctx, huge_amount, timelock_id).unwrap_err(), +// 6014, +// ); +// } + +// #[test] +// fn test_cancel_timelock() { +// let mut fixture_create_release = TestFixture::default(); +// let program_id = fixture_create_release.program_id; +// let tokenlock_account_info = fixture_create_release.tokenlock_account.into_account_info(); +// let mut authority_info = fixture_create_release.authority.into_account_info(); +// let authority_wallet_role_info = fixture_create_release +// .authority_wallet_role +// .into_account_info(); +// let access_control_info = fixture_create_release.access_control.into_account_info(); +// let mut accounts_create_release = TestFixture::create_release_schedule( +// tokenlock_account_info, +// &mut authority_info, +// &authority_wallet_role_info, +// &access_control_info, +// ) +// .expect("Getting accounts error"); + +// let release_count = 2; +// let delay_until_first_release_in_seconds = 0; +// let initial_release_portion_in_bips = 5000; +// let period_between_releases_in_seconds = 3600; + +// let bumps = ManagementTokenlockBumps::default(); +// let ctx: Context = +// Context::new(&program_id, &mut accounts_create_release, &[], bumps); +// assert_eq!( +// tokenlock::create_release_schedule( +// ctx, +// UUID, +// release_count, +// delay_until_first_release_in_seconds, +// initial_release_portion_in_bips, +// period_between_releases_in_seconds, +// ) +// .is_ok(), +// true +// ); + +// let mut fixture = TestFixture::default(); +// let program_id = fixture.program_id; +// let tokenlock_account_info = fixture.tokenlock_account.into_account_info(); +// let escrow_account_info = fixture.escrow_account.into_account_info(); +// let timelock_account_info = fixture.timelock_account.into_account_info(); +// let from_info = fixture.from.into_account_info(); +// let to_info = fixture.to.into_account_info(); +// let token_program_info = fixture.token_program.into_account_info(); +// let mut authority_info = fixture.authority.into_account_info(); +// let authority_wallet_role_info = fixture.authority_wallet_role.into_account_info(); +// let mint_info = fixture.mint_address.into_account_info(); +// let mut accounts_fund_release = TestFixture::fund_release_schedule( +// &escrow_account_info, +// &tokenlock_account_info, +// &timelock_account_info, +// &mut authority_info, +// &authority_wallet_role_info, +// &access_control_info, +// &mint_info, +// &from_info, +// to_info, +// &token_program_info, +// ) +// .expect("Getting accounts error"); +// accounts_fund_release.tokenlock_account = accounts_create_release.tokenlock_account; + +// let amount = 10000; +// let commencement_timestamp = 0; +// let schedule_id = 0; +// let cancelar = Pubkey::new_unique(); +// let cancelable_by = vec![cancelar, Pubkey::new_unique()]; +// let bumps = FundReleaseScheduleBumps::default(); +// let ctx: Context = +// Context::new(&program_id, &mut accounts_fund_release, &[], bumps); +// assert_eq!( +// tokenlock::fund_release_schedule( +// ctx, +// UUID, +// amount, +// commencement_timestamp, +// schedule_id, +// cancelable_by.clone() +// ) +// .is_ok(), +// true +// ); + +// // BadCase: Invalid timelock id +// let timelock_id = 0; +// let mut fixture = TestFixture::default(); +// let tokenlock_account_info = fixture.tokenlock_account.into_account_info(); +// let escrow_account_info = fixture.escrow_account.into_account_info(); +// let timelock_account_info = fixture.timelock_account.into_account_info(); +// let mut authority_info = fixture.authority.into_account_info(); +// let pda_info = fixture.pda_account.into_account_info(); +// let target_info = fixture.target.into_account_info(); +// let reclaimer_info = fixture.reclaimer.into_account_info(); +// let target_assoc_info = fixture.target_assoc.into_account_info(); +// let token_program_info = fixture.token_program.into_account_info(); +// let mint_info = fixture.mint_address.into_account_info(); +// let mut accounts = TestFixture::cancel_timelock( +// &escrow_account_info, +// &tokenlock_account_info, +// &timelock_account_info, +// target_info, +// pda_info, +// &mut authority_info, +// &reclaimer_info, +// &target_assoc_info, +// &mint_info, +// &token_program_info, +// ) +// .expect("Getting accounts error"); +// let bumps = CancelTimelockBumps::default(); +// let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); + +// match_anchor_err( +// tokenlock::cancel_timelock(ctx, timelock_id).unwrap_err(), +// 6011, +// ); + +// // BadCase: You are not allowed to cancel this timelock +// accounts.timelock_account.timelocks.push(Timelock { +// schedule_id: 0, +// commencement_timestamp: utils::get_unix_timestamp(), +// tokens_transferred: 1_000_000_000, +// total_amount: 1_000_000_000, +// cancelable_by_count: 1, +// cancelable_by: [0; 10], +// signer_hash: [0; 20], +// }); +// let bumps = CancelTimelockBumps::default(); +// let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); + +// match_anchor_err( +// tokenlock::cancel_timelock(ctx, timelock_id).unwrap_err(), +// 6013, +// ); + +// // BadCase: Timelock has no value left +// let mut authority_info = accounts.authority.to_account_info(); +// authority_info.is_signer = true; +// authority_info.key = &cancelar; +// accounts.authority = Signer::try_from(&authority_info).unwrap(); +// // accounts.authority.key = &cancelar; +// accounts.timelock_account.cancelables.push(cancelar); +// let bumps = CancelTimelockBumps::default(); +// let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); + +// match_anchor_err( +// tokenlock::cancel_timelock(ctx, timelock_id).unwrap_err(), +// 6012, +// ); + +// accounts.tokenlock_account = accounts_fund_release.tokenlock_account; +// accounts.timelock_account.timelocks.push(Timelock { +// schedule_id: 0, +// commencement_timestamp: utils::get_unix_timestamp(), +// tokens_transferred: 0, +// total_amount: 1_000_000_000, +// cancelable_by_count: 1, +// cancelable_by: [0; 10], +// signer_hash: [0; 20], +// }); + +// let timelock_id = 1; +// let bumps = CancelTimelockBumps::default(); +// let ctx: Context = Context::new(&program_id, &mut accounts, &[], bumps); + +// assert_eq!(tokenlock::cancel_timelock(ctx, timelock_id).is_ok(), true); +// }