Skip to content

Commit

Permalink
Release/0.23 (#416)
Browse files Browse the repository at this point in the history
* Changed versions

* Version updates

* Version

* Description

* Better makefile

* Added starship update

* Added Clone

* version

* Added remove state in trait

* Added remove

* Added ibctxanalyssis to check ibc return

* Updated docs and starship
  • Loading branch information
Kayanski authored Jun 13, 2024
1 parent 1e5e4fa commit 20a4612
Show file tree
Hide file tree
Showing 33 changed files with 169 additions and 66 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# cw-orchestrator Changelog

## Unreleased
## 0.23.0

- Added a test to make sure the derive macros stay compatible with new cw-orch versions
- Changed the derive macros import from cw_orch to cw_orch_core. This allows changing the cw-orch API without breaking the derive macros.
Expand All @@ -19,6 +19,7 @@
- Writing to a file happens when all Daemon's that use same file dropped instead of hot writes
- `force_write` added to the `DaemonState` to allow force write of the state
- Added `event_attr_values` to get all the attribute values corresponding to a key
- Added `remove_{address,code_id}` functions to be able to erase an entry in state. Involves core, mock, daemon, osmosis-test-tube, clone-testing
- Added `state` to DaemonBuilder to be able to share state between daemons

### Breaking
Expand Down
19 changes: 10 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,29 @@ anyhow = "1.0"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
tokio = { version = "1.4", features = ["full"] }

cw-orch = { path = "./cw-orch", version = "0.22.0" }
cw-orch-daemon = { path = "./cw-orch-daemon", version = "0.22.0" }
cw-orch-core = { path = "packages/cw-orch-core", version = "1.0.0" }
cw-orch = { path = "./cw-orch", version = "0.23.0" }
cw-orch-daemon = { path = "./cw-orch-daemon", version = "0.23.2" }
cw-orch-core = { path = "packages/cw-orch-core", version = "1.1.1" }
cw-orch-traits = { path = "packages/cw-orch-traits", version = "0.22.0" }
cw-orch-mock = { path = "packages/cw-orch-mock", version = "0.22.0" }
cw-orch-networks = { path = "packages/cw-orch-networks", version = "0.22.0" }

# Macros
cw-orch-contract-derive = { path = "packages/macros/cw-orch-contract-derive", version = "0.21.0" }
cw-orch-fns-derive = { path = "packages/macros/cw-orch-fns-derive", version = "0.20.0" }
cw-orch-fns-derive = { path = "packages/macros/cw-orch-fns-derive", version = "0.21.0" }

# Extensions
cw-orch-osmosis-test-tube = { version = "0.1.0", path = "packages/cw-orch-osmosis-test-tube" }

# Interchain
cw-orch-interchain-core = { path = "packages/interchain/interchain-core", version = "0.2.0" }
cw-orch-interchain-daemon = { path = "packages/interchain/interchain-daemon", version = "0.2.0" }
cw-orch-interchain-mock = { path = "packages/interchain/interchain-mock", version = "0.2.0" }
cw-orch-starship = { path = "packages/interchain/starship", version = "0.2.0" }
cw-orch-interchain = { path = "cw-orch-interchain", version = "0.2.0" }
cw-orch-interchain-core = { path = "packages/interchain/interchain-core", version = "0.3.0" }
cw-orch-interchain-daemon = { path = "packages/interchain/interchain-daemon", version = "0.3.2" }
cw-orch-interchain-mock = { path = "packages/interchain/interchain-mock", version = "0.3.1" }
cw-orch-starship = { path = "packages/interchain/starship", version = "0.3.0" }

#Clone Testing
cw-orch-clone-testing = { version = "0.4.1", path = "packages/clone-testing" }
cw-orch-clone-testing = { version = "0.5.0", path = "packages/clone-testing" }


thiserror = { version = "1.0.21" }
Expand Down
2 changes: 1 addition & 1 deletion cw-orch-daemon/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cw-orch-daemon"
version = "0.22.2"
version = "0.23.3"
authors = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion cw-orch-daemon/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub enum DaemonError {
Instantiate2Error(#[from] Instantiate2AddressError),
#[error("Error opening file {0},err: ({1})")]
OpenFile(String, String),
#[error("State file {0} already locked, use another state file or clone daemon which holds the lock")]
#[error("State file {0} already locked, use another state file, clone daemon which holds the lock, or use `state` method of Builder")]
StateAlreadyLocked(String),
}

Expand Down
27 changes: 27 additions & 0 deletions cw-orch-daemon/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,25 @@ impl DaemonState {
Ok(())
}

/// Remove a stateful value using the chainId and networkId
pub fn remove(&mut self, key: &str, contract_id: &str) -> Result<(), DaemonError> {
let json_file_state = match &mut self.json_state {
DaemonStateFile::ReadOnly { path } => {
return Err(DaemonError::StateReadOnly(path.clone()))
}
DaemonStateFile::FullAccess { json_file_state } => json_file_state,
};

let mut json_file_lock = json_file_state.lock().unwrap();
let val = json_file_lock.get_mut(
&self.chain_data.network_info.chain_name,
&self.chain_data.chain_id,
);
val[key][contract_id] = Value::Null;

Ok(())
}

/// Forcefully write current json to a file
pub fn force_write(&mut self) -> Result<(), DaemonError> {
let json_file_state = match &mut self.json_state {
Expand Down Expand Up @@ -247,6 +266,11 @@ impl StateInterface for DaemonState {
.unwrap();
}

fn remove_address(&mut self, contract_id: &str) {
let deployment_id = self.deployment_id.clone();
self.remove(&deployment_id, contract_id).unwrap();
}

/// Get the locally-saved version of the contract's version on this network
fn get_code_id(&self, contract_id: &str) -> Result<u64, CwEnvError> {
let value = self
Expand All @@ -262,6 +286,9 @@ impl StateInterface for DaemonState {
fn set_code_id(&mut self, contract_id: &str, code_id: u64) {
self.set("code_ids", contract_id, code_id).unwrap();
}
fn remove_code_id(&mut self, contract_id: &str) {
self.remove("code_ids", contract_id).unwrap();
}

/// Get all addresses for deployment id from state file
fn get_all_addresses(&self) -> Result<HashMap<String, Addr>, CwEnvError> {
Expand Down
2 changes: 1 addition & 1 deletion cw-orch-interchain/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cw-orch-interchain"
version = "0.1.0"
version = "0.2.0"
authors = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion cw-orch/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cw-orch"
version = "0.22.3"
version = "0.23.0"
authors = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
Expand Down
13 changes: 0 additions & 13 deletions cw-orch/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,3 @@ pub use cw_orch_traits::*;

#[cfg(feature = "snapshot-testing")]
pub use crate::take_storage_snapshot;

#[cfg(feature = "interchain")]
/// Everything that concerns interchain capabilities
pub mod interchain {
pub use cw_orch_interchain_core::{IbcQueryHandler, InterchainEnv};
pub use cw_orch_interchain_daemon::{
ChannelCreationValidator, ChannelCreator, DaemonInterchainEnv,
};
pub use cw_orch_interchain_mock::{MockBech32InterchainEnv, MockInterchainEnv};
pub use cw_orch_starship::Starship;
}
#[cfg(feature = "interchain")]
pub use interchain::*;
21 changes: 21 additions & 0 deletions docs/src/integrations/daemon.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,27 @@ This simple script actually hides another parameter which is the `LOCAL_MNEMONIC
>
> Under the hood, the `DaemonBuilder` struct creates a `tokio::Runtime`. Be careful because this builder is not usable in an `async` function. In such function, you can use <a href="https://docs.rs/cw-orch/latest/cw_orch/daemon/struct.DaemonAsync.html" target="_blank">`DaemonAsync`</a>
<div class="warning">

When using multiple Daemons with the same state file, you should re-use a single Daemon State to avoid conflicts and panics:

```rust,ignore
let daemon1 = Daemon::builder()
.chain(OSMOSIS_1)
.build()?;
// If you don't use the `state` method here, this will fail with:
// State file <file-name> already locked, use another state file, clone daemon which holds the lock, or use `state` method of Builder
let daemon2 = Daemon::builder()
.chain(JUNO_1)
.state(daemon1.state())
.build()?;
```


</div>



## Interacting with contracts

You can then use the resulting `Daemon` variable to interact with your [contracts](../contracts/index.md):
Expand Down
2 changes: 1 addition & 1 deletion packages/clone-testing/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cw-orch-clone-testing"
version = "0.4.1"
version = "0.5.1"
authors.workspace = true
edition.workspace = true
license.workspace = true
Expand Down
3 changes: 0 additions & 3 deletions packages/clone-testing/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,11 +454,8 @@ mod test {
use cw_orch_core::environment::QueryHandler;
use cw_orch_daemon::networks::JUNO_1;
use cw_orch_mock::cw_multi_test::{Contract as MockContract, ContractWrapper};
use serde::Serialize;
use speculoos::prelude::*;

#[derive(Debug, Serialize)]
struct MigrateMsg {}
pub struct MockCw20;

fn execute(
Expand Down
8 changes: 8 additions & 0 deletions packages/clone-testing/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ impl StateInterface for MockState {
.insert(contract_id.to_string(), address.to_owned());
}

fn remove_address(&mut self, contract_id: &str) {
self.addresses.remove(contract_id);
}

/// Get the locally-saved version of the contract's version on this network
fn get_code_id(&self, contract_id: &str) -> Result<u64, CwEnvError> {
self.code_ids
Expand All @@ -66,6 +70,10 @@ impl StateInterface for MockState {
self.code_ids.insert(contract_id.to_string(), code_id);
}

fn remove_code_id(&mut self, contract_id: &str) {
self.code_ids.remove(contract_id);
}

fn get_all_addresses(&self) -> Result<HashMap<String, Addr>, CwEnvError> {
let mock_addresses = self.addresses.clone();
let daemon_addresses = self.daemon_state.get_all_addresses().unwrap_or_default();
Expand Down
2 changes: 1 addition & 1 deletion packages/cw-orch-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cw-orch-core"
version = "1.0.0"
version = "1.1.1"
authors = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
Expand Down
9 changes: 9 additions & 0 deletions packages/cw-orch-core/src/contract/contract_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ impl<Chain: ChainState> Contract<Chain> {
self.chain.state().set_address(&self.id, address)
}

/// Remove state address for contract
pub fn remove_address(&self) {
self.chain.state().remove_address(&self.id)
}

/// Returns state code_id for contract
pub fn code_id(&self) -> Result<u64, CwEnvError> {
let state_code_id = self.chain.state().get_code_id(&self.id);
Expand All @@ -83,6 +88,10 @@ impl<Chain: ChainState> Contract<Chain> {
pub fn set_code_id(&self, code_id: u64) {
self.chain.state().set_code_id(&self.id, code_id)
}
/// Remove state code_id for contract
pub fn remove_code_id(&self) {
self.chain.state().remove_code_id(&self.id)
}
}

/// Expose chain and state function to call them on the contract
Expand Down
10 changes: 10 additions & 0 deletions packages/cw-orch-core/src/contract/interface_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ pub trait ContractInstance<Chain: ChainState> {
Contract::set_address(self.as_instance(), address)
}

/// Removes the address for the contract
fn remove_address(&self) {
Contract::remove_address(self.as_instance())
}

/// Sets a default address for the contract. If the contract already has an address registered in the state, this won't be used.
/// This is mostly used to ship address with a cw-orch package.
fn set_default_address(&mut self, address: &Addr) {
Expand All @@ -59,6 +64,11 @@ pub trait ContractInstance<Chain: ChainState> {
Contract::set_code_id(self.as_instance(), code_id)
}

/// Removes the code_id for the contract
fn remove_code_id(&self) {
Contract::remove_code_id(self.as_instance())
}

/// Sets a default address for the contract. If the contract already has an address registered in the state, this won't be used.
/// This is mostly used to ship address with a cw-orch package.
fn set_default_code_id(&mut self, code_id: u64) {
Expand Down
20 changes: 20 additions & 0 deletions packages/cw-orch-core/src/environment/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,24 @@ pub trait StateInterface: Clone {
/// Set the address of a contract using the specified contract id.
fn set_address(&mut self, contract_id: &str, address: &Addr);

/// Removes the address of a contract using the specified contract id.
fn remove_address(&mut self, _contract_id: &str) {
// Using default impl to avoid breaking changes
unimplemented!()
}

/// Get the code id for a contract with the specified contract id.
fn get_code_id(&self, contract_id: &str) -> Result<u64, CwEnvError>;

/// Set the code id for a contract with the specified contract id.
fn set_code_id(&mut self, contract_id: &str, code_id: u64);

/// Removes the code id for a contract with the specified contract id.
fn remove_code_id(&mut self, _contract_id: &str) {
// Using default impl to avoid breaking changes
unimplemented!()
}

/// Get all addresses related to this deployment.
fn get_all_addresses(&self) -> Result<HashMap<String, Addr>, CwEnvError>;

Expand Down Expand Up @@ -58,6 +70,14 @@ impl<S: StateInterface> StateInterface for Rc<RefCell<S>> {
fn get_all_code_ids(&self) -> Result<HashMap<String, u64>, CwEnvError> {
(**self).borrow().get_all_code_ids()
}

fn remove_address(&mut self, contract_id: &str) {
(**self).borrow_mut().remove_address(contract_id)
}

fn remove_code_id(&mut self, contract_id: &str) {
(**self).borrow_mut().remove_code_id(contract_id)
}
}

impl<S: StateInterface> StateInterface for Rc<S> {
Expand Down
2 changes: 1 addition & 1 deletion packages/cw-orch-mock/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cw-orch-mock"
version = "0.22.2"
version = "0.22.4"
authors.workspace = true
edition.workspace = true
license.workspace = true
Expand Down
4 changes: 0 additions & 4 deletions packages/cw-orch-mock/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,17 +255,13 @@ mod test {
};
use cw_multi_test::ContractWrapper;
use cw_orch_core::environment::{BankQuerier, DefaultQueriers, QueryHandler};
use serde::Serialize;
use speculoos::prelude::*;

use crate::core::*;

const SENDER: &str = "cosmos123";
const BALANCE_ADDR: &str = "cosmos456";

#[derive(Debug, Serialize)]
struct MigrateMsg {}

fn execute(
_deps: DepsMut,
_env: Env,
Expand Down
8 changes: 8 additions & 0 deletions packages/cw-orch-mock/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ impl StateInterface for MockState {
.insert(contract_id.to_string(), address.to_owned());
}

fn remove_address(&mut self, contract_id: &str) {
self.addresses.remove(contract_id);
}

/// Get the locally-saved version of the contract's version on this network
fn get_code_id(&self, contract_id: &str) -> Result<u64, CwEnvError> {
self.code_ids
Expand All @@ -74,6 +78,10 @@ impl StateInterface for MockState {
self.code_ids.insert(contract_id.to_string(), code_id);
}

fn remove_code_id(&mut self, contract_id: &str) {
self.code_ids.remove(contract_id);
}

fn get_all_addresses(&self) -> Result<HashMap<String, Addr>, CwEnvError> {
Ok(self.addresses.clone())
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cw-orch-networks/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cw-orch-networks"
version = "0.22.0"
version = "0.22.1"
authors = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
Expand Down
3 changes: 2 additions & 1 deletion packages/cw-orch-osmosis-test-tube/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "cw-orch-osmosis-test-tube"
version = "0.1.0"
version = "0.1.1"
description = "Cw-orch environment adapter for osmosis-test-tube"
authors.workspace = true
edition.workspace = true
license.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion packages/interchain/interchain-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cw-orch-interchain-core"
version = "0.2.0"
version = "0.3.2"
authors.workspace = true
edition.workspace = true
license.workspace = true
Expand Down
Loading

0 comments on commit 20a4612

Please sign in to comment.