Skip to content

Commit

Permalink
fix: add feature for alloy-provider, fix test_util (#738)
Browse files Browse the repository at this point in the history
  • Loading branch information
steph-rs authored Oct 28, 2024
1 parent 938805a commit e230e20
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion crates/mpt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ alloy-primitives = { workspace = true, features = ["rlp"] }

[dev-dependencies]
# Alloy
alloy-provider.workspace = true
alloy-provider = { workspace = true, features = ["reqwest"] }
alloy-consensus.workspace = true
alloy-transport-http.workspace = true
alloy-rpc-types = { workspace = true, features = ["eth"] }
Expand Down
23 changes: 13 additions & 10 deletions crates/mpt/src/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ pub(crate) async fn get_live_derivable_receipts_list(
let block = provider
.get_block(block_number.into(), BlockTransactionsKind::Full)
.await
.map_err(|e| anyhow!(e))?
.ok_or(anyhow!("Missing block"))?;
.map_err(anyhow::Error::from)?
.ok_or_else(|| anyhow!("Missing block"))?;
let receipts = provider
.get_block_receipts(block_number.into())
.await
.map_err(|e| anyhow!(e))?
.ok_or(anyhow!("Missing receipts"))?;
.map_err(anyhow::Error::from)?
.ok_or_else(|| anyhow!("Missing receipts"))?;

let consensus_receipts = receipts
.into_iter()
Expand Down Expand Up @@ -59,7 +59,9 @@ pub(crate) async fn get_live_derivable_receipts_list(

// Compute the derivable list
let mut list =
ordered_trie_with_encoder(consensus_receipts.as_ref(), |rlp, buf| rlp.encode_2718(buf));
ordered_trie_with_encoder(consensus_receipts.as_ref(), |rlp: &ReceiptEnvelope, buf| {
rlp.encode_2718(buf)
});
let root = list.root();

// Sanity check receipts root is correct
Expand Down Expand Up @@ -87,20 +89,21 @@ pub(crate) async fn get_live_derivable_transactions_list(
let block = provider
.get_block(block_number.into(), BlockTransactionsKind::Full)
.await
.map_err(|e| anyhow!(e))?
.ok_or(anyhow!("Missing block"))?;
.map_err(anyhow::Error::from)?
.ok_or_else(|| anyhow!("Missing block"))?;

let BlockTransactions::Full(txs) = block.transactions else {
anyhow::bail!("Did not fetch full block");
};
let consensus_txs = txs
.into_iter()
.map(|tx| TxEnvelope::try_from(tx).map_err(|e| anyhow!(e)))
.map(|tx| TxEnvelope::try_from(tx).map_err(anyhow::Error::from))
.collect::<Result<Vec<_>>>()?;

// Compute the derivable list
let mut list =
ordered_trie_with_encoder(consensus_txs.as_ref(), |rlp, buf| rlp.encode_2718(buf));
let mut list = ordered_trie_with_encoder(consensus_txs.as_ref(), |rlp: &TxEnvelope, buf| {
rlp.encode_2718(buf)
});
let root = list.root();

// Sanity check transaction root is correct
Expand Down

0 comments on commit e230e20

Please sign in to comment.