From 7007c7c0780cc2ca26f5c0b75afc709910738083 Mon Sep 17 00:00:00 2001 From: Moncef AOUDIA Date: Tue, 17 Oct 2023 17:50:33 +0200 Subject: [PATCH] refactor: add some basic tests --- .../src/stream/new_slot_execution_outputs.rs | 18 +- massa-grpc/src/tests/stream.rs | 619 ++++++++++-------- 2 files changed, 350 insertions(+), 287 deletions(-) diff --git a/massa-grpc/src/stream/new_slot_execution_outputs.rs b/massa-grpc/src/stream/new_slot_execution_outputs.rs index afebf3ba5bb..802a94f5020 100644 --- a/massa-grpc/src/stream/new_slot_execution_outputs.rs +++ b/massa-grpc/src/stream/new_slot_execution_outputs.rs @@ -126,7 +126,10 @@ pub(crate) async fn new_slot_execution_outputs( error!("failed to get filter: {}", err); // Send the error response back to the client if let Err(e) = tx.send(Err(err.into())).await { - error!("failed to send back NewBlocks error response: {}", e); + error!( + "failed to send back NewSlotExecutionOutputs error response: {}", + e + ); } return; } @@ -447,11 +450,14 @@ fn filter_map_exec_output( } } - if let (Some(original_operation_ids), Some(origin_operation_id)) = ( - execution_event_filter.original_operation_ids.clone(), - event.context.origin_operation_id, - ) { - if !original_operation_ids.contains(&origin_operation_id) { + if let Some(original_operation_ids) = + execution_event_filter.original_operation_ids.clone() + { + if let Some(origin_operation_id) = event.context.origin_operation_id { + if !original_operation_ids.contains(&origin_operation_id) { + return false; + } + } else { return false; } } diff --git a/massa-grpc/src/tests/stream.rs b/massa-grpc/src/tests/stream.rs index 071628fde03..47f09463bc4 100644 --- a/massa-grpc/src/tests/stream.rs +++ b/massa-grpc/src/tests/stream.rs @@ -2,8 +2,9 @@ use crate::tests::mock::{grpc_public_service, MockExecutionCtrl, MockPoolCtrl}; use massa_bootstrap::test_exports::{ - get_random_async_pool_changes, get_random_executed_de_changes, get_random_executed_ops_changes, - get_random_execution_trail_hash_change, get_random_ledger_changes, + get_dummy_block_id, get_random_async_pool_changes, get_random_executed_de_changes, + get_random_executed_ops_changes, get_random_execution_trail_hash_change, + get_random_ledger_changes, }; use massa_consensus_exports::test_exports::MockConsensusControllerImpl; use massa_execution_exports::{ @@ -14,6 +15,8 @@ use massa_models::{ address::Address, block::FilledBlock, secure_share::SecureShareSerializer, slot::Slot, stats::ExecutionStats, }; +use massa_proto_rs::massa::api::v1::{self as grpc_api}; +use massa_proto_rs::massa::model::v1::{self as grpc_model}; use massa_proto_rs::massa::{ api::v1::{ public_service_client::PublicServiceClient, NewBlocksRequest, NewFilledBlocksRequest, @@ -22,6 +25,7 @@ use massa_proto_rs::massa::{ }, model::v1::{Addresses, Slot as ProtoSlot, SlotRange}, }; + use massa_protocol_exports::{ test_exports::tools::{ create_block, create_block_with_operations, create_endorsement, @@ -201,16 +205,14 @@ async fn new_operations() { .unwrap() .into_inner(); - let filter = massa_proto_rs::massa::api::v1::NewOperationsFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_operations_filter::Filter::OperationIds( - massa_proto_rs::massa::model::v1::OperationIds { - operation_ids: vec![ - "O1q4CBcuYo8YANEV34W4JRWVHrzcYns19VJfyAB7jT4qfitAnMC".to_string() - ], - }, - ), - ), + let filter = grpc_api::NewOperationsFilter { + filter: Some(grpc_api::new_operations_filter::Filter::OperationIds( + grpc_model::OperationIds { + operation_ids: vec![ + "O1q4CBcuYo8YANEV34W4JRWVHrzcYns19VJfyAB7jT4qfitAnMC".to_string() + ], + }, + )), }; // send filter with unknow op id @@ -229,14 +231,12 @@ async fn new_operations() { assert!(result.is_err()); // send filter with known op id - let filter_id = massa_proto_rs::massa::api::v1::NewOperationsFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_operations_filter::Filter::OperationIds( - massa_proto_rs::massa::model::v1::OperationIds { - operation_ids: vec![op.id.to_string()], - }, - ), - ), + let filter_id = grpc_api::NewOperationsFilter { + filter: Some(grpc_api::new_operations_filter::Filter::OperationIds( + grpc_model::OperationIds { + operation_ids: vec![op.id.to_string()], + }, + )), }; tx_request @@ -260,14 +260,12 @@ async fn new_operations() { keypair.get_public_key().to_string() ); - let mut filter_type = massa_proto_rs::massa::api::v1::NewOperationsFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_operations_filter::Filter::OperationTypes( - massa_proto_rs::massa::model::v1::OpTypes { - op_types: vec![massa_proto_rs::massa::model::v1::OpType::CallSc as i32], - }, - ), - ), + let mut filter_type = grpc_api::NewOperationsFilter { + filter: Some(grpc_api::new_operations_filter::Filter::OperationTypes( + grpc_model::OpTypes { + op_types: vec![grpc_model::OpType::CallSc as i32], + }, + )), }; tx_request @@ -283,14 +281,12 @@ async fn new_operations() { assert!(result.is_err()); - filter_type = massa_proto_rs::massa::api::v1::NewOperationsFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_operations_filter::Filter::OperationTypes( - massa_proto_rs::massa::model::v1::OpTypes { - op_types: vec![massa_proto_rs::massa::model::v1::OpType::Transaction as i32], - }, - ), - ), + filter_type = grpc_api::NewOperationsFilter { + filter: Some(grpc_api::new_operations_filter::Filter::OperationTypes( + grpc_model::OpTypes { + op_types: vec![grpc_model::OpType::Transaction as i32], + }, + )), }; tx_request @@ -330,16 +326,12 @@ async fn new_operations() { keypair.get_public_key().to_string() ); - let mut filter_addr = massa_proto_rs::massa::api::v1::NewOperationsFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_operations_filter::Filter::Addresses( - massa_proto_rs::massa::model::v1::Addresses { - addresses: vec![ - "AU12BTfZ7k1z6PsLEUZeHYNirz6WJ3NdrWto9H4TkVpkV9xE2TJg2".to_string() - ], - }, - ), - ), + let mut filter_addr = grpc_api::NewOperationsFilter { + filter: Some(grpc_api::new_operations_filter::Filter::Addresses( + grpc_model::Addresses { + addresses: vec!["AU12BTfZ7k1z6PsLEUZeHYNirz6WJ3NdrWto9H4TkVpkV9xE2TJg2".to_string()], + }, + )), }; tx_request @@ -354,14 +346,12 @@ async fn new_operations() { // unknown address assert!(result.is_err()); - filter_addr = massa_proto_rs::massa::api::v1::NewOperationsFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_operations_filter::Filter::Addresses( - massa_proto_rs::massa::model::v1::Addresses { - addresses: vec![address.to_string()], - }, - ), - ), + filter_addr = grpc_api::NewOperationsFilter { + filter: Some(grpc_api::new_operations_filter::Filter::Addresses( + grpc_model::Addresses { + addresses: vec![address.to_string()], + }, + )), }; tx_request @@ -424,16 +414,14 @@ async fn new_blocks() { .unwrap() .into_inner(); - let mut filter_slot = massa_proto_rs::massa::api::v1::NewBlocksFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_blocks_filter::Filter::SlotRange(SlotRange { - start_slot: Some(ProtoSlot { - period: 1, - thread: 1, - }), - end_slot: None, + let mut filter_slot = grpc_api::NewBlocksFilter { + filter: Some(grpc_api::new_blocks_filter::Filter::SlotRange(SlotRange { + start_slot: Some(ProtoSlot { + period: 1, + thread: 1, }), - ), + end_slot: None, + })), }; tx_request .send(NewBlocksRequest { @@ -454,16 +442,14 @@ async fn new_blocks() { // assert block is received assert!(result.signed_block.is_some()); - filter_slot = massa_proto_rs::massa::api::v1::NewBlocksFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_blocks_filter::Filter::SlotRange(SlotRange { - start_slot: Some(ProtoSlot { - period: 1, - thread: 15, - }), - end_slot: None, + filter_slot = grpc_api::NewBlocksFilter { + filter: Some(grpc_api::new_blocks_filter::Filter::SlotRange(SlotRange { + start_slot: Some(ProtoSlot { + period: 1, + thread: 15, }), - ), + end_slot: None, + })), }; // update filter @@ -483,16 +469,14 @@ async fn new_blocks() { // elapsed, start slot is after block slot assert!(result.is_err()); - filter_slot = massa_proto_rs::massa::api::v1::NewBlocksFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_blocks_filter::Filter::SlotRange(SlotRange { - start_slot: None, - end_slot: Some(ProtoSlot { - period: 1, - thread: 15, - }), + filter_slot = grpc_api::NewBlocksFilter { + filter: Some(grpc_api::new_blocks_filter::Filter::SlotRange(SlotRange { + start_slot: None, + end_slot: Some(ProtoSlot { + period: 1, + thread: 15, }), - ), + })), }; tx_request @@ -515,12 +499,10 @@ async fn new_blocks() { // assert block is received assert!(result.signed_block.is_some()); - let mut filter_addr = massa_proto_rs::massa::api::v1::NewBlocksFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_blocks_filter::Filter::Addresses(Addresses { - addresses: vec!["AU12BTfZ7k1z6PsLEUZeHYNirz6WJ3NdrWto9H4TkVpkV9xE2TJg2".to_string()], - }), - ), + let mut filter_addr = grpc_api::NewBlocksFilter { + filter: Some(grpc_api::new_blocks_filter::Filter::Addresses(Addresses { + addresses: vec!["AU12BTfZ7k1z6PsLEUZeHYNirz6WJ3NdrWto9H4TkVpkV9xE2TJg2".to_string()], + })), }; tx_request @@ -539,12 +521,10 @@ async fn new_blocks() { // elapsed assert!(result.is_err()); - filter_addr = massa_proto_rs::massa::api::v1::NewBlocksFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_blocks_filter::Filter::Addresses(Addresses { - addresses: vec![address.to_string()], - }), - ), + filter_addr = grpc_api::NewBlocksFilter { + filter: Some(grpc_api::new_blocks_filter::Filter::Addresses(Addresses { + addresses: vec![address.to_string()], + })), }; tx_request @@ -567,16 +547,12 @@ async fn new_blocks() { assert!(result.signed_block.is_some()); - let mut filter_ids = massa_proto_rs::massa::api::v1::NewBlocksFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_blocks_filter::Filter::BlockIds( - massa_proto_rs::massa::model::v1::BlockIds { - block_ids: vec![ - "B1q4CBcuYo8YANEV34W4JRWVHrzcYns19VJfyAB7jT4qfitAnMC".to_string() - ], - }, - ), - ), + let mut filter_ids = grpc_api::NewBlocksFilter { + filter: Some(grpc_api::new_blocks_filter::Filter::BlockIds( + grpc_model::BlockIds { + block_ids: vec!["B1q4CBcuYo8YANEV34W4JRWVHrzcYns19VJfyAB7jT4qfitAnMC".to_string()], + }, + )), }; tx_request @@ -595,14 +571,12 @@ async fn new_blocks() { // elapsed assert!(result.is_err()); - filter_ids = massa_proto_rs::massa::api::v1::NewBlocksFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_blocks_filter::Filter::BlockIds( - massa_proto_rs::massa::model::v1::BlockIds { - block_ids: vec![block_op.id.to_string()], - }, - ), - ), + filter_ids = grpc_api::NewBlocksFilter { + filter: Some(grpc_api::new_blocks_filter::Filter::BlockIds( + grpc_model::BlockIds { + block_ids: vec![block_op.id.to_string()], + }, + )), }; tx_request @@ -625,12 +599,10 @@ async fn new_blocks() { assert!(result.signed_block.is_some()); - filter_addr = massa_proto_rs::massa::api::v1::NewBlocksFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_blocks_filter::Filter::Addresses(Addresses { - addresses: vec!["massa".to_string()], - }), - ), + filter_addr = grpc_api::NewBlocksFilter { + filter: Some(grpc_api::new_blocks_filter::Filter::Addresses(Addresses { + addresses: vec!["massa".to_string()], + })), }; tx_request @@ -682,20 +654,18 @@ async fn new_endorsements() { .unwrap() .into_inner(); - let mut filter_ids = massa_proto_rs::massa::api::v1::NewEndorsementsFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_endorsements_filter::Filter::EndorsementIds( - massa_proto_rs::massa::model::v1::EndorsementIds { - endorsement_ids: vec![ - "E1q4CBcuYo8YANEV34W4JRWVHrzcYns19VJfyAB7jT4qfitAnMC".to_string() - ], - }, - ), - ), + let mut filter_ids = grpc_api::NewEndorsementsFilter { + filter: Some(grpc_api::new_endorsements_filter::Filter::EndorsementIds( + grpc_model::EndorsementIds { + endorsement_ids: vec![ + "E1q4CBcuYo8YANEV34W4JRWVHrzcYns19VJfyAB7jT4qfitAnMC".to_string() + ], + }, + )), }; tx_request - .send(massa_proto_rs::massa::api::v1::NewEndorsementsRequest { + .send(grpc_api::NewEndorsementsRequest { filters: vec![filter_ids], }) .await @@ -708,18 +678,16 @@ async fn new_endorsements() { let result = tokio::time::timeout(Duration::from_secs(2), resp_stream.next()).await; assert!(result.is_err()); - filter_ids = massa_proto_rs::massa::api::v1::NewEndorsementsFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_endorsements_filter::Filter::EndorsementIds( - massa_proto_rs::massa::model::v1::EndorsementIds { - endorsement_ids: vec![endorsement.id.to_string()], - }, - ), - ), + filter_ids = grpc_api::NewEndorsementsFilter { + filter: Some(grpc_api::new_endorsements_filter::Filter::EndorsementIds( + grpc_model::EndorsementIds { + endorsement_ids: vec![endorsement.id.to_string()], + }, + )), }; tx_request - .send(massa_proto_rs::massa::api::v1::NewEndorsementsRequest { + .send(grpc_api::NewEndorsementsRequest { filters: vec![filter_ids], }) .await @@ -737,20 +705,16 @@ async fn new_endorsements() { assert!(result.signed_endorsement.is_some()); - let mut filter_addr = massa_proto_rs::massa::api::v1::NewEndorsementsFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_endorsements_filter::Filter::Addresses( - massa_proto_rs::massa::model::v1::Addresses { - addresses: vec![ - "AU12BTfZ7k1z6PsLEUZeHYNirz6WJ3NdrWto9H4TkVpkV9xE2TJg2".to_string() - ], - }, - ), - ), + let mut filter_addr = grpc_api::NewEndorsementsFilter { + filter: Some(grpc_api::new_endorsements_filter::Filter::Addresses( + grpc_model::Addresses { + addresses: vec!["AU12BTfZ7k1z6PsLEUZeHYNirz6WJ3NdrWto9H4TkVpkV9xE2TJg2".to_string()], + }, + )), }; tx_request - .send(massa_proto_rs::massa::api::v1::NewEndorsementsRequest { + .send(grpc_api::NewEndorsementsRequest { filters: vec![filter_addr], }) .await @@ -764,18 +728,16 @@ async fn new_endorsements() { // unknown address assert!(result.is_err()); - filter_addr = massa_proto_rs::massa::api::v1::NewEndorsementsFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_endorsements_filter::Filter::Addresses( - massa_proto_rs::massa::model::v1::Addresses { - addresses: vec![endorsement.content_creator_address.to_string()], - }, - ), - ), + filter_addr = grpc_api::NewEndorsementsFilter { + filter: Some(grpc_api::new_endorsements_filter::Filter::Addresses( + grpc_model::Addresses { + addresses: vec![endorsement.content_creator_address.to_string()], + }, + )), }; tx_request - .send(massa_proto_rs::massa::api::v1::NewEndorsementsRequest { + .send(grpc_api::NewEndorsementsRequest { filters: vec![filter_addr], }) .await @@ -793,20 +755,16 @@ async fn new_endorsements() { assert!(result.signed_endorsement.is_some()); - let mut filter_block_ids = massa_proto_rs::massa::api::v1::NewEndorsementsFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_endorsements_filter::Filter::BlockIds( - massa_proto_rs::massa::model::v1::BlockIds { - block_ids: vec![ - "B1q4CBcuYo8YANEV34W4JRWVHrzcYns19VJfyAB7jT4qfitAnMC".to_string() - ], - }, - ), - ), + let mut filter_block_ids = grpc_api::NewEndorsementsFilter { + filter: Some(grpc_api::new_endorsements_filter::Filter::BlockIds( + grpc_model::BlockIds { + block_ids: vec!["B1q4CBcuYo8YANEV34W4JRWVHrzcYns19VJfyAB7jT4qfitAnMC".to_string()], + }, + )), }; tx_request - .send(massa_proto_rs::massa::api::v1::NewEndorsementsRequest { + .send(grpc_api::NewEndorsementsRequest { filters: vec![filter_block_ids], }) .await @@ -819,18 +777,16 @@ async fn new_endorsements() { let result = tokio::time::timeout(Duration::from_secs(2), resp_stream.next()).await; assert!(result.is_err()); - filter_block_ids = massa_proto_rs::massa::api::v1::NewEndorsementsFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_endorsements_filter::Filter::BlockIds( - massa_proto_rs::massa::model::v1::BlockIds { - block_ids: vec![endorsement.content.endorsed_block.to_string()], - }, - ), - ), + filter_block_ids = grpc_api::NewEndorsementsFilter { + filter: Some(grpc_api::new_endorsements_filter::Filter::BlockIds( + grpc_model::BlockIds { + block_ids: vec![endorsement.content.endorsed_block.to_string()], + }, + )), }; tx_request - .send(massa_proto_rs::massa::api::v1::NewEndorsementsRequest { + .send(grpc_api::NewEndorsementsRequest { filters: vec![filter_block_ids], }) .await @@ -887,16 +843,14 @@ async fn new_filled_blocks() { .unwrap() .into_inner(); - let mut filter = massa_proto_rs::massa::api::v1::NewBlocksFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_blocks_filter::Filter::SlotRange(SlotRange { - start_slot: Some(ProtoSlot { - period: 1, - thread: 0, - }), - end_slot: None, + let mut filter = grpc_api::NewBlocksFilter { + filter: Some(grpc_api::new_blocks_filter::Filter::SlotRange(SlotRange { + start_slot: Some(ProtoSlot { + period: 1, + thread: 0, }), - ), + end_slot: None, + })), }; tx_request @@ -918,16 +872,14 @@ async fn new_filled_blocks() { assert!(result.filled_block.is_some()); - filter = massa_proto_rs::massa::api::v1::NewBlocksFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_blocks_filter::Filter::SlotRange(SlotRange { - start_slot: Some(ProtoSlot { - period: 1, - thread: 5, - }), - end_slot: None, + filter = grpc_api::NewBlocksFilter { + filter: Some(grpc_api::new_blocks_filter::Filter::SlotRange(SlotRange { + start_slot: Some(ProtoSlot { + period: 1, + thread: 5, }), - ), + end_slot: None, + })), }; tx_request @@ -945,16 +897,12 @@ async fn new_filled_blocks() { // stat slot is after block slot assert!(result.is_err()); - filter = massa_proto_rs::massa::api::v1::NewBlocksFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_blocks_filter::Filter::BlockIds( - massa_proto_rs::massa::model::v1::BlockIds { - block_ids: vec![ - "B1q4CBcuYo8YANEV34W4JRWVHrzcYns19VJfyAB7jT4qfitAnMC".to_string() - ], - }, - ), - ), + filter = grpc_api::NewBlocksFilter { + filter: Some(grpc_api::new_blocks_filter::Filter::BlockIds( + grpc_model::BlockIds { + block_ids: vec!["B1q4CBcuYo8YANEV34W4JRWVHrzcYns19VJfyAB7jT4qfitAnMC".to_string()], + }, + )), }; tx_request @@ -972,14 +920,12 @@ async fn new_filled_blocks() { // unknown block id assert!(result.is_err()); - filter = massa_proto_rs::massa::api::v1::NewBlocksFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_blocks_filter::Filter::BlockIds( - massa_proto_rs::massa::model::v1::BlockIds { - block_ids: vec![filled_block.header.id.to_string()], - }, - ), - ), + filter = grpc_api::NewBlocksFilter { + filter: Some(grpc_api::new_blocks_filter::Filter::BlockIds( + grpc_model::BlockIds { + block_ids: vec![filled_block.header.id.to_string()], + }, + )), }; tx_request @@ -1001,12 +947,10 @@ async fn new_filled_blocks() { assert!(result.filled_block.is_some()); - filter = massa_proto_rs::massa::api::v1::NewBlocksFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_blocks_filter::Filter::Addresses(Addresses { - addresses: vec!["AU12BTfZ7k1z6PsLEUZeHYNirz6WJ3NdrWto9H4TkVpkV9xE2TJg2".to_string()], - }), - ), + filter = grpc_api::NewBlocksFilter { + filter: Some(grpc_api::new_blocks_filter::Filter::Addresses(Addresses { + addresses: vec!["AU12BTfZ7k1z6PsLEUZeHYNirz6WJ3NdrWto9H4TkVpkV9xE2TJg2".to_string()], + })), }; tx_request @@ -1024,12 +968,10 @@ async fn new_filled_blocks() { // unknown address assert!(result.is_err()); - filter = massa_proto_rs::massa::api::v1::NewBlocksFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_blocks_filter::Filter::Addresses(Addresses { - addresses: vec![address.to_string()], - }), - ), + filter = grpc_api::NewBlocksFilter { + filter: Some(grpc_api::new_blocks_filter::Filter::Addresses(Addresses { + addresses: vec![address.to_string()], + })), }; tx_request @@ -1071,21 +1013,30 @@ async fn new_slot_execution_outputs() { // Given let mut state_changes = StateChanges::default(); // Create async pool changes - state_changes.async_pool_changes = get_random_async_pool_changes(3, config.thread_count); + let async_pool_changes = get_random_async_pool_changes(2, config.thread_count); + state_changes.async_pool_changes = async_pool_changes.clone(); // Create executed denunciations changes - state_changes.executed_denunciations_changes = get_random_executed_de_changes(3); + let executed_denunciations_changes = get_random_executed_de_changes(2); + state_changes.executed_denunciations_changes = executed_denunciations_changes.clone(); // Create executed operations changes - state_changes.executed_ops_changes = get_random_executed_ops_changes(3); + let executed_ops_changes = get_random_executed_ops_changes(2); + state_changes.executed_ops_changes = executed_ops_changes.clone(); // Create ledger changes - state_changes.ledger_changes = get_random_ledger_changes(3); + let ledger_changes = get_random_ledger_changes(2); + state_changes.ledger_changes = ledger_changes.clone(); // Create execution trail hash change - state_changes.execution_trail_hash_change = get_random_execution_trail_hash_change(true); + let execution_trail_hash_change = get_random_execution_trail_hash_change(true); + state_changes.execution_trail_hash_change = execution_trail_hash_change.clone(); let exec_output_1 = ExecutionOutput { slot: Slot::new(1, 5), - block_info: None, + block_info: Some(massa_execution_exports::ExecutedBlockInfo { + block_id: get_dummy_block_id("toto"), + current_version: 1, + announced_version: None, + }), state_changes, - events: get_random_eventstore(3), + events: get_random_eventstore(2), }; let (tx_request, rx) = tokio::sync::mpsc::channel(10); @@ -1106,17 +1057,15 @@ async fn new_slot_execution_outputs() { .unwrap() .into_inner(); - let mut filter = massa_proto_rs::massa::api::v1::NewSlotExecutionOutputsFilter { + let mut filter = grpc_api::NewSlotExecutionOutputsFilter { filter: Some( - massa_proto_rs::massa::api::v1::new_slot_execution_outputs_filter::Filter::SlotRange( - SlotRange { - start_slot: Some(ProtoSlot { - period: 1, - thread: 0, - }), - end_slot: None, - }, - ), + grpc_api::new_slot_execution_outputs_filter::Filter::SlotRange(SlotRange { + start_slot: Some(ProtoSlot { + period: 1, + thread: 0, + }), + end_slot: None, + }), ), }; @@ -1140,20 +1089,18 @@ async fn new_slot_execution_outputs() { assert!(result.output.is_some()); - filter = massa_proto_rs::massa::api::v1::NewSlotExecutionOutputsFilter { + filter = grpc_api::NewSlotExecutionOutputsFilter { filter: Some( - massa_proto_rs::massa::api::v1::new_slot_execution_outputs_filter::Filter::SlotRange( - SlotRange { - start_slot: Some(ProtoSlot { - period: 1, - thread: 0, - }), - end_slot: Some(ProtoSlot { - period: 1, - thread: 7, - }), - }, - ), + grpc_api::new_slot_execution_outputs_filter::Filter::SlotRange(SlotRange { + start_slot: Some(ProtoSlot { + period: 1, + thread: 0, + }), + end_slot: Some(ProtoSlot { + period: 1, + thread: 7, + }), + }), ), }; @@ -1177,17 +1124,15 @@ async fn new_slot_execution_outputs() { // start slot and end slot are in range assert!(result.output.is_some()); - filter = massa_proto_rs::massa::api::v1::NewSlotExecutionOutputsFilter { + filter = grpc_api::NewSlotExecutionOutputsFilter { filter: Some( - massa_proto_rs::massa::api::v1::new_slot_execution_outputs_filter::Filter::SlotRange( - SlotRange { - start_slot: Some(ProtoSlot { - period: 1, - thread: 7, - }), - end_slot: None, - }, - ), + grpc_api::new_slot_execution_outputs_filter::Filter::SlotRange(SlotRange { + start_slot: Some(ProtoSlot { + period: 1, + thread: 7, + }), + end_slot: None, + }), ), }; @@ -1207,15 +1152,13 @@ async fn new_slot_execution_outputs() { // start slot is after block slot assert!(result.is_err()); - // TODO add test when filter is updated - - filter = massa_proto_rs::massa::api::v1::NewSlotExecutionOutputsFilter { + filter = grpc_api::NewSlotExecutionOutputsFilter { filter: Some( - massa_proto_rs::massa::api::v1::new_slot_execution_outputs_filter::Filter::EventFilter( - massa_proto_rs::massa::api::v1::ExecutionEventFilter { + grpc_api::new_slot_execution_outputs_filter::Filter::EventFilter( + grpc_api::ExecutionEventFilter { filter: Some( - massa_proto_rs::massa::api::v1::execution_event_filter::Filter::OriginalOperationId( "O1q4CBcuYo8YANEV34W4JRWVHrzcYns19VJfyAB7jT4qfitAnMC" - .to_string() + grpc_api::execution_event_filter::Filter::OriginalOperationId( + "O1q4CBcuYo8YANEV34W4JRWVHrzcYns19VJfyAB7jT4qfitAnMC".to_string(), ), ), }, @@ -1236,9 +1179,123 @@ async fn new_slot_execution_outputs() { .unwrap(); let result = tokio::time::timeout(Duration::from_secs(2), resp_stream.next()).await; - dbg!(&result); assert!(result.is_err()); + // execution status filter + let mut filters = Vec::new(); + filter = grpc_api::NewSlotExecutionOutputsFilter { + filter: Some(grpc_api::new_slot_execution_outputs_filter::Filter::Status( + grpc_model::ExecutionOutputStatus::Final as i32, + )), + }; + filters.push(filter); + let mut filters = Vec::new(); + filter = grpc_api::NewSlotExecutionOutputsFilter { + filter: Some(grpc_api::new_slot_execution_outputs_filter::Filter::Status( + grpc_model::ExecutionOutputStatus::Candidate as i32, + )), + }; + filters.push(filter); + // event filter + filter = grpc_api::NewSlotExecutionOutputsFilter { + filter: Some( + grpc_api::new_slot_execution_outputs_filter::Filter::EventFilter( + grpc_api::ExecutionEventFilter { + filter: Some(grpc_api::execution_event_filter::Filter::None( + grpc_model::Empty {}, + )), + }, + ), + ), + }; + filters.push(filter); + // async pool changes filter + filter = grpc_api::NewSlotExecutionOutputsFilter { + filter: Some( + grpc_api::new_slot_execution_outputs_filter::Filter::AsyncPoolChangesFilter( + grpc_api::AsyncPoolChangesFilter { + filter: Some(grpc_api::async_pool_changes_filter::Filter::None( + grpc_model::Empty {}, + )), + }, + ), + ), + }; + filters.push(filter); + + // executed denunciations changes filter + filter = grpc_api::NewSlotExecutionOutputsFilter { + filter: Some( + grpc_api::new_slot_execution_outputs_filter::Filter::ExecutedDenounciationFilter( + grpc_api::ExecutedDenounciationFilter { + filter: Some(grpc_api::executed_denounciation_filter::Filter::None( + grpc_model::Empty {}, + )), + }, + ), + ), + }; + filters.push(filter); + let (op_id, (_, _)) = executed_ops_changes.iter().next().unwrap(); + // executed operations changes filter + filter = grpc_api::NewSlotExecutionOutputsFilter { + filter: Some( + grpc_api::new_slot_execution_outputs_filter::Filter::ExecutedOpsChangesFilter( + grpc_api::ExecutedOpsChangesFilter { + filter: Some(grpc_api::executed_ops_changes_filter::Filter::OperationId( + op_id.to_string(), + )), + }, + ), + ), + }; + filters.push(filter); + + // ledger changes filter + filter = grpc_api::NewSlotExecutionOutputsFilter { + filter: Some( + grpc_api::new_slot_execution_outputs_filter::Filter::LedgerChangesFilter( + grpc_api::LedgerChangesFilter { + filter: Some(grpc_api::ledger_changes_filter::Filter::None( + grpc_model::Empty {}, + )), + }, + ), + ), + }; + filters.push(filter); + + tx_request + .send(NewSlotExecutionOutputsRequest { filters }) + .await + .unwrap(); + tokio::time::sleep(Duration::from_millis(50)).await; + + slot_tx + .send(SlotExecutionOutput::ExecutedSlot(exec_output_1.clone())) + .unwrap(); + + let result = tokio::time::timeout(Duration::from_secs(5), resp_stream.next()) + .await + .unwrap() + .unwrap() + .unwrap(); + + // complexe filter result + assert!(result.output.is_some()); + assert!(result.output.clone().unwrap().execution_output.is_some()); + let state_changes = result + .output + .unwrap() + .execution_output + .unwrap() + .state_changes + .unwrap(); + assert!(state_changes.async_pool_changes.is_empty()); + assert!(state_changes.executed_ops_changes.len() == 1); + assert!(state_changes.executed_denunciations_changes.is_empty()); + assert!(state_changes.ledger_changes.is_empty()); + stop_handle.stop(); } @@ -1304,10 +1361,10 @@ async fn send_operations() { .unwrap(); match result.result.unwrap() { - massa_proto_rs::massa::api::v1::send_operations_response::Result::OperationIds(_) => { + grpc_api::send_operations_response::Result::OperationIds(_) => { panic!("should be error"); } - massa_proto_rs::massa::api::v1::send_operations_response::Result::Error(err) => { + grpc_api::send_operations_response::Result::Error(err) => { assert!(err.message.contains("invalid operation")); } } @@ -1330,7 +1387,7 @@ async fn send_operations() { .unwrap(); match result.result.unwrap() { - massa_proto_rs::massa::api::v1::send_operations_response::Result::Error(err) => { + grpc_api::send_operations_response::Result::Error(err) => { assert!(err .message .contains("Operation expire_period is lower than the current period of this node")); @@ -1361,11 +1418,11 @@ async fn send_operations() { .unwrap(); match result { - massa_proto_rs::massa::api::v1::send_operations_response::Result::OperationIds(ope_id) => { + grpc_api::send_operations_response::Result::OperationIds(ope_id) => { assert_eq!(ope_id.operation_ids.len(), 1); assert_eq!(ope_id.operation_ids[0], op2.id.to_string()); } - massa_proto_rs::massa::api::v1::send_operations_response::Result::Error(_) => { + grpc_api::send_operations_response::Result::Error(_) => { panic!("should be ok") } } @@ -1383,7 +1440,7 @@ async fn send_operations() { .unwrap(); match result.result.unwrap() { - massa_proto_rs::massa::api::v1::send_operations_response::Result::Error(err) => { + grpc_api::send_operations_response::Result::Error(err) => { assert_eq!(err.message, "too many operations per message"); } _ => { @@ -1474,7 +1531,7 @@ async fn send_endorsements() { .unwrap(); match result.result.unwrap() { - massa_proto_rs::massa::api::v1::send_endorsements_response::Result::Error(err) => { + grpc_api::send_endorsements_response::Result::Error(err) => { assert!(err.message.contains("failed to deserialize endorsement")) } _ => panic!("should be error"), @@ -1538,7 +1595,7 @@ async fn send_blocks() { // .unwrap(); // match result.result.unwrap() { - // massa_proto_rs::massa::api::v1::send_blocks_response::Result::Error(err) => { + // grpc_api::send_blocks_response::Result::Error(err) => { // assert!(err.message.contains("not available")) // } // _ => panic!("should be error"),