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

SimulateTransactions integration tests #628

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

marioiordanov
Copy link
Contributor

@marioiordanov marioiordanov commented Oct 17, 2024

Development related changes

  • Enhanced integration tests for starknet_simulateTransactions
  • added new error type
  • small refactor about fee related errors

Checklist:

  • Checked out the contribution guidelines
  • Applied formatting - ./scripts/format.sh
  • No linter errors - ./scripts/clippy_check.sh
  • No unused dependencies - ./scripts/check_unused_deps.sh
  • No spelling errors - ./scripts/check_spelling.sh
  • Performed code self-review
  • Rebased to the latest commit of the target branch (or merged it into my branch)
    • Once you make the PR reviewable, please avoid force-pushing
  • Updated the docs if needed - ./website/README.md
  • Linked the issues resolvable by this PR - linking info
  • Updated the tests if needed; all passing - execution info

@marioiordanov marioiordanov linked an issue Oct 17, 2024 that may be closed by this pull request
@marioiordanov marioiordanov marked this pull request as ready for review October 17, 2024 19:53
@@ -1210,6 +1153,7 @@ impl Starknet {
transactions,
Some(!skip_fee_charge),
Some(!skip_validate),
false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why should return_error_on_reverted_execution be false here? Won't the error have already occurred on blockifier_transaction.execute in L1126?


match estimate_fee_result {
Ok(estimated_fee) => Ok(estimated_fee),
Err(Error::UnexpectedInternalError { msg }) => Err(Error::ExecutionError { execution_error: msg, index: idx }),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should ExecutionError (used by RPC) be mapped into UnexpectedInternalError? When do we even get UnexpectedInternalError? Isn't it a way to catch those unfortunate conversions that never fail?

impl From<TransactionExecutionError> for Error {
fn from(value: TransactionExecutionError) -> Self {
match value {
blockifier::transaction::errors::TransactionExecutionError::TransactionPreValidationError(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why fully qualify the error if it's already imported at the top of the file? Applicable to other new impl From sections in this file.

@@ -178,7 +182,7 @@ mod old_state {
.await
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the block_id defined in L165 be used in L180?

Comment on lines -113 to +117
async fn estimate_fee_and_simulate_transaction_for_contract_deployment_in_an_old_block_should_produce_the_same_error()
async fn estimate_fee_and_simulate_transaction_for_contract_deployment_in_an_old_block_should_not_produce_the_same_error()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it or should it not? starknet_simulateTransactions can return TRANSACTION_EXECUTION_ERROR according to the spec, but in what case if not in this? I think this is a difference between your PR and mine (#627).

@@ -578,4 +583,201 @@ mod estimate_fee_tests {
.iter()
.for_each(assert_fee_estimation);
}

#[tokio::test]
async fn estimate_fee_of_multiple_txs_should_return_correct_index_if_one_of_them_fails() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test name is not discriminative enough, compared with the other test you added in this file, since it could also be applied there.

Comment on lines +1043 to +1057
if skip_fee_charge {
simulation_result.unwrap();
} else {
match simulation_result.unwrap_err() {
AccountError::Provider(ProviderError::StarknetError(
StarknetError::TransactionExecutionError(TransactionExecutionErrorData {
execution_error,
..
}),
)) => {
assert_contains(&execution_error, "max fee is not enough");
}
other_error => panic!("Unexpected error {other_error:?}"),
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This suggestion uses less lines and avoids matching inside an if-else construct.

Suggested change
if skip_fee_charge {
simulation_result.unwrap();
} else {
match simulation_result.unwrap_err() {
AccountError::Provider(ProviderError::StarknetError(
StarknetError::TransactionExecutionError(TransactionExecutionErrorData {
execution_error,
..
}),
)) => {
assert_contains(&execution_error, "max fee is not enough");
}
other_error => panic!("Unexpected error {other_error:?}"),
}
}
match (simulation_result, skip_fee_charge) {
(Ok(_), true) => (),
(
Err(AccountError::Provider(ProviderError::StarknetError(
StarknetError::TransactionExecutionError(TransactionExecutionErrorData {
execution_error,
..
}),
))),
false,
) => assert_contains(&execution_error, "max fee is not enough"),
invalid_combination => panic!("Invalid combination: {invalid_combination:?}"),
}

let chain_id = devnet.json_rpc_client.chain_id().await.unwrap();
let paymaster_data = vec![];
let tip = 0;
let gas = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does it work with gas set to 0 and validation not skipped?


let salt = Felt::from_hex_unchecked("0x123");

account
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a function in commons/utils.rs that abstracts declaring and deploying. Currently it does so relying on v1, but that shouldn't matter in this and similar cases in this file, because the declaring and deploying don't need to be v3 if we're later just testing a panic behavior in an invoke v3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve testing of starknet_simulateTransactions
2 participants