mirror of
https://github.com/fluencelabs/aquavm
synced 2024-12-04 15:20:16 +00:00
Add tests for duplicates and fold with join (#75)
This commit is contained in:
parent
8a48212d7c
commit
acb00a1b07
@ -208,6 +208,26 @@ mod tests {
|
||||
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.
|
||||
#[test]
|
||||
fn string_parameters() {
|
||||
|
@ -344,6 +344,36 @@ mod tests {
|
||||
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]
|
||||
fn json_path() {
|
||||
use crate::contexts::execution_trace::CallResult::*;
|
||||
@ -358,8 +388,8 @@ mod tests {
|
||||
let lfold = String::from(
|
||||
r#"
|
||||
(seq
|
||||
(call "set_variable" ("" "") [] Iterable)
|
||||
(fold Iterable.$.array! i
|
||||
(call "set_variable" ("" "") [] iterable)
|
||||
(fold iterable.$.array! i
|
||||
(seq
|
||||
(call "A" ("" "") [i] acc[])
|
||||
(next i)
|
||||
@ -396,13 +426,13 @@ mod tests {
|
||||
r#"
|
||||
(seq
|
||||
(seq
|
||||
(call "set_variable" ("" "") [] Iterable1)
|
||||
(call "set_variable" ("" "") [] Iterable2)
|
||||
(call "set_variable" ("" "") [] iterable1)
|
||||
(call "set_variable" ("" "") [] iterable2)
|
||||
)
|
||||
(fold Iterable1 i
|
||||
(fold iterable1 i
|
||||
(seq
|
||||
(seq
|
||||
(fold Iterable2 j
|
||||
(fold iterable2 j
|
||||
(seq
|
||||
(seq
|
||||
(call "A" ("" "") [i] local_j)
|
||||
@ -461,15 +491,15 @@ mod tests {
|
||||
r#"
|
||||
(seq
|
||||
(seq
|
||||
(call "set_variable" ("" "") [] Iterable1)
|
||||
(call "set_variable" ("" "") [] Iterable2)
|
||||
(call "set_variable" ("" "") [] iterable1)
|
||||
(call "set_variable" ("" "") [] iterable2)
|
||||
)
|
||||
(fold Iterable1 i
|
||||
(fold iterable1 i
|
||||
(seq
|
||||
(seq
|
||||
(call "A" ("" "") ["value"] local_j)
|
||||
(seq
|
||||
(fold Iterable2 j
|
||||
(fold iterable2 j
|
||||
(seq
|
||||
(seq
|
||||
(call "A" ("" "") [i] local_j)
|
||||
|
Loading…
Reference in New Issue
Block a user