use anyhow::Context;
use miden_protocol::asset::FungibleAsset;
use miden_protocol::{self, Felt, Word};
use miden_testing::{Auth, MockChain};
use crate::prove_and_verify_transaction;
#[tokio::test]
async fn prove_account_creation_with_fees() -> anyhow::Result<()> {
let amount = 10_000;
let mut builder = MockChain::builder().verification_base_fee(50);
let account = builder.create_new_wallet(Auth::IncrNonce)?;
let fee_note = builder.add_p2id_note_with_fee(account.id(), amount)?;
let chain = builder.build()?;
let tx = chain
.build_tx_context(account, &[fee_note.id()], &[])?
.build()?
.execute()
.await
.context("failed to execute account-creating transaction")?;
let expected_fee = tx.compute_fee();
assert_eq!(expected_fee, tx.fee().amount());
let added_asset = FungibleAsset::new(chain.native_asset_id(), amount)?.sub(tx.fee())?;
assert_eq!(tx.account_delta().nonce_delta(), Felt::new(1));
assert!(tx.account_delta().storage().is_empty());
assert_eq!(tx.account_delta().vault().added_assets().count(), 1);
assert_eq!(tx.account_delta().vault().removed_assets().count(), 0);
assert_eq!(tx.account_delta().vault().added_assets().next().unwrap(), added_asset.into());
assert_eq!(tx.final_account().nonce(), Felt::new(1));
assert_ne!(tx.account_delta().to_commitment(), Word::empty());
prove_and_verify_transaction(tx).await?;
Ok(())
}