Skip to content

Commit 883ad61

Browse files
committed
add static_check_error_bad_trait_implementation
1 parent 159e798 commit 883ad61

File tree

2 files changed

+175
-1
lines changed

2 files changed

+175
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
---
2+
source: stackslib/src/chainstate/tests/static_analysis_tests.rs
3+
expression: result
4+
---
5+
[
6+
Success(ExpectedBlockOutput(
7+
marf_hash: "ea4bd6655c60fab8f7361d5dadafe85828880fe8eedfcd1ee1009089d080c69a",
8+
evaluated_epoch: Epoch33,
9+
transactions: [
10+
ExpectedTransactionOutput(
11+
tx: "SmartContract(name: trait-contract, code_body: [..], clarity_version: Some(Clarity4))",
12+
vm_error: "None [NON-CONSENSUS BREAKING]",
13+
return_type: Response(ResponseData(
14+
committed: true,
15+
data: Bool(true),
16+
)),
17+
cost: ExecutionCost(
18+
write_length: 87,
19+
write_count: 2,
20+
read_length: 1,
21+
read_count: 1,
22+
runtime: 10190,
23+
),
24+
),
25+
],
26+
total_block_cost: ExecutionCost(
27+
write_length: 87,
28+
write_count: 2,
29+
read_length: 1,
30+
read_count: 1,
31+
runtime: 10190,
32+
),
33+
)),
34+
Success(ExpectedBlockOutput(
35+
marf_hash: "3e216b0c84ceed92b873d280c01a1541de4bc3fc8dea66968cd7af59387080e5",
36+
evaluated_epoch: Epoch33,
37+
transactions: [
38+
ExpectedTransactionOutput(
39+
tx: "SmartContract(name: contract-name-Epoch3_3-Clarity1, code_body: [..], clarity_version: Some(Clarity1))",
40+
vm_error: "Some(invalid signature for method \'get-1\' regarding trait\'s specification <trait-1>) [NON-CONSENSUS BREAKING]",
41+
return_type: Response(ResponseData(
42+
committed: false,
43+
data: Optional(OptionalData(
44+
data: None,
45+
)),
46+
)),
47+
cost: ExecutionCost(
48+
write_length: 17,
49+
write_count: 1,
50+
read_length: 1,
51+
read_count: 1,
52+
runtime: 3373,
53+
),
54+
),
55+
],
56+
total_block_cost: ExecutionCost(
57+
write_length: 17,
58+
write_count: 1,
59+
read_length: 1,
60+
read_count: 1,
61+
runtime: 3373,
62+
),
63+
)),
64+
Success(ExpectedBlockOutput(
65+
marf_hash: "53c830893cccd63de3eba2d50e763cf0e31166f51a97761352201aca2607caee",
66+
evaluated_epoch: Epoch33,
67+
transactions: [
68+
ExpectedTransactionOutput(
69+
tx: "SmartContract(name: contract-name-Epoch3_3-Clarity2, code_body: [..], clarity_version: Some(Clarity2))",
70+
vm_error: "Some(invalid signature for method \'get-1\' regarding trait\'s specification <trait-1>) [NON-CONSENSUS BREAKING]",
71+
return_type: Response(ResponseData(
72+
committed: false,
73+
data: Optional(OptionalData(
74+
data: None,
75+
)),
76+
)),
77+
cost: ExecutionCost(
78+
write_length: 17,
79+
write_count: 1,
80+
read_length: 1,
81+
read_count: 1,
82+
runtime: 3373,
83+
),
84+
),
85+
],
86+
total_block_cost: ExecutionCost(
87+
write_length: 17,
88+
write_count: 1,
89+
read_length: 1,
90+
read_count: 1,
91+
runtime: 3373,
92+
),
93+
)),
94+
Success(ExpectedBlockOutput(
95+
marf_hash: "fa6cc1f8cd406b2dc50bb654268085d7c62d89e775f756bec97cbcc3e70df447",
96+
evaluated_epoch: Epoch33,
97+
transactions: [
98+
ExpectedTransactionOutput(
99+
tx: "SmartContract(name: contract-name-Epoch3_3-Clarity3, code_body: [..], clarity_version: Some(Clarity3))",
100+
vm_error: "Some(invalid signature for method \'get-1\' regarding trait\'s specification <trait-1>) [NON-CONSENSUS BREAKING]",
101+
return_type: Response(ResponseData(
102+
committed: false,
103+
data: Optional(OptionalData(
104+
data: None,
105+
)),
106+
)),
107+
cost: ExecutionCost(
108+
write_length: 17,
109+
write_count: 1,
110+
read_length: 1,
111+
read_count: 1,
112+
runtime: 3373,
113+
),
114+
),
115+
],
116+
total_block_cost: ExecutionCost(
117+
write_length: 17,
118+
write_count: 1,
119+
read_length: 1,
120+
read_count: 1,
121+
runtime: 3373,
122+
),
123+
)),
124+
Success(ExpectedBlockOutput(
125+
marf_hash: "b559f59ceb3fcd78971206e63bac42f5c3c7bd29ab001c21e1431d4fea0377fe",
126+
evaluated_epoch: Epoch33,
127+
transactions: [
128+
ExpectedTransactionOutput(
129+
tx: "SmartContract(name: contract-name-Epoch3_3-Clarity4, code_body: [..], clarity_version: Some(Clarity4))",
130+
vm_error: "Some(invalid signature for method \'get-1\' regarding trait\'s specification <trait-1>) [NON-CONSENSUS BREAKING]",
131+
return_type: Response(ResponseData(
132+
committed: false,
133+
data: Optional(OptionalData(
134+
data: None,
135+
)),
136+
)),
137+
cost: ExecutionCost(
138+
write_length: 17,
139+
write_count: 1,
140+
read_length: 1,
141+
read_count: 1,
142+
runtime: 3373,
143+
),
144+
),
145+
],
146+
total_block_cost: ExecutionCost(
147+
write_length: 17,
148+
write_count: 1,
149+
read_length: 1,
150+
read_count: 1,
151+
runtime: 3373,
152+
),
153+
)),
154+
]

stackslib/src/chainstate/tests/static_analysis_tests.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#[allow(unused_imports)]
1919
use clarity::vm::analysis::CheckErrorKind;
2020

21-
use crate::chainstate::tests::consensus::contract_deploy_consensus_test;
21+
use crate::chainstate::tests::consensus::{contract_deploy_consensus_test, SetupContract};
2222
use crate::core::BLOCK_LIMIT_MAINNET_21;
2323
use crate::util_lib::boot::boot_code_test_addr;
2424

@@ -204,3 +204,23 @@ fn static_check_error_expected_optional_type() {
204204
contract_code: "(default-to 3 5)",
205205
);
206206
}
207+
208+
/// StaticCheckErrorKind: [`StaticCheckErrorKind::BadTraitImplementation`]
209+
/// Caused by: trying to implement a trait with a bad implementation.
210+
/// Outcome: block accepted.
211+
#[test]
212+
fn static_check_error_bad_trait_implementation() {
213+
let setup_contract = SetupContract::new(
214+
"trait-contract",
215+
"(define-trait trait-1 ((get-1 ((list 10 uint)) (response uint uint))))",
216+
);
217+
218+
contract_deploy_consensus_test!(
219+
contract_name: "contract-name",
220+
contract_code: &format!("
221+
(impl-trait .trait-contract.trait-1)
222+
(define-public (get-1 (x (list 5 uint))) (ok u1))",
223+
),
224+
setup_contracts: &[setup_contract],
225+
);
226+
}

0 commit comments

Comments
 (0)