mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-09 07:17:56 -05:00
feat: test engine RPC with example payload
This commit is contained in:
69
crates/rpc/rpc-builder/tests/it/engine.rs
Normal file
69
crates/rpc/rpc-builder/tests/it/engine.rs
Normal file
@@ -0,0 +1,69 @@
|
||||
///! Engine API tests
|
||||
use crate::utils::launch_auth_with_chainspec;
|
||||
use jsonrpsee::core::client::ClientT;
|
||||
use reth_primitives::{Hardfork, MAINNET, U64};
|
||||
use reth_rpc::JwtSecret;
|
||||
use reth_rpc_types::engine::{
|
||||
ExecutionPayloadInputV2, PayloadStatus,
|
||||
};
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn test_v1_to_v2_transition() {
|
||||
reth_tracing::init_test_tracing();
|
||||
let secret = JwtSecret::random();
|
||||
let chainspec = MAINNET.clone();
|
||||
|
||||
// TODO: add configure test consensus engine that does nothing - we are just testing validity
|
||||
// of transition fields and ser/deser
|
||||
let handle = launch_auth_with_chainspec(secret, MAINNET.clone()).await;
|
||||
let client = handle.http_client();
|
||||
|
||||
// get the shanghai fork time
|
||||
let shanghai_fork_time = chainspec
|
||||
.fork(Hardfork::Shanghai)
|
||||
.as_timestamp()
|
||||
.expect("shanghai is configured as a timestamp fork");
|
||||
|
||||
// send a block after the shanghai fork, with withdrawals
|
||||
|
||||
let request = r#"
|
||||
{
|
||||
"baseFeePerGas": "0x173b30b3",
|
||||
"blockHash": "0x99d486755fd046ad0bbb60457bac93d4856aa42fa00629cc7e4a28b65b5f8164",
|
||||
"blockNumber": "0xb",
|
||||
"extraData": "0xd883010d01846765746888676f312e32302e33856c696e7578",
|
||||
"feeRecipient": "0x0000000000000000000000000000000000000000",
|
||||
"gasLimit": "0x405829",
|
||||
"gasUsed": "0x3f0ca0",
|
||||
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||
"parentHash": "0xfe34aaa2b869c66a727783ee5ad3e3983b6ef22baf24a1e502add94e7bcac67a",
|
||||
"prevRandao": "0x74132c32fe3ab9a470a8352544514d21b6969e7749f97742b53c18a1b22b396c",
|
||||
"receiptsRoot": "0x6a5c41dc55a1bd3e74e7f6accc799efb08b00c36c15265058433fcea6323e95f",
|
||||
"stateRoot": "0xde3b357f5f099e4c33d0343c9e9d204d663d7bd9c65020a38e5d0b2a9ace78a2",
|
||||
"timestamp": "0x6507d6b4",
|
||||
"transactions": [
|
||||
"0xf86d0a8458b20efd825208946177843db3138ae69679a54b95cf345ed759450d8806f3e8d87878800080820a95a0f8bddb1dcc4558b532ff747760a6f547dd275afdbe7bdecc90680e71de105757a014f34ba38c180913c0543b0ac2eccfb77cc3f801a535008dc50e533fbe435f53",
|
||||
"0xf86d0b8458b20efd82520894687704db07e902e9a8b3754031d168d46e3d586e8806f3e8d87878800080820a95a0e3108f710902be662d5c978af16109961ffaf2ac4f88522407d40949a9574276a0205719ed21889b42ab5c1026d40b759a507c12d92db0d100fa69e1ac79137caa",
|
||||
"0xf86d0c8458b20efd8252089415e6a5a2e131dd5467fa1ff3acd104f45ee5940b8806f3e8d87878800080820a96a0af556ba9cda1d686239e08c24e169dece7afa7b85e0948eaa8d457c0561277fca029da03d3af0978322e54ac7e8e654da23934e0dd839804cb0430f8aaafd732dc",
|
||||
"0xf8521784565adcb7830186a0808080820a96a0ec782872a673a9fe4eff028a5bdb30d6b8b7711f58a187bf55d3aec9757cb18ea001796d373da76f2b0aeda72183cce0ad070a4f03aa3e6fee4c757a9444245206",
|
||||
"0xf8521284565adcb7830186a0808080820a95a08a0ea89028eff02596b385a10e0bd6ae098f3b281be2c95a9feb1685065d7384a06239d48a72e4be767bd12f317dd54202f5623a33e71e25a87cb25dd781aa2fc8",
|
||||
"0xf8521384565adcb7830186a0808080820a95a0784dbd311a82f822184a46f1677a428cbe3a2b88a798fb8ad1370cdbc06429e8a07a7f6a0efd428e3d822d1de9a050b8a883938b632185c254944dd3e40180eb79"
|
||||
],
|
||||
"withdrawals": []
|
||||
}
|
||||
"#;
|
||||
|
||||
// TODO: this isn't necessary for this test since we aren't testing the argument deser
|
||||
// we could do something similar to check the output serialize with an expected output
|
||||
// let mut raw_payload: Value = serde_json::from_str(request).unwrap();
|
||||
|
||||
let mut payload: ExecutionPayloadInputV2 = serde_json::from_str(request).unwrap();
|
||||
payload.execution_payload.timestamp = U64::from(shanghai_fork_time - 1);
|
||||
let response = client
|
||||
.request::<PayloadStatus, &[ExecutionPayloadInputV2]>("engine_newPayloadV1", &[payload])
|
||||
.await;
|
||||
|
||||
// TODO: this should fail due to an error - arg should not be able to deser due to presence of
|
||||
// withdrawals
|
||||
response.unwrap();
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
mod auth;
|
||||
mod engine;
|
||||
mod http;
|
||||
mod serde;
|
||||
mod startup;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use reth_beacon_consensus::BeaconConsensusEngineHandle;
|
||||
use reth_network_api::noop::NoopNetwork;
|
||||
use reth_payload_builder::test_utils::spawn_test_payload_service;
|
||||
use reth_primitives::MAINNET;
|
||||
use reth_primitives::{ChainSpec, MAINNET};
|
||||
use reth_provider::test_utils::{NoopProvider, TestCanonStateSubscriptions};
|
||||
use reth_rpc::JwtSecret;
|
||||
use reth_rpc_builder::{
|
||||
@@ -12,7 +12,10 @@ use reth_rpc_builder::{
|
||||
use reth_rpc_engine_api::EngineApi;
|
||||
use reth_tasks::TokioTaskExecutor;
|
||||
use reth_transaction_pool::test_utils::{testing_pool, TestPool};
|
||||
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4};
|
||||
use std::{
|
||||
net::{Ipv4Addr, SocketAddr, SocketAddrV4},
|
||||
sync::Arc,
|
||||
};
|
||||
use tokio::sync::mpsc::unbounded_channel;
|
||||
|
||||
/// Localhost with port 0 so a free port is used.
|
||||
@@ -20,14 +23,19 @@ pub fn test_address() -> SocketAddr {
|
||||
SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, 0))
|
||||
}
|
||||
|
||||
/// Launches a new server for the auth module
|
||||
pub async fn launch_auth(secret: JwtSecret) -> AuthServerHandle {
|
||||
/// Launches a new server for the auth module, using the given [ChainSpec] to configure the
|
||||
/// [EngineApi]. This still uses the default [BeaconConsensusEngineHandle] and test payload
|
||||
/// service.
|
||||
pub async fn launch_auth_with_chainspec(
|
||||
secret: JwtSecret,
|
||||
chain_spec: Arc<ChainSpec>,
|
||||
) -> AuthServerHandle {
|
||||
let config = AuthServerConfig::builder(secret).socket_addr(test_address()).build();
|
||||
let (tx, _rx) = unbounded_channel();
|
||||
let beacon_engine_handle = BeaconConsensusEngineHandle::new(tx);
|
||||
let engine_api = EngineApi::new(
|
||||
NoopProvider::default(),
|
||||
MAINNET.clone(),
|
||||
chain_spec,
|
||||
beacon_engine_handle,
|
||||
spawn_test_payload_service().into(),
|
||||
Box::<TokioTaskExecutor>::default(),
|
||||
@@ -36,6 +44,11 @@ pub async fn launch_auth(secret: JwtSecret) -> AuthServerHandle {
|
||||
module.start_server(config).await.unwrap()
|
||||
}
|
||||
|
||||
/// Launches a new server for the auth module
|
||||
pub async fn launch_auth(secret: JwtSecret) -> AuthServerHandle {
|
||||
launch_auth_with_chainspec(secret, MAINNET.clone()).await
|
||||
}
|
||||
|
||||
/// Launches a new server with http only with the given modules
|
||||
pub async fn launch_http(modules: impl Into<RpcModuleSelection>) -> RpcServerHandle {
|
||||
let builder = test_rpc_builder();
|
||||
|
||||
Reference in New Issue
Block a user