mirror of
https://github.com/fluencelabs/aquavm
synced 2024-12-04 15:20:16 +00:00
fix behaviour with compare values after applying lambda (#166)
This commit is contained in:
parent
18f4c0036f
commit
653f42167a
@ -115,10 +115,14 @@ fn compare_matchable<'ctx>(
|
||||
let jvaluable = resolve_ast_variable(&vl.variable, exec_ctx)?;
|
||||
let jvalues = jvaluable.apply_lambda(&vl.lambda)?;
|
||||
|
||||
let jvalue = jvalues.into_iter().cloned().collect::<Vec<_>>();
|
||||
let jvalue = JValue::Array(jvalue);
|
||||
// TODO: it's known that apply_lambda always returns array with one value that is
|
||||
// intended to support multi-return in the future, this check is needed just in
|
||||
// case and should be refactored after introducing boxed values
|
||||
if jvalues.len() != 1 {
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
Ok(comparator(Cow::Owned(jvalue)))
|
||||
Ok(comparator(Cow::Borrowed(jvalues[0])))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -234,3 +234,40 @@ fn match_with_two_xors() {
|
||||
|
||||
assert_eq!(actual_trace.pop().unwrap(), expected_executed_call_result);
|
||||
}
|
||||
|
||||
// https://github.com/fluencelabs/aquavm/issues/165
|
||||
#[test]
|
||||
fn issue_165() {
|
||||
let result_setter_peer_id = "result_setter_peer_id";
|
||||
let mut result_setter = create_avm(
|
||||
set_variable_call_service(serde_json::json!({"success": true})),
|
||||
result_setter_peer_id,
|
||||
);
|
||||
|
||||
let echo_peer_id = "echo_peer_id";
|
||||
let mut echo_peer = create_avm(echo_call_service(), echo_peer_id);
|
||||
|
||||
let script = format!(
|
||||
r#"
|
||||
(seq
|
||||
(call "{0}" ("" "") ["set_result"] result)
|
||||
(seq
|
||||
(xor
|
||||
(match result.$.success! true
|
||||
(ap 1 $results)
|
||||
)
|
||||
(ap 2 $results)
|
||||
)
|
||||
(call "{1}" ("callbackSrv" "response") [$results.$.[0]!])
|
||||
)
|
||||
)
|
||||
"#,
|
||||
result_setter_peer_id, echo_peer_id
|
||||
);
|
||||
|
||||
let setter_result = checked_call_vm!(result_setter, "", &script, "", "");
|
||||
let echo_result = checked_call_vm!(echo_peer, "", &script, "", setter_result.data);
|
||||
|
||||
let trace = trace_from_result(&echo_result);
|
||||
assert_eq!(trace.last().unwrap(), &executed_state::scalar(json!(1)));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user