Skip to content

Commit

Permalink
add test for entrypoint not found
Browse files Browse the repository at this point in the history
  • Loading branch information
glihm committed Oct 27, 2023
1 parent cd63e2d commit 4f7b8ca
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion starknet-providers/src/jsonrpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ where
Ok(code) => MaybeUnknownErrorCode::Known(code),
Err(_) => MaybeUnknownErrorCode::Unknown(error.code),
},
message: error.message,
message: format!("{}: {}", error.message, error.data),
}))
}
}
Expand Down
40 changes: 40 additions & 0 deletions starknet-providers/tests/jsonrpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,46 @@ async fn jsonrpc_call() {
assert!(eth_balance[0] > FieldElement::ZERO);
}

#[tokio::test]
async fn jsonrpc_call_error() {
let rpc_client = create_jsonrpc_client();

// Checks invalid entrypoint contract error (40) in data field.
let should_be_error = rpc_client
.call(
&FunctionCall {
contract_address: FieldElement::from_hex_be(
"049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
)
.unwrap(),
entry_point_selector: get_selector_from_name("notValidEntryPoint").unwrap(),
calldata: vec![FieldElement::from_hex_be(
"01352dd0ac2a462cb53e4f125169b28f13bd6199091a9815c444dcae83056bbc",
)
.unwrap()],
},
BlockId::Tag(BlockTag::Latest),
)
.await;

match should_be_error {
Ok(_) => panic!("unexpected success result"),
Err(e) => match e {
ProviderError::StarknetError(StarknetErrorWithMessage { code, ref message }) => {
if let MaybeUnknownErrorCode::Known(sne) = code {
assert_eq!(sne, StarknetError::ContractError);
} else {
panic!("unexpected StarknetError {:?}", code);
}

assert!(!message.is_empty());
assert!(message.contains("Entry point EntryPointSelector(StarkFelt(\\\"0x03cf855c74a42fd097b17c8e32d22d463abd6e275cf10fbb682ad147f25641dc\\\")) not found in contract"));
}
_ => panic!("unexpected error type {:?}", e),
},
}
}

#[tokio::test]
async fn jsonrpc_estimate_fee() {
let rpc_client = create_jsonrpc_client();
Expand Down

0 comments on commit 4f7b8ca

Please sign in to comment.