From e44f18bae5b97cf73d706d50c51fd9790ead3060 Mon Sep 17 00:00:00 2001 From: KtorZ Date: Fri, 10 Mar 2023 09:14:05 +0100 Subject: [PATCH] Add failing test scenario for recursive types. --- .../aiken-project/src/blueprint/validator.rs | 66 ++++++++++++++++++- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/crates/aiken-project/src/blueprint/validator.rs b/crates/aiken-project/src/blueprint/validator.rs index 0db0d96c..070854f9 100644 --- a/crates/aiken-project/src/blueprint/validator.rs +++ b/crates/aiken-project/src/blueprint/validator.rs @@ -265,7 +265,7 @@ mod test { } } - fn assert_validator(source_code: &str, json: serde_json::Value) { + fn assert_validator(source_code: &str, expected: serde_json::Value) { let mut project = TestProject::new(); let modules = CheckedModules::singleton(project.check(project.parse(source_code))); @@ -283,7 +283,9 @@ mod test { let validator = Validator::from_checked_module(&modules, &mut generator, validator, def) .expect("Failed to create validator blueprint"); - assert_json_eq!(serde_json::to_value(&validator).unwrap(), json); + println!("{}", serde_json::to_string_pretty(&validator).unwrap()); + + assert_json_eq!(serde_json::to_value(&validator).unwrap(), expected); } #[test] @@ -734,4 +736,64 @@ mod test { ), ); } + + #[test] + fn recursive_type() { + assert_validator( + r#" + pub type LinkedList { + Nil + Cons(a, LinkedList) + } + + pub type Foo { + Foo { + foo: LinkedList, + } + Bar { + bar: Int, + baz: (ByteArray, List>) + } + } + + validator spend { + fn(datum: Foo, redeemer: LinkedList, ctx: Void) { + True + } + } + "#, + json!({ + "redeemer": { + "schema": { + "$ref": "#/$defs/LinkedList_Int" + } + }, + "$defs": { + "LinkedList_Int": { + "anyOf": [ + { + "title": "Nil", + "dataType": "constructor", + "index": 0, + "fields": [] + }, + { + "title": "Cons", + "dataType": "constructor", + "index": 1, + "fields": [ + { + "dataType": "integer" + }, + { + "$ref": "#/$defs/LinkedList_Int" + }, + ] + } + ], + }, + } + }), + ) + } }