diff --git a/programs/bubblegum/program/tests/collection.rs b/programs/bubblegum/program/tests/collection.rs index e4ac096e..2797dc03 100644 --- a/programs/bubblegum/program/tests/collection.rs +++ b/programs/bubblegum/program/tests/collection.rs @@ -1,13 +1,15 @@ #![cfg(feature = "test-sbf")] pub mod utils; +use anchor_lang::solana_program::instruction::InstructionError; +use bubblegum::error::BubblegumError; use solana_program::native_token::LAMPORTS_PER_SOL; -use solana_program_test::tokio; +use solana_program_test::{tokio, BanksClientError}; -use solana_sdk::{signature::Keypair, signer::Signer}; +use solana_sdk::{signature::Keypair, signer::Signer, transaction::TransactionError}; use utils::context::BubblegumTestContext; -use crate::utils::{Airdrop, DirtyClone}; +use crate::utils::{Airdrop, DirtyClone, Error::BanksClient}; // Test for multiple combinations? const MAX_DEPTH: usize = 14; @@ -80,7 +82,7 @@ async fn verify_collection_with_old_delegate() { } #[tokio::test] -async fn verify_collection_with_new_delegate() { +async fn verify_collection_with_new_collection_delegate() { // Uses MetadataDelegate to verify a collection item. let mut context = BubblegumTestContext::new().await.unwrap(); @@ -131,3 +133,73 @@ async fn verify_collection_with_new_delegate() { .await .unwrap(); } + +#[tokio::test] +async fn cannot_verify_collection_with_new_data_delegate() { + // Attempts to use MetadataDelegate with incorrect role to verify a collection item. + + let mut context = BubblegumTestContext::new().await.unwrap(); + + let (mut tree, mut leaves) = context + .default_create_and_mint::(DEFAULT_NUM_MINTS) + .await + .unwrap(); + + let payer = context.payer().dirty_clone(); + + // Set up our old delegate record: collection_authority_record. + let delegate = Keypair::new(); + delegate + .airdrop(context.mut_test_context(), LAMPORTS_PER_SOL) + .await + .unwrap(); + + let mut collection_asset = context.default_collection.dirty_clone(); + let mut program_context = context.owned_test_context(); + + let args = mpl_token_metadata::types::DelegateArgs::DataV1 { + authorization_data: None, + }; + + let record = collection_asset + .delegate( + &mut program_context, + payer.dirty_clone(), + delegate.pubkey(), + args, + ) + .await + .unwrap() + .unwrap(); + + // Get the first leaf and try to verify it with the delegate as the authority. + let leaf = leaves.first_mut().unwrap(); + + // Cannot verify collection. + let result = tree + .delegate_verify_collection( + leaf, + &delegate, + collection_asset.mint.pubkey(), + collection_asset.metadata, + collection_asset.edition.unwrap(), + record, + ) + .await; + + if let Err(err) = result { + if let BanksClient(BanksClientError::TransactionError(e)) = *err { + assert_eq!( + e, + TransactionError::InstructionError( + 0, + InstructionError::Custom(BubblegumError::InvalidDelegateRecord.into()), + ) + ); + } else { + panic!("Wrong variant"); + } + } else { + panic!("Should have failed"); + } +}