Skip to content

Commit

Permalink
Fixes and helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
Kayanski committed Sep 17, 2024
1 parent eb23e76 commit 7847f73
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 33 deletions.
5 changes: 3 additions & 2 deletions contracts-ws/contracts/counter/tests/checksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ fn checksum() {
let file = File::open(path).unwrap();
let lines = io::BufReader::new(file).lines();
let mut found = false;
let rt = cw_orch::tokio::runtime::Runtime::new().unwrap();

for line in lines.map_while(Result::ok) {
if line.contains("counter_contract.wasm") {
let parts: Vec<&str> = line.split_whitespace().collect();
if parts.len() > 1 {
let calculated_hash = CounterContract::<Mock>::wasm(&OSMOSIS_1.into())
.checksum()
let calculated_hash = rt
.block_on(CounterContract::<Mock>::wasm(&OSMOSIS_1.into()).checksum())
.unwrap();
assert_eq!(parts[0], calculated_hash.to_string());
found = true;
Expand Down
2 changes: 1 addition & 1 deletion cw-orch-daemon/tests/daemon_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ fn reuse_same_state_multichain() {
.build()
.unwrap();

let daemon_res = DaemonBuilder::new(NEUTRON_1)
DaemonBuilder::new(NEUTRON_1)
.state(daemon.state())
.mnemonic(DUMMY_MNEMONIC)
.build()
Expand Down
6 changes: 3 additions & 3 deletions cw-orch-interchain/tests/common/ica_demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ struct Controller;

impl<Chain: CwEnv> Uploadable for Controller<Chain> {
fn wasm(_chain: &ChainInfoOwned) -> <Daemon as TxHandler>::ContractSource {
WasmPath::new(format!("{CRATE_PATH}/wasms/simple_ica_controller.wasm")).unwrap()
WasmPath::path(format!("{CRATE_PATH}/wasms/simple_ica_controller.wasm")).unwrap()
}

fn wrapper() -> Box<dyn MockContract<Empty, Empty>> {
Expand Down Expand Up @@ -206,7 +206,7 @@ pub fn host_execute(_: DepsMut, _: Env, _: MessageInfo, _: Empty) -> StdResult<R
struct Host;
impl<Chain: CwEnv> Uploadable for Host<Chain> {
fn wasm(_chain: &ChainInfoOwned) -> <Daemon as TxHandler>::ContractSource {
WasmPath::new(format!("{CRATE_PATH}/wasms/simple_ica_host.wasm")).unwrap()
WasmPath::path(format!("{CRATE_PATH}/wasms/simple_ica_host.wasm")).unwrap()
}

fn wrapper() -> Box<dyn MockContract<Empty, Empty>> {
Expand Down Expand Up @@ -235,7 +235,7 @@ struct Cw1;

impl<Chain: CwEnv> Uploadable for Cw1<Chain> {
fn wasm(_chain: &ChainInfoOwned) -> <Daemon as TxHandler>::ContractSource {
WasmPath::new(format!("{CRATE_PATH}/wasms/cw1_whitelist.wasm")).unwrap()
WasmPath::path(format!("{CRATE_PATH}/wasms/cw1_whitelist.wasm")).unwrap()
}
fn wrapper() -> Box<dyn MockContract<Empty, Empty>> {
Box::new(ContractWrapper::new_with_empty(
Expand Down
15 changes: 6 additions & 9 deletions cw-orch/examples/cw-plus-wasm.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use cosmwasm_std::Uint128;
use cw20::{Cw20Coin, Cw20ExecuteMsg};
use cw_orch::contract::{GithubWasmPath, GithubWasmPathLocation};
use cw_orch::prelude::*;
use cw_plus_orch::cw20_base::{Cw20Base, InstantiateMsg};
use cw_plus_orch::cw20_base::{QueryMsg, QueryMsgInterfaceFns};
Expand Down Expand Up @@ -63,14 +62,12 @@ pub struct FileCw20Base;
impl<Chain: CwEnv> Uploadable for FileCw20Base<Chain> {
// Return the path to the wasm file
fn wasm(_chain: &ChainInfoOwned) -> WasmPath {
WasmPath::Github(GithubWasmPath {
owner: "Abstractsdk".to_string(),
repo_name: "cw-plus".to_string(),
location: GithubWasmPathLocation::File {
reference: "abstract_versions".to_string(),
file_path: "artifacts/abstract_cw20_base.wasm".to_string(),
},
})
WasmPath::github_file(
"AbstractSDK",
"cw-plus",
"abstract_versions",
"artifacts/abstract_cw20_base.wasm",
)
}
// Return a CosmWasm contract wrapper
fn wrapper() -> Box<dyn MockContract<Empty>> {
Expand Down
2 changes: 1 addition & 1 deletion docs/src/contracts/interfaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ In the counter contract we re-export in `lib.rs`;
> ```rust,ignore
> let crate_path = env!("CARGO_MANIFEST_DIR");
> let wasm_path = format!("{}/../../artifacts/counter_contract.wasm", crate_path);
> WasmPath::new(wasm_path).unwrap()
> WasmPath::path(wasm_path).unwrap()
> ```
## Constructor
Expand Down
2 changes: 1 addition & 1 deletion packages/cw-orch-core/src/contract/paths/artifacts_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl ArtifactsDir {
self.path().to_str().unwrap_or_default().to_owned(),
)
})?;
WasmPath::new(self.path().join(path_str))
WasmPath::path(self.path().join(path_str))
}
}

Expand Down
40 changes: 37 additions & 3 deletions packages/cw-orch-core/src/contract/paths/wasm_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::error::CwEnvError;
use cosmwasm_std::{ensure_eq, Checksum};
use std::{io::Read, path::PathBuf};

use super::github::GithubWasmPath;
use super::{github::GithubWasmPath, GithubWasmPathLocation};

/// Direct path to a `.wasm` file
/// Stored as `PathBuf` to avoid lifetimes.
Expand All @@ -13,7 +13,7 @@ use super::github::GithubWasmPath;
/// use cw_orch_core::contract::WasmPath;
///
/// // Create a new WasmPath from a path to a WASM file.
/// let wasm_path: WasmPath = WasmPath::new("path/to/contract.wasm").unwrap();
/// let wasm_path: WasmPath = WasmPath::path("path/to/contract.wasm").unwrap();
///
/// // Calculate the checksum of the WASM file.
/// let checksum: cosmwasm_std::Checksum = wasm_path.checksum().unwrap();
Expand All @@ -27,7 +27,7 @@ pub enum WasmPath {

impl WasmPath {
/// Create a new WasmPath from a path to a WASM file.
pub fn new(path: impl Into<PathBuf>) -> Result<Self, CwEnvError> {
pub fn path(path: impl Into<PathBuf>) -> Result<Self, CwEnvError> {

Check failure on line 30 in packages/cw-orch-core/src/contract/paths/wasm_path.rs

View workflow job for this annotation

GitHub Actions / clippy

the `Err`-variant returned from this function is very large

error: the `Err`-variant returned from this function is very large --> packages/cw-orch-core/src/contract/paths/wasm_path.rs:30:46 | 30 | pub fn path(path: impl Into<PathBuf>) -> Result<Self, CwEnvError> { | ^^^^^^^^^^^^^^^^^^^^^^^^ | ::: packages/cw-orch-core/src/error.rs:38:5 | 38 | Octocrab(#[from] octocrab::Error), | --------------------------------- the largest variant contains at least 128 bytes | = help: try reducing the size of `error::CwEnvError`, for example by boxing large elements or replacing it with `Box<error::CwEnvError>` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#result_large_err
let path: PathBuf = path.into();
assert!(
path.exists(),
Expand All @@ -42,6 +42,40 @@ impl WasmPath {
Ok(Self::Path(path))
}

/// Creates a new WasmPath from a github release asset
pub fn github_release(
owner: impl Into<String>,
repo_name: impl Into<String>,
release_tag: impl Into<String>,
file_name: impl Into<String>,
) -> Self {
WasmPath::Github(GithubWasmPath {
owner: owner.into(),
repo_name: repo_name.into(),
location: GithubWasmPathLocation::Release {
tag: release_tag.into(),
file_name: file_name.into(),
},
})
}

/// Creates a new WasmPath from a github file
pub fn github_file(
owner: impl Into<String>,
repo_name: impl Into<String>,
reference: impl Into<String>,
file_path: impl Into<String>,
) -> Self {
WasmPath::Github(GithubWasmPath {
owner: owner.into(),
repo_name: repo_name.into(),
location: GithubWasmPathLocation::File {
reference: reference.into(),
file_path: file_path.into(),
},
})
}

/// Get the content of the WASM file
pub async fn wasm(&self) -> Result<Vec<u8>, CwEnvError> {
match self {
Expand Down
19 changes: 7 additions & 12 deletions packages/integrations/cw-plus/src/cw20_base.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use cw_orch::{
contract::{GithubWasmPath, GithubWasmPathLocation},
interface,
};
use cw_orch::interface;

use cw20_base::contract;
pub use cw20_base::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg};
Expand All @@ -21,14 +18,12 @@ use crate::{WASM_RELEASE_TAG, WASM_REPO_NAME, WASM_REPO_OWNER};
impl<Chain: CwEnv> Uploadable for Cw20Base<Chain> {
// Return the path to the wasm file
fn wasm(_chain: &ChainInfoOwned) -> WasmPath {
WasmPath::Github(GithubWasmPath {
owner: WASM_REPO_OWNER.to_string(),
repo_name: WASM_REPO_NAME.to_string(),
location: GithubWasmPathLocation::Release {
tag: WASM_RELEASE_TAG.to_string(),
file_name: "cw20_base.wasm".to_string(),
},
})
WasmPath::github_release(
WASM_REPO_OWNER,
WASM_REPO_NAME,
WASM_RELEASE_TAG,
"cw20_base.wasm",
)
}
// Return a CosmWasm contract wrapper
fn wrapper() -> Box<dyn MockContract<Empty>> {
Expand Down
2 changes: 1 addition & 1 deletion packages/macros/cw-orch-contract-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl <Chain> Uploadable for Cw20<Chain> {
}
fn wasm(_chain: &ChainInfoOwned) -> <Daemon as cw_orch::TxHandler>::ContractSource {
WasmPath::new("path/to/cw20.wasm").unwrap()
WasmPath::path("path/to/cw20.wasm").unwrap()
}
}
*/
Expand Down

0 comments on commit 7847f73

Please sign in to comment.