Skip to content

Commit

Permalink
Merge pull request #966 from carver/test-json-with-shanghai
Browse files Browse the repository at this point in the history
test: post-shanghai block for eth_getBlockByHash
  • Loading branch information
carver authored Oct 11, 2023
2 parents 6ab314a + 474cf7f commit 91e3db7
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ utp-rs = "0.1.0-alpha.8"
ethers-core = { version = "2.0", default-features = false}
ethers-providers = { version = "2.0", default-features = false, features = ["ipc"] }
ethportal-peertest = { path = "ethportal-peertest" }
serde_yaml = "0.9.25"
serial_test = "0.5.1"
ureq = { version = "2.5.0", features = ["json"] }

Expand Down
22 changes: 13 additions & 9 deletions tests/rpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::net::{IpAddr, Ipv4Addr};
use ethers_core::types::{Bloom, U256};
use ethers_providers::*;
use jsonrpsee::async_client::Client;
use serde_json::Value;
use serde_yaml::Value;
use serial_test::serial;
use ssz::Decode;

Expand Down Expand Up @@ -156,12 +156,16 @@ async fn test_eth_get_block_by_hash() {
}

fn get_header_with_proof() -> HeaderWithProof {
let file =
fs::read_to_string("trin-validation/src/assets/fluffy/header_with_proofs.json").unwrap();
let json: Value = serde_json::from_str(&file).unwrap();
let json = json.as_object().unwrap();
let raw_header = json.get("1000001").unwrap().as_object().unwrap();
let raw_header = raw_header.get("value").unwrap().as_str().unwrap();
let hwp_ssz = hex_decode(raw_header).unwrap();
HeaderWithProof::from_ssz_bytes(&hwp_ssz).unwrap()
let file = fs::read_to_string("trin-validation/src/assets/hive/blocks.yaml").unwrap();
let value: Value = serde_yaml::from_str(&file).unwrap();
let all_blocks = value.as_sequence().unwrap();
let post_shanghai = all_blocks.last().unwrap();
// Why assert the block number? With the current yaml structure, appending a new block into the
// yaml file would cause this function to return a different block. This assertion catches the
// problem early.
assert_eq!(post_shanghai["number"], 17510000);
let header_pair = post_shanghai.get("header").unwrap().as_mapping().unwrap();
let hex_encoded_header = header_pair.get("content_value").unwrap().as_str().unwrap();
let ssz_encoded_header = hex_decode(hex_encoded_header).unwrap();
HeaderWithProof::from_ssz_bytes(&ssz_encoded_header).unwrap()
}
23 changes: 23 additions & 0 deletions trin-validation/src/assets/hive/blocks.yaml

Large diffs are not rendered by default.

0 comments on commit 91e3db7

Please # to comment.