diff --git a/x/contracts/examples/counter/src/lib.rs b/x/contracts/examples/counter/src/lib.rs index 3fb5519fa2..d3e1a2605e 100644 --- a/x/contracts/examples/counter/src/lib.rs +++ b/x/contracts/examples/counter/src/lib.rs @@ -3,7 +3,7 @@ use wasmlanche::{public, state_schema, Address, Context}; -type Count = u64; +pub type Count = u64; state_schema! { /// Counter for each address. diff --git a/x/contracts/wasmlanche/src/build.rs b/x/contracts/wasmlanche/src/build.rs index ebebd4af53..8ed0bc5d3a 100644 --- a/x/contracts/wasmlanche/src/build.rs +++ b/x/contracts/wasmlanche/src/build.rs @@ -25,6 +25,21 @@ pub fn build_wasm() { "test" }; + let features = std::env::vars() + .filter_map(|(key, value)| { + if key.starts_with("CARGO_FEATURE_") && value == "1" { + let feature = key.trim_start_matches("CARGO_FEATURE_").to_lowercase(); + + match feature.as_str() { + "bindings" | "test" => None, + _ => Some(feature), + } + } else { + None + } + }) + .collect::>(); + let target_dir = format!("{manifest_dir}/{BUILD_DIR_NAME}"); let mut command = Command::new("cargo"); command @@ -38,6 +53,10 @@ pub fn build_wasm() { command.arg("--release"); } + if !features.is_empty() { + command.arg("--features").arg(features.join(",")); + } + command.arg("--crate-type").arg("cdylib"); let cargo_build_output = command diff --git a/x/contracts/wasmlanche/src/context.rs b/x/contracts/wasmlanche/src/context.rs index e60422539e..8c5d376320 100644 --- a/x/contracts/wasmlanche/src/context.rs +++ b/x/contracts/wasmlanche/src/context.rs @@ -279,6 +279,7 @@ impl Context { target: Address, function: &str, args: T, + // TODO: remove this max_units: Gas, max_value: u64, result: U, diff --git a/x/contracts/wasmlanche/src/lib.rs b/x/contracts/wasmlanche/src/lib.rs index decee2f064..9fd862b84e 100644 --- a/x/contracts/wasmlanche/src/lib.rs +++ b/x/contracts/wasmlanche/src/lib.rs @@ -71,6 +71,12 @@ mod types; mod logging; #[cfg(not(feature = "debug"))] mod logging { + #[macro_export] + macro_rules! dbg { + // match anything + ($($token:tt)*) => {}; + } + pub fn log(_msg: &str) {} pub fn register_panic() {} } diff --git a/x/contracts/wasmlanche/src/types.rs b/x/contracts/wasmlanche/src/types.rs index 77a604adc9..61d4b2f092 100644 --- a/x/contracts/wasmlanche/src/types.rs +++ b/x/contracts/wasmlanche/src/types.rs @@ -28,7 +28,7 @@ impl From> for ContractId { /// Represents an address where a smart contract is deployed. #[cfg_attr(feature = "debug", derive(Debug))] -#[derive(Clone, Copy, PartialEq, Eq, BorshSerialize, BorshDeserialize, Hash)] +#[derive(Clone, Copy, Ord, PartialOrd, PartialEq, Eq, BorshSerialize, BorshDeserialize, Hash)] #[repr(transparent)] pub struct Address([u8; 33]); diff --git a/x/contracts/wasmlanche/tests/wasmtime-integration.rs b/x/contracts/wasmlanche/tests/wasmtime-integration.rs index 536f023cc2..2869e39ba5 100644 --- a/x/contracts/wasmlanche/tests/wasmtime-integration.rs +++ b/x/contracts/wasmlanche/tests/wasmtime-integration.rs @@ -35,8 +35,7 @@ fn public_functions() { #[should_panic = "failed to allocate memory"] fn allocate_zero() { let mut test_crate = build_test_crate(); - let result = test_crate.allocate(Vec::new()); - dbg!(result); + test_crate.allocate(Vec::new()); } const ALLOCATION_MAP_OVERHEAD: usize = 48; @@ -206,8 +205,7 @@ impl TestCrate { .expect("data should exist"); let args: Vec<(StateKey, StateValue)> = - borsh::from_slice(dbg!(&serialized_args)) - .expect("failed to deserialize args"); + borsh::from_slice(serialized_args).expect("failed to deserialize args"); let state = &mut caller.data_mut().1;