Skip to content

Commit

Permalink
Test reading the balance of a missing account
Browse files Browse the repository at this point in the history
The system API should fallback and return zero in that case.
  • Loading branch information
jvff committed Nov 28, 2024
1 parent 60c7b13 commit 7b3f1bc
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions linera-execution/tests/service_runtime_apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 7b3f1bc

Please sign in to comment.