Skip to content

Commit

Permalink
Bump CosmWasm to v2.0 (#23)
Browse files Browse the repository at this point in the history
* bump cosmwasm versions

* bump cosmwasm versions

* fix tests
  • Loading branch information
CyberHoward authored Jun 10, 2024
1 parent eed2b87 commit 718351d
Show file tree
Hide file tree
Showing 12 changed files with 135 additions and 157 deletions.
222 changes: 100 additions & 122 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ license = "Apache-2.0"
keywords = ["cosmos", "cosmwasm"]

[workspace.dependencies]
cosmwasm-schema = "1.2"
cosmwasm-std = "1.2"
cw-address-like = { version = "1.0.4", path = "./packages/address-like" }
cw-ownable-derive = { version = "0.5.1", path = "./packages/ownable/derive" }
cw-storage-plus = "1.1"
cw-utils = "1.0"
cosmwasm-schema = "2.0"
cosmwasm-std = "2.0"
cw-address-like = { version = "2.0.0", path = "./packages/address-like" }
cw-ownable-derive = { version = "0.6.0", path = "./packages/ownable/derive" }
cw-storage-plus = "2.0"
cw-utils = "2.0"
proc-macro2 = "1"
quote = "1"
serde = { version = "1", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion packages/address-like/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cw-address-like"
version = "1.0.4"
version = "2.0.4"
description = "A trait that marks unchecked or checked CosmWasm address strings"
authors = { workspace = true }
edition = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion packages/item-set/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cw-item-set"
version = "0.7.1"
version = "0.8.0"
description = "Set of non-duplicate items for smart contract store"
authors = { workspace = true }
edition = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions packages/item-set/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct Set<'a, T> {
namespace: &'a [u8],

#[cfg(feature = "counter")]
counter: Item<'a, u64>,
counter: Item<u64>,

item_type: PhantomData<T>,
}
Expand All @@ -40,7 +40,7 @@ impl<'a, T> Set<'a, T> {
#[cfg(feature = "counter")]
impl<'a, T> Set<'a, T> {
/// Create a new instance of the item set with the given map and counter namespaces.
pub const fn new(namespace: &'a str, counter_namespace: &'a str) -> Self {
pub const fn new(namespace: &'a str, counter_namespace: &'static str) -> Self {
Set {
namespace: namespace.as_bytes(),
counter: Item::new(counter_namespace),
Expand Down
2 changes: 1 addition & 1 deletion packages/optional-indexes/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cw-optional-indexes"
version = "0.1.1"
version = "0.2.0"
description = "Index types for CosmWasm IndexedMaps where an item may or may not have an index"
authors = { workspace = true }
edition = { workspace = true }
Expand Down
16 changes: 8 additions & 8 deletions packages/optional-indexes/src/unique.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ pub(crate) struct UniqueRef<T> {
/// In cw-sdk, this is used in the `ACCOUNTS` map, where smart contract accounts
/// are indexed by their labels such that we can enforce that the labels are
/// unique, while base accounts are not indexed.
pub struct OptionalUniqueIndex<'a, IK, T, PK = ()> {
pub struct OptionalUniqueIndex<IK, T, PK = ()> {
index: fn(&T) -> Option<IK>,
idx_map: Map<'a, IK, UniqueRef<T>>,
idx_map: Map<IK, UniqueRef<T>>,
phantom: PhantomData<PK>,
}

impl<'a, IK, T, PK> OptionalUniqueIndex<'a, IK, T, PK> {
pub const fn new(idx_fn: fn(&T) -> Option<IK>, idx_namespace: &'a str) -> Self {
impl<'a, IK, T, PK> OptionalUniqueIndex<IK, T, PK> {
pub const fn new(idx_fn: fn(&T) -> Option<IK>, idx_namespace: &'static str) -> Self {
Self {
index: idx_fn,
idx_map: Map::new(idx_namespace),
Expand All @@ -32,7 +32,7 @@ impl<'a, IK, T, PK> OptionalUniqueIndex<'a, IK, T, PK> {
}
}

impl<'a, IK, T, PK> OptionalUniqueIndex<'a, IK, T, PK>
impl<'a, IK, T, PK> OptionalUniqueIndex<IK, T, PK>
where
PK: KeyDeserialize,
IK: PrimaryKey<'a>,
Expand All @@ -41,7 +41,7 @@ where
pub fn load(&self, store: &dyn Storage, key: IK) -> StdResult<(PK::Output, T)> {
let UniqueRef {
pk,
value
value,
} = self.idx_map.load(store, key)?;
let key = PK::from_slice(&pk)?;
Ok((key, value))
Expand Down Expand Up @@ -82,13 +82,13 @@ where
}
}

impl<'a, IK, T, PK> Index<T> for OptionalUniqueIndex<'a, IK, T, PK>
impl<'a, IK, T, PK> Index<T> for OptionalUniqueIndex<IK, T, PK>
where
T: Serialize + DeserializeOwned + Clone,
IK: PrimaryKey<'a>,
{
fn save(&self, store: &mut dyn Storage, pk: &[u8], data: &T) -> StdResult<()> {
// only save data in idx_map if the index in `Some`
// only save data in idx_map if the index is `Some`
if let Some(idx) = (self.index)(data) {
self.idx_map.update(store, idx, |opt| {
if opt.is_some() {
Expand Down
2 changes: 1 addition & 1 deletion packages/ownable/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cw-ownable"
version = "0.5.1"
version = "0.6.0"
description = "Utility for controlling ownership of CosmWasm smart contracts"
authors = { workspace = true }
edition = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion packages/ownable/derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cw-ownable-derive"
version = "0.5.1"
version = "0.6.0"
description = "Macros for generating code used by the `cw-ownable` crate"
authors = { workspace = true }
edition = { workspace = true }
Expand Down
20 changes: 10 additions & 10 deletions packages/ownable/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,15 +291,15 @@ fn renounce_ownership(

#[cfg(test)]
mod tests {
use cosmwasm_std::{testing::mock_dependencies, Timestamp};
use cosmwasm_std::{testing::{mock_dependencies, MockApi}, Timestamp};

use super::*;

fn mock_addresses() -> [Addr; 3] {
fn mock_addresses(api: &MockApi) -> [Addr; 3] {
[
Addr::unchecked("larry"),
Addr::unchecked("jake"),
Addr::unchecked("pumpkin"),
api.addr_make("larry"),
api.addr_make("jake"),
api.addr_make("pumpkin"),
]
}

Expand All @@ -314,7 +314,7 @@ mod tests {
#[test]
fn initializing_ownership() {
let mut deps = mock_dependencies();
let [larry, _, _] = mock_addresses();
let [larry, _, _] = mock_addresses(&deps.api);

let ownership =
initialize_owner(&mut deps.storage, &deps.api, Some(larry.as_str())).unwrap();
Expand Down Expand Up @@ -349,7 +349,7 @@ mod tests {
#[test]
fn asserting_ownership() {
let mut deps = mock_dependencies();
let [larry, jake, _] = mock_addresses();
let [larry, jake, _] = mock_addresses(&deps.api);

// case 1. owner has not renounced
{
Expand All @@ -374,7 +374,7 @@ mod tests {
#[test]
fn transferring_ownership() {
let mut deps = mock_dependencies();
let [larry, jake, pumpkin] = mock_addresses();
let [larry, jake, pumpkin] = mock_addresses(&deps.api);

initialize_owner(&mut deps.storage, &deps.api, Some(larry.as_str())).unwrap();

Expand Down Expand Up @@ -422,7 +422,7 @@ mod tests {
#[test]
fn accepting_ownership() {
let mut deps = mock_dependencies();
let [larry, jake, pumpkin] = mock_addresses();
let [larry, jake, pumpkin] = mock_addresses(&deps.api);

initialize_owner(&mut deps.storage, &deps.api, Some(larry.as_str())).unwrap();

Expand Down Expand Up @@ -496,7 +496,7 @@ mod tests {
#[test]
fn renouncing_ownership() {
let mut deps = mock_dependencies();
let [larry, jake, pumpkin] = mock_addresses();
let [larry, jake, pumpkin] = mock_addresses(&deps.api);

let ownership = Ownership {
owner: Some(larry.clone()),
Expand Down
2 changes: 1 addition & 1 deletion packages/paginate/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cw-paginate"
version = "0.2.1"
version = "0.3.0"
description = "Helper function for iterating CosmWasm storage maps with pagination"
authors = [
"Larry Engineer <[email protected]>",
Expand Down
6 changes: 3 additions & 3 deletions packages/paginate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ where
///
/// TODO: add docs
pub fn paginate_map<'a, K, T, R, E, F>(
map: &Map<'a, K, T>,
map: &Map<K, T>,
store: &dyn Storage,
start: Option<Bound<'a, K>>,
limit: Option<u32>,
Expand All @@ -52,7 +52,7 @@ where
///
/// TODO: add docs
pub fn paginate_map_prefix<'a, K, T, R, E, F>(
map: &Map<'a, K, T>,
map: &Map<K, T>,
store: &dyn Storage,
prefix: K::Prefix,
start: Option<Bound<'a, K::Suffix>>,
Expand All @@ -75,7 +75,7 @@ where
///
/// TODO: add docs
pub fn paginate_indexed_map<'a, K, T, I, R, E, F>(
map: &IndexedMap<'a, K, T, I>,
map: &IndexedMap<K, T, I>,
store: &dyn Storage,
start: Option<Bound<'a, K>>,
limit: Option<u32>,
Expand Down

0 comments on commit 718351d

Please sign in to comment.