diff --git a/crates/aiken-project/src/blueprint/validator.rs b/crates/aiken-project/src/blueprint/validator.rs index b2523918..a7b534ca 100644 --- a/crates/aiken-project/src/blueprint/validator.rs +++ b/crates/aiken-project/src/blueprint/validator.rs @@ -703,6 +703,107 @@ mod test { ); } + #[test] + fn acceptance_test_4_concat_no_anon_func() { + let src = r#" + pub fn foldr(xs: List, f: fn(a, b) -> b, zero: b) -> b { + when xs is { + [] -> + zero + [x, ..rest] -> + f(x, foldr(rest, f, zero)) + } + } + + pub fn prepend(x: a, xs: List) -> List { + [x, ..xs] + } + + pub fn concat(left: List, right: List) -> List { + foldr(left, prepend, right) + } + + test concat_1() { + concat([1, 2, 3], [4, 5, 6]) == [1, 2, 3, 4, 5, 6] + } + "#; + + assert_uplc( + src, + Term::equals_data() + .apply( + Term::list_data().apply( + Term::var("concat") + .lambda("concat") + .apply( + Term::var("foldr") + .apply(Term::var("left")) + .apply(Term::var("prepend")) + .apply(Term::var("right")) + .lambda("right") + .lambda("left"), + ) + .lambda("prepend") + .apply( + Term::mk_cons() + .apply(Term::i_data().apply(Term::var("x"))) + .apply(Term::var("xs")) + .lambda("xs") + .lambda("x"), + ) + .lambda("foldr") + .apply(Term::var("foldr").apply(Term::var("foldr"))) + .lambda("foldr") + .apply( + Term::var("xs") + .delayed_choose_list( + Term::var("zero"), + Term::var("f") + .apply(Term::var("x")) + .apply( + Term::var("foldr") + .apply(Term::var("foldr")) + .apply(Term::var("rest")) + .apply(Term::var("f")) + .apply(Term::var("zero")), + ) + .lambda("rest") + .apply(Term::tail_list().apply(Term::var("xs"))) + .lambda("x") + .apply( + Term::un_i_data().apply( + Term::head_list().apply(Term::var("xs")), + ), + ), + ) + .lambda("zero") + .lambda("f") + .lambda("xs") + .lambda("foldr"), + ) + .apply(Term::list_values(vec![ + Constant::Data(PlutusData::BigInt(BigInt::Int(1.into()))), + Constant::Data(PlutusData::BigInt(BigInt::Int(2.into()))), + Constant::Data(PlutusData::BigInt(BigInt::Int(3.into()))), + ])) + .apply(Term::list_values(vec![ + Constant::Data(PlutusData::BigInt(BigInt::Int(4.into()))), + Constant::Data(PlutusData::BigInt(BigInt::Int(5.into()))), + Constant::Data(PlutusData::BigInt(BigInt::Int(6.into()))), + ])), + ), + ) + .apply(Term::list_data().apply(Term::list_values(vec![ + Constant::Data(PlutusData::BigInt(BigInt::Int(1.into()))), + Constant::Data(PlutusData::BigInt(BigInt::Int(2.into()))), + Constant::Data(PlutusData::BigInt(BigInt::Int(3.into()))), + Constant::Data(PlutusData::BigInt(BigInt::Int(4.into()))), + Constant::Data(PlutusData::BigInt(BigInt::Int(5.into()))), + Constant::Data(PlutusData::BigInt(BigInt::Int(6.into()))), + ]))), + ); + } + #[test] fn mint_parameterized() { assert_validator(