65 lines
2.4 KiB
Rust
Raw Normal View History

2021-08-24 16:14:15 +03:00
/*
2022-03-10 16:06:43 +03:00
* Copyright 2022 Fluence Labs Limited
2021-08-24 16:14:15 +03:00
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use air_test_utils::prelude::*;
2021-08-24 16:14:15 +03:00
#[test]
fn ap_with_fold() {
let nums: Vec<String> = (1..10).map(|i| i.to_string()).collect();
let vec = vec![nums.clone(), nums.clone(), nums.clone()];
let elems: Vec<(String, Vec<Vec<String>>)> = vec![
("a".into(), vec.clone()),
("a".into(), vec.clone()),
("a".into(), vec.clone()),
("a".into(), vec.clone()),
("a".into(), vec),
];
let set_variable_id = "set_variable_peer_id";
let mut set_variable_vm = create_avm(set_variable_call_service(json!(elems)), set_variable_id);
2021-08-24 16:14:15 +03:00
let local_vm_peer_id = "local_peer_id";
let mut local_vm = create_avm(unit_call_service(), local_vm_peer_id);
2022-03-10 16:06:43 +03:00
let script = f!(r#"
2021-08-24 16:14:15 +03:00
(seq
2022-03-10 16:06:43 +03:00
(call "{set_variable_id}" ("" "") [] permutations)
2021-08-24 16:14:15 +03:00
(seq
(seq
(fold permutations pair
(par
2021-08-24 16:14:15 +03:00
(fold pair.$.[1]! peer_ids
(par
2021-08-24 16:14:15 +03:00
(ap peer_ids $inner)
(next peer_ids)))
(next pair)))
2021-08-24 16:14:15 +03:00
(fold $inner ns
(par
(next ns)
(null))))
2021-08-24 16:14:15 +03:00
(seq
2022-03-10 16:06:43 +03:00
(call "{local_vm_peer_id}" ("op" "noop") [])
(seq
(canon "{local_vm_peer_id}" $inner #canon_stream)
(call "{local_vm_peer_id}" ("return" "") [#canon_stream])))))
2022-03-10 16:06:43 +03:00
"#);
2021-08-24 16:14:15 +03:00
2022-04-20 23:05:37 +03:00
let result = checked_call_vm!(set_variable_vm, <_>::default(), &script, "", "");
2021-08-24 16:14:15 +03:00
assert_eq!(result.next_peer_pks, vec![local_vm_peer_id.to_string()]);
2022-04-20 23:05:37 +03:00
let result = checked_call_vm!(local_vm, <_>::default(), &script, "", result.data);
2021-08-24 16:14:15 +03:00
assert!(result.next_peer_pks.is_empty());
}