77 lines
3.1 KiB
Rust
77 lines
3.1 KiB
Rust
use super::*;
|
|
|
|
#[test]
|
|
fn transaction_flow_preserves_syntax_and_inspection_and_allows_clock_reads() {
|
|
let root = project(
|
|
"transaction-clock",
|
|
"transaction flow stamp() (out: DateTime)\n| step | kind | do |\n| out | flow | dever.time.now() |\ntransaction flow nested() (out: DateTime)\n| step | kind | do |\n| out | flow | stamp() |",
|
|
);
|
|
let (loaded, program) = analyze(&root);
|
|
let artifact = build::build(
|
|
&loaded,
|
|
&program,
|
|
"demo.article.app.nested",
|
|
Profile::Dev,
|
|
None,
|
|
)
|
|
.unwrap();
|
|
assert!(run(&artifact.binary).starts_with("DateTime("));
|
|
let path = root.to_str().unwrap();
|
|
success(cli(&["fmt", path]));
|
|
success(cli(&["fmt", path, "--check"]));
|
|
assert!(
|
|
fs::read_to_string(root.join("module/demo/article/app/main.dever"))
|
|
.unwrap()
|
|
.contains("transaction flow stamp")
|
|
);
|
|
let inspection: serde_json::Value = serde_json::from_str(&success(cli(&[
|
|
"inspect",
|
|
path,
|
|
"--json",
|
|
"--symbol",
|
|
"demo.article.app.stamp",
|
|
"--depth",
|
|
"0",
|
|
])))
|
|
.unwrap();
|
|
assert!(inspection["flows"].as_array().unwrap().iter().any(|flow| {
|
|
flow["nodes"]
|
|
.as_array()
|
|
.unwrap()
|
|
.iter()
|
|
.any(|node| node["kind"] == "transaction")
|
|
}));
|
|
}
|
|
|
|
#[test]
|
|
fn transaction_rejects_effects_through_subflows_and_static_handlers() {
|
|
let root = project("transaction-effects", "");
|
|
for body in [
|
|
"transaction flow waitFor() ()\n| step | kind | do |\n| - | flow | dever.time.sleep(1) |",
|
|
"flow waitFor() ()\n| step | kind | do |\n| - | flow | dever.time.sleep(1) |\ntransaction flow wrapped() ()\n| step | kind | do |\n| - | flow | waitFor() |",
|
|
"flow waitFor() ()\n| step | kind | do |\n| - | flow | dever.time.sleep(1) |\ntransaction flow wrapped(action: handler() ()) ()\n| step | kind | do |\n| - | calc | action() |\nflow start() ()\n| step | kind | do |\n| - | flow | wrapped(waitFor) |",
|
|
"transaction flow random() (out: Secret)\n| step | kind | do |\n| out | flow | dever.crypto.token(32) |",
|
|
"transaction flow hash(password: Secret) (out: Text)\n| step | kind | do |\n| out | flow | dever.crypto.passwordHash(password) |",
|
|
] {
|
|
write_source(root.join("module/demo/article/app/main.dever"), body).unwrap();
|
|
let loaded = Project::load(&root).unwrap();
|
|
assert!(loaded.diagnostics.is_empty(), "{:?}", loaded.diagnostics);
|
|
let analysis = program::analyze(&loaded.declarations, &loaded.modules);
|
|
assert!(
|
|
analysis
|
|
.diagnostics
|
|
.iter()
|
|
.any(|error| error.message.contains("transaction flow cannot")),
|
|
"{:?}",
|
|
analysis.diagnostics
|
|
);
|
|
}
|
|
for body in [
|
|
"transaction rule wrong(value: Int) (out: Int)",
|
|
"transaction plain() () {}",
|
|
] {
|
|
write_source(root.join("module/demo/article/app/main.dever"), body).unwrap();
|
|
assert!(!Project::load(&root).unwrap().diagnostics.is_empty());
|
|
}
|
|
}
|