Skip to content

Commit

Permalink
jsontests: added validation for EIP-7702
Browse files Browse the repository at this point in the history
  • Loading branch information
mrLSD committed Sep 16, 2024
1 parent d021461 commit d58aaf0
Show file tree
Hide file tree
Showing 10 changed files with 327 additions and 116 deletions.
1 change: 1 addition & 0 deletions evm-tests/ethjson/src/authentication_list.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions evm-tests/ethjson/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ pub mod transaction;
pub mod uint;
pub mod vm;

mod authentication_list;
#[cfg(any(test, feature = "test-helpers"))]
pub mod test_helpers;
27 changes: 27 additions & 0 deletions evm-tests/ethjson/src/test_helpers/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ pub struct MultiTransaction {
pub blob_versioned_hashes: Vec<U256>,
/// EIP-4844
pub max_fee_per_blob_gas: Option<Uint>,

/// EIP-7702
#[serde(default)]
pub authorization_list: AuthorizationList,
}

impl MultiTransaction {
Expand Down Expand Up @@ -109,6 +113,7 @@ impl MultiTransaction {
v: Default::default(),
secret: self.secret,
access_list,
authorization_list: self.authorization_list.clone(),
}
}
}
Expand All @@ -127,6 +132,28 @@ pub struct AccessListTuple {
pub storage_keys: Vec<H256>,
}

/// EIP-7702 Authorization List
pub type AuthorizationList = Vec<AuthorizationItem>;
/// EIP-7702 Authorization item
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AuthorizationItem {
/// Chain ID
pub chain_id: Uint,
/// Address to access
pub address: Address,
/// Keys (slots) to access at that address
pub nonce: Uint,
/// r signature
pub r: Uint,
/// s signature
pub s: Uint,
/// Parity
pub v: Uint,
/// Signer address
pub signer: Option<Address>,
}

/// State test indexes deserialization.
#[derive(Debug, PartialEq, Eq, Deserialize)]
pub struct PostStateIndexes {
Expand Down
4 changes: 4 additions & 0 deletions evm-tests/ethjson/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

//! Transaction deserialization.
use crate::test_helpers::state::AuthorizationList;
use crate::{
bytes::Bytes,
hash::{Address, H256},
Expand All @@ -33,6 +34,9 @@ pub struct Transaction {
/// Transaction access list (see EIP-2930).
#[serde(default)]
pub access_list: Vec<(Address, Vec<H256>)>,
/// Transaction authorization list (see EIP-7702`s).
#[serde(default)]
pub authorization_list: AuthorizationList,
/// Gas limit.
pub gas_limit: Uint,
/// To.
Expand Down
2 changes: 2 additions & 0 deletions evm-tests/jsontests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
extern crate core;

mod utils;

pub mod state;
Expand Down
1 change: 0 additions & 1 deletion evm-tests/jsontests/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ fn run_test_for_file(
);
}
let file = File::open(file_name).expect("Open file failed");

let reader = BufReader::new(file);
let test_suite = serde_json::from_reader::<_, HashMap<String, statetests::Test>>(reader)
.expect("Parse test cases failed");
Expand Down
Loading

0 comments on commit d58aaf0

Please sign in to comment.