mine test

This commit is contained in:
Hardhat Chad
2024-02-16 18:38:20 +00:00
parent 3934f81b31
commit 1aaee211c7
5 changed files with 37 additions and 67 deletions

View File

@@ -93,12 +93,6 @@ async fn test_initialize() {
let bus = Bus::try_from_bytes(&bus_account.data).unwrap();
assert_eq!(bus.id as u8, i as u8);
assert_eq!(bus.rewards, 0);
println!(
"Bus {:?} {:?} {:?}",
bus_pdas[i].0,
bus_account,
bs64::encode(&bus_account.data)
);
}
// Test treasury state
@@ -111,12 +105,6 @@ async fn test_initialize() {
assert_eq!(treasury.epoch_start_at as u8, 0);
assert_eq!(treasury.reward_rate, INITIAL_REWARD_RATE);
assert_eq!(treasury.total_claimed_rewards as u8, 0);
println!(
"Treasury {:?} {:?} {:?}",
treasury_pda.0,
treasury_account,
bs64::encode(&treasury_account.data)
);
// Test mint state
let mint_account = banks.get_account(mint_pda.0).await.unwrap().unwrap();
@@ -127,12 +115,6 @@ async fn test_initialize() {
assert_eq!(mint.decimals, ore::TOKEN_DECIMALS);
assert_eq!(mint.is_initialized, true);
assert_eq!(mint.freeze_authority, COption::None);
println!(
"Mint {:?} {:?} {:?}",
mint_pda.0,
mint_account,
bs64::encode(&mint_account.data)
);
// Test treasury token state
let treasury_tokens_account = banks
@@ -150,14 +132,6 @@ async fn test_initialize() {
assert_eq!(treasury_tokens.is_native, COption::None);
assert_eq!(treasury_tokens.delegated_amount, 0);
assert_eq!(treasury_tokens.close_authority, COption::None);
println!(
"Treasury tokens {:?} {:?} {:?}",
treasury_tokens_address,
treasury_tokens_account,
bs64::encode(&treasury_tokens_account.data)
);
// assert!(false);
}
async fn setup_program_test_env() -> (BanksClient, Keypair, Hash) {

View File

@@ -1,4 +1,4 @@
use std::str::FromStr;
use std::{mem::size_of, str::FromStr};
use ore::{
state::{Bus, Proof, Treasury},
@@ -13,6 +13,7 @@ use solana_program::{
program_option::COption,
program_pack::Pack,
pubkey::Pubkey,
slot_hashes::SlotHash,
sysvar,
};
use solana_program_test::{processor, BanksClient, ProgramTest};
@@ -27,12 +28,10 @@ async fn test_mine() {
// Setup
let (mut banks, payer, hash) = setup_program_test_env().await;
// Build register ix
// Submit register tx
let proof_pda = Pubkey::find_program_address(&[PROOF, payer.pubkey().as_ref()], &ore::id());
let ix_0 = ore::instruction::register(payer.pubkey());
// Submit tx
let tx = Transaction::new_signed_with_payer(&[ix_0], Some(&payer.pubkey()), &[&payer], hash);
let ix = ore::instruction::register(payer.pubkey());
let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], hash);
let res = banks.process_transaction(tx).await;
assert!(res.is_ok());
@@ -40,6 +39,11 @@ async fn test_mine() {
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.hash, hashv(&[payer.pubkey().as_ref()]).into());
assert_eq!(proof.total_hashes, 0);
assert_eq!(proof.total_rewards, 0);
// Assert proof state
let treasury_pda = Pubkey::find_program_address(&[TREASURY], &ore::id());
@@ -54,13 +58,29 @@ async fn test_mine() {
);
// Submit mine tx
let ix_1 = ore::instruction::mine(payer.pubkey(), BUS_ADDRESSES[0], next_hash.into(), nonce);
let tx = Transaction::new_signed_with_payer(&[ix_1], Some(&payer.pubkey()), &[&payer], hash);
let ix = ore::instruction::mine(payer.pubkey(), BUS_ADDRESSES[0], next_hash.into(), nonce);
let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], hash);
let res = banks.process_transaction(tx).await;
assert!(res.is_ok());
// TODO Assert proof state
// TODO Assert bus state
// 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::<SlotHash>()];
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);
}
fn find_next_hash(hash: KeccakHash, difficulty: KeccakHash, signer: Pubkey) -> (KeccakHash, u64) {

View File

@@ -49,12 +49,6 @@ async fn test_reset() {
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();
println!(
"Bus {:?} {:?} {:?}",
bus_pdas[i].0,
bus_account,
bs64::encode(&bus_account.data)
);
assert_eq!(bus.id as u8, i as u8);
assert_eq!(bus.rewards, BUS_EPOCH_REWARDS);
}
@@ -72,12 +66,6 @@ async fn test_reset() {
assert_eq!(treasury.epoch_start_at as u8, 100);
assert_eq!(treasury.reward_rate, INITIAL_REWARD_RATE.saturating_div(2));
assert_eq!(treasury.total_claimed_rewards as u8, 0);
println!(
"Treasury {:?} {:?} {:?}",
treasury_pda.0,
treasury_account,
bs64::encode(&treasury_account.data)
);
// Test mint state
let mint_account = banks.get_account(mint_pda.0).await.unwrap().unwrap();
@@ -88,12 +76,6 @@ async fn test_reset() {
assert_eq!(mint.decimals, ore::TOKEN_DECIMALS);
assert_eq!(mint.is_initialized, true);
assert_eq!(mint.freeze_authority, COption::None);
println!(
"Mint {:?} {:?} {:?}",
mint_pda.0,
mint_account,
bs64::encode(&mint_account.data)
);
// Test treasury token state
let treasury_tokens_account = banks
@@ -111,14 +93,6 @@ async fn test_reset() {
assert_eq!(treasury_tokens.is_native, COption::None);
assert_eq!(treasury_tokens.delegated_amount, 0);
assert_eq!(treasury_tokens.close_authority, COption::None);
println!(
"Treasury tokens {:?} {:?} {:?}",
treasury_tokens_address,
treasury_tokens_account,
bs64::encode(&treasury_tokens_account.data)
);
// assert!(false);
}
async fn setup_program_test_env() -> (BanksClient, Keypair, Hash) {