Skip to content

Commit ec4b61c

Browse files
Move some tests to a separate directory. (#4406)
## Motivation Several tests have emerged that are unit test in nature but require a full application to be built. Currently, the source code of those tests is in `examples` which makes them sit alongside more functional applications that are of more general interest. ## Proposal The tests are moved to the directory `linera-sdk/tests/fixtures`. They are not part of the strusture of the cargo crate. The advantage is that those smart contracts are no longer compiled again and again (ScyllaDb, DynamoDb, StorageService, RemoteNet), and so we gain on CI here. The cost of compiling for tests in `--release` is about 2-3 minutes per such instance. The cost of running `linera-sdk/tests/fixtures` is 7 minutes, so overall, we have a speed gain from this work. ## Test Plan The CI. The same tests are being tested. The same tests are being applied, just differently ordered. ## Release Plan - Nothing to do / These changes follow the usual release cycle. ## Links None.
1 parent 25dbdb8 commit ec4b61c

File tree

41 files changed

+5630
-92
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+5630
-92
lines changed

.github/workflows/rust.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,29 @@ jobs:
139139
cd examples
140140
cargo test --locked
141141
142+
linera-sdk-tests-fixtures:
143+
needs: changed-files
144+
if: needs.changed-files.outputs.should-run == 'true'
145+
runs-on: ubuntu-latest
146+
timeout-minutes: 10
147+
148+
steps:
149+
- uses: actions/checkout@v4
150+
- uses: actions-rust-lang/setup-rust-toolchain@v1
151+
- name: Install Protoc
152+
uses: arduino/setup-protoc@v3
153+
with:
154+
repo-token: ${{ secrets.GITHUB_TOKEN }}
155+
- name: Run linera-sdk fixtures
156+
run: |
157+
cd linera-sdk/tests/fixtures
158+
cargo test --locked
159+
- name: Run linera-sdk tests application lints
160+
run: |
161+
cd linera-sdk/tests/fixtures
162+
cargo fmt -- --check
163+
cargo clippy --all-targets --all-features --target wasm32-unknown-unknown --locked
164+
142165
default-features-and-witty-integration-test:
143166
needs: changed-files
144167
if: needs.changed-files.outputs.should-run == 'true'

Cargo.lock

Lines changed: 1 addition & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ proptest = { version = "1.6.0", default-features = false, features = ["alloc"] }
176176
prost = "0.14"
177177
quick_cache = "0.6.13"
178178
quote = "1.0"
179-
rand = { version = "0.8.5", default-features = false }
179+
rand = { version = "0.8.5", default-features = false, features = ["std_rng"] }
180180
rand_chacha = { version = "0.3.1", default-features = false }
181181
rand_distr = { version = "0.4.3", default-features = false }
182182
rcgen = "0.12.1"
@@ -323,10 +323,10 @@ ethereum-tracker = { path = "./examples/ethereum-tracker" }
323323
fungible = { path = "./examples/fungible" }
324324
hex-game = { path = "./examples/hex-game" }
325325
matching-engine = { path = "./examples/matching-engine" }
326-
meta-counter = { path = "./examples/meta-counter" }
326+
meta-counter = { path = "./linera-sdk/tests/fixtures/meta-counter" }
327327
native-fungible = { path = "./examples/native-fungible" }
328328
non-fungible = { path = "./examples/non-fungible" }
329-
publish-read-data-blob = { path = "./examples/publish-read-data-blob" }
329+
publish-read-data-blob = { path = "./linera-sdk/tests/fixtures/publish-read-data-blob" }
330330
social = { path = "./examples/social" }
331331
track-instantiation = { path = "./examples/track-instantiation" }
332332

examples/Cargo.lock

Lines changed: 0 additions & 50 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/Cargo.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ resolver = "2"
33
members = [
44
"amm",
55
"call-evm-counter",
6-
"contract-call",
76
"counter",
87
"counter-no-graphql",
9-
"create-and-call",
108
"crowd-funding",
119
"ethereum-tracker",
1210
"fungible",
@@ -15,13 +13,10 @@ members = [
1513
"how-to/perform-http-requests",
1614
"llm",
1715
"matching-engine",
18-
"meta-counter",
1916
"native-fungible",
2017
"non-fungible",
21-
"publish-read-data-blob",
2218
"rfq",
2319
"social",
24-
"track-instantiation",
2520
]
2621

2722
[workspace.dependencies]

linera-execution/src/wasm/mod.rs

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ mod wasmer;
1919
#[cfg(with_wasmtime)]
2020
mod wasmtime;
2121

22+
#[cfg(with_fs)]
23+
use std::path::Path;
24+
2225
use linera_base::data_types::Bytecode;
2326
#[cfg(with_metrics)]
2427
use linera_base::prometheus_util::MeasureLatency as _;
@@ -94,7 +97,7 @@ impl WasmContractModule {
9497
/// Creates a new [`WasmContractModule`] using the WebAssembly module in `contract_bytecode_file`.
9598
#[cfg(with_fs)]
9699
pub async fn from_file(
97-
contract_bytecode_file: impl AsRef<std::path::Path>,
100+
contract_bytecode_file: impl AsRef<Path>,
98101
runtime: WasmRuntime,
99102
) -> Result<Self, WasmExecutionError> {
100103
Self::new(
@@ -156,7 +159,7 @@ impl WasmServiceModule {
156159
/// Creates a new [`WasmServiceModule`] using the WebAssembly module in `service_bytecode_file`.
157160
#[cfg(with_fs)]
158161
pub async fn from_file(
159-
service_bytecode_file: impl AsRef<std::path::Path>,
162+
service_bytecode_file: impl AsRef<Path>,
160163
runtime: WasmRuntime,
161164
) -> Result<Self, WasmExecutionError> {
162165
Self::new(
@@ -339,36 +342,48 @@ impl From<::wasmer::InstantiationError> for WasmExecutionError {
339342
/// This assumes that the current directory is one of the crates.
340343
#[cfg(with_testing)]
341344
pub mod test {
342-
use std::sync::LazyLock;
345+
use std::{path::Path, sync::LazyLock};
343346

344347
#[cfg(with_fs)]
345348
use super::{WasmContractModule, WasmRuntime, WasmServiceModule};
346349

347-
fn build_applications() -> Result<(), std::io::Error> {
348-
tracing::info!("Building example applications with cargo");
350+
fn build_applications_in_directory(dir: &str) -> Result<(), std::io::Error> {
349351
let output = std::process::Command::new("cargo")
350-
.current_dir("../examples")
352+
.current_dir(dir)
351353
.args(["build", "--release", "--target", "wasm32-unknown-unknown"])
352354
.output()?;
353-
assert!(
354-
output.status.success(),
355-
"Failed to build example applications.\n\n\
356-
stdout:\n-------\n{}\n\n\
357-
stderr:\n-------\n{}",
358-
String::from_utf8_lossy(&output.stdout),
359-
String::from_utf8_lossy(&output.stderr),
360-
);
355+
if !output.status.success() {
356+
panic!(
357+
"Failed to build applications in directory {dir}.\n\n\
358+
stdout:\n-------\n{}\n\n\
359+
stderr:\n-------\n{}",
360+
String::from_utf8_lossy(&output.stdout),
361+
String::from_utf8_lossy(&output.stderr),
362+
);
363+
}
364+
Ok(())
365+
}
366+
367+
fn build_applications() -> Result<(), std::io::Error> {
368+
for dir in ["../examples", "../linera-sdk/tests/fixtures"] {
369+
build_applications_in_directory(dir)?;
370+
}
361371
Ok(())
362372
}
363373

364374
pub fn get_example_bytecode_paths(name: &str) -> Result<(String, String), std::io::Error> {
365375
let name = name.replace('-', "_");
366376
static INSTANCE: LazyLock<()> = LazyLock::new(|| build_applications().unwrap());
367377
LazyLock::force(&INSTANCE);
368-
Ok((
369-
format!("../examples/target/wasm32-unknown-unknown/release/{name}_contract.wasm"),
370-
format!("../examples/target/wasm32-unknown-unknown/release/{name}_service.wasm"),
371-
))
378+
for dir in ["../examples", "../linera-sdk/tests/fixtures"] {
379+
let prefix = format!("{dir}/target/wasm32-unknown-unknown/release");
380+
let file_contract = format!("{prefix}/{name}_contract.wasm");
381+
let file_service = format!("{prefix}/{name}_service.wasm");
382+
if Path::new(&file_contract).exists() && Path::new(&file_service).exists() {
383+
return Ok((file_contract, file_service));
384+
}
385+
}
386+
Err(std::io::Error::last_os_error())
372387
}
373388

374389
#[cfg(with_fs)]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/target/
2+
.DS_Store

0 commit comments

Comments
 (0)