@@ -97,51 +97,78 @@ fn test_get_block_info_eval(
97
97
epoch : StacksEpochId ,
98
98
mut tl_env_factory : TopLevelMemoryEnvironmentGenerator ,
99
99
) {
100
- let contracts = [
101
- "(define-private (test-func) (get-block-info? time u1))" ,
102
- "(define-private (test-func) (get-block-info? time block-height))" ,
103
- "(define-private (test-func) (get-block-info? time u100000))" ,
104
- "(define-private (test-func) (get-block-info? time (- 1)))" ,
105
- "(define-private (test-func) (get-block-info? time true))" ,
106
- "(define-private (test-func) (get-block-info? header-hash u1))" ,
107
- "(define-private (test-func) (get-block-info? burnchain-header-hash u1))" ,
108
- "(define-private (test-func) (get-block-info? vrf-seed u1))" ,
100
+ let mut test_cases = vec ! [
101
+ (
102
+ "case-1" ,
103
+ "(define-private (test-func) (get-block-info? time u1))" ,
104
+ Ok ( Value :: none( ) ) ,
105
+ ) ,
106
+ (
107
+ "case-2" ,
108
+ "(define-private (test-func) (get-block-info? time block-height))" ,
109
+ Ok ( Value :: none( ) ) ,
110
+ ) ,
111
+ (
112
+ "case-3" ,
113
+ "(define-private (test-func) (get-block-info? time u100000))" ,
114
+ Ok ( Value :: none( ) ) ,
115
+ ) ,
116
+ (
117
+ "case-4" ,
118
+ "(define-private (test-func) (get-block-info? header-hash u1))" ,
119
+ Ok ( Value :: none( ) ) ,
120
+ ) ,
121
+ (
122
+ "case-5" ,
123
+ "(define-private (test-func) (get-block-info? burnchain-header-hash u1))" ,
124
+ Ok ( Value :: none( ) ) ,
125
+ ) ,
126
+ (
127
+ "case-6" ,
128
+ "(define-private (test-func) (get-block-info? vrf-seed u1))" ,
129
+ Ok ( Value :: none( ) ) ,
130
+ ) ,
109
131
] ;
110
132
111
- let expected = [
112
- Ok ( Value :: none ( ) ) ,
113
- Ok ( Value :: none ( ) ) ,
114
- Ok ( Value :: none ( ) ) ,
115
- Err ( CheckErrors :: TypeValueError ( TypeSignature :: UIntType , Value :: Int ( -1 ) ) . into ( ) ) ,
116
- Err ( CheckErrors :: TypeValueError ( TypeSignature :: UIntType , Value :: Bool ( true ) ) . into ( ) ) ,
117
- Ok ( Value :: none ( ) ) ,
118
- Ok ( Value :: none ( ) ) ,
119
- Ok ( Value :: none ( ) ) ,
120
- ] ;
133
+ // test cases where the clarity-wasm analysis pass would fail.
134
+ if cfg ! ( not( feature = "clarity-wasm" ) ) {
135
+ test_cases. extend ( [
136
+ (
137
+ "case-7" ,
138
+ "(define-private (test-func) (get-block-info? time (- 1)))" ,
139
+ Err ( CheckErrors :: TypeValueError ( TypeSignature :: UIntType , Value :: Int ( -1 ) ) . into ( ) ) ,
140
+ ) ,
141
+ (
142
+ "case-8" ,
143
+ "(define-private (test-func) (get-block-info? time true))" ,
144
+ Err ( CheckErrors :: TypeValueError ( TypeSignature :: UIntType , Value :: Bool ( true ) ) . into ( ) ) ,
145
+ ) ,
146
+ ] ) ;
147
+ }
121
148
122
- let mut placeholder_context = ContractContext :: new (
149
+ let placeholder_context = ContractContext :: new (
123
150
QualifiedContractIdentifier :: transient ( ) ,
124
151
ClarityVersion :: Clarity2 ,
125
152
) ;
126
153
127
154
let mut owned_env = tl_env_factory. get_env ( epoch) ;
128
- for i in 0 ..contracts . len ( ) {
155
+ for ( case , contract , expected ) in test_cases {
129
156
let contract_identifier =
130
- QualifiedContractIdentifier :: local ( & format ! ( "test-contract-{}" , i ) ) . unwrap ( ) ;
157
+ QualifiedContractIdentifier :: local ( & format ! ( "test-contract-{}" , case ) ) . unwrap ( ) ;
131
158
owned_env
132
159
. initialize_versioned_contract (
133
160
contract_identifier. clone ( ) ,
134
161
ClarityVersion :: Clarity2 ,
135
- contracts [ i ] ,
162
+ contract ,
136
163
None ,
137
164
ASTRules :: PrecheckSize ,
138
165
)
139
166
. unwrap ( ) ;
140
167
141
- let mut env = owned_env. get_exec_environment ( None , None , & mut placeholder_context) ;
142
- eprintln ! ( "{}" , contracts [ i ] ) ;
168
+ let mut env = owned_env. get_exec_environment ( None , None , & placeholder_context) ;
169
+ eprintln ! ( "{}" , contract ) ;
143
170
let eval_result = env. eval_read_only ( & contract_identifier, "(test-func)" ) ;
144
- match expected[ i ] {
171
+ match expected {
145
172
// any (some UINT) is okay for checking get-block-info? time
146
173
Ok ( Value :: UInt ( 0 ) ) => {
147
174
assert ! (
@@ -152,7 +179,7 @@ fn test_get_block_info_eval(
152
179
}
153
180
) ;
154
181
}
155
- _ => assert_eq ! ( expected[ i ] , eval_result) ,
182
+ _ => assert_eq ! ( expected, eval_result) ,
156
183
}
157
184
}
158
185
}
0 commit comments