fix: confusing public validator closes #902
This commit is contained in:
parent
ce2c723d0c
commit
b5f27026e2
|
@ -583,7 +583,7 @@ impl<'comments> Formatter<'comments> {
|
|||
let fun_doc_comments = self.doc_comments(fun.location.start);
|
||||
let first_fn = self
|
||||
.definition_fn(
|
||||
&false,
|
||||
&fun.public,
|
||||
&fun.name,
|
||||
&fun.arguments,
|
||||
&fun.return_annotation,
|
||||
|
@ -601,7 +601,7 @@ impl<'comments> Formatter<'comments> {
|
|||
|
||||
let other_fn = self
|
||||
.definition_fn(
|
||||
&false,
|
||||
&other.public,
|
||||
&other.name,
|
||||
&other.arguments,
|
||||
&other.return_annotation,
|
||||
|
|
|
@ -2208,3 +2208,69 @@ fn allow_discard_for_backpassing_args() {
|
|||
|
||||
assert_eq!(warnings.len(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validator_private_type_leak() {
|
||||
let source_code = r#"
|
||||
type Datum {
|
||||
foo: Int,
|
||||
}
|
||||
|
||||
type Redeemer {
|
||||
bar: Int,
|
||||
}
|
||||
|
||||
validator {
|
||||
pub fn bar(datum: Datum, redeemer: Redeemer, _ctx) {
|
||||
datum.foo == redeemer.bar
|
||||
}
|
||||
}
|
||||
"#;
|
||||
|
||||
assert!(matches!(
|
||||
check_validator(parse(source_code)),
|
||||
Err((_, Error::PrivateTypeLeak { .. }))
|
||||
))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validator_public() {
|
||||
let source_code = r#"
|
||||
pub type Datum {
|
||||
foo: Int,
|
||||
}
|
||||
|
||||
pub type Redeemer {
|
||||
bar: Int,
|
||||
}
|
||||
|
||||
validator {
|
||||
pub fn bar(datum: Datum, redeemer: Redeemer, _ctx) {
|
||||
datum.foo == redeemer.bar
|
||||
}
|
||||
}
|
||||
"#;
|
||||
|
||||
assert!(check_validator(parse(source_code)).is_ok())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validator_private_everything() {
|
||||
let source_code = r#"
|
||||
type Datum {
|
||||
foo: Int,
|
||||
}
|
||||
|
||||
type Redeemer {
|
||||
bar: Int,
|
||||
}
|
||||
|
||||
validator {
|
||||
fn bar(datum: Datum, redeemer: Redeemer, _ctx) {
|
||||
datum.foo == redeemer.bar
|
||||
}
|
||||
}
|
||||
"#;
|
||||
|
||||
assert!(check_validator(parse(source_code)).is_ok())
|
||||
}
|
||||
|
|
|
@ -185,6 +185,21 @@ fn format_double_validator() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn format_double_validator_public() {
|
||||
assert_format!(
|
||||
r#"
|
||||
validator ( param1 : ByteArray ) {
|
||||
pub fn foo (d: Datum, r: Redeemer, ctx: ScriptContext) -> Bool {
|
||||
True
|
||||
}
|
||||
/// This is bar
|
||||
pub fn bar(r: Redeemer, ctx : ScriptContext ) -> Bool { True }
|
||||
}
|
||||
"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn format_when() {
|
||||
assert_format!(
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
---
|
||||
source: crates/aiken-lang/src/tests/format.rs
|
||||
description: "Code:\n\n validator ( param1 : ByteArray ) {\n pub fn foo (d: Datum, r: Redeemer, ctx: ScriptContext) -> Bool {\n True\n }\n /// This is bar\npub fn bar(r: Redeemer, ctx : ScriptContext ) -> Bool { True }\n }\n"
|
||||
---
|
||||
validator(param1: ByteArray) {
|
||||
pub fn foo(d: Datum, r: Redeemer, ctx: ScriptContext) -> Bool {
|
||||
True
|
||||
}
|
||||
|
||||
/// This is bar
|
||||
pub fn bar(r: Redeemer, ctx: ScriptContext) -> Bool {
|
||||
True
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue