diff --git a/nft-packs/program/Cargo.toml b/nft-packs/program/Cargo.toml index 2b9e25c36c..4b760426a4 100644 --- a/nft-packs/program/Cargo.toml +++ b/nft-packs/program/Cargo.toml @@ -19,7 +19,7 @@ spl-token = { version="3.2.0", features = [ "no-entrypoint" ] } mpl-metaplex = { path = "../../metaplex/program", features = ["no-entrypoint"] } mpl-token-metadata = { version="1.1.0", features = [ "no-entrypoint" ] } mpl-token-vault = { path = "../../token-vault/program", features = [ "no-entrypoint" ] } -randomness-oracle-program = { git = "https://github.com/metaplex/randomness-oracle", features = [ "no-entrypoint" ] } +arrayref = "0.3.6" [dev-dependencies] solana-program-test = "1.8.5" diff --git a/nft-packs/program/README.md b/nft-packs/program/README.md index 7b2f1a10fd..718632506b 100644 --- a/nft-packs/program/README.md +++ b/nft-packs/program/README.md @@ -30,7 +30,7 @@ Supports creation of "mystery" packages of NFTs that are not revealed until afte - Request card for redeem - user calls this instruction to receive index of card which he can redeem - program burns user's voucher token account - - program is using RandomOracle program to count probability to decide which card user will receive + - program is using hash of slot, timestamp and recent slothash to count probability to decide which card user will receive - probability is calculating using weighted list from PackConfig account - index of next card to redeem is written to ProvingProcess account - ProvingProcess is a PDA account with seeds [pack, "proving", voucher_mint_key] diff --git a/nft-packs/program/src/error.rs b/nft-packs/program/src/error.rs index 5006acb0f3..f7d3c67cce 100644 --- a/nft-packs/program/src/error.rs +++ b/nft-packs/program/src/error.rs @@ -100,10 +100,6 @@ pub enum NFTPacksError { #[error("Voucher should have supply greater then 0")] WrongVoucherSupply, - /// Random oracle updated long time ago - #[error("Random oracle updated long time ago")] - RandomOracleOutOfDate, - /// Card ran out of editions #[error("Card ran out of editions")] CardDoesntHaveEditions, diff --git a/nft-packs/program/src/instruction.rs b/nft-packs/program/src/instruction.rs index 3991743f79..0d4bf25637 100644 --- a/nft-packs/program/src/instruction.rs +++ b/nft-packs/program/src/instruction.rs @@ -87,7 +87,6 @@ pub enum NFTPacksInstruction { /// - write pack_set /// - signer authority /// - read store - /// - read random_oracle /// - read Rent account /// - read Clock account /// - read whitelisted_creator. Optional key @@ -180,7 +179,7 @@ pub enum NFTPacksInstruction { /// ClaimPack /// - /// Call this instruction with ProvingProcess and PackCard accounts and program among with random oracle will transfer + /// Call this instruction with ProvingProcess and PackCard accounts and program will transfer /// MasterEdition to user account or return empty response depends successfully or not user open pack with specific MasterEdition. /// /// Accounts: @@ -198,7 +197,6 @@ pub enum NFTPacksInstruction { /// - read metadata_mint_acc /// - read edition_acc /// - read rent program - /// - read randomness oracle account /// - read mpl_token_metadata program /// - read spl_token program /// - read system program @@ -283,7 +281,7 @@ pub enum NFTPacksInstruction { /// - read pack_voucher /// - read, write proving_process (PDA, ['proving', pack, user_wallet]) /// - signer user_wallet - /// - read randomness_oracle + /// - read recent_slothashes /// - read clock /// - read rent /// - read system_program @@ -320,7 +318,6 @@ pub fn init_pack( pack_set: &Pubkey, authority: &Pubkey, store: &Pubkey, - random_oracle: &Pubkey, whitelisted_creator: &Pubkey, args: InitPackSetArgs, ) -> Instruction { @@ -328,7 +325,6 @@ pub fn init_pack( AccountMeta::new(*pack_set, false), AccountMeta::new_readonly(*authority, true), AccountMeta::new_readonly(*store, false), - AccountMeta::new_readonly(*random_oracle, false), AccountMeta::new_readonly(sysvar::rent::id(), false), AccountMeta::new_readonly(sysvar::clock::id(), false), AccountMeta::new_readonly(*whitelisted_creator, false), @@ -461,7 +457,6 @@ pub fn claim_pack( new_mint_authority: &Pubkey, metadata: &Pubkey, metadata_mint: &Pubkey, - randomness_oracle: &Pubkey, index: u32, ) -> Instruction { let (proving_process, _) = @@ -500,7 +495,6 @@ pub fn claim_pack( AccountMeta::new(*metadata_mint, false), AccountMeta::new(edition_mark_pda, false), AccountMeta::new_readonly(sysvar::rent::id(), false), - AccountMeta::new_readonly(*randomness_oracle, false), AccountMeta::new_readonly(mpl_token_metadata::id(), false), AccountMeta::new_readonly(spl_token::id(), false), AccountMeta::new_readonly(system_program::id(), false), @@ -623,7 +617,6 @@ pub fn request_card_for_redeem( edition_mint: &Pubkey, user_wallet: &Pubkey, user_token_acc: &Option, - random_oracle: &Pubkey, index: u32, ) -> Instruction { let (proving_process, _) = @@ -642,7 +635,7 @@ pub fn request_card_for_redeem( AccountMeta::new_readonly(pack_voucher, false), AccountMeta::new(proving_process, false), AccountMeta::new(*user_wallet, true), - AccountMeta::new_readonly(*random_oracle, false), + AccountMeta::new_readonly(sysvar::slot_hashes::id(), false), AccountMeta::new_readonly(sysvar::clock::id(), false), AccountMeta::new_readonly(sysvar::rent::id(), false), AccountMeta::new_readonly(spl_token::id(), false), diff --git a/nft-packs/program/src/processor/claim_pack.rs b/nft-packs/program/src/processor/claim_pack.rs index ce4a6e7a28..4d71ca6519 100644 --- a/nft-packs/program/src/processor/claim_pack.rs +++ b/nft-packs/program/src/processor/claim_pack.rs @@ -39,7 +39,6 @@ pub fn claim_pack( let metadata_mint_account = next_account_info(account_info_iter)?; let edition_marker_account = next_account_info(account_info_iter)?; let rent_account = next_account_info(account_info_iter)?; - let randomness_oracle_account = next_account_info(account_info_iter)?; let _token_metadata_account = next_account_info(account_info_iter)?; let token_program_account = next_account_info(account_info_iter)?; let system_program_account = next_account_info(account_info_iter)?; @@ -47,7 +46,6 @@ pub fn claim_pack( // Validate owners assert_owned_by(pack_set_account, program_id)?; - assert_owned_by(randomness_oracle_account, &randomness_oracle_program::id())?; assert_signer(&user_wallet_account)?; diff --git a/nft-packs/program/src/processor/init_pack.rs b/nft-packs/program/src/processor/init_pack.rs index ba3765a8f4..7cd64ea446 100644 --- a/nft-packs/program/src/processor/init_pack.rs +++ b/nft-packs/program/src/processor/init_pack.rs @@ -26,7 +26,6 @@ pub fn init_pack( let pack_set_account = next_account_info(account_info_iter)?; let authority_account = next_account_info(account_info_iter)?; let store_account = next_account_info(account_info_iter)?; - let random_oracle_account = next_account_info(account_info_iter)?; let rent_info = next_account_info(account_info_iter)?; let rent = &Rent::from_account_info(rent_info)?; let clock_info = next_account_info(account_info_iter)?; @@ -36,7 +35,6 @@ pub fn init_pack( assert_rent_exempt(rent, pack_set_account)?; assert_signer(authority_account)?; assert_owned_by(store_account, &mpl_metaplex::id())?; - assert_owned_by(random_oracle_account, &randomness_oracle_program::id())?; assert_admin_whitelisted( store_account, whitelisted_creator_account, @@ -45,12 +43,6 @@ pub fn init_pack( let mut pack_set = PackSet::unpack_unchecked(&pack_set_account.data.borrow_mut())?; - // make sure that random oracle account is already initialized - if random_oracle_account.data.borrow()[0] - != randomness_oracle_program::state::AccountType::RandomnessOracle as u8 - { - return Err(ProgramError::UninitializedAccount); - } if pack_set.is_initialized() { return Err(ProgramError::AccountAlreadyInitialized); @@ -93,7 +85,6 @@ pub fn init_pack( allowed_amount_to_redeem: args.allowed_amount_to_redeem, redeem_start_date: redeem_start_date, redeem_end_date: args.redeem_end_date, - random_oracle: *random_oracle_account.key, }); pack_set.puff_out_data_fields(); diff --git a/nft-packs/program/src/processor/request_card_to_redeem.rs b/nft-packs/program/src/processor/request_card_to_redeem.rs index 53d1d6a580..505c80fbcf 100644 --- a/nft-packs/program/src/processor/request_card_to_redeem.rs +++ b/nft-packs/program/src/processor/request_card_to_redeem.rs @@ -24,9 +24,13 @@ use solana_program::{ program_option::COption, program_pack::Pack, pubkey::Pubkey, - sysvar::{rent::Rent, Sysvar}, + sysvar::{ + rent::Rent, + Sysvar, + }, }; use spl_token::state::Account; +use arrayref::array_ref; /// Process RequestCardForRedeem instruction pub fn request_card_for_redeem( @@ -43,7 +47,7 @@ pub fn request_card_for_redeem( let voucher_account = next_account_info(account_info_iter)?; let proving_process_account = next_account_info(account_info_iter)?; let user_wallet_account = next_account_info(account_info_iter)?; - let randomness_oracle_account = next_account_info(account_info_iter)?; + let recent_slothashes_info = next_account_info(account_info_iter)?; let clock_info = next_account_info(account_info_iter)?; let clock = Clock::from_account_info(clock_info)?; let rent_info = next_account_info(account_info_iter)?; @@ -77,7 +81,6 @@ pub fn request_card_for_redeem( let pack_set = PackSet::unpack(&pack_set_account.data.borrow())?; assert_account_key(store_account, &pack_set.store)?; - assert_account_key(randomness_oracle_account, &pack_set.random_oracle)?; let proving_process_seeds = &[ ProvingProcess::PREFIX.as_bytes(), @@ -166,8 +169,12 @@ pub fn request_card_for_redeem( return Err(NFTPacksError::UserRedeemedAllCards.into()); } - let random_value = - get_random_oracle_value(randomness_oracle_account, &proving_process, &clock)?; + // get slot hash + let data = recent_slothashes_info.data.borrow(); + let most_recent_slothash = array_ref![data, 8, 8]; + + // get random value + let random_value = get_random_value(most_recent_slothash, &proving_process, &clock)?; let weight_sum = if pack_set.distribution_type == PackDistributionType::MaxSupply { pack_set.total_editions } else { diff --git a/nft-packs/program/src/state/pack_set.rs b/nft-packs/program/src/state/pack_set.rs index c202381b45..89ae08e75e 100644 --- a/nft-packs/program/src/state/pack_set.rs +++ b/nft-packs/program/src/state/pack_set.rs @@ -89,8 +89,6 @@ pub struct PackSet { pub redeem_start_date: u64, /// Date when pack set becomes inactive pub redeem_end_date: Option, - /// Random oracle - pub random_oracle: Pubkey, } impl PackSet { @@ -112,7 +110,6 @@ impl PackSet { self.allowed_amount_to_redeem = params.allowed_amount_to_redeem; self.redeem_start_date = params.redeem_start_date; self.redeem_end_date = params.redeem_end_date; - self.random_oracle = params.random_oracle; } /// Increase pack cards counter @@ -267,8 +264,6 @@ pub struct InitPackSetParams { pub redeem_start_date: u64, /// Redeem end date pub redeem_end_date: Option, - /// Random oracle - pub random_oracle: Pubkey, } impl Sealed for PackSet {} diff --git a/nft-packs/program/src/utils.rs b/nft-packs/program/src/utils.rs index 19e6322041..285d31cf03 100644 --- a/nft-packs/program/src/utils.rs +++ b/nft-packs/program/src/utils.rs @@ -1,8 +1,6 @@ //! Program utils use crate::{ - error::NFTPacksError, - math::SafeMath, state::{ProvingProcess, MAX_LAG_SLOTS}, }; use borsh::BorshSerialize; @@ -248,27 +246,26 @@ pub fn empty_account_balance( Ok(()) } -/// get random value from oracle account -pub fn get_random_oracle_value( - randomness_oracle_account: &AccountInfo, +/// get random value +pub fn get_random_value( + recent_slothash: &[u8], proving_process: &ProvingProcess, clock: &Clock, ) -> Result { - let (oracle_random_value, slot) = - randomness_oracle_program::read_value(randomness_oracle_account)?; - - if clock.slot.error_sub(slot)? > MAX_LAG_SLOTS { - return Err(NFTPacksError::RandomOracleOutOfDate.into()); - } - - // Hash random value from the oracle with current slot and proving process data and receive new random u16 + // Hash slot, current timestamp and value from last slothash and proving process data and receive new random u16 let mut hasher = DefaultHasher::new(); - hasher.write(oracle_random_value.as_ref()); - hasher.write(proving_process.try_to_vec()?.as_ref()); + + // recent slothash + hasher.write(recent_slothash); + // slot hasher.write_u64(clock.slot); + // timestamp + hasher.write_i64(clock.unix_timestamp); + // ProvingProcess(to make hash different for each instruction in the same slot) + hasher.write(proving_process.try_to_vec()?.as_ref()); let mut random_value: [u8; 2] = [0u8; 2]; random_value.copy_from_slice(&hasher.finish().to_le_bytes()[..2]); Ok(u16::from_le_bytes(random_value)) -} +} \ No newline at end of file diff --git a/nft-packs/program/tests/activate.rs b/nft-packs/program/tests/activate.rs index 24f2a3c066..35912effa3 100644 --- a/nft-packs/program/tests/activate.rs +++ b/nft-packs/program/tests/activate.rs @@ -34,8 +34,6 @@ async fn setup() -> ( let uri = String::from("some link to storage"); let description = String::from("Pack description"); - let mut test_randomness_oracle = TestRandomnessOracle::new(); - test_randomness_oracle.init(&mut context).await.unwrap(); let test_pack_set = TestPackSet::new(store_key); test_pack_set @@ -51,7 +49,6 @@ async fn setup() -> ( redeem_start_date: None, redeem_end_date: None, }, - &test_randomness_oracle.keypair.pubkey(), ) .await .unwrap(); diff --git a/nft-packs/program/tests/add_card_to_pack.rs b/nft-packs/program/tests/add_card_to_pack.rs index e26b3f8b4f..0272fb9395 100644 --- a/nft-packs/program/tests/add_card_to_pack.rs +++ b/nft-packs/program/tests/add_card_to_pack.rs @@ -33,9 +33,6 @@ async fn setup( let uri = String::from("some link to storage"); let description = String::from("Pack description"); - let mut test_randomness_oracle = TestRandomnessOracle::new(); - test_randomness_oracle.init(&mut context).await.unwrap(); - let test_pack_set = TestPackSet::new(store_key); test_pack_set .init( @@ -50,7 +47,6 @@ async fn setup( redeem_start_date: None, redeem_end_date: None, }, - &test_randomness_oracle.keypair.pubkey(), ) .await .unwrap(); diff --git a/nft-packs/program/tests/add_voucher_to_pack.rs b/nft-packs/program/tests/add_voucher_to_pack.rs index 456abf9063..ec638f0b9e 100644 --- a/nft-packs/program/tests/add_voucher_to_pack.rs +++ b/nft-packs/program/tests/add_voucher_to_pack.rs @@ -32,9 +32,6 @@ async fn setup() -> ( let uri = String::from("some link to storage"); let description = String::from("Pack description"); - let mut test_randomness_oracle = TestRandomnessOracle::new(); - test_randomness_oracle.init(&mut context).await.unwrap(); - let test_pack_set = TestPackSet::new(store_key); test_pack_set .init( @@ -49,7 +46,6 @@ async fn setup() -> ( redeem_start_date: None, redeem_end_date: None, }, - &test_randomness_oracle.keypair.pubkey(), ) .await .unwrap(); diff --git a/nft-packs/program/tests/claim_card.rs b/nft-packs/program/tests/claim_card.rs index 5978bde498..7ade94f821 100644 --- a/nft-packs/program/tests/claim_card.rs +++ b/nft-packs/program/tests/claim_card.rs @@ -77,9 +77,6 @@ async fn success_fixed_probability() { .await .unwrap(); - let mut test_randomness_oracle = TestRandomnessOracle::new(); - test_randomness_oracle.init(&mut context).await.unwrap(); - let test_pack_set = TestPackSet::new(store_key); test_pack_set .init( @@ -94,7 +91,6 @@ async fn success_fixed_probability() { redeem_start_date, redeem_end_date, }, - &test_randomness_oracle.keypair.pubkey(), ) .await .unwrap(); @@ -171,8 +167,6 @@ async fn success_fixed_probability() { let new_mint = Keypair::new(); let new_mint_token_acc = Keypair::new(); - test_randomness_oracle.update(&mut context).await.unwrap(); - test_pack_set .request_card_for_redeem( &mut context, @@ -181,7 +175,6 @@ async fn success_fixed_probability() { &voucher_edition.mint.pubkey(), &edition_authority, &Some(voucher_edition.token.pubkey()), - &test_randomness_oracle.keypair.pubkey(), 1, ) .await @@ -203,7 +196,6 @@ async fn success_fixed_probability() { &edition_authority, &card_metadata.pubkey, &card_master_edition.mint_pubkey, - &test_randomness_oracle.keypair.pubkey(), 1, ) .await @@ -247,9 +239,6 @@ async fn success_max_supply_probability() { .await .unwrap(); - let mut test_randomness_oracle = TestRandomnessOracle::new(); - test_randomness_oracle.init(&mut context).await.unwrap(); - let test_pack_set = TestPackSet::new(store_key); test_pack_set .init( @@ -264,7 +253,6 @@ async fn success_max_supply_probability() { redeem_start_date, redeem_end_date, }, - &test_randomness_oracle.keypair.pubkey(), ) .await .unwrap(); @@ -338,8 +326,6 @@ async fn success_max_supply_probability() { test_pack_set.activate(&mut context).await.unwrap(); test_pack_set.clean_up(&mut context).await.unwrap(); - test_randomness_oracle.update(&mut context).await.unwrap(); - context.warp_to_slot(3).unwrap(); let new_mint = Keypair::new(); @@ -353,7 +339,6 @@ async fn success_max_supply_probability() { &voucher_edition.mint.pubkey(), &edition_authority, &Some(voucher_edition.token.pubkey()), - &test_randomness_oracle.keypair.pubkey(), 1, ) .await @@ -371,7 +356,6 @@ async fn success_max_supply_probability() { &edition_authority, &card_metadata.pubkey, &card_master_edition.mint_pubkey, - &test_randomness_oracle.keypair.pubkey(), 1, ) .await @@ -411,9 +395,6 @@ async fn success_claim_two_same_cards() { .await .unwrap(); - let mut test_randomness_oracle = TestRandomnessOracle::new(); - test_randomness_oracle.init(&mut context).await.unwrap(); - let test_pack_set = TestPackSet::new(store_key); test_pack_set .init( @@ -428,7 +409,6 @@ async fn success_claim_two_same_cards() { redeem_start_date, redeem_end_date, }, - &test_randomness_oracle.keypair.pubkey(), ) .await .unwrap(); @@ -510,8 +490,6 @@ async fn success_claim_two_same_cards() { let new_mint1 = Keypair::new(); let new_mint_token_acc1 = Keypair::new(); - test_randomness_oracle.update(&mut context).await.unwrap(); - test_pack_set .request_card_for_redeem( &mut context, @@ -520,7 +498,6 @@ async fn success_claim_two_same_cards() { &voucher_edition.mint.pubkey(), &edition_authority, &Some(voucher_edition.token.pubkey()), - &test_randomness_oracle.keypair.pubkey(), 1, ) .await @@ -537,7 +514,6 @@ async fn success_claim_two_same_cards() { &voucher_edition.mint.pubkey(), &edition_authority, &None, - &test_randomness_oracle.keypair.pubkey(), 1, ) .await @@ -557,7 +533,6 @@ async fn success_claim_two_same_cards() { &edition_authority, &card_metadata.pubkey, &card_master_edition.mint_pubkey, - &test_randomness_oracle.keypair.pubkey(), 1, ) .await @@ -577,7 +552,6 @@ async fn success_claim_two_same_cards() { &edition_authority, &card_metadata.pubkey, &card_master_edition.mint_pubkey, - &test_randomness_oracle.keypair.pubkey(), 1, ) .await @@ -605,9 +579,6 @@ async fn success_claim_decrement_redeem_cards() { .await .unwrap(); - let mut test_randomness_oracle = TestRandomnessOracle::new(); - test_randomness_oracle.init(&mut context).await.unwrap(); - let test_pack_set = TestPackSet::new(store_key); test_pack_set .init( @@ -622,7 +593,6 @@ async fn success_claim_decrement_redeem_cards() { redeem_start_date, redeem_end_date, }, - &test_randomness_oracle.keypair.pubkey(), ) .await .unwrap(); @@ -704,8 +674,6 @@ async fn success_claim_decrement_redeem_cards() { let new_mint1 = Keypair::new(); let new_mint_token_acc1 = Keypair::new(); - test_randomness_oracle.update(&mut context).await.unwrap(); - test_pack_set .request_card_for_redeem( &mut context, @@ -714,7 +682,6 @@ async fn success_claim_decrement_redeem_cards() { &voucher_edition.mint.pubkey(), &edition_authority, &Some(voucher_edition.token.pubkey()), - &test_randomness_oracle.keypair.pubkey(), 1, ) .await @@ -737,7 +704,6 @@ async fn success_claim_decrement_redeem_cards() { &voucher_edition.mint.pubkey(), &edition_authority, &None, - &test_randomness_oracle.keypair.pubkey(), 1, ) .await @@ -761,7 +727,6 @@ async fn success_claim_decrement_redeem_cards() { &edition_authority, &card_metadata.pubkey, &card_master_edition.mint_pubkey, - &test_randomness_oracle.keypair.pubkey(), 1, ) .await @@ -785,7 +750,6 @@ async fn success_claim_decrement_redeem_cards() { &edition_authority, &card_metadata.pubkey, &card_master_edition.mint_pubkey, - &test_randomness_oracle.keypair.pubkey(), 1, ) .await @@ -814,9 +778,6 @@ async fn success_claim_two_indexes() { .await .unwrap(); - let mut test_randomness_oracle = TestRandomnessOracle::new(); - test_randomness_oracle.init(&mut context).await.unwrap(); - let test_pack_set = TestPackSet::new(store_key); test_pack_set .init( @@ -831,7 +792,6 @@ async fn success_claim_two_indexes() { redeem_start_date, redeem_end_date, }, - &test_randomness_oracle.keypair.pubkey(), ) .await .unwrap(); @@ -934,8 +894,6 @@ async fn success_claim_two_indexes() { let new_mint = Keypair::new(); let new_mint_token_acc = Keypair::new(); - test_randomness_oracle.update(&mut context).await.unwrap(); - test_pack_set .request_card_for_redeem( &mut context, @@ -944,7 +902,6 @@ async fn success_claim_two_indexes() { &voucher_edition.mint.pubkey(), &edition_authority, &Some(voucher_edition.token.pubkey()), - &test_randomness_oracle.keypair.pubkey(), 1, ) .await @@ -961,7 +918,6 @@ async fn success_claim_two_indexes() { &voucher_edition.mint.pubkey(), &edition_authority, &None, - &test_randomness_oracle.keypair.pubkey(), 1, ) .await @@ -990,7 +946,6 @@ async fn success_claim_two_indexes() { &edition_authority, &card_metadata.pubkey, &card_master_edition.mint_pubkey, - &test_randomness_oracle.keypair.pubkey(), index, ) .await @@ -1026,9 +981,6 @@ async fn success_claim_after_redeem_end_date() { .await .unwrap(); - let mut test_randomness_oracle = TestRandomnessOracle::new(); - test_randomness_oracle.init(&mut context).await.unwrap(); - let test_pack_set = TestPackSet::new(store_key); test_pack_set .init( @@ -1043,7 +995,6 @@ async fn success_claim_after_redeem_end_date() { redeem_start_date, redeem_end_date, }, - &test_randomness_oracle.keypair.pubkey(), ) .await .unwrap(); @@ -1115,8 +1066,6 @@ async fn success_claim_after_redeem_end_date() { test_pack_set.activate(&mut context).await.unwrap(); test_pack_set.clean_up(&mut context).await.unwrap(); - test_randomness_oracle.update(&mut context).await.unwrap(); - context.warp_to_slot(3).unwrap(); let new_mint = Keypair::new(); @@ -1130,7 +1079,6 @@ async fn success_claim_after_redeem_end_date() { &voucher_edition.mint.pubkey(), &edition_authority, &Some(voucher_edition.token.pubkey()), - &test_randomness_oracle.keypair.pubkey(), 1, ) .await @@ -1158,7 +1106,6 @@ async fn success_claim_after_redeem_end_date() { &edition_authority, &card_metadata.pubkey, &card_master_edition.mint_pubkey, - &test_randomness_oracle.keypair.pubkey(), 1, ) .await @@ -1186,9 +1133,6 @@ async fn fail_wrong_user_wallet() { .await .unwrap(); - let mut test_randomness_oracle = TestRandomnessOracle::new(); - test_randomness_oracle.init(&mut context).await.unwrap(); - let test_pack_set = TestPackSet::new(store_key); test_pack_set .init( @@ -1203,7 +1147,6 @@ async fn fail_wrong_user_wallet() { redeem_start_date, redeem_end_date, }, - &test_randomness_oracle.keypair.pubkey(), ) .await .unwrap(); @@ -1277,8 +1220,6 @@ async fn fail_wrong_user_wallet() { test_pack_set.activate(&mut context).await.unwrap(); test_pack_set.clean_up(&mut context).await.unwrap(); - test_randomness_oracle.update(&mut context).await.unwrap(); - test_pack_set .request_card_for_redeem( &mut context, @@ -1287,7 +1228,6 @@ async fn fail_wrong_user_wallet() { &voucher_edition.mint.pubkey(), &edition_authority, &Some(voucher_edition.token.pubkey()), - &test_randomness_oracle.keypair.pubkey(), 1, ) .await @@ -1370,9 +1310,6 @@ async fn fail_wrong_user_wallet() { &mpl_token_metadata::id(), ); - let mut test_randomness_oracle = TestRandomnessOracle::new(); - test_randomness_oracle.init(&mut context).await.unwrap(); - let accounts = vec![ AccountMeta::new_readonly(test_pack_set.keypair.pubkey(), false), AccountMeta::new(proving_process, false), @@ -1389,7 +1326,6 @@ async fn fail_wrong_user_wallet() { AccountMeta::new(card_master_edition.mint_pubkey, false), AccountMeta::new(edition_mark_pda, false), AccountMeta::new_readonly(sysvar::rent::id(), false), - AccountMeta::new_readonly(test_randomness_oracle.keypair.pubkey(), false), AccountMeta::new_readonly(mpl_token_metadata::id(), false), AccountMeta::new_readonly(spl_token::id(), false), AccountMeta::new_readonly(system_program::id(), false), @@ -1436,9 +1372,6 @@ async fn fail_claim_twice() { .await .unwrap(); - let mut test_randomness_oracle = TestRandomnessOracle::new(); - test_randomness_oracle.init(&mut context).await.unwrap(); - let test_pack_set = TestPackSet::new(store_key); test_pack_set .init( @@ -1453,7 +1386,6 @@ async fn fail_claim_twice() { redeem_start_date, redeem_end_date, }, - &test_randomness_oracle.keypair.pubkey(), ) .await .unwrap(); @@ -1527,8 +1459,6 @@ async fn fail_claim_twice() { test_pack_set.activate(&mut context).await.unwrap(); test_pack_set.clean_up(&mut context).await.unwrap(); - test_randomness_oracle.update(&mut context).await.unwrap(); - context.warp_to_slot(3).unwrap(); let new_mint = Keypair::new(); @@ -1542,7 +1472,6 @@ async fn fail_claim_twice() { &voucher_edition.mint.pubkey(), &edition_authority, &Some(voucher_edition.token.pubkey()), - &test_randomness_oracle.keypair.pubkey(), 1, ) .await @@ -1560,7 +1489,6 @@ async fn fail_claim_twice() { &edition_authority, &card_metadata.pubkey, &card_master_edition.mint_pubkey, - &test_randomness_oracle.keypair.pubkey(), 1, ) .await @@ -1602,7 +1530,6 @@ async fn fail_claim_twice() { &edition_authority.pubkey(), &card_metadata.pubkey, &card_master_edition.mint_pubkey, - &test_randomness_oracle.keypair.pubkey(), 1, )], Some(&context.payer.pubkey()), diff --git a/nft-packs/program/tests/clean_up.rs b/nft-packs/program/tests/clean_up.rs index e176518181..55513b7010 100644 --- a/nft-packs/program/tests/clean_up.rs +++ b/nft-packs/program/tests/clean_up.rs @@ -61,9 +61,6 @@ async fn success_clean_up_change() { .await .unwrap(); - let mut test_randomness_oracle = TestRandomnessOracle::new(); - test_randomness_oracle.init(&mut context).await.unwrap(); - let test_pack_set = TestPackSet::new(store_key); test_pack_set .init( @@ -78,7 +75,6 @@ async fn success_clean_up_change() { redeem_start_date, redeem_end_date, }, - &test_randomness_oracle.keypair.pubkey(), ) .await .unwrap(); @@ -151,8 +147,6 @@ async fn success_clean_up_change() { test_pack_set.activate(&mut context).await.unwrap(); test_pack_set.clean_up(&mut context).await.unwrap(); - test_randomness_oracle.update(&mut context).await.unwrap(); - test_pack_set .request_card_for_redeem( &mut context, @@ -161,7 +155,6 @@ async fn success_clean_up_change() { &voucher_edition.mint.pubkey(), &edition_authority, &Some(voucher_edition.token.pubkey()), - &test_randomness_oracle.keypair.pubkey(), 1, ) .await @@ -208,9 +201,6 @@ async fn success_clean_up_sort() { .await .unwrap(); - let mut test_randomness_oracle = TestRandomnessOracle::new(); - test_randomness_oracle.init(&mut context).await.unwrap(); - let test_pack_set = TestPackSet::new(store_key); test_pack_set .init( @@ -225,7 +215,6 @@ async fn success_clean_up_sort() { redeem_start_date, redeem_end_date, }, - &test_randomness_oracle.keypair.pubkey(), ) .await .unwrap(); diff --git a/nft-packs/program/tests/close_pack.rs b/nft-packs/program/tests/close_pack.rs index b6c8f4df19..93d7d9546a 100644 --- a/nft-packs/program/tests/close_pack.rs +++ b/nft-packs/program/tests/close_pack.rs @@ -32,9 +32,6 @@ async fn setup() -> ( .await .unwrap(); - let mut test_randomness_oracle = TestRandomnessOracle::new(); - test_randomness_oracle.init(&mut context).await.unwrap(); - let test_pack_set = TestPackSet::new(store_key); test_pack_set .init( @@ -49,7 +46,6 @@ async fn setup() -> ( redeem_start_date, redeem_end_date, }, - &test_randomness_oracle.keypair.pubkey(), ) .await .unwrap(); diff --git a/nft-packs/program/tests/deactivate.rs b/nft-packs/program/tests/deactivate.rs index aa8be289c6..5b408d0d75 100644 --- a/nft-packs/program/tests/deactivate.rs +++ b/nft-packs/program/tests/deactivate.rs @@ -39,9 +39,6 @@ async fn setup() -> ( .await .unwrap(); - let mut test_randomness_oracle = TestRandomnessOracle::new(); - test_randomness_oracle.init(&mut context).await.unwrap(); - let test_pack_set = TestPackSet::new(store_key); test_pack_set .init( @@ -56,7 +53,6 @@ async fn setup() -> ( redeem_start_date, redeem_end_date, }, - &test_randomness_oracle.keypair.pubkey(), ) .await .unwrap(); diff --git a/nft-packs/program/tests/delete_pack.rs b/nft-packs/program/tests/delete_pack.rs index e83b5d4cd0..1f4cb95e24 100644 --- a/nft-packs/program/tests/delete_pack.rs +++ b/nft-packs/program/tests/delete_pack.rs @@ -39,9 +39,6 @@ async fn setup() -> ( .await .unwrap(); - let mut test_randomness_oracle = TestRandomnessOracle::new(); - test_randomness_oracle.init(&mut context).await.unwrap(); - let test_pack_set = TestPackSet::new(store_key); test_pack_set .init( @@ -56,7 +53,6 @@ async fn setup() -> ( redeem_start_date, redeem_end_date, }, - &test_randomness_oracle.keypair.pubkey(), ) .await .unwrap(); diff --git a/nft-packs/program/tests/delete_pack_card.rs b/nft-packs/program/tests/delete_pack_card.rs index 9bf7d1424e..f769130d71 100644 --- a/nft-packs/program/tests/delete_pack_card.rs +++ b/nft-packs/program/tests/delete_pack_card.rs @@ -40,9 +40,6 @@ async fn setup() -> ( .await .unwrap(); - let mut test_randomness_oracle = TestRandomnessOracle::new(); - test_randomness_oracle.init(&mut context).await.unwrap(); - let test_pack_set = TestPackSet::new(store_key); test_pack_set .init( @@ -57,7 +54,6 @@ async fn setup() -> ( redeem_start_date, redeem_end_date, }, - &test_randomness_oracle.keypair.pubkey(), ) .await .unwrap(); diff --git a/nft-packs/program/tests/delete_pack_voucher.rs b/nft-packs/program/tests/delete_pack_voucher.rs index 9eb8dcb6ea..b67d6a79eb 100644 --- a/nft-packs/program/tests/delete_pack_voucher.rs +++ b/nft-packs/program/tests/delete_pack_voucher.rs @@ -40,9 +40,6 @@ async fn setup() -> ( .await .unwrap(); - let mut test_randomness_oracle = TestRandomnessOracle::new(); - test_randomness_oracle.init(&mut context).await.unwrap(); - let test_pack_set = TestPackSet::new(store_key); test_pack_set .init( @@ -57,7 +54,6 @@ async fn setup() -> ( redeem_start_date, redeem_end_date, }, - &test_randomness_oracle.keypair.pubkey(), ) .await .unwrap(); diff --git a/nft-packs/program/tests/edit_pack.rs b/nft-packs/program/tests/edit_pack.rs index 5fd3efcf42..7cd194fcbb 100644 --- a/nft-packs/program/tests/edit_pack.rs +++ b/nft-packs/program/tests/edit_pack.rs @@ -36,9 +36,6 @@ async fn setup( .await .unwrap(); - let mut test_randomness_oracle = TestRandomnessOracle::new(); - test_randomness_oracle.init(&mut context).await.unwrap(); - let test_pack_set = TestPackSet::new(store_key); test_pack_set .init( @@ -53,7 +50,6 @@ async fn setup( redeem_start_date, redeem_end_date, }, - &test_randomness_oracle.keypair.pubkey(), ) .await .unwrap(); diff --git a/nft-packs/program/tests/init_pack_set.rs b/nft-packs/program/tests/init_pack_set.rs index 8e7c865e2e..d5bb57103b 100644 --- a/nft-packs/program/tests/init_pack_set.rs +++ b/nft-packs/program/tests/init_pack_set.rs @@ -32,9 +32,6 @@ async fn success() { .await .unwrap(); - let mut test_randomness_oracle = TestRandomnessOracle::new(); - test_randomness_oracle.init(&mut context).await.unwrap(); - let test_pack_set = TestPackSet::new(store_key); test_pack_set .init( @@ -49,7 +46,6 @@ async fn success() { redeem_start_date, redeem_end_date, }, - &test_randomness_oracle.keypair.pubkey(), ) .await .unwrap(); @@ -86,9 +82,6 @@ async fn fail() { .await .unwrap(); - let mut test_randomness_oracle = TestRandomnessOracle::new(); - test_randomness_oracle.init(&mut context).await.unwrap(); - let test_pack_set = TestPackSet::new(store_key); let result = test_pack_set .init( @@ -103,7 +96,6 @@ async fn fail() { redeem_start_date, redeem_end_date: redeem_start_date, }, - &test_randomness_oracle.keypair.pubkey(), ) .await; diff --git a/nft-packs/program/tests/request_card_to_redeem.rs b/nft-packs/program/tests/request_card_to_redeem.rs index 7f1b2bdd51..01b9c7c32b 100644 --- a/nft-packs/program/tests/request_card_to_redeem.rs +++ b/nft-packs/program/tests/request_card_to_redeem.rs @@ -70,9 +70,6 @@ async fn success() { .await .unwrap(); - let mut test_randomness_oracle = TestRandomnessOracle::new(); - test_randomness_oracle.init(&mut context).await.unwrap(); - let test_pack_set = TestPackSet::new(store_key); test_pack_set .init( @@ -87,7 +84,6 @@ async fn success() { redeem_start_date, redeem_end_date, }, - &test_randomness_oracle.keypair.pubkey(), ) .await .unwrap(); @@ -160,8 +156,6 @@ async fn success() { test_pack_set.activate(&mut context).await.unwrap(); test_pack_set.clean_up(&mut context).await.unwrap(); - test_randomness_oracle.update(&mut context).await.unwrap(); - test_pack_set .request_card_for_redeem( &mut context, @@ -170,7 +164,6 @@ async fn success() { &voucher_edition.mint.pubkey(), &edition_authority, &Some(voucher_edition.token.pubkey()), - &test_randomness_oracle.keypair.pubkey(), 1, ) .await @@ -209,9 +202,6 @@ async fn success_two_cards() { .await .unwrap(); - let mut test_randomness_oracle = TestRandomnessOracle::new(); - test_randomness_oracle.init(&mut context).await.unwrap(); - let test_pack_set = TestPackSet::new(store_key); test_pack_set .init( @@ -226,7 +216,6 @@ async fn success_two_cards() { redeem_start_date, redeem_end_date, }, - &test_randomness_oracle.keypair.pubkey(), ) .await .unwrap(); @@ -319,8 +308,6 @@ async fn success_two_cards() { test_pack_set.activate(&mut context).await.unwrap(); test_pack_set.clean_up(&mut context).await.unwrap(); - test_randomness_oracle.update(&mut context).await.unwrap(); - test_pack_set .request_card_for_redeem( &mut context, @@ -329,7 +316,6 @@ async fn success_two_cards() { &voucher_edition.mint.pubkey(), &edition_authority, &Some(voucher_edition.token.pubkey()), - &test_randomness_oracle.keypair.pubkey(), 1, ) .await @@ -369,9 +355,6 @@ async fn fail_request_without_clean_up() { .await .unwrap(); - let mut test_randomness_oracle = TestRandomnessOracle::new(); - test_randomness_oracle.init(&mut context).await.unwrap(); - let test_pack_set = TestPackSet::new(store_key); test_pack_set .init( @@ -386,7 +369,6 @@ async fn fail_request_without_clean_up() { redeem_start_date, redeem_end_date, }, - &test_randomness_oracle.keypair.pubkey(), ) .await .unwrap(); @@ -459,8 +441,6 @@ async fn fail_request_without_clean_up() { test_pack_set.activate(&mut context).await.unwrap(); test_pack_set.clean_up(&mut context).await.unwrap(); - test_randomness_oracle.update(&mut context).await.unwrap(); - test_pack_set .request_card_for_redeem( &mut context, @@ -469,7 +449,6 @@ async fn fail_request_without_clean_up() { &voucher_edition.mint.pubkey(), &edition_authority, &Some(voucher_edition.token.pubkey()), - &test_randomness_oracle.keypair.pubkey(), 1, ) .await @@ -486,7 +465,6 @@ async fn fail_request_without_clean_up() { &voucher_edition.mint.pubkey(), &edition_authority, &Some(voucher_edition.token.pubkey()), - &test_randomness_oracle.keypair.pubkey(), 1, ) .await; @@ -518,9 +496,6 @@ async fn fail_request_after_end_date() { .await .unwrap(); - let mut test_randomness_oracle = TestRandomnessOracle::new(); - test_randomness_oracle.init(&mut context).await.unwrap(); - let test_pack_set = TestPackSet::new(store_key); test_pack_set .init( @@ -535,7 +510,6 @@ async fn fail_request_after_end_date() { redeem_start_date, redeem_end_date, }, - &test_randomness_oracle.keypair.pubkey(), ) .await .unwrap(); @@ -626,8 +600,6 @@ async fn fail_request_after_end_date() { test_pack_set.activate(&mut context).await.unwrap(); test_pack_set.clean_up(&mut context).await.unwrap(); - test_randomness_oracle.update(&mut context).await.unwrap(); - // Wait until we reach over `redeem_end_date` timestamp warp_sleep(&mut context, std::time::Duration::from_secs(5)).await; let last_timestamp = context @@ -646,7 +618,6 @@ async fn fail_request_after_end_date() { &voucher_edition.mint.pubkey(), &edition_authority, &Some(voucher_edition.token.pubkey()), - &test_randomness_oracle.keypair.pubkey(), 1, ) .await @@ -673,9 +644,6 @@ async fn fail_request_with_invalid_voucher() { .await .unwrap(); - let mut test_randomness_oracle = TestRandomnessOracle::new(); - test_randomness_oracle.init(&mut context).await.unwrap(); - let test_pack_set = TestPackSet::new(store_key); test_pack_set .init( @@ -690,7 +658,6 @@ async fn fail_request_with_invalid_voucher() { redeem_start_date, redeem_end_date, }, - &test_randomness_oracle.keypair.pubkey(), ) .await .unwrap(); @@ -781,8 +748,6 @@ async fn fail_request_with_invalid_voucher() { test_pack_set.activate(&mut context).await.unwrap(); test_pack_set.clean_up(&mut context).await.unwrap(); - test_randomness_oracle.update(&mut context).await.unwrap(); - // Wait until we reach over `redeem_end_date` timestamp warp_sleep(&mut context, std::time::Duration::from_secs(5)).await; let last_timestamp = context @@ -801,7 +766,6 @@ async fn fail_request_with_invalid_voucher() { &voucher_edition.mint.pubkey(), &edition_authority, &Some(voucher_edition.token.pubkey()), - &test_randomness_oracle.keypair.pubkey(), 1, ) .await diff --git a/nft-packs/program/tests/transfer_pack_authority.rs b/nft-packs/program/tests/transfer_pack_authority.rs index 7c057244af..e06e390c43 100644 --- a/nft-packs/program/tests/transfer_pack_authority.rs +++ b/nft-packs/program/tests/transfer_pack_authority.rs @@ -40,9 +40,6 @@ async fn setup() -> ( .await .unwrap(); - let mut test_randomness_oracle = TestRandomnessOracle::new(); - test_randomness_oracle.init(&mut context).await.unwrap(); - let test_pack_set = TestPackSet::new(store_key); test_pack_set .init( @@ -57,7 +54,6 @@ async fn setup() -> ( redeem_start_date, redeem_end_date, }, - &test_randomness_oracle.keypair.pubkey(), ) .await .unwrap(); diff --git a/nft-packs/program/tests/utils/mod.rs b/nft-packs/program/tests/utils/mod.rs index 08d117a57b..7779bf295f 100644 --- a/nft-packs/program/tests/utils/mod.rs +++ b/nft-packs/program/tests/utils/mod.rs @@ -8,7 +8,6 @@ mod metadata; mod pack_card; mod pack_set; mod pack_voucher; -mod randomness_oracle; mod user; mod vault; @@ -21,7 +20,6 @@ pub use metadata::TestMetadata; pub use pack_card::TestPackCard; pub use pack_set::TestPackSet; pub use pack_voucher::TestPackVoucher; -pub use randomness_oracle::TestRandomnessOracle; use solana_program::clock::Clock; use solana_program_test::*; use solana_sdk::{ @@ -38,11 +36,6 @@ pub fn nft_packs_program_test<'a>() -> ProgramTest { program.add_program("mpl_metaplex", mpl_metaplex::id(), None); program.add_program("mpl_token_metadata", mpl_token_metadata::id(), None); program.prefer_bpf(false); - program.add_program( - "randomness_oracle_program", - randomness_oracle_program::id(), - processor!(randomness_oracle_program::processor::Processor::process_instruction), - ); program } diff --git a/nft-packs/program/tests/utils/pack_set.rs b/nft-packs/program/tests/utils/pack_set.rs index 79fdb8b47d..88238e6814 100644 --- a/nft-packs/program/tests/utils/pack_set.rs +++ b/nft-packs/program/tests/utils/pack_set.rs @@ -40,7 +40,6 @@ impl TestPackSet { &self, context: &mut ProgramTestContext, args: instruction::InitPackSetArgs, - randomness_oracle: &Pubkey, ) -> transport::Result<()> { create_account::(context, &self.keypair, &mpl_nft_packs::id()).await?; @@ -57,7 +56,6 @@ impl TestPackSet { &self.keypair.pubkey(), &self.authority.pubkey(), &self.store, - randomness_oracle, &self.minting_authority.pubkey(), args, ), @@ -339,7 +337,6 @@ impl TestPackSet { edition_mint: &Pubkey, user_wallet: &Keypair, user_token_acc: &Option, - random_oracle: &Pubkey, voucher_index: u32, ) -> transport::Result<()> { let tx = Transaction::new_signed_with_payer( @@ -351,7 +348,6 @@ impl TestPackSet { edition_mint, &user_wallet.pubkey(), user_token_acc, - random_oracle, voucher_index, )], Some(&context.payer.pubkey()), @@ -370,7 +366,6 @@ impl TestPackSet { edition_mint: &Pubkey, user_wallet: &Keypair, user_token_acc: &Option, - random_oracle: &Pubkey, voucher_index: u32, ) -> transport::Result<()> { let mut ix = instruction::request_card_for_redeem( @@ -381,7 +376,6 @@ impl TestPackSet { edition_mint, &user_wallet.pubkey(), user_token_acc, - random_oracle, voucher_index, ); @@ -410,7 +404,6 @@ impl TestPackSet { new_mint_authority: &Keypair, master_metadata: &Pubkey, master_mint: &Pubkey, - randomness_oracle: &Pubkey, index: u32, ) -> transport::Result<()> { create_mint(context, new_mint, &new_mint_authority.pubkey(), None) @@ -469,7 +462,6 @@ impl TestPackSet { &new_mint_authority.pubkey(), master_metadata, master_mint, - randomness_oracle, index, )], Some(&context.payer.pubkey()), diff --git a/nft-packs/program/tests/utils/randomness_oracle.rs b/nft-packs/program/tests/utils/randomness_oracle.rs deleted file mode 100644 index acc3bcaf6a..0000000000 --- a/nft-packs/program/tests/utils/randomness_oracle.rs +++ /dev/null @@ -1,72 +0,0 @@ -use rand::prelude::*; -use randomness_oracle_program::{id, instruction, state::RandomnessOracle}; -use solana_program_test::*; -use solana_sdk::{ - program_pack::Pack, signature::Keypair, signer::Signer, system_instruction, - transaction::Transaction, transport, -}; - -use super::get_account; - -pub struct TestRandomnessOracle { - pub keypair: Keypair, - pub rand: ThreadRng, -} - -impl TestRandomnessOracle { - pub fn new() -> Self { - let rng = rand::thread_rng(); - TestRandomnessOracle { - keypair: Keypair::new(), - rand: rng, - } - } - - pub async fn init(&mut self, context: &mut ProgramTestContext) -> transport::Result<()> { - let rent = context.banks_client.get_rent().await.unwrap(); - println!("{}", self.keypair.pubkey()); - let tx = Transaction::new_signed_with_payer( - &[ - system_instruction::create_account( - &context.payer.pubkey(), - &self.keypair.pubkey(), - rent.minimum_balance(RandomnessOracle::LEN), - RandomnessOracle::LEN as u64, - &id(), - ), - instruction::init_randomness_oracle( - &id(), - &self.keypair.pubkey(), - &context.payer.pubkey(), - ), - ], - Some(&context.payer.pubkey()), - &[&context.payer, &self.keypair], - context.last_blockhash, - ); - - context.banks_client.process_transaction(tx).await - } - - pub async fn update(&mut self, context: &mut ProgramTestContext) -> transport::Result<()> { - let value: [u8; 32] = self.rand.gen(); - let tx = Transaction::new_signed_with_payer( - &[instruction::update_randomness_oracle( - &id(), - &self.keypair.pubkey(), - &context.payer.pubkey(), - value, - )], - Some(&context.payer.pubkey()), - &[&context.payer], - context.last_blockhash, - ); - - context.banks_client.process_transaction(tx).await - } - - pub async fn get_data(&mut self, context: &mut ProgramTestContext) -> RandomnessOracle { - let account = get_account(context, &self.keypair.pubkey()).await; - RandomnessOracle::unpack_unchecked(&account.data).unwrap() - } -}