reth_primitives/transaction/
access_list.rs

1//!  [EIP-2930](https://eips.ethereum.org/EIPS/eip-2930): Access List types
2
3#[cfg(test)]
4mod tests {
5    use alloy_eips::eip2930::{AccessList, AccessListItem};
6    use alloy_primitives::{Address, B256};
7    use alloy_rlp::{RlpDecodable, RlpDecodableWrapper, RlpEncodable, RlpEncodableWrapper};
8    use proptest::proptest;
9    use proptest_arbitrary_interop::arb;
10    use reth_codecs::{add_arbitrary_tests, Compact};
11    use serde::{Deserialize, Serialize};
12
13    /// This type is kept for compatibility tests after the codec support was added to alloy-eips
14    /// AccessList type natively
15    #[derive(
16        Clone,
17        Debug,
18        PartialEq,
19        Eq,
20        Hash,
21        Default,
22        RlpDecodableWrapper,
23        RlpEncodableWrapper,
24        Serialize,
25        Deserialize,
26        Compact,
27    )]
28    #[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
29    #[add_arbitrary_tests(compact, rlp)]
30    struct RethAccessList(Vec<RethAccessListItem>);
31
32    impl PartialEq<AccessList> for RethAccessList {
33        fn eq(&self, other: &AccessList) -> bool {
34            self.0.iter().zip(other.iter()).all(|(a, b)| a == b)
35        }
36    }
37
38    // This
39    #[derive(
40        Clone,
41        Debug,
42        PartialEq,
43        Eq,
44        Hash,
45        Default,
46        RlpDecodable,
47        RlpEncodable,
48        Serialize,
49        Deserialize,
50        Compact,
51    )]
52    #[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
53    #[add_arbitrary_tests(compact, rlp)]
54    #[serde(rename_all = "camelCase")]
55    struct RethAccessListItem {
56        /// Account address that would be loaded at the start of execution
57        address: Address,
58        /// The storage keys to be loaded at the start of execution.
59        ///
60        /// Each key is a 32-byte value representing a specific storage slot.
61        storage_keys: Vec<B256>,
62    }
63
64    impl PartialEq<AccessListItem> for RethAccessListItem {
65        fn eq(&self, other: &AccessListItem) -> bool {
66            self.address == other.address && self.storage_keys == other.storage_keys
67        }
68    }
69
70    proptest!(
71        #[test]
72        fn test_roundtrip_accesslist_compat(access_list in arb::<RethAccessList>()) {
73            // Convert access_list to buffer and then create alloy_access_list from buffer and
74            // compare
75            let mut compacted_reth_access_list = Vec::<u8>::new();
76            let len = access_list.to_compact(&mut compacted_reth_access_list);
77
78            // decode the compacted buffer to AccessList
79            let alloy_access_list = AccessList::from_compact(&compacted_reth_access_list, len).0;
80            assert_eq!(access_list, alloy_access_list);
81
82            let mut compacted_alloy_access_list = Vec::<u8>::new();
83            let alloy_len = alloy_access_list.to_compact(&mut compacted_alloy_access_list);
84            assert_eq!(len, alloy_len);
85            assert_eq!(compacted_reth_access_list, compacted_alloy_access_list);
86        }
87    );
88}