Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 57 additions & 18 deletions crates/astria-sequencer/src/app/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,26 +257,65 @@ pub(crate) async fn initialize_app(
reason = "allow is only necessary when benchmark isn't enabled"
)]
#[cfg_attr(feature = "benchmark", allow(dead_code))]
pub(crate) fn mock_tx(
pub(crate) struct MockTxBuilder {
nonce: u32,
signer: &SigningKey,
rollup_name: &str,
) -> Arc<SignedTransaction> {
let tx = UnsignedTransaction::builder()
.actions(vec![
SequenceAction {
rollup_id: RollupId::from_unhashed_bytes(rollup_name.as_bytes()),
data: Bytes::from_static(&[0x99]),
fee_asset: denom_0(),
}
.into(),
])
.chain_id("test")
.nonce(nonce)
.try_build()
.unwrap();
signer: SigningKey,
chain_id: String,
}

#[expect(
clippy::allow_attributes,
clippy::allow_attributes_without_reason,
reason = "allow is only necessary when benchmark isn't enabled"
)]
#[cfg_attr(feature = "benchmark", allow(dead_code))]
impl MockTxBuilder {
pub(crate) fn new() -> Self {
Self {
chain_id: "test".to_string(),
nonce: 0,
signer: get_alice_signing_key(),
}
}

Arc::new(tx.into_signed(signer))
pub(crate) fn nonce(self, nonce: u32) -> Self {
Self {
nonce,
..self
}
}

pub(crate) fn signer(self, signer: SigningKey) -> Self {
Self {
signer,
..self
}
}

pub(crate) fn chain_id(self, chain_id: &str) -> Self {
Self {
chain_id: chain_id.to_string(),
..self
}
}

pub(crate) fn build(self) -> Arc<SignedTransaction> {
let tx = UnsignedTransaction::builder()
.actions(vec![
SequenceAction {
rollup_id: RollupId::from_unhashed_bytes("rollup-id"),
data: Bytes::from_static(&[0x99]),
fee_asset: denom_0(),
}
.into(),
])
.chain_id(self.chain_id)
.nonce(self.nonce)
.try_build()
.unwrap();

Arc::new(tx.into_signed(&self.signer))
}
}

pub(crate) const MOCK_SEQUENCE_FEE: u128 = 10;
Expand Down
13 changes: 10 additions & 3 deletions crates/astria-sequencer/src/grpc/sequencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,20 @@ mod tests {
let alice_address = astria_address(&alice.address_bytes());
// insert a transaction with a nonce gap
let gapped_nonce = 99;
let tx = crate::app::test_utils::mock_tx(gapped_nonce, &get_alice_signing_key(), "test");
let tx = crate::app::test_utils::MockTxBuilder::new()
.nonce(gapped_nonce)
.build();
mempool
.insert(tx, 0, mock_balances(0, 0), mock_tx_cost(0, 0, 0))
.await
.unwrap();

// insert a transaction at the current nonce
let account_nonce = 0;
let tx = crate::app::test_utils::mock_tx(account_nonce, &get_alice_signing_key(), "test");
let tx = crate::app::test_utils::MockTxBuilder::new()
.nonce(account_nonce)
.build();

mempool
.insert(tx, 0, mock_balances(0, 0), mock_tx_cost(0, 0, 0))
.await
Expand All @@ -287,7 +292,9 @@ mod tests {
// insert a transactions one above account nonce (not gapped)
let sequential_nonce = 1;
let tx: Arc<astria_core::protocol::transaction::v1alpha1::SignedTransaction> =
crate::app::test_utils::mock_tx(sequential_nonce, &get_alice_signing_key(), "test");
crate::app::test_utils::MockTxBuilder::new()
.nonce(sequential_nonce)
.build();
mempool
.insert(tx, 0, mock_balances(0, 0), mock_tx_cost(0, 0, 0))
.await
Expand Down
Loading