mirror of
https://github.com/alexgo-io/stacks-puppet-node.git
synced 2026-01-12 22:43:42 +08:00
Merge pull request #4699 from bestmike007/fix/rollback-global-context
chore: properly handle context rollback for eval readonly
This commit is contained in:
@@ -973,7 +973,11 @@ impl<'a, 'b, 'hooks> Environment<'a, 'b, 'hooks> {
|
||||
let contract = self
|
||||
.global_context
|
||||
.database
|
||||
.get_contract(contract_identifier)?;
|
||||
.get_contract(contract_identifier)
|
||||
.or_else(|e| {
|
||||
self.global_context.roll_back()?;
|
||||
Err(e)
|
||||
})?;
|
||||
|
||||
let result = {
|
||||
let mut nested_env = Environment::new(
|
||||
|
||||
@@ -1147,3 +1147,38 @@ fn test_cc_trait_stack_depth(
|
||||
RuntimeErrorType::MaxStackDepthReached.into()
|
||||
);
|
||||
}
|
||||
|
||||
#[apply(test_epochs)]
|
||||
fn test_eval_with_non_existing_contract(
|
||||
epoch: StacksEpochId,
|
||||
mut env_factory: MemoryEnvironmentGenerator,
|
||||
) {
|
||||
let mut owned_env = env_factory.get_env(epoch);
|
||||
|
||||
let mut placeholder_context = ContractContext::new(
|
||||
QualifiedContractIdentifier::transient(),
|
||||
ClarityVersion::Clarity2,
|
||||
);
|
||||
|
||||
let mut env = owned_env.get_exec_environment(
|
||||
Some(get_principal().expect_principal().unwrap()),
|
||||
None,
|
||||
&mut placeholder_context,
|
||||
);
|
||||
|
||||
let result = env.eval_read_only(
|
||||
&QualifiedContractIdentifier::local("absent").unwrap(),
|
||||
"(ok 0)",
|
||||
);
|
||||
assert_eq!(
|
||||
result.as_ref().unwrap_err(),
|
||||
&Error::Unchecked(CheckErrors::NoSuchContract(
|
||||
QualifiedContractIdentifier::local("absent")
|
||||
.unwrap()
|
||||
.to_string()
|
||||
))
|
||||
);
|
||||
drop(env);
|
||||
owned_env.commit().unwrap();
|
||||
assert!(owned_env.destruct().is_some());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user