Skip to content

Commit

Permalink
Test read_balance_owners service runtime API
Browse files Browse the repository at this point in the history
Ensure applications can read a list of all accounts.
  • Loading branch information
jvff committed Nov 28, 2024
1 parent 8a38f36 commit 60c7b13
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion linera-execution/tests/service_runtime_apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

#![allow(clippy::field_reassign_with_default)]

use std::{collections::BTreeMap, vec};
use std::{
collections::{BTreeMap, HashSet},
vec,
};

use linera_base::{
data_types::Amount,
Expand Down Expand Up @@ -120,3 +123,42 @@ async fn test_read_owner_balances_system_api(

view.query_application(context, query, None).await.unwrap();
}

/// Tests the contract system API to read all account owners.
#[proptest(async = "tokio")]
async fn test_read_balance_owners_system_api(
#[strategy(test_accounts_strategy())] accounts: BTreeMap<AccountOwner, Amount>,
) {
let mut view = SystemExecutionState {
description: Some(ChainDescription::Root(0)),
balances: accounts.clone(),
..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_balance_owners()
.unwrap()
.into_iter()
.collect::<HashSet<_>>(),
accounts.keys().copied().collect::<HashSet<_>>()
);
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();
}

0 comments on commit 60c7b13

Please sign in to comment.