Skip to content

Commit

Permalink
add session command testing
Browse files Browse the repository at this point in the history
  • Loading branch information
brady.ouren committed Jul 22, 2024
1 parent de400c1 commit 5dd997a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 8 deletions.
4 changes: 2 additions & 2 deletions components/clarinet-sdk-wasm/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ impl SDK {
let session = self.get_session_mut();
match session.advance_stacks_chaintip(1) {
Ok(new_height) => Ok(new_height),
Err(msg) => Err(msg),
Err(_) => Err("use mineEmptyBurnBlock in epoch lower than 3.0".to_string()),
}
}

Expand All @@ -943,7 +943,7 @@ impl SDK {
let session = self.get_session_mut();
match session.advance_stacks_chaintip(count.unwrap_or(1)) {
Ok(new_height) => Ok(new_height),
Err(msg) => Err(msg),
Err(_) => Err("use mineEmptyBurnBlocks in epoch lower than 3.0".to_string()),
}
}

Expand Down
5 changes: 1 addition & 4 deletions components/clarity-repl/src/repl/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1107,10 +1107,7 @@ impl ClarityInterpreter {
pub fn advance_stacks_chaintip(&mut self, count: u32) -> Result<u32, String> {
let current_epoch = self.burn_datastore.get_current_epoch();
if current_epoch < StacksEpochId::Epoch30 {
Err(format!(
"stacks block height can't be advanced in {}",
current_epoch
))
Err("only burn chain height can be advanced in epoch lower than 3.0".to_string())
} else {
Ok(self.datastore.advance_chain_tip(count))
}
Expand Down
49 changes: 47 additions & 2 deletions components/clarity-repl/src/repl/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1282,9 +1282,8 @@ fn clarity_keywords() -> HashMap<String, String> {
mod tests {
use clarity::vm::types::TupleData;

use crate::{repl::settings::Account, test_fixtures::clarity_contract::ClarityContractBuilder};

use super::*;
use crate::{repl::settings::Account, test_fixtures::clarity_contract::ClarityContractBuilder};

#[track_caller]
fn assert_execution_result_value(
Expand Down Expand Up @@ -1342,6 +1341,52 @@ mod tests {
);
}

#[test]
fn test_parse_and_advance_stacks_chaintip() {
let mut session = Session::new(SessionSettings::default());
let result = session.handle_command("::advance_stacks_chaintip 1");
assert_eq!(
result,
"only burn chain height can be advanced in epoch lower than 3.0"
.to_string()
.red()
.to_string()
);
session.handle_command("::set_epoch 3.0");
let _ = session.handle_command("::advance_stacks_chaintip 1");
let new_height = session.handle_command("::get_stacks_block_height");
assert_eq!(new_height, "Current height: 1");
}

#[test]
fn test_parse_and_advance_burn_chaintip_pre_epoch3() {
let mut session = Session::new(SessionSettings::default());
let result = session.handle_command("::advance_burn_chaintip 1");
assert_eq!(
result,
"1 blocks simulated, new height: 1"
.to_string()
.green()
.to_string()
);
}
#[test]
fn test_parse_and_advance_burn_chaintip_epoch3() {
let mut session = Session::new(SessionSettings::default());
session.handle_command("::set_epoch 3.0");
let result = session.handle_command("::advance_burn_chaintip 1");
assert_eq!(
result,
"1 blocks simulated, new height: 1"
.to_string()
.green()
.to_string()
);
let new_height = session.handle_command("::get_stacks_block_height");
assert_eq!(new_height, "Current height: 1");
let new_height = session.handle_command("::get_burn_block_height");
assert_eq!(new_height, "Current height: 1");
}
#[test]
fn set_epoch_command() {
let mut session = Session::new(SessionSettings::default());
Expand Down

0 comments on commit 5dd997a

Please sign in to comment.