Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix starknet_getCompiledCasm #713

Merged
merged 3 commits into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion crates/starknet-devnet-core/src/starknet/get_class_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ pub fn get_compiled_casm_impl(
let contract_class = get_class_impl(starknet, &BlockId::Tag(BlockTag::Latest), class_hash)?;
match contract_class {
ContractClass::Cairo1(sierra_contract_class) => {
Ok(compile_sierra_contract(&sierra_contract_class)?)
let mut casm = compile_sierra_contract(&sierra_contract_class)?;
casm.pythonic_hints = None; // removes the extra key from serialized form
Ok(casm)
}
ContractClass::Cairo0(_) => Err(Error::StateError(StateError::NoneCasmClass(class_hash))),
}
Expand Down
20 changes: 10 additions & 10 deletions tests/integration/test_get_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ async fn test_getting_class_after_block_abortion() {
}

#[tokio::test]
async fn test_getting_compiled_casm_for_cairo0_or_non_existing_hash_have_to_return_class_hash_not_found_error()
async fn getting_compiled_casm_for_cairo0_or_non_existing_hash_should_return_class_hash_not_found_error()
{
let devnet = BackgroundDevnet::spawn_with_additional_args(&["--account-class", "cairo0"])
.await
Expand All @@ -280,15 +280,15 @@ async fn test_getting_compiled_casm_for_cairo0_or_non_existing_hash_have_to_retu

// Felt::ONE is non existing class hash
for el in [class_hash, Felt::ONE] {
match get_compiled_casm(&devnet, block_id, el).await.unwrap_err() {
match get_compiled_casm(&devnet, el).await.unwrap_err() {
StarknetError::ClassHashNotFound => {}
other => panic!("Unexpected error {:?}", other),
}
}
}

#[tokio::test]
async fn test_getting_compiled_casm_for_cairo_1_have_to_succeed() {
async fn getting_compiled_casm_for_cairo_1_should_succeed() {
let devnet = BackgroundDevnet::spawn_with_additional_args(&["--account-class", "cairo1"])
.await
.expect("Could not start Devnet");
Expand All @@ -303,25 +303,25 @@ async fn test_getting_compiled_casm_for_cairo_1_have_to_succeed() {
let class_hash =
devnet.json_rpc_client.get_class_hash_at(block_id, account_address).await.unwrap();

let casm = get_compiled_casm(&devnet, block_id, class_hash).await.unwrap();
let casm = get_compiled_casm(&devnet, class_hash).await.unwrap();
assert_eq!(casm.compiled_class_hash(), expected_casm_hash);
}

async fn get_compiled_casm(
devnet: &BackgroundDevnet,
block_id: BlockId,
class_hash: Felt,
) -> Result<CasmContractClass, StarknetError> {
devnet
.send_custom_rpc(
"starknet_getCompiledCasm",
serde_json::json!({
"block_id": block_id,
"class_hash": format!("{:#x}", class_hash),
}),
serde_json::json!({ "class_hash": class_hash }),
)
.await
.map(|json_value| serde_json::from_value::<CasmContractClass>(json_value).unwrap())
.map(|json_value| {
// Check done because `CasmContractClass` does not perfectly correspond to RPC spec
assert!(json_value.get("pythonic_hints").is_none());
serde_json::from_value::<CasmContractClass>(json_value).unwrap()
})
.map_err(|err| {
let json_rpc_error =
JsonRpcError { code: err.code, message: err.message.to_string(), data: err.data };
Expand Down