Test of DonationBox example fails

I’m following the Radix DLT tutorial about User Badge Pattern

I created the project with scrypto new-package and used the example code for the Component (DonationBox), and ajusted the test to use it:

#[test]
fn test_component() {
    // Setup the environment
    let mut ledger = LedgerSimulatorBuilder::new().build();

    // Create an account
    let (public_key, _private_key, _account) = ledger.new_allocated_account();

    // Publish package
    let package_address = ledger.compile_and_publish(this_package!());

    // Test the `instantiate_donations_box` function.
    let manifest = ManifestBuilder::new()
        .lock_fee_from_faucet()
        .call_function(
            package_address,
            "DonationsBox",
            "instantiate_donations_box",
            manifest_args!(),
        )
        .build();
    let receipt = ledger.execute_manifest(
        manifest,
        vec![NonFungibleGlobalId::from_public_key(&public_key)],
    );
    println!("{:?}\n", receipt);
    let _component = receipt.expect_commit(true).new_component_addresses()[0];
}

It fails with this error:

thread ‘test_component’ panicked at C:\Users\user_1.cargo\registry\src\index.crates.io-6f17d22bba15001f\radix-engine-1.2.0\src\transaction\transaction_receipt.rs:434:13:
Expected success but was failure: Failure(ApplicationError(FungibleResourceManagerError(DropNonEmptyBucket)))

Why?
How to call the function in the test to avoid DropNonEmptyBucket?

1 Like