discriminator

This commit is contained in:
Hardhat Chad
2024-02-15 23:43:33 +00:00
parent 086a705a39
commit 754b18e21a
12 changed files with 215 additions and 176 deletions

28
Cargo.lock generated
View File

@@ -418,9 +418,9 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
[[package]] [[package]]
name = "base64" name = "base64"
version = "0.21.5" version = "0.21.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567"
[[package]] [[package]]
name = "base64ct" name = "base64ct"
@@ -2851,7 +2851,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37b1ae8d9ac08420c66222fb9096fc5de435c3c48542bc5336c51892cffafb41" checksum = "37b1ae8d9ac08420c66222fb9096fc5de435c3c48542bc5336c51892cffafb41"
dependencies = [ dependencies = [
"async-compression", "async-compression",
"base64 0.21.5", "base64 0.21.7",
"bytes", "bytes",
"encoding_rs", "encoding_rs",
"futures-core", "futures-core",
@@ -3009,7 +3009,7 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c"
dependencies = [ dependencies = [
"base64 0.21.5", "base64 0.21.7",
] ]
[[package]] [[package]]
@@ -3372,7 +3372,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21ed570fba6f909f69c888b48b39c7e61b454e3594e448d0dad9d973f27f5668" checksum = "21ed570fba6f909f69c888b48b39c7e61b454e3594e448d0dad9d973f27f5668"
dependencies = [ dependencies = [
"Inflector", "Inflector",
"base64 0.21.5", "base64 0.21.7",
"bincode", "bincode",
"bs58 0.4.0", "bs58 0.4.0",
"bv", "bv",
@@ -3827,7 +3827,7 @@ dependencies = [
"ark-ec", "ark-ec",
"ark-ff", "ark-ff",
"ark-serialize", "ark-serialize",
"base64 0.21.5", "base64 0.21.7",
"bincode", "bincode",
"bitflags 2.4.1", "bitflags 2.4.1",
"blake3", "blake3",
@@ -3877,7 +3877,7 @@ version = "1.17.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d5dbb56d36cc15b4cf5a71c0ce6262a263212f7a312b0dbc41b226654329c37" checksum = "9d5dbb56d36cc15b4cf5a71c0ce6262a263212f7a312b0dbc41b226654329c37"
dependencies = [ dependencies = [
"base64 0.21.5", "base64 0.21.7",
"bincode", "bincode",
"eager", "eager",
"enum-iterator", "enum-iterator",
@@ -3907,7 +3907,7 @@ checksum = "61bbf119c35d4393702953e586b72053c3b80a92c781931cd412d53d2036475e"
dependencies = [ dependencies = [
"assert_matches", "assert_matches",
"async-trait", "async-trait",
"base64 0.21.5", "base64 0.21.7",
"bincode", "bincode",
"chrono-humanize", "chrono-humanize",
"crossbeam-channel", "crossbeam-channel",
@@ -4017,7 +4017,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91503edfdb2ba9c5e0127048e7795f22e050cf2bcee1259361af113d533b4b26" checksum = "91503edfdb2ba9c5e0127048e7795f22e050cf2bcee1259361af113d533b4b26"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"base64 0.21.5", "base64 0.21.7",
"bincode", "bincode",
"bs58 0.4.0", "bs58 0.4.0",
"indicatif", "indicatif",
@@ -4042,7 +4042,7 @@ version = "1.17.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "131662e5eea4fa5fc88b01f07d9e430315c0976be848ba3994244249c5fb033a" checksum = "131662e5eea4fa5fc88b01f07d9e430315c0976be848ba3994244249c5fb033a"
dependencies = [ dependencies = [
"base64 0.21.5", "base64 0.21.7",
"bs58 0.4.0", "bs58 0.4.0",
"jsonrpc-core", "jsonrpc-core",
"reqwest", "reqwest",
@@ -4078,7 +4078,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf63159e669f29065c9ff280c09f5b96139b00258502ee401338150fce78fed7" checksum = "cf63159e669f29065c9ff280c09f5b96139b00258502ee401338150fce78fed7"
dependencies = [ dependencies = [
"arrayref", "arrayref",
"base64 0.21.5", "base64 0.21.7",
"bincode", "bincode",
"blake3", "blake3",
"bv", "bv",
@@ -4155,7 +4155,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb34583922c5e79004ad8d8d69f333d274d21b614f0e1a575f325fc29a104ec2" checksum = "cb34583922c5e79004ad8d8d69f333d274d21b614f0e1a575f325fc29a104ec2"
dependencies = [ dependencies = [
"assert_matches", "assert_matches",
"base64 0.21.5", "base64 0.21.7",
"bincode", "bincode",
"bitflags 2.4.1", "bitflags 2.4.1",
"borsh 0.10.3", "borsh 0.10.3",
@@ -4344,7 +4344,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c180013e406418d593ce7b51da7007a638ace18261de14901b090e53a1d7025" checksum = "4c180013e406418d593ce7b51da7007a638ace18261de14901b090e53a1d7025"
dependencies = [ dependencies = [
"Inflector", "Inflector",
"base64 0.21.5", "base64 0.21.7",
"bincode", "bincode",
"borsh 0.10.3", "borsh 0.10.3",
"bs58 0.4.0", "bs58 0.4.0",
@@ -4455,7 +4455,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03d932d7b13a223a6c1068d7061df7e9d2de14bfc0a874350eef19d59086b04a" checksum = "03d932d7b13a223a6c1068d7061df7e9d2de14bfc0a874350eef19d59086b04a"
dependencies = [ dependencies = [
"aes-gcm-siv", "aes-gcm-siv",
"base64 0.21.5", "base64 0.21.7",
"bincode", "bincode",
"bytemuck", "bytemuck",
"byteorder", "byteorder",

View File

@@ -7,21 +7,21 @@ pub const START_AT: i64 = 0;
// SHA2 const stable // SHA2 const stable
/// Bus pubkeys /// Bus pubkeys
pub const BUS_ADDRESSES: [Pubkey; BUS_COUNT] = [ pub const BUS_ADDRESSES: [Pubkey; BUS_COUNT] = [
pubkey!("2uwqyH2gKqstgAFCSniirx73X4iQek5ETc2vVJKUiNMg"), pubkey!("E2EJ9xxK78b5XJu9cBnYf6fDbJuLqXuLN5fhaUtEuPPf"),
pubkey!("FRMC6jVczm1cRaEs5EhDsfw7X8vsmSDpf3bJWVkawngu"), pubkey!("4J3EHs3tMuW46iNAQEEkZESYTeaPcRxYarH2pheRM9ET"),
pubkey!("9nWyycs4GHjnLujPR2sbA1A8K8CkiLc5VzxWUD4hg2uM"), pubkey!("6CNKKLPgC7pouftqXP43yaCBssmDRXD7ww7jGxNLgz6n"),
pubkey!("Kt7kqD3MyvxLbj4ek9urXUxkDoxaMuQn82K2VdYD1jM"), pubkey!("94vZ1ErDFmUJqQkMBLNQQaczSU981g3U884WXgns1rxQ"),
pubkey!("8r9mXYnFQXhwrNfvatGUTxbbNSqxScuCwp4sBTSxDVTJ"), pubkey!("6srtSHdy3GncfFPFyoa6gw3iY2mzp6aMS3naje2wLsd"),
pubkey!("D9cEH32k8p9uWc4w5RrStK9rWssU8NuX1Dg5YaUim4wL"), pubkey!("4w2BYLwDu1EV3HiZnWsdNYfEwLwkkNZZbWyarSe2AnQ5"),
pubkey!("H1RKMYADPzd4C1j1RZu51NvRSVktoTYEJyeVy98Kmdyu"), pubkey!("CtLrZCzr1BPDB75LTh381z9NtyTYzKEnupYUt37L8Jvu"),
pubkey!("3XbdZNbBjjp8qnDJjv1RxaKisyfx6ahznYkSigs6dayy"), pubkey!("EaACXDgdd6RKw4Wr4t2o9qFodFTH5m8cbuW3G4xmyUMw"),
]; ];
/// The mint address of the ORE token. /// The mint address of the ORE token.
pub const MINT_ADDRESS: Pubkey = pubkey!("DY4JVebraRXg9BGt4MRU4mvqHGDzmi2Ay1HGjDU5YeNf"); pub const MINT_ADDRESS: Pubkey = pubkey!("3jXYL3mCgf3Dh69NpG4adNX3jogjmFbz3RoqiuBmkrYN");
/// Treasury address /// Treasury address
pub const TREASURY_ADDRESS: Pubkey = pubkey!("67PLJej6iZm915WbEu6NLeZtRZtnHc5nSVQvkHRZyPiC"); pub const TREASURY_ADDRESS: Pubkey = pubkey!("2kdcgA7hmKbGvKHZpLFJD9rgSD1Bgggc8UUeJWGMWSRo");
/// The initial reward rate to payout in the first epoch. /// The initial reward rate to payout in the first epoch.
pub const INITIAL_REWARD_RATE: u64 = 10u64.pow(3u32); pub const INITIAL_REWARD_RATE: u64 = 10u64.pow(3u32);

View File

@@ -17,7 +17,7 @@ use solana_program::{
// TODO Test admin and difficulty adjustment functions // TODO Test admin and difficulty adjustment functions
// TODO Increase decimals? // TODO Increase decimals?
declare_id!("CeJShZEAzBLwtcLQvbZc7UT38e4nUTn63Za5UFyYYDTS"); declare_id!("ore2mSzJwAZhxLyCLbNEnFvYq9U8jvCMvUBrVvbmqDF");
#[cfg(not(feature = "no-entrypoint"))] #[cfg(not(feature = "no-entrypoint"))]
solana_program::entrypoint!(process_instruction); solana_program::entrypoint!(process_instruction);
@@ -28,12 +28,15 @@ pub fn process_instruction(
accounts: &[AccountInfo], accounts: &[AccountInfo],
data: &[u8], data: &[u8],
) -> ProgramResult { ) -> ProgramResult {
if program_id.ne(&crate::id()) {
return Err(ProgramError::IncorrectProgramId);
}
let (tag, data) = data let (tag, data) = data
.split_first() .split_first()
.ok_or(ProgramError::InvalidInstructionData)?; .ok_or(ProgramError::InvalidInstructionData)?;
let ix = OreInstruction::try_from(*tag).or(Err(ProgramError::InvalidInstructionData))?; match OreInstruction::try_from(*tag).or(Err(ProgramError::InvalidInstructionData))? {
match ix {
OreInstruction::Reset => process_reset(program_id, accounts, data)?, OreInstruction::Reset => process_reset(program_id, accounts, data)?,
OreInstruction::Register => process_register(program_id, accounts, data)?, OreInstruction::Register => process_register(program_id, accounts, data)?,
OreInstruction::Mine => process_mine(program_id, accounts, data)?, OreInstruction::Mine => process_mine(program_id, accounts, data)?,

View File

@@ -7,7 +7,7 @@ use spl_token::state::Mint;
use crate::{ use crate::{
state::{Bus, Proof}, state::{Bus, Proof},
utils::AccountDeserialize, utils::AccountDeserialize,
BUS_COUNT, MINT_ADDRESS, TREASURY_ADDRESS, BUS_ADDRESSES, BUS_COUNT, MINT_ADDRESS, TREASURY_ADDRESS,
}; };
pub fn load_signer<'a, 'info>(info: &'a AccountInfo<'info>) -> Result<(), ProgramError> { pub fn load_signer<'a, 'info>(info: &'a AccountInfo<'info>) -> Result<(), ProgramError> {
@@ -33,10 +33,14 @@ pub fn load_bus<'a, 'info>(
let bus_data = info.data.borrow(); let bus_data = info.data.borrow();
let bus = Bus::try_from_bytes(&bus_data)?; let bus = Bus::try_from_bytes(&bus_data)?;
if !(0..BUS_COUNT).contains(&(bus.id as usize)) { if bus.id.ge(&(BUS_COUNT as u64)) {
return Err(ProgramError::InvalidAccountData); return Err(ProgramError::InvalidAccountData);
} }
if info.key.ne(&BUS_ADDRESSES[bus.id as usize]) {
return Err(ProgramError::InvalidSeeds);
}
if is_writable && !info.is_writable { if is_writable && !info.is_writable {
return Err(ProgramError::InvalidAccountData); return Err(ProgramError::InvalidAccountData);
} }

View File

@@ -83,8 +83,8 @@ pub fn process_initialize<'a, 'info>(
let mut bus_data = bus_infos[i].try_borrow_mut_data()?; let mut bus_data = bus_infos[i].try_borrow_mut_data()?;
bus_data[0] = Bus::discriminator() as u8; bus_data[0] = Bus::discriminator() as u8;
let mut bus = Bus::try_from_bytes_mut(&mut bus_data)?; let mut bus = Bus::try_from_bytes_mut(&mut bus_data)?;
bus.bump = bus_bumps[i] as u32; // bus.bump = bus_bumps[i] as u32;
bus.id = i as u32; bus.id = i as u64;
bus.available_rewards = 0; bus.available_rewards = 0;
} }

View File

@@ -42,7 +42,7 @@ pub fn process_register<'a, 'info>(
let mut proof_data = proof_info.data.borrow_mut(); let mut proof_data = proof_info.data.borrow_mut();
proof_data[0] = Proof::discriminator() as u8; proof_data[0] = Proof::discriminator() as u8;
let mut proof = Proof::try_from_bytes_mut(&mut proof_data)?; let mut proof = Proof::try_from_bytes_mut(&mut proof_data)?;
proof.bump = args.bump as u64; // proof.bump = args.bump as u64;
proof.authority = *signer.key; proof.authority = *signer.key;
proof.claimable_rewards = 0; proof.claimable_rewards = 0;
proof.hash = hashv(&[&signer.key.to_bytes()]).into(); proof.hash = hashv(&[&signer.key.to_bytes()]).into();

View File

@@ -39,7 +39,7 @@ pub fn process_reset<'a, 'info>(
true, true,
)?; )?;
load_sysvar(token_program, spl_token::id())?; load_sysvar(token_program, spl_token::id())?;
let busses: [&AccountInfo; 8] = [ let busses: [&AccountInfo; BUS_COUNT] = [
bus_0_info, bus_1_info, bus_2_info, bus_3_info, bus_4_info, bus_5_info, bus_6_info, bus_0_info, bus_1_info, bus_2_info, bus_3_info, bus_4_info, bus_5_info, bus_6_info,
bus_7_info, bus_7_info,
]; ];

View File

@@ -8,11 +8,8 @@ use crate::{
#[repr(C)] #[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)] #[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct Bus { pub struct Bus {
/// The bump of the bus account PDA.
pub bump: u32,
/// The ID of the bus account. /// The ID of the bus account.
pub id: u32, pub id: u64,
/// The quantity of rewards this bus can issue in the current epoch epoch. /// The quantity of rewards this bus can issue in the current epoch epoch.
pub available_rewards: u64, pub available_rewards: u64,

View File

@@ -10,9 +10,6 @@ use crate::{
#[repr(C)] #[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)] #[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct Proof { pub struct Proof {
/// The bump of the proof account PDA.
pub bump: u64,
/// The account (i.e. miner) authorized to use this proof. /// The account (i.e. miner) authorized to use this proof.
pub authority: Pubkey, pub authority: Pubkey,

View File

@@ -91,7 +91,7 @@ async fn test_initialize() {
let bus_account = banks.get_account(bus_pdas[i].0).await.unwrap().unwrap(); let bus_account = banks.get_account(bus_pdas[i].0).await.unwrap().unwrap();
assert_eq!(bus_account.owner, ore::id()); assert_eq!(bus_account.owner, ore::id());
let bus = Bus::try_from_bytes(&bus_account.data).unwrap(); let bus = Bus::try_from_bytes(&bus_account.data).unwrap();
assert_eq!(bus.bump as u8, bus_pdas[i].1); // assert_eq!(bus.bump as u8, bus_pdas[i].1);
assert_eq!(bus.id as u8, i as u8); assert_eq!(bus.id as u8, i as u8);
assert_eq!(bus.available_rewards, 0); assert_eq!(bus.available_rewards, 0);
println!( println!(
@@ -128,6 +128,12 @@ async fn test_initialize() {
assert_eq!(mint.decimals, ore::TOKEN_DECIMALS); assert_eq!(mint.decimals, ore::TOKEN_DECIMALS);
assert_eq!(mint.is_initialized, true); assert_eq!(mint.is_initialized, true);
assert_eq!(mint.freeze_authority, COption::None); assert_eq!(mint.freeze_authority, COption::None);
println!(
"Mint {:?} {:?} {:?}",
mint_pda.0,
mint_account,
bs64::encode(&mint_account.data)
);
// Test treasury token state // Test treasury token state
let treasury_tokens_account = banks let treasury_tokens_account = banks
@@ -145,6 +151,12 @@ async fn test_initialize() {
assert_eq!(treasury_tokens.is_native, COption::None); assert_eq!(treasury_tokens.is_native, COption::None);
assert_eq!(treasury_tokens.delegated_amount, 0); assert_eq!(treasury_tokens.delegated_amount, 0);
assert_eq!(treasury_tokens.close_authority, COption::None); 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); // assert!(false);
} }

View File

@@ -1,14 +1,17 @@
use std::str::FromStr; use std::str::FromStr;
use ore::{ use ore::{
state::{Proof, Treasury}, state::{Bus, Proof, Treasury},
utils::AccountDeserialize, utils::{AccountDeserialize, Discriminator},
BUS, PROOF, TREASURY, BUS_ADDRESSES, BUS_COUNT, INITIAL_REWARD_RATE, MINT_ADDRESS, PROOF, TOKEN_DECIMALS, TREASURY,
TREASURY_ADDRESS,
}; };
use solana_program::{ use solana_program::{
clock::Clock, clock::Clock,
epoch_schedule::DEFAULT_SLOTS_PER_EPOCH, epoch_schedule::DEFAULT_SLOTS_PER_EPOCH,
keccak::{hashv, Hash as KeccakHash}, keccak::{hashv, Hash as KeccakHash},
program_option::COption,
program_pack::Pack,
pubkey::Pubkey, pubkey::Pubkey,
sysvar, sysvar,
}; };
@@ -17,6 +20,7 @@ use solana_sdk::{
signature::{Keypair, Signer}, signature::{Keypair, Signer},
transaction::Transaction, transaction::Transaction,
}; };
use spl_token::state::{AccountState, Mint};
#[tokio::test] #[tokio::test]
async fn test_mine() { async fn test_mine() {
@@ -49,11 +53,8 @@ async fn test_mine() {
payer.pubkey(), payer.pubkey(),
); );
// Build mine ix // Submit mine tx
let bus_pda = Pubkey::find_program_address(&[BUS, &[0]], &ore::id()); let ix_1 = ore::instruction::mine(payer.pubkey(), BUS_ADDRESSES[0], next_hash.into(), nonce);
let ix_1 = ore::instruction::mine(payer.pubkey(), bus_pda.0, next_hash.into(), nonce);
// Submit tx
let tx = Transaction::new_signed_with_payer(&[ix_1], Some(&payer.pubkey()), &[&payer], hash); let tx = Transaction::new_signed_with_payer(&[ix_1], Some(&payer.pubkey()), &[&payer], hash);
let res = banks.process_transaction(tx).await; let res = banks.process_transaction(tx).await;
assert!(res.is_ok()); assert!(res.is_ok());
@@ -86,77 +87,90 @@ async fn setup_program_test_env() -> (BanksClient, Keypair, solana_program::hash
program_test.prefer_bpf(true); program_test.prefer_bpf(true);
// Busses // Busses
program_test.add_account_with_base64_data( for i in 0..BUS_COUNT {
Pubkey::from_str("2uwqyH2gKqstgAFCSniirx73X4iQek5ETc2vVJKUiNMg").unwrap(), program_test.add_account_with_base64_data(
1002240, BUS_ADDRESSES[i],
ore::id(), 1057920,
"ZAAAAAAAAAD/AAAAAAAAAICy5g4AAAAA", ore::id(),
); bs64::encode(
program_test.add_account_with_base64_data( &[
Pubkey::from_str("FRMC6jVczm1cRaEs5EhDsfw7X8vsmSDpf3bJWVkawngu").unwrap(), &(Bus::discriminator() as u64).to_le_bytes(),
1002240, Bus {
ore::id(), id: i as u64,
"ZAAAAAAAAAD+AAAAAQAAAICy5g4AAAAA", available_rewards: 250_000_000,
); }
program_test.add_account_with_base64_data( .to_bytes(),
Pubkey::from_str("9nWyycs4GHjnLujPR2sbA1A8K8CkiLc5VzxWUD4hg2uM").unwrap(), ]
1002240, .concat(),
ore::id(), )
"ZAAAAAAAAAD/AAAAAgAAAICy5g4AAAAA", .as_str(),
); );
program_test.add_account_with_base64_data( }
Pubkey::from_str("Kt7kqD3MyvxLbj4ek9urXUxkDoxaMuQn82K2VdYD1jM").unwrap(),
1002240,
ore::id(),
"ZAAAAAAAAAD6AAAAAwAAAICy5g4AAAAA",
);
program_test.add_account_with_base64_data(
Pubkey::from_str("8r9mXYnFQXhwrNfvatGUTxbbNSqxScuCwp4sBTSxDVTJ").unwrap(),
1002240,
ore::id(),
"ZAAAAAAAAAD9AAAABAAAAICy5g4AAAAA",
);
program_test.add_account_with_base64_data(
Pubkey::from_str("D9cEH32k8p9uWc4w5RrStK9rWssU8NuX1Dg5YaUim4wL").unwrap(),
1002240,
ore::id(),
"ZAAAAAAAAAD/AAAABQAAAICy5g4AAAAA",
);
program_test.add_account_with_base64_data(
Pubkey::from_str("H1RKMYADPzd4C1j1RZu51NvRSVktoTYEJyeVy98Kmdyu").unwrap(),
1002240,
ore::id(),
"ZAAAAAAAAAD/AAAABgAAAICy5g4AAAAA",
);
program_test.add_account_with_base64_data(
Pubkey::from_str("3XbdZNbBjjp8qnDJjv1RxaKisyfx6ahznYkSigs6dayy").unwrap(),
1002240,
ore::id(),
"ZAAAAAAAAAD5AAAABwAAAICy5g4AAAAA",
);
// Treasury (difficulty = MAX) // 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( program_test.add_account_with_base64_data(
Pubkey::from_str("67PLJej6iZm915WbEu6NLeZtRZtnHc5nSVQvkHRZyPiC").unwrap(), treasury_pda.0,
1559040, 1614720,
ore::id(), ore::id(),
"ZgAAAAAAAAD/AAAAAAAAAI9MXkItHZzhz/U8d4MsXPzDSQZSRgZsJnNpvgvcborr//////////////////////////////////////////9kAAAAAAAAAPQBAAAAAAAAAAAAAAAAAAA=", 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(),
epoch_start_at: 100,
reward_rate: INITIAL_REWARD_RATE,
total_claimed_rewards: 0,
}
.to_bytes(),
]
.concat(),
)
.as_str(),
); );
// Mint // 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( program_test.add_account_with_base64_data(
Pubkey::from_str("DY4JVebraRXg9BGt4MRU4mvqHGDzmi2Ay1HGjDU5YeNf").unwrap(), MINT_ADDRESS,
1461600, 1461600,
spl_token::id(), spl_token::id(),
"AQAAAEvtK9pjA/sPMEl3rhUgX8iz4/q0A5icrVGp0GdL3satAJQ1dwAAAAAJAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==" bs64::encode(&mint_src).as_str(),
); );
// Treasury tokens // 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( program_test.add_account_with_base64_data(
Pubkey::from_str("EH4tskvkeNqX5ce3FBr4oJob3FKSns9th7NvP28ZHsNL").unwrap(), tokens_address,
2039280, 2039280,
spl_token::id(), spl_token::id(),
"ukD7Oc0QjzbigRIB1x9/XLzAT3w7X0UTZ1NVeB85lRRL7SvaYwP7DzBJd64VIF/Is+P6tAOYnK1RqdBnS97GrQCUNXcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" bs64::encode(&tokens_src).as_str(),
); );
// Set sysvar // Set sysvar

View File

@@ -2,9 +2,9 @@ use std::str::FromStr;
use ore::{ use ore::{
state::{Bus, Treasury}, state::{Bus, Treasury},
utils::AccountDeserialize, utils::{AccountDeserialize, Discriminator},
BUS, BUS_COUNT, BUS_EPOCH_REWARDS, INITIAL_DIFFICULTY, INITIAL_REWARD_RATE, MAX_EPOCH_REWARDS, BUS, BUS_ADDRESSES, BUS_COUNT, BUS_EPOCH_REWARDS, INITIAL_DIFFICULTY, INITIAL_REWARD_RATE,
MINT, TREASURY, MAX_EPOCH_REWARDS, MINT, MINT_ADDRESS, TOKEN_DECIMALS, TREASURY, TREASURY_ADDRESS,
}; };
use solana_program::{ use solana_program::{
clock::Clock, epoch_schedule::DEFAULT_SLOTS_PER_EPOCH, hash::Hash, program_option::COption, clock::Clock, epoch_schedule::DEFAULT_SLOTS_PER_EPOCH, hash::Hash, program_option::COption,
@@ -55,7 +55,6 @@ async fn test_reset() {
bus_account, bus_account,
bs64::encode(&bus_account.data) bs64::encode(&bus_account.data)
); );
assert_eq!(bus.bump as u8, bus_pdas[i].1);
assert_eq!(bus.id as u8, i as u8); assert_eq!(bus.id as u8, i as u8);
assert_eq!(bus.available_rewards, BUS_EPOCH_REWARDS); assert_eq!(bus.available_rewards, BUS_EPOCH_REWARDS);
} }
@@ -89,12 +88,12 @@ async fn test_reset() {
assert_eq!(mint.decimals, ore::TOKEN_DECIMALS); assert_eq!(mint.decimals, ore::TOKEN_DECIMALS);
assert_eq!(mint.is_initialized, true); assert_eq!(mint.is_initialized, true);
assert_eq!(mint.freeze_authority, COption::None); assert_eq!(mint.freeze_authority, COption::None);
// println!( println!(
// "Mint {:?} {:?} {:?}", "Mint {:?} {:?} {:?}",
// mint_pda.0, mint_pda.0,
// mint_account, mint_account,
// bs64::encode(&mint_account.data) bs64::encode(&mint_account.data)
// ); );
// Test treasury token state // Test treasury token state
let treasury_tokens_account = banks let treasury_tokens_account = banks
@@ -112,12 +111,12 @@ async fn test_reset() {
assert_eq!(treasury_tokens.is_native, COption::None); assert_eq!(treasury_tokens.is_native, COption::None);
assert_eq!(treasury_tokens.delegated_amount, 0); assert_eq!(treasury_tokens.delegated_amount, 0);
assert_eq!(treasury_tokens.close_authority, COption::None); assert_eq!(treasury_tokens.close_authority, COption::None);
// println!( println!(
// "Treasury tokens {:?} {:?} {:?}", "Treasury tokens {:?} {:?} {:?}",
// treasury_tokens_address, treasury_tokens_address,
// treasury_tokens_account, treasury_tokens_account,
// bs64::encode(&treasury_tokens_account.data) bs64::encode(&treasury_tokens_account.data)
// ); );
// assert!(false); // assert!(false);
} }
@@ -127,77 +126,90 @@ async fn setup_program_test_env() -> (BanksClient, Keypair, Hash) {
program_test.prefer_bpf(true); program_test.prefer_bpf(true);
// Busses // Busses
program_test.add_account_with_base64_data( for i in 0..BUS_COUNT {
Pubkey::from_str("2uwqyH2gKqstgAFCSniirx73X4iQek5ETc2vVJKUiNMg").unwrap(), program_test.add_account_with_base64_data(
1002240, BUS_ADDRESSES[i],
ore::id(), 1057920,
"ZAAAAAAAAAD/AAAAAAAAAAAAAAAAAAAA", ore::id(),
); bs64::encode(
program_test.add_account_with_base64_data( &[
Pubkey::from_str("FRMC6jVczm1cRaEs5EhDsfw7X8vsmSDpf3bJWVkawngu").unwrap(), &(Bus::discriminator() as u64).to_le_bytes(),
1002240, Bus {
ore::id(), id: i as u64,
"ZAAAAAAAAAD+AAAAAQAAAAAAAAAAAAAA", available_rewards: 0,
); }
program_test.add_account_with_base64_data( .to_bytes(),
Pubkey::from_str("9nWyycs4GHjnLujPR2sbA1A8K8CkiLc5VzxWUD4hg2uM").unwrap(), ]
1002240, .concat(),
ore::id(), )
"ZAAAAAAAAAD/AAAAAgAAAAAAAAAAAAAA", .as_str(),
); );
program_test.add_account_with_base64_data( }
Pubkey::from_str("Kt7kqD3MyvxLbj4ek9urXUxkDoxaMuQn82K2VdYD1jM").unwrap(),
1002240,
ore::id(),
"ZAAAAAAAAAD6AAAAAwAAAAAAAAAAAAAA",
);
program_test.add_account_with_base64_data(
Pubkey::from_str("8r9mXYnFQXhwrNfvatGUTxbbNSqxScuCwp4sBTSxDVTJ").unwrap(),
1002240,
ore::id(),
"ZAAAAAAAAAD9AAAABAAAAAAAAAAAAAAA",
);
program_test.add_account_with_base64_data(
Pubkey::from_str("D9cEH32k8p9uWc4w5RrStK9rWssU8NuX1Dg5YaUim4wL").unwrap(),
1002240,
ore::id(),
"ZAAAAAAAAAD/AAAABQAAAAAAAAAAAAAA",
);
program_test.add_account_with_base64_data(
Pubkey::from_str("H1RKMYADPzd4C1j1RZu51NvRSVktoTYEJyeVy98Kmdyu").unwrap(),
1002240,
ore::id(),
"ZAAAAAAAAAD/AAAABgAAAAAAAAAAAAAA",
);
program_test.add_account_with_base64_data(
Pubkey::from_str("3XbdZNbBjjp8qnDJjv1RxaKisyfx6ahznYkSigs6dayy").unwrap(),
1002240,
ore::id(),
"ZAAAAAAAAAD5AAAABwAAAAAAAAAAAAAA",
);
// Treasury // 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( program_test.add_account_with_base64_data(
Pubkey::from_str("67PLJej6iZm915WbEu6NLeZtRZtnHc5nSVQvkHRZyPiC").unwrap(), treasury_pda.0,
1559040, 1614720,
ore::id(), ore::id(),
"ZgAAAAAAAAD/AAAAAAAAAI9MXkItHZzhz/U8d4MsXPzDSQZSRgZsJnNpvgvcborrAAD///////////////////////////////////////8AAAAAAAAAAOgDAAAAAAAAAAAAAAAAAAA=", bs64::encode(
&[
&(Treasury::discriminator() as u64).to_le_bytes(),
Treasury {
bump: treasury_pda.1 as u64,
admin: admin_address,
difficulty: INITIAL_DIFFICULTY.into(),
epoch_start_at: 0,
reward_rate: INITIAL_REWARD_RATE,
total_claimed_rewards: 0,
}
.to_bytes(),
]
.concat(),
)
.as_str(),
); );
// Mint // 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( program_test.add_account_with_base64_data(
Pubkey::from_str("DY4JVebraRXg9BGt4MRU4mvqHGDzmi2Ay1HGjDU5YeNf").unwrap(), MINT_ADDRESS,
1461600, 1461600,
spl_token::id(), spl_token::id(),
"AQAAAEvtK9pjA/sPMEl3rhUgX8iz4/q0A5icrVGp0GdL3satAAAAAAAAAAAJAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==", bs64::encode(&mint_src).as_str(),
); );
// Treasury tokens // 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( program_test.add_account_with_base64_data(
Pubkey::from_str("EH4tskvkeNqX5ce3FBr4oJob3FKSns9th7NvP28ZHsNL").unwrap(), tokens_address,
2039280, 2039280,
spl_token::id(), spl_token::id(),
"ukD7Oc0QjzbigRIB1x9/XLzAT3w7X0UTZ1NVeB85lRRL7SvaYwP7DzBJd64VIF/Is+P6tAOYnK1RqdBnS97GrQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" bs64::encode(&tokens_src).as_str(),
); );
// Set sysvar // Set sysvar