Skip to content

Commit

Permalink
fix bug with empty iterable constructed from json path (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikevoronov authored Apr 13, 2021
1 parent 45fc92a commit 3d59e6f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
27 changes: 27 additions & 0 deletions interpreter-lib/src/execution/air/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,33 @@ mod tests {
assert_eq!(res[0], Call(Executed(Rc::new(json!([])))));
}

#[test]
fn empty_fold_json_path() {
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#"{ "messages": [] }"#), "set_variable");

let empty_fold = r#"
(seq
(call "set_variable" ("" "") [] messages)
(fold messages.$.messages! i
(seq
(call "A" ("" "") [i] $acc)
(next i)
)
)
)"#;

let res = call_vm!(set_variable_vm, "", empty_fold, "", "");
let res = call_vm!(vm, "", empty_fold, "", 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!({ "messages": [] })))));
}

// Check that fold works with the join behaviour without hanging up.
#[test]
fn fold_with_join() {
Expand Down
4 changes: 2 additions & 2 deletions interpreter-lib/src/execution/air/fold/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,12 @@ fn from_jvalues(
json_path: &str,
should_flatten: bool,
) -> ExecutionResult<Option<IterableValue>> {
let jvalues = construct_iterable_jvalues(jvalues, should_flatten)?;

if jvalues.is_empty() {
return Ok(None);
}

let jvalues = construct_iterable_jvalues(jvalues, should_flatten)?;

let tetraplet = SecurityTetraplet {
triplet,
json_path: json_path.to_string(),
Expand Down

0 comments on commit 3d59e6f

Please sign in to comment.