1
- use core :: clone :: Clone ;
2
- use core :: serde :: Serde ;
3
- use core :: traits :: TryInto ;
4
- use starknet :: {ContractAddress , ClassHash , testing :: cheatcode, SyscallResult };
1
+ use starknet :: {ContractAddress , ClassHash , SyscallResult };
5
2
use super :: super :: byte_array :: byte_array_as_felt_array;
6
- use super :: super :: _cheatcode :: handle_cheatcode;
7
- use core :: traits :: Into ;
3
+ use super :: super :: _cheatcode :: execute_cheatcode_and_deserialize;
8
4
9
5
#[derive(Drop , Serde , Copy )]
10
6
pub struct ContractClass {
@@ -64,19 +60,15 @@ impl ContractClassImpl of ContractClassTrait {
64
60
) -> ContractAddress {
65
61
let mut inputs = _prepare_calldata (self . class_hash, constructor_calldata );
66
62
67
- let mut outputs = handle_cheatcode (cheatcode :: <' precalculate_address' >(inputs . span ()));
68
-
69
- Serde :: deserialize (ref outputs ). unwrap ()
63
+ execute_cheatcode_and_deserialize :: <' precalculate_address' >(inputs . span ())
70
64
}
71
65
72
66
fn deploy (
73
67
self : @ ContractClass , constructor_calldata : @ Array :: <felt252 >
74
68
) -> SyscallResult <(ContractAddress , Span <felt252 >)> {
75
69
let mut inputs = _prepare_calldata (self . class_hash, constructor_calldata );
76
70
77
- let mut outputs = handle_cheatcode (cheatcode :: <' deploy' >(inputs . span ()));
78
-
79
- Serde :: deserialize (ref outputs ). unwrap ()
71
+ execute_cheatcode_and_deserialize :: <' deploy' >(inputs . span ())
80
72
}
81
73
82
74
fn deploy_at (
@@ -87,9 +79,7 @@ impl ContractClassImpl of ContractClassTrait {
87
79
let mut inputs = _prepare_calldata (self . class_hash, constructor_calldata );
88
80
inputs . append (contract_address . into ());
89
81
90
- let mut outputs = handle_cheatcode (cheatcode :: <' deploy_at' >(inputs . span ()));
91
-
92
- Serde :: deserialize (ref outputs ). unwrap ()
82
+ execute_cheatcode_and_deserialize :: <' deploy_at' >(inputs . span ())
93
83
}
94
84
95
85
fn new <T , + Into <T , ClassHash >>(class_hash : T ) -> ContractClass {
@@ -121,22 +111,14 @@ impl DeclareResultImpl of DeclareResultTrait {
121
111
/// - `AlreadyDeclared`: Contains `ContractClass` and signals that the contract has already been
122
112
/// declared.
123
113
pub fn declare (contract : ByteArray ) -> Result <DeclareResult , Array <felt252 >> {
124
- let mut span = handle_cheatcode (
125
- cheatcode :: <' declare' >(byte_array_as_felt_array (@ contract ). span ())
126
- );
127
-
128
- Serde :: deserialize (ref span ). unwrap ()
114
+ execute_cheatcode_and_deserialize :: <' declare' >(byte_array_as_felt_array (@ contract ). span ())
129
115
}
130
116
131
117
/// Retrieves a class hash of a contract deployed under the given address
132
118
/// `contract_address` - target contract address
133
119
/// Returns the `ClassHash` under given address
134
120
pub fn get_class_hash (contract_address : ContractAddress ) -> ClassHash {
135
- let mut span = handle_cheatcode (
136
- cheatcode :: <' get_class_hash' >(array! [contract_address . into ()]. span ())
137
- );
138
-
139
- Serde :: deserialize (ref span ). unwrap ()
121
+ execute_cheatcode_and_deserialize :: <' get_class_hash' >(array! [contract_address . into ()]. span ())
140
122
}
141
123
142
124
fn _prepare_calldata (
0 commit comments