4141#[ macro_use]
4242extern crate cfg_if;
4343
44+ #[ cfg( feature = "std" ) ]
45+ use std:: vec:: Vec ;
46+
47+ use types:: * ;
48+ #[ cfg( feature = "std" ) ]
49+ use utils:: * ;
50+
4451cfg_if ! {
4552 if #[ cfg( feature = "wee_alloc" ) ] {
4653 extern crate wee_alloc;
@@ -58,7 +65,7 @@ mod utils;
5865
5966pub mod types;
6067
61- #[ cfg ( feature = "debug" ) ]
68+ #[ macro_use ]
6269pub mod debug;
6370
6471#[ cfg( feature = "experimental" ) ]
@@ -70,30 +77,17 @@ pub mod eth2;
7077#[ cfg( not( feature = "std" ) ) ]
7178pub mod convert;
7279
73- #[ cfg( feature = "std" ) ]
74- use std:: vec:: Vec ;
75-
76- use types:: * ;
77- #[ cfg( feature = "std" ) ]
78- use utils:: * ;
79-
8080/// Re-export of all the basic features.
8181pub mod prelude {
82- pub use crate :: * ;
83-
84- pub use crate :: types:: * ;
85-
82+ #[ cfg( feature = "experimental" ) ]
83+ pub use crate :: bignum;
8684 #[ cfg( not( feature = "std" ) ) ]
8785 pub use crate :: convert:: * ;
88-
89- #[ cfg( feature = "debug" ) ]
9086 pub use crate :: debug;
91-
92- #[ cfg( feature = "experimental" ) ]
93- pub use crate :: bignum;
94-
9587 #[ cfg( feature = "eth2" ) ]
9688 pub use crate :: eth2;
89+ pub use crate :: types:: * ;
90+ pub use crate :: * ;
9791}
9892
9993/// Declare entry point for a contract. Expects a Rust function name to be executed.
@@ -667,3 +661,98 @@ pub fn selfdestruct(address: &Address) -> ! {
667661 native:: ethereum_selfDestruct ( address. bytes . as_ptr ( ) as * const u32 ) ;
668662 }
669663}
664+
665+ #[ cfg( test) ]
666+ mod debug_macros {
667+ use crate :: types:: StorageKey ;
668+
669+ #[ cfg( debug_assertions) ]
670+ #[ no_mangle]
671+ pub fn debug_print32 ( _value : u32 ) { }
672+
673+ #[ cfg( debug_assertions) ]
674+ #[ no_mangle]
675+ pub fn debug_print64 ( _value : u64 ) { }
676+
677+ #[ cfg( debug_assertions) ]
678+ #[ allow( non_snake_case) ]
679+ #[ no_mangle]
680+ pub fn debug_printMem ( _offset : * const u32 , _len : u32 ) { }
681+
682+ #[ cfg( debug_assertions) ]
683+ #[ allow( non_snake_case) ]
684+ #[ no_mangle]
685+ pub fn debug_printMemHex ( _offset : * const u32 , _len : u32 ) { }
686+
687+ #[ cfg( debug_assertions) ]
688+ #[ allow( non_snake_case) ]
689+ #[ no_mangle]
690+ pub fn debug_printStorage ( _path_offset : * const u32 ) { }
691+
692+ #[ cfg( debug_assertions) ]
693+ #[ allow( non_snake_case) ]
694+ #[ no_mangle]
695+ pub fn debug_printStorageHex ( _path_offset : * const u32 ) { }
696+
697+ #[ test]
698+ fn test_print32 ( ) {
699+ let _v: u32 = 42 ;
700+ print32 ! ( _v) ;
701+ print32 ! ( 42 ) ;
702+ print32 ! ( 42 + 1 ) ;
703+ }
704+
705+ #[ test]
706+ fn test_print64 ( ) {
707+ let _v: u64 = 4242 ;
708+ print64 ! ( _v) ;
709+ print64 ! ( 4242 ) ;
710+ print64 ! ( 4242 + 1 ) ;
711+ }
712+
713+ #[ test]
714+ fn test_print_mem ( ) {
715+ let _mem: [ u8 ; 0 ] = [ ] ;
716+ print_mem ! ( _mem) ;
717+ let _mem: [ u8 ; 3 ] = [ 0 , 1 , 2 ] ;
718+ print_mem ! ( _mem) ;
719+ let _mem = [ 0 , 1 , 2 , 3 , 4 , 5 ] ;
720+ print_mem ! ( _mem) ;
721+ print_mem ! ( [ 0 , 1 ] ) ;
722+ }
723+
724+ #[ test]
725+ fn test_print_mem_hex ( ) {
726+ let _mem: [ u8 ; 0 ] = [ ] ;
727+ print_mem_hex ! ( _mem) ;
728+ let _mem: [ u8 ; 3 ] = [ 0 , 1 , 2 ] ;
729+ print_mem_hex ! ( _mem) ;
730+ let _mem = [ 0 , 1 , 2 , 3 , 4 , 5 ] ;
731+ print_mem_hex ! ( _mem) ;
732+ print_mem_hex ! ( [ 0 , 1 ] ) ;
733+ }
734+
735+ #[ test]
736+ fn test_print_storage ( ) {
737+ let _key = StorageKey {
738+ bytes : [
739+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
740+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
741+ 0x00 , 0x00 , 0x00 , 0x00 ,
742+ ] ,
743+ } ;
744+ print_storage ! ( _key) ;
745+ }
746+
747+ #[ test]
748+ fn test_print_storage_hex ( ) {
749+ let _key = StorageKey {
750+ bytes : [
751+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
752+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
753+ 0x00 , 0x00 , 0x00 , 0x00 ,
754+ ] ,
755+ } ;
756+ print_storage_hex ! ( _key) ;
757+ }
758+ }
0 commit comments