@@ -280,6 +280,8 @@ cfg_if! {
280280 ///
281281 /// Returns the signature generated for the message `sr25519`.
282282 fn test_sr25519_crypto( ) -> ( sr25519:: AppSignature , sr25519:: AppPublic ) ;
283+ /// Run various tests against storage.
284+ fn test_storage( ) ;
283285 }
284286 }
285287 } else {
@@ -322,6 +324,8 @@ cfg_if! {
322324 ///
323325 /// Returns the signature generated for the message `sr25519`.
324326 fn test_sr25519_crypto( ) -> ( sr25519:: AppSignature , sr25519:: AppPublic ) ;
327+ /// Run various tests against storage.
328+ fn test_storage( ) ;
325329 }
326330 }
327331 }
@@ -590,6 +594,11 @@ cfg_if! {
590594 fn test_sr25519_crypto( ) -> ( sr25519:: AppSignature , sr25519:: AppPublic ) {
591595 test_sr25519_crypto( )
592596 }
597+
598+ fn test_storage( ) {
599+ test_read_storage( ) ;
600+ test_read_child_storage( ) ;
601+ }
593602 }
594603
595604 impl aura_primitives:: AuraApi <Block , AuraId > for Runtime {
@@ -805,6 +814,11 @@ cfg_if! {
805814 fn test_sr25519_crypto( ) -> ( sr25519:: AppSignature , sr25519:: AppPublic ) {
806815 test_sr25519_crypto( )
807816 }
817+
818+ fn test_storage( ) {
819+ test_read_storage( ) ;
820+ test_read_child_storage( ) ;
821+ }
808822 }
809823
810824 impl aura_primitives:: AuraApi <Block , AuraId > for Runtime {
@@ -887,6 +901,46 @@ fn test_sr25519_crypto() -> (sr25519::AppSignature, sr25519::AppPublic) {
887901 ( signature, public0)
888902}
889903
904+ fn test_read_storage ( ) {
905+ const KEY : & [ u8 ] = b":read_storage" ;
906+ runtime_io:: set_storage ( KEY , b"test" ) ;
907+
908+ let mut v = [ 0u8 ; 4 ] ;
909+ let r = runtime_io:: read_storage (
910+ KEY ,
911+ & mut v,
912+ 0
913+ ) ;
914+ assert_eq ! ( r, Some ( 4 ) ) ;
915+ assert_eq ! ( & v, b"test" ) ;
916+
917+ let mut v = [ 0u8 ; 4 ] ;
918+ let r = runtime_io:: read_storage ( KEY , & mut v, 8 ) ;
919+ assert_eq ! ( r, Some ( 4 ) ) ;
920+ assert_eq ! ( & v, & [ 0 , 0 , 0 , 0 ] ) ;
921+ }
922+
923+ fn test_read_child_storage ( ) {
924+ const CHILD_KEY : & [ u8 ] = b":child_storage:default:read_child_storage" ;
925+ const KEY : & [ u8 ] = b":read_child_storage" ;
926+ runtime_io:: set_child_storage ( CHILD_KEY , KEY , b"test" ) ;
927+
928+ let mut v = [ 0u8 ; 4 ] ;
929+ let r = runtime_io:: read_child_storage (
930+ CHILD_KEY ,
931+ KEY ,
932+ & mut v,
933+ 0
934+ ) ;
935+ assert_eq ! ( r, Some ( 4 ) ) ;
936+ assert_eq ! ( & v, b"test" ) ;
937+
938+ let mut v = [ 0u8 ; 4 ] ;
939+ let r = runtime_io:: read_child_storage ( CHILD_KEY , KEY , & mut v, 8 ) ;
940+ assert_eq ! ( r, Some ( 4 ) ) ;
941+ assert_eq ! ( & v, & [ 0 , 0 , 0 , 0 ] ) ;
942+ }
943+
890944#[ cfg( test) ]
891945mod tests {
892946 use substrate_test_runtime_client:: {
@@ -981,4 +1035,15 @@ mod tests {
9811035 let ret = runtime_api. vec_with_capacity ( & new_block_id, 1048576 ) ;
9821036 assert ! ( ret. is_ok( ) ) ;
9831037 }
1038+
1039+ #[ test]
1040+ fn test_storage ( ) {
1041+ let client = TestClientBuilder :: new ( )
1042+ . set_execution_strategy ( ExecutionStrategy :: Both )
1043+ . build ( ) ;
1044+ let runtime_api = client. runtime_api ( ) ;
1045+ let block_id = BlockId :: Number ( client. info ( ) . chain . best_number ) ;
1046+
1047+ runtime_api. test_storage ( & block_id) . unwrap ( ) ;
1048+ }
9841049}
0 commit comments