Skip to content

Commit

Permalink
feat: use bubblegum batch mint sdk for batch mint verification (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
n00m4d authored Aug 19, 2024
1 parent d37f4c9 commit dc14c21
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 887 deletions.
1 change: 1 addition & 0 deletions blockbuster/blockbuster/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ spl-pod = { version = "0.1.0", features = ["serde-traits"] }
serde = "1.0.140"
solana-zk-token-sdk = "~1.18.11"
anchor-lang = { version = "0.29.0" }
bubblegum-batch-sdk = { workspace = true }

[dev-dependencies]
flatbuffers = "23.1.21"
Expand Down
23 changes: 22 additions & 1 deletion blockbuster/blockbuster/src/programs/bubblegum/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{
programs::ProgramParseResult,
};
use borsh::{BorshDeserialize, BorshSerialize};
use bubblegum_batch_sdk::model::BatchMintInstruction;
use log::warn;
use mpl_bubblegum::{
get_instruction_type,
Expand All @@ -13,7 +14,7 @@ use mpl_bubblegum::{
UnverifyCreatorInstructionArgs, UpdateMetadataInstructionArgs,
VerifyCreatorInstructionArgs,
},
types::{BubblegumEventType, MetadataArgs, UpdateArgs},
types::{BubblegumEventType, MetadataArgs, UpdateArgs, Version},
};
pub use mpl_bubblegum::{
types::{LeafSchema, UseMethod},
Expand Down Expand Up @@ -97,6 +98,26 @@ pub struct BubblegumInstruction {
pub payload: Option<Payload>,
}

impl From<&BatchMintInstruction> for BubblegumInstruction {
fn from(value: &BatchMintInstruction) -> Self {
let hash = value.leaf_update.hash();
Self {
instruction: InstructionName::MintV1,
tree_update: Some((&value.tree_update).into()),
leaf_update: Some(LeafSchemaEvent::new(
Version::V1,
value.leaf_update.clone(),
hash,
)),
payload: Some(Payload::MintV1 {
args: value.mint_args.clone(),
authority: value.authority,
tree_id: value.tree_update.id,
}),
}
}
}

impl BubblegumInstruction {
pub fn new(ix: InstructionName) -> Self {
BubblegumInstruction {
Expand Down
19 changes: 14 additions & 5 deletions integration_tests/tests/integration_tests/batch_mint_tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::common::TestSetup;
use borsh::BorshSerialize;
use bubblegum_batch_sdk::batch_mint_client::BatchMintClient;
use bubblegum_batch_sdk::batch_mint_validations::generate_batch_mint;
use bubblegum_batch_sdk::model::BatchMint;
use bubblegum_batch_sdk::model::CollectionConfig;
use cadence::{NopMetricSink, StatsdClient};
use cadence_macros::set_global_default;
Expand All @@ -19,9 +21,8 @@ use nft_ingester::plerkle::PlerkleTransactionInfo;
use plerkle_serialization::root_as_transaction_info;
use plerkle_serialization::serializer::serialize_transaction;
use program_transformers::batch_minting::batch_mint_persister::{
BatchMint, BatchMintPersister, MockBatchMintDownloader,
BatchMintPersister, MockBatchMintDownloader,
};
use program_transformers::batch_minting::tests::generate_batch_mint;
use program_transformers::error::BatchMintValidationError;
use sea_orm::sea_query::OnConflict;
use sea_orm::{ColumnTrait, ConnectionTrait, DbBackend, IntoActiveModel, QueryTrait, Set};
Expand Down Expand Up @@ -193,7 +194,7 @@ async fn batch_mint_persister_test() {
set_global_default(client);

let setup = TestSetup::new("batch_mint_persister_test".to_string()).await;
let test_batch_mint = generate_batch_mint(10, false);
let test_batch_mint = generate_batch_mint(10);
let tmp_dir = tempfile::TempDir::new().unwrap();

let tmp_file = File::create(tmp_dir.path().join("batch-mint-10.json")).unwrap();
Expand Down Expand Up @@ -321,7 +322,7 @@ async fn batch_mint_persister_download_fail_test() {
set_global_default(client);

let setup = TestSetup::new("batch_mint_persister_download_fail_test".to_string()).await;
let test_batch_mint = generate_batch_mint(10, false);
let test_batch_mint = generate_batch_mint(10);
let tmp_dir = tempfile::TempDir::new().unwrap();
let tmp_file = File::create(tmp_dir.path().join("batch-mint-10.json")).unwrap();
serde_json::to_writer(tmp_file, &test_batch_mint).unwrap();
Expand Down Expand Up @@ -552,7 +553,15 @@ async fn batch_mint_with_unverified_creators_test() {
// generate batch mint with creators verified value set to true
// but signatures will not be attached
// batch should not be saved
let test_batch_mint = generate_batch_mint(10, true);
let mut test_batch_mint = generate_batch_mint(10);

// set creators verified to true for this test case
for b_mint in test_batch_mint.batch_mints.iter_mut() {
for creator in b_mint.mint_args.creators.iter_mut() {
creator.verified = true;
}
}

let tmp_dir = tempfile::TempDir::new().unwrap();

let tmp_file = File::create(tmp_dir.path().join("batch-mint-10.json")).unwrap();
Expand Down
Loading

0 comments on commit dc14c21

Please sign in to comment.