Skip to content

Commit

Permalink
chore: handle pox-locking in simnet (#1375)
Browse files Browse the repository at this point in the history
* feat: handle pox-locking

* refactor: remove dead code

* refactor: change update_session_with_contracts_executions signature

* refactore: remove dead code
  • Loading branch information
hugocaillard authored Mar 12, 2024
1 parent ae47f28 commit dbc0178
Show file tree
Hide file tree
Showing 15 changed files with 569 additions and 206 deletions.
13 changes: 12 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 22 additions & 10 deletions components/clarinet-deployments/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,22 @@ use types::RequirementPublishSpecification;
use types::TransactionSpecification;
use types::{ContractPublishSpecification, EpochSpec};

pub type ExecutionResultMap =
BTreeMap<QualifiedContractIdentifier, Result<ExecutionResult, Vec<Diagnostic>>>;

pub struct UpdateSessionExecutionResult {
pub boot_contracts: ExecutionResultMap,
pub contracts: ExecutionResultMap,
}

pub fn setup_session_with_deployment(
manifest: &ProjectManifest,
deployment: &DeploymentSpecification,
contracts_asts: Option<&BTreeMap<QualifiedContractIdentifier, ContractAST>>,
) -> DeploymentGenerationArtifacts {
let mut session = initiate_session_from_deployment(manifest);
update_session_with_genesis_accounts(&mut session, deployment);
let results = update_session_with_contracts_executions(
let UpdateSessionExecutionResult { contracts, .. } = update_session_with_contracts_executions(
&mut session,
deployment,
contracts_asts,
Expand All @@ -61,7 +69,7 @@ pub fn setup_session_with_deployment(
let mut asts = BTreeMap::new();
let mut contracts_analysis = HashMap::new();
let mut success = true;
for (contract_id, res) in results.into_iter() {
for (contract_id, res) in contracts.into_iter() {
match res {
Ok(execution_result) => {
diags.insert(contract_id.clone(), execution_result.diagnostics);
Expand Down Expand Up @@ -122,17 +130,18 @@ pub fn update_session_with_contracts_executions(
contracts_asts: Option<&BTreeMap<QualifiedContractIdentifier, ContractAST>>,
code_coverage_enabled: bool,
forced_min_epoch: Option<StacksEpochId>,
) -> BTreeMap<QualifiedContractIdentifier, Result<ExecutionResult, Vec<Diagnostic>>> {
) -> UpdateSessionExecutionResult {
let boot_contracts_data = BOOT_CONTRACTS_DATA.clone();

for (_, (boot_contract, ast)) in boot_contracts_data {
session
let mut boot_contracts = BTreeMap::new();
for (contract_id, (boot_contract, ast)) in boot_contracts_data {
let result = session
.interpreter
.run(&boot_contract, &mut Some(ast), false, None)
.expect("failed to interprete boot contract");
.run(&boot_contract, &mut Some(ast), false, None);
boot_contracts.insert(contract_id, result);
}

let mut results = BTreeMap::new();
let mut contracts = BTreeMap::new();
for batch in deployment.plan.batches.iter() {
let epoch: StacksEpochId = match (batch.epoch, forced_min_epoch) {
(Some(epoch), _) => epoch.into(),
Expand Down Expand Up @@ -184,7 +193,7 @@ pub fn update_session_with_contracts_executions(
},
&mut contract_ast,
);
results.insert(contract_id, result);
contracts.insert(contract_id, result);
session.set_tx_sender(default_tx_sender);
}
TransactionSpecification::EmulatedContractCall(tx) => {
Expand All @@ -200,7 +209,10 @@ pub fn update_session_with_contracts_executions(
}
session.advance_chain_tip(1);
}
results
UpdateSessionExecutionResult {
boot_contracts,
contracts,
}
}

pub async fn generate_default_deployment(
Expand Down
2 changes: 1 addition & 1 deletion components/clarinet-sdk-wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
edition = "2021"
name = "clarinet-sdk-wasm"
version = "2.3.2"
version = "2.4.0-beta2"
license = "GPL-3.0"
repository = "https://github.com/hirosystems/clarinet"
description = "The core lib that powers @hirosystems/clarinet-sdk"
Expand Down
10 changes: 7 additions & 3 deletions components/clarinet-sdk-wasm/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use crate::utils::events::serialize_event;

#[wasm_bindgen(typescript_custom_section)]
const SET_EPOCH: &'static str = r#"
type EpochString = "2.0" | "2.05" | "2.1" | "2.2" | "2.3" | "2.4"
type EpochString = "2.0" | "2.05" | "2.1" | "2.2" | "2.3" | "2.4" | "3.0"
"#;

#[wasm_bindgen]
Expand Down Expand Up @@ -414,7 +414,7 @@ impl SDK {

let mut session = initiate_session_from_deployment(&manifest);
update_session_with_genesis_accounts(&mut session, &deployment);
let results = update_session_with_contracts_executions(
let executed_contracts = update_session_with_contracts_executions(
&mut session,
&deployment,
Some(&artifacts.asts),
Expand All @@ -437,7 +437,11 @@ impl SDK {
.insert(contract_id, location.clone());
}

for (_, result) in results.into_iter() {
for (_, result) in executed_contracts
.boot_contracts
.into_iter()
.chain(executed_contracts.contracts.into_iter())
{
match result {
Ok(execution_result) => {
self.add_contract(&execution_result);
Expand Down
7 changes: 0 additions & 7 deletions components/clarinet-sdk-wasm/src/utils/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ pub struct StacksEvent {
pub data: serde_json::Value,
}

#[allow(unused_macros)]
macro_rules! log {
( $( $t:tt )* ) => {
web_sys::console::log_1(&format!( $( $t )* ).into());
}
}

pub fn serialize_event(event: &StacksTransactionEvent) -> StacksEvent {
match event {
StacksTransactionEvent::SmartContractEvent(data) => StacksEvent {
Expand Down
Loading

0 comments on commit dbc0178

Please sign in to comment.