Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Radix-engine-tests reorganisation #1656

Merged
merged 24 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 3 additions & 2 deletions check_stack_usage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
set -e

PACKAGE=radix-engine-tests
EXEC=arguments
TARGET=system
FILE=arguments
TEST=vector_of_buckets_argument_should_succeed

# Return error if stack usage greater than
Expand All @@ -23,7 +24,7 @@ function get_stack_usage() {
stack=$(( $low + ($high - $low) / 2))
echo checking stack $stack

if RUST_MIN_STACK=$stack cargo test -p $PACKAGE --test $EXEC -- $TEST >$output 2>&1 ; then
if RUST_MIN_STACK=$stack cargo test -p $PACKAGE --test $TARGET $FILE::$TEST -- >$output 2>&1 ; then
if grep 'stack overflow' $output ; then
cat $output
echo "unexpected error occurred"
Expand Down
12 changes: 8 additions & 4 deletions radix-engine-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ utils = { path = "../utils", default-features = false }
radix-engine-profiling = { path = "../radix-engine-profiling", optional = true, features = ["resource_tracker"]}
resources-tracker-macro = { path = "../radix-engine-profiling/resources-tracker-macro" }
scrypto-test = { path = "../scrypto-test", default-features = false }
scrypto-unit = { path = "../scrypto-unit", default-features = false }

[dev-dependencies]
transaction = { path = "../transaction", default-features = false }
wabt = { version = "0.10.0" }
criterion = { version = "0.3", features = ["html_reports"] }
scrypto = { path = "../scrypto", default-features = false }
sbor-derive = { path = "../sbor-derive", default-features = false }
scrypto-unit = { path = "../scrypto-unit", default-features = false }
rand = { version = "0.8.5" }
rand_chacha = { version = "0.3.1" }
rayon = "1.5.3"
Expand All @@ -37,8 +37,8 @@ walkdir = { version = "2.3.3" }
paste = { version = "1.0.13" }
lazy_static = { version = "1.4.0" }
hex = { version = "0.4.3", default-features = false }
tuple-return = { path = "./tests/blueprints/tuple-return", features = ["test"], default-features = false }
trybuild = { version = "1.0.85" }
automod = "1.0.13"

[build-dependencies]
walkdir = { version = "2.3.3", optional = true }
Expand Down Expand Up @@ -71,11 +71,15 @@ harness = false
name = "transaction_validation"
harness = false

[lib]
bench = false
test = false

[features]
# You should enable either `std` or `alloc`
default = ["std"]
std = ["sbor/std", "transaction/std", "transaction-scenarios/std", "radix-engine/std", "radix-engine/moka", "radix-engine-interface/std", "radix-engine-stores/std", "radix-engine-store-interface/std", "radix-engine-queries/std", "utils/std", "scrypto/std", "scrypto-unit/std", "scrypto-test/std", "scrypto-test/moka", "tuple-return/std"]
alloc = ["sbor/alloc", "transaction/alloc", "transaction-scenarios/alloc", "radix-engine/alloc", "radix-engine/lru", "radix-engine-interface/alloc", "radix-engine-stores/alloc", "radix-engine-store-interface/alloc", "radix-engine-queries/alloc", "utils/alloc", "scrypto/alloc", "scrypto-unit/alloc", "scrypto-test/alloc", "scrypto-test/lru", "tuple-return/alloc"]
std = ["sbor/std", "transaction/std", "transaction-scenarios/std", "radix-engine/std", "radix-engine/moka", "radix-engine-interface/std", "radix-engine-stores/std", "radix-engine-store-interface/std", "radix-engine-queries/std", "utils/std", "scrypto/std", "scrypto-unit/std", "scrypto-test/std", "scrypto-test/moka"]
alloc = ["sbor/alloc", "transaction/alloc", "transaction-scenarios/alloc", "radix-engine/alloc", "radix-engine/lru", "radix-engine-interface/alloc", "radix-engine-stores/alloc", "radix-engine-store-interface/alloc", "radix-engine-queries/alloc", "utils/alloc", "scrypto/alloc", "scrypto-unit/alloc", "scrypto-test/alloc", "scrypto-test/lru"]
wasmer = ["radix-engine/wasmer"]
cpu_ram_metrics = ["radix-engine/cpu_ram_metrics"]
flamegraph = []
Expand Down
28 changes: 28 additions & 0 deletions radix-engine-tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Tests organization

`test` subdirecotry containg integration tests is divided according to execution layers using following subfolders:

- Application
- Blueprints
- System
- VM
- Kernel
- Db

Additional assets required by some of the tests are stored in `assets` subdirectory:

- `blueprints` all blueprints projects used during the tests
- `metering` used to store costs metering tests csv files
- `wasm` containing web assembly modules in wat file format

# Tests execution

To execute all tests run command: `cargo nextest run` or `cargo test` from `radix-engine-tests` directory or subdirectory.

To execute tests for a specific layer run command: `cargo nextest run --test LAYER_NAME` or `cargo test --test LAYER_NAME`, example: `cargo nextest run --test kernel`, `cargo nextest run --test kernel --test system`.

To execute tests from specific file run command: `cargo nextest run --test LAYER_NAME FILE_NAME`, example: `cargo nextest run --test kernel frame` (this will also run tests which include `frame` word). Alternatively name filtering can be used: `cargo test LAYER_NAME::FILE_NAME::`, example: `cargo nextest run kernel::frame::`.

# Benches

`radix-engine-tests` project contains also some benches in `benches` subdirectory. They can be executed using command: `cargo bench`.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ members = [
"transaction_limits",
"transaction_runtime",
"tx_processor_access",
"tuple-return",
"events",
"events_invalid",
"logger",
Expand Down
24 changes: 13 additions & 11 deletions radix-engine-tests/benches/costing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use radix_engine::{
},
};
use radix_engine_queries::typed_substate_layout::{CodeHash, PackageDefinition};
use radix_engine_tests::common::*;
use sbor::rust::iter;
use scrypto_unit::TestRunnerBuilder;
use transaction::{
Expand All @@ -22,15 +23,15 @@ use transaction::{
use wabt::wat2wasm;

fn bench_decode_sbor(c: &mut Criterion) {
let payload = include_bytes!("../../assets/radiswap.rpd");
let payload = include_workspace_asset_bytes!("radiswap.rpd");
println!("Payload size: {}", payload.len());
c.bench_function("costing::decode_sbor", |b| {
b.iter(|| manifest_decode::<ManifestValue>(payload))
});
}

fn bench_decode_sbor_bytes(c: &mut Criterion) {
let payload = manifest_encode(include_bytes!("../../assets/radiswap.rpd")).unwrap();
let payload = manifest_encode(include_workspace_asset_bytes!("radiswap.rpd")).unwrap();
println!("Payload size: {}", payload.len());
c.bench_function("costing::decode_sbor_bytes", |b| {
b.iter(|| manifest_decode::<ManifestValue>(&payload))
Expand All @@ -39,7 +40,8 @@ fn bench_decode_sbor_bytes(c: &mut Criterion) {

fn bench_validate_sbor_payload(c: &mut Criterion) {
let package_definition =
manifest_decode::<PackageDefinition>(include_bytes!("../../assets/radiswap.rpd")).unwrap();
manifest_decode::<PackageDefinition>(include_workspace_asset_bytes!("radiswap.rpd"))
.unwrap();
let payload = scrypto_encode(&package_definition).unwrap();
println!("Payload size: {}", payload.len());
let (index, schema) =
Expand All @@ -59,7 +61,7 @@ fn bench_validate_sbor_payload(c: &mut Criterion) {
}

fn bench_validate_sbor_payload_bytes(c: &mut Criterion) {
let payload = scrypto_encode(include_bytes!("../../assets/radiswap.rpd")).unwrap();
let payload = scrypto_encode(include_workspace_asset_bytes!("radiswap.rpd")).unwrap();
println!("Payload size: {}", payload.len());
let (index, schema) = generate_full_schema_from_single_type::<Vec<u8>, ScryptoCustomSchema>();

Expand Down Expand Up @@ -92,7 +94,7 @@ fn bench_validate_secp256k1(c: &mut Criterion) {

fn bench_spin_loop(c: &mut Criterion) {
// Prepare code
let code = wat2wasm(&include_str!("../tests/wasm/loop.wat").replace("${n}", "100000")).unwrap();
let code = wat2wasm(&include_local_wasm_str!("loop.wat").replace("${n}", "100000")).unwrap();

// Instrument
let validator = WasmValidator::default();
Expand Down Expand Up @@ -140,7 +142,7 @@ macro_rules! bench_instantiate {
paste! {
fn [< bench_instantiate_ $what >] (c: &mut Criterion) {
// Prepare code
let code = include_bytes!(concat!("../../assets/", $what, ".wasm"));
let code = include_workspace_asset_bytes!(concat!($what, ".wasm"));

// Instrument
let validator = WasmValidator::default();
Expand All @@ -167,9 +169,9 @@ bench_instantiate!("radiswap");
bench_instantiate!("flash_loan");

fn bench_validate_wasm(c: &mut Criterion) {
let code = include_bytes!("../../assets/radiswap.wasm");
let code = include_workspace_asset_bytes!("radiswap.wasm");
let definition: PackageDefinition =
manifest_decode(include_bytes!("../../assets/radiswap.rpd")).unwrap();
manifest_decode(include_workspace_asset_bytes!("radiswap.rpd")).unwrap();

c.bench_function("costing::validate_wasm", |b| {
b.iter(|| {
Expand All @@ -183,7 +185,7 @@ fn bench_validate_wasm(c: &mut Criterion) {
}

fn bench_deserialize_wasm(c: &mut Criterion) {
let code = include_bytes!("../../assets/radiswap.wasm");
let code = include_workspace_asset_bytes!("radiswap.wasm");

c.bench_function("costing::deserialize_wasm", |b| {
b.iter(|| WasmModule::init(code).unwrap())
Expand All @@ -192,9 +194,9 @@ fn bench_deserialize_wasm(c: &mut Criterion) {

fn bench_prepare_wasm(c: &mut Criterion) {
let mut test_runner = TestRunnerBuilder::new().without_trace().build();
let code = include_bytes!("../../assets/radiswap.wasm").to_vec();
let code = include_workspace_asset_bytes!("radiswap.wasm").to_vec();
let package_definition: PackageDefinition =
manifest_decode(include_bytes!("../../assets/radiswap.rpd")).unwrap();
manifest_decode(include_workspace_asset_bytes!("radiswap.rpd")).unwrap();

c.bench_function("costing::bench_prepare_wasm", |b| {
b.iter(|| {
Expand Down
5 changes: 3 additions & 2 deletions radix-engine-tests/benches/radiswap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use radix_engine::vm::NoExtension;
use radix_engine_stores::memory_db::InMemorySubstateDatabase;
#[cfg(feature = "rocksdb")]
use radix_engine_stores::rocks_db_with_merkle_tree::RocksDBWithMerkleTreeSubstateStore;
use radix_engine_tests::common::*;
use scrypto_unit::{TestRunner, TestRunnerBuilder};
#[cfg(feature = "rocksdb")]
use std::path::PathBuf;
Expand Down Expand Up @@ -45,8 +46,8 @@ fn bench_radiswap(c: &mut Criterion) {
let (pk, _, account) = test_runner.new_allocated_account();
let package_address = test_runner.publish_package(
(
include_bytes!("../../assets/radiswap.wasm").to_vec(),
manifest_decode(include_bytes!("../../assets/radiswap.rpd")).unwrap(),
include_workspace_asset_bytes!("radiswap.wasm").to_vec(),
manifest_decode(include_workspace_asset_bytes!("radiswap.rpd")).unwrap(),
),
btreemap!(),
OwnerRole::Updatable(rule!(require(NonFungibleGlobalId::from_public_key(&pk)))),
Expand Down
2 changes: 1 addition & 1 deletion radix-engine-tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn main() {
use scrypto::prelude::*;

let manifest_dir = PathBuf::from_str(env!("CARGO_MANIFEST_DIR")).unwrap();
let blueprints_dir = manifest_dir.join("tests").join("blueprints");
let blueprints_dir = manifest_dir.join("assets").join("blueprints");
println!("cargo:rerun-if-changed=\"{:?}\"", blueprints_dir);

let mut packages = HashMap::new();
Expand Down
122 changes: 122 additions & 0 deletions radix-engine-tests/src/common.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#[cfg(feature = "compile-blueprints-at-build-time")]
#[allow(unused)]
pub mod package_loader {
use radix_engine_common::prelude::*;
use radix_engine_queries::typed_substate_layout::*;

const PACKAGES_BINARY: &[u8] =
include_bytes!(concat!(env!("OUT_DIR"), "/compiled_packages.bin"));

lazy_static::lazy_static! {
static ref PACKAGES: HashMap<String, (Vec<u8>, PackageDefinition)> = {
scrypto_decode(PACKAGES_BINARY).unwrap()
};
}

pub struct PackageLoader;
impl PackageLoader {
pub fn get(name: &str) -> (Vec<u8>, PackageDefinition) {
if let Some(rtn) = PACKAGES.get(name) {
rtn.clone()
} else {
panic!("Package \"{}\" not found. Are you sure that this package is: a) in the blueprints folder, b) that this is the same as the package name in the Cargo.toml file?", name)
}
}
}
}

#[cfg(not(feature = "compile-blueprints-at-build-time"))]
#[allow(unused)]
pub mod package_loader {
use radix_engine_common::prelude::*;
use radix_engine_queries::typed_substate_layout::*;
use std::path::PathBuf;

pub struct PackageLoader;
impl PackageLoader {
pub fn get(name: &str) -> (Vec<u8>, PackageDefinition) {
let manifest_dir = PathBuf::from_str(env!("CARGO_MANIFEST_DIR")).unwrap();
let package_dir = manifest_dir.join("assets").join("blueprints").join(name);
scrypto_unit::Compile::compile(package_dir)
}
}
}

pub use package_loader::PackageLoader;

/// Defines globally for all tests paths for various assets used during the tests and benches.
/// To use it in a test definition file include following statement:
/// use radix_engine_tests::common::*;
pub mod path_macros {

#[macro_export]
macro_rules! include_workspace_asset_bytes {
($name: expr) => {
include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../assets/", $name))
};
}

#[macro_export]
macro_rules! include_workspace_transaction_examples_str {
($name: expr) => {
include_str!(path_workspace_transaction_examples!($name))
};
}

#[macro_export]
macro_rules! path_workspace_blueprint {
($name: expr) => {
concat!(env!("CARGO_MANIFEST_DIR"), "/../assets/blueprints/", $name)
};
}

#[macro_export]
macro_rules! path_workspace_transaction_examples {
($name: expr) => {
concat!(
env!("CARGO_MANIFEST_DIR"),
"/../transaction/examples/",
$name
)
};
}

#[macro_export]
macro_rules! include_local_wasm_str {
($name: expr) => {
include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/assets/wasm/", $name))
};
}

#[macro_export]
macro_rules! include_local_meterng_csv_str {
($name: expr) => {
include_str!(path_local_meterng_csv!($name))
};
}

#[macro_export]
macro_rules! path_local_blueprint {
($name: expr) => {
concat!(env!("CARGO_MANIFEST_DIR"), "/assets/blueprints/", $name)
};
}

#[macro_export]
macro_rules! path_local_meterng_csv {
($name: expr) => {
concat!(env!("CARGO_MANIFEST_DIR"), "/assets/metering/", $name)
};
}

pub use crate::include_local_meterng_csv_str;
pub use crate::include_local_wasm_str;
pub use crate::include_workspace_asset_bytes;
pub use crate::include_workspace_transaction_examples_str;
pub use crate::path_local_blueprint;
pub use crate::path_local_meterng_csv;
pub use crate::path_workspace_blueprint;
pub use crate::path_workspace_transaction_examples;
}

pub use path_macros::*;
2 changes: 2 additions & 0 deletions radix-engine-tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Provides assets paths to benchmarks.
pub mod common;
3 changes: 3 additions & 0 deletions radix-engine-tests/tests/application.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod application {
automod::dir!("tests/application");
}
Loading
Loading