1use fuel_tx as tx;
2use fuel_vm::{self as vm};
3
4pub type ContractDeploymentSetup = (tx::ContractId, vm::checked_transaction::Checked<tx::Create>);
6
7#[derive(Debug, Clone)]
9pub enum DeploymentSetup {
10 Script(ScriptTestSetup),
11 Contract(ContractTestSetup),
12}
13
14impl DeploymentSetup {
15 fn storage(&self) -> &vm::storage::MemoryStorage {
17 match self {
18 DeploymentSetup::Script(script_setup) => &script_setup.storage,
19 DeploymentSetup::Contract(contract_setup) => &contract_setup.storage,
20 }
21 }
22
23 fn root_contract_id(&self) -> Option<tx::ContractId> {
25 match self {
26 DeploymentSetup::Script(_) => None,
27 DeploymentSetup::Contract(contract_setup) => Some(contract_setup.root_contract_id),
28 }
29 }
30}
31
32#[derive(Debug, Clone)]
34pub enum TestSetup {
35 WithDeployment(DeploymentSetup),
36 WithoutDeployment(vm::storage::MemoryStorage),
37}
38
39impl TestSetup {
40 pub fn storage(&self) -> &vm::storage::MemoryStorage {
42 match self {
43 TestSetup::WithDeployment(deployment_setup) => deployment_setup.storage(),
44 TestSetup::WithoutDeployment(storage) => storage,
45 }
46 }
47
48 pub fn contract_dependency_ids(&self) -> impl Iterator<Item = &tx::ContractId> + '_ {
50 match self {
51 TestSetup::WithDeployment(deployment_setup) => match deployment_setup {
52 DeploymentSetup::Script(script_setup) => {
53 script_setup.contract_dependency_ids.iter()
54 }
55 DeploymentSetup::Contract(contract_setup) => {
56 contract_setup.contract_dependency_ids.iter()
57 }
58 },
59 TestSetup::WithoutDeployment(_) => [].iter(),
60 }
61 }
62
63 pub fn root_contract_id(&self) -> Option<tx::ContractId> {
65 match self {
66 TestSetup::WithDeployment(deployment_setup) => deployment_setup.root_contract_id(),
67 TestSetup::WithoutDeployment(_) => None,
68 }
69 }
70
71 pub fn contract_ids(&self) -> impl Iterator<Item = tx::ContractId> + '_ {
74 self.contract_dependency_ids()
75 .cloned()
76 .chain(self.root_contract_id())
77 }
78}
79
80#[derive(Debug, Clone)]
82pub struct ContractTestSetup {
83 pub storage: vm::storage::MemoryStorage,
84 pub contract_dependency_ids: Vec<tx::ContractId>,
85 pub root_contract_id: tx::ContractId,
86}
87
88#[derive(Debug, Clone)]
90pub struct ScriptTestSetup {
91 pub storage: vm::storage::MemoryStorage,
92 pub contract_dependency_ids: Vec<tx::ContractId>,
93}