diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b7ce905685..5180dcc76a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -200,6 +200,8 @@ jobs: run: | cargo test -p radix-engine-monkey-tests --features std,rocksdb,post_run_db_check,resource_tracker --no-run --locked cargo test -p radix-engine-profiling --all-features --no-run --locked + - name: Build with fuzzing feature + run: cargo build --features fuzzing radix-engine-test: name: Run Radix Engine tests diff --git a/build.sh b/build.sh index c747a80334..9a5431f218 100755 --- a/build.sh +++ b/build.sh @@ -9,6 +9,7 @@ echo "Building the workspace packages and tests (with all extended features)..." (set -x; cargo build; cargo test --no-run; cargo bench --no-run) (set -x; cargo build -p radix-engine-profiling --all-features; cargo test -p radix-engine-profiling --all-features --no-run; cargo bench -p radix-engine-profiling --all-features --no-run) +(set -x; cargo build --features fuzzing) echo "Building scrypto packages and tests using cargo build, to catch errors quickly..." diff --git a/radix-common/src/data/manifest/model/manifest_address.rs b/radix-common/src/data/manifest/model/manifest_address.rs index e9707e92a8..ac9acc2b23 100644 --- a/radix-common/src/data/manifest/model/manifest_address.rs +++ b/radix-common/src/data/manifest/model/manifest_address.rs @@ -40,6 +40,7 @@ impl ManifestAddress { as_ref = "&ManifestAddress::Named(*self)", from_value = "value.into_named().ok_or(DecodeError::InvalidCustomValue)?" )] +#[cfg_attr(feature = "fuzzing", derive(Arbitrary))] pub struct ManifestNamedAddress(pub u32); pub const MANIFEST_ADDRESS_DISCRIMINATOR_STATIC: u8 = 0u8; diff --git a/radix-common/src/data/scrypto/model/non_fungible_local_id.rs b/radix-common/src/data/scrypto/model/non_fungible_local_id.rs index b0c44b6f78..8515cc8c44 100644 --- a/radix-common/src/data/scrypto/model/non_fungible_local_id.rs +++ b/radix-common/src/data/scrypto/model/non_fungible_local_id.rs @@ -3,7 +3,7 @@ use crate::data::scrypto::model::*; use crate::data::scrypto::*; use crate::*; #[cfg(feature = "fuzzing")] -use arbitrary::{Arbitrary, Result, Unstructured}; +use arbitrary::{Arbitrary, Unstructured}; use radix_rust::copy_u8_array; use sbor::rust::prelude::*; use sbor::*; @@ -227,7 +227,7 @@ impl StringNonFungibleLocalId { #[cfg(feature = "fuzzing")] impl<'a> Arbitrary<'a> for StringNonFungibleLocalId { - fn arbitrary(u: &mut Unstructured<'a>) -> Result { + fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result { let charset: Vec = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWZYZ012345678989_" .chars() @@ -308,7 +308,7 @@ impl BytesNonFungibleLocalId { #[cfg(feature = "fuzzing")] impl<'a> Arbitrary<'a> for BytesNonFungibleLocalId { - fn arbitrary(u: &mut Unstructured<'a>) -> Result { + fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result { let len: u8 = u .int_in_range(1..=NON_FUNGIBLE_LOCAL_ID_MAX_LENGTH as u8) .unwrap(); diff --git a/radix-engine-interface/src/blueprints/resource/non_fungible/non_fungible_resource_manager.rs b/radix-engine-interface/src/blueprints/resource/non_fungible/non_fungible_resource_manager.rs index e88e9a6a90..d9a76d2da8 100644 --- a/radix-engine-interface/src/blueprints/resource/non_fungible/non_fungible_resource_manager.rs +++ b/radix-engine-interface/src/blueprints/resource/non_fungible/non_fungible_resource_manager.rs @@ -420,15 +420,15 @@ impl<'a> Arbitrary<'a> for NonFungibleDataSchema { // ScryptoSchema, therefore implementing arbitrary by hand. // TODO: Introduce a method that genearates NonFungibleDataSchema in a truly random manner fn arbitrary(_u: &mut Unstructured<'a>) -> Result { - Ok(Self::Local { - schema: VersionedSchema::V1(SchemaV1 { + Ok(Self::Local(LocalNonFungibleDataSchema { + schema: VersionedScryptoSchema::from_latest_version(SchemaV1 { type_kinds: vec![], type_metadata: vec![], type_validations: vec![], }), type_id: LocalTypeId::WellKnown(sbor::basic_well_known_types::UNIT_TYPE), mutable_fields: indexset!(), - }) + })) } } diff --git a/radix-engine-toolkit-common/src/receipt/receipt/runtime.rs b/radix-engine-toolkit-common/src/receipt/receipt/runtime.rs index b6fe00066e..2de554900f 100644 --- a/radix-engine-toolkit-common/src/receipt/receipt/runtime.rs +++ b/radix-engine-toolkit-common/src/receipt/receipt/runtime.rs @@ -130,7 +130,7 @@ impl TryFrom for RuntimeToolkitTransactionReceipt { .collect(), // We get the newly minted non-fungibles from the events. newly_minted_non_fungibles: application_events.iter().fold( - IndexSet::new(), + index_set_new(), |mut acc, (EventTypeIdentifier(emitter, event_name), event_data)| { match emitter { Emitter::Method(node_id, ModuleId::Main) => { @@ -234,7 +234,7 @@ fn get_metadata_updates( .map(|partition_state_updates| (node_id, partition_state_updates)) }) .fold( - IndexMap::new(), + index_map_new(), |mut acc, (node_id, partition_state_updates)| { acc.entry(*node_id).or_default().extend( partition_state_updates diff --git a/radix-transactions/src/manifest/ast.rs b/radix-transactions/src/manifest/ast.rs index 6918aa9c50..4e5664600f 100644 --- a/radix-transactions/src/manifest/ast.rs +++ b/radix-transactions/src/manifest/ast.rs @@ -1,10 +1,11 @@ use crate::manifest::token::Span; use radix_common::data::manifest::{ManifestCustomValueKind, ManifestValueKind}; -use strum::{EnumCount, EnumDiscriminants}; +use strum::{EnumCount, EnumDiscriminants, FromRepr}; use super::generator::*; #[derive(Debug, Clone, PartialEq, Eq, EnumDiscriminants, EnumCount)] +#[strum_discriminants(derive(FromRepr))] pub enum Instruction { //======================================== // PSEUDO-INSTRUCTIONS AT THE START diff --git a/radix-transactions/src/manifest/generator.rs b/radix-transactions/src/manifest/generator.rs index e51656c644..c1d2fc8585 100644 --- a/radix-transactions/src/manifest/generator.rs +++ b/radix-transactions/src/manifest/generator.rs @@ -2633,9 +2633,9 @@ mod tests { .try_into() .unwrap() ), - IndexMap::::new(), - IndexMap::::new(), - IndexMap::::new(), + IndexMap::::new(), + IndexMap::::new(), + IndexMap::::new(), RoleAssignmentInit::new() ) .into(), @@ -2807,13 +2807,13 @@ mod tests { "name" => "Token".to_string(), locked; } }, - entries: IndexMap::from([( - NonFungibleLocalId::integer(1), + entries: indexmap!( + NonFungibleLocalId::integer(1) => (to_manifest_value_and_unwrap!(&( String::from("Hello World"), dec!("12") )),), - )]), + ), address_reservation: None, } ), @@ -2931,13 +2931,13 @@ mod tests { address: resource_address.into(), method_name: NON_FUNGIBLE_RESOURCE_MANAGER_MINT_IDENT.to_string(), args: to_manifest_value_and_unwrap!(&NonFungibleResourceManagerMintManifestInput { - entries: IndexMap::from([( - NonFungibleLocalId::integer(1), + entries: indexmap!( + NonFungibleLocalId::integer(1) => (to_manifest_value_and_unwrap!(&( String::from("Hello World"), dec!("12") )),) - )]) + ) }) }, ); diff --git a/run-code-coverage.sh b/run-code-coverage.sh index 55b1088781..5aa577d343 100755 --- a/run-code-coverage.sh +++ b/run-code-coverage.sh @@ -3,6 +3,12 @@ set -x set -e -CARGO_INCREMENTAL=0 RUSTFLAGS='-Cinstrument-coverage' LLVM_PROFILE_FILE='cargo-test-%p-%m.profraw' cargo test --features compile-blueprints-at-build-time --no-fail-fast +CARGO_INCREMENTAL=0 RUSTFLAGS='-Cinstrument-coverage' LLVM_PROFILE_FILE='cargo-test-%p-%m.profraw' cargo test --no-fail-fast \ + --package radix-engine-tests \ + --package radix-transactions \ + --package radix-transaction-scenarios \ + --package radix-common \ + --package sbor \ + --package sbor-tests grcov . --binary-path ./target/debug/deps/ -s . -t html --branch --ignore-not-existing --ignore '../*' --ignore "/*" -o target/coverage/html --excl-br-start "^declare_native_blueprint_state" --excl-start "^declare_native_blueprint_state" --excl-br-stop "^}$" --excl-stop "^}$"