Skip to content

Commit dd02031

Browse files
authored
Merge pull request #6222 from BowTiedWoo/wasm-issue-668/no-such-contract-error
[clarity-wasm-tests] fix chainstate::stacks::boot::contract_tests
2 parents 1dee9cb + 43abd9e commit dd02031

File tree

2 files changed

+56
-4
lines changed

2 files changed

+56
-4
lines changed

clarity/src/vm/contexts.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,51 @@ impl<'a> OwnedEnvironment<'a> {
735735
)
736736
}
737737

738+
/// Initializes a versioned Clarity smart contract with a custom analysis database within a transaction context.
739+
///
740+
/// This function should only be used for testing.
741+
///
742+
/// This function creates a complete transaction environment to initialize a Clarity smart contract
743+
/// using a provided memory-backed database for analysis data. It executes the contract initialization
744+
/// within a proper execution context with a specific Clarity version.
745+
///
746+
/// # Arguments
747+
///
748+
/// * `contract_identifier` - Unique identifier for the contract (principal + contract name)
749+
/// * `version` - The Clarity version to use for this contract
750+
/// * `contract_content` - The raw Clarity source code as a string
751+
/// * `sponsor` - Optional sponsor principal for transaction fees (if `None`, sender pays)
752+
/// * `ast_rules` - Parsing rules to apply during AST construction (e.g., `ASTRules::PrecheckSize`)
753+
/// * `analysis_db` - Mutable reference to a database for analysis data
754+
///
755+
#[cfg(any(test, feature = "testing"))]
756+
pub fn initialize_versioned_contract_with_db(
757+
&mut self,
758+
contract_identifier: QualifiedContractIdentifier,
759+
version: ClarityVersion,
760+
contract_content: &str,
761+
sponsor: Option<PrincipalData>,
762+
ast_rules: ASTRules,
763+
analysis_db: &mut AnalysisDatabase,
764+
) -> Result<((), AssetMap, Vec<StacksTransactionEvent>)> {
765+
self.execute_in_env(
766+
contract_identifier.issuer.clone().into(),
767+
sponsor,
768+
Some(ContractContext::new(
769+
QualifiedContractIdentifier::transient(),
770+
version,
771+
)),
772+
|exec_env| {
773+
exec_env.initialize_contract_with_db(
774+
contract_identifier,
775+
contract_content,
776+
ast_rules,
777+
analysis_db,
778+
)
779+
},
780+
)
781+
}
782+
738783
pub fn initialize_contract_from_ast(
739784
&mut self,
740785
contract_identifier: QualifiedContractIdentifier,

stackslib/src/chainstate/stacks/boot/contract_tests.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -667,33 +667,40 @@ fn pox_2_contract_caller_units() {
667667

668668
let expected_unlock_height = POX_TESTNET_CYCLE_LENGTH * 4;
669669

670+
let mut store = MemoryBackingStore::new();
671+
let mut analysis_db = store.as_analysis_db();
672+
analysis_db.begin();
673+
670674
// execute past 2.1 epoch initialization
671675
sim.execute_next_block(|_env| {});
672676
sim.execute_next_block(|_env| {});
673677
sim.execute_next_block(|_env| {});
674678

675679
sim.execute_next_block(|env| {
676-
env.initialize_versioned_contract(
680+
env.initialize_versioned_contract_with_db(
677681
POX_2_CONTRACT_TESTNET.clone(),
678682
ClarityVersion::Clarity2,
679683
&POX_2_TESTNET_CODE,
680684
None,
681685
ASTRules::PrecheckSize,
686+
&mut analysis_db,
682687
)
683688
.unwrap()
684689
});
685690

686691
let cc = boot_code_id("stack-through", false);
687692

688693
sim.execute_next_block(|env| {
689-
env.initialize_contract(cc.clone(),
694+
env.initialize_contract_with_db(cc.clone(),
690695
"(define-public (cc-stack-stx (amount-ustx uint)
691696
(pox-addr (tuple (version (buff 1)) (hashbytes (buff 32))))
692697
(start-burn-ht uint)
693698
(lock-period uint))
694699
(contract-call? .pox-2 stack-stx amount-ustx pox-addr start-burn-ht lock-period))",
695-
None,
696-
ASTRules::PrecheckSize)
700+
None,
701+
ASTRules::PrecheckSize,
702+
&mut analysis_db,
703+
)
697704
.unwrap();
698705

699706
let burn_height = env.eval_raw("burn-block-height").unwrap().0;

0 commit comments

Comments
 (0)