Skip to content

Commit

Permalink
refactor: start generating test data
Browse files Browse the repository at this point in the history
  • Loading branch information
aoudiamoncef committed Oct 12, 2023
1 parent 1a141ff commit 736e5f5
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions massa-grpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ tower-http = { workspace = true, "features" = ["cors"] }
tracing = { workspace = true }

[dev-dependencies]
massa_async_pool = { workspace = true }
massa_bootstrap = { workspace = true , "features" = ["testing"]}
massa_channel = { workspace = true }
massa_consensus_exports = { workspace = true, "features" = ["testing"] }
massa_executed_ops = { workspace = true }
massa_final_state = { workspace = true }
mockall = { workspace = true }
num = { workspace = true }
Expand Down
55 changes: 52 additions & 3 deletions massa-grpc/src/tests/stream.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
// Copyright (c) 2023 MASSA LABS <[email protected]>

use crate::tests::mock::{grpc_public_service, MockExecutionCtrl, MockPoolCtrl};
use massa_async_pool::{AsyncMessage, AsyncPoolChanges};
use massa_consensus_exports::test_exports::MockConsensusControllerImpl;
use massa_executed_ops::ExecutedDenunciationsChanges;
use massa_execution_exports::{ExecutionOutput, SlotExecutionOutput};
use massa_final_state::StateChanges;
use massa_ledger_exports::SetUpdateOrDelete;
use massa_models::{
address::Address, block::FilledBlock, secure_share::SecureShareSerializer, slot::Slot,
address::Address,
amount::Amount,
block::FilledBlock,
denunciation::{Denunciation, DenunciationIndex},
secure_share::SecureShareSerializer,
slot::Slot,
stats::ExecutionStats,
test_exports::{gen_block_headers_for_denunciation, gen_endorsements_for_denunciation},
};
use massa_proto_rs::massa::{
api::v1::{
Expand All @@ -25,7 +35,7 @@ use massa_protocol_exports::{
use massa_serialization::Serializer;
use massa_signature::KeyPair;
use massa_time::MassaTime;
use std::{net::SocketAddr, ops::Add, time::Duration};
use std::{collections::HashSet, net::SocketAddr, ops::Add, str::FromStr, time::Duration};
use tokio_stream::StreamExt;

#[tokio::test]
Expand Down Expand Up @@ -1061,10 +1071,49 @@ async fn new_slot_execution_outputs() {

let stop_handle = public_server.serve(&config).await.unwrap();

// Given
let mut state_changes = StateChanges::default();

// Create async pool changes
let message = AsyncMessage::new(
Slot::new(1, 0),
0,
Address::from_str("AU12dG5xP1RDEB5ocdHkymNVvvSJmUL9BgHwCksDowqmGWxfpm93x").unwrap(),
Address::from_str("AU12htxRWiEm8jDJpJptr6cwEhWNcCSFWstN1MLSa96DDkVM9Y42G").unwrap(),
String::from("test"),
10000000,
Amount::from_str("1").unwrap(),
Amount::from_str("1").unwrap(),
Slot::new(2, 0),
Slot::new(3, 0),
vec![1, 2, 3, 4],
None,
None,
);
let mut async_pool_changes = AsyncPoolChanges::default();
async_pool_changes
.0
.insert(message.compute_id(), SetUpdateOrDelete::Set(message));
state_changes.async_pool_changes = async_pool_changes;

// Create executed denunciations changes
let (_, _, s_block_header_1, s_block_header_2, _) =
gen_block_headers_for_denunciation(None, None);
let denunciation_1: Denunciation = (&s_block_header_1, &s_block_header_2).try_into().unwrap();
let denunciation_index_1 = DenunciationIndex::from(&denunciation_1);

let (_, _, s_endorsement_1, s_endorsement_2, _) = gen_endorsements_for_denunciation(None, None);
let denunciation_2 = Denunciation::try_from((&s_endorsement_1, &s_endorsement_2)).unwrap();
let denunciation_index_2 = DenunciationIndex::from(&denunciation_2);

let p_de_changes: ExecutedDenunciationsChanges =
HashSet::from([(denunciation_index_1), (denunciation_index_2)]);
state_changes.executed_denunciations_changes = p_de_changes;

let exec_output_1 = ExecutionOutput {
slot: Slot::new(1, 5),
block_info: None,
state_changes: massa_final_state::StateChanges::default(),
state_changes,
events: Default::default(),
};

Expand Down

0 comments on commit 736e5f5

Please sign in to comment.