mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-06 10:11:44 +00:00
1.1.5 merge spec tests (#2781)
* Fix arbitrary check kintsugi * Add merge chain spec fields, and a function to determine which constant to use based on the state variant * increment spec test version * Remove `Transaction` enum wrapper * Remove Transaction new-type * Remove gas validations * Add `--terminal-block-hash-epoch-override` flag * Increment spec tests version to 1.1.5 * Remove extraneous gossip verification https://github.com/ethereum/consensus-specs/pull/2687 * - Remove unused Error variants - Require both "terminal-block-hash-epoch-override" and "terminal-block-hash-override" when either flag is used * - Remove a couple more unused Error variants Co-authored-by: Paul Hauner <paul@paulhauner.com>
This commit is contained in:
@@ -308,7 +308,8 @@ pub struct JsonExecutionPayload<T: EthSpec> {
|
||||
pub base_fee_per_gas: Uint256,
|
||||
pub block_hash: Hash256,
|
||||
#[serde(with = "serde_transactions")]
|
||||
pub transactions: VariableList<Transaction<T>, T::MaxTransactionsPerPayload>,
|
||||
pub transactions:
|
||||
VariableList<Transaction<T::MaxBytesPerTransaction>, T::MaxTransactionsPerPayload>,
|
||||
}
|
||||
|
||||
impl<T: EthSpec> From<ExecutionPayload<T>> for JsonExecutionPayload<T> {
|
||||
@@ -410,16 +411,16 @@ pub mod serde_transactions {
|
||||
use serde::{de, Deserializer, Serializer};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
type Value<T, N> = VariableList<Transaction<T>, N>;
|
||||
type Value<M, N> = VariableList<Transaction<M>, N>;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct ListOfBytesListVisitor<T, N> {
|
||||
_phantom_t: PhantomData<T>,
|
||||
pub struct ListOfBytesListVisitor<M, N> {
|
||||
_phantom_m: PhantomData<M>,
|
||||
_phantom_n: PhantomData<N>,
|
||||
}
|
||||
|
||||
impl<'a, T: EthSpec, N: Unsigned> serde::de::Visitor<'a> for ListOfBytesListVisitor<T, N> {
|
||||
type Value = Value<T, N>;
|
||||
impl<'a, M: Unsigned, N: Unsigned> serde::de::Visitor<'a> for ListOfBytesListVisitor<M, N> {
|
||||
type Value = Value<M, N>;
|
||||
|
||||
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(formatter, "a list of 0x-prefixed byte lists")
|
||||
@@ -433,10 +434,9 @@ pub mod serde_transactions {
|
||||
|
||||
while let Some(val) = seq.next_element::<String>()? {
|
||||
let inner_vec = hex::decode(&val).map_err(de::Error::custom)?;
|
||||
let opaque_transaction = VariableList::new(inner_vec).map_err(|e| {
|
||||
let transaction = VariableList::new(inner_vec).map_err(|e| {
|
||||
serde::de::Error::custom(format!("transaction too large: {:?}", e))
|
||||
})?;
|
||||
let transaction = Transaction::OpaqueTransaction(opaque_transaction);
|
||||
outer.push(transaction).map_err(|e| {
|
||||
serde::de::Error::custom(format!("too many transactions: {:?}", e))
|
||||
})?;
|
||||
@@ -446,8 +446,8 @@ pub mod serde_transactions {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn serialize<S, T: EthSpec, N: Unsigned>(
|
||||
value: &Value<T, N>,
|
||||
pub fn serialize<S, M: Unsigned, N: Unsigned>(
|
||||
value: &Value<M, N>,
|
||||
serializer: S,
|
||||
) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@@ -458,21 +458,19 @@ pub mod serde_transactions {
|
||||
// It's important to match on the inner values of the transaction. Serializing the
|
||||
// entire `Transaction` will result in appending the SSZ union prefix byte. The
|
||||
// execution node does not want that.
|
||||
let hex = match transaction {
|
||||
Transaction::OpaqueTransaction(val) => hex::encode(&val[..]),
|
||||
};
|
||||
let hex = hex::encode(&transaction[..]);
|
||||
seq.serialize_element(&hex)?;
|
||||
}
|
||||
seq.end()
|
||||
}
|
||||
|
||||
pub fn deserialize<'de, D, T: EthSpec, N: Unsigned>(
|
||||
pub fn deserialize<'de, D, M: Unsigned, N: Unsigned>(
|
||||
deserializer: D,
|
||||
) -> Result<Value<T, N>, D::Error>
|
||||
) -> Result<Value<M, N>, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let visitor: ListOfBytesListVisitor<T, N> = <_>::default();
|
||||
let visitor: ListOfBytesListVisitor<M, N> = <_>::default();
|
||||
deserializer.deserialize_any(visitor)
|
||||
}
|
||||
}
|
||||
@@ -558,7 +556,10 @@ mod test {
|
||||
const LOGS_BLOOM_01: &str = "0x01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101";
|
||||
|
||||
fn encode_transactions<E: EthSpec>(
|
||||
transactions: VariableList<Transaction<E>, E::MaxTransactionsPerPayload>,
|
||||
transactions: VariableList<
|
||||
Transaction<E::MaxBytesPerTransaction>,
|
||||
E::MaxTransactionsPerPayload,
|
||||
>,
|
||||
) -> Result<serde_json::Value, serde_json::Error> {
|
||||
let ep: JsonExecutionPayload<E> = JsonExecutionPayload {
|
||||
transactions,
|
||||
@@ -570,7 +571,10 @@ mod test {
|
||||
|
||||
fn decode_transactions<E: EthSpec>(
|
||||
transactions: serde_json::Value,
|
||||
) -> Result<VariableList<Transaction<E>, E::MaxTransactionsPerPayload>, serde_json::Error> {
|
||||
) -> Result<
|
||||
VariableList<Transaction<E::MaxBytesPerTransaction>, E::MaxTransactionsPerPayload>,
|
||||
serde_json::Error,
|
||||
> {
|
||||
let json = json!({
|
||||
"parentHash": HASH_00,
|
||||
"coinbase": ADDRESS_01,
|
||||
@@ -593,17 +597,17 @@ mod test {
|
||||
|
||||
fn assert_transactions_serde<E: EthSpec>(
|
||||
name: &str,
|
||||
as_obj: VariableList<Transaction<E>, E::MaxTransactionsPerPayload>,
|
||||
as_obj: VariableList<Transaction<E::MaxBytesPerTransaction>, E::MaxTransactionsPerPayload>,
|
||||
as_json: serde_json::Value,
|
||||
) {
|
||||
assert_eq!(
|
||||
encode_transactions(as_obj.clone()).unwrap(),
|
||||
encode_transactions::<E>(as_obj.clone()).unwrap(),
|
||||
as_json,
|
||||
"encoding for {}",
|
||||
name
|
||||
);
|
||||
assert_eq!(
|
||||
decode_transactions(as_json).unwrap(),
|
||||
decode_transactions::<E>(as_json).unwrap(),
|
||||
as_obj,
|
||||
"decoding for {}",
|
||||
name
|
||||
@@ -611,9 +615,9 @@ mod test {
|
||||
}
|
||||
|
||||
/// Example: if `spec == &[1, 1]`, then two one-byte transactions will be created.
|
||||
fn generate_opaque_transactions<E: EthSpec>(
|
||||
fn generate_transactions<E: EthSpec>(
|
||||
spec: &[usize],
|
||||
) -> VariableList<Transaction<E>, E::MaxTransactionsPerPayload> {
|
||||
) -> VariableList<Transaction<E::MaxBytesPerTransaction>, E::MaxTransactionsPerPayload> {
|
||||
let mut txs = VariableList::default();
|
||||
|
||||
for &num_bytes in spec {
|
||||
@@ -621,7 +625,7 @@ mod test {
|
||||
for _ in 0..num_bytes {
|
||||
tx.push(0).unwrap();
|
||||
}
|
||||
txs.push(Transaction::OpaqueTransaction(tx)).unwrap();
|
||||
txs.push(tx).unwrap();
|
||||
}
|
||||
|
||||
txs
|
||||
@@ -631,32 +635,32 @@ mod test {
|
||||
fn transaction_serde() {
|
||||
assert_transactions_serde::<MainnetEthSpec>(
|
||||
"empty",
|
||||
generate_opaque_transactions(&[]),
|
||||
generate_transactions::<MainnetEthSpec>(&[]),
|
||||
json!([]),
|
||||
);
|
||||
assert_transactions_serde::<MainnetEthSpec>(
|
||||
"one empty tx",
|
||||
generate_opaque_transactions(&[0]),
|
||||
generate_transactions::<MainnetEthSpec>(&[0]),
|
||||
json!(["0x"]),
|
||||
);
|
||||
assert_transactions_serde::<MainnetEthSpec>(
|
||||
"two empty txs",
|
||||
generate_opaque_transactions(&[0, 0]),
|
||||
generate_transactions::<MainnetEthSpec>(&[0, 0]),
|
||||
json!(["0x", "0x"]),
|
||||
);
|
||||
assert_transactions_serde::<MainnetEthSpec>(
|
||||
"one one-byte tx",
|
||||
generate_opaque_transactions(&[1]),
|
||||
generate_transactions::<MainnetEthSpec>(&[1]),
|
||||
json!(["0x00"]),
|
||||
);
|
||||
assert_transactions_serde::<MainnetEthSpec>(
|
||||
"two one-byte txs",
|
||||
generate_opaque_transactions(&[1, 1]),
|
||||
generate_transactions::<MainnetEthSpec>(&[1, 1]),
|
||||
json!(["0x00", "0x00"]),
|
||||
);
|
||||
assert_transactions_serde::<MainnetEthSpec>(
|
||||
"mixed bag",
|
||||
generate_opaque_transactions(&[0, 1, 3, 0]),
|
||||
generate_transactions::<MainnetEthSpec>(&[0, 1, 3, 0]),
|
||||
json!(["0x", "0x00", "0x000000", "0x"]),
|
||||
);
|
||||
|
||||
@@ -680,7 +684,7 @@ mod test {
|
||||
|
||||
use eth2_serde_utils::hex;
|
||||
|
||||
let num_max_bytes = <MainnetEthSpec as EthSpec>::MaxBytesPerOpaqueTransaction::to_usize();
|
||||
let num_max_bytes = <MainnetEthSpec as EthSpec>::MaxBytesPerTransaction::to_usize();
|
||||
let max_bytes = (0..num_max_bytes).map(|_| 0_u8).collect::<Vec<_>>();
|
||||
let too_many_bytes = (0..=num_max_bytes).map(|_| 0_u8).collect::<Vec<_>>();
|
||||
decode_transactions::<MainnetEthSpec>(
|
||||
|
||||
Reference in New Issue
Block a user