mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-23 15:10:37 +00:00
admin tests
This commit is contained in:
@@ -1,17 +1,9 @@
|
||||
use ore::{
|
||||
instruction::{InitializeArgs, OreInstruction},
|
||||
state::{Bus, Treasury},
|
||||
utils::AccountDeserialize,
|
||||
BUS, BUS_COUNT, INITIAL_DIFFICULTY, INITIAL_REWARD_RATE, MINT, TREASURY,
|
||||
};
|
||||
use solana_program::{
|
||||
hash::Hash,
|
||||
instruction::{AccountMeta, Instruction},
|
||||
program_option::COption,
|
||||
program_pack::Pack,
|
||||
pubkey::Pubkey,
|
||||
system_program, sysvar,
|
||||
BUS_ADDRESSES, BUS_COUNT, INITIAL_DIFFICULTY, INITIAL_REWARD_RATE, MINT_ADDRESS, TREASURY,
|
||||
};
|
||||
use solana_program::{hash::Hash, program_option::COption, program_pack::Pack, pubkey::Pubkey};
|
||||
use solana_program_test::{processor, BanksClient, ProgramTest};
|
||||
use solana_sdk::{
|
||||
signature::{Keypair, Signer},
|
||||
@@ -22,73 +14,22 @@ use spl_token::state::{AccountState, Mint};
|
||||
#[tokio::test]
|
||||
async fn test_initialize() {
|
||||
// Setup
|
||||
let (mut banks, payer, hash) = setup_program_test_env().await;
|
||||
let (mut banks, payer, blockhash) = setup_program_test_env().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_pda = Pubkey::find_program_address(&[TREASURY], &ore::id());
|
||||
let treasury_tokens_address =
|
||||
spl_associated_token_account::get_associated_token_address(&treasury_pda.0, &mint_pda.0);
|
||||
|
||||
// Build ix
|
||||
let ix = Instruction {
|
||||
program_id: ore::ID,
|
||||
accounts: vec![
|
||||
AccountMeta::new(payer.pubkey(), 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_pda.0, false),
|
||||
AccountMeta::new(treasury_pda.0, false),
|
||||
AccountMeta::new(treasury_tokens_address, false),
|
||||
AccountMeta::new_readonly(system_program::id(), false),
|
||||
AccountMeta::new_readonly(spl_token::id(), false),
|
||||
AccountMeta::new_readonly(spl_associated_token_account::id(), false),
|
||||
AccountMeta::new_readonly(sysvar::rent::id(), false),
|
||||
],
|
||||
data: [
|
||||
OreInstruction::Initialize.to_vec(),
|
||||
InitializeArgs {
|
||||
bus_0_bump: bus_pdas[0].1,
|
||||
bus_1_bump: bus_pdas[1].1,
|
||||
bus_2_bump: bus_pdas[2].1,
|
||||
bus_3_bump: bus_pdas[3].1,
|
||||
bus_4_bump: bus_pdas[4].1,
|
||||
bus_5_bump: bus_pdas[5].1,
|
||||
bus_6_bump: bus_pdas[6].1,
|
||||
bus_7_bump: bus_pdas[7].1,
|
||||
mint_bump: mint_pda.1,
|
||||
treasury_bump: treasury_pda.1,
|
||||
}
|
||||
.to_bytes()
|
||||
.to_vec(),
|
||||
]
|
||||
.concat(),
|
||||
};
|
||||
spl_associated_token_account::get_associated_token_address(&treasury_pda.0, &MINT_ADDRESS);
|
||||
|
||||
// Submit tx
|
||||
let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], hash);
|
||||
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_pdas[i].0).await.unwrap().unwrap();
|
||||
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);
|
||||
@@ -107,7 +48,7 @@ async fn test_initialize() {
|
||||
assert_eq!(treasury.total_claimed_rewards as u8, 0);
|
||||
|
||||
// Test mint state
|
||||
let mint_account = banks.get_account(mint_pda.0).await.unwrap().unwrap();
|
||||
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));
|
||||
@@ -124,7 +65,7 @@ async fn test_initialize() {
|
||||
.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_pda.0);
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user