Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new Borsh and Pubkey methods #24

Merged
merged 1 commit into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions blockbuster/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ impl<'a> Default for InstructionBundle<'a> {
}
}

pub fn order_instructions<'a, 'b>(
programs: HashSet<&'b [u8]>,
pub fn order_instructions<'a>(
programs: HashSet<&[u8]>,
transaction_info: &'a TransactionInfo<'a>,
) -> VecDeque<(IxPair<'a>, Option<Vec<IxPair<'a>>>)> {
let mut ordered_ixs: VecDeque<(IxPair, Option<Vec<IxPair>>)> = VecDeque::new();
Expand Down
4 changes: 2 additions & 2 deletions blockbuster/src/programs/candy_guard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use mpl_candy_guard::{
guards::MintCounter,
state::{CandyGuard, CandyGuardData, DATA_OFFSET},
};
use plerkle_serialization::{AccountInfo};
use solana_sdk::{borsh::try_from_slice_unchecked, pubkey::Pubkey, pubkeys};
use plerkle_serialization::AccountInfo;
use solana_sdk::{borsh0_10::try_from_slice_unchecked, pubkey::Pubkey, pubkeys};
use std::convert::TryInto;

pubkeys!(
Expand Down
2 changes: 1 addition & 1 deletion blockbuster/src/programs/candy_machine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
},
};
use plerkle_serialization::AccountInfo;
use solana_sdk::{borsh::try_from_slice_unchecked, pubkey::Pubkey, pubkeys};
use solana_sdk::{borsh0_10::try_from_slice_unchecked, pubkey::Pubkey, pubkeys};
use std::convert::TryInto;

pub mod state;
Expand Down
2 changes: 1 addition & 1 deletion blockbuster/src/programs/candy_machine_core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
};
use mpl_candy_machine_core::CandyMachine;
use plerkle_serialization::AccountInfo;
use solana_sdk::{borsh::try_from_slice_unchecked, pubkey::Pubkey, pubkeys};
use solana_sdk::{borsh0_10::try_from_slice_unchecked, pubkey::Pubkey, pubkeys};
use std::convert::TryInto;

pubkeys!(
Expand Down
2 changes: 1 addition & 1 deletion blockbuster/src/programs/token_metadata/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
programs::ProgramParseResult,
};
use borsh::BorshDeserialize;
use solana_sdk::{borsh::try_from_slice_unchecked, pubkey::Pubkey, pubkeys};
use solana_sdk::{borsh0_10::try_from_slice_unchecked, pubkey::Pubkey, pubkeys};

use plerkle_serialization::AccountInfo;

Expand Down
50 changes: 25 additions & 25 deletions blockbuster/tests/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,19 @@ use flatbuffers::{FlatBufferBuilder, WIPOffset};
pub use mpl_bubblegum::id as program_id;
use mpl_bubblegum::state::leaf_schema::LeafSchemaEvent;
use plerkle_serialization::{
root_as_account_info, root_as_compiled_instruction, AccountInfo, AccountInfoArgs,
serializer::seralize_encoded_transaction_with_status,
CompiledInstruction, CompiledInstructionBuilder, InnerInstructionsBuilder, Pubkey as FBPubkey, TransactionInfo, TransactionInfoBuilder,
root_as_account_info, root_as_compiled_instruction,
serializer::seralize_encoded_transaction_with_status, AccountInfo, AccountInfoArgs,
CompiledInstruction, CompiledInstructionBuilder, InnerInstructionsBuilder, Pubkey as FBPubkey,
TransactionInfo, TransactionInfoBuilder,
};
use rand::Rng;
use solana_geyser_plugin_interface::geyser_plugin_interface::ReplicaAccountInfo;
use solana_sdk::{pubkey::Pubkey};
use solana_transaction_status::{
EncodedConfirmedTransactionWithStatusMeta,
};
use solana_sdk::pubkey::Pubkey;
use solana_transaction_status::EncodedConfirmedTransactionWithStatusMeta;
use spl_account_compression::events::{
AccountCompressionEvent, ApplicationDataEvent, ApplicationDataEventV1,
};
use std::{fs::File};
use std::fs::File;
use std::io::BufReader;

pub fn random_program() -> Pubkey {
Expand Down Expand Up @@ -137,8 +136,8 @@ pub fn get_programs(txn_info: TransactionInfo) -> Vec<Pubkey> {
.iter()
.map(|ix| {
println!("{:?}", txn_info);
Pubkey::new(
&txn_info
Pubkey::new_from_array(
txn_info
.account_keys()
.unwrap()
.iter()
Expand All @@ -156,8 +155,8 @@ pub fn get_programs(txn_info: TransactionInfo) -> Vec<Pubkey> {
.iter()
.fold(&mut inner, |ix, curr| {
for p in curr.instructions().unwrap() {
ix.push(Pubkey::new(
&txn_info
ix.push(Pubkey::new_from_array(
txn_info
.account_keys()
.unwrap()
.iter()
Expand Down Expand Up @@ -252,24 +251,29 @@ pub fn build_random_account_update<'a>(
build_account_update(fbb, &replica_account_info, 0, false)
}

pub fn build_txn_from_fixture<'a>(
pub fn build_txn_from_fixture(
fixture_name: String,
fbb: FlatBufferBuilder<'a>,
) -> Result<FlatBufferBuilder<'a>, BlockbusterError> {
let file = File::open(format!("{}/tests/fixtures/{}.json", env!("CARGO_MANIFEST_DIR"), fixture_name)).unwrap();
fbb: FlatBufferBuilder,
) -> Result<FlatBufferBuilder, BlockbusterError> {
let file = File::open(format!(
"{}/tests/fixtures/{}.json",
env!("CARGO_MANIFEST_DIR"),
fixture_name
))
.unwrap();
let reader = BufReader::new(file);
let ectxn: EncodedConfirmedTransactionWithStatusMeta = serde_json::from_reader(reader).unwrap();
seralize_encoded_transaction_with_status(fbb, ectxn)
.map_err(Into::into)
seralize_encoded_transaction_with_status(fbb, ectxn).map_err(Into::into)
}

#[allow(clippy::too_many_arguments)]
pub fn build_bubblegum_bundle<'a>(
fbb1: &'a mut FlatBufferBuilder<'a>,
fbb2: &'a mut FlatBufferBuilder<'a>,
fbb3: &'a mut FlatBufferBuilder<'a>,
fbb4: &'a mut FlatBufferBuilder<'a>,
accounts: &'a Vec<FBPubkey>,
account_indexes: &'a Vec<u8>,
account_indexes: &'a [u8],
ix_data: &'a [u8],
lse: LeafSchemaEvent,
cs_event: AccountCompressionEvent,
Expand All @@ -286,13 +290,11 @@ pub fn build_bubblegum_bundle<'a>(
let ix = build_instruction(fbb2, &noop_bgum, account_indexes).unwrap();
let noop_bgum_ix: IxPair = (FBPubkey(spl_noop::id().to_bytes()), ix);
// The Compression Instruction here doesnt matter only the noop but we add it here to ensure we are validating that one Account compression event is happening after Bubblegum
let ix = build_instruction(fbb3, &[0; 0], account_indexes)
.unwrap();
let ix = build_instruction(fbb3, &[0; 0], account_indexes).unwrap();
let gummy_roll_ix: IxPair = (FBPubkey(spl_account_compression::id().to_bytes()), ix);
let cs = cs_event.try_to_vec().unwrap();
let noop_compression = spl_noop::instruction(cs).data;
let ix = build_instruction(fbb4, &noop_compression, account_indexes)
.unwrap();
let ix = build_instruction(fbb4, &noop_compression, account_indexes).unwrap();
let noop_compression_ix = (FBPubkey(spl_noop::id().to_bytes()), ix);

let inner_ix = vec![noop_bgum_ix, gummy_roll_ix, noop_compression_ix];
Expand All @@ -302,5 +304,3 @@ pub fn build_bubblegum_bundle<'a>(
ixb.keys = accounts.as_slice();
ixb.instruction = Some(outer_ix);
}


16 changes: 12 additions & 4 deletions blockbuster/tests/instructions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use blockbuster::{
program_handler::ProgramParser,
programs::{
bubblegum::{BubblegumParser, Payload},
token_metadata::{LeafSchemaEvent},
token_metadata::LeafSchemaEvent,
ProgramParseResult,
},
};
Expand All @@ -19,7 +19,7 @@ use spl_account_compression::events::{
AccountCompressionEvent::{self},
ApplicationDataEvent, ApplicationDataEventV1, ChangeLogEvent, ChangeLogEventV1,
};
use std::collections::{HashSet};
use std::collections::HashSet;
use std::env;
#[test]
fn test_filter() {
Expand Down Expand Up @@ -137,7 +137,11 @@ fn test_double_mint() {
if let Some(inner) = &bix.1 {
println!("{}", inner.len());
for ii in inner {
println!("pp{} {:?}", count, Pubkey::new(ii.0 .0.as_ref()));
println!(
"pp{} {:?}",
count,
Pubkey::try_from(ii.0 .0.as_ref()).unwrap()
);
}
println!("------");
let cl = AccountCompressionEvent::try_from_slice(inner[1].1.data().unwrap().bytes())
Expand Down Expand Up @@ -179,7 +183,11 @@ fn test_double_tree() {
contains.for_each(|bix| {
if let Some(inner) = &bix.1 {
for ii in inner {
println!("pp{} {:?}", count, Pubkey::new(ii.0 .0.as_ref()));
println!(
"pp{} {:?}",
count,
Pubkey::try_from(ii.0 .0.as_ref()).unwrap()
);
}
println!("------");
let cl = AccountCompressionEvent::try_from_slice(inner[1].1.data().unwrap().bytes())
Expand Down