Skip to content

Commit 3f4ff5a

Browse files
committed
test: fix intermediary response test
+ ignore irrelevant tests
1 parent d94788a commit 3f4ff5a

File tree

3 files changed

+25
-50
lines changed

3 files changed

+25
-50
lines changed

stackslib/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,14 @@ rlimit = "0.10.2"
9999
chrono = "0.4.19"
100100

101101
[features]
102-
default = []
102+
default = ["clarity-wasm"]
103103
profile-sqlite = []
104104
disable-costs = []
105105
developer-mode = ["clarity/developer-mode"]
106106
monitoring_prom = ["prometheus"]
107107
slog_json = ["stacks-common/slog_json", "clarity/slog_json", "pox-locking/slog_json"]
108108
testing = ["chrono"]
109+
clarity-wasm = []
109110

110111
[target.'cfg(all(any(target_arch = "x86_64", target_arch = "x86", target_arch = "aarch64"), not(any(target_os="windows"))))'.dependencies]
111112
sha2 = { version = "0.10", features = ["asm"] }

stackslib/src/clarity_vm/tests/costs.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -731,11 +731,11 @@ fn epoch205_nfts(use_mainnet: bool) {
731731
// test nft-mint
732732
let smaller_exec = "(define-non-fungible-token db (list 500 int))
733733
(define-public (execute)
734-
(begin (try! (nft-mint? db (list 1 2 3 4 5) tx-sender))
734+
(begin (nft-mint? db (list 1 2 3 4 5) tx-sender)
735735
(ok 1)))";
736736
let larger_exec = "(define-non-fungible-token db (list 500 int))
737737
(define-public (execute)
738-
(begin (try! (nft-mint? db (list 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20) tx-sender))
738+
(begin (nft-mint? db (list 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20) tx-sender)
739739
(ok 1)))";
740740
let smaller_cost_epoch_200 = exec_cost(smaller_exec, use_mainnet, StacksEpochId::Epoch20);
741741
let smaller_cost_epoch_205 = exec_cost(smaller_exec, use_mainnet, StacksEpochId::Epoch2_05);
@@ -753,13 +753,13 @@ fn epoch205_nfts(use_mainnet: bool) {
753753
// these transfers fail, but the cost tabulation is still the same
754754
let smaller_exec = "(define-non-fungible-token db (list 500 int))
755755
(define-public (execute)
756-
(begin (try! (nft-transfer? db (list 1 2 3 4 5)
757-
tx-sender 'SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR))
756+
(begin (nft-transfer? db (list 1 2 3 4 5)
757+
tx-sender 'SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR)
758758
(ok 1)))";
759759
let larger_exec = "(define-non-fungible-token db (list 500 int))
760760
(define-public (execute)
761-
(begin (try! (nft-transfer? db (list 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20)
762-
tx-sender 'SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR))
761+
(begin (nft-transfer? db (list 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20)
762+
tx-sender 'SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR)
763763
(ok 1)))";
764764
let smaller_cost_epoch_200 = exec_cost(smaller_exec, use_mainnet, StacksEpochId::Epoch20);
765765
let smaller_cost_epoch_205 = exec_cost(smaller_exec, use_mainnet, StacksEpochId::Epoch2_05);
@@ -777,13 +777,13 @@ fn epoch205_nfts(use_mainnet: bool) {
777777
// these burns fail, but the cost tabulation is still the same
778778
let smaller_exec = "(define-non-fungible-token db (list 500 int))
779779
(define-public (execute)
780-
(begin (try! (nft-burn? db (list 1 2 3 4 5)
781-
'SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR))
780+
(begin (nft-burn? db (list 1 2 3 4 5)
781+
'SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR)
782782
(ok 1)))";
783783
let larger_exec = "(define-non-fungible-token db (list 500 int))
784784
(define-public (execute)
785-
(begin (try! (nft-burn? db (list 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20)
786-
'SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR))
785+
(begin (nft-burn? db (list 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20)
786+
'SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR)
787787
(ok 1)))";
788788
let smaller_cost_epoch_200 = exec_cost(smaller_exec, use_mainnet, StacksEpochId::Epoch20);
789789
let smaller_cost_epoch_205 = exec_cost(smaller_exec, use_mainnet, StacksEpochId::Epoch2_05);
@@ -821,11 +821,13 @@ fn epoch205_nfts(use_mainnet: bool) {
821821
}
822822

823823
#[test]
824+
#[cfg(not(feature = "clarity-wasm"))]
824825
fn epoch205_nfts_mainnet() {
825826
epoch205_nfts(true)
826827
}
827828

828829
#[test]
830+
#[cfg(not(feature = "clarity-wasm"))]
829831
fn epoch205_nfts_testnet() {
830832
epoch205_nfts(false)
831833
}

stackslib/src/clarity_vm/tests/events.rs

Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -273,48 +273,20 @@ fn test_emit_stx_burn_nok() {
273273

274274
#[test]
275275
fn test_emit_nested_print_nok() {
276-
// The original code had two problems:
277-
// 1. emit-event-ok called emit-event-nok without handling the (err u1)
278-
// response, causing "UncheckedIntermediaryResponses" error during
279-
// contract initialization.
280-
// 2. The test incorrectly expected (ok u1) and 1 event, but when a public
281-
// function returns an error, the entire transaction rolls back and no
282-
// events are emitted.
283-
//
284-
// Fixed by:
285-
// - Adding try! to properly handle the error response from emit-event-nok.
286-
// - Adding an if statement to make both code paths valid for contract
287-
// initialization.
288-
// - Updating test expectations to match actual behavior: (err u1) and 0
289-
// events.
290-
//
291-
// This test demonstrates that when a public function returns an error,
292-
// ALL side effects (including print statements) are rolled back, even if
293-
// they executed successfully before the error occurred.
294-
let contract = r#"
295-
(define-public (emit-event-nok)
296-
(if (is-eq 1 1)
297-
(begin
298-
(print "bar")
299-
(err u1)
300-
)
301-
(ok u1)
302-
))
303-
304-
(define-public (emit-event-ok)
276+
let contract = "(define-public (emit-event-nok)
305277
(begin
306-
(try! (emit-event-nok))
307-
(print "foo")
308-
(ok u1)))
309-
"#;
278+
(print \"bar\")
279+
(err u1)))
280+
(define-public (emit-event-ok)
281+
(begin
282+
(unwrap-err! (emit-event-nok) (err u1))
283+
(print \"foo\")
284+
(ok u1)))";
310285

311286
let (value, events) = helper_execute(contract, "emit-event-ok");
312-
// try! propagates the error from emit-event-nok, so emit-event-ok returns (err u1).
313-
assert_eq!(value, Value::error(Value::UInt(1)).unwrap());
314-
// No events are emitted because when a public function returns an error,
315-
// Clarity rolls back the entire transaction, discarding all side effects
316-
// including print statements.
317-
assert_eq!(events.len(), 0);
287+
assert_eq!(value, Value::okay(Value::UInt(1)).unwrap());
288+
assert_eq!(events.len(), 1);
289+
318290
}
319291

320292
#[test]

0 commit comments

Comments
 (0)