Skip to content

Commit

Permalink
Box test utils err and remove RefCells from test objects
Browse files Browse the repository at this point in the history
  • Loading branch information
danenbm committed May 15, 2023
1 parent 98dea5c commit 48cbbed
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 125 deletions.
38 changes: 20 additions & 18 deletions bubblegum/program/tests/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub async fn context_tree_and_leaves() -> Result<(
async fn test_create_tree_and_mint_passes() {
// The mint operation implicitly called below also verifies that the on-chain tree
// root matches the expected value as leaves are added.
let (context, tree, _) = context_tree_and_leaves().await.unwrap();
let (context, mut tree, _) = context_tree_and_leaves().await.unwrap();

let payer = context.payer();

Expand All @@ -71,7 +71,7 @@ async fn test_create_tree_and_mint_passes() {

#[tokio::test]
async fn test_creator_verify_and_unverify_passes() {
let (context, tree, mut leaves) = context_tree_and_leaves().await.unwrap();
let (context, mut tree, mut leaves) = context_tree_and_leaves().await.unwrap();

// `verify_creator` and `unverify_creator` also validate the on-chain tree root
// always has the expected value via the inner `TxBuilder::execute` call.
Expand All @@ -91,7 +91,7 @@ async fn test_creator_verify_and_unverify_passes() {

#[tokio::test]
async fn test_delegate_passes() {
let (_, tree, mut leaves) = context_tree_and_leaves().await.unwrap();
let (_, mut tree, mut leaves) = context_tree_and_leaves().await.unwrap();
let new_delegate = Keypair::new();

// `delegate` also validates whether the on-chain tree root always has the expected
Expand All @@ -104,7 +104,7 @@ async fn test_delegate_passes() {

#[tokio::test]
async fn test_transfer_passes() {
let (_, tree, mut leaves) = context_tree_and_leaves().await.unwrap();
let (_, mut tree, mut leaves) = context_tree_and_leaves().await.unwrap();
let new_owner = Keypair::new();

// `transfer` also validates whether the on-chain tree root always has the expected
Expand All @@ -117,7 +117,7 @@ async fn test_transfer_passes() {

#[tokio::test]
async fn test_delegated_transfer_passes() {
let (mut context, tree, mut leaves) = context_tree_and_leaves().await.unwrap();
let (mut context, mut tree, mut leaves) = context_tree_and_leaves().await.unwrap();
let delegate = Keypair::new();
let new_owner = Keypair::new();

Expand All @@ -143,7 +143,7 @@ async fn test_delegated_transfer_passes() {

#[tokio::test]
async fn test_burn_passes() {
let (_, tree, leaves) = context_tree_and_leaves().await.unwrap();
let (_, mut tree, leaves) = context_tree_and_leaves().await.unwrap();

// `burn` also validates whether the on-chain tree root always has the expected
// value via the inner `TxBuilder::execute` call.
Expand All @@ -155,7 +155,7 @@ async fn test_burn_passes() {

#[tokio::test]
async fn test_set_tree_delegate_passes() {
let (context, tree, _) = context_tree_and_leaves().await.unwrap();
let (context, mut tree, _) = context_tree_and_leaves().await.unwrap();
let new_tree_delegate = Keypair::new();

// `set_tree_delegate` also validates whether the on-chain tree root always has the expected
Expand All @@ -175,7 +175,7 @@ async fn test_set_tree_delegate_passes() {

#[tokio::test]
async fn test_reedem_and_cancel_passes() {
let (_, tree, leaves) = context_tree_and_leaves().await.unwrap();
let (_, mut tree, leaves) = context_tree_and_leaves().await.unwrap();

// `redeem` and `cancel_redeem` also validate the on-chain tree root
// always has the expected value via the inner `TxBuilder::execute` call.
Expand All @@ -194,7 +194,7 @@ async fn test_reedem_and_cancel_passes() {

#[tokio::test]
async fn test_decompress_passes() {
let (ctx, tree, mut leaves) = context_tree_and_leaves().await.unwrap();
let (ctx, mut tree, mut leaves) = context_tree_and_leaves().await.unwrap();

for leaf in leaves.iter_mut() {
tree.verify_creator(leaf, &ctx.default_creators[0])
Expand Down Expand Up @@ -317,11 +317,11 @@ async fn test_create_public_tree_and_mint_passes() {
// The mint operation implicitly called below also verifies that the on-chain tree
// root matches the expected value as leaves are added.
let mut context = BubblegumTestContext::new().await.unwrap();
let tree = context
let mut tree = context
.create_public_tree::<MAX_DEPTH, MAX_BUF_SIZE>()
.await
.unwrap();
let tree_private = context
let mut tree_private = context
.default_create_tree::<MAX_DEPTH, MAX_BUF_SIZE>()
.await
.unwrap();
Expand All @@ -347,13 +347,15 @@ async fn test_create_public_tree_and_mint_passes() {
let cfg = tree.read_tree_config().await.unwrap();
assert_eq!(cfg.num_minted, 1);

if let Err(BanksClient(BanksClientError::TransactionError(e))) =
tree_private.mint_v1_non_owner(&minter, &mut args).await
{
assert_eq!(
e,
TransactionError::InstructionError(0, InstructionError::Custom(6016),)
);
if let Err(err) = tree_private.mint_v1_non_owner(&minter, &mut args).await {
if let BanksClient(BanksClientError::TransactionError(e)) = *err {
assert_eq!(
e,
TransactionError::InstructionError(0, InstructionError::Custom(6016),)
);
} else {
panic!("Wrong variant");
}
} else {
panic!("Should have failed");
}
Expand Down
8 changes: 4 additions & 4 deletions bubblegum/program/tests/utils/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl BubblegumTestContext {
.banks_client
.process_transaction(tx)
.await
.map_err(Error::BanksClient)
.map_err(|err| Box::new(Error::BanksClient(err)))
}

pub fn payer(&self) -> Keypair {
Expand Down Expand Up @@ -150,7 +150,7 @@ impl BubblegumTestContext {
&self,
) -> Result<Tree<MAX_DEPTH, MAX_BUFFER_SIZE>> {
let payer = self.payer();
let tree = Tree::<MAX_DEPTH, MAX_BUFFER_SIZE>::with_creator(&payer, self.client());
let mut tree = Tree::<MAX_DEPTH, MAX_BUFFER_SIZE>::with_creator(&payer, self.client());
tree.alloc(&payer).await?;
tree.create(&payer).await?;
Ok(tree)
Expand All @@ -160,7 +160,7 @@ impl BubblegumTestContext {
&self,
) -> Result<Tree<MAX_DEPTH, MAX_BUFFER_SIZE>> {
let payer = self.payer();
let tree = Tree::<MAX_DEPTH, MAX_BUFFER_SIZE>::with_creator(&payer, self.client());
let mut tree = Tree::<MAX_DEPTH, MAX_BUFFER_SIZE>::with_creator(&payer, self.client());
tree.alloc(&payer).await?;
tree.create_public(&payer).await?;
Ok(tree)
Expand All @@ -171,7 +171,7 @@ impl BubblegumTestContext {
&self,
num_mints: u64,
) -> Result<(Tree<MAX_DEPTH, MAX_BUFFER_SIZE>, Vec<LeafArgs>)> {
let tree = self
let mut tree = self
.default_create_tree::<MAX_DEPTH, MAX_BUFFER_SIZE>()
.await?;

Expand Down
2 changes: 1 addition & 1 deletion bubblegum/program/tests/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub enum Error {
Signer(SignerError),
}

pub type Result<T> = result::Result<T, Error>;
pub type Result<T> = result::Result<T, Box<Error>>;

pub fn program_test() -> ProgramTest {
let mut test = ProgramTest::new("mpl_bubblegum", mpl_bubblegum::id(), None);
Expand Down
Loading

0 comments on commit 48cbbed

Please sign in to comment.