From e530baede3022762be2c966558dabc4fb7215b00 Mon Sep 17 00:00:00 2001 From: Steven Cordero <112043913+stevencartavia@users.noreply.github.com> Date: Thu, 16 May 2024 07:11:38 -0600 Subject: [PATCH] test: estime_fee skip validation (#1584) Co-authored-by: Steven --- CHANGELOG.md | 1 + crates/pallets/starknet/src/tests/query_tx.rs | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 277ae1c30b..33c6b29262 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Next release +- dev: pallet test for estimate_fee that skip validation - feat: add versioned constants to pallet constants - bug: fix contract serialisation - fix: starknet_call errs if contract nonexistent diff --git a/crates/pallets/starknet/src/tests/query_tx.rs b/crates/pallets/starknet/src/tests/query_tx.rs index 48780befa0..79e4537582 100644 --- a/crates/pallets/starknet/src/tests/query_tx.rs +++ b/crates/pallets/starknet/src/tests/query_tx.rs @@ -1,5 +1,6 @@ use blockifier::transaction::account_transaction::AccountTransaction; use frame_support::{assert_err, assert_ok}; +use mp_simulations::SimulationFlags; use mp_transactions::compute_hash::ComputeTransactionHash; use starknet_api::core::Nonce; use starknet_api::hash::StarkFelt; @@ -97,3 +98,24 @@ fn query_tx_should_not_be_executable() { ); }); } + +#[test] +fn estimate_fee_skips_validation_for_invalid_tx() { + new_test_ext::().execute_with(|| { + basic_test_setup(2); + + // // Invalid nonce (actual: 42, expected: 0) + let invalid_transaction = get_invoke_dummy(Starknet::chain_id(), Nonce(StarkFelt::from(42u64))); + let tx = AccountTransaction::Invoke(invalid_transaction.clone()); + + let tx_vec = vec![tx.clone()]; + + let fee_estimation_result = + Starknet::estimate_fee(tx_vec.clone(), &SimulationFlags { validate: true, charge_fee: true }); + assert!(fee_estimation_result.unwrap().is_err(), "Fee estimation succeded"); + + let fee_estimation_result = + Starknet::estimate_fee(tx_vec.clone(), &SimulationFlags { validate: false, charge_fee: true }); + assert!(fee_estimation_result.is_ok(), "Fee estimation failed unexpectedly"); + }); +}