Formatting
This commit is contained in:
parent
699628df62
commit
d353e07ea1
|
@ -261,9 +261,11 @@ impl Type {
|
|||
},
|
||||
],
|
||||
}],
|
||||
}.into(),
|
||||
}
|
||||
.into(),
|
||||
},
|
||||
}.into(),
|
||||
}
|
||||
.into(),
|
||||
),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -499,7 +499,7 @@ pub fn prelude(id_gen: &IdGenerator) -> TypeInfo {
|
|||
// fn(PRNG, Int) -> Option<(PRNG, a)>
|
||||
let scaled_fuzzer_value = Type::generic_var(id_gen.next());
|
||||
prelude.types.insert(
|
||||
well_known::SCALED_FUZZER.to_string(),
|
||||
well_known::SCALED_FUZZER.to_string(),
|
||||
TypeConstructor {
|
||||
location: Span::empty(),
|
||||
parameters: vec![scaled_fuzzer_value.clone()],
|
||||
|
|
|
@ -385,7 +385,9 @@ impl PropertyTest {
|
|||
value,
|
||||
choices: next_prng.choices(),
|
||||
cache: Cache::new(move |choices| {
|
||||
match Prng::from_choices(choices, iteration).sample(&self.fuzzer.program, iteration) {
|
||||
match Prng::from_choices(choices, iteration)
|
||||
.sample(&self.fuzzer.program, iteration)
|
||||
{
|
||||
Err(..) => Status::Invalid,
|
||||
Ok(None) => Status::Invalid,
|
||||
Ok(Some((_, value))) => {
|
||||
|
@ -504,13 +506,13 @@ impl PropertyTest {
|
|||
///
|
||||
#[derive(Debug)]
|
||||
pub enum Prng {
|
||||
Seeded {
|
||||
choices: Vec<u8>,
|
||||
Seeded {
|
||||
choices: Vec<u8>,
|
||||
uplc: PlutusData,
|
||||
iteration: usize,
|
||||
},
|
||||
Replayed {
|
||||
choices: Vec<u8>,
|
||||
Replayed {
|
||||
choices: Vec<u8>,
|
||||
uplc: PlutusData,
|
||||
iteration: usize,
|
||||
},
|
||||
|
@ -556,10 +558,7 @@ impl Prng {
|
|||
choices: vec![],
|
||||
uplc: Data::constr(
|
||||
Prng::SEEDED,
|
||||
vec![
|
||||
Data::bytestring(digest.to_vec()),
|
||||
Data::bytestring(vec![]),
|
||||
],
|
||||
vec![Data::bytestring(digest.to_vec()), Data::bytestring(vec![])],
|
||||
),
|
||||
iteration: 0,
|
||||
}
|
||||
|
@ -591,7 +590,7 @@ impl Prng {
|
|||
let program_clone = program.clone();
|
||||
|
||||
let result = program.eval(ExBudget::max());
|
||||
|
||||
|
||||
match result.result() {
|
||||
Ok(term) if matches!(term, Term::Constant(_)) => {
|
||||
// If we got a valid constant result, process it
|
||||
|
@ -599,22 +598,19 @@ impl Prng {
|
|||
}
|
||||
_ => {
|
||||
// Use the cloned program for the second attempt
|
||||
let program_with_iteration = Program::<NamedDeBruijn>::try_from(
|
||||
program_clone.apply_data(Data::integer(num_bigint::BigInt::from(iteration as i64)))
|
||||
).unwrap();
|
||||
|
||||
let program_with_iteration = program_clone
|
||||
.apply_data(Data::integer(num_bigint::BigInt::from(iteration as i64)));
|
||||
|
||||
let mut result = program_with_iteration.eval(ExBudget::max());
|
||||
match result.result() {
|
||||
Ok(term) if matches!(term, Term::Constant(_)) => {
|
||||
Ok(Prng::from_result(term, iteration))
|
||||
}
|
||||
Err(uplc_error) => {
|
||||
Err(FuzzerError {
|
||||
traces: result.logs(),
|
||||
uplc_error,
|
||||
})
|
||||
}
|
||||
_ => unreachable!("Fuzzer returned a malformed result? {result:#?}")
|
||||
Err(uplc_error) => Err(FuzzerError {
|
||||
traces: result.logs(),
|
||||
uplc_error,
|
||||
}),
|
||||
_ => unreachable!("Fuzzer returned a malformed result? {result:#?}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -630,7 +626,10 @@ impl Prng {
|
|||
/// made during shrinking aren't breaking underlying invariants (if only, because we run out of
|
||||
/// values to replay). In such case, the replayed sequence is simply invalid and the fuzzer
|
||||
/// aborted altogether with 'None'.
|
||||
pub fn from_result(result: Term<NamedDeBruijn>, iteration: usize) -> Option<(Self, PlutusData)> {
|
||||
pub fn from_result(
|
||||
result: Term<NamedDeBruijn>,
|
||||
iteration: usize,
|
||||
) -> Option<(Self, PlutusData)> {
|
||||
/// Interpret the given 'PlutusData' as one of two Prng constructors.
|
||||
fn as_prng(cst: &PlutusData, iteration: usize) -> Prng {
|
||||
if let PlutusData::Constr(Constr { tag, fields, .. }) = cst {
|
||||
|
|
|
@ -861,8 +861,12 @@ fn infer_scaled_fuzzer(
|
|||
// Check if this is a ScaledFuzzer (fn(PRNG, Int) -> Option<(PRNG, a)>)
|
||||
if args.len() == 2 {
|
||||
match ret.borrow() {
|
||||
Type::App { module, name, args: ret_args, .. }
|
||||
if module.is_empty() && name == "Option" && ret_args.len() == 1 => {
|
||||
Type::App {
|
||||
module,
|
||||
name,
|
||||
args: ret_args,
|
||||
..
|
||||
} if module.is_empty() && name == "Option" && ret_args.len() == 1 => {
|
||||
if let Type::Tuple { elems, .. } = ret_args[0].borrow() {
|
||||
if elems.len() == 2 {
|
||||
let wrapped = &elems[1];
|
||||
|
@ -879,7 +883,7 @@ fn infer_scaled_fuzzer(
|
|||
}
|
||||
}
|
||||
}
|
||||
_ => ()
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -947,4 +951,4 @@ fn put_params_in_scope<'a>(
|
|||
ArgName::Named { .. } | ArgName::Discarded { .. } => (),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -417,9 +417,8 @@ where
|
|||
error,
|
||||
path: options.blueprint_path,
|
||||
}
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
.into()
|
||||
})
|
||||
}
|
||||
CodeGenMode::Test {
|
||||
match_tests,
|
||||
|
|
|
@ -230,8 +230,7 @@ impl EventListener for Terminal {
|
|||
" Complete"
|
||||
.if_supports_color(Stderr, |s| s.bold())
|
||||
.if_supports_color(Stderr, |s| s.green()),
|
||||
"benchmark results written to CSV"
|
||||
.if_supports_color(Stderr, |s| s.bold())
|
||||
"benchmark results written to CSV".if_supports_color(Stderr, |s| s.bold())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue