Skip to content

Commit 774c0c6

Browse files
authored
Add new tests: cairo0 non-existent method, fork call (#693)
1 parent d2d5f6f commit 774c0c6

File tree

3 files changed

+67
-2
lines changed

3 files changed

+67
-2
lines changed

crates/starknet-devnet-server/src/api/json_rpc/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ impl ApiError {
223223
| Self::NoTraceAvailable
224224
| Self::TypesError(_)
225225
| Self::RpcError(_)
226-
| Self::ContractNotFound
226+
| Self::ContractNotFound // Doesn't require forwarding, handled at state reader level
227227
| Self::InvalidTransactionIndexInBlock
228228
| Self::ContractError { .. }
229229
| Self::NoBlocks

tests/integration/test_call.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,34 @@ async fn calling_method_of_undeployed_contract() {
3333
}
3434

3535
#[tokio::test]
36-
async fn calling_nonexistent_contract_method() {
36+
async fn calling_nonexistent_cairo0_contract_method() {
37+
let devnet_args = ["--account-class", "cairo0"];
38+
let devnet = BackgroundDevnet::spawn_with_additional_args(&devnet_args).await.unwrap();
39+
let contract_address = Felt::from_hex_unchecked(PREDEPLOYED_ACCOUNT_ADDRESS);
40+
let entry_point_selector =
41+
starknet_rs_core::utils::get_selector_from_name("nonExistentMethod").unwrap();
42+
43+
let err = devnet
44+
.json_rpc_client
45+
.call(
46+
FunctionCall {
47+
contract_address,
48+
entry_point_selector,
49+
calldata: vec![contract_address],
50+
},
51+
BlockId::Tag(BlockTag::Latest),
52+
)
53+
.await
54+
.expect_err("Should have failed");
55+
56+
match err {
57+
ProviderError::StarknetError(StarknetError::ContractError(_)) => (),
58+
_ => panic!("Invalid error: {err:?}"),
59+
}
60+
}
61+
62+
#[tokio::test]
63+
async fn calling_nonexistent_cairo1_contract_method() {
3764
let devnet = BackgroundDevnet::spawn().await.expect("Could not start Devnet");
3865
let contract_address = Felt::from_hex_unchecked(PREDEPLOYED_ACCOUNT_ADDRESS);
3966
let entry_point_selector =

tests/integration/test_fork.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,44 @@ async fn test_get_storage_if_contract_deployed_on_origin() {
448448
assert_eq!(real_value, signer.get_public_key().await.unwrap().scalar());
449449
}
450450

451+
#[tokio::test]
452+
async fn test_deploying_on_origin_calling_on_fork() {
453+
let origin_devnet = BackgroundDevnet::spawn_forkable_devnet().await.unwrap();
454+
455+
// obtain account for deployment
456+
let (signer, account_address) = origin_devnet.get_first_predeployed_account().await;
457+
let predeployed_account = SingleOwnerAccount::new(
458+
&origin_devnet.json_rpc_client,
459+
signer.clone(),
460+
account_address,
461+
constants::CHAIN_ID,
462+
ExecutionEncoding::New,
463+
);
464+
465+
let (contract_class, casm_hash) = get_simple_contract_in_sierra_and_compiled_class_hash();
466+
467+
let initial_value = Felt::from(10_u32);
468+
let ctor_args = vec![initial_value];
469+
let (_, contract_address) =
470+
declare_v3_deploy_v3(&predeployed_account, contract_class.clone(), casm_hash, &ctor_args)
471+
.await
472+
.unwrap();
473+
474+
let fork_devnet = origin_devnet.fork().await.unwrap();
475+
476+
let entry_point_selector = get_selector_from_name("get_balance").unwrap();
477+
let call_result = fork_devnet
478+
.json_rpc_client
479+
.call(
480+
FunctionCall { contract_address, entry_point_selector, calldata: vec![] },
481+
BlockId::Tag(BlockTag::Latest),
482+
)
483+
.await
484+
.unwrap();
485+
486+
assert_eq!(call_result, vec![initial_value]);
487+
}
488+
451489
#[tokio::test]
452490
async fn test_fork_using_origin_token_contract() {
453491
let origin_devnet = BackgroundDevnet::spawn_forkable_devnet().await.unwrap();

0 commit comments

Comments
 (0)