@@ -2,13 +2,15 @@ use assertions::ClassHashAssert;
2
2
use blockifier:: execution:: call_info:: CallInfo ;
3
3
use blockifier:: execution:: contract_class:: TrackedResource ;
4
4
use blockifier:: execution:: entry_point:: {
5
- CallEntryPoint , CallType , EntryPointExecutionContext , EntryPointExecutionResult ,
5
+ CallEntryPoint , CallType , ConstructorContext , EntryPointExecutionContext ,
6
+ EntryPointExecutionResult ,
6
7
} ;
7
8
use blockifier:: execution:: execution_utils:: ReadOnlySegments ;
8
9
use blockifier:: execution:: syscalls:: hint_processor:: SyscallHintProcessor ;
9
10
use blockifier:: state:: state_api:: State ;
10
11
use cairo_lang_casm:: hints:: Hint ;
11
12
use cairo_vm:: types:: relocatable:: Relocatable ;
13
+ use cheatnet:: runtime_extensions:: call_to_blockifier_runtime_extension:: execution:: cheated_syscalls;
12
14
use cheatnet:: runtime_extensions:: call_to_blockifier_runtime_extension:: execution:: entry_point:: execute_call_entry_point;
13
15
use cheatnet:: runtime_extensions:: call_to_blockifier_runtime_extension:: rpc:: {
14
16
AddressOrClassHash , call_entry_point,
@@ -19,9 +21,7 @@ use cheatnet::runtime_extensions::call_to_blockifier_runtime_extension::rpc::{
19
21
use cheatnet:: runtime_extensions:: common:: create_execute_calldata;
20
22
use cheatnet:: runtime_extensions:: forge_runtime_extension:: cheatcodes:: CheatcodeError ;
21
23
use cheatnet:: runtime_extensions:: forge_runtime_extension:: cheatcodes:: declare:: declare;
22
- use cheatnet:: runtime_extensions:: forge_runtime_extension:: cheatcodes:: deploy:: {
23
- deploy, deploy_at,
24
- } ;
24
+ use cheatnet:: runtime_extensions:: forge_runtime_extension:: cheatcodes:: deploy:: deploy_at;
25
25
use cheatnet:: runtime_extensions:: forge_runtime_extension:: contracts_data:: ContractsData ;
26
26
use cheatnet:: state:: CheatnetState ;
27
27
use conversions:: IntoConv ;
@@ -36,8 +36,10 @@ use scarb_api::{
36
36
use starknet:: core:: utils:: get_selector_from_name;
37
37
use starknet_api:: contract_class:: EntryPointType ;
38
38
use starknet_api:: core:: { ClassHash , ContractAddress , EntryPointSelector } ;
39
+ use starknet_api:: transaction:: fields:: Calldata ;
39
40
use starknet_types_core:: felt:: Felt ;
40
41
use std:: collections:: HashMap ;
42
+ use std:: sync:: Arc ;
41
43
42
44
pub mod assertions;
43
45
pub mod cache;
@@ -116,23 +118,23 @@ pub fn deploy_contract(
116
118
& hints,
117
119
) ;
118
120
119
- let ( contract_address, _retdata ) = deploy (
121
+ let ( contract_address, _ ) = deploy_helper (
120
122
& mut syscall_hint_processor,
121
123
cheatnet_state,
122
124
& class_hash,
125
+ None ,
123
126
calldata,
124
- )
125
- . unwrap ( ) ;
127
+ ) ;
126
128
127
129
contract_address
128
130
}
129
131
130
- pub fn deploy_wrapper (
132
+ pub fn deploy (
131
133
state : & mut dyn State ,
132
134
cheatnet_state : & mut CheatnetState ,
133
135
class_hash : & ClassHash ,
134
136
calldata : & [ Felt ] ,
135
- ) -> Result < ContractAddress , CheatcodeError > {
137
+ ) -> ContractAddress {
136
138
let mut entry_point_execution_context = build_context (
137
139
& cheatnet_state. block_info ,
138
140
None ,
@@ -147,14 +149,15 @@ pub fn deploy_wrapper(
147
149
& hints,
148
150
) ;
149
151
150
- let ( contract_address, _retdata ) = deploy (
152
+ let ( contract_address, _ ) = deploy_helper (
151
153
& mut syscall_hint_processor,
152
154
cheatnet_state,
153
155
class_hash,
156
+ None ,
154
157
calldata,
155
- ) ? ;
158
+ ) ;
156
159
157
- Ok ( contract_address)
160
+ contract_address
158
161
}
159
162
160
163
pub fn deploy_at_wrapper (
@@ -189,6 +192,41 @@ pub fn deploy_at_wrapper(
189
192
Ok ( contract_address)
190
193
}
191
194
195
+ fn deploy_helper (
196
+ syscall_handler : & mut SyscallHintProcessor ,
197
+ cheatnet_state : & mut CheatnetState ,
198
+ class_hash : & ClassHash ,
199
+ contract_address : Option < ContractAddress > ,
200
+ calldata : & [ Felt ] ,
201
+ ) -> ( ContractAddress , Vec < cairo_vm:: Felt252 > ) {
202
+ let contract_address = contract_address
203
+ . unwrap_or_else ( || cheatnet_state. precalculate_address ( class_hash, calldata) ) ;
204
+ let calldata = Calldata ( Arc :: new ( calldata. to_vec ( ) ) ) ;
205
+
206
+ let ctor_context = ConstructorContext {
207
+ class_hash : * class_hash,
208
+ code_address : Some ( contract_address) ,
209
+ storage_address : contract_address,
210
+ caller_address : TryFromHexStr :: try_from_hex_str ( TEST_ADDRESS ) . unwrap ( ) ,
211
+ } ;
212
+
213
+ let call_info = cheated_syscalls:: execute_deployment (
214
+ syscall_handler. base . state ,
215
+ cheatnet_state,
216
+ syscall_handler. base . context ,
217
+ & ctor_context,
218
+ calldata,
219
+ i64:: MAX as u64 ,
220
+ )
221
+ . unwrap ( ) ;
222
+ cheatnet_state. increment_deploy_salt_base ( ) ;
223
+
224
+ let retdata = call_info. execution . retdata . 0 . clone ( ) ;
225
+ syscall_handler. base . inner_calls . push ( call_info) ;
226
+
227
+ ( contract_address, retdata)
228
+ }
229
+
192
230
// This does contract call without the transaction layer. This way `call_contract` can return data and modify state.
193
231
// `call` and `invoke` on the transactional layer use such method under the hood.
194
232
pub fn call_contract (
0 commit comments