feat: add ability to reference validators in tests closes #632
This commit is contained in:
parent
13ee62c05c
commit
e7c1b28b52
|
@ -14,6 +14,7 @@
|
|||
- **aiken-lang**: Parsing of error / todo keywords in when cases
|
||||
- **aiken-lang**: Parsing of negative integer patterns and constants
|
||||
- **aiken-lang**: automatically infer unused validator args as `Data`
|
||||
- **aiken-lang**: test crashing when referencing validators
|
||||
- **aiken**: mem and cpu values were not showing in white terminals, switched to cyan
|
||||
|
||||
### Changed
|
||||
|
|
|
@ -88,6 +88,23 @@ impl<'a> CodeGenerator<'a> {
|
|||
self.defined_functions = IndexMap::new();
|
||||
}
|
||||
|
||||
pub fn insert_function(
|
||||
&mut self,
|
||||
module_name: String,
|
||||
function_name: String,
|
||||
variant_name: String,
|
||||
value: &'a TypedFunction,
|
||||
) -> Option<&'a TypedFunction> {
|
||||
self.functions.insert(
|
||||
FunctionAccessKey {
|
||||
module_name,
|
||||
function_name,
|
||||
variant_name,
|
||||
},
|
||||
value,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn generate(
|
||||
&mut self,
|
||||
TypedValidator {
|
||||
|
|
|
@ -162,7 +162,7 @@ impl fmt::Display for Token {
|
|||
Token::Fn => "fn",
|
||||
Token::If => "if",
|
||||
Token::Else => "else",
|
||||
Token::Use => "import",
|
||||
Token::Use => "use",
|
||||
Token::Let => "let",
|
||||
Token::Opaque => "opaque",
|
||||
Token::Pub => "pub",
|
||||
|
|
|
@ -16,7 +16,7 @@ mod tests;
|
|||
|
||||
use crate::blueprint::Blueprint;
|
||||
use aiken_lang::{
|
||||
ast::{Definition, Function, ModuleKind, Tracing, TypedDataType, TypedFunction},
|
||||
ast::{Definition, Function, ModuleKind, Tracing, TypedDataType, TypedFunction, Validator},
|
||||
builtins,
|
||||
gen_uplc::builder::{DataTypeKey, FunctionAccessKey},
|
||||
tipo::TypeInfo,
|
||||
|
@ -638,6 +638,7 @@ where
|
|||
tracing: bool,
|
||||
) -> Result<Vec<Script>, Error> {
|
||||
let mut scripts = Vec::new();
|
||||
let mut testable_validators = Vec::new();
|
||||
|
||||
let match_tests = match_tests.map(|mt| {
|
||||
mt.into_iter()
|
||||
|
@ -669,7 +670,29 @@ where
|
|||
}
|
||||
|
||||
for def in checked_module.ast.definitions() {
|
||||
if let Definition::Test(func) = def {
|
||||
match def {
|
||||
Definition::Validator(Validator {
|
||||
params,
|
||||
fun,
|
||||
other_fun,
|
||||
..
|
||||
}) => {
|
||||
let mut fun = fun.clone();
|
||||
|
||||
fun.arguments = params.clone().into_iter().chain(fun.arguments).collect();
|
||||
|
||||
testable_validators.push((&checked_module.name, fun));
|
||||
|
||||
if let Some(other) = other_fun {
|
||||
let mut other = other.clone();
|
||||
|
||||
other.arguments =
|
||||
params.clone().into_iter().chain(other.arguments).collect();
|
||||
|
||||
testable_validators.push((&checked_module.name, other));
|
||||
}
|
||||
}
|
||||
Definition::Test(func) => {
|
||||
if let Some(match_tests) = &match_tests {
|
||||
let is_match = match_tests.iter().any(|(module, names)| {
|
||||
let matched_module =
|
||||
|
@ -704,11 +727,29 @@ where
|
|||
))
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mut programs = Vec::new();
|
||||
|
||||
let mut generator = self.checked_modules.new_generator(
|
||||
&self.functions,
|
||||
&self.data_types,
|
||||
&self.module_types,
|
||||
tracing,
|
||||
);
|
||||
|
||||
for (module_name, testable_validator) in &testable_validators {
|
||||
generator.insert_function(
|
||||
module_name.to_string(),
|
||||
testable_validator.name.clone(),
|
||||
String::new(),
|
||||
testable_validator,
|
||||
);
|
||||
}
|
||||
|
||||
for (input_path, module_name, func_def) in scripts {
|
||||
let Function {
|
||||
name,
|
||||
|
@ -724,13 +765,6 @@ where
|
|||
})
|
||||
}
|
||||
|
||||
let mut generator = self.checked_modules.new_generator(
|
||||
&self.functions,
|
||||
&self.data_types,
|
||||
&self.module_types,
|
||||
tracing,
|
||||
);
|
||||
|
||||
let evaluation_hint = func_def.test_hint().map(|(bin_op, left_src, right_src)| {
|
||||
let left = generator
|
||||
.clone()
|
||||
|
|
|
@ -335,7 +335,7 @@ impl CheckedModules {
|
|||
Definition::TypeAlias(_)
|
||||
| Definition::ModuleConstant(_)
|
||||
| Definition::Test(_)
|
||||
| Definition::Validator { .. }
|
||||
| Definition::Validator(_)
|
||||
| Definition::Use(_) => {}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue