mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
53 lines
2.2 KiB
Rust
53 lines
2.2 KiB
Rust
//! Decoding tests for [`PooledTransactions`]
|
|
use alloy_rlp::{Decodable, Encodable};
|
|
use reth_eth_wire::{EthVersion, PooledTransactions, ProtocolMessage};
|
|
use reth_primitives::{hex, Bytes, PooledTransactionsElement};
|
|
use std::{fs, path::PathBuf};
|
|
|
|
#[test]
|
|
fn decode_pooled_transactions_data() {
|
|
let network_data_path =
|
|
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("testdata/pooled_transactions_with_blob");
|
|
let data = fs::read_to_string(network_data_path).expect("Unable to read file");
|
|
let hex_data = hex::decode(data.trim()).unwrap();
|
|
let txs = PooledTransactions::decode(&mut &hex_data[..]).unwrap();
|
|
|
|
// do a roundtrip test
|
|
let mut buf = Vec::new();
|
|
txs.encode(&mut buf);
|
|
if hex_data != buf {
|
|
panic!("mixed pooled transaction roundtrip failed");
|
|
}
|
|
|
|
// now do another decoding, on what we encoded - this should succeed
|
|
let _txs2 = PooledTransactions::decode(&mut &buf[..]).unwrap();
|
|
}
|
|
|
|
#[test]
|
|
fn decode_request_pair_pooled_blob_transactions() {
|
|
let network_data_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
|
.join("testdata/request_pair_pooled_blob_transactions");
|
|
let data = fs::read_to_string(network_data_path).expect("Unable to read file");
|
|
let hex_data = hex::decode(data.trim()).unwrap();
|
|
let _txs = ProtocolMessage::decode_message(EthVersion::Eth68, &mut &hex_data[..]).unwrap();
|
|
}
|
|
|
|
#[test]
|
|
fn decode_blob_transaction_data() {
|
|
let network_data_path =
|
|
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("testdata/blob_transaction");
|
|
let data = fs::read_to_string(network_data_path).expect("Unable to read file");
|
|
let hex_data = hex::decode(data.trim()).unwrap();
|
|
let _txs = PooledTransactionsElement::decode(&mut &hex_data[..]).unwrap();
|
|
}
|
|
|
|
#[test]
|
|
fn decode_blob_rpc_transaction() {
|
|
// test data pulled from hive test that sends blob transactions
|
|
let network_data_path =
|
|
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("testdata/rpc_blob_transaction");
|
|
let data = fs::read_to_string(network_data_path).expect("Unable to read file");
|
|
let hex_data = Bytes::from(hex::decode(data.trim()).unwrap());
|
|
let _txs = PooledTransactionsElement::decode_enveloped(hex_data).unwrap();
|
|
}
|