diff --git a/linera-execution/tests/service_runtime_apis.rs b/linera-execution/tests/service_runtime_apis.rs index fb41f7e8d6e6..9fe0222e7fbc 100644 --- a/linera-execution/tests/service_runtime_apis.rs +++ b/linera-execution/tests/service_runtime_apis.rs @@ -85,6 +85,38 @@ async fn test_read_owner_balance_system_api( view.query_application(context, query, None).await.unwrap(); } +/// Tests if reading the balance of a missing account returns zero. +#[proptest(async = "tokio")] +async fn test_read_owner_balance_returns_zero_for_missing_accounts(missing_account: AccountOwner) { + let mut view = SystemExecutionState { + description: Some(ChainDescription::Root(0)), + ..SystemExecutionState::default() + } + .into_view() + .await; + + let (application_id, application) = view.register_mock_application().await.unwrap(); + + application.expect_call(ExpectedCall::handle_query( + move |runtime, _context, _query| { + assert_eq!( + runtime.read_owner_balance(missing_account).unwrap(), + Amount::ZERO + ); + Ok(vec![]) + }, + )); + application.expect_call(ExpectedCall::default_finalize()); + + let context = create_dummy_query_context(); + let query = Query::User { + application_id, + bytes: vec![], + }; + + view.query_application(context, query, None).await.unwrap(); +} + /// Tests the contract system API to read all account balances. #[proptest(async = "tokio")] async fn test_read_owner_balances_system_api(