Skip to content

Commit

Permalink
replace use of lazy_static_include_bytes in tests with std::fs::read (#…
Browse files Browse the repository at this point in the history
…6729)

Replace use of `lazy_static_include_bytes` in tests with `std::fs::read`

Since we don’t need to include test data files in test binaries,
prefer reading the files via `std::fs::read` rather than using
`lazy_static_include_bytes`.  In release builds the latter results in
the file being read at compilation which is a waste of time.

Fixes: #6665
  • Loading branch information
abhijeetbhagat committed May 1, 2022
1 parent d92234c commit 960c8eb
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 19 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion genesis-tools/genesis-csv-to-json/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ near-network-primitives = { path = "../../chain/network-primitives" }
tempfile = "3"
serde_json = "^1.0.41"
serde = "^1.0.102"
lazy-static-include = "3"
9 changes: 5 additions & 4 deletions genesis-tools/genesis-csv-to-json/src/csv_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ fn account_records(row: &Row, gas_price: Balance) -> Vec<StateRecord> {

#[cfg(test)]
mod tests {
use std::path::Path;

use chrono::TimeZone;
use csv::WriterBuilder;
use tempfile::NamedTempFile;
Expand Down Expand Up @@ -342,9 +344,8 @@ mod tests {

#[test]
fn test_res_file() {
lazy_static_include::lazy_static_include_bytes! {
RES => "res/test_accounts.csv"
}
keys_to_state_records(&RES[..], 1).unwrap();
let path = Path::new(env!("CARGO_MANIFEST_DIR")).join("res/test_accounts.csv");
let res = std::fs::read(path).unwrap();
keys_to_state_records(&res[..], 1).unwrap();
}
}
13 changes: 7 additions & 6 deletions nearcore/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1493,14 +1493,15 @@ fn test_init_config_localnet() {
/// correctly parsed and defaults being applied correctly applied.
#[test]
fn test_config_from_file() {
lazy_static_include::lazy_static_include_bytes! {
EXAMPLE_CONFIG_GC => "res/example-config-gc.json",
EXAMPLE_CONFIG_NO_GC => "res/example-config-no-gc.json",
};
let base = Path::new(env!("CARGO_MANIFEST_DIR"));

for (has_gc, data) in [(true, &EXAMPLE_CONFIG_GC[..]), (false, &EXAMPLE_CONFIG_NO_GC[..])] {
for (has_gc, path) in
[(true, "res/example-config-gc.json"), (false, "res/example-config-no-gc.json")]
{
let path = base.join(path);
let data = std::fs::read(path).unwrap();
let tmp = tempfile::NamedTempFile::new().unwrap();
tmp.as_file().write_all(data).unwrap();
tmp.as_file().write_all(&data).unwrap();

let config = Config::from_file(&tmp.into_temp_path()).unwrap();

Expand Down
1 change: 0 additions & 1 deletion runtime/near-vm-runner-standalone/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ serde = { version = "1", features = ["derive"] }
serde_json = "1"
clap = { version = "3.1.6", features = ["derive"] }
base64 = "0.13"
lazy-static-include = "3"
num-rational = "0.3"
tracing-span-tree = "0.1"
rayon = "1.0"
Expand Down
9 changes: 4 additions & 5 deletions runtime/near-vm-runner-standalone/src/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,6 @@ fn profile_data_is_per_outcome() {
#[cfg(feature = "no_cache")]
#[test]
fn test_evm_slow_deserialize_repro() {
lazy_static_include::lazy_static_include_bytes! {
ZOMBIE_OWNERSHIP_BIN => "../near-test-contracts/res/ZombieOwnership.bin",
};

fn evm_slow_deserialize_repro(vm_kind: VMKind) {
println!("evm_slow_deserialize_repro of {:?}", &vm_kind);
tracing_span_tree::span_tree().enable();
Expand All @@ -265,7 +261,10 @@ fn test_evm_slow_deserialize_repro() {
let contract =
script.contract_from_file(Path::new("../near-test-contracts/res/near_evm.wasm"));

let input = hex::decode(&ZOMBIE_OWNERSHIP_BIN[..]).unwrap();
let path = Path::new(env!("CARGO_MANIFEST_DIR"))
.join("../near-test-contracts/res/ZombieOwnership.bin");
let zombie_ownership_bin = std::fs::read(path).unwrap();
let input = hex::decode(&zombie_ownership_bin[..]).unwrap();
script.step(contract, "deploy_code").input(input).repeat(3);
let res = script.run();
assert_eq!(res.outcomes[0].error(), None);
Expand Down

0 comments on commit 960c8eb

Please sign in to comment.