Skip to content

Commit

Permalink
Merge pull request #2009 from radixdlt/feature/fix-fuzzing-build
Browse files Browse the repository at this point in the history
Feature/fix fuzzing build
  • Loading branch information
iamyulong authored Nov 21, 2024
2 parents c3aa433 + a15d827 commit 6547430
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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..."

Expand Down
1 change: 1 addition & 0 deletions radix-common/src/data/manifest/model/manifest_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions radix-common/src/data/scrypto/model/non_fungible_local_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -227,7 +227,7 @@ impl StringNonFungibleLocalId {

#[cfg(feature = "fuzzing")]
impl<'a> Arbitrary<'a> for StringNonFungibleLocalId {
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
let charset: Vec<char> =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWZYZ012345678989_"
.chars()
Expand Down Expand Up @@ -308,7 +308,7 @@ impl BytesNonFungibleLocalId {

#[cfg(feature = "fuzzing")]
impl<'a> Arbitrary<'a> for BytesNonFungibleLocalId {
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
let len: u8 = u
.int_in_range(1..=NON_FUNGIBLE_LOCAL_ID_MAX_LENGTH as u8)
.unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
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!(),
})
}))
}
}

Expand Down
4 changes: 2 additions & 2 deletions radix-engine-toolkit-common/src/receipt/receipt/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl TryFrom<TransactionReceipt> 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) => {
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion radix-transactions/src/manifest/ast.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
18 changes: 9 additions & 9 deletions radix-transactions/src/manifest/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2633,9 +2633,9 @@ mod tests {
.try_into()
.unwrap()
),
IndexMap::<String, BlueprintStateSchemaInit>::new(),
IndexMap::<String, PackageRoyaltyConfig>::new(),
IndexMap::<String, MetadataValue>::new(),
IndexMap::<String, BlueprintStateSchemaInit, _>::new(),
IndexMap::<String, PackageRoyaltyConfig, _>::new(),
IndexMap::<String, MetadataValue, _>::new(),
RoleAssignmentInit::new()
)
.into(),
Expand Down Expand Up @@ -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,
}
),
Expand Down Expand Up @@ -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")
)),)
)])
)
})
},
);
Expand Down
8 changes: 7 additions & 1 deletion run-code-coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "^}$"

0 comments on commit 6547430

Please sign in to comment.