Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cosmwasm v2 updates #172

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
1,123 changes: 735 additions & 388 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 11 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "2"
members = ["packages/*", "contracts/*"]

[workspace.package]
Expand All @@ -11,10 +12,10 @@ documentation = "https://docs.cosmwasm.com"
rust-version = "1.78"

[workspace.dependencies]
cosmwasm-schema = "^1.5"
cosmwasm-std = "^1.5"
cw2 = "^1.1"
cw20 = "^1.1"
cosmwasm-schema = "^2.1"
cosmwasm-std = "^2.1"
cw2 = "^2.0"
cw20 = "^2.0"
cw721 = { version = "*", path = "./packages/cw721" }
cw721-016 = { git = "https://github.com/CosmWasm/cw-nfts", tag = "v0.16.0", package = "cw721" } # needed for backwards compatibility and legacy migration
cw721-base = { version = "*", path = "./contracts/cw721-base" }
Expand All @@ -23,11 +24,12 @@ cw721-base-016 = { git = "https://github.com/CosmWasm/cw-nfts", tag = "v0.16.0"
cw721-metadata-onchain-016 = { git = "https://github.com/CosmWasm/cw-nfts", tag = "v0.16.0", package = "cw721-metadata-onchain" } # needed for testing legacy migration
cw721-base-017 = { git = "https://github.com/CosmWasm/cw-nfts", tag = "v0.17.0", package = "cw721-base" } # needed for testing legacy migration
cw721-base-018 = { git = "https://github.com/CosmWasm/cw-nfts", tag = "v0.18.0", package = "cw721-base" } # needed for testing legacy migration
cw-multi-test = { version = "^0.20", features = ["cosmwasm_1_2"] }
cw-ownable = { git = "https://github.com/public-awesome/cw-plus-plus.git", rev = "28c1a09bfc6b4f1942fefe3eb0b50faf9d3b1523"} # TODO: switch to official https://github.com/larry0x/cw-plus-plus once merged
cw-paginate-storage = { version = "^2.4", git = "https://github.com/DA0-DA0/dao-contracts.git" }
cw-storage-plus = "^1.1"
cw-utils = "^1.0"
cw-multi-test = { version = "^2.1", features = ["cosmwasm_2_0"] }
# TODO: switch to official https://github.com/larry0x/cw-plus-plus
# requires merge of https://github.com/larry0x/cw-plus-plus/pull/25
cw-ownable = { git = "https://github.com/mintthemoon/cw-plus-plus", branch = "dev", package = "cw-ownable" }
Comment on lines +28 to +30

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed that mentioned PR got merged 👀

Suggested change
# TODO: switch to official https://github.com/larry0x/cw-plus-plus
# requires merge of https://github.com/larry0x/cw-plus-plus/pull/25
cw-ownable = { git = "https://github.com/mintthemoon/cw-plus-plus", branch = "dev", package = "cw-ownable" }
cw-ownable = { version = "^2.1" }

cw-storage-plus = "^2.0"
cw-utils = "^2.0"
schemars = "^0.8"
serde = { version = "^1.0", default-features = false, features = ["derive"] }
thiserror = "^1.0"
Expand Down
2 changes: 0 additions & 2 deletions contracts/cw2981-royalties/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ rust-version = { workspace = true }
crate-type = ["cdylib", "rlib"]

[features]
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]
# use library feature to disable all instantiate/execute/query exports
library = []

Expand Down
38 changes: 19 additions & 19 deletions contracts/cw2981-royalties/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ mod tests {

use cosmwasm_std::{from_json, Uint128};

use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info};
use cosmwasm_std::testing::{message_info, mock_dependencies, mock_env};
use cw721::msg::Cw721InstantiateMsg;
use cw721::traits::Cw721Query;
use state::Cw2981Contract;
Expand All @@ -143,8 +143,8 @@ mod tests {
fn use_metadata_extension() {
let mut deps = mock_dependencies();
let contract = Cw2981Contract::default();

let info = mock_info(CREATOR, &[]);
let creator = deps.api.addr_make(CREATOR);
let info = message_info(&creator, &[]);
let init_msg = Cw721InstantiateMsg {
name: "SpaceShips".to_string(),
symbol: "SPACE".to_string(),
Expand All @@ -164,7 +164,7 @@ mod tests {
});
let exec_msg = ExecuteMsg::Mint {
token_id: token_id.to_string(),
owner: "john".to_string(),
owner: deps.api.addr_make("john").to_string(),
token_uri: token_uri.clone(),
extension: extension.clone(),
};
Expand All @@ -182,8 +182,8 @@ mod tests {
fn validate_royalty_information() {
let mut deps = mock_dependencies();
let _contract = Cw2981Contract::default();

let info = mock_info(CREATOR, &[]);
let creator = deps.api.addr_make(CREATOR);
let info = message_info(&creator, &[]);
let init_msg = Cw721InstantiateMsg {
name: "SpaceShips".to_string(),
symbol: "SPACE".to_string(),
Expand Down Expand Up @@ -215,8 +215,8 @@ mod tests {
fn check_royalties_response() {
let mut deps = mock_dependencies();
let _contract = Cw2981Contract::default();

let info = mock_info(CREATOR, &[]);
let creator = deps.api.addr_make(CREATOR);
let info = message_info(&creator, &[]);
let init_msg = Cw721InstantiateMsg {
name: "SpaceShips".to_string(),
symbol: "SPACE".to_string(),
Expand All @@ -230,7 +230,7 @@ mod tests {
let token_id = "Enterprise";
let exec_msg = ExecuteMsg::Mint {
token_id: token_id.to_string(),
owner: "john".to_string(),
owner: deps.api.addr_make("john").to_string(),
token_uri: Some("https://starships.example.com/Starship/Enterprise.json".into()),
extension: Some(MetadataWithRoyalty {
description: Some("Spaceship with Warp Drive".into()),
Expand All @@ -256,8 +256,8 @@ mod tests {
#[test]
fn check_token_royalties() {
let mut deps = mock_dependencies();

let info = mock_info(CREATOR, &[]);
let creator = deps.api.addr_make(CREATOR);
let info = message_info(&creator, &[]);
let init_msg = Cw721InstantiateMsg {
name: "SpaceShips".to_string(),
symbol: "SPACE".to_string(),
Expand All @@ -270,23 +270,23 @@ mod tests {
entry::instantiate(deps.as_mut(), env.clone(), info.clone(), init_msg).unwrap();

let token_id = "Enterprise";
let owner = "jeanluc";
let owner = deps.api.addr_make("jeanluc");
let exec_msg = ExecuteMsg::Mint {
token_id: token_id.to_string(),
owner: owner.into(),
owner: owner.to_string(),
token_uri: Some("https://starships.example.com/Starship/Enterprise.json".into()),
extension: Some(MetadataWithRoyalty {
description: Some("Spaceship with Warp Drive".into()),
name: Some("Starship USS Enterprise".to_string()),
royalty_payment_address: Some("jeanluc".to_string()),
royalty_payment_address: Some(owner.to_string()),
royalty_percentage: Some(10),
..MetadataWithRoyalty::default()
}),
};
entry::execute(deps.as_mut(), mock_env(), info.clone(), exec_msg).unwrap();

let expected = RoyaltiesInfoResponse {
address: owner.into(),
address: owner.to_string(),
royalty_amount: Uint128::new(10),
};
let res =
Expand All @@ -305,15 +305,15 @@ mod tests {
// check for rounding down
// which is the default behaviour
let voyager_token_id = "Voyager";
let owner = "janeway";
let owner = deps.api.addr_make("janeway");
let voyager_exec_msg = ExecuteMsg::Mint {
token_id: voyager_token_id.to_string(),
owner: owner.into(),
owner: owner.to_string(),
token_uri: Some("https://starships.example.com/Starship/Voyager.json".into()),
extension: Some(MetadataWithRoyalty {
description: Some("Spaceship with Warp Drive".into()),
name: Some("Starship USS Voyager".to_string()),
royalty_payment_address: Some("janeway".to_string()),
royalty_payment_address: Some(owner.to_string()),
royalty_percentage: Some(4),
..MetadataWithRoyalty::default()
}),
Expand All @@ -323,7 +323,7 @@ mod tests {
// 43 x 0.04 (i.e., 4%) should be 1.72
// we expect this to be rounded down to 1
let voyager_expected = RoyaltiesInfoResponse {
address: owner.into(),
address: owner.to_string(),
royalty_amount: Uint128::new(1),
};

Expand Down
2 changes: 1 addition & 1 deletion contracts/cw2981-royalties/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn query_royalties_info(
},
None => Decimal::percent(0),
};
let royalty_from_sale_price = sale_price * royalty_percentage;
let royalty_from_sale_price = sale_price.mul_floor(royalty_percentage);

let royalty_address = match token_info.extension {
Some(ext) => ext.royalty_payment_address.unwrap_or_default(),
Expand Down
2 changes: 0 additions & 2 deletions contracts/cw721-base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ doctest = false # disable doc tests
crate-type = ["cdylib", "rlib"]

[features]
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]
# use library feature to disable all instantiate/execute/query exports
library = []

Expand Down
8 changes: 5 additions & 3 deletions contracts/cw721-base/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub mod entry {
mod tests {
use super::*;

use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info};
use cosmwasm_std::testing::{message_info, mock_dependencies, mock_env};
use cw721::traits::{Cw721Execute, Cw721Query};
use extension::Cw721BaseExtensions;
use msg::{ExecuteMsg, InstantiateMsg};
Expand All @@ -102,7 +102,8 @@ mod tests {
fn use_empty_metadata_extension() {
let mut deps = mock_dependencies();
let contract = Cw721BaseExtensions::default();
let info = mock_info(CREATOR, &[]);
let creator = deps.api.addr_make(CREATOR);
let info = message_info(&creator, &[]);
let init_msg = InstantiateMsg {
name: "SpaceShips".to_string(),
symbol: "SPACE".to_string(),
Expand All @@ -118,9 +119,10 @@ mod tests {
let token_id = "Enterprise";
let token_uri = Some("https://starships.example.com/Starship/Enterprise.json".into());
let extension = Some(Empty {});
let owner = deps.api.addr_make("john");
let exec_msg = ExecuteMsg::Mint {
token_id: token_id.to_string(),
owner: "john".to_string(),
owner: owner.to_string(),
token_uri: token_uri.clone(),
extension: extension.clone(),
};
Expand Down
2 changes: 0 additions & 2 deletions contracts/cw721-expiration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ rust-version = { workspace = true }
crate-type = ["cdylib", "rlib"]

[features]
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]
# use library feature to disable all instantiate/execute/query exports
library = []

Expand Down
Loading