Skip to content

Commit

Permalink
fix: fix CR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AlonLStarkWare committed Dec 2, 2024
1 parent c3b9d96 commit ece1dab
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions crates/starknet_mempool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ rstest.workspace = true
starknet_api = { workspace = true, features = ["testing"] }
# Enable test utils feature for integration tests.
starknet_mempool = { workspace = true, features = ["testing"] }
starknet_mempool_p2p_types = { workspace = true, features = ["testing"] }

[features]
testing = ["mempool_test_utils", "pretty_assertions", "starknet-types-core"]
Expand Down
58 changes: 58 additions & 0 deletions crates/starknet_mempool/src/mempool_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,3 +687,61 @@ fn test_update_gas_price_threshold_decreases_threshold() {
.build();
expected_mempool_content.assert_eq(&mempool);
}

#[rstest]
#[tokio::test]
async fn test_new_tx_sent_to_p2p(mempool: Mempool) {
// add_tx_input! creates an Invoke Transaction
let tx_args = add_tx_input!(tx_hash: 1, address: "0x0", tx_nonce: 2, account_nonce: 2);
let propagateor_args =
AddTransactionArgsWrapper { args: tx_args.clone(), p2p_message_metadata: None };
// TODO: use regular conversion once we have a compiler component
let rpc_tx = match tx_args.tx {
AccountTransaction::Declare(_declare_tx) => {
panic!("No implementation for converting DeclareTransaction to an RpcTransaction")
}
AccountTransaction::DeployAccount(deploy_account_transaction) => {
RpcTransaction::DeployAccount(RpcDeployAccountTransaction::V3(
deploy_account_transaction.clone().into(),
))
}
AccountTransaction::Invoke(invoke_transaction) => {
RpcTransaction::Invoke(RpcInvokeTransaction::V3(invoke_transaction.clone().into()))
}
};

let mut mock_mempool_p2p_propagator_client = MockMempoolP2pPropagatorClient::new();
mock_mempool_p2p_propagator_client
.expect_add_transaction()
.times(1)
.with(predicate::eq(rpc_tx))
.returning(|_| Ok(()));
let mut mempool_wrapper =
MempoolCommunicationWrapper::new(mempool, Arc::new(mock_mempool_p2p_propagator_client));

mempool_wrapper.add_tx(propagateor_args).await.unwrap();
}

#[rstest]
#[tokio::test]
async fn test_propagated_tx_sent_to_p2p(mempool: Mempool) {
// add_tx_input! creates an Invoke Transaction
let tx_args = add_tx_input!(tx_hash: 2, address: "0x0", tx_nonce: 3, account_nonce: 2);
let expected_message_metadata = BroadcastedMessageMetadata::get_test_instance(&mut get_rng());
let propagated_args = AddTransactionArgsWrapper {
args: tx_args.clone(),
p2p_message_metadata: Some(expected_message_metadata.clone()),
};

let mut mock_mempool_p2p_propagator_client = MockMempoolP2pPropagatorClient::new();
mock_mempool_p2p_propagator_client
.expect_continue_propagation()
.times(1)
.with(predicate::eq(expected_message_metadata.clone()))
.returning(|_| Ok(()));

let mut mempool_wrapper =
MempoolCommunicationWrapper::new(mempool, Arc::new(mock_mempool_p2p_propagator_client));

mempool_wrapper.add_tx(propagated_args).await.unwrap();
}
7 changes: 7 additions & 0 deletions crates/starknet_mempool_p2p_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@ workspace = true

[dependencies]
async-trait.workspace = true
mockall = { workspace = true, optional = true }
papyrus_network_types.workspace = true
papyrus_proc_macros.workspace = true
serde = { workspace = true, features = ["derive"] }
starknet_api.workspace = true
starknet_sequencer_infra.workspace = true
thiserror.workspace = true

[dev-dependencies]
mockall.workspace = true

[features]
testing = ["mockall"]
1 change: 1 addition & 0 deletions crates/starknet_mempool_p2p_types/src/communication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use thiserror::Error;
use crate::errors::MempoolP2pPropagatorError;
use crate::mempool_p2p_types::MempoolP2pPropagatorResult;

#[cfg_attr(any(feature = "testing", test), mockall::automock)]
#[async_trait]
pub trait MempoolP2pPropagatorClient: Send + Sync {
/// Adds a transaction to be propagated to other peers. This should only be called on a new
Expand Down

0 comments on commit ece1dab

Please sign in to comment.