diff --git a/src/compiler/clvm.rs b/src/compiler/clvm.rs index a0b7765b..b4b31262 100644 --- a/src/compiler/clvm.rs +++ b/src/compiler/clvm.rs @@ -431,6 +431,16 @@ pub fn get_history_len(step: Rc) -> usize { /// Generically determine whether a value is truthy. pub fn truthy(sexp: Rc) -> bool { + if NewStyleIntConversion::setting() { + // The previous truthy would not have taken account of all zero bit + // values of lengths other than zero. + match sexp.borrow() { + SExp::Atom(_, a) => { return a.len() != 0; } + SExp::QuotedString(_, _, a) => { return a.len() != 0; } + _ => { } + } + } + // Fails for cons, but cons is truthy atom_value(sexp).unwrap_or_else(|_| bi_one()) != bi_zero() } diff --git a/src/tests/classic/zero_constant_generation.rs b/src/tests/classic/zero_constant_generation.rs index f14e44e8..98814030 100644 --- a/src/tests/classic/zero_constant_generation.rs +++ b/src/tests/classic/zero_constant_generation.rs @@ -35,3 +35,43 @@ fn test_fuzz_constant_gen() { test_parallel_run(test); } } + +#[test] +fn test_truthy_in_constant_generation() { + let test_program = "(mod X %1 (defconst C (if %c 1 0)) X)"; + + let test_parallel_run = |test| { + let final_program_classic = test_program.replace("%1", "").replace("%c", test); + let final_program_23_1 = test_program + .replace("%1", "(include *standard-cl-23.1*)") + .replace("%c", test); + let classic = do_basic_run(&vec!["run".to_string(), final_program_classic]); + let new_ver = do_basic_run(&vec!["run".to_string(), final_program_23_1]); + let classic_output = do_basic_brun(&vec!["brun".to_string(), classic, "0x01".to_string()]); + let new_output = do_basic_brun(&vec!["brun".to_string(), new_ver, "0x01".to_string()]); + assert_eq!(classic_output, new_output); + }; + + for test in [ + "0", + "\"\"", + "()", + "0x00", + "(concat 0 0)", + "(concat 0x00 0x00)", + "(concat 0 0x00)", + "(concat 1 0x00)", + "(concat -1 0x00)", + "(concat -129 0x00)", + "(concat 0x00 0)", + "(concat 0x00 1)", + "(concat 0x00 -1)", + "(concat 0x00 -129)", + "(concat 0x00 (sha256 0x00 0))", + "(concat 0x00 (sha256 0 0x00 0))", + ] + .iter() + { + test_parallel_run(test); + } +} diff --git a/src/tests/compiler/mod.rs b/src/tests/compiler/mod.rs index 1c5db92c..2d6b6813 100644 --- a/src/tests/compiler/mod.rs +++ b/src/tests/compiler/mod.rs @@ -11,6 +11,7 @@ mod compiler; mod evaluate; mod fuzz; mod fuzz_assign; +mod fuzz_program; mod optimizer; mod preprocessor; mod repl;