From ee351fc493cf183b56831ca492351554ffed3ec3 Mon Sep 17 00:00:00 2001 From: DoTheBestToGetTheBest <146037313+DoTheBestToGetTheBest@users.noreply.github.com> Date: Fri, 10 Nov 2023 03:45:50 -0800 Subject: [PATCH] feat(transaction-pool) : impl MockTransaction for Desposit variant (#5321) Co-authored-by: Matthias Seitz --- .../transaction-pool/src/test_utils/mock.rs | 84 ++++++++++++++----- 1 file changed, 65 insertions(+), 19 deletions(-) diff --git a/crates/transaction-pool/src/test_utils/mock.rs b/crates/transaction-pool/src/test_utils/mock.rs index d3cb4de214..a59f173ad6 100644 --- a/crates/transaction-pool/src/test_utils/mock.rs +++ b/crates/transaction-pool/src/test_utils/mock.rs @@ -36,6 +36,40 @@ pub fn mock_tx_pool() -> MockTxPool { MockTxPool::new(Default::default(), Default::default()) } +macro_rules! op_set_value { + ($this:ident, sender, $value:ident) => { + $this.from = $value; + }; + ($this:ident, gas_limit, $value:ident) => { + $this.gas_limit = $value; + }; + ($this:ident, value, $value:ident) => { + $this.value = $value.into(); + }; + ($this:ident, input, $value:ident) => { + $this.value = $value; + }; + ($this:ident, $other:ident, $field:ident) => {}; +} + +macro_rules! op_get_value { + ($this:ident, sender) => { + $this.from + }; + ($this:ident, gas_limit) => { + $this.gas_limit + }; + ($this:ident, value) => { + $this.value.into() + }; + ($this:ident, input) => { + $this.input.clone() + }; + ($this:ident, $other:ident) => { + Default::default() + }; +} + /// Sets the value for the field macro_rules! set_value { ($this:ident => $field:ident) => { @@ -54,8 +88,8 @@ macro_rules! set_value { *$field = new_value; } #[cfg(feature = "optimism")] - MockTransaction::Deposit(_) => { - panic!("not implemented") + MockTransaction::Deposit(ref mut tx) => { + op_set_value!(tx, $this, new_value); } } }; @@ -63,15 +97,15 @@ macro_rules! set_value { /// Gets the value for the field macro_rules! get_value { - ($this:ident => $field:ident) => { + ($this:tt => $field:ident) => { match $this { - MockTransaction::Legacy { $field, .. } => $field, - MockTransaction::Eip1559 { $field, .. } => $field, - MockTransaction::Eip4844 { $field, .. } => $field, - MockTransaction::Eip2930 { $field, .. } => $field, + MockTransaction::Legacy { $field, .. } => $field.clone(), + MockTransaction::Eip1559 { $field, .. } => $field.clone(), + MockTransaction::Eip4844 { $field, .. } => $field.clone(), + MockTransaction::Eip2930 { $field, .. } => $field.clone(), #[cfg(feature = "optimism")] - MockTransaction::Deposit(_) => { - panic!("not implemented") + MockTransaction::Deposit(tx) => { + op_get_value!(tx, $field) } } }; @@ -92,7 +126,7 @@ macro_rules! make_setters_getters { } pub fn [](&self) -> $t { - get_value!(self => $name).clone() + get_value!(self => $name) } )*} }; @@ -308,9 +342,7 @@ impl MockTransaction { } MockTransaction::Eip2930 { gas_price, .. } => *gas_price = val, #[cfg(feature = "optimism")] - MockTransaction::Deposit(_) => { - panic!("not implemented") - } + MockTransaction::Deposit(_) => {} } self } @@ -340,9 +372,7 @@ impl MockTransaction { *gas_price = val; } #[cfg(feature = "optimism")] - MockTransaction::Deposit(_) => { - panic!("not implemented") - } + MockTransaction::Deposit(_) => {} } self } @@ -724,9 +754,25 @@ impl FromRecoveredTransaction for MockTransaction { accesslist: access_list, }, #[cfg(feature = "optimism")] - Transaction::Deposit { .. } => { - unimplemented!() - } + Transaction::Deposit(TxDeposit { + source_hash, + from, + to, + mint, + value, + gas_limit, + is_system_transaction, + input, + }) => MockTransaction::Deposit(TxDeposit { + source_hash, + from, + to, + mint, + value, + gas_limit, + is_system_transaction, + input, + }), } } }