mirror of
https://github.com/fluencelabs/aquavm
synced 2025-04-25 07:12:16 +00:00
Add a new test for join behaviour (#70)
This commit is contained in:
parent
13f93a0f88
commit
73fe4d9d3b
@ -29,6 +29,7 @@ pub(crate) fn call_service(
|
|||||||
serde_json::from_str(&result).expect("Cannot parse CallServiceResult")
|
serde_json::from_str(&result).expect("Cannot parse CallServiceResult")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::unnecessary_wraps)]
|
||||||
pub(crate) fn get_current_peer_id() -> std::result::Result<String, VarError> {
|
pub(crate) fn get_current_peer_id() -> std::result::Result<String, VarError> {
|
||||||
Ok(get_current_peer_id_impl())
|
Ok(get_current_peer_id_impl())
|
||||||
}
|
}
|
||||||
|
@ -178,7 +178,7 @@ impl<'i> ResolvedCall<'i> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_service_error<'i>(
|
fn handle_service_error(
|
||||||
service_result: CallServiceResult,
|
service_result: CallServiceResult,
|
||||||
trace_ctx: &mut ExecutionTraceCtx,
|
trace_ctx: &mut ExecutionTraceCtx,
|
||||||
) -> ExecutionResult<CallServiceResult> {
|
) -> ExecutionResult<CallServiceResult> {
|
||||||
|
@ -187,7 +187,7 @@ fn construct_iterable_jvalues(jvalues: Vec<&JValue>, should_flatten: bool) -> Ex
|
|||||||
}
|
}
|
||||||
|
|
||||||
match jvalues[0] {
|
match jvalues[0] {
|
||||||
JValue::Array(values) => Ok(values.into_iter().cloned().collect::<Vec<_>>()),
|
JValue::Array(values) => Ok(values.clone()),
|
||||||
_ => {
|
_ => {
|
||||||
let jvalues = jvalues.into_iter().cloned().collect();
|
let jvalues = jvalues.into_iter().cloned().collect();
|
||||||
let jvalue = JValue::Array(jvalues);
|
let jvalue = JValue::Array(jvalues);
|
||||||
|
@ -40,15 +40,10 @@ impl<'i> super::ExecutableInstruction<'i> for Xor<'i> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true, if this execution error type should be catched by xor.
|
/// Returns true, if this execution error type should be caught by xor.
|
||||||
fn is_catchable_by_xor(exec_error: &ExecutionError) -> bool {
|
fn is_catchable_by_xor(exec_error: &ExecutionError) -> bool {
|
||||||
use ExecutionError::*;
|
// this type of errors related to invalid data and should treat as hard errors.
|
||||||
|
!matches!(exec_error, ExecutionError::InvalidExecutedState(..))
|
||||||
match exec_error {
|
|
||||||
// this type of errors related to invalid data and should treat as hard errors.
|
|
||||||
InvalidExecutedState(..) => false,
|
|
||||||
_ => true,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -44,17 +44,16 @@ pub(crate) fn resolve_to_args<'i>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prepare_consts<'i>(
|
#[allow(clippy::unnecessary_wraps)]
|
||||||
arg: impl Into<JValue>,
|
fn prepare_consts(arg: impl Into<JValue>, ctx: &ExecutionCtx<'_>) -> ExecutionResult<(JValue, Vec<SecurityTetraplet>)> {
|
||||||
ctx: &ExecutionCtx<'i>,
|
|
||||||
) -> ExecutionResult<(JValue, Vec<SecurityTetraplet>)> {
|
|
||||||
let jvalue = arg.into();
|
let jvalue = arg.into();
|
||||||
let tetraplet = SecurityTetraplet::literal_tetraplet(ctx.init_peer_id.clone());
|
let tetraplet = SecurityTetraplet::literal_tetraplet(ctx.init_peer_id.clone());
|
||||||
|
|
||||||
Ok((jvalue, vec![tetraplet]))
|
Ok((jvalue, vec![tetraplet]))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prepare_last_error<'i>(ctx: &ExecutionCtx<'i>) -> ExecutionResult<(JValue, Vec<SecurityTetraplet>)> {
|
#[allow(clippy::unnecessary_wraps)]
|
||||||
|
fn prepare_last_error(ctx: &ExecutionCtx<'_>) -> ExecutionResult<(JValue, Vec<SecurityTetraplet>)> {
|
||||||
let result = match &ctx.last_error {
|
let result = match &ctx.last_error {
|
||||||
Some(error) => {
|
Some(error) => {
|
||||||
let serialized_error = error.serialize();
|
let serialized_error = error.serialize();
|
||||||
|
@ -82,7 +82,7 @@ fn make_contexts(
|
|||||||
trace: ExecutionTrace,
|
trace: ExecutionTrace,
|
||||||
init_peer_id: String,
|
init_peer_id: String,
|
||||||
) -> PreparationResult<(ExecutionCtx<'static>, ExecutionTraceCtx)> {
|
) -> PreparationResult<(ExecutionCtx<'static>, ExecutionTraceCtx)> {
|
||||||
let current_peer_id = get_current_peer_id().map_err(|e| PreparationError::CurrentPeerIdEnvError(e))?;
|
let current_peer_id = get_current_peer_id().map_err(PreparationError::CurrentPeerIdEnvError)?;
|
||||||
log::trace!(target: RUN_PARAMS, "current peer id {}", current_peer_id);
|
log::trace!(target: RUN_PARAMS, "current peer id {}", current_peer_id);
|
||||||
|
|
||||||
let exec_ctx = ExecutionCtx::new(current_peer_id, init_peer_id);
|
let exec_ctx = ExecutionCtx::new(current_peer_id, init_peer_id);
|
||||||
|
75
interpreter-lib/tests/join_behaviour.rs
Normal file
75
interpreter-lib/tests/join_behaviour.rs
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2020 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 aqua_test_utils::call_vm;
|
||||||
|
use aqua_test_utils::create_aqua_vm;
|
||||||
|
use aqua_test_utils::set_variables_call_service;
|
||||||
|
use aqua_test_utils::unit_call_service;
|
||||||
|
|
||||||
|
use interpreter_lib::execution_trace::ExecutionTrace;
|
||||||
|
|
||||||
|
use serde_json::json;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn non_wait_on_json_path() {
|
||||||
|
use log::LevelFilter::Info;
|
||||||
|
|
||||||
|
let status = json!({
|
||||||
|
"err_msg": "",
|
||||||
|
"is_authenticated": 1,
|
||||||
|
"ret_code": 0,
|
||||||
|
});
|
||||||
|
|
||||||
|
let msg = String::from(r#""some message""#);
|
||||||
|
|
||||||
|
let variables = maplit::hashmap!(
|
||||||
|
"msg".to_string() => msg,
|
||||||
|
"status".to_string() => status.to_string(),
|
||||||
|
);
|
||||||
|
|
||||||
|
let set_variables_call_service = set_variables_call_service(variables);
|
||||||
|
|
||||||
|
let set_variable_peer_id = "set_variable";
|
||||||
|
let mut set_variable_vm = create_aqua_vm(set_variables_call_service, set_variable_peer_id);
|
||||||
|
|
||||||
|
let local_peer_id = "local_peer_id";
|
||||||
|
let mut local_vm = create_aqua_vm(unit_call_service(), local_peer_id);
|
||||||
|
|
||||||
|
let script = format!(
|
||||||
|
r#"
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(call "{0}" ("" "") ["msg"] msg)
|
||||||
|
(call "{0}" ("" "") ["status"] status)
|
||||||
|
)
|
||||||
|
(seq
|
||||||
|
(call "{1}" ("op" "identity") [])
|
||||||
|
(seq
|
||||||
|
(call "{1}" ("history" "add") [msg status.$.is_authenticated!] auth_result)
|
||||||
|
(call %init_peer_id% ("returnService" "run") [auth_result])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
"#,
|
||||||
|
set_variable_peer_id, local_peer_id
|
||||||
|
);
|
||||||
|
|
||||||
|
let init_peer_id = "asd";
|
||||||
|
let res = call_vm!(set_variable_vm, init_peer_id, &script, "", "");
|
||||||
|
let res = call_vm!(local_vm, init_peer_id, script, "", res.data);
|
||||||
|
|
||||||
|
assert_eq!(res.next_peer_pks, vec![init_peer_id.to_string()]);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user