Skip to content

Commit

Permalink
Add local_hash function to WasmCodeQuerier trait and implement it…
Browse files Browse the repository at this point in the history
… for envs
  • Loading branch information
CyberHoward committed Dec 19, 2023
1 parent 4155f24 commit f1e9b3e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/cw-orch-core/src/contract/interface_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ pub trait ConditionalUpload<Chain: CwEnv>: CwOrchUpload<Chain> {
let on_chain_hash = chain
.contract_hash(latest_uploaded_code_id)
.map_err(Into::into)?;
let local_hash = self.wasm().checksum()?;
let local_hash = chain.local_hash(self)?;
Ok(local_hash == on_chain_hash)
}

Expand Down
8 changes: 8 additions & 0 deletions packages/cw-orch-core/src/environment/cosmwasm_environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ pub trait WasmCodeQuerier: TxHandler + Clone {
&self,
contract: &T,
) -> Result<ContractInfoResponse, <Self as TxHandler>::Error>;

/// Returns the checksum of the WASM file if the env supports it. Will re-upload every time if not supported.
fn local_hash<T: Uploadable + ContractInstance<Self>>(
&self,
contract: &T,
) -> Result<String, CwEnvError> {
contract.wasm().checksum()
}
}

pub trait BankQuerier: TxHandler {
Expand Down
1 change: 1 addition & 0 deletions packages/cw-orch-mock/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ cosmwasm-std = { workspace = true }
cw-multi-test = { workspace = true }
cw-utils = { workspace = true }
serde = { workspace = true }
sha256 = { workspace = true }

[dev-dependencies]
speculoos = { workspace = true }
Expand Down
9 changes: 9 additions & 0 deletions packages/cw-orch-mock/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,15 @@ impl WasmCodeQuerier for Mock {
.query_wasm_contract_info(contract.address()?)?;
Ok(info)
}

fn local_hash<T: Uploadable + ContractInstance<Mock>>(
&self,
contract: &T,
) -> Result<String, CwEnvError> {
// We return the hashed contract-id.
// This will cause the logic to never re-upload a contract if it has the same contract-id.
Ok(sha256::digest(contract.id().as_bytes()))
}
}

impl BankQuerier for Mock {
Expand Down

0 comments on commit f1e9b3e

Please sign in to comment.