use alloc::vec::Vec;
use miden_protocol::account::component::AccountComponentMetadata;
use miden_protocol::account::{
AccountCode,
AccountComponent,
AccountStorage,
AccountType,
StorageSlot,
};
use crate::testing::mock_account_code::MockAccountCodeExt;
pub struct MockAccountComponent {
storage_slots: Vec<StorageSlot>,
}
impl MockAccountComponent {
pub fn with_empty_slots() -> Self {
Self::new(vec![])
}
pub fn with_slots(storage_slots: Vec<StorageSlot>) -> Self {
Self::new(storage_slots)
}
fn new(storage_slots: Vec<StorageSlot>) -> Self {
debug_assert!(
storage_slots.len() <= AccountStorage::MAX_NUM_STORAGE_SLOTS,
"too many storage slots passed to MockAccountComponent"
);
Self { storage_slots }
}
}
impl From<MockAccountComponent> for AccountComponent {
fn from(mock_component: MockAccountComponent) -> Self {
let metadata =
AccountComponentMetadata::new("miden::testing::mock_account", AccountType::all())
.with_description("Mock account component for testing");
AccountComponent::new(
AccountCode::mock_account_library(),
mock_component.storage_slots,
metadata,
)
.expect(
"mock account component should satisfy the requirements of a valid account component",
)
}
}