File tree Expand file tree Collapse file tree 2 files changed +68
-2
lines changed
Expand file tree Collapse file tree 2 files changed +68
-2
lines changed Original file line number Diff line number Diff line change @@ -85,7 +85,6 @@ impl ThinStateDiff {
8585 )
8686 }
8787
88- #[ allow( clippy:: len_without_is_empty) ]
8988 /// This has the same value as `state_diff_length` in the corresponding `BlockHeader`.
9089 pub fn len ( & self ) -> usize {
9190 let mut result = 0usize ;
@@ -100,6 +99,18 @@ impl ThinStateDiff {
10099 }
101100 result
102101 }
102+
103+ pub fn is_empty ( & self ) -> bool {
104+ self . deployed_contracts . is_empty ( )
105+ && self . declared_classes . is_empty ( )
106+ && self . deprecated_declared_classes . is_empty ( )
107+ && self . nonces . is_empty ( )
108+ && self . replaced_classes . is_empty ( )
109+ && self
110+ . storage_diffs
111+ . iter ( )
112+ . all ( |( _contract_address, storage_diffs) | storage_diffs. is_empty ( ) )
113+ }
103114}
104115
105116impl From < StateDiff > for ThinStateDiff {
Original file line number Diff line number Diff line change 11use std:: collections:: HashMap ;
22
3- use indexmap:: indexmap;
3+ use indexmap:: { indexmap, IndexMap } ;
44use serde_json:: json;
55
66use super :: ThinStateDiff ;
@@ -61,3 +61,58 @@ fn thin_state_diff_len() {
6161 } ;
6262 assert_eq ! ( state_diff. len( ) , 13 ) ;
6363}
64+
65+ #[ test]
66+ fn thin_state_diff_is_empty ( ) {
67+ assert ! ( ThinStateDiff :: default ( ) . is_empty( ) ) ;
68+ assert ! (
69+ ThinStateDiff {
70+ storage_diffs: indexmap! { Default :: default ( ) => IndexMap :: new( ) } ,
71+ ..Default :: default ( )
72+ }
73+ . is_empty( )
74+ ) ;
75+
76+ assert ! (
77+ !ThinStateDiff {
78+ deployed_contracts: indexmap! { Default :: default ( ) => Default :: default ( ) } ,
79+ ..Default :: default ( )
80+ }
81+ . is_empty( )
82+ ) ;
83+ assert ! (
84+ !ThinStateDiff {
85+ storage_diffs: indexmap! { Default :: default ( ) => indexmap! { Default :: default ( ) => Default :: default ( ) } } ,
86+ ..Default :: default ( )
87+ }
88+ . is_empty( )
89+ ) ;
90+ assert ! (
91+ !ThinStateDiff {
92+ declared_classes: indexmap! { Default :: default ( ) => Default :: default ( ) } ,
93+ ..Default :: default ( )
94+ }
95+ . is_empty( )
96+ ) ;
97+ assert ! (
98+ !ThinStateDiff {
99+ deprecated_declared_classes: vec![ Default :: default ( ) ] ,
100+ ..Default :: default ( )
101+ }
102+ . is_empty( )
103+ ) ;
104+ assert ! (
105+ !ThinStateDiff {
106+ nonces: indexmap! { Default :: default ( ) => Default :: default ( ) } ,
107+ ..Default :: default ( )
108+ }
109+ . is_empty( )
110+ ) ;
111+ assert ! (
112+ !ThinStateDiff {
113+ replaced_classes: indexmap! { Default :: default ( ) => Default :: default ( ) } ,
114+ ..Default :: default ( )
115+ }
116+ . is_empty( )
117+ ) ;
118+ }
You can’t perform that action at this time.
0 commit comments