Add tests for duplicates and fold with join (#75)

This commit is contained in:
vms 2021-03-10 17:34:14 +03:00 committed by GitHub
parent 8a48212d7c
commit acb00a1b07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 60 additions and 10 deletions

View File

@ -208,6 +208,26 @@ mod tests {
assert!(res.next_peer_pks.is_empty()); assert!(res.next_peer_pks.is_empty());
} }
// Check that duplicate variables are impossible.
#[test]
fn duplicate_variables() {
let mut vm = create_aqua_vm(unit_call_service(), "some_peer_id");
let script = format!(
r#"
(seq
(call "some_peer_id" ("some_service_id" "local_fn_name") [] modules)
(call "some_peer_id" ("some_service_id" "local_fn_name") [] modules)
)
"#,
);
let res = call_vm!(vm, "asd", script, "", "");
assert_eq!(res.ret_code, 1005);
assert!(res.next_peer_pks.is_empty());
}
// Check that string literals can be used as call parameters. // Check that string literals can be used as call parameters.
#[test] #[test]
fn string_parameters() { fn string_parameters() {

View File

@ -344,6 +344,36 @@ mod tests {
assert_eq!(res[0], Call(Executed(Rc::new(json!([]))))); assert_eq!(res[0], Call(Executed(Rc::new(json!([])))));
} }
// Check that fold works with the join behaviour without hanging up.
#[test]
fn fold_with_join() {
use crate::contexts::execution_trace::CallResult::*;
use crate::contexts::execution_trace::ExecutedState::*;
let mut vm = create_aqua_vm(echo_number_call_service(), "A");
let mut set_variable_vm = create_aqua_vm(set_variable_call_service(r#"["1","2"]"#), "set_variable");
let fold_with_join = String::from(
r#"
(seq
(call "set_variable" ("" "") [] iterable)
(fold iterable i
(seq
(call "A" ("" "") [non_exist_variable.$.hash!] acc[])
(next i)
)
)
)"#,
);
let res = call_vm!(set_variable_vm, "", &fold_with_join, "", "");
let res = call_vm!(vm, "", fold_with_join, "", res.data);
let res: ExecutionTrace = serde_json::from_slice(&res.data).expect("should be valid executed trace");
assert_eq!(res.len(), 1);
assert_eq!(res[0], Call(Executed(Rc::new(json!(["1", "2"])))));
}
#[test] #[test]
fn json_path() { fn json_path() {
use crate::contexts::execution_trace::CallResult::*; use crate::contexts::execution_trace::CallResult::*;
@ -358,8 +388,8 @@ mod tests {
let lfold = String::from( let lfold = String::from(
r#" r#"
(seq (seq
(call "set_variable" ("" "") [] Iterable) (call "set_variable" ("" "") [] iterable)
(fold Iterable.$.array! i (fold iterable.$.array! i
(seq (seq
(call "A" ("" "") [i] acc[]) (call "A" ("" "") [i] acc[])
(next i) (next i)
@ -396,13 +426,13 @@ mod tests {
r#" r#"
(seq (seq
(seq (seq
(call "set_variable" ("" "") [] Iterable1) (call "set_variable" ("" "") [] iterable1)
(call "set_variable" ("" "") [] Iterable2) (call "set_variable" ("" "") [] iterable2)
) )
(fold Iterable1 i (fold iterable1 i
(seq (seq
(seq (seq
(fold Iterable2 j (fold iterable2 j
(seq (seq
(seq (seq
(call "A" ("" "") [i] local_j) (call "A" ("" "") [i] local_j)
@ -461,15 +491,15 @@ mod tests {
r#" r#"
(seq (seq
(seq (seq
(call "set_variable" ("" "") [] Iterable1) (call "set_variable" ("" "") [] iterable1)
(call "set_variable" ("" "") [] Iterable2) (call "set_variable" ("" "") [] iterable2)
) )
(fold Iterable1 i (fold iterable1 i
(seq (seq
(seq (seq
(call "A" ("" "") ["value"] local_j) (call "A" ("" "") ["value"] local_j)
(seq (seq
(fold Iterable2 j (fold iterable2 j
(seq (seq
(seq (seq
(call "A" ("" "") [i] local_j) (call "A" ("" "") [i] local_j)