File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -65,3 +65,48 @@ impl std::fmt::Display for SystemError {
6565 }
6666 }
6767}
68+
69+ #[ cfg( test) ]
70+ mod tests {
71+ use super :: * ;
72+ use crate :: { from_slice, to_vec} ;
73+
74+ #[ test]
75+ fn system_error_no_such_contract_serialization ( ) {
76+ let err = SystemError :: NoSuchContract {
77+ addr : "gibtsnicht" . to_string ( ) ,
78+ } ;
79+
80+ // ser
81+ let json = to_vec ( & err) . unwrap ( ) ;
82+ assert_eq ! (
83+ String :: from_utf8_lossy( & json) ,
84+ r#"{"no_such_contract":{"addr":"gibtsnicht"}}"# ,
85+ ) ;
86+
87+ // de
88+ let err: SystemError = from_slice ( br#"{"no_such_contract":{"addr":"nada"}}"# ) . unwrap ( ) ;
89+ assert_eq ! (
90+ err,
91+ SystemError :: NoSuchContract {
92+ addr: "nada" . to_string( )
93+ }
94+ ) ;
95+ }
96+
97+ #[ test]
98+ fn system_error_no_such_code_serialization ( ) {
99+ let err = SystemError :: NoSuchCode { code_id : 13 } ;
100+
101+ // ser
102+ let json = to_vec ( & err) . unwrap ( ) ;
103+ assert_eq ! (
104+ String :: from_utf8_lossy( & json) ,
105+ r#"{"no_such_code":{"code_id":13}}"# ,
106+ ) ;
107+
108+ // de
109+ let err: SystemError = from_slice ( br#"{"no_such_code":{"code_id":987}}"# ) . unwrap ( ) ;
110+ assert_eq ! ( err, SystemError :: NoSuchCode { code_id: 987 } , ) ;
111+ }
112+ }
You can’t perform that action at this time.
0 commit comments