@@ -109,6 +109,14 @@ impl TestEnvironment {
109109 fn make_app_description ( & self ) -> ( ApplicationDescription , Blob , Blob ) {
110110 let contract = Bytecode :: new ( b"contract" . into ( ) ) ;
111111 let service = Bytecode :: new ( b"service" . into ( ) ) ;
112+ self . make_app_from_bytecodes ( contract, service)
113+ }
114+
115+ fn make_app_from_bytecodes (
116+ & self ,
117+ contract : Bytecode ,
118+ service : Bytecode ,
119+ ) -> ( ApplicationDescription , Blob , Blob ) {
112120 let contract_blob = Blob :: new_contract_bytecode ( contract. compress ( ) ) ;
113121 let service_blob = Blob :: new_service_bytecode ( service. compress ( ) ) ;
114122 let vm_runtime = VmRuntime :: Wasm ;
@@ -254,8 +262,17 @@ async fn test_application_permissions() -> anyhow::Result<()> {
254262 let application_id = ApplicationId :: from ( & app_description) ;
255263 let application = MockApplication :: default ( ) ;
256264
265+ let ( another_app, another_contract, another_service) = env. make_app_from_bytecodes (
266+ Bytecode :: new ( b"contractB" . into ( ) ) ,
267+ Bytecode :: new ( b"serviceB" . into ( ) ) ,
268+ ) ;
269+ let another_app_id = ApplicationId :: from ( & another_app) ;
270+
257271 let config = InitialChainConfig {
258- application_permissions : ApplicationPermissions :: new_single ( application_id) ,
272+ application_permissions : ApplicationPermissions :: new_multiple ( vec ! [
273+ application_id,
274+ another_app_id,
275+ ] ) ,
259276 ..env. make_open_chain_config ( )
260277 } ;
261278 let chain_desc = env. make_child_chain_description_with_config ( 3 , config) ;
@@ -267,6 +284,10 @@ async fn test_application_permissions() -> anyhow::Result<()> {
267284 extra
268285 . user_contracts ( )
269286 . insert ( application_id, application. clone ( ) . into ( ) ) ;
287+ extra
288+ . user_contracts ( )
289+ . insert ( another_app_id, application. clone ( ) . into ( ) ) ;
290+
270291 extra. add_blobs ( env. description_blobs ( ) ) . await ?;
271292 extra
272293 . add_blobs ( [
@@ -275,6 +296,13 @@ async fn test_application_permissions() -> anyhow::Result<()> {
275296 Blob :: new_application_description ( & app_description) ,
276297 ] )
277298 . await ?;
299+ extra
300+ . add_blobs ( [
301+ another_contract,
302+ another_service,
303+ Blob :: new_application_description ( & another_app) ,
304+ ] )
305+ . await ?;
278306
279307 // Initialize the chain, with a chain application.
280308 chain. ensure_is_active ( time) . await ?;
@@ -285,20 +313,31 @@ async fn test_application_permissions() -> anyhow::Result<()> {
285313 . execute_block ( & invalid_block, time, None , & [ ] , None )
286314 . await ;
287315 assert_matches ! ( result, Err ( ChainError :: AuthorizedApplications ( app_ids) )
288- if app_ids == vec![ application_id]
316+ if app_ids == vec![ application_id, another_app_id ]
289317 ) ;
290318
291319 // After registering, an app operation can already be used in the first block.
292320 application. expect_call ( ExpectedCall :: execute_operation ( |_, _| Ok ( vec ! [ ] ) ) ) ;
293321 application. expect_call ( ExpectedCall :: default_finalize ( ) ) ;
322+ application. expect_call ( ExpectedCall :: execute_operation ( |_, _| Ok ( vec ! [ ] ) ) ) ;
323+ application. expect_call ( ExpectedCall :: default_finalize ( ) ) ;
294324 let app_operation = Operation :: User {
295325 application_id,
296326 bytes : b"foo" . to_vec ( ) ,
297327 } ;
298- let valid_block = make_first_block ( chain_id) . with_operation ( app_operation. clone ( ) ) ;
328+ let another_app_operation = Operation :: User {
329+ application_id : another_app_id,
330+ bytes : b"bar" . to_vec ( ) ,
331+ } ;
332+
333+ let valid_block = make_first_block ( chain_id)
334+ . with_operation ( app_operation. clone ( ) )
335+ . with_operation ( another_app_operation. clone ( ) ) ;
336+
299337 let outcome = chain
300338 . execute_block ( & valid_block, time, None , & [ ] , None )
301339 . await ?;
340+
302341 let value = ConfirmedBlock :: new ( outcome. with ( valid_block) ) ;
303342 chain. apply_confirmed_block ( & value, time) . await ?;
304343
@@ -310,22 +349,24 @@ async fn test_application_permissions() -> anyhow::Result<()> {
310349 . execute_block ( & invalid_block, time, None , & [ ] , None )
311350 . await ;
312351 assert_matches ! ( result, Err ( ChainError :: AuthorizedApplications ( app_ids) )
313- if app_ids == vec![ application_id]
352+ if app_ids == vec![ application_id, another_app_id ]
314353 ) ;
315-
316- // Also, blocks without an application operation or incoming message are forbidden.
317- let invalid_block = make_child_block ( & value) ;
354+ // Also, blocks without all authorized applications operation, or incoming message, are forbidden.
355+ let invalid_block = make_child_block ( & value) . with_operation ( another_app_operation. clone ( ) ) ;
318356 let result = chain
319357 . execute_block ( & invalid_block, time, None , & [ ] , None )
320358 . await ;
321359 assert_matches ! ( result, Err ( ChainError :: MissingMandatoryApplications ( app_ids) )
322360 if app_ids == vec![ application_id]
323361 ) ;
324-
325362 // But app operations continue to work.
326363 application. expect_call ( ExpectedCall :: execute_operation ( |_, _| Ok ( vec ! [ ] ) ) ) ;
327364 application. expect_call ( ExpectedCall :: default_finalize ( ) ) ;
328- let valid_block = make_child_block ( & value) . with_operation ( app_operation) ;
365+ application. expect_call ( ExpectedCall :: execute_operation ( |_, _| Ok ( vec ! [ ] ) ) ) ;
366+ application. expect_call ( ExpectedCall :: default_finalize ( ) ) ;
367+ let valid_block = make_child_block ( & value)
368+ . with_operation ( app_operation. clone ( ) )
369+ . with_operation ( another_app_operation. clone ( ) ) ;
329370 let outcome = chain
330371 . execute_block ( & valid_block, time, None , & [ ] , None )
331372 . await ?;
0 commit comments