Skip to content

Commit

Permalink
fixup! Mock ledger services in integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sug0 committed Oct 12, 2023
1 parent f57fc93 commit 481fc72
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions apps/src/lib/node/ledger/shell/testing/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ pub struct MockServices {
/// Actions to be performed by the mock node, as a result
/// of driving [`MockServices`].
pub enum MockServiceAction {
/// The ledger should broadcast a new transaction.
BroadcastTx(Vec<u8>),
/// The ledger should broadcast new transactions.
BroadcastTxs(Vec<Vec<u8>>),
/// Progress to the next Ethereum block to process.
IncrementEthHeight,
}
Expand All @@ -181,14 +181,23 @@ impl MockServices {
}

// receive txs from the broadcaster
let mut tx_receiver = self.tx_receiver.lock().await;
while let Some(tx) = poll_fn(|cx| match tx_receiver.poll_recv(cx) {
Poll::Pending => Poll::Ready(None),
poll => poll,
})
.await
{
actions.push(MockServiceAction::BroadcastTx(tx));
let txs = {
let mut txs = vec![];
let mut tx_receiver = self.tx_receiver.lock().await;

while let Some(tx) = poll_fn(|cx| match tx_receiver.poll_recv(cx) {
Poll::Pending => Poll::Ready(None),
poll => poll,
})
.await
{
txs.push(tx);
}

txs
};
if !txs.is_empty() {
actions.push(MockServiceAction::BroadcastTxs(txs));
}

actions
Expand Down Expand Up @@ -262,8 +271,8 @@ impl Drop for MockNode {
impl MockNode {
pub async fn handle_service_action(&self, action: MockServiceAction) {
match action {
MockServiceAction::BroadcastTx(tx) => {
_ = self.broadcast_tx_sync_impl(tx.into());
MockServiceAction::BroadcastTxs(txs) => {
self.submit_txs(txs);
}
MockServiceAction::IncrementEthHeight => {
*self
Expand Down

0 comments on commit 481fc72

Please sign in to comment.