Skip to content

Commit 0453927

Browse files
authored
Fix inclusion of service-as-oracle tests in linera-chain (#3583)
## Motivation On `main`, running `cargo test -p linera-chain` fails to compile. That happens because some tests assume that the `linera-execution/unstable-oracles` feature flag was always enabled. CI failed to catch this because all tests are currently being executing with that feature enabled. ## Proposal Only include those tests if a new `linera-chain/unstable-oracles` feature is enabled, which is enabled if `linera-core/unstable-oracles` is enabled. ## Test Plan Ran `cargo test -p linera-chain` and `cargo test -p linera-chain --features unstable-oracles` manually. CI was not updated because the current plan is to remove `unstable-oracles` in the next few days (#3524). ## Release Plan - Nothing to do, because this only affects tests. ## Links - [reviewer checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist)
1 parent a2a810d commit 0453927

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

linera-chain/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ test = ["tokio/macros", "linera-base/test", "linera-execution/test"]
1616
metrics = ["prometheus", "linera-views/metrics", "linera-execution/metrics"]
1717
web = ["linera-base/web", "linera-views/web", "linera-execution/web"]
1818
benchmark = ["linera-base/test"]
19+
unstable-oracles = ["linera-execution/unstable-oracles"]
1920

2021
[dependencies]
2122
async-graphql.workspace = true

linera-chain/src/unit_tests/chain_tests.rs

+18-8
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33

44
#![allow(clippy::large_futures)]
55

6+
use std::{collections::BTreeMap, iter};
7+
#[cfg(feature = "unstable-oracles")]
68
use std::{
7-
collections::BTreeMap,
8-
iter, thread,
9+
thread,
910
time::{Duration, Instant},
1011
};
1112

@@ -25,20 +26,25 @@ use linera_execution::{
2526
committee::{Committee, Epoch, ValidatorState},
2627
system::{OpenChainConfig, Recipient},
2728
test_utils::{ExpectedCall, MockApplication},
28-
ContractRuntime, ExecutionError, ExecutionRuntimeConfig, ExecutionRuntimeContext, Message,
29-
MessageKind, Operation, ResourceControlPolicy, ServiceRuntime, SystemMessage, SystemOperation,
30-
TestExecutionRuntimeContext,
29+
ExecutionError, ExecutionRuntimeConfig, ExecutionRuntimeContext, Message, MessageKind,
30+
Operation, ResourceControlPolicy, SystemMessage, SystemOperation, TestExecutionRuntimeContext,
3131
};
32+
#[cfg(feature = "unstable-oracles")]
33+
use linera_execution::{ContractRuntime, ServiceRuntime};
34+
#[cfg(feature = "unstable-oracles")]
35+
use linera_views::{context::ViewContext, memory::MemoryStore};
3236
use linera_views::{
33-
context::{Context as _, MemoryContext, ViewContext},
34-
memory::MemoryStore,
37+
context::{Context as _, MemoryContext},
3538
views::{View, ViewError},
3639
};
40+
#[cfg(feature = "unstable-oracles")]
3741
use test_case::test_case;
3842

43+
#[cfg(feature = "unstable-oracles")]
44+
use crate::data_types::ProposedBlock;
3945
use crate::{
4046
block::{Block, ConfirmedBlock},
41-
data_types::{IncomingBundle, MessageAction, MessageBundle, Origin, ProposedBlock},
47+
data_types::{IncomingBundle, MessageAction, MessageBundle, Origin},
4248
test::{make_child_block, make_first_block, BlockTestExt, MessageTestExt},
4349
ChainError, ChainExecutionContext, ChainStateView,
4450
};
@@ -286,6 +292,7 @@ async fn test_application_permissions() -> anyhow::Result<()> {
286292
}
287293

288294
/// Tests if services can execute as oracles if the total execution time is less than the limit.
295+
#[cfg(feature = "unstable-oracles")]
289296
#[test_case(&[100]; "single service as oracle call")]
290297
#[test_case(&[50, 50]; "two service as oracle calls")]
291298
#[test_case(&[90, 10]; "long and short service as oracle calls")]
@@ -324,6 +331,7 @@ async fn test_service_as_oracles(service_oracle_execution_times_ms: &[u64]) -> a
324331
}
325332

326333
/// Tests if execution fails if services executing as oracles exceed the time limit.
334+
#[cfg(feature = "unstable-oracles")]
327335
#[test_case(&[120]; "single service as oracle call")]
328336
#[test_case(&[60, 60]; "two service as oracle calls")]
329337
#[test_case(&[105, 15]; "long and short service as oracle calls")]
@@ -380,6 +388,7 @@ async fn test_service_as_oracle_exceeding_time_limit(
380388
/// Creates and initializes a [`ChainStateView`] configured with the
381389
/// `maximum_service_oracle_execution_ms` policy. Registers the dummy application on the chain, and
382390
/// creates a block proposal with a dummy operation.
391+
#[cfg(feature = "unstable-oracles")]
383392
async fn prepare_test_with_dummy_mock_application(
384393
maximum_service_oracle_execution_ms: u64,
385394
) -> anyhow::Result<(
@@ -445,6 +454,7 @@ async fn prepare_test_with_dummy_mock_application(
445454
}
446455

447456
/// Tests if execution fails early if services call `check_execution_time`.
457+
#[cfg(feature = "unstable-oracles")]
448458
#[test_case(&[120]; "single service as oracle call")]
449459
#[test_case(&[60, 60]; "two service as oracle calls")]
450460
#[test_case(&[105, 15]; "long and short service as oracle calls")]

linera-core/Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ rocksdb = ["linera-views/rocksdb"]
3131
dynamodb = ["linera-views/dynamodb"]
3232
scylladb = ["linera-views/scylladb"]
3333
storage-service = ["linera-storage-service"]
34-
unstable-oracles = ["linera-execution/unstable-oracles"]
34+
unstable-oracles = [
35+
"linera-chain/unstable-oracles",
36+
"linera-execution/unstable-oracles",
37+
]
3538
metrics = [
3639
"prometheus",
3740
"linera-base/metrics",

0 commit comments

Comments
 (0)