1
1
use reqwest:: StatusCode ;
2
2
use serde_json:: json;
3
- use starknet_rs_core:: types:: { BlockId , BlockTag , Felt } ;
4
- use starknet_rs_core:: utils:: { get_storage_var_address, parse_cairo_short_string} ;
3
+ use starknet_rs_core:: codec:: Decode ;
4
+ use starknet_rs_core:: types:: { BlockId , BlockTag , ByteArray , Felt , FunctionCall } ;
5
+ use starknet_rs_core:: utils:: { get_selector_from_name, get_storage_var_address} ;
5
6
use starknet_rs_providers:: Provider ;
6
7
7
8
use crate :: common:: background_devnet:: BackgroundDevnet ;
@@ -186,14 +187,14 @@ async fn test_config() {
186
187
assert_eq ! ( fetched_config, expected_config) ;
187
188
}
188
189
190
+ /// Part of the responsibility of this test was transferred to test
191
+ /// `predeployed_erc20_tokens_return_expected_values_from_property_getters`
189
192
#[ tokio:: test]
190
193
async fn predeployed_erc20_tokens_have_expected_storage ( ) {
191
194
let devnet = BackgroundDevnet :: spawn ( ) . await . unwrap ( ) ;
192
195
for ( token_address, var_name, expected_value) in [
193
- ( ETH_ERC20_CONTRACT_ADDRESS , "ERC20_name" , "Ether" ) ,
194
- ( ETH_ERC20_CONTRACT_ADDRESS , "ERC20_symbol" , "ETH" ) ,
195
- ( STRK_ERC20_CONTRACT_ADDRESS , "ERC20_name" , "StarkNet Token" ) ,
196
- ( STRK_ERC20_CONTRACT_ADDRESS , "ERC20_symbol" , "STRK" ) ,
196
+ ( ETH_ERC20_CONTRACT_ADDRESS , "ERC20_decimals" , Felt :: from ( 18 ) ) ,
197
+ ( STRK_ERC20_CONTRACT_ADDRESS , "ERC20_decimals" , Felt :: from ( 18 ) ) ,
197
198
] {
198
199
let actual_value = devnet
199
200
. json_rpc_client
@@ -205,6 +206,34 @@ async fn predeployed_erc20_tokens_have_expected_storage() {
205
206
. await
206
207
. unwrap ( ) ;
207
208
208
- assert_eq ! ( parse_cairo_short_string( & actual_value) . unwrap( ) . as_str( ) , expected_value) ;
209
+ assert_eq ! ( actual_value, expected_value) ;
210
+ }
211
+ }
212
+
213
+ #[ tokio:: test]
214
+ async fn predeployed_erc20_tokens_return_expected_values_from_property_getters ( ) {
215
+ let devnet = BackgroundDevnet :: spawn ( ) . await . unwrap ( ) ;
216
+ for ( token_address, getter_name, expected_value) in [
217
+ ( ETH_ERC20_CONTRACT_ADDRESS , "name" , "Ether" ) ,
218
+ ( ETH_ERC20_CONTRACT_ADDRESS , "symbol" , "ETH" ) ,
219
+ ( STRK_ERC20_CONTRACT_ADDRESS , "name" , "StarkNet Token" ) ,
220
+ ( STRK_ERC20_CONTRACT_ADDRESS , "symbol" , "STRK" ) ,
221
+ ] {
222
+ let actual_felts = devnet
223
+ . json_rpc_client
224
+ . call (
225
+ FunctionCall {
226
+ contract_address : token_address,
227
+ entry_point_selector : get_selector_from_name ( getter_name) . unwrap ( ) ,
228
+ calldata : vec ! [ ] ,
229
+ } ,
230
+ BlockId :: Tag ( BlockTag :: Latest ) ,
231
+ )
232
+ . await
233
+ . unwrap ( ) ;
234
+
235
+ // We expect the felt vector to contain the encoded ByteArray, thus we decode it
236
+ let actual_string: String = ByteArray :: decode ( & actual_felts) . unwrap ( ) . try_into ( ) . unwrap ( ) ;
237
+ assert_eq ! ( & actual_string, expected_value) ;
209
238
}
210
239
}
0 commit comments