reth_primitives/transaction/
access_list.rs1#[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 #[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 #[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 address: Address,
58 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 let mut compacted_reth_access_list = Vec::<u8>::new();
76 let len = access_list.to_compact(&mut compacted_reth_access_list);
77
78 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}