Created
August 21, 2024 20:48
-
-
Save benhenryhunter/22253d85b2dcc063e01901379cf917f6 to your computer and use it in GitHub Desktop.
Rust serializing issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "serialize-gist" | |
version = "0.1.0" | |
edition = "2021" | |
[dependencies] | |
reqwest = { version = "0.12.5", features = ["json"] } | |
serde = { version = "1.0", features = ["derive"] } | |
serde_json = "1.0" | |
mev-rs = { git = "https://github.com/ralexstokes/mev-rs", tag = "v0.4.0-alpha.6" } | |
mockito = "1.5.0" | |
beacon-api-client = { git = "https://github.com/ralexstokes/ethereum-consensus"} | |
tokio = { version = "1.0", features = ["full"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use beacon_api_client::VersionedValue; | |
use mev_rs::types::{AuctionContents, SignedBuilderBid}; | |
use serde_json::json; | |
fn main() {} | |
async fn make_request(relay: String) -> Option<AuctionContents> { | |
println!("Getting payload from relay: {}", relay); | |
let relay = relay.clone(); | |
let url = format!("{}/eth/v1/builder/blinded_blocks", relay); | |
let client = reqwest::Client::new(); | |
let client = reqwest::Client::new(); | |
let res = client | |
.post(url.clone()) | |
.header("Content-Type", "application/json") | |
.body(json!({}).to_string()) | |
.send() | |
.await; | |
if res.is_err() { | |
println!("Failed to get payload from relay: {}", url); | |
return None; | |
} | |
let res = res.unwrap(); | |
if !res.status().is_success() { | |
println!("Failed to get payload from relay: {}", url); | |
} | |
let result: Result<VersionedValue<AuctionContents>, reqwest::Error> = | |
res.json::<VersionedValue<AuctionContents>>().await; | |
match result { | |
Ok(result) => Some(result.data), | |
Err(err) => { | |
println!("err: {:?}", err); | |
return None; | |
} | |
} | |
} | |
#[cfg(test)] | |
mod tests { | |
use super::*; | |
use mockito; | |
use serde_json::json; | |
#[tokio::test] | |
async fn test_make_request() { | |
let mut external_relay_server = mockito::Server::new_async().await; | |
let external_relay_mock = external_relay_server | |
.mock("POST", "/eth/v1/builder/blinded_blocks") | |
.with_status(200) | |
.with_header("Content-Type", "application/json") | |
.with_body( | |
json!({ | |
"version": "deneb", | |
"data": { | |
"execution_payload": { | |
"parent_hash": "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", | |
"fee_recipient": "0xabcf8e0d4e9587369b2301d0790347320302cc09", | |
"state_root": "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", | |
"receipts_root": "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", | |
"logs_bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", | |
"prev_randao": "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", | |
"block_number": "1", | |
"gas_limit": "1", | |
"gas_used": "1", | |
"timestamp": "1", | |
"extra_data": "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", | |
"base_fee_per_gas": "1", | |
"blob_gas_used": "1", | |
"excess_blob_gas": "1", | |
"block_hash": "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", | |
"transactions": [ | |
"0x02f878831469668303f51d843b9ac9f9843b9aca0082520894c93269b73096998db66be0441e836d873535cb9c8894a19041886f000080c001a031cc29234036afbf9a1fb9476b463367cb1f957ac0b919b69bbc798436e604aaa018c4e9c3914eb27aadd0b91e10b18655739fcf8c1fc398763a9f1beecb8ddc86" | |
], | |
"withdrawals": [ | |
{ | |
"index": "1", | |
"validator_index": "1", | |
"address": "0xabcf8e0d4e9587369b2301d0790347320302cc09", | |
"amount": "32000000000" | |
} | |
] | |
}, | |
"blobs_bundle": { | |
"commitments": [ | |
"0x8dab030c51e16e84be9caab84ee3d0b8bbec1db4a0e4de76439da8424d9b957370a10a78851f97e4b54d2ce1ab0d686f" | |
], | |
"proofs": [ | |
"0xb4021b0de10f743893d4f71e1bf830c019e832958efd6795baf2f83b8699a9eccc5dc99015d8d4d8ec370d0cc333c06a" | |
], | |
"blobs": [ | |
"0x24564723180fcb3d994104538d351c8dcbde12d541676bb736cf678018ca4739" | |
] | |
} | |
} | |
}) | |
.to_string(), | |
) | |
.create_async() | |
.await; | |
let auction_contents = make_request(external_relay_server.url()).await; | |
assert!(auction_contents.is_some()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment