Skip to content

Commit

Permalink
Use Bubblegum Rust SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
danenbm committed Oct 5, 2023
1 parent e3b1f8e commit 50f96a0
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 198 deletions.
180 changes: 86 additions & 94 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions blockbuster/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ readme = "../README.md"
[dependencies]
spl-account-compression = { version = "0.2.0", features = ["no-entrypoint"] }
spl-noop = { version = "0.1.3", features = ["no-entrypoint"] }
mpl-bubblegum = { version = "0.10.1", features = ["no-entrypoint"] }
mpl-bubblegum = { git = "https://github.com/metaplex-foundation/mpl-bubblegum.git", rev = "e804b70a0b3bb892d7f50d7e5cc1cb64a75b52b0" }
mpl-candy-guard = { version="2.0.0", features = ["no-entrypoint"] }
mpl-candy-machine-core = { version = "2.0.0", features = ["no-entrypoint"] }
mpl-token-metadata = { version = "2.0.0-beta.1", features = ["no-entrypoint", "serde-feature"] }
Expand All @@ -23,14 +23,14 @@ lazy_static = "1.4.0"
flatbuffers = "23.1.21"
borsh = "~0.10.3"
thiserror = "1.0.32"
solana-sdk = "~1.16.5"
solana-sdk = "~1.16.11"
anchor-lang = { version = "0.28.0"}
log = "0.4.17"

[dev-dependencies]
rand = "0.8.5"
spl-concurrent-merkle-tree = "0.2.0"
solana-client = "~1.16.5"
solana-transaction-status = "~1.16.5"
solana-geyser-plugin-interface = "~1.16.5"
solana-client = "~1.16.11"
solana-transaction-status = "~1.16.11"
solana-geyser-plugin-interface = "~1.16.11"
serde_json="1.0.89"
2 changes: 1 addition & 1 deletion blockbuster/src/program_handler.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
error::BlockbusterError, instruction::InstructionBundle, programs::ProgramParseResult,
};
use plerkle_serialization::{AccountInfo};
use plerkle_serialization::AccountInfo;
use solana_sdk::pubkey::Pubkey;

pub trait ParseResult: Sync + Send {
Expand Down
12 changes: 4 additions & 8 deletions blockbuster/src/programs/bubblegum/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@ use crate::{program_handler::NotUsed, programs::ProgramParseResult};
use borsh::de::BorshDeserialize;
use mpl_bubblegum::{
get_instruction_type,
state::{metaplex_adapter::MetadataArgs, BubblegumEventType},
};
pub use mpl_bubblegum::{
id as program_id,
state::leaf_schema::{LeafSchema, LeafSchemaEvent},
InstructionName,
types::{BubblegumEventType, MetadataArgs},
};
pub use mpl_bubblegum::{types::LeafSchema, InstructionName, LeafSchemaEvent, ID};
use plerkle_serialization::AccountInfo;
use solana_sdk::pubkey::Pubkey;
pub use spl_account_compression::events::{
Expand Down Expand Up @@ -70,11 +66,11 @@ pub struct BubblegumParser;

impl ProgramParser for BubblegumParser {
fn key(&self) -> Pubkey {
program_id()
ID
}

fn key_match(&self, key: &Pubkey) -> bool {
key == &program_id()
key == &ID
}
fn handles_account_updates(&self) -> bool {
false
Expand Down
5 changes: 1 addition & 4 deletions blockbuster/src/programs/token_metadata/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ use solana_sdk::{borsh0_10::try_from_slice_unchecked, pubkey::Pubkey, pubkeys};

use plerkle_serialization::AccountInfo;

pub use mpl_bubblegum::{
state::leaf_schema::{LeafSchema, LeafSchemaEvent},
InstructionName,
};
pub use mpl_bubblegum::{types::LeafSchema, InstructionName, LeafSchemaEvent};
use mpl_token_metadata::{
state::{
CollectionAuthorityRecord, Edition, EditionMarker, Key, MasterEditionV1, MasterEditionV2,
Expand Down
154 changes: 75 additions & 79 deletions blockbuster/tests/bubblegum_parser_test.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@


#[cfg(test)]
use anchor_lang::{prelude::*, InstructionData};
use blockbuster::{
instruction::{InstructionBundle},
instruction::InstructionBundle,
program_handler::ProgramParser,
programs::{bubblegum::BubblegumParser, ProgramParseResult},
};
use borsh::ser::BorshSerialize;
use flatbuffers::FlatBufferBuilder;
use helpers::*;
pub use mpl_bubblegum::id as program_id;
use mpl_bubblegum::state::{
leaf_schema::{LeafSchema, Version},
metaplex_adapter::{Creator, MetadataArgs, TokenProgramVersion},
BubblegumEventType,
use mpl_bubblegum::{
instructions::{MintV1InstructionArgs, TransferInstructionArgs},
types::{BubblegumEventType, Creator, LeafSchema, MetadataArgs, TokenProgramVersion, Version},
LeafSchemaEvent,
};
use plerkle_serialization::{Pubkey};
use plerkle_serialization::Pubkey;
use spl_account_compression::{
events::{
AccountCompressionEvent, ApplicationDataEvent, ApplicationDataEventV1, ChangeLogEvent,
},
events::{AccountCompressionEvent, ChangeLogEvent},
state::PathNode,
};

Expand All @@ -29,17 +22,26 @@ mod helpers;
#[test]
fn test_setup() {
let subject = BubblegumParser {};
assert_eq!(subject.key(), program_id());
assert!(subject.key_match(&program_id()));
assert_eq!(subject.key(), mpl_bubblegum::ID);
assert!(subject.key_match(&mpl_bubblegum::ID));
}

#[test]
fn test_mint() {
let subject = BubblegumParser {};

let accounts = random_list_of(8, |_i| Pubkey(random_pubkey().to_bytes()));
let account_indexes: Vec<u8> = accounts.iter().enumerate().map(|(i, _)| i as u8).collect();
let message = MetadataArgs {
let accounts = random_list_of(9, |_i| random_pubkey());
let fb_accounts: Vec<Pubkey> = accounts
.iter()
.map(|account| Pubkey(account.to_bytes()))
.collect();
let fb_account_indexes: Vec<u8> = fb_accounts
.iter()
.enumerate()
.map(|(i, _)| i as u8)
.collect();

let metadata = MetadataArgs {
name: "test".to_string(),
symbol: "test".to_string(),
uri: "www.solana.pos".to_owned(),
Expand All @@ -57,35 +59,24 @@ fn test_mint() {
share: 20,
}],
};
let ix = mpl_bubblegum::instruction::MintV1 { message };

let _lse = mpl_bubblegum::state::leaf_schema::LeafSchemaEvent {
event_type: BubblegumEventType::LeafSchemaEvent,
version: Version::V1,
schema: LeafSchema::V1 {
id: random_pubkey(),
owner: random_pubkey(),
delegate: random_pubkey(),
nonce: 0,
data_hash: [0; 32],
creator_hash: [0; 32],
},
leaf_hash: [0; 32],
// We are only using this to get the instruction data, so the accounts don't actually matter
// here.
let mut accounts_iter = accounts.iter();
let ix = mpl_bubblegum::instructions::MintV1 {
tree_config: *accounts_iter.next().unwrap(),
leaf_owner: *accounts_iter.next().unwrap(),
leaf_delegate: *accounts_iter.next().unwrap(),
merkle_tree: *accounts_iter.next().unwrap(),
payer: *accounts_iter.next().unwrap(),
tree_creator_or_delegate: *accounts_iter.next().unwrap(),
log_wrapper: *accounts_iter.next().unwrap(),
compression_program: *accounts_iter.next().unwrap(),
system_program: *accounts_iter.next().unwrap(),
};
let ix_data = ix.instruction(MintV1InstructionArgs { metadata }).data;

let cs = ChangeLogEvent::new(
random_pubkey(),
vec![PathNode {
node: [0; 32],
index: 0,
}],
0,
0,
);

let _cs_event = AccountCompressionEvent::ChangeLog(cs);

let lse = mpl_bubblegum::state::leaf_schema::LeafSchemaEvent {
let lse = LeafSchemaEvent {
event_type: BubblegumEventType::LeafSchemaEvent,
version: Version::V1,
schema: LeafSchema::V1 {
Expand All @@ -99,13 +90,6 @@ fn test_mint() {
leaf_hash: [0; 32],
};

let lse_versioned = ApplicationDataEventV1 {
application_data: lse.try_to_vec().unwrap(),
};

let _lse_event =
AccountCompressionEvent::ApplicationData(ApplicationDataEvent::V1(lse_versioned));

let cs = ChangeLogEvent::new(
random_pubkey(),
vec![PathNode {
Expand All @@ -115,11 +99,9 @@ fn test_mint() {
0,
0,
);

let cs_event = AccountCompressionEvent::ChangeLog(cs);
let ix_data = ix.data();

let mut ix_b = InstructionBundle::default();
// this is horrifying, we need to re write the flatbuffers sdk
let mut fbb1 = FlatBufferBuilder::new();
let mut fbb2 = FlatBufferBuilder::new();
let mut fbb3 = FlatBufferBuilder::new();
Expand All @@ -130,8 +112,8 @@ fn test_mint() {
&mut fbb2,
&mut fbb3,
&mut fbb4,
&accounts,
&account_indexes,
&fb_accounts,
&fb_account_indexes,
&ix_data,
lse,
cs_event,
Expand All @@ -158,18 +140,41 @@ fn test_mint() {
fn test_basic_success_parsing() {
let subject = BubblegumParser {};

let accounts = random_list_of(8, |_i| Pubkey(random_pubkey().to_bytes()));
let account_indexes: Vec<u8> = accounts.iter().enumerate().map(|(i, _)| i as u8).collect();

let ix = mpl_bubblegum::instruction::Transfer {
creator_hash: [0; 32],
index: 0,
data_hash: [0; 32],
nonce: 0,
root: [0; 32],
let accounts = random_list_of(8, |_i| random_pubkey());
let fb_accounts: Vec<Pubkey> = accounts
.iter()
.map(|account| Pubkey(account.to_bytes()))
.collect();
let fb_account_indexes: Vec<u8> = fb_accounts
.iter()
.enumerate()
.map(|(i, _)| i as u8)
.collect();

// We are only using this to get the instruction data, so the accounts don't actually matter
// here.
let mut accounts_iter = accounts.iter();
let ix = mpl_bubblegum::instructions::Transfer {
tree_config: *accounts_iter.next().unwrap(),
leaf_owner: (*accounts_iter.next().unwrap(), true),
leaf_delegate: (*accounts_iter.next().unwrap(), false),
merkle_tree: *accounts_iter.next().unwrap(),
log_wrapper: *accounts_iter.next().unwrap(),
compression_program: *accounts_iter.next().unwrap(),
system_program: *accounts_iter.next().unwrap(),
new_leaf_owner: *accounts_iter.next().unwrap(),
};
let ix_data = ix
.instruction(TransferInstructionArgs {
root: [0; 32],
data_hash: [0; 32],
creator_hash: [0; 32],
nonce: 0,
index: 0,
})
.data;

let lse = mpl_bubblegum::state::leaf_schema::LeafSchemaEvent {
let lse = LeafSchemaEvent {
event_type: BubblegumEventType::LeafSchemaEvent,
version: Version::V1,
schema: LeafSchema::V1 {
Expand All @@ -183,13 +188,6 @@ fn test_basic_success_parsing() {
leaf_hash: [0; 32],
};

let lse_versioned = ApplicationDataEventV1 {
application_data: lse.try_to_vec().unwrap(),
};

let _lse_event =
AccountCompressionEvent::ApplicationData(ApplicationDataEvent::V1(lse_versioned));

let cs = ChangeLogEvent::new(
random_pubkey(),
vec![PathNode {
Expand All @@ -199,11 +197,9 @@ fn test_basic_success_parsing() {
0,
0,
);

let cs_event = AccountCompressionEvent::ChangeLog(cs);
let ix_data = ix.data();

let mut ix_b = InstructionBundle::default();
// this is horrifying, we need to re write the flatbuffers sdk
let mut fbb1 = FlatBufferBuilder::new();
let mut fbb2 = FlatBufferBuilder::new();
let mut fbb3 = FlatBufferBuilder::new();
Expand All @@ -214,8 +210,8 @@ fn test_basic_success_parsing() {
&mut fbb2,
&mut fbb3,
&mut fbb4,
&accounts,
&account_indexes,
&fb_accounts,
&fb_account_indexes,
&ix_data,
lse,
cs_event,
Expand Down
5 changes: 2 additions & 3 deletions blockbuster/tests/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use blockbuster::{
};
use borsh::ser::BorshSerialize;
use flatbuffers::{FlatBufferBuilder, WIPOffset};
pub use mpl_bubblegum::id as program_id;
use mpl_bubblegum::state::leaf_schema::LeafSchemaEvent;
use mpl_bubblegum::LeafSchemaEvent;
use plerkle_serialization::{
root_as_account_info, root_as_compiled_instruction,
serializer::seralize_encoded_transaction_with_status, AccountInfo, AccountInfoArgs,
Expand Down Expand Up @@ -299,7 +298,7 @@ pub fn build_bubblegum_bundle<'a>(

let inner_ix = vec![noop_bgum_ix, gummy_roll_ix, noop_compression_ix];

ixb.program = FBPubkey(program_id().to_bytes());
ixb.program = FBPubkey(mpl_bubblegum::ID.to_bytes());
ixb.inner_ix = Some(inner_ix);
ixb.keys = accounts.as_slice();
ixb.instruction = Some(outer_ix);
Expand Down
8 changes: 4 additions & 4 deletions blockbuster/tests/instructions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn helium_nested() {
let txn = prepare_fixture(fbb, "helium_nested");
let txn = root_as_transaction_info(txn.finished_data()).expect("Fail deser");
let mut prog = HashSet::new();
let id = mpl_bubblegum::id();
let id = mpl_bubblegum::ID;
let slot = txn.slot();
prog.insert(id.as_ref());
let res = order_instructions(prog, &txn);
Expand All @@ -74,7 +74,7 @@ fn helium_nested() {

let contains = res
.iter()
.any(|(ib, _inner)| ib.0 .0.as_ref() == mpl_bubblegum::id().as_ref());
.any(|(ib, _inner)| ib.0 .0.as_ref() == mpl_bubblegum::ID.as_ref());
assert!(contains, "Must containe bgum at hoisted root");
let subject = BubblegumParser {};
for (outer_ix, inner_ix) in res.into_iter() {
Expand Down Expand Up @@ -130,7 +130,7 @@ fn test_double_mint() {
assert_eq!(ix.len(), 2);
let contains = ix
.iter()
.filter(|(ib, _inner)| ib.0 .0.as_ref() == mpl_bubblegum::id().as_ref());
.filter(|(ib, _inner)| ib.0 .0.as_ref() == mpl_bubblegum::ID.as_ref());
let mut count = 0;
contains.for_each(|bix| {
count += 1;
Expand Down Expand Up @@ -178,7 +178,7 @@ fn test_double_tree() {
let ix = order_instructions(programs, &txn);
let contains = ix
.iter()
.filter(|(ib, _inner)| ib.0 .0.as_ref() == mpl_bubblegum::id().as_ref());
.filter(|(ib, _inner)| ib.0 .0.as_ref() == mpl_bubblegum::ID.as_ref());
let mut count = 0;
contains.for_each(|bix| {
if let Some(inner) = &bix.1 {
Expand Down

0 comments on commit 50f96a0

Please sign in to comment.