From 61ff0a0f228d8e39b625070307c909ce588a757c Mon Sep 17 00:00:00 2001 From: "brady.ouren" Date: Mon, 22 Jul 2024 11:03:57 -0700 Subject: [PATCH] add session command testing --- components/clarinet-sdk-wasm/src/core.rs | 4 +- .../node/tests/simnet-usage.test.ts | 4 +- .../clarity-repl/src/repl/interpreter.rs | 5 +- components/clarity-repl/src/repl/session.rs | 49 ++++++++++++++++++- 4 files changed, 53 insertions(+), 9 deletions(-) diff --git a/components/clarinet-sdk-wasm/src/core.rs b/components/clarinet-sdk-wasm/src/core.rs index 1dc522e3c..7da76e657 100644 --- a/components/clarinet-sdk-wasm/src/core.rs +++ b/components/clarinet-sdk-wasm/src/core.rs @@ -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()), } } @@ -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()), } } diff --git a/components/clarinet-sdk/node/tests/simnet-usage.test.ts b/components/clarinet-sdk/node/tests/simnet-usage.test.ts index 09a643651..489314c81 100644 --- a/components/clarinet-sdk/node/tests/simnet-usage.test.ts +++ b/components/clarinet-sdk/node/tests/simnet-usage.test.ts @@ -48,7 +48,9 @@ describe("basic simnet interactions", () => { expect(simnet.blockHeight).toBe(blockHeight + 5); }); it("can not mine empty stacks block in pre-3.0", () => { - expect(() => simnet.mineEmptyStacksBlock()).toThrowError("stacks block height can't be advanced in 2.4"); + expect(() => simnet.mineEmptyStacksBlock()).toThrowError( + "use mineEmptyBurnBlock in epoch lower than 3.0" + ); }) it("exposes devnet stacks accounts", () => { diff --git a/components/clarity-repl/src/repl/interpreter.rs b/components/clarity-repl/src/repl/interpreter.rs index 27c257a23..1fc6d78c2 100644 --- a/components/clarity-repl/src/repl/interpreter.rs +++ b/components/clarity-repl/src/repl/interpreter.rs @@ -1107,10 +1107,7 @@ impl ClarityInterpreter { pub fn advance_stacks_chaintip(&mut self, count: u32) -> Result { 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)) } diff --git a/components/clarity-repl/src/repl/session.rs b/components/clarity-repl/src/repl/session.rs index 005b42894..1547f839c 100644 --- a/components/clarity-repl/src/repl/session.rs +++ b/components/clarity-repl/src/repl/session.rs @@ -1282,9 +1282,8 @@ fn clarity_keywords() -> HashMap { 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( @@ -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());