Skip to content

Commit e295a8b

Browse files
Use exclude_clarity_versions
Signed-off-by: Jacinta Ferrant <jacinta@stackslabs.com>
1 parent d3d512b commit e295a8b

File tree

5 files changed

+67
-763
lines changed

5 files changed

+67
-763
lines changed

stacks-common/src/types/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,16 @@ impl StacksEpochId {
150150
StacksEpochId::Epoch33 => PEER_VERSION_EPOCH_3_3,
151151
}
152152
}
153+
154+
#[cfg(any(test, feature = "testing"))]
155+
pub fn since(epoch: StacksEpochId) -> &'static [StacksEpochId] {
156+
let idx = Self::ALL
157+
.iter()
158+
.position(|&e| e == epoch)
159+
.expect("epoch not found in ALL");
160+
161+
&Self::ALL[idx..]
162+
}
153163
}
154164

155165
#[derive(Debug)]

stackslib/src/chainstate/tests/consensus.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,7 +1620,7 @@ macro_rules! contract_call_consensus_test {
16201620
) => {
16211621
{
16221622
// Handle deploy_epochs parameter (default to all epochs >= 2.0 if not provided)
1623-
let deploy_epochs = &clarity::types::StacksEpochId::ALL[1..];
1623+
let deploy_epochs = &clarity::types::StacksEpochId::since(clarity::types::StacksEpochId::Epoch20);
16241624
$(let deploy_epochs = $deploy_epochs;)?
16251625

16261626
// Handle call_epochs parameter (default to EPOCHS_TO_TEST if not provided)
@@ -1892,6 +1892,6 @@ fn problematic_supertype_list() {
18921892
(err 1)))
18931893
(print (var-get my-list))
18941894
",
1895-
deploy_epochs: &StacksEpochId::ALL[1..],
1895+
deploy_epochs: &StacksEpochId::since(StacksEpochId::Epoch20),
18961896
);
18971897
}

stackslib/src/chainstate/tests/runtime_tests.rs

Lines changed: 16 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ use crate::chainstate::stacks::boot::test::{
3131
make_signer_key_signature,
3232
};
3333
use crate::chainstate::tests::consensus::{
34-
clarity_versions_for_epoch, contract_call_consensus_test, contract_deploy_consensus_test,
35-
ConsensusTest, ConsensusUtils, TestBlock, EPOCHS_TO_TEST, SK_1,
34+
contract_call_consensus_test, contract_deploy_consensus_test, ConsensusTest, TestBlock, SK_1,
3635
};
3736
use crate::chainstate::tests::parse_tests;
3837
use crate::core::test_util::to_addr;
@@ -414,6 +413,8 @@ fn arithmetic_zero_n_log_n() {
414413
)",
415414
function_name: "trigger",
416415
function_args: &[],
416+
deploy_epochs: &StacksEpochId::since(StacksEpochId::Epoch21),
417+
exclude_clarity_versions: &[ClarityVersion::Clarity1],
417418
);
418419
}
419420

@@ -752,64 +753,17 @@ fn pox_already_locked() {
752753
/// Outcome: block accepted
753754
#[test]
754755
fn block_time_not_available() {
755-
let contract_code = "
756-
(define-read-only (trigger (height uint))
757-
(ok (at-block (unwrap! (get-stacks-block-info? id-header-hash height) (err u100))
758-
stacks-block-time
759-
))
760-
)";
761-
762-
let mut nonce = 0;
763-
let mut contract_names = vec![];
764-
let mut epoch_blocks = HashMap::new();
765-
for &epoch in &StacksEpochId::ALL[11..] {
766-
let mut blocks = vec![];
767-
// Get all Clarity versions supported in this epoch
768-
let clarity_versions = clarity_versions_for_epoch(epoch);
769-
// For each clarity version, deploy a contract
770-
for &each_clarity_ver in clarity_versions {
771-
// Skip Clarity 1/2/3 — they can't compile this code (stacks-block-time doesn't exist)
772-
if matches!(
773-
each_clarity_ver,
774-
ClarityVersion::Clarity1 | ClarityVersion::Clarity2 | ClarityVersion::Clarity3
775-
) {
776-
continue;
777-
};
778-
let epoch_name = format!("Epoch{}", epoch.to_string().replace('.', "_"));
779-
780-
let version_tag = each_clarity_ver.to_string().replace(' ', "");
781-
let contract_name = format!("no-block-time-{epoch_name}-{version_tag}");
782-
// Create the deploy block
783-
blocks.push(TestBlock {
784-
transactions: vec![ConsensusUtils::new_deploy_tx(
785-
nonce,
786-
&contract_name,
787-
contract_code,
788-
Some(each_clarity_ver),
789-
)],
790-
});
791-
nonce += 1;
792-
contract_names.push(contract_name);
793-
794-
if EPOCHS_TO_TEST.contains(&epoch) {
795-
for contract_name in &contract_names {
796-
blocks.push(TestBlock {
797-
transactions: vec![ConsensusUtils::new_call_tx(
798-
nonce,
799-
contract_name,
800-
"trigger",
801-
&[ClarityValue::UInt(1)],
802-
)],
803-
});
804-
nonce += 1;
805-
}
806-
}
807-
}
808-
if !blocks.is_empty() {
809-
epoch_blocks.insert(epoch, blocks);
810-
}
811-
}
812-
813-
let results = ConsensusTest::new(function_name!(), vec![], epoch_blocks).run();
814-
insta::assert_ron_snapshot!(results);
756+
contract_call_consensus_test!(
757+
contract_name: "no-block-time",
758+
contract_code: "
759+
(define-read-only (trigger (height uint))
760+
(ok (at-block (unwrap! (get-stacks-block-info? id-header-hash height) (err u100))
761+
stacks-block-time
762+
))
763+
)",
764+
function_name: "trigger",
765+
function_args: &[ClarityValue::UInt(1)],
766+
deploy_epochs: &StacksEpochId::since(StacksEpochId::Epoch33),
767+
exclude_clarity_versions: &[ClarityVersion::Clarity1, ClarityVersion::Clarity2, ClarityVersion::Clarity3],
768+
)
815769
}

0 commit comments

Comments
 (0)