@@ -21,9 +21,11 @@ use counter::CounterAbi;
2121use fungible:: { FungibleOperation , InitialState , Parameters } ;
2222use hex_game:: { HexAbi , Operation as HexOperation , Timeouts } ;
2323use linera_base:: {
24- crypto:: InMemorySigner ,
25- data_types:: { Amount , BlockHeight , Bytecode , ChainDescription , Event , OracleResponse } ,
26- identifiers:: { ApplicationId , BlobId , BlobType , ModuleId , StreamId , StreamName } ,
24+ crypto:: { CryptoHash , InMemorySigner } ,
25+ data_types:: {
26+ Amount , BlobContent , BlockHeight , Bytecode , ChainDescription , Event , OracleResponse ,
27+ } ,
28+ identifiers:: { ApplicationId , BlobId , BlobType , DataBlobHash , ModuleId , StreamId , StreamName } ,
2729 ownership:: { ChainOwnership , TimeoutConfig } ,
2830 vm:: VmRuntime ,
2931} ;
@@ -989,3 +991,115 @@ where
989991 . await ?;
990992 Ok ( ( ) )
991993}
994+
995+ #[ cfg_attr( feature = "wasmer" , test_case( WasmRuntime :: Wasmer ; "wasmer" ) ) ]
996+ #[ cfg_attr( feature = "wasmtime" , test_case( WasmRuntime :: Wasmtime ; "wasmtime" ) ) ]
997+ #[ test_log:: test( tokio:: test( flavor = "multi_thread" ) ) ]
998+ async fn test_memory_publish_read_data_blob ( wasm_runtime : WasmRuntime ) -> anyhow:: Result < ( ) > {
999+ run_test_publish_read_data_blob ( MemoryStorageBuilder :: with_wasm_runtime ( wasm_runtime) ) . await
1000+ }
1001+
1002+ #[ ignore]
1003+ #[ cfg( feature = "storage-service" ) ]
1004+ #[ cfg_attr( feature = "wasmer" , test_case( WasmRuntime :: Wasmer ; "wasmer" ) ) ]
1005+ #[ cfg_attr( feature = "wasmtime" , test_case( WasmRuntime :: Wasmtime ; "wasmtime" ) ) ]
1006+ #[ test_log:: test( tokio:: test( flavor = "multi_thread" ) ) ]
1007+ async fn test_service_publish_read_data_blob ( wasm_runtime : WasmRuntime ) -> anyhow:: Result < ( ) > {
1008+ run_test_publish_read_data_blob ( ServiceStorageBuilder :: with_wasm_runtime ( wasm_runtime) . await )
1009+ . await
1010+ }
1011+
1012+ #[ ignore]
1013+ #[ cfg( feature = "rocksdb" ) ]
1014+ #[ cfg_attr( feature = "wasmer" , test_case( WasmRuntime :: Wasmer ; "wasmer" ) ) ]
1015+ #[ cfg_attr( feature = "wasmtime" , test_case( WasmRuntime :: Wasmtime ; "wasmtime" ) ) ]
1016+ #[ test_log:: test( tokio:: test( flavor = "multi_thread" ) ) ]
1017+ async fn test_rocks_db_publish_read_data_blob ( wasm_runtime : WasmRuntime ) -> anyhow:: Result < ( ) > {
1018+ run_test_publish_read_data_blob ( RocksDbStorageBuilder :: with_wasm_runtime ( wasm_runtime) . await )
1019+ . await
1020+ }
1021+
1022+ #[ ignore]
1023+ #[ cfg( feature = "dynamodb" ) ]
1024+ #[ cfg_attr( feature = "wasmer" , test_case( WasmRuntime :: Wasmer ; "wasmer" ) ) ]
1025+ #[ cfg_attr( feature = "wasmtime" , test_case( WasmRuntime :: Wasmtime ; "wasmtime" ) ) ]
1026+ #[ test_log:: test( tokio:: test( flavor = "multi_thread" ) ) ]
1027+ async fn test_dynamo_db_publish_read_data_blob ( wasm_runtime : WasmRuntime ) -> anyhow:: Result < ( ) > {
1028+ run_test_publish_read_data_blob ( DynamoDbStorageBuilder :: with_wasm_runtime ( wasm_runtime) ) . await
1029+ }
1030+
1031+ #[ ignore]
1032+ #[ cfg( feature = "scylladb" ) ]
1033+ #[ cfg_attr( feature = "wasmer" , test_case( WasmRuntime :: Wasmer ; "wasmer" ) ) ]
1034+ #[ cfg_attr( feature = "wasmtime" , test_case( WasmRuntime :: Wasmtime ; "wasmtime" ) ) ]
1035+ #[ test_log:: test( tokio:: test( flavor = "multi_thread" ) ) ]
1036+ async fn test_scylla_db_publish_read_data_blob ( wasm_runtime : WasmRuntime ) -> anyhow:: Result < ( ) > {
1037+ run_test_publish_read_data_blob ( ScyllaDbStorageBuilder :: with_wasm_runtime ( wasm_runtime) ) . await
1038+ }
1039+
1040+ async fn run_test_publish_read_data_blob < B > ( storage_builder : B ) -> anyhow:: Result < ( ) >
1041+ where
1042+ B : StorageBuilder ,
1043+ {
1044+ use publish_read_data_blob:: PublishReadDataBlobAbi ;
1045+
1046+ let keys = InMemorySigner :: new ( None ) ;
1047+ let mut builder = TestBuilder :: new ( storage_builder, 4 , 1 , keys)
1048+ . await ?
1049+ . with_policy ( ResourceControlPolicy :: all_categories ( ) ) ;
1050+ let client = builder. add_root_chain ( 0 , Amount :: from_tokens ( 3 ) ) . await ?;
1051+
1052+ let module_id = client
1053+ . publish_wasm_example ( "publish-read-data-blob" )
1054+ . await ?;
1055+ let module_id = module_id. with_abi :: < PublishReadDataBlobAbi , ( ) , ( ) > ( ) ;
1056+
1057+ let ( application_id, _) = client
1058+ . create_application ( module_id, & ( ) , & ( ) , vec ! [ ] )
1059+ . await
1060+ . unwrap_ok_committed ( ) ;
1061+
1062+ // Method 1: Publishing and reading in different blocks.
1063+ let test_data = b"This is test data for method 1." . to_vec ( ) ;
1064+
1065+ // publishing the data.
1066+ let publish_op = publish_read_data_blob:: Operation :: CreateDataBlob ( test_data. clone ( ) ) ;
1067+ client
1068+ . execute_operation ( Operation :: user ( application_id, & publish_op) ?)
1069+ . await
1070+ . unwrap_ok_committed ( ) ;
1071+
1072+ // getting the hash
1073+ let content = BlobContent :: new_data ( test_data. clone ( ) ) ;
1074+ let hash = DataBlobHash ( CryptoHash :: new ( & content) ) ;
1075+
1076+ // reading and checking
1077+ let read_op = publish_read_data_blob:: Operation :: ReadDataBlob ( hash, test_data) ;
1078+ client
1079+ . execute_operation ( Operation :: user ( application_id, & read_op) ?)
1080+ . await
1081+ . unwrap_ok_committed ( ) ;
1082+
1083+ // Method 2: Publishing and reading in the same transaction
1084+ let test_data = b"This is test data for method 2." . to_vec ( ) ;
1085+ let combined_op = publish_read_data_blob:: Operation :: CreateAndReadDataBlob ( test_data) ;
1086+ client
1087+ . execute_operation ( Operation :: user ( application_id, & combined_op) ?)
1088+ . await
1089+ . unwrap_ok_committed ( ) ;
1090+
1091+ // Method 3: Publishing and reading in the same block but different transactions
1092+ let test_data = b"This is test data for method 3." . to_vec ( ) ;
1093+ let publish_op = publish_read_data_blob:: Operation :: CreateDataBlob ( test_data. clone ( ) ) ;
1094+ let content = BlobContent :: new_data ( test_data. clone ( ) ) ;
1095+ let hash = DataBlobHash ( CryptoHash :: new ( & content) ) ;
1096+ let read_op = publish_read_data_blob:: Operation :: ReadDataBlob ( hash, test_data) ;
1097+ let op1 = Operation :: user ( application_id, & publish_op) ?;
1098+ let op2 = Operation :: user ( application_id, & read_op) ?;
1099+ client
1100+ . execute_operations ( vec ! [ op1, op2] , vec ! [ ] )
1101+ . await
1102+ . unwrap_ok_committed ( ) ;
1103+
1104+ Ok ( ( ) )
1105+ }
0 commit comments