Skip to content

Commit

Permalink
Series of changes that improve development (#1583)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardpringle authored Sep 20, 2024
1 parent e0a3324 commit 6c15244
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion x/contracts/examples/counter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use wasmlanche::{public, state_schema, Address, Context};

type Count = u64;
pub type Count = u64;

state_schema! {
/// Counter for each address.
Expand Down
19 changes: 19 additions & 0 deletions x/contracts/wasmlanche/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>();

let target_dir = format!("{manifest_dir}/{BUILD_DIR_NAME}");
let mut command = Command::new("cargo");
command
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions x/contracts/wasmlanche/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ impl Context {
target: Address,
function: &str,
args: T,
// TODO: remove this
max_units: Gas,
max_value: u64,
result: U,
Expand Down
6 changes: 6 additions & 0 deletions x/contracts/wasmlanche/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
}
Expand Down
2 changes: 1 addition & 1 deletion x/contracts/wasmlanche/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl From<Box<[u8]>> 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]);

Expand Down
6 changes: 2 additions & 4 deletions x/contracts/wasmlanche/tests/wasmtime-integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 6c15244

Please sign in to comment.