Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
clabby committed Apr 23, 2024
1 parent c90f868 commit 3f01fc7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions 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/mpt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ alloy-consensus = { git = "https://github.com/alloy-rs/alloy", version = "0.1.0"
alloy-transport-http = { git = "https://github.com/alloy-rs/alloy", version = "0.1.0" }
reqwest = "0.12"
tracing-subscriber = "0.3.18"
futures = { version = "0.3.30", default-features = false }
36 changes: 35 additions & 1 deletion crates/mpt/src/retrieval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,13 @@ pub fn retrieve(
#[cfg(test)]
mod test {
use alloc::{collections::BTreeMap, vec::Vec};
use alloy_primitives::{keccak256, Bytes, B256};
use alloy_primitives::{b256, keccak256, Bytes, B256};
use alloy_provider::{Provider, ProviderBuilder};
use alloy_rlp::{Decodable, Encodable, EMPTY_STRING_CODE};
use alloy_trie::Nibbles;
use anyhow::{anyhow, Result};
use reqwest::Url;
use tokio::runtime::Runtime;

use crate::{retrieve, test_util::ordered_trie_with_encoder, TrieNode};

Expand Down Expand Up @@ -135,4 +138,35 @@ mod test {
assert_eq!(v, encoded_value);
}
}

fn test_online_retrieval() {
extern crate std;
use std::dbg;

const RPC_URL: &str = "https://mainnet-replica-0-op-geth.primary.client.dev.oplabs.cloud";

// Initialize the provider.
let provider = ProviderBuilder::new()
.on_http(Url::parse(RPC_URL).expect("invalid rpc url"))
.map_err(|e| anyhow!(e))
.unwrap();

let block_number = 19005266;
let block = futures::executor::block_on(async { provider.get_block(block_number.into(), true) }).await.unwrap().unwrap();

let root = block.header.state_root;
let fetch = |hash: B256| -> Result<Bytes> {
let preimage = futures::executor::block_on(async {
provider
.client()
.request::<&[B256; 1], Bytes>("debug_dbGet", &[hash])
.await
.unwrap()
});
Ok(preimage)
};

dbg!(fetch(b256!("7cb368272bf53782d801c81c5a326202d21a5a5c6cbf292c7223838301acfbf3"))
.unwrap());
}
}

0 comments on commit 3f01fc7

Please sign in to comment.