use fuel_tx as tx;
use fuel_vm::{self as vm};
pub type ContractDeploymentSetup = (tx::ContractId, vm::checked_transaction::Checked<tx::Create>);
#[derive(Debug, Clone)]
pub enum DeploymentSetup {
Script(ScriptTestSetup),
Contract(ContractTestSetup),
}
impl DeploymentSetup {
fn storage(&self) -> &vm::storage::MemoryStorage {
match self {
DeploymentSetup::Script(script_setup) => &script_setup.storage,
DeploymentSetup::Contract(contract_setup) => &contract_setup.storage,
}
}
fn root_contract_id(&self) -> Option<tx::ContractId> {
match self {
DeploymentSetup::Script(_) => None,
DeploymentSetup::Contract(contract_setup) => Some(contract_setup.root_contract_id),
}
}
}
#[derive(Debug, Clone)]
pub enum TestSetup {
WithDeployment(DeploymentSetup),
WithoutDeployment(vm::storage::MemoryStorage),
}
impl TestSetup {
pub fn storage(&self) -> &vm::storage::MemoryStorage {
match self {
TestSetup::WithDeployment(deployment_setup) => deployment_setup.storage(),
TestSetup::WithoutDeployment(storage) => storage,
}
}
pub fn contract_dependency_ids(&self) -> impl Iterator<Item = &tx::ContractId> + '_ {
match self {
TestSetup::WithDeployment(deployment_setup) => match deployment_setup {
DeploymentSetup::Script(script_setup) => {
script_setup.contract_dependency_ids.iter()
}
DeploymentSetup::Contract(contract_setup) => {
contract_setup.contract_dependency_ids.iter()
}
},
TestSetup::WithoutDeployment(_) => [].iter(),
}
}
pub fn root_contract_id(&self) -> Option<tx::ContractId> {
match self {
TestSetup::WithDeployment(deployment_setup) => deployment_setup.root_contract_id(),
TestSetup::WithoutDeployment(_) => None,
}
}
pub fn contract_ids(&self) -> impl Iterator<Item = tx::ContractId> + '_ {
self.contract_dependency_ids()
.cloned()
.chain(self.root_contract_id())
}
}
#[derive(Debug, Clone)]
pub struct ContractTestSetup {
pub storage: vm::storage::MemoryStorage,
pub contract_dependency_ids: Vec<tx::ContractId>,
pub root_contract_id: tx::ContractId,
}
#[derive(Debug, Clone)]
pub struct ScriptTestSetup {
pub storage: vm::storage::MemoryStorage,
pub contract_dependency_ids: Vec<tx::ContractId>,
}