Skip to content

Commit 147105c

Browse files
Do not include a read only call in early return tests and create a sep test for this case
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent 7be9d22 commit 147105c

6 files changed

+2232
-803
lines changed

stackslib/src/chainstate/tests/consensus.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,3 +1893,19 @@ fn problematic_supertype_list() {
18931893
deploy_epochs: &StacksEpochId::since(StacksEpochId::Epoch20),
18941894
);
18951895
}
1896+
1897+
#[test]
1898+
/// Test that a read-only function call can be included in a block without issue.
1899+
/// The fn also shows that a non-response is handled without issue with the testing framework.
1900+
fn read_only_transaction_block() {
1901+
contract_call_consensus_test!(
1902+
contract_name: "read-only-call",
1903+
contract_code: "
1904+
(define-read-only (trigger)
1905+
(some u1)
1906+
)
1907+
",
1908+
function_name: "trigger",
1909+
function_args: &[],
1910+
);
1911+
}

stackslib/src/chainstate/tests/early_return_tests.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ fn native_try_ret_err_ccall() {
8888
contract_call_consensus_test!(
8989
contract_name: "unwrap-err",
9090
contract_code: "
91-
(define-read-only (trigger (resp (response uint uint)))
91+
(define-public (trigger (resp (response uint uint)))
9292
(begin
9393
(try! resp)
9494
(ok u1)
@@ -124,12 +124,19 @@ fn native_try_ret_none_ccall() {
124124
contract_call_consensus_test!(
125125
contract_name: "unwrap-try-opt",
126126
contract_code: "
127-
(define-read-only (trigger (opt (optional bool)))
127+
(define-read-only (trigger-ro (opt (optional bool)))
128128
(begin
129129
(try! opt)
130130
(some true)
131131
)
132132
)
133+
(define-public (trigger (opt (optional bool)))
134+
(match (trigger-ro opt)
135+
value
136+
(ok u1)
137+
(err u404)
138+
)
139+
)
133140
",
134141
function_name: "trigger",
135142
function_args: &[ClarityValue::none()],
@@ -190,7 +197,7 @@ fn native_unwrap_or_ret_none_ccall() {
190197
contract_call_consensus_test!(
191198
contract_name: "unwrap-opt",
192199
contract_code: "
193-
(define-read-only (trigger (opt (optional bool)))
200+
(define-public (trigger (opt (optional bool)))
194201
(begin
195202
(unwrap! opt (err false))
196203
(ok true)

0 commit comments

Comments
 (0)