From e13377c5b0173d186d94981c6a4053803deaf561 Mon Sep 17 00:00:00 2001 From: Mike Voronov Date: Wed, 24 Nov 2021 18:47:49 +0300 Subject: [PATCH] Add test for par ap behaviour (#175) --- Cargo.lock | 1 + air/Cargo.toml | 1 + air/tests/test_module/instructions/ap.rs | 51 ++++- air/tests/test_module/instructions/call.rs | 2 +- air/tests/test_module/instructions/new.rs | 2 +- air/tests/test_module/instructions/xor.rs | 28 +-- .../test_module/integration/air_basic.rs | 12 +- .../integration/call_evidence_basic.rs | 47 ++-- air/tests/test_module/integration/join.rs | 56 ++--- .../test_module/integration/last_error.rs | 4 +- air/tests/test_module/integration/streams.rs | 204 +++++++++--------- .../integration/streams_early_exit.rs | 72 +++---- .../air-lib/test-utils/src/call_services.rs | 10 +- .../air-lib/test-utils/src/executed_state.rs | 4 +- 14 files changed, 270 insertions(+), 224 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0b53f4ff..7e099ebb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -29,6 +29,7 @@ dependencies = [ "csv", "env_logger", "fluence-app-service", + "fstrings", "log", "maplit", "marine-rs-sdk", diff --git a/air/Cargo.toml b/air/Cargo.toml index dae91939..70b2bdda 100644 --- a/air/Cargo.toml +++ b/air/Cargo.toml @@ -33,6 +33,7 @@ boolinator = "2.4.0" maplit = "1.0.2" log = "0.4.11" thiserror = "1.0.23" +fstrings = "0.2.3" strum = "0.21" strum_macros = "0.21" diff --git a/air/tests/test_module/instructions/ap.rs b/air/tests/test_module/instructions/ap.rs index 2ed28932..ad1c2530 100644 --- a/air/tests/test_module/instructions/ap.rs +++ b/air/tests/test_module/instructions/ap.rs @@ -1,5 +1,5 @@ /* - * Copyright 2020 Fluence Labs Limited + * Copyright 2021 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. @@ -16,6 +16,10 @@ use air_test_utils::prelude::*; +use fstrings::f; +use fstrings::format_args_f; +use std::collections::HashSet; + #[test] fn ap_with_scalars() { let vm_1_peer_id = "vm_1_peer_id"; @@ -159,18 +163,15 @@ fn ap_with_dst_stream() { let vm_2_peer_id = "vm_2_peer_id"; let mut vm_2 = create_avm(echo_call_service(), vm_2_peer_id); - let script = format!( - r#" + let script = f!(r#" (seq (seq - (call "{}" ("" "") ["scalar_1_result"] scalar_1) + (call "{vm_1_peer_id}" ("" "") ["scalar_1_result"] scalar_1) (ap scalar_1 $stream) ) - (call "{}" ("" "") [$stream]) + (call "{vm_2_peer_id}" ("" "") [$stream]) ) - "#, - vm_1_peer_id, vm_2_peer_id - ); + "#); let result = checked_call_vm!(vm_1, "", &script, "", ""); let result = checked_call_vm!(vm_2, "", script, "", result.data); @@ -185,3 +186,37 @@ fn ap_with_dst_stream() { assert_eq!(actual_trace, expected_state); assert!(result.next_peer_pks.is_empty()); } + +#[test] +fn par_ap_behaviour() { + let client_id = "client_id"; + let relay_id = "relay_id"; + let variable_setter_id = "variable_setter_id"; + let mut client = create_avm(unit_call_service(), client_id); + let mut relay = create_avm(unit_call_service(), relay_id); + let mut variable_setter = create_avm(unit_call_service(), variable_setter_id); + + let script = f!(r#" + (par + (call "{variable_setter_id}" ("peer" "timeout") [] join_it) + (seq + (par + (call "{relay_id}" ("peer" "timeout") [join_it] $result) + (ap "fast_result" $result) ;; ap doesn't affect the subtree_complete flag + ) + (call "{client_id}" ("op" "return") [$result.$[0]]) + ) + ) + "#); + + let mut client_result_1 = checked_call_vm!(client, "", &script, "", ""); + let actual_next_peers: HashSet<_> = client_result_1.next_peer_pks.drain(..).collect(); + let expected_next_peers: HashSet<_> = maplit::hashset!(relay_id.to_string(), variable_setter_id.to_string()); + assert_eq!(actual_next_peers, expected_next_peers); + + let setter_result = checked_call_vm!(variable_setter, "", &script, "", client_result_1.data.clone()); + assert!(setter_result.next_peer_pks.is_empty()); + + let relay_result = checked_call_vm!(relay, "", script, "", client_result_1.data); + assert!(relay_result.next_peer_pks.is_empty()); +} diff --git a/air/tests/test_module/instructions/call.rs b/air/tests/test_module/instructions/call.rs index 0cced9ec..2e8ff818 100644 --- a/air/tests/test_module/instructions/call.rs +++ b/air/tests/test_module/instructions/call.rs @@ -35,7 +35,7 @@ fn current_peer_id_call() { let result = checked_call_vm!(vm, vm_peer_id, script, "", ""); let actual_trace = trace_from_result(&result); - let expected_trace = vec![executed_state::scalar_string("test")]; + let expected_trace = vec![executed_state::scalar_string("result from unit_call_service")]; assert_eq!(actual_trace, expected_trace); assert!(result.next_peer_pks.is_empty()); diff --git a/air/tests/test_module/instructions/new.rs b/air/tests/test_module/instructions/new.rs index 17ca8b78..8ee84c00 100644 --- a/air/tests/test_module/instructions/new.rs +++ b/air/tests/test_module/instructions/new.rs @@ -264,7 +264,7 @@ fn new_with_errors() { let expected_trace = vec![ executed_state::stream_number(1, 0), executed_state::stream_number(2, 0), - executed_state::service_failed(1, r#""error""#), + executed_state::service_failed(1, "failed result from fallible_call_service"), ]; assert_eq!(actual_trace, expected_trace); diff --git a/air/tests/test_module/instructions/xor.rs b/air/tests/test_module/instructions/xor.rs index 92608da8..72ffff16 100644 --- a/air/tests/test_module/instructions/xor.rs +++ b/air/tests/test_module/instructions/xor.rs @@ -34,10 +34,13 @@ fn xor() { let result = checked_call_vm!(vm, "asd", script, "", ""); let actual_trace = trace_from_result(&result); - let expected_call_result = executed_state::scalar_string("test"); + let expected_call_result = executed_state::scalar_string("success result from fallible_call_service"); assert_eq!(actual_trace.len(), 2); - assert_eq!(actual_trace[0], executed_state::service_failed(1, r#""error""#)); + assert_eq!( + actual_trace[0], + executed_state::service_failed(1, "failed result from fallible_call_service") + ); assert_eq!(actual_trace[1], expected_call_result); let script = format!( @@ -146,18 +149,18 @@ fn xor_par() { let result = checked_call_vm!(vm, "asd", &script, "", ""); let actual_trace = trace_from_result(&result); - let scalar_result = String::from("test"); - + let success_result = "success result from fallible_call_service"; + let failed_result = "failed result from fallible_call_service"; let expected_trace = vec![ par(3, 3), par(1, 1), - service_failed(1, r#""error""#), - service_failed(1, r#""error""#), + service_failed(1, failed_result), + service_failed(1, failed_result), par(1, 1), - service_failed(1, r#""error""#), - service_failed(1, r#""error""#), - scalar_string(&scalar_result), - scalar_string(&scalar_result), + service_failed(1, failed_result), + service_failed(1, failed_result), + scalar_string(success_result), + scalar_string(success_result), ]; assert_eq!(actual_trace, expected_trace); @@ -188,8 +191,9 @@ fn last_error_with_xor() { let result = checked_call_vm!(vm, "asd", script, "", result.data); let actual_trace = trace_from_result(&result); - let expected_state = - executed_state::scalar_string(r#"Local service error, ret_code is 1, error message is '"error"'"#); + let expected_state = executed_state::scalar_string( + r#"Local service error, ret_code is 1, error message is '"failed result from fallible_call_service"'"#, + ); assert_eq!(actual_trace[1], expected_state); } diff --git a/air/tests/test_module/integration/air_basic.rs b/air/tests/test_module/integration/air_basic.rs index 44967525..179466c6 100644 --- a/air/tests/test_module/integration/air_basic.rs +++ b/air/tests/test_module/integration/air_basic.rs @@ -36,12 +36,12 @@ fn seq_par_call() { let result = checked_call_vm!(vm, "asd", script, "", ""); let actual_trace = trace_from_result(&result); - let test_string = "test"; + let unit_call_service_result = "result from unit_call_service"; let expected_trace = vec![ executed_state::par(1, 1), - executed_state::scalar_string(test_string), + executed_state::scalar_string(unit_call_service_result), executed_state::request_sent_by(vm_peer_id), - executed_state::scalar_string(test_string), + executed_state::scalar_string(unit_call_service_result), ]; assert_eq!(actual_trace, expected_trace); @@ -68,13 +68,13 @@ fn par_par_call() { let result = checked_call_vm!(vm, "asd", script, "", ""); let actual_trace = trace_from_result(&result); - let test_string = "test"; + let unit_call_service_result = "result from unit_call_service"; let expected_trace = vec![ executed_state::par(3, 1), executed_state::par(1, 1), - executed_state::scalar_string(test_string), + executed_state::scalar_string(unit_call_service_result), executed_state::request_sent_by(vm_peer_id), - executed_state::scalar_string(test_string), + executed_state::scalar_string(unit_call_service_result), ]; assert_eq!(actual_trace, expected_trace); diff --git a/air/tests/test_module/integration/call_evidence_basic.rs b/air/tests/test_module/integration/call_evidence_basic.rs index f8d8fb21..9b7123a0 100644 --- a/air/tests/test_module/integration/call_evidence_basic.rs +++ b/air/tests/test_module/integration/call_evidence_basic.rs @@ -33,19 +33,22 @@ fn executed_trace_seq_par_call() { local_peer_id ); - let initial_trace = vec![par(1, 1), scalar_string("test"), scalar_string("test")]; + let unit_call_service_result = "result from unit_call_service"; + let initial_trace = vec![ + par(1, 1), + scalar_string(unit_call_service_result), + scalar_string(unit_call_service_result), + ]; let initial_data = raw_data_from_trace(initial_trace); let result = checked_call_vm!(vm, "asd", script, "", initial_data); let actual_trace = trace_from_result(&result); - let test_string = "test"; - let expected_trace = vec![ par(1, 1), - scalar_string(test_string), - scalar_string(test_string), - scalar_string(test_string), + scalar_string(unit_call_service_result), + scalar_string(unit_call_service_result), + scalar_string(unit_call_service_result), ]; assert_eq!(actual_trace, expected_trace); @@ -69,11 +72,12 @@ fn executed_trace_par_par_call() { local_peer_id, ); + let unit_call_service_result = "result from unit_call_service"; let initial_state = vec![ par(2, 1), par(1, 0), request_sent_by("peer_id_1"), - scalar_string("test"), + scalar_string(unit_call_service_result), ]; let initial_data = raw_data_from_trace(initial_state); @@ -81,13 +85,12 @@ fn executed_trace_par_par_call() { let result = checked_call_vm!(vm, "asd", &script, "", initial_data); let actual_trace = trace_from_result(&result); - let test_string = "test"; let expected_trace = vec![ par(3, 1), par(1, 1), - scalar_string(test_string), + scalar_string(unit_call_service_result), request_sent_by(local_peer_id), - scalar_string(test_string), + scalar_string(unit_call_service_result), ]; assert_eq!(actual_trace, expected_trace); @@ -138,11 +141,11 @@ fn executed_trace_seq_seq() { let actual_trace = trace_from_result(&result); - let test_string = "test"; + let call_serivce_result = "result from unit_call_service"; let expected_trace = vec![ - scalar_string(test_string), - scalar_string(test_string), - scalar_string(test_string), + scalar_string(call_serivce_result), + scalar_string(call_serivce_result), + scalar_string(call_serivce_result), ]; assert_eq!(actual_trace, expected_trace); @@ -269,7 +272,7 @@ fn executed_trace_par_seq_fold_call() { stream_string(9.to_string(), generation), par(1, 0), stream_string(10.to_string(), generation), - scalar_string("test"), + scalar_string("result from unit_call_service"), ]; assert_eq!(actual_trace, expected_trace); @@ -333,7 +336,7 @@ fn executed_trace_par_seq_fold_in_cycle_call() { stream_string(9.to_string(), generation), par(1, 0), stream_string(10.to_string(), generation), - scalar_string("test"), + scalar_string("result from unit_call_service"), ]; assert_eq!(actual_trace, expected_trace); @@ -377,14 +380,14 @@ fn executed_trace_seq_par_seq_seq() { let actual_trace = trace_from_result(&result); - let service_result_string = "test"; + let unit_call_service_result = "result from unit_call_service"; let executed_trace = vec![ par(2, 2), - scalar_string(service_result_string), - scalar_string(service_result_string), - scalar_string(service_result_string), - scalar_string(service_result_string), - scalar_string(service_result_string), + scalar_string(unit_call_service_result), + scalar_string(unit_call_service_result), + scalar_string(unit_call_service_result), + scalar_string(unit_call_service_result), + scalar_string(unit_call_service_result), ]; assert_eq!(actual_trace, executed_trace); diff --git a/air/tests/test_module/integration/join.rs b/air/tests/test_module/integration/join.rs index 18b0cd61..8349841a 100644 --- a/air/tests/test_module/integration/join.rs +++ b/air/tests/test_module/integration/join.rs @@ -62,7 +62,7 @@ fn join_chat() { let relay_1_actual_trace = trace_from_result(&relay_1_result); let relay_1_expected_trace = vec![ - executed_state::stream_string("test", 0), + executed_state::stream_string("result from unit_call_service", 0), executed_state::request_sent_by("Relay1"), ]; @@ -73,7 +73,7 @@ fn join_chat() { let remote_actual_trace = trace_from_result(&remote_result); let remote_expected_trace = vec![ - executed_state::stream_string("test", 0), + executed_state::stream_string("result from unit_call_service", 0), executed_state::stream(json!([["A", "Relay1"], ["B", "Relay2"]]), 0), executed_state::scalar(json!([["A", "Relay1"], ["B", "Relay2"]])), executed_state::par(1, 2), @@ -96,11 +96,11 @@ fn join_chat() { let relay_1_actual_trace = trace_from_result(&relay_1_result); let relay_1_expected_trace = vec![ - executed_state::stream_string("test", 0), + executed_state::stream_string("result from unit_call_service", 0), executed_state::stream(json!([["A", "Relay1"], ["B", "Relay2"]]), 0), executed_state::scalar(json!([["A", "Relay1"], ["B", "Relay2"]])), executed_state::par(2, 2), - executed_state::stream_string("test", 0), + executed_state::stream_string("result from unit_call_service", 0), executed_state::request_sent_by("Relay1"), executed_state::par(1, 0), executed_state::request_sent_by("Remote"), @@ -114,12 +114,12 @@ fn join_chat() { let client_1_actual_trace = trace_from_result(&client_1_result); let client_1_expected_trace = vec![ - executed_state::stream_string("test", 0), + executed_state::stream_string("result from unit_call_service", 0), executed_state::stream(json!([["A", "Relay1"], ["B", "Relay2"]]), 0), executed_state::scalar(json!([["A", "Relay1"], ["B", "Relay2"]])), executed_state::par(2, 2), - executed_state::stream_string("test", 0), - executed_state::stream_string("test", 0), + executed_state::stream_string("result from unit_call_service", 0), + executed_state::stream_string("result from unit_call_service", 0), executed_state::par(1, 0), executed_state::request_sent_by("Remote"), ]; @@ -132,13 +132,13 @@ fn join_chat() { let relay_2_actual_trace = trace_from_result(&relay_2_result); let relay_2_expected_trace = vec![ - executed_state::stream_string("test", 0), + executed_state::stream_string("result from unit_call_service", 0), executed_state::stream(json!([["A", "Relay1"], ["B", "Relay2"]]), 0), executed_state::scalar(json!([["A", "Relay1"], ["B", "Relay2"]])), executed_state::par(1, 3), executed_state::request_sent_by("Remote"), executed_state::par(2, 0), - executed_state::stream_string("test", 0), + executed_state::stream_string("result from unit_call_service", 0), executed_state::request_sent_by("Relay2"), ]; @@ -150,14 +150,14 @@ fn join_chat() { let client_2_actual_trace = trace_from_result(&client_2_result); let client_2_expected_trace = vec![ - executed_state::stream_string("test", 0), + executed_state::stream_string("result from unit_call_service", 0), executed_state::stream(json!([["A", "Relay1"], ["B", "Relay2"]]), 0), executed_state::scalar(json!([["A", "Relay1"], ["B", "Relay2"]])), executed_state::par(1, 3), executed_state::request_sent_by("Remote"), executed_state::par(2, 0), - executed_state::stream_string("test", 0), - executed_state::stream_string("test", 0), + executed_state::stream_string("result from unit_call_service", 0), + executed_state::stream_string("result from unit_call_service", 0), ]; assert_eq!(client_2_actual_trace, client_2_expected_trace); @@ -200,14 +200,14 @@ fn join() { let client_1_actual_trace = trace_from_result(&client_1_result); let client_1_expected_trace = vec![ - executed_state::stream_string("test", 0), + executed_state::stream_string("result from unit_call_service", 0), executed_state::scalar(json!([["A"], ["B"]])), executed_state::par(2, 3), - executed_state::stream_string("test", 0), - executed_state::stream_string("test", 0), + executed_state::stream_string("result from unit_call_service", 0), + executed_state::stream_string("result from unit_call_service", 0), executed_state::par(2, 0), - executed_state::stream_string("test", 0), - executed_state::stream_string("test", 0), + executed_state::stream_string("result from unit_call_service", 0), + executed_state::stream_string("result from unit_call_service", 0), ]; assert_eq!(client_1_actual_trace, client_1_expected_trace); @@ -256,14 +256,14 @@ fn init_peer_id() { let client_1_actual_trace = trace_from_result(&client_1_result); let client_1_expected_trace = vec![ - executed_state::scalar_string("test"), + executed_state::scalar_string("result from unit_call_service"), executed_state::scalar(json!([["A"], ["B"]])), executed_state::par(2, 3), - executed_state::scalar_string("test"), - executed_state::scalar_string("test"), + executed_state::scalar_string("result from unit_call_service"), + executed_state::scalar_string("result from unit_call_service"), executed_state::par(2, 0), - executed_state::scalar_string("test"), - executed_state::scalar_string("test"), + executed_state::scalar_string("result from unit_call_service"), + executed_state::scalar_string("result from unit_call_service"), executed_state::request_sent_by("A"), ]; @@ -275,15 +275,15 @@ fn init_peer_id() { let initiator_1_actual_trace = trace_from_result(&initiator_1_result); let initiator_1_expected_trace = vec![ - executed_state::scalar_string("test"), + executed_state::scalar_string("result from unit_call_service"), executed_state::scalar(json!([["A"], ["B"]])), executed_state::par(2, 3), - executed_state::scalar_string("test"), - executed_state::scalar_string("test"), + executed_state::scalar_string("result from unit_call_service"), + executed_state::scalar_string("result from unit_call_service"), executed_state::par(2, 0), - executed_state::scalar_string("test"), - executed_state::scalar_string("test"), - executed_state::scalar_string("test"), + executed_state::scalar_string("result from unit_call_service"), + executed_state::scalar_string("result from unit_call_service"), + executed_state::scalar_string("result from unit_call_service"), ]; assert_eq!(initiator_1_actual_trace, initiator_1_expected_trace); diff --git a/air/tests/test_module/integration/last_error.rs b/air/tests/test_module/integration/last_error.rs index fa0e479a..b53d203a 100644 --- a/air/tests/test_module/integration/last_error.rs +++ b/air/tests/test_module/integration/last_error.rs @@ -73,7 +73,7 @@ fn last_error_tetraplets() { assert_eq!( actual_value.msg, - r#"Local service error, ret_code is 1, error message is '"error"'"# + r#"Local service error, ret_code is 1, error message is '"failed result from fallible_call_service"'"# ); let tetraplet = (*tetraplets.borrow()).as_ref().unwrap()[0][0].clone(); @@ -142,7 +142,7 @@ fn not_clear_last_error_in_mismatch() { (seq (call "{0}" ("" "") [] relayVariableName) (xor - (mismatch relayVariableName "test" + (mismatch relayVariableName "result from unit_call_service" (call "unknown_peer" ("" "") [%last_error%]) ) (seq diff --git a/air/tests/test_module/integration/streams.rs b/air/tests/test_module/integration/streams.rs index 08dcd0f4..87068f22 100644 --- a/air/tests/test_module/integration/streams.rs +++ b/air/tests/test_module/integration/streams.rs @@ -68,9 +68,9 @@ fn stream_merging_v0() { let executor_result_1 = checked_call_vm!(executor, "", &script, "", setter_1_res.data); let actual_trace_1 = trace_from_result(&executor_result_1); - let test_value = "test"; + let unit_call_service_result = "result from unit_call_service"; let expected_trace_1 = vec![ - executed_state::scalar_string(test_value), + executed_state::scalar_string(unit_call_service_result), executed_state::par(11, 1), executed_state::par(9, 1), executed_state::par(7, 1), @@ -89,12 +89,12 @@ fn stream_merging_v0() { executed_state::subtrace_lore(9, SubTraceDesc::new(17, 2), SubTraceDesc::new(21, 0)), executed_state::subtrace_lore(12, SubTraceDesc::new(19, 2), SubTraceDesc::new(21, 0)), ]), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), ]; assert_eq!(actual_trace_1, expected_trace_1); @@ -102,7 +102,7 @@ fn stream_merging_v0() { let actual_trace_2 = trace_from_result(&executor_result_2); let expected_trace_2 = vec![ - executed_state::scalar_string(test_value), + executed_state::scalar_string(unit_call_service_result), executed_state::par(11, 1), executed_state::par(9, 1), executed_state::par(7, 1), @@ -123,16 +123,16 @@ fn stream_merging_v0() { executed_state::subtrace_lore(8, SubTraceDesc::new(21, 2), SubTraceDesc::new(25, 0)), executed_state::subtrace_lore(13, SubTraceDesc::new(23, 2), SubTraceDesc::new(25, 0)), ]), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), ]; assert_eq!(actual_trace_2, expected_trace_2); @@ -140,7 +140,7 @@ fn stream_merging_v0() { let actual_trace_3 = trace_from_result(&executor_result_3); let expected_trace_3 = vec![ - executed_state::scalar_string(test_value), + executed_state::scalar_string(unit_call_service_result), executed_state::par(11, 1), executed_state::par(9, 1), executed_state::par(7, 1), @@ -163,20 +163,20 @@ fn stream_merging_v0() { executed_state::subtrace_lore(10, SubTraceDesc::new(25, 2), SubTraceDesc::new(29, 0)), executed_state::subtrace_lore(11, SubTraceDesc::new(27, 2), SubTraceDesc::new(29, 0)), ]), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), ]; assert_eq!(actual_trace_3, expected_trace_3); } @@ -208,9 +208,9 @@ fn stream_merging_v1() { let executor_result_1 = checked_call_vm!(executor, "", &script, "", setter_1_res.data); let actual_trace_1 = trace_from_result(&executor_result_1); - let test_value = "test"; + let unit_call_service_result = "result from unit_call_service"; let expected_trace_1 = vec![ - executed_state::scalar_string(test_value), + executed_state::scalar_string(unit_call_service_result), executed_state::par(11, 1), executed_state::par(9, 1), executed_state::par(7, 1), @@ -229,12 +229,12 @@ fn stream_merging_v1() { executed_state::subtrace_lore(9, SubTraceDesc::new(16, 1), SubTraceDesc::new(19, 1)), executed_state::subtrace_lore(12, SubTraceDesc::new(17, 1), SubTraceDesc::new(18, 1)), ]), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), ]; assert_eq!(actual_trace_1, expected_trace_1); @@ -242,7 +242,7 @@ fn stream_merging_v1() { let actual_trace_2 = trace_from_result(&executor_result_2); let expected_trace_2 = vec![ - executed_state::scalar_string(test_value), + executed_state::scalar_string(unit_call_service_result), executed_state::par(11, 1), executed_state::par(9, 1), executed_state::par(7, 1), @@ -263,16 +263,16 @@ fn stream_merging_v1() { executed_state::subtrace_lore(8, SubTraceDesc::new(21, 1), SubTraceDesc::new(24, 1)), executed_state::subtrace_lore(13, SubTraceDesc::new(22, 1), SubTraceDesc::new(23, 1)), ]), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), ]; assert_eq!(actual_trace_2, expected_trace_2); @@ -280,7 +280,7 @@ fn stream_merging_v1() { let actual_trace_3 = trace_from_result(&executor_result_3); let expected_trace_3 = vec![ - executed_state::scalar_string(test_value), + executed_state::scalar_string(unit_call_service_result), executed_state::par(11, 1), executed_state::par(9, 1), executed_state::par(7, 1), @@ -303,20 +303,20 @@ fn stream_merging_v1() { executed_state::subtrace_lore(10, SubTraceDesc::new(25, 1), SubTraceDesc::new(28, 1)), executed_state::subtrace_lore(11, SubTraceDesc::new(26, 1), SubTraceDesc::new(27, 1)), ]), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), ]; assert_eq!(actual_trace_3, expected_trace_3); } @@ -348,9 +348,9 @@ fn stream_merging_v2() { let executor_result_1 = checked_call_vm!(executor, "", &script, "", setter_1_res.data); let actual_trace_1 = trace_from_result(&executor_result_1); - let test_value = "test"; + let unit_call_service_result = "result from unit_call_service"; let expected_trace_1 = vec![ - executed_state::scalar_string(test_value), + executed_state::scalar_string(unit_call_service_result), executed_state::par(11, 1), executed_state::par(9, 1), executed_state::par(7, 1), @@ -369,12 +369,12 @@ fn stream_merging_v2() { executed_state::subtrace_lore(9, SubTraceDesc::new(15, 0), SubTraceDesc::new(17, 2)), executed_state::subtrace_lore(12, SubTraceDesc::new(15, 0), SubTraceDesc::new(15, 2)), ]), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), ]; assert_eq!(actual_trace_1, expected_trace_1); @@ -382,7 +382,7 @@ fn stream_merging_v2() { let actual_trace_2 = trace_from_result(&executor_result_2); let expected_trace_2 = vec![ - executed_state::scalar_string(test_value), + executed_state::scalar_string(unit_call_service_result), executed_state::par(11, 1), executed_state::par(9, 1), executed_state::par(7, 1), @@ -403,16 +403,16 @@ fn stream_merging_v2() { executed_state::subtrace_lore(8, SubTraceDesc::new(21, 0), SubTraceDesc::new(23, 2)), executed_state::subtrace_lore(13, SubTraceDesc::new(21, 0), SubTraceDesc::new(21, 2)), ]), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), ]; assert_eq!(actual_trace_2, expected_trace_2); @@ -420,7 +420,7 @@ fn stream_merging_v2() { let actual_trace_3 = trace_from_result(&executor_result_3); let expected_trace_3 = vec![ - executed_state::scalar_string(test_value), + executed_state::scalar_string(unit_call_service_result), executed_state::par(11, 1), executed_state::par(9, 1), executed_state::par(7, 1), @@ -443,20 +443,20 @@ fn stream_merging_v2() { executed_state::subtrace_lore(10, SubTraceDesc::new(25, 0), SubTraceDesc::new(27, 2)), executed_state::subtrace_lore(11, SubTraceDesc::new(25, 0), SubTraceDesc::new(25, 2)), ]), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), ]; assert_eq!(actual_trace_3, expected_trace_3); } diff --git a/air/tests/test_module/integration/streams_early_exit.rs b/air/tests/test_module/integration/streams_early_exit.rs index 13083deb..0d8560dd 100644 --- a/air/tests/test_module/integration/streams_early_exit.rs +++ b/air/tests/test_module/integration/streams_early_exit.rs @@ -40,7 +40,7 @@ fn par_early_exit() { let actual_trace_1 = trace_from_result(&setter_3_res_1); let expected_trace = vec![ - executed_state::scalar_string("test"), + executed_state::scalar_string("result from unit_call_service"), executed_state::par(12, 1), executed_state::par(9, 1), executed_state::par(7, 1), @@ -50,11 +50,11 @@ fn par_early_exit() { executed_state::request_sent_by(init_peer_id), executed_state::request_sent_by(init_peer_id), executed_state::request_sent_by(init_peer_id), - executed_state::stream_string("test", 0), - executed_state::service_failed(1, r#""error""#), - executed_state::stream_string("test", 0), - executed_state::service_failed(1, r#""error""#), - executed_state::service_failed(1, r#""error""#), + executed_state::stream_string("success result from fallible_call_service", 0), + executed_state::service_failed(1, "failed result from fallible_call_service"), + executed_state::stream_string("success result from fallible_call_service", 0), + executed_state::service_failed(1, "failed result from fallible_call_service"), + executed_state::service_failed(1, "failed result from fallible_call_service"), executed_state::request_sent_by(setter_3_id), ]; assert_eq!(actual_trace_1, expected_trace); @@ -84,7 +84,7 @@ fn par_early_exit() { let actual_trace_3 = trace_from_result(&init_result_2); let expected_trace = vec![ - executed_state::scalar_string("test"), + executed_state::scalar_string("result from unit_call_service"), executed_state::par(12, 1), executed_state::par(9, 1), executed_state::par(7, 1), @@ -94,17 +94,17 @@ fn par_early_exit() { executed_state::stream_string("1", 1), executed_state::stream_string("2", 2), executed_state::stream_string("1", 1), - executed_state::stream_string("test", 0), - executed_state::service_failed(1, r#""error""#), - executed_state::stream_string("test", 0), - executed_state::service_failed(1, r#""error""#), - executed_state::service_failed(1, r#""error""#), + executed_state::stream_string("success result from fallible_call_service", 0), + executed_state::service_failed(1, "failed result from fallible_call_service"), + executed_state::stream_string("success result from fallible_call_service", 0), + executed_state::service_failed(1, "failed result from fallible_call_service"), + executed_state::service_failed(1, "failed result from fallible_call_service"), executed_state::request_sent_by("setter_3"), ]; assert_eq!(actual_trace_2, expected_trace); let expected_trace = vec![ - executed_state::scalar_string("test"), + executed_state::scalar_string("result from unit_call_service"), executed_state::par(12, 1), executed_state::par(9, 1), executed_state::par(7, 1), @@ -114,17 +114,17 @@ fn par_early_exit() { executed_state::stream_string("1", 0), executed_state::stream_string("2", 0), executed_state::stream_string("1", 0), - executed_state::stream_string("test", 0), - executed_state::service_failed(1, r#""error""#), - executed_state::stream_string("test", 0), - executed_state::service_failed(1, r#""error""#), - executed_state::service_failed(1, r#""error""#), - executed_state::scalar_string("test"), + executed_state::stream_string("success result from fallible_call_service", 0), + executed_state::service_failed(1, "failed result from fallible_call_service"), + executed_state::stream_string("success result from fallible_call_service", 0), + executed_state::service_failed(1, "failed result from fallible_call_service"), + executed_state::service_failed(1, "failed result from fallible_call_service"), + executed_state::scalar_string("result from unit_call_service"), ]; assert_eq!(actual_trace_3, expected_trace); let setter_3_malicious_trace = vec![ - executed_state::scalar_string("test"), + executed_state::scalar_string("result from unit_call_service"), executed_state::par(10, 0), executed_state::par(9, 0), executed_state::par(7, 1), @@ -134,8 +134,8 @@ fn par_early_exit() { executed_state::request_sent_by(init_peer_id), executed_state::request_sent_by(init_peer_id), executed_state::stream_string("non_exist_value", 0), - executed_state::stream_string("test", 0), - executed_state::service_failed(1, r#""error""#), + executed_state::stream_string("success result from fallible_call_service", 0), + executed_state::service_failed(1, "failed result from fallible_call_service"), executed_state::request_sent_by(setter_3_id), ]; let setter_3_malicious_data = raw_data_from_trace(setter_3_malicious_trace); @@ -189,7 +189,7 @@ fn fold_early_exit() { checked_call_vm!(last_peer_checker, "", &script, "", last_error_receiver_result.data); let actual_trace = trace_from_result(&last_peer_checker_result); - let test_value = "test"; + let unit_call_service_result = "result from unit_call_service"; let expected_trace = vec![ executed_state::scalar_string_array(vec!["a1", "a2"]), executed_state::scalar_string_array(vec!["b1", "b2"]), @@ -222,17 +222,17 @@ fn fold_early_exit() { executed_state::subtrace_lore(10, SubTraceDesc::new(17, 1), SubTraceDesc::new(19, 0)), executed_state::subtrace_lore(11, SubTraceDesc::new(18, 1), SubTraceDesc::new(19, 0)), ]), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), executed_state::fold(vec![ executed_state::subtrace_lore(10, SubTraceDesc::new(20, 1), SubTraceDesc::new(22, 0)), executed_state::subtrace_lore(11, SubTraceDesc::new(21, 1), SubTraceDesc::new(22, 0)), ]), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), - executed_state::service_failed(1, r#""error""#), - executed_state::scalar_string(test_value), - executed_state::scalar_string(test_value), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), + executed_state::service_failed(1, "failed result from fallible_call_service"), + executed_state::scalar_string(unit_call_service_result), + executed_state::scalar_string(unit_call_service_result), ]; assert_eq!(actual_trace, expected_trace); @@ -280,7 +280,7 @@ fn fold_par_early_exit() { checked_call_vm!(last_peer_checker, "", &script, "", last_error_receiver_result.data); let actual_trace = trace_from_result(&last_peer_checker_result); - let test_value = "test"; + let unit_call_service_result = "result from unit_call_service"; let expected_trace = vec![ executed_state::scalar_string_array(vec!["a1", "a2"]), executed_state::scalar_string_array(vec!["b1", "b2"]), @@ -316,19 +316,19 @@ fn fold_par_early_exit() { executed_state::subtrace_lore(11, SubTraceDesc::new(23, 2), SubTraceDesc::new(25, 0)), ]), executed_state::par(1, 2), - executed_state::scalar_string(test_value), + executed_state::scalar_string(unit_call_service_result), executed_state::par(1, 0), - executed_state::scalar_string(test_value), + executed_state::scalar_string(unit_call_service_result), executed_state::par(5, 0), executed_state::fold(vec![ executed_state::subtrace_lore(10, SubTraceDesc::new(27, 2), SubTraceDesc::new(31, 0)), executed_state::subtrace_lore(11, SubTraceDesc::new(29, 2), SubTraceDesc::new(31, 0)), ]), executed_state::par(1, 2), - executed_state::scalar_string(test_value), + executed_state::scalar_string(unit_call_service_result), executed_state::par(1, 0), - executed_state::scalar_string(test_value), - executed_state::service_failed(1, r#""error""#), + executed_state::scalar_string(unit_call_service_result), + executed_state::service_failed(1, "failed result from fallible_call_service"), executed_state::par(15, 0), executed_state::par(13, 1), executed_state::fold(vec![ diff --git a/crates/air-lib/test-utils/src/call_services.rs b/crates/air-lib/test-utils/src/call_services.rs index b73e8d74..bc000246 100644 --- a/crates/air-lib/test-utils/src/call_services.rs +++ b/crates/air-lib/test-utils/src/call_services.rs @@ -20,7 +20,9 @@ use serde_json::json; use std::collections::HashMap; pub fn unit_call_service() -> CallServiceClosure { - Box::new(|_| -> CallServiceResult { CallServiceResult::ok(json!("test")) }) + Box::new(|_| -> CallServiceResult { + CallServiceResult::ok(json!("result from unit_call_service")) + }) } pub fn echo_call_service() -> CallServiceClosure { @@ -43,7 +45,7 @@ pub fn set_variables_call_service( }; variables_mapping.get(&var_name).map_or_else( - || CallServiceResult::ok(json!("test")), + || CallServiceResult::ok(json!("default result from set_variables_call_service")), |var| CallServiceResult::ok(var.clone()), ) }) @@ -61,10 +63,10 @@ pub fn fallible_call_service(fallible_service_id: impl Into) -> CallServ Box::new(move |params| -> CallServiceResult { // return a error for service with such id if params.service_id == fallible_service_id { - CallServiceResult::err(1, json!("error")) + CallServiceResult::err(1, json!("failed result from fallible_call_service")) } else { // return success for services with other service id - CallServiceResult::ok(json!("test")) + CallServiceResult::ok(json!("success result from fallible_call_service")) } }) } diff --git a/crates/air-lib/test-utils/src/executed_state.rs b/crates/air-lib/test-utils/src/executed_state.rs index 951c49ba..a5c2378f 100644 --- a/crates/air-lib/test-utils/src/executed_state.rs +++ b/crates/air-lib/test-utils/src/executed_state.rs @@ -100,10 +100,10 @@ pub fn par(left: usize, right: usize) -> ExecutedState { ExecutedState::Par(par_result) } -pub fn service_failed(ret_code: i32, error_message: impl Into) -> ExecutedState { +pub fn service_failed(ret_code: i32, error_message: &str) -> ExecutedState { ExecutedState::Call(CallResult::CallServiceFailed( ret_code, - Rc::new(error_message.into()), + Rc::new(format!(r#""{}""#, error_message)), )) }