fix data handling in Ap (#217)

This commit is contained in:
Mike Voronov 2022-02-17 13:37:36 +03:00 committed by GitHub
parent 9fb085b6d6
commit 1ca121cf93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 64 additions and 4 deletions

View File

@ -39,6 +39,10 @@ use std::rc::Rc;
impl<'i> super::ExecutableInstruction<'i> for Ap<'i> {
fn execute(&self, exec_ctx: &mut ExecutionCtx<'i>, trace_ctx: &mut TraceHandler) -> ExecutionResult<()> {
let should_touch_trace = should_touch_trace(self);
// this applying should be at the very beginning of this function,
// because it's necessary to check argument lambda, for more details see
// https://github.com/fluencelabs/aquavm/issues/216
let result = apply_to_arg(&self.argument, exec_ctx, trace_ctx, should_touch_trace)?;
let merger_ap_result = if should_touch_trace {
let merger_ap_result = trace_to_exec_err!(trace_ctx.meet_ap_start(), self)?;
@ -47,8 +51,6 @@ impl<'i> super::ExecutableInstruction<'i> for Ap<'i> {
} else {
MergerApResult::Empty
};
let result = apply_to_arg(&self.argument, exec_ctx, trace_ctx, should_touch_trace)?;
save_result(&self.result, &merger_ap_result, result, exec_ctx)?;
if should_touch_trace {

View File

@ -196,12 +196,11 @@ impl<'i> ResolvedCall<'i> {
self.function_arg_paths
.iter()
.map(|arg_path| match resolve_to_args(arg_path, exec_ctx) {
.try_for_each(|arg_path| match resolve_to_args(arg_path, exec_ctx) {
Ok(_) => Ok(()),
Err(e) if e.is_joinable() => Ok(()),
Err(e) => Err(e),
})
.collect::<_>()
}
}

View File

@ -0,0 +1,58 @@
/*
* Copyright 2022 Fluence Labs Limited
*
* 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::*;
use fstrings::f;
use fstrings::format_args_f;
#[test]
// test for github.com/fluencelabs/aquavm/issues/216
fn issue_216() {
let some_peer_id = "relay_peer_id";
let variables_mapping = maplit::hashmap! {
"value".to_string() => json!([]),
};
let mut some_peer = create_avm(
set_variables_call_service(variables_mapping, VariableOptionSource::FunctionName),
some_peer_id,
);
let client_id = "client_peer_id";
let mut client = create_avm(echo_call_service(), client_id);
let error_message = "error message";
let script = f!(r#"
(xor
(seq
(call "{some_peer_id}" ("" "value") [] value)
(ap value.$.non_exist_field $stream) ;; (1)
)
(call %init_peer_id% ("" "") ["{error_message}"]) ;; (2)
)
"#);
let result = checked_call_vm!(some_peer, client_id, &script, "", "");
let result = checked_call_vm!(client, client_id, &script, "", result.data); // before 0.20.4 it's just failed
let actual_trace = trace_from_result(&result);
let expected_trace = vec![
executed_state::scalar(json!([])),
executed_state::scalar_string(error_message),
];
assert_eq!(actual_trace, expected_trace);
}

View File

@ -22,3 +22,4 @@ mod issue_180;
mod issue_206;
mod issue_211;
mod issue_214;
mod issue_216;