Skip to content

Commit

Permalink
Merge pull request #1879 from CosmWasm/1492-remove-deprecated
Browse files Browse the repository at this point in the history
[2.0] Remove depreated symbols
  • Loading branch information
chipshort committed Oct 16, 2023
2 parents b2577a4 + a2f48bc commit d4972f5
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 94 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ and this project adheres to

## [Unreleased]

### Changed

- cosmwasm-std: Replace `ContractInfoResponse::new` with new (unstable)
constructor, remove `SubMsgExecutionResponse` (Use `SubMsgResponse` instead)
and remove `PartialEq<&str> for Addr` (validate the address and use
`PartialEq<Addr> for Addr` instead). ([#1879])

[#1879]: https://github.com/CosmWasm/cosmwasm/pull/1879

## [1.5.0-rc.0]

### Added
Expand Down
58 changes: 1 addition & 57 deletions packages/std/src/addresses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Addr {
/// ```
/// # use cosmwasm_std::{Addr};
/// let address = Addr::unchecked("foobar");
/// assert_eq!(address, "foobar");
/// assert_eq!(address.as_str(), "foobar");
/// ```
pub fn unchecked(input: impl Into<String>) -> Addr {
Addr(input.into())
Expand Down Expand Up @@ -87,46 +87,6 @@ impl AsRef<str> for Addr {
}
}

/// Implement `Addr == &str`
///
/// Deprecated. This comparison unsafe. Convert both sides to Addr first.
/// Will be removed soon: https://github.com/CosmWasm/cosmwasm/issues/1669
impl PartialEq<&str> for Addr {
fn eq(&self, rhs: &&str) -> bool {
self.0 == *rhs
}
}

/// Implement `&str == Addr`
///
/// Deprecated. This comparison unsafe. Convert both sides to Addr first.
/// Will be removed soon: https://github.com/CosmWasm/cosmwasm/issues/1669
impl PartialEq<Addr> for &str {
fn eq(&self, rhs: &Addr) -> bool {
*self == rhs.0
}
}

/// Implement `Addr == String`
///
/// Deprecated. This comparison unsafe. Convert both sides to Addr first.
/// Will be removed soon: https://github.com/CosmWasm/cosmwasm/issues/1669
impl PartialEq<String> for Addr {
fn eq(&self, rhs: &String) -> bool {
&self.0 == rhs
}
}

/// Implement `String == Addr`
///
/// Deprecated. This comparison unsafe. Convert both sides to Addr first.
/// Will be removed soon: https://github.com/CosmWasm/cosmwasm/issues/1669
impl PartialEq<Addr> for String {
fn eq(&self, rhs: &Addr) -> bool {
self == &rhs.0
}
}

// Addr->String is a safe conversion.
// However, the opposite direction is unsafe and must not be implemented.

Expand Down Expand Up @@ -440,22 +400,6 @@ mod tests {
assert_eq!(addr.as_ref(), "literal-string");
}

// Please note that this will be removed soon
// https://github.com/CosmWasm/cosmwasm/issues/1669
#[test]
fn addr_implements_partial_eq_with_str_and_string() {
let addr = Addr::unchecked("cos934gh9034hg04g0h134");

// `Addr == &str`
assert_eq!(addr, "cos934gh9034hg04g0h134");
// `&str == Addr`
assert_eq!("cos934gh9034hg04g0h134", addr);
// `Addr == String`
assert_eq!(addr, String::from("cos934gh9034hg04g0h134"));
// `String == Addr`
assert_eq!(String::from("cos934gh9034hg04g0h134"), addr);
}

#[test]
fn addr_implements_partial_eq_addr_ref() {
let addr = Addr::unchecked("cos934gh9034hg04g0h134");
Expand Down
4 changes: 2 additions & 2 deletions packages/std/src/assertions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ macro_rules! ensure {
/// # Unauthorized {},
/// # }
/// # struct Config {
/// # admin: String,
/// # admin: Addr,
/// # }
/// #
/// # fn body() -> Result<(), ContractError> {
/// # let info = MessageInfo { sender: Addr::unchecked("foo"), funds: Vec::new() };
/// # let cfg = Config { admin: "foo".to_string() };
/// # let cfg = Config { admin: Addr::unchecked("foo") };
/// use cosmwasm_std::ensure_eq;
///
/// ensure_eq!(info.sender, cfg.admin, ContractError::Unauthorized {});
Expand Down
2 changes: 0 additions & 2 deletions packages/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ pub use crate::query::{
DistributionQuery, FullDelegation, IbcQuery, ListChannelsResponse, PortIdResponse,
QueryRequest, StakingQuery, SupplyResponse, Validator, ValidatorResponse, WasmQuery,
};
#[allow(deprecated)]
pub use crate::results::SubMsgExecutionResponse;
#[cfg(all(feature = "stargate", feature = "cosmwasm_1_2"))]
pub use crate::results::WeightedVoteOption;
pub use crate::results::{
Expand Down
25 changes: 8 additions & 17 deletions packages/std/src/query/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,14 @@ pub struct ContractInfoResponse {

impl QueryResponseType for ContractInfoResponse {}

impl ContractInfoResponse {
/// Constructor for testing frameworks such as cw-multi-test.
/// This is required because query response types should be #[non_exhaustive].
/// As a contract developer you should not need this constructor since
/// query responses are constructed for you via deserialization.
#[doc(hidden)]
#[deprecated(
note = "Use ContractInfoResponse::default() and mutate the fields you want to set."
)]
pub fn new(code_id: u64, creator: impl Into<String>) -> Self {
ContractInfoResponse {
code_id,
creator: creator.into(),
..Default::default()
}
}
}
impl_response_constructor!(
ContractInfoResponse,
code_id: u64,
creator: String,
admin: Option<String>,
pinned: bool,
ibc_port: Option<String>
);

/// The essential data from wasmd's [CodeInfo]/[CodeInfoResponse].
///
Expand Down
2 changes: 0 additions & 2 deletions packages/std/src/results/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,5 @@ pub use empty::Empty;
pub use events::{attr, Attribute, Event};
pub use query::QueryResponse;
pub use response::Response;
#[allow(deprecated)]
pub use submessages::SubMsgExecutionResponse;
pub use submessages::{Reply, ReplyOn, SubMsg, SubMsgResponse, SubMsgResult};
pub use system_result::SystemResult;
3 changes: 0 additions & 3 deletions packages/std/src/results/submessages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,6 @@ pub struct SubMsgResponse {
pub data: Option<Binary>,
}

#[deprecated(note = "Renamed to SubMsgResponse")]
pub type SubMsgExecutionResponse = SubMsgResponse;

#[cfg(test)]
mod tests {
use super::*;
Expand Down
37 changes: 27 additions & 10 deletions packages/std/src/testing/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl Api for MockApi {
fn addr_validate(&self, input: &str) -> StdResult<Addr> {
let canonical = self.addr_canonicalize(input)?;
let normalized = self.addr_humanize(&canonical)?;
if input != normalized {
if input != normalized.as_str() {
return Err(StdError::generic_err(
"Invalid input: address not normalized",
));
Expand Down Expand Up @@ -1203,7 +1203,7 @@ mod tests {

// valid
let addr = api.addr_validate("foobar123").unwrap();
assert_eq!(addr, "foobar123");
assert_eq!(addr.as_str(), "foobar123");

// invalid: too short
api.addr_validate("").unwrap_err();
Expand Down Expand Up @@ -1232,20 +1232,20 @@ mod tests {
let original = String::from("shorty");
let canonical = api.addr_canonicalize(&original).unwrap();
let recovered = api.addr_humanize(&canonical).unwrap();
assert_eq!(recovered, original);
assert_eq!(recovered.as_str(), original);

// normalizes input
let original = String::from("CosmWasmChef");
let canonical = api.addr_canonicalize(&original).unwrap();
let recovered = api.addr_humanize(&canonical).unwrap();
assert_eq!(recovered, "cosmwasmchef");
assert_eq!(recovered.as_str(), "cosmwasmchef");

// Long input (Juno contract address)
let original =
String::from("juno1v82su97skv6ucfqvuvswe0t5fph7pfsrtraxf0x33d8ylj5qnrysdvkc95");
let canonical = api.addr_canonicalize(&original).unwrap();
let recovered = api.addr_humanize(&canonical).unwrap();
assert_eq!(recovered, original);
assert_eq!(recovered.as_str(), original);
}

#[test]
Expand Down Expand Up @@ -1695,15 +1695,15 @@ mod tests {

let res = distribution.query(&query).unwrap().unwrap();
let res: DelegatorWithdrawAddressResponse = from_json(res).unwrap();
assert_eq!(res.withdraw_address, "withdraw0");
assert_eq!(res.withdraw_address.as_str(), "withdraw0");

let query = DistributionQuery::DelegatorWithdrawAddress {
delegator_address: "addr1".to_string(),
};

let res = distribution.query(&query).unwrap().unwrap();
let res: DelegatorWithdrawAddressResponse = from_json(res).unwrap();
assert_eq!(res.withdraw_address, "addr1");
assert_eq!(res.withdraw_address.as_str(), "addr1");
}

#[cfg(feature = "cosmwasm_1_4")]
Expand Down Expand Up @@ -2169,9 +2169,16 @@ mod tests {
let mut storage1 = HashMap::<Binary, Binary>::default();
storage1.insert(b"the key".into(), b"the value".into());

let api = MockApi::default();

match request {
WasmQuery::Raw { contract_addr, key } => {
if *contract_addr == constract1 {
let Ok(addr) = api.addr_validate(contract_addr) else {
return SystemResult::Err(SystemError::NoSuchContract {
addr: contract_addr.clone(),
});
};
if addr == constract1 {
if let Some(value) = storage1.get(key) {
SystemResult::Ok(ContractResult::Ok(value.clone()))
} else {
Expand All @@ -2184,7 +2191,12 @@ mod tests {
}
}
WasmQuery::Smart { contract_addr, msg } => {
if *contract_addr == constract1 {
let Ok(addr) = api.addr_validate(contract_addr) else {
return SystemResult::Err(SystemError::NoSuchContract {
addr: contract_addr.clone(),
});
};
if addr == constract1 {
#[derive(Deserialize)]
struct MyMsg {}
let _msg: MyMsg = match from_json(msg) {
Expand All @@ -2202,7 +2214,12 @@ mod tests {
}
}
WasmQuery::ContractInfo { contract_addr } => {
if *contract_addr == constract1 {
let Ok(addr) = api.addr_validate(contract_addr) else {
return SystemResult::Err(SystemError::NoSuchContract {
addr: contract_addr.clone(),
});
};
if addr == constract1 {
let response = ContractInfoResponse {
code_id: 4,
creator: "lalala".into(),
Expand Down
2 changes: 1 addition & 1 deletion packages/std/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ pub trait Api {
/// # let api = MockApi::default();
/// let input = "what-users-provide";
/// let validated: Addr = api.addr_validate(input).unwrap();
/// assert_eq!(validated, input);
/// assert_eq!(validated.as_str(), input);
/// ```
fn addr_validate(&self, human: &str) -> StdResult<Addr>;

Expand Down

0 comments on commit d4972f5

Please sign in to comment.