@@ -23,7 +23,9 @@ use tokio::task;
23
23
24
24
use crate :: config:: { StatefulTransactionValidatorConfig , StatelessTransactionValidatorConfig } ;
25
25
use crate :: errors:: GatewayError ;
26
- use crate :: gateway:: { add_tx, compile_contract_class, AppState , SharedMempoolClient } ;
26
+ use crate :: gateway:: {
27
+ add_tx, compile_contract_class, AppState , SharedMempoolClient , SierraToCasmCompilationConfig ,
28
+ } ;
27
29
use crate :: state_reader_test_utils:: {
28
30
local_test_state_reader_factory, local_test_state_reader_factory_for_deploy_account,
29
31
TestStateReaderFactory ,
@@ -33,6 +35,8 @@ use crate::stateless_transaction_validator::StatelessTransactionValidator;
33
35
use crate :: utils:: { external_tx_to_account_tx, get_tx_hash} ;
34
36
35
37
const MEMPOOL_INVOCATIONS_QUEUE_SIZE : usize = 32 ;
38
+ const SIERRA_TO_CASM_COMPILATION_CONFIG : SierraToCasmCompilationConfig =
39
+ SierraToCasmCompilationConfig { max_bytecode_size : usize:: MAX , max_raw_class_size : usize:: MAX } ;
36
40
37
41
#[ fixture]
38
42
fn mempool ( ) -> Mempool {
@@ -121,14 +125,57 @@ fn test_compile_contract_class_compiled_class_hash_missmatch() {
121
125
tx. compiled_class_hash = supplied_hash;
122
126
let declare_tx = RPCDeclareTransaction :: V3 ( tx) ;
123
127
124
- let result = compile_contract_class ( & declare_tx) ;
128
+ let result = compile_contract_class ( & declare_tx, SIERRA_TO_CASM_COMPILATION_CONFIG ) ;
125
129
assert_matches ! (
126
130
result. unwrap_err( ) ,
127
131
GatewayError :: CompiledClassHashMismatch { supplied, hash_result }
128
132
if supplied == supplied_hash && hash_result == expected_hash_result
129
133
) ;
130
134
}
131
135
136
+ #[ rstest]
137
+ #[ case:: bytecode_size(
138
+ SierraToCasmCompilationConfig { max_bytecode_size: 1 , max_raw_class_size: usize :: MAX } ,
139
+ GatewayError :: CasmBytecodeSizeTooLarge { bytecode_size: 4800 , max_bytecode_size: 1 }
140
+ ) ]
141
+ #[ case:: raw_class_size(
142
+ SierraToCasmCompilationConfig { max_bytecode_size: usize :: MAX , max_raw_class_size: 1 } ,
143
+ GatewayError :: CasmContractClassObjectSizeTooLarge {
144
+ contract_class_object_size: 111037 , max_contract_class_object_size: 1
145
+ }
146
+ ) ]
147
+ fn test_compile_contract_class_size_validation (
148
+ #[ case] sierra_to_casm_compilation_config : SierraToCasmCompilationConfig ,
149
+ #[ case] expected_error : GatewayError ,
150
+ ) {
151
+ let declare_tx = match declare_tx ( ) {
152
+ RPCTransaction :: Declare ( declare_tx) => declare_tx,
153
+ _ => panic ! ( "Invalid transaction type" ) ,
154
+ } ;
155
+
156
+ let result = compile_contract_class ( & declare_tx, sierra_to_casm_compilation_config) ;
157
+ if let GatewayError :: CasmBytecodeSizeTooLarge {
158
+ bytecode_size : expected_bytecode_size, ..
159
+ } = expected_error
160
+ {
161
+ assert_matches ! (
162
+ result. unwrap_err( ) ,
163
+ GatewayError :: CasmBytecodeSizeTooLarge { bytecode_size, .. }
164
+ if bytecode_size == expected_bytecode_size
165
+ )
166
+ } else if let GatewayError :: CasmContractClassObjectSizeTooLarge {
167
+ contract_class_object_size : expected_contract_class_object_size,
168
+ ..
169
+ } = expected_error
170
+ {
171
+ assert_matches ! (
172
+ result. unwrap_err( ) ,
173
+ GatewayError :: CasmContractClassObjectSizeTooLarge { contract_class_object_size, .. }
174
+ if contract_class_object_size == expected_contract_class_object_size
175
+ )
176
+ }
177
+ }
178
+
132
179
#[ test]
133
180
fn test_compile_contract_class_bad_sierra ( ) {
134
181
let mut tx = assert_matches ! (
@@ -139,7 +186,7 @@ fn test_compile_contract_class_bad_sierra() {
139
186
tx. contract_class . sierra_program = tx. contract_class . sierra_program [ ..100 ] . to_vec ( ) ;
140
187
let declare_tx = RPCDeclareTransaction :: V3 ( tx) ;
141
188
142
- let result = compile_contract_class ( & declare_tx) ;
189
+ let result = compile_contract_class ( & declare_tx, SIERRA_TO_CASM_COMPILATION_CONFIG ) ;
143
190
assert_matches ! (
144
191
result. unwrap_err( ) ,
145
192
GatewayError :: CompilationError ( CompilationUtilError :: AllowedLibfuncsError (
@@ -157,7 +204,8 @@ fn test_compile_contract_class() {
157
204
let RPCDeclareTransaction :: V3 ( declare_tx_v3) = & declare_tx;
158
205
let contract_class = & declare_tx_v3. contract_class ;
159
206
160
- let class_info = compile_contract_class ( & declare_tx) . unwrap ( ) ;
207
+ let class_info =
208
+ compile_contract_class ( & declare_tx, SIERRA_TO_CASM_COMPILATION_CONFIG ) . unwrap ( ) ;
161
209
assert_matches ! ( class_info. contract_class( ) , ContractClass :: V1 ( _) ) ;
162
210
assert_eq ! ( class_info. sierra_program_length( ) , contract_class. sierra_program. len( ) ) ;
163
211
assert_eq ! ( class_info. abi_length( ) , contract_class. abi. len( ) ) ;
@@ -169,7 +217,9 @@ async fn to_bytes(res: Response) -> Bytes {
169
217
170
218
fn calculate_hash ( external_tx : & RPCTransaction ) -> TransactionHash {
171
219
let optional_class_info = match & external_tx {
172
- RPCTransaction :: Declare ( declare_tx) => Some ( compile_contract_class ( declare_tx) . unwrap ( ) ) ,
220
+ RPCTransaction :: Declare ( declare_tx) => {
221
+ Some ( compile_contract_class ( declare_tx, SIERRA_TO_CASM_COMPILATION_CONFIG ) . unwrap ( ) )
222
+ }
173
223
_ => None ,
174
224
} ;
175
225
0 commit comments