Fix few blueprint generation tests
Some remains invalid, in particular: - We need to handle the annotated Data case, which we still parse correctly but do nothing about any longer. - There's also a strange behavior with opaque type turned public?
This commit is contained in:
parent
f9acbd3bcb
commit
c706d6072d
|
@ -1,9 +1,15 @@
|
||||||
---
|
---
|
||||||
source: crates/aiken-project/src/blueprint/validator.rs
|
source: crates/aiken-project/src/blueprint/validator.rs
|
||||||
description: "Code:\n\ntype Either<left, right> {\n Left(left)\n Right(right)\n}\n\ntype Interval<a> {\n Finite(a)\n Infinite\n}\n\nvalidator {\n fn generics(redeemer: Either<ByteArray, Interval<Int>>, ctx: Void) {\n True\n }\n}\n"
|
description: "Code:\n\npub type Either<left, right> {\n Left(left)\n Right(right)\n}\n\npub type Interval<a> {\n Finite(a)\n Infinite\n}\n\nvalidator generics {\n spend(datum: Option<Data>, redeemer: Either<ByteArray, Interval<Int>>, output_reference: Data, transaction: Data) {\n True\n }\n}\n"
|
||||||
---
|
---
|
||||||
{
|
{
|
||||||
"title": "test_module.generics",
|
"title": "test_module.generics_spend",
|
||||||
|
"datum": {
|
||||||
|
"title": "datum",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/Data"
|
||||||
|
}
|
||||||
|
},
|
||||||
"redeemer": {
|
"redeemer": {
|
||||||
"title": "redeemer",
|
"title": "redeemer",
|
||||||
"schema": {
|
"schema": {
|
||||||
|
@ -16,6 +22,10 @@ description: "Code:\n\ntype Either<left, right> {\n Left(left)\n Right(rig
|
||||||
"ByteArray": {
|
"ByteArray": {
|
||||||
"dataType": "bytes"
|
"dataType": "bytes"
|
||||||
},
|
},
|
||||||
|
"Data": {
|
||||||
|
"title": "Data",
|
||||||
|
"description": "Any Plutus data."
|
||||||
|
},
|
||||||
"Int": {
|
"Int": {
|
||||||
"dataType": "integer"
|
"dataType": "integer"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
---
|
---
|
||||||
source: crates/aiken-project/src/blueprint/validator.rs
|
source: crates/aiken-project/src/blueprint/validator.rs
|
||||||
description: "Code:\n\ntype Dict<key, value> {\n inner: List<(ByteArray, value)>\n}\n\ntype UUID { UUID }\n\nvalidator {\n fn list_2_tuples_as_list(redeemer: Dict<UUID, Int>, ctx: Void) {\n True\n }\n}\n"
|
description: "Code:\n\npub type Dict<key, value> {\n inner: List<(ByteArray, value)>\n}\n\npub type UUID { UUID }\n\nvalidator list_2_tuples_as_list {\n mint(redeemer: Dict<UUID, Int>, policy_id: ByteArray, transaction: Data) {\n True\n }\n}\n"
|
||||||
---
|
---
|
||||||
{
|
{
|
||||||
"title": "test_module.list_2_tuples_as_list",
|
"title": "test_module.list_2_tuples_as_list_mint",
|
||||||
"redeemer": {
|
"redeemer": {
|
||||||
"title": "redeemer",
|
"title": "redeemer",
|
||||||
"schema": {
|
"schema": {
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
---
|
---
|
||||||
source: crates/aiken-project/src/blueprint/validator.rs
|
source: crates/aiken-project/src/blueprint/validator.rs
|
||||||
description: "Code:\n\nvalidator(utxo_ref: Int) {\n fn mint(redeemer: Data, ctx: Data) {\n True\n }\n}\n// "
|
description: "Code:\n\nvalidator thing(utxo_ref: Int) {\n mint(redeemer: Data, policy_id: ByteArray, transaction: Data) {\n True\n }\n}\n// "
|
||||||
---
|
---
|
||||||
{
|
{
|
||||||
"title": "test_module.mint",
|
"title": "test_module.thing_mint",
|
||||||
"redeemer": {
|
"redeemer": {
|
||||||
"title": "redeemer",
|
"title": "redeemer",
|
||||||
"schema": {
|
"schema": {
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
---
|
---
|
||||||
source: crates/aiken-project/src/blueprint/validator.rs
|
source: crates/aiken-project/src/blueprint/validator.rs
|
||||||
description: "Code:\n\npub type Foo {\n foo: Data\n}\n\nvalidator {\n fn nested_data(datum: Foo, redeemer: Int, ctx: Void) {\n True\n }\n}\n"
|
description: "Code:\n\npub type Foo {\n foo: Data\n}\n\nvalidator nested_data {\n spend(datum: Option<Foo>, redeemer: Int, output_reference: Data, transaction: Data) {\n True\n }\n}\n"
|
||||||
---
|
---
|
||||||
{
|
{
|
||||||
"title": "test_module.nested_data",
|
"title": "test_module.nested_data_spend",
|
||||||
"datum": {
|
"datum": {
|
||||||
"title": "datum",
|
"title": "datum",
|
||||||
"schema": {
|
"schema": {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
---
|
---
|
||||||
source: crates/aiken-project/src/blueprint/validator.rs
|
source: crates/aiken-project/src/blueprint/validator.rs
|
||||||
description: "Code:\n\npub opaque type Rational {\n numerator: Int,\n denominator: Int,\n}\n\nvalidator opaque_singleton_multi_variants {\n spend(redeemer: Rational, oref: Data, ctx: Void) {\n True\n }\n}\n"
|
description: "Code:\n\npub opaque type Rational {\n numerator: Int,\n denominator: Int,\n}\n\nvalidator opaque_singleton_multi_variants {\n spend(datum: Option<Data>, redeemer: Rational, oref: Data, transaction: Data) {\n True\n }\n}\n"
|
||||||
---
|
---
|
||||||
Schema {
|
Schema {
|
||||||
error: Error {
|
error: Error {
|
||||||
|
@ -16,7 +16,7 @@ Schema {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
location: 120..138,
|
location: 141..159,
|
||||||
source_code: NamedSource {
|
source_code: NamedSource {
|
||||||
name: "",
|
name: "",
|
||||||
source: "<redacted>",
|
source: "<redacted>",
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
---
|
---
|
||||||
source: crates/aiken-project/src/blueprint/validator.rs
|
source: crates/aiken-project/src/blueprint/validator.rs
|
||||||
description: "Code:\n\npub type LinkedList<a> {\n Cons(a, LinkedList<a>)\n Nil\n}\n\npub type Foo {\n Foo {\n foo: LinkedList<Bool>,\n }\n Bar {\n bar: Int,\n baz: (ByteArray, List<LinkedList<Int>>)\n }\n}\n\nvalidator {\n fn recursive_generic_types(datum: Foo, redeemer: LinkedList<Int>, ctx: Void) {\n True\n }\n}\n"
|
description: "Code:\n\npub type LinkedList<a> {\n Cons(a, LinkedList<a>)\n Nil\n}\n\npub type Foo {\n Foo {\n foo: LinkedList<Bool>,\n }\n Bar {\n bar: Int,\n baz: (ByteArray, List<LinkedList<Int>>)\n }\n}\n\nvalidator recursive_generic_types {\n spend(datum: Option<Foo>, redeemer: LinkedList<Int>, output_reference: Data, transaction: Data) {\n True\n }\n}\n"
|
||||||
---
|
---
|
||||||
{
|
{
|
||||||
"title": "test_module.recursive_generic_types",
|
"title": "test_module.recursive_generic_types_spend",
|
||||||
"datum": {
|
"datum": {
|
||||||
"title": "datum",
|
"title": "datum",
|
||||||
"schema": {
|
"schema": {
|
||||||
|
|
|
@ -1,9 +1,15 @@
|
||||||
---
|
---
|
||||||
source: crates/aiken-project/src/blueprint/validator.rs
|
source: crates/aiken-project/src/blueprint/validator.rs
|
||||||
description: "Code:\n\npub type Expr {\n Val(Int)\n Sum(Expr, Expr)\n Mul(Expr, Expr)\n}\n\nvalidator {\n fn recursive_types(redeemer: Expr, ctx: Void) {\n True\n }\n}\n"
|
description: "Code:\n\npub type Expr {\n Val(Int)\n Sum(Expr, Expr)\n Mul(Expr, Expr)\n}\n\nvalidator recursive_types {\n spend(datum: Option<Data>, redeemer: Expr, output_reference: Data, transaction: Data) {\n True\n }\n}\n"
|
||||||
---
|
---
|
||||||
{
|
{
|
||||||
"title": "test_module.recursive_types",
|
"title": "test_module.recursive_types_spend",
|
||||||
|
"datum": {
|
||||||
|
"title": "datum",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/Data"
|
||||||
|
}
|
||||||
|
},
|
||||||
"redeemer": {
|
"redeemer": {
|
||||||
"title": "redeemer",
|
"title": "redeemer",
|
||||||
"schema": {
|
"schema": {
|
||||||
|
@ -13,6 +19,10 @@ description: "Code:\n\npub type Expr {\n Val(Int)\n Sum(Expr, Expr)\n Mul(Exp
|
||||||
"compiledCode": "<redacted>",
|
"compiledCode": "<redacted>",
|
||||||
"hash": "<redacted>",
|
"hash": "<redacted>",
|
||||||
"definitions": {
|
"definitions": {
|
||||||
|
"Data": {
|
||||||
|
"title": "Data",
|
||||||
|
"description": "Any Plutus data."
|
||||||
|
},
|
||||||
"Int": {
|
"Int": {
|
||||||
"dataType": "integer"
|
"dataType": "integer"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
---
|
---
|
||||||
source: crates/aiken-project/src/blueprint/validator.rs
|
source: crates/aiken-project/src/blueprint/validator.rs
|
||||||
description: "Code:\n\n/// On-chain state\ntype State {\n /// The contestation period as a number of seconds\n contestationPeriod: ContestationPeriod,\n /// List of public key hashes of all participants\n parties: List<Party>,\n utxoHash: Hash<Blake2b_256>,\n}\n\n/// A Hash digest for a given algorithm.\ntype Hash<alg> = ByteArray\n\ntype Blake2b_256 { Blake2b_256 }\n\n/// Whatever\ntype ContestationPeriod {\n /// A positive, non-zero number of seconds.\n ContestationPeriod(Int)\n}\n\ntype Party =\n ByteArray\n\ntype Input {\n CollectCom\n Close\n /// Abort a transaction\n Abort\n}\n\nvalidator {\n fn simplified_hydra(datum: State, redeemer: Input, ctx: Data) {\n True\n }\n}\n"
|
description: "Code:\n\n/// On-chain state\npub type State {\n /// The contestation period as a number of seconds\n contestationPeriod: ContestationPeriod,\n /// List of public key hashes of all participants\n parties: List<Party>,\n utxoHash: Hash<Blake2b_256>,\n}\n\n/// A Hash digest for a given algorithm.\npub type Hash<alg> = ByteArray\n\npub type Blake2b_256 { Blake2b_256 }\n\n/// Whatever\npub type ContestationPeriod {\n /// A positive, non-zero number of seconds.\n ContestationPeriod(Int)\n}\n\npub type Party =\n ByteArray\n\npub type Input {\n CollectCom\n Close\n /// Abort a transaction\n Abort\n}\n\nvalidator simplified_hydra {\n spend(datum: Option<State>, redeemer: Input, output_reference: Data, transaction: Data) {\n True\n }\n}\n"
|
||||||
---
|
---
|
||||||
{
|
{
|
||||||
"title": "test_module.simplified_hydra",
|
"title": "test_module.simplified_hydra_spend",
|
||||||
"datum": {
|
"datum": {
|
||||||
"title": "datum",
|
"title": "datum",
|
||||||
"schema": {
|
"schema": {
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
---
|
---
|
||||||
source: crates/aiken-project/src/blueprint/validator.rs
|
source: crates/aiken-project/src/blueprint/validator.rs
|
||||||
description: "Code:\n\nvalidator {\n fn tuples(datum: (Int, ByteArray), redeemer: (Int, Int, Int), ctx: Void) {\n True\n }\n}\n"
|
description: "Code:\n\nvalidator tuples {\n spend(datum: Option<(Int, ByteArray)>, redeemer: (Int, Int, Int), output_reference: Data, transaction: Data) {\n True\n }\n}\n"
|
||||||
---
|
---
|
||||||
{
|
{
|
||||||
"title": "test_module.tuples",
|
"title": "test_module.tuples_spend",
|
||||||
"datum": {
|
"datum": {
|
||||||
"title": "datum",
|
"title": "datum",
|
||||||
"schema": {
|
"schema": {
|
||||||
|
|
|
@ -7,7 +7,7 @@ use super::{
|
||||||
};
|
};
|
||||||
use crate::module::{CheckedModule, CheckedModules};
|
use crate::module::{CheckedModule, CheckedModules};
|
||||||
use aiken_lang::{
|
use aiken_lang::{
|
||||||
ast::{Annotation, TypedArg, TypedFunction, TypedValidator},
|
ast::{well_known, Annotation, TypedArg, TypedFunction, TypedValidator},
|
||||||
gen_uplc::CodeGenerator,
|
gen_uplc::CodeGenerator,
|
||||||
plutus_version::PlutusVersion,
|
plutus_version::PlutusVersion,
|
||||||
tipo::Type,
|
tipo::Type,
|
||||||
|
@ -124,9 +124,18 @@ impl Validator {
|
||||||
|
|
||||||
let datum = datum
|
let datum = datum
|
||||||
.map(|datum| {
|
.map(|datum| {
|
||||||
|
match datum.tipo.as_ref() {
|
||||||
|
Type::App { module: module_name, name, args, .. } if module_name.is_empty() && name == well_known::OPTION => {
|
||||||
Annotated::from_type(
|
Annotated::from_type(
|
||||||
modules.into(),
|
modules.into(),
|
||||||
tipo_or_annotation(module, datum),
|
tipo_or_annotation(module, &TypedArg {
|
||||||
|
arg_name: datum.arg_name.clone(),
|
||||||
|
location: datum.location,
|
||||||
|
annotation: datum.annotation.clone(),
|
||||||
|
doc: datum.doc.clone(),
|
||||||
|
is_validator_param: datum.is_validator_param,
|
||||||
|
tipo: args.first().expect("Option always have a single type argument.").clone()
|
||||||
|
}),
|
||||||
&mut definitions,
|
&mut definitions,
|
||||||
)
|
)
|
||||||
.map_err(|error| Error::Schema {
|
.map_err(|error| Error::Schema {
|
||||||
|
@ -137,6 +146,9 @@ impl Validator {
|
||||||
module.code.clone(),
|
module.code.clone(),
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
_ => panic!("Datum isn't an option but should be; this should have been caught by the type-checker!"),
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.transpose()?
|
.transpose()?
|
||||||
.map(|schema| Parameter {
|
.map(|schema| Parameter {
|
||||||
|
@ -395,7 +407,7 @@ mod tests {
|
||||||
assert_validator!(
|
assert_validator!(
|
||||||
r#"
|
r#"
|
||||||
validator thing {
|
validator thing {
|
||||||
mint(redeemer: Data, policy_id: Data, transaction: Data) {
|
mint(redeemer: Data, policy_id: ByteArray, transaction: Data) {
|
||||||
True
|
True
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -408,7 +420,7 @@ mod tests {
|
||||||
assert_validator!(
|
assert_validator!(
|
||||||
r#"
|
r#"
|
||||||
validator thing(utxo_ref: Int) {
|
validator thing(utxo_ref: Int) {
|
||||||
mint(redeemer: Data, ctx: Data) {
|
mint(redeemer: Data, policy_id: ByteArray, transaction: Data) {
|
||||||
True
|
True
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -451,7 +463,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
validator simplified_hydra {
|
validator simplified_hydra {
|
||||||
spend(datum: State, redeemer: Input, ctx: Data) {
|
spend(datum: Option<State>, redeemer: Input, output_reference: Data, transaction: Data) {
|
||||||
True
|
True
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -464,7 +476,7 @@ mod tests {
|
||||||
assert_validator!(
|
assert_validator!(
|
||||||
r#"
|
r#"
|
||||||
validator tuples {
|
validator tuples {
|
||||||
spend(datum: (Int, ByteArray), redeemer: (Int, Int, Int), ctx: Void) {
|
spend(datum: Option<(Int, ByteArray)>, redeemer: (Int, Int, Int), output_reference: Data, transaction: Data) {
|
||||||
True
|
True
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -487,7 +499,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
validator generics {
|
validator generics {
|
||||||
spend(redeemer: Either<ByteArray, Interval<Int>>, ctx: Void) {
|
spend(datum: Option<Data>, redeemer: Either<ByteArray, Interval<Int>>, output_reference: Data, transaction: Data) {
|
||||||
True
|
True
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -500,7 +512,7 @@ mod tests {
|
||||||
assert_validator!(
|
assert_validator!(
|
||||||
r#"
|
r#"
|
||||||
validator generics {
|
validator generics {
|
||||||
mint(redeemer: a, policy_id: ByteArray, ctx: Void) {
|
mint(redeemer: a, policy_id: ByteArray, transaction: Data) {
|
||||||
True
|
True
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -519,7 +531,7 @@ mod tests {
|
||||||
pub type UUID { UUID }
|
pub type UUID { UUID }
|
||||||
|
|
||||||
validator list_2_tuples_as_list {
|
validator list_2_tuples_as_list {
|
||||||
mint(redeemer: Dict<UUID, Int>, ctx: Void) {
|
mint(redeemer: Dict<UUID, Int>, policy_id: ByteArray, transaction: Data) {
|
||||||
True
|
True
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -538,7 +550,7 @@ mod tests {
|
||||||
pub type UUID { UUID }
|
pub type UUID { UUID }
|
||||||
|
|
||||||
validator list_pairs_as_map {
|
validator list_pairs_as_map {
|
||||||
spend(redeemer: Dict<UUID, Int>, ctx: Void) {
|
spend(datum: Option<Data>, redeemer: Dict<UUID, Int>, ctx: Void) {
|
||||||
True
|
True
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -557,7 +569,7 @@ mod tests {
|
||||||
pub type UUID { UUID }
|
pub type UUID { UUID }
|
||||||
|
|
||||||
validator opaque_singleton_variants {
|
validator opaque_singleton_variants {
|
||||||
spend(redeemer: Dict<UUID, Int>, ctx: Void) {
|
spend(datum: Option<Data>, redeemer: Dict<UUID, Int>, output_reference: Data, transaction: Data) {
|
||||||
True
|
True
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -575,7 +587,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
validator opaque_singleton_multi_variants {
|
validator opaque_singleton_multi_variants {
|
||||||
spend(redeemer: Rational, oref: Data, ctx: Void) {
|
spend(datum: Option<Data>, redeemer: Rational, oref: Data, transaction: Data) {
|
||||||
True
|
True
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -592,7 +604,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
validator nested_data {
|
validator nested_data {
|
||||||
spend(datum: Foo, redeemer: Int, ctx: Void) {
|
spend(datum: Option<Foo>, redeemer: Int, output_reference: Data, transaction: Data) {
|
||||||
True
|
True
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -611,7 +623,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
validator recursive_types {
|
validator recursive_types {
|
||||||
spend(redeemer: Expr, ctx: Void) {
|
spend(datum: Option<Data>, redeemer: Expr, output_reference: Data, transaction: Data) {
|
||||||
True
|
True
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -639,7 +651,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
validator recursive_generic_types {
|
validator recursive_generic_types {
|
||||||
spend(datum: Foo, redeemer: LinkedList<Int>, ctx: Void) {
|
spend(datum: Option<Foo>, redeemer: LinkedList<Int>, output_reference: Data, transaction: Data) {
|
||||||
True
|
True
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -656,7 +668,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
validator annotated_data {
|
validator annotated_data {
|
||||||
spend(datum: Data<Foo>, redeemer: Data, ctx: Void) {
|
spend(datum: Option<Data<Foo>>, redeemer: Data, output_reference: Data, transpose: Data) {
|
||||||
True
|
True
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -846,11 +858,13 @@ mod tests {
|
||||||
let mut definitions = fixture_definitions();
|
let mut definitions = fixture_definitions();
|
||||||
definitions.insert(
|
definitions.insert(
|
||||||
&schema,
|
&schema,
|
||||||
Schema::Data(Data::AnyOf(vec![Constructor {
|
Schema::Data(Data::AnyOf(vec![
|
||||||
|
Constructor {
|
||||||
index: 0,
|
index: 0,
|
||||||
fields: vec![Declaration::Referenced(Reference::new("Bool")).into()],
|
fields: vec![Declaration::Referenced(Reference::new("Bool")).into()],
|
||||||
}
|
}
|
||||||
.into()]))
|
.into(),
|
||||||
|
]))
|
||||||
.into(),
|
.into(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue