Skip to content

Commit e8ec90d

Browse files
authored
Merge pull request #6204 from csgui/wasm-issue-677/unchecked-type-error
[clarity-wasm-tests] fix Unchecked(TypeError(UIntType, IntType))
2 parents 71d75d1 + f5f441b commit e8ec90d

File tree

1 file changed

+54
-27
lines changed

1 file changed

+54
-27
lines changed

clarity/src/vm/tests/contracts.rs

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -97,51 +97,78 @@ fn test_get_block_info_eval(
9797
epoch: StacksEpochId,
9898
mut tl_env_factory: TopLevelMemoryEnvironmentGenerator,
9999
) {
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+
),
109131
];
110132

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+
}
121148

122-
let mut placeholder_context = ContractContext::new(
149+
let placeholder_context = ContractContext::new(
123150
QualifiedContractIdentifier::transient(),
124151
ClarityVersion::Clarity2,
125152
);
126153

127154
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 {
129156
let contract_identifier =
130-
QualifiedContractIdentifier::local(&format!("test-contract-{}", i)).unwrap();
157+
QualifiedContractIdentifier::local(&format!("test-contract-{}", case)).unwrap();
131158
owned_env
132159
.initialize_versioned_contract(
133160
contract_identifier.clone(),
134161
ClarityVersion::Clarity2,
135-
contracts[i],
162+
contract,
136163
None,
137164
ASTRules::PrecheckSize,
138165
)
139166
.unwrap();
140167

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);
143170
let eval_result = env.eval_read_only(&contract_identifier, "(test-func)");
144-
match expected[i] {
171+
match expected {
145172
// any (some UINT) is okay for checking get-block-info? time
146173
Ok(Value::UInt(0)) => {
147174
assert!(
@@ -152,7 +179,7 @@ fn test_get_block_info_eval(
152179
}
153180
);
154181
}
155-
_ => assert_eq!(expected[i], eval_result),
182+
_ => assert_eq!(expected, eval_result),
156183
}
157184
}
158185
}

0 commit comments

Comments
 (0)