|
15 | 15 | // along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16 | 16 |
|
17 | 17 | use clarity::vm::ast::ASTRules;
|
18 |
| -use clarity::vm::clarity::TransactionConnection; |
| 18 | +use clarity::vm::clarity::{Error as ClarityError, TransactionConnection}; |
19 | 19 | use clarity::vm::costs::ExecutionCost;
|
| 20 | +use clarity::vm::errors::CheckErrors; |
20 | 21 | use clarity::vm::functions::NativeFunctions;
|
21 | 22 | use clarity::vm::test_util::TEST_HEADER_DB;
|
22 | 23 | use clarity::vm::tests::{test_only_mainnet_to_chain_id, UnitTestBurnStateDB};
|
23 | 24 | use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier, Value};
|
24 | 25 | use clarity::vm::{execute as vm_execute, ClarityVersion, ContractName};
|
| 26 | +use rstest::rstest; |
25 | 27 | use stacks_common::types::chainstate::StacksBlockId;
|
26 | 28 | use stacks_common::types::StacksEpochId;
|
27 | 29 |
|
@@ -304,3 +306,49 @@ fn epoch_205_test_all_mainnet() {
|
304 | 306 | fn epoch_205_test_all_testnet() {
|
305 | 307 | epoch_205_test_all(false);
|
306 | 308 | }
|
| 309 | + |
| 310 | +#[rstest] |
| 311 | +#[case(true, StacksEpochId::Epoch21)] |
| 312 | +#[case(true, StacksEpochId::Epoch2_05)] |
| 313 | +#[case(false, StacksEpochId::Epoch21)] |
| 314 | +#[case(false, StacksEpochId::Epoch2_05)] |
| 315 | +fn undefined_top_variable_error(#[case] use_mainnet: bool, #[case] epoch: StacksEpochId) { |
| 316 | + let mut clarity_instance = |
| 317 | + setup_tracked_cost_test(use_mainnet, epoch, ClarityVersion::Clarity1); |
| 318 | + let contract_self = "foo"; |
| 319 | + |
| 320 | + let self_contract_id = |
| 321 | + QualifiedContractIdentifier::local("undefined-top-variable-error").unwrap(); |
| 322 | + |
| 323 | + let burn_state_db = UnitTestBurnStateDB { |
| 324 | + epoch_id: epoch, |
| 325 | + ast_rules: ASTRules::PrecheckSize, |
| 326 | + }; |
| 327 | + |
| 328 | + { |
| 329 | + let mut conn = clarity_instance.begin_block( |
| 330 | + &StacksBlockId([3; 32]), |
| 331 | + &StacksBlockId([4; 32]), |
| 332 | + &TEST_HEADER_DB, |
| 333 | + &burn_state_db, |
| 334 | + ); |
| 335 | + |
| 336 | + conn.as_transaction(|conn| { |
| 337 | + let analysis_result = conn.analyze_smart_contract( |
| 338 | + &self_contract_id, |
| 339 | + ClarityVersion::Clarity1, |
| 340 | + &contract_self, |
| 341 | + ASTRules::PrecheckSize, |
| 342 | + ); |
| 343 | + let Err(ClarityError::Analysis(check_error)) = analysis_result else { |
| 344 | + panic!("Bad analysis result: {:?}", &analysis_result); |
| 345 | + }; |
| 346 | + let CheckErrors::UndefinedVariable(var_name) = check_error.err else { |
| 347 | + panic!("Bad analysis error: {:?}", &check_error); |
| 348 | + }; |
| 349 | + assert_eq!(var_name, "foo".to_string()); |
| 350 | + }); |
| 351 | + |
| 352 | + conn.commit_block(); |
| 353 | + } |
| 354 | +} |
0 commit comments