diff --git a/.cargo/config b/.cargo/config.toml similarity index 100% rename from .cargo/config rename to .cargo/config.toml diff --git a/.circleci/config.yml b/.circleci/config.yml index 856d6d100..881a730c9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -267,7 +267,7 @@ jobs: # Uses --debug for compilation speed command: | source $HOME/.cargo/env - cargo install --debug --version 1.1.0 --locked cosmwasm-check + cargo install --debug --version 2.0.1 --locked cosmwasm-check - run: name: Check wasm contracts command: | diff --git a/Cargo.lock b/Cargo.lock index 3bad6b0f2..437013d11 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,12 +13,157 @@ dependencies = [ "version_check", ] +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "allocator-api2" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" + [[package]] name = "anyhow" version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" +[[package]] +name = "ark-bls12-381" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c775f0d12169cba7aae4caeb547bb6a50781c7449a8aa53793827c9ec4abf488" +dependencies = [ + "ark-ec", + "ark-ff", + "ark-serialize", + "ark-std", +] + +[[package]] +name = "ark-ec" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "defd9a439d56ac24968cca0571f598a61bc8c55f71d50a89cda591cb750670ba" +dependencies = [ + "ark-ff", + "ark-poly", + "ark-serialize", + "ark-std", + "derivative", + "hashbrown 0.13.2", + "itertools 0.10.5", + "num-traits", + "rayon", + "zeroize", +] + +[[package]] +name = "ark-ff" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec847af850f44ad29048935519032c33da8aa03340876d351dfab5660d2966ba" +dependencies = [ + "ark-ff-asm", + "ark-ff-macros", + "ark-serialize", + "ark-std", + "derivative", + "digest 0.10.7", + "itertools 0.10.5", + "num-bigint", + "num-traits", + "paste", + "rayon", + "rustc_version", + "zeroize", +] + +[[package]] +name = "ark-ff-asm" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ed4aa4fe255d0bc6d79373f7e31d2ea147bcf486cba1be5ba7ea85abdb92348" +dependencies = [ + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-ff-macros" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7abe79b0e4288889c4574159ab790824d0033b9fdcb2a112a3182fac2e514565" +dependencies = [ + "num-bigint", + "num-traits", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-poly" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d320bfc44ee185d899ccbadfa8bc31aab923ce1558716e1997a1e74057fe86bf" +dependencies = [ + "ark-ff", + "ark-serialize", + "ark-std", + "derivative", + "hashbrown 0.13.2", +] + +[[package]] +name = "ark-serialize" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adb7b85a02b83d2f22f89bd5cac66c9c89474240cb6207cb1efc16d098e822a5" +dependencies = [ + "ark-serialize-derive", + "ark-std", + "digest 0.10.7", + "num-bigint", +] + +[[package]] +name = "ark-serialize-derive" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae3281bc6d0fd7e549af32b52511e1302185bd688fd3359fa36423346ff682ea" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-std" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94893f1e0c6eeab764ade8dc4c0db24caf4fe7cbbaafc0eba0a9030f447b5185" +dependencies = [ + "num-traits", + "rand", + "rayon", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + [[package]] name = "base16ct" version = "0.2.0" @@ -31,6 +176,12 @@ version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "base64ct" version = "1.6.0" @@ -43,6 +194,12 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" +[[package]] +name = "bech32" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d" + [[package]] name = "block-buffer" version = "0.9.0" @@ -63,9 +220,15 @@ dependencies = [ [[package]] name = "bnum" -version = "0.10.0" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab9008b6bb9fc80b5277f2fe481c09e828743d9151203e804583eb4c9e15b31d" + +[[package]] +name = "bnum" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56953345e39537a3e18bdaeba4cb0c58a78c1f61f361dc0fa7c5c7340ae87c5f" +checksum = "3e31ea183f6ee62ac8b8a8cf7feddd766317adfb13ff469de57ce033efd6a790" [[package]] name = "byteorder" @@ -91,20 +254,49 @@ version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" +[[package]] +name = "cosmwasm-core" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d075f6bb1483a6ce83b5cbc73a3a1207e0316ac1e34ed1f2a4d9fc3a0f07bf6" + [[package]] name = "cosmwasm-crypto" -version = "1.5.5" +version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd50718a2b6830ce9eb5d465de5a018a12e71729d66b70807ce97e6dd14f931d" +checksum = "8ed6aa9f904de106fa16443ad14ec2abe75e94ba003bb61c681c0e43d4c58d2a" dependencies = [ "digest 0.10.7", "ecdsa", - "ed25519-zebra", + "ed25519-zebra 3.1.0", "k256", "rand_core 0.6.4", "thiserror", ] +[[package]] +name = "cosmwasm-crypto" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ced5a6dd2801a383d3e14e5ae5caa7fdfeff1bd9f22b30e810e0aded8a5869" +dependencies = [ + "ark-bls12-381", + "ark-ec", + "ark-ff", + "ark-serialize", + "cosmwasm-core", + "digest 0.10.7", + "ecdsa", + "ed25519-zebra 4.0.3", + "k256", + "num-traits", + "p256", + "rand_core 0.6.4", + "rayon", + "sha2 0.10.8", + "thiserror", +] + [[package]] name = "cosmwasm-derive" version = "1.5.5" @@ -114,13 +306,37 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "cosmwasm-derive" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35bd1873f84d9b17edf8a90ffe10a89a649b82feacc00e36788b81d2c3cbf03c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", +] + [[package]] name = "cosmwasm-schema" version = "1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7879036156092ad1c22fe0d7316efc5a5eceec2bc3906462a2560215f2a2f929" dependencies = [ - "cosmwasm-schema-derive", + "cosmwasm-schema-derive 1.5.5", + "schemars", + "serde", + "serde_json", + "thiserror", +] + +[[package]] +name = "cosmwasm-schema" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27984b137eb2ac561f97f6bdb02004a98eb6f2ba263062c140b8e231ee1826b7" +dependencies = [ + "cosmwasm-schema-derive 2.1.0", "schemars", "serde", "serde_json", @@ -138,23 +354,57 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "cosmwasm-schema-derive" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4ef0d201f611bdb6c9124207032423eb956f1fc8ab3e3ee7253a9c08a5f5809" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", +] + [[package]] name = "cosmwasm-std" -version = "1.5.5" +version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78c1556156fdf892a55cced6115968b961eaaadd6f724a2c2cb7d1e168e32dd3" +checksum = "ad011ae7447188e26e4a7dbca2fcd0fc186aa21ae5c86df0503ea44c78f9e469" dependencies = [ - "base64", - "bech32", - "bnum", - "cosmwasm-crypto", - "cosmwasm-derive", + "base64 0.21.7", + "bech32 0.9.1", + "bnum 0.8.1", + "cosmwasm-crypto 1.5.2", + "cosmwasm-derive 1.5.5", "derivative", "forward_ref", "hex", "schemars", "serde", - "serde-json-wasm", + "serde-json-wasm 0.5.2", + "sha2 0.10.8", + "static_assertions", + "thiserror", +] + +[[package]] +name = "cosmwasm-std" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2522fb5c9a0409712bb1d036128bccf3564e6b2ac82f942ae4cf3c8df3e26fa8" +dependencies = [ + "base64 0.22.1", + "bech32 0.11.0", + "bnum 0.11.0", + "cosmwasm-core", + "cosmwasm-crypto 2.1.0", + "cosmwasm-derive 2.1.0", + "derive_more", + "hex", + "rand_core 0.6.4", + "schemars", + "serde", + "serde-json-wasm 1.0.1", "sha2 0.10.8", "static_assertions", "thiserror", @@ -169,6 +419,31 @@ dependencies = [ "libc", ] +[[package]] +name = "crossbeam-deque" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" + [[package]] name = "crypto-bigint" version = "0.5.5" @@ -204,36 +479,63 @@ dependencies = [ "zeroize", ] +[[package]] +name = "curve25519-dalek" +version = "4.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be" +dependencies = [ + "cfg-if", + "cpufeatures", + "curve25519-dalek-derive", + "digest 0.10.7", + "fiat-crypto", + "rustc_version", + "subtle", + "zeroize", +] + +[[package]] +name = "curve25519-dalek-derive" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", +] + [[package]] name = "cw-address-like" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "451a4691083a88a3c0630a8a88799e9d4cd6679b7ce8ff22b8da2873ff31d380" dependencies = [ - "cosmwasm-std", + "cosmwasm-std 1.5.2", ] [[package]] name = "cw-address-like" -version = "1.0.4" -source = "git+https://github.com/public-awesome/cw-plus-plus.git?rev=28c1a09bfc6b4f1942fefe3eb0b50faf9d3b1523#28c1a09bfc6b4f1942fefe3eb0b50faf9d3b1523" +version = "2.0.4" +source = "git+https://github.com/larry0x/cw-plus-plus.git?rev=718351d4e9d66edbf3b6dbea2d13b56ef732f51c#718351d4e9d66edbf3b6dbea2d13b56ef732f51c" dependencies = [ - "cosmwasm-std", + "cosmwasm-std 2.1.0", ] [[package]] name = "cw-multi-test" -version = "0.20.1" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc392a5cb7e778e3f90adbf7faa43c4db7f35b6623224b08886d796718edb875" +checksum = "e0034bfb4c06dfc8b50f0b1a06c3fc0f2312a1bae568a97db65930de071288ba" dependencies = [ "anyhow", - "bech32", - "cosmwasm-std", - "cw-storage-plus 1.2.0", - "cw-utils 1.0.3", + "bech32 0.11.0", + "cosmwasm-std 2.1.0", + "cw-storage-plus 2.0.0", + "cw-utils 2.0.0", "derivative", - "itertools 0.12.1", + "itertools 0.13.0", "prost 0.12.6", "schemars", "serde", @@ -247,9 +549,9 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "093dfb4520c48b5848274dd88ea99e280a04bc08729603341c7fb0d758c74321" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cw-address-like 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "cosmwasm-schema 1.5.5", + "cosmwasm-std 1.5.2", + "cw-address-like 1.0.4", "cw-ownable-derive 0.5.1", "cw-storage-plus 1.2.0", "cw-utils 1.0.3", @@ -259,14 +561,14 @@ dependencies = [ [[package]] name = "cw-ownable" version = "0.6.0" -source = "git+https://github.com/public-awesome/cw-plus-plus.git?rev=28c1a09bfc6b4f1942fefe3eb0b50faf9d3b1523#28c1a09bfc6b4f1942fefe3eb0b50faf9d3b1523" +source = "git+https://github.com/larry0x/cw-plus-plus.git?rev=718351d4e9d66edbf3b6dbea2d13b56ef732f51c#718351d4e9d66edbf3b6dbea2d13b56ef732f51c" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cw-address-like 1.0.4 (git+https://github.com/public-awesome/cw-plus-plus.git?rev=28c1a09bfc6b4f1942fefe3eb0b50faf9d3b1523)", + "cosmwasm-schema 2.1.0", + "cosmwasm-std 2.1.0", + "cw-address-like 2.0.4", "cw-ownable-derive 0.6.0", - "cw-storage-plus 1.2.0", - "cw-utils 1.0.3", + "cw-storage-plus 2.0.0", + "cw-utils 2.0.0", "thiserror", ] @@ -284,7 +586,7 @@ dependencies = [ [[package]] name = "cw-ownable-derive" version = "0.6.0" -source = "git+https://github.com/public-awesome/cw-plus-plus.git?rev=28c1a09bfc6b4f1942fefe3eb0b50faf9d3b1523#28c1a09bfc6b4f1942fefe3eb0b50faf9d3b1523" +source = "git+https://github.com/larry0x/cw-plus-plus.git?rev=718351d4e9d66edbf3b6dbea2d13b56ef732f51c#718351d4e9d66edbf3b6dbea2d13b56ef732f51c" dependencies = [ "proc-macro2", "quote", @@ -297,7 +599,7 @@ version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b6f91c0b94481a3e9ef1ceb183c37d00764f8751e39b45fc09f4d9b970d469" dependencies = [ - "cosmwasm-std", + "cosmwasm-std 1.5.2", "schemars", "serde", ] @@ -308,7 +610,18 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d5ff29294ee99373e2cd5fd21786a3c0ced99a52fec2ca347d565489c61b723c" dependencies = [ - "cosmwasm-std", + "cosmwasm-std 1.5.2", + "schemars", + "serde", +] + +[[package]] +name = "cw-storage-plus" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f13360e9007f51998d42b1bc6b7fa0141f74feae61ed5fd1e5b0a89eec7b5de1" +dependencies = [ + "cosmwasm-std 2.1.0", "schemars", "serde", ] @@ -319,8 +632,8 @@ version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6a84c6c1c0acc3616398eba50783934bd6c964bad6974241eaee3460c8f5b26" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", + "cosmwasm-schema 1.5.5", + "cosmwasm-std 1.5.2", "cw2 0.16.0", "schemars", "semver", @@ -334,8 +647,8 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c4a657e5caacc3a0d00ee96ca8618745d050b8f757c709babafb81208d4239c" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", + "cosmwasm-schema 1.5.5", + "cosmwasm-std 1.5.2", "cw2 1.1.2", "schemars", "semver", @@ -343,14 +656,27 @@ dependencies = [ "thiserror", ] +[[package]] +name = "cw-utils" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07dfee7f12f802431a856984a32bce1cb7da1e6c006b5409e3981035ce562dec" +dependencies = [ + "cosmwasm-schema 2.1.0", + "cosmwasm-std 2.1.0", + "schemars", + "serde", + "thiserror", +] + [[package]] name = "cw2" version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "91398113b806f4d2a8d5f8d05684704a20ffd5968bf87e3473e1973710b884ad" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", + "cosmwasm-schema 1.5.5", + "cosmwasm-std 1.5.2", "cw-storage-plus 0.16.0", "schemars", "serde", @@ -362,8 +688,8 @@ version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c6c120b24fbbf5c3bedebb97f2cc85fbfa1c3287e09223428e7e597b5293c1fa" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", + "cosmwasm-schema 1.5.5", + "cosmwasm-std 1.5.2", "cw-storage-plus 1.2.0", "schemars", "semver", @@ -371,29 +697,44 @@ dependencies = [ "thiserror", ] +[[package]] +name = "cw2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b04852cd38f044c0751259d5f78255d07590d136b8a86d4e09efdd7666bd6d27" +dependencies = [ + "cosmwasm-schema 2.1.0", + "cosmwasm-std 2.1.0", + "cw-storage-plus 2.0.0", + "schemars", + "semver", + "serde", + "thiserror", +] + [[package]] name = "cw20" -version = "1.1.2" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "526e39bb20534e25a1cd0386727f0038f4da294e5e535729ba3ef54055246abd" +checksum = "a42212b6bf29bbdda693743697c621894723f35d3db0d5df930be22903d0e27c" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cw-utils 1.0.3", + "cosmwasm-schema 2.1.0", + "cosmwasm-std 2.1.0", + "cw-utils 2.0.0", "schemars", "serde", ] [[package]] name = "cw2981-royalties" -version = "0.19.0" +version = "2.0.0" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", + "cosmwasm-schema 2.1.0", + "cosmwasm-std 2.1.0", "cw-ownable 0.6.0", - "cw2 1.1.2", - "cw721 0.19.0", - "cw721-base 0.19.0", + "cw2 2.0.0", + "cw721 2.0.0", + "cw721-base 2.0.0", "schemars", "serde", "thiserror", @@ -405,8 +746,8 @@ version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94a1ea6e6277bdd6dfc043a9b1380697fe29d6e24b072597439523658d21d791" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", + "cosmwasm-schema 1.5.5", + "cosmwasm-std 1.5.2", "cw-utils 0.16.0", "schemars", "serde", @@ -417,8 +758,8 @@ name = "cw721" version = "0.16.0" source = "git+https://github.com/CosmWasm/cw-nfts?tag=v0.16.0#2cad1d3e15e0a34d466a0b51e02c58b82ebe5ecd" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", + "cosmwasm-schema 1.5.5", + "cosmwasm-std 1.5.2", "cw-utils 0.16.0", "schemars", "serde", @@ -429,8 +770,8 @@ name = "cw721" version = "0.17.0" source = "git+https://github.com/CosmWasm/cw-nfts?tag=v0.17.0#c1ece555dded6cbcebba1d417ed2a18d47ca3c8a" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", + "cosmwasm-schema 1.5.5", + "cosmwasm-std 1.5.2", "cw-utils 1.0.3", "schemars", "serde", @@ -441,8 +782,8 @@ name = "cw721" version = "0.18.0" source = "git+https://github.com/CosmWasm/cw-nfts?tag=v0.18.0#177a993dfb5a1a3164be1baf274f43b1ca53da53" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", + "cosmwasm-schema 1.5.5", + "cosmwasm-std 1.5.2", "cw-utils 1.0.3", "schemars", "serde", @@ -450,15 +791,15 @@ dependencies = [ [[package]] name = "cw721" -version = "0.19.0" +version = "2.0.0" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", + "cosmwasm-schema 2.1.0", + "cosmwasm-std 2.1.0", "cw-multi-test", "cw-ownable 0.6.0", - "cw-storage-plus 1.2.0", - "cw-utils 1.0.3", - "cw2 1.1.2", + "cw-storage-plus 2.0.0", + "cw-utils 2.0.0", + "cw2 2.0.0", "cw721 0.16.0 (git+https://github.com/CosmWasm/cw-nfts?tag=v0.16.0)", "cw721-base 0.16.0 (git+https://github.com/CosmWasm/cw-nfts?tag=v0.16.0)", "cw721-base 0.17.0", @@ -474,8 +815,8 @@ version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77518e27431d43214cff4cdfbd788a7508f68d9b1f32389e6fce513e7eaccbef" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", + "cosmwasm-schema 1.5.5", + "cosmwasm-std 1.5.2", "cw-storage-plus 0.16.0", "cw-utils 0.16.0", "cw2 0.16.0", @@ -490,8 +831,8 @@ name = "cw721-base" version = "0.16.0" source = "git+https://github.com/CosmWasm/cw-nfts?tag=v0.16.0#2cad1d3e15e0a34d466a0b51e02c58b82ebe5ecd" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", + "cosmwasm-schema 1.5.5", + "cosmwasm-std 1.5.2", "cw-storage-plus 0.16.0", "cw-utils 0.16.0", "cw2 0.16.0", @@ -506,8 +847,8 @@ name = "cw721-base" version = "0.17.0" source = "git+https://github.com/CosmWasm/cw-nfts?tag=v0.17.0#c1ece555dded6cbcebba1d417ed2a18d47ca3c8a" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", + "cosmwasm-schema 1.5.5", + "cosmwasm-std 1.5.2", "cw-ownable 0.5.1", "cw-storage-plus 1.2.0", "cw-utils 1.0.3", @@ -524,8 +865,8 @@ name = "cw721-base" version = "0.18.0" source = "git+https://github.com/CosmWasm/cw-nfts?tag=v0.18.0#177a993dfb5a1a3164be1baf274f43b1ca53da53" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", + "cosmwasm-schema 1.5.5", + "cosmwasm-std 1.5.2", "cw-ownable 0.5.1", "cw-storage-plus 1.2.0", "cw-utils 1.0.3", @@ -539,30 +880,33 @@ dependencies = [ [[package]] name = "cw721-base" -version = "0.19.0" +version = "2.0.0" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", + "cosmwasm-schema 2.1.0", + "cosmwasm-std 2.1.0", + "cw-multi-test", "cw-ownable 0.6.0", - "cw2 1.1.2", + "cw-storage-plus 2.0.0", + "cw-utils 2.0.0", + "cw2 2.0.0", "cw721 0.17.0", "cw721 0.18.0", - "cw721 0.19.0", + "cw721 2.0.0", "serde", ] [[package]] name = "cw721-expiration" -version = "0.19.0" +version = "2.0.0" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", + "cosmwasm-schema 2.1.0", + "cosmwasm-std 2.1.0", "cw-multi-test", "cw-ownable 0.6.0", - "cw-storage-plus 1.2.0", - "cw2 1.1.2", - "cw721 0.19.0", - "cw721-base 0.19.0", + "cw-storage-plus 2.0.0", + "cw2 2.0.0", + "cw721 2.0.0", + "cw721-base 2.0.0", "schemars", "serde", "thiserror", @@ -570,16 +914,16 @@ dependencies = [ [[package]] name = "cw721-fixed-price" -version = "0.19.0" +version = "2.0.0" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cw-storage-plus 1.2.0", - "cw-utils 1.0.3", - "cw2 1.1.2", + "cosmwasm-schema 2.1.0", + "cosmwasm-std 2.1.0", + "cw-storage-plus 2.0.0", + "cw-utils 2.0.0", + "cw2 2.0.0", "cw20", - "cw721 0.19.0", - "cw721-base 0.19.0", + "cw721 2.0.0", + "cw721-base 2.0.0", "prost 0.10.4", "schemars", "serde", @@ -588,27 +932,27 @@ dependencies = [ [[package]] name = "cw721-non-transferable" -version = "0.19.0" -dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cw-storage-plus 1.2.0", - "cw2 1.1.2", - "cw721 0.19.0", - "cw721-base 0.19.0", +version = "2.0.0" +dependencies = [ + "cosmwasm-schema 2.1.0", + "cosmwasm-std 2.1.0", + "cw-storage-plus 2.0.0", + "cw2 2.0.0", + "cw721 2.0.0", + "cw721-base 2.0.0", "schemars", "serde", ] [[package]] name = "cw721-receiver-tester" -version = "0.19.0" +version = "2.0.0" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", + "cosmwasm-schema 2.1.0", + "cosmwasm-std 2.1.0", "cw-multi-test", - "cw721 0.19.0", - "cw721-base 0.19.0", + "cw721 2.0.0", + "cw721-base 2.0.0", "schemars", "serde", "thiserror", @@ -635,6 +979,27 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "derive_more" +version = "1.0.0-beta.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7abbfc297053be59290e3152f8cbcd52c8642e0728b69ee187d991d4c1af08d" +dependencies = [ + "derive_more-impl", +] + +[[package]] +name = "derive_more-impl" +version = "1.0.0-beta.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bba3e9872d7c58ce7ef0fcf1844fcc3e23ef2a58377b50df35dd98e42a5726e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", + "unicode-xid", +] + [[package]] name = "digest" version = "0.9.0" @@ -676,14 +1041,23 @@ dependencies = [ "spki", ] +[[package]] +name = "ed25519" +version = "2.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" +dependencies = [ + "signature", +] + [[package]] name = "ed25519-zebra" version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c24f403d068ad0b359e577a77f92392118be3f3c927538f2bb544a5ecd828c6" dependencies = [ - "curve25519-dalek", - "hashbrown", + "curve25519-dalek 3.2.0", + "hashbrown 0.12.3", "hex", "rand_core 0.6.4", "serde", @@ -691,6 +1065,21 @@ dependencies = [ "zeroize", ] +[[package]] +name = "ed25519-zebra" +version = "4.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d9ce6874da5d4415896cd45ffbc4d1cfc0c4f9c079427bd870742c30f2f65a9" +dependencies = [ + "curve25519-dalek 4.1.3", + "ed25519", + "hashbrown 0.14.5", + "hex", + "rand_core 0.6.4", + "sha2 0.10.8", + "zeroize", +] + [[package]] name = "either" version = "1.12.0" @@ -726,6 +1115,12 @@ dependencies = [ "subtle", ] +[[package]] +name = "fiat-crypto" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" + [[package]] name = "forward_ref" version = "1.0.0" @@ -771,7 +1166,26 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" dependencies = [ - "ahash", + "ahash 0.7.8", +] + +[[package]] +name = "hashbrown" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" +dependencies = [ + "ahash 0.8.11", +] + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +dependencies = [ + "ahash 0.8.11", + "allocator-api2", ] [[package]] @@ -807,6 +1221,15 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.11" @@ -815,9 +1238,9 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "k256" -version = "0.13.1" +version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cadb76004ed8e97623117f3df85b17aaa6626ab0b0831e6573f104df16cd1bcc" +checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" dependencies = [ "cfg-if", "ecdsa", @@ -833,6 +1256,34 @@ version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +[[package]] +name = "num-bigint" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" +dependencies = [ + "num-integer", + "num-traits", +] + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + [[package]] name = "once_cell" version = "1.19.0" @@ -845,6 +1296,24 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" +[[package]] +name = "p256" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9863ad85fa8f4460f9c48cb909d38a0d689dba1f6f6988a5e3e0d31071bcd4b" +dependencies = [ + "ecdsa", + "elliptic-curve", + "primeorder", + "sha2 0.10.8", +] + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + [[package]] name = "pkcs8" version = "0.10.2" @@ -855,6 +1324,21 @@ dependencies = [ "spki", ] +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "primeorder" +version = "0.13.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "353e1ca18966c16d9deb1c69278edbc5f194139612772bd9537af60ac231e1e6" +dependencies = [ + "elliptic-curve", +] + [[package]] name = "proc-macro2" version = "1.0.85" @@ -919,6 +1403,26 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "rand_chacha", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.4", +] + [[package]] name = "rand_core" version = "0.5.1" @@ -934,6 +1438,26 @@ dependencies = [ "getrandom", ] +[[package]] +name = "rayon" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + [[package]] name = "rfc6979" version = "0.4.0" @@ -944,6 +1468,15 @@ dependencies = [ "subtle", ] +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + [[package]] name = "ryu" version = "1.0.18" @@ -1012,6 +1545,15 @@ dependencies = [ "serde", ] +[[package]] +name = "serde-json-wasm" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f05da0d153dd4595bdffd5099dc0e9ce425b205ee648eb93437ff7302af8c9a5" +dependencies = [ + "serde", +] + [[package]] name = "serde_derive" version = "1.0.203" @@ -1155,6 +1697,12 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + [[package]] name = "version_check" version = "0.9.4" @@ -1167,8 +1715,42 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", +] + [[package]] name = "zeroize" version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", +] diff --git a/Cargo.toml b/Cargo.toml index 8e8bea930..fd5964474 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,9 @@ [workspace] members = ["packages/*", "contracts/*"] +resolver = "2" [workspace.package] -version = "0.19.0" +version = "2.0.0" edition = "2021" license = "Apache-2.0" repository = "https://github.com/CosmWasm/cw-nfts" @@ -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.0" +cosmwasm-std = "^2.0" +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-017 = { git = "https://github.com/CosmWasm/cw-nfts", tag = "v0.17.0", package = "cw721" } # needed for testing legacy migration @@ -23,10 +24,11 @@ cw721-base = { version = "*", path = "./contracts/cw721-base" } cw721-base-016 = { git = "https://github.com/CosmWasm/cw-nfts", tag = "v0.16.0", package = "cw721-base" } # 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 = "^0.20" -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-storage-plus = "^1.1" -cw-utils = "^1.0" + +cw-multi-test = "^2.0" +cw-ownable = { git = "https://github.com/larry0x/cw-plus-plus.git", rev = "718351d4e9d66edbf3b6dbea2d13b56ef732f51c"} # TODO: switch to official https://github.com/larry0x/cw-plus-plus once merged +cw-storage-plus = "^2.0" +cw-utils = "^2.0" schemars = "^0.8" serde = { version = "1.0.152", default-features = false, features = ["derive"] } thiserror = "^1.0" @@ -35,10 +37,6 @@ thiserror = "^1.0" codegen-units = 1 incremental = false -[profile.release.package.cw721-metadata-onchain] -codegen-units = 1 -incremental = false - [profile.release.package.cw721-fixed-price] codegen-units = 1 incremental = false @@ -47,10 +45,11 @@ incremental = false codegen-units = 1 incremental = false -[profile.release.package.cw721-receiver] +[profile.release.package.cw721-receiver-tester] codegen-units = 1 incremental = false + [profile.release] rpath = false lto = true diff --git a/contracts/cw2981-royalties/Cargo.toml b/contracts/cw2981-royalties/Cargo.toml index e66cb6284..471daef90 100644 --- a/contracts/cw2981-royalties/Cargo.toml +++ b/contracts/cw2981-royalties/Cargo.toml @@ -13,8 +13,6 @@ documentation = { 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 = [] diff --git a/contracts/cw2981-royalties/src/lib.rs b/contracts/cw2981-royalties/src/lib.rs index 3a138f7e4..ad644fa8f 100644 --- a/contracts/cw2981-royalties/src/lib.rs +++ b/contracts/cw2981-royalties/src/lib.rs @@ -134,8 +134,9 @@ mod tests { fn use_metadata_extension() { let mut deps = mock_dependencies(); let contract = Cw2981Contract::default(); + let creator = deps.api.addr_make(CREATOR); - let info = mock_info(CREATOR, &[]); + let info = mock_info(creator.as_ref(), &[]); let init_msg = InstantiateMsg { name: "SpaceShips".to_string(), symbol: "SPACE".to_string(), @@ -153,7 +154,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(), }; @@ -171,8 +172,9 @@ mod tests { fn validate_royalty_information() { let mut deps = mock_dependencies(); let _contract = Cw2981Contract::default(); + let creator = deps.api.addr_make(CREATOR); - let info = mock_info(CREATOR, &[]); + let info = mock_info(creator.as_ref(), &[]); let init_msg = InstantiateMsg { name: "SpaceShips".to_string(), symbol: "SPACE".to_string(), @@ -184,7 +186,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(Metadata { description: Some("Spaceship with Warp Drive".into()), @@ -203,7 +205,9 @@ mod tests { let mut deps = mock_dependencies(); let _contract = Cw2981Contract::default(); - let info = mock_info(CREATOR, &[]); + let creator = deps.api.addr_make(CREATOR); + + let info = mock_info(creator.as_ref(), &[]); let init_msg = InstantiateMsg { name: "SpaceShips".to_string(), symbol: "SPACE".to_string(), @@ -215,7 +219,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(Metadata { description: Some("Spaceship with Warp Drive".into()), @@ -241,8 +245,9 @@ mod tests { #[test] fn check_token_royalties() { let mut deps = mock_dependencies(); + let creator = deps.api.addr_make(CREATOR); - let info = mock_info(CREATOR, &[]); + let info = mock_info(creator.as_ref(), &[]); let init_msg = InstantiateMsg { name: "SpaceShips".to_string(), symbol: "SPACE".to_string(), @@ -253,15 +258,15 @@ 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(Metadata { 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(deps.api.addr_make("jeanluc").to_string()), royalty_percentage: Some(10), ..Metadata::default() }), @@ -269,7 +274,7 @@ mod tests { 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 = query_royalties_info( @@ -293,15 +298,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(Metadata { 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(deps.api.addr_make("janeway").to_string()), royalty_percentage: Some(4), ..Metadata::default() }), @@ -311,7 +316,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), }; diff --git a/contracts/cw2981-royalties/src/query.rs b/contracts/cw2981-royalties/src/query.rs index 373048c89..67309bcb0 100644 --- a/contracts/cw2981-royalties/src/query.rs +++ b/contracts/cw2981-royalties/src/query.rs @@ -21,7 +21,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) => match ext.royalty_payment_address { diff --git a/contracts/cw721-base/Cargo.toml b/contracts/cw721-base/Cargo.toml index 8b0427498..f49921071 100644 --- a/contracts/cw721-base/Cargo.toml +++ b/contracts/cw721-base/Cargo.toml @@ -18,8 +18,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 = [] @@ -27,10 +25,14 @@ library = [] cosmwasm-schema = { workspace = true } cosmwasm-std = { workspace = true } cw-ownable = { workspace = true } +cw-storage-plus = { workspace = true } +cw-utils = { workspace = true } cw2 = { workspace = true } cw721 = { workspace = true } serde = { workspace = true } + [dev-dependencies] +cw-multi-test = { workspace = true } cw721-017 = { workspace = true } -cw721-018 = { workspace = true } +cw721-018 = { workspace = true } \ No newline at end of file diff --git a/contracts/cw721-base/src/lib.rs b/contracts/cw721-base/src/lib.rs index 80c1d23fb..f3b6a305d 100644 --- a/contracts/cw721-base/src/lib.rs +++ b/contracts/cw721-base/src/lib.rs @@ -69,10 +69,9 @@ pub mod entry { } #[cfg_attr(not(feature = "library"), entry_point)] - pub fn migrate( - deps: DepsMut, - env: Env, - msg: Cw721MigrateMsg, + pub fn migrate(deps: DepsMut, + env: Env, + msg: Cw721MigrateMsg ) -> Result { let contract = Cw721Contract::::default(); contract.migrate(deps, env, msg, CONTRACT_NAME, CONTRACT_VERSION) diff --git a/contracts/cw721-base/src/state.rs b/contracts/cw721-base/src/state.rs index 688a50684..91688ba90 100644 --- a/contracts/cw721-base/src/state.rs +++ b/contracts/cw721-base/src/state.rs @@ -24,12 +24,22 @@ pub struct Cw721Contract< impl Default for Cw721Contract<'static, TMetadataExtension, TCustomResponseMessage, TMetadataExtensionMsg> where - TMetadataExtension: Serialize + DeserializeOwned + Clone, - TMetadataExtensionMsg: CustomMsg, + T: Serialize + DeserializeOwned + Clone, + C: CustomMsg, + E: CustomMsg, + Q: CustomMsg, +{ +} + +impl Default for Cw721Contract<'static, T, C, E, Q> +where + T: Serialize + DeserializeOwned + Clone, + E: CustomMsg, + Q: CustomMsg, { fn default() -> Self { Self { config: Cw721Config::default(), } } -} +} \ No newline at end of file diff --git a/contracts/cw721-expiration/Cargo.toml b/contracts/cw721-expiration/Cargo.toml index 4854b31b6..1461552f0 100644 --- a/contracts/cw721-expiration/Cargo.toml +++ b/contracts/cw721-expiration/Cargo.toml @@ -13,8 +13,6 @@ documentation = { 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 = [] diff --git a/contracts/cw721-expiration/src/contract_tests.rs b/contracts/cw721-expiration/src/contract_tests.rs index f6a7bf834..4a0b85baa 100644 --- a/contracts/cw721-expiration/src/contract_tests.rs +++ b/contracts/cw721-expiration/src/contract_tests.rs @@ -29,17 +29,18 @@ const SYMBOL: &str = "MGK"; fn setup_contract( deps: DepsMut<'_>, expiration_days: u16, + creator: Addr, + minter: Addr, ) -> Cw721ExpirationContract<'static, DefaultOptionMetadataExtension, Empty, Empty> { - let contract = - Cw721ExpirationContract::::default(); + let contract = Cw721ExpirationContract::::default(); let msg = InstantiateMsg { expiration_days, name: CONTRACT_NAME.to_string(), symbol: SYMBOL.to_string(), - minter: Some(String::from(MINTER_ADDR)), + minter: Some(minter.to_string()), withdraw_address: None, }; - let info = mock_info("creator", &[]); + let info = mock_info(creator.as_ref(), &[]); let res = contract.instantiate(deps, mock_env(), info, msg).unwrap(); assert_eq!(0, res.messages.len()); contract @@ -50,13 +51,14 @@ fn proper_instantiation() { let mut deps = mock_dependencies(); let contract = Cw721ExpirationContract::::default(); - + let minter = deps.api.addr_make(MINTER); + let creator = deps.api.addr_make(CREATOR); let msg = InstantiateMsg { expiration_days: 1, name: CONTRACT_NAME.to_string(), symbol: SYMBOL.to_string(), - minter: Some(String::from(MINTER_ADDR)), - withdraw_address: Some(String::from(CREATOR_ADDR)), + minter: Some(minter.to_string()), + withdraw_address: Some(creator.to_string()), }; let info = mock_info("creator", &[]); let env = mock_env(); @@ -68,8 +70,8 @@ fn proper_instantiation() { assert_eq!(0, res.messages.len()); // it worked, let's query the state - let minter_ownership = MINTER.get_ownership(deps.as_ref().storage).unwrap(); - assert_eq!(Some(Addr::unchecked(MINTER_ADDR)), minter_ownership.owner); + let minter_ownership = minter.get_ownership(deps.as_ref().storage).unwrap(); + assert_eq!(Some(minter), minter_ownership.owner); let collection_info = contract .base_contract .query_collection_info(deps.as_ref(), env.clone()) @@ -82,59 +84,12 @@ fn proper_instantiation() { } ); - let withdraw_address = contract - .base_contract - .config - .withdraw_address - .may_load(deps.as_ref().storage) - .unwrap(); - assert_eq!(Some(CREATOR_ADDR.to_string()), withdraw_address); - - let count = contract - .base_contract - .query_num_tokens(deps.as_ref(), env) - .unwrap(); - assert_eq!(0, count.count); - - // list the token_ids - let tokens = contract - .query_all_tokens_include_expired_nft(deps.as_ref(), mock_env(), None, None, false) - .unwrap(); - assert_eq!(0, tokens.tokens.len()); -} - -#[test] -fn proper_instantiation_with_collection_info() { - let mut deps = mock_dependencies(); - let contract = - Cw721ExpirationContract::::default(); - - let msg = InstantiateMsg { - expiration_days: 1, - name: CONTRACT_NAME.to_string(), - symbol: SYMBOL.to_string(), - minter: Some(String::from(MINTER_ADDR)), - withdraw_address: Some(String::from(CREATOR_ADDR)), - }; - let info = mock_info("creator", &[]); - let env = mock_env(); - - // we can just call .unwrap() to assert this was a success - let res = contract - .instantiate(deps.as_mut(), env.clone(), info, msg) - .unwrap(); - assert_eq!(0, res.messages.len()); - - // it worked, let's query the state - let minter_ownership = MINTER.get_ownership(deps.as_ref().storage).unwrap(); - assert_eq!(Some(Addr::unchecked(MINTER_ADDR)), minter_ownership.owner); - let collection_info = contract - .base_contract - .query_collection_info(deps.as_ref(), env.clone()) - .unwrap(); + let res = contract.minter(deps.as_ref()).unwrap(); + assert_eq!(Some(minter.to_string()), res.minter); + let info = contract.contract_info(deps.as_ref()).unwrap(); assert_eq!( - collection_info, - CollectionInfo { + info, + ContractInfoResponse { name: CONTRACT_NAME.to_string(), symbol: SYMBOL.to_string(), } @@ -146,7 +101,7 @@ fn proper_instantiation_with_collection_info() { .withdraw_address .may_load(deps.as_ref().storage) .unwrap(); - assert_eq!(Some(CREATOR_ADDR.to_string()), withdraw_address); + assert_eq!(Some(creator.to_string()), withdraw_address); let count = contract .base_contract @@ -164,14 +119,16 @@ fn proper_instantiation_with_collection_info() { #[test] fn test_mint() { let mut deps = mock_dependencies(); - let contract = setup_contract(deps.as_mut(), 1); + let creator = deps.api.addr_make("creator"); + let minter = deps.api.addr_make("minter"); + let contract = setup_contract(deps.as_mut(), 1, creator, minter.clone()); let token_id = "atomize".to_string(); let token_uri = "https://www.merriam-webster.com/dictionary/atomize".to_string(); let mint_msg = Cw721ExecuteMsg::Mint { token_id: token_id.clone(), - owner: String::from("medusa"), + owner: deps.api.addr_make("medusa").into_string(), token_uri: Some(token_uri.clone()), extension: None, }; @@ -188,7 +145,7 @@ fn test_mint() { ); // minter can mint - let allowed = mock_info(MINTER_ADDR, &[]); + let allowed = mock_info(minter.as_ref(), &[]); let _ = contract .execute(deps.as_mut(), mock_env(), allowed, mint_msg) .unwrap(); @@ -230,7 +187,7 @@ fn test_mint() { assert_eq!( owner, OwnerOfResponse { - owner: String::from("medusa"), + owner: deps.api.addr_make("medusa").to_string(), approvals: vec![], } ); @@ -245,12 +202,12 @@ fn test_mint() { // Cannot mint same token_id again let mint_msg2 = Cw721ExecuteMsg::Mint { token_id: token_id.clone(), - owner: String::from("hercules"), + owner: deps.api.addr_make("hercules").to_string(), token_uri: None, extension: None, }; - let allowed = mock_info(MINTER_ADDR, &[]); + let allowed = mock_info(minter.as_ref(), &[]); let err = contract .execute(deps.as_mut(), mock_env(), allowed, mint_msg2) .unwrap_err(); @@ -267,33 +224,36 @@ fn test_mint() { #[test] fn test_update_minter() { let mut deps = mock_dependencies(); - let contract = setup_contract(deps.as_mut(), 1); + let creator = deps.api.addr_make("creator"); + let minter = deps.api.addr_make(MINTER); + let contract = setup_contract(deps.as_mut(), 1, creator, minter.clone()); let token_id = "petrify".to_string(); let token_uri = "https://www.merriam-webster.com/dictionary/petrify".to_string(); let mint_msg = Cw721ExecuteMsg::Mint { token_id, - owner: String::from("medusa"), + owner: deps.api.addr_make("medusa").into_string(), token_uri: Some(token_uri.clone()), extension: None, }; // Minter can mint - let minter_info = mock_info(MINTER_ADDR, &[]); + let minter_info = mock_info(minter.as_ref(), &[]); let _ = contract .execute(deps.as_mut(), mock_env(), minter_info.clone(), mint_msg) .unwrap(); // Update the owner to "random". The new owner should be able to // mint new tokens, the old one should not. + let random = deps.api.addr_make("random"); contract .execute( deps.as_mut(), mock_env(), minter_info.clone(), Cw721ExecuteMsg::UpdateOwnership(Action::TransferOwnership { - new_owner: "random".to_string(), + new_owner: random.to_string(), expiry: None, }), ) @@ -310,15 +270,15 @@ fn test_update_minter() { assert_eq!( ownership, - Ownership:: { - owner: Some(Addr::unchecked(MINTER_ADDR)), - pending_owner: Some(Addr::unchecked("random")), + cw_ownable::Ownership:: { + owner: Some(minter), + pending_owner: Some(random.clone()), pending_expiry: None, } ); // Accept the ownership transfer. - let random_info = mock_info("random", &[]); + let random_info = mock_info(random.as_ref(), &[]); contract .execute( deps.as_mut(), @@ -335,11 +295,11 @@ fn test_update_minter() { .unwrap(), ) .unwrap(); - assert_eq!(minter_ownership.owner, Some(random_info.sender.clone())); + assert_eq!(minter.minter, Some(deps.api.addr_make("random").to_string())); let mint_msg = Cw721ExecuteMsg::Mint { token_id: "randoms_token".to_string(), - owner: String::from("medusa"), + owner: deps.api.addr_make("medusa").to_string(), token_uri: Some(token_uri), extension: None, }; @@ -362,14 +322,16 @@ fn test_update_minter() { #[test] fn test_burn() { let mut deps = mock_dependencies(); - let contract = setup_contract(deps.as_mut(), 1); + let creator = deps.api.addr_make("creator"); + let minter = deps.api.addr_make(MINTER); + let contract = setup_contract(deps.as_mut(), 1, creator, minter.clone()); let token_id = "petrify".to_string(); let token_uri = "https://www.merriam-webster.com/dictionary/petrify".to_string(); let mint_msg = Cw721ExecuteMsg::Mint { token_id: token_id.clone(), - owner: MINTER_ADDR.to_string(), + owner: minter.to_string(), token_uri: Some(token_uri), extension: None, }; @@ -380,13 +342,13 @@ fn test_burn() { // mint some NFT let mut env = mock_env(); - let minter = mock_info(MINTER_ADDR, &[]); + let minter = mock_info(minter.as_ref(), &[]); let _ = contract .execute(deps.as_mut(), env.clone(), minter.clone(), mint_msg.clone()) .unwrap(); // random not allowed to burn - let random = mock_info("random", &[]); + let random = mock_info(deps.api.addr_make("random").as_ref(), &[]); let err = contract .execute(deps.as_mut(), env.clone(), random, burn_msg.clone()) .unwrap_err(); @@ -448,13 +410,15 @@ fn test_burn() { #[test] fn test_transfer_nft() { let mut deps = mock_dependencies(); - let contract = setup_contract(deps.as_mut(), 1); + let creator = deps.api.addr_make("creator"); + let minter = deps.api.addr_make(MINTER); + let contract = setup_contract(deps.as_mut(), 1, creator, minter.clone()); // Mint a token let token_id = "melt".to_string(); let token_uri = "https://www.merriam-webster.com/dictionary/melt".to_string(); - let owner = "owner"; + let owner = deps.api.addr_make("owner"); let mint_msg = Cw721ExecuteMsg::Mint { token_id: token_id.clone(), owner: String::from(owner), @@ -463,15 +427,15 @@ fn test_transfer_nft() { }; let mut env = mock_env(); - let minter = mock_info(MINTER_ADDR, &[]); + let minter = mock_info(minter.as_ref(), &[]); contract .execute(deps.as_mut(), env.clone(), minter, mint_msg) .unwrap(); // random cannot transfer - let random = mock_info("random", &[]); + let random = mock_info(deps.api.addr_make("random").as_ref(), &[]); let transfer_msg = Cw721ExecuteMsg::TransferNft { - recipient: String::from("random"), + recipient: deps.api.addr_make("random").to_string(), token_id: token_id.clone(), }; @@ -484,8 +448,9 @@ fn test_transfer_nft() { ); // owner can - let owner_info = mock_info(owner, &[]); - let new_owner = "random"; + let owner_info = mock_info(owner.as_ref(), &[]); + let binding = deps.api.addr_make("random"); + let new_owner = binding.as_ref(); let transfer_msg = Cw721ExecuteMsg::TransferNft { recipient: String::from(new_owner), token_id: token_id.clone(), @@ -529,7 +494,9 @@ fn test_transfer_nft() { #[test] fn test_send_nft() { let mut deps = mock_dependencies(); - let contract = setup_contract(deps.as_mut(), 1); + let creator = deps.api.addr_make("creator"); + let minter = deps.api.addr_make(MINTER); + let contract = setup_contract(deps.as_mut(), 1, creator, minter.clone()); // Mint a token let token_id = "melt".to_string(); @@ -537,26 +504,26 @@ fn test_send_nft() { let mint_msg = Cw721ExecuteMsg::Mint { token_id: token_id.clone(), - owner: String::from("venus"), + owner: deps.api.addr_make("venus").to_string(), token_uri: Some(token_uri), extension: None, }; let mut env = mock_env(); - let minter = mock_info(MINTER_ADDR, &[]); + let minter = mock_info(minter.as_ref(), &[]); contract .execute(deps.as_mut(), env.clone(), minter, mint_msg) .unwrap(); let msg = to_json_binary("You now have the melting power").unwrap(); - let target = String::from("another_contract"); + let target = deps.api.addr_make("another_contract"); let send_msg = Cw721ExecuteMsg::SendNft { - contract: target.clone(), + contract: target.to_string(), token_id: token_id.clone(), msg: msg.clone(), }; - let random = mock_info("random", &[]); + let random = mock_info(deps.api.addr_make("random").as_ref(), &[]); let err = contract .execute(deps.as_mut(), env.clone(), random, send_msg.clone()) .unwrap_err(); @@ -566,13 +533,13 @@ fn test_send_nft() { ); // but owner can - let random = mock_info("venus", &[]); + let random = mock_info(deps.api.addr_make("venus").as_ref(), &[]); let res = contract .execute(deps.as_mut(), env.clone(), random.clone(), send_msg.clone()) .unwrap(); let payload = Cw721ReceiveMsg { - sender: String::from("venus"), + sender: deps.api.addr_make("venus").to_string(), token_id: token_id.clone(), msg, }; @@ -580,9 +547,9 @@ fn test_send_nft() { // ensure expected serializes as we think it should match &expected { CosmosMsg::Wasm(WasmMsg::Execute { contract_addr, .. }) => { - assert_eq!(contract_addr, &target) + assert_eq!(contract_addr, target.as_ref()) } - m => panic!("Unexpected message type: {m:?}"), + _m => panic!("Unexpected message type: {_m:?}"), } // and make sure this is the request sent by the contract assert_eq!( @@ -590,8 +557,8 @@ fn test_send_nft() { Response::new() .add_message(expected) .add_attribute("action", "send_nft") - .add_attribute("sender", "venus") - .add_attribute("recipient", "another_contract") + .add_attribute("sender", deps.api.addr_make("venus").as_ref()) + .add_attribute("recipient", deps.api.addr_make("another_contract").as_ref()) .add_attribute("token_id", token_id.clone()) ); @@ -615,7 +582,9 @@ fn test_send_nft() { #[test] fn test_approve_revoke() { let mut deps = mock_dependencies(); - let contract = setup_contract(deps.as_mut(), 1); + let creator = deps.api.addr_make("creator"); + let minter = deps.api.addr_make(MINTER); + let contract = setup_contract(deps.as_mut(), 1, creator, minter.clone()); // Mint a token let token_id = "grow".to_string(); @@ -623,13 +592,13 @@ fn test_approve_revoke() { let mint_msg = Cw721ExecuteMsg::Mint { token_id: token_id.clone(), - owner: String::from("demeter"), + owner: deps.api.addr_make("demeter").to_string(), token_uri: Some(token_uri), extension: None, }; let mut env = mock_env(); - let minter = mock_info(MINTER_ADDR, &[]); + let minter = mock_info(minter.as_ref(), &[]); contract .execute(deps.as_mut(), env.clone(), minter, mint_msg) .unwrap(); @@ -640,7 +609,7 @@ fn test_approve_revoke() { deps.as_ref(), env.clone(), token_id.clone(), - String::from("demeter"), + deps.api.addr_make("demeter").to_string(), false, false, ) @@ -649,7 +618,7 @@ fn test_approve_revoke() { res, ApprovalResponse { approval: Approval { - spender: Addr::unchecked("demeter"), + spender: deps.api.addr_make("demeter").to_string(), expires: Expiration::Never {} } } @@ -657,11 +626,11 @@ fn test_approve_revoke() { // Give random transferring power let approve_msg = Cw721ExecuteMsg::Approve { - spender: String::from("random"), + spender: deps.api.addr_make("random").to_string(), token_id: token_id.clone(), expires: None, }; - let owner = mock_info("demeter", &[]); + let owner = mock_info(deps.api.addr_make("demeter").as_ref(), &[]); let res = contract .execute(deps.as_mut(), env.clone(), owner, approve_msg) .unwrap(); @@ -669,8 +638,8 @@ fn test_approve_revoke() { res, Response::new() .add_attribute("action", "approve") - .add_attribute("sender", "demeter") - .add_attribute("spender", "random") + .add_attribute("sender", deps.api.addr_make("demeter").as_ref()) + .add_attribute("spender", deps.api.addr_make("random").as_ref()) .add_attribute("token_id", token_id.clone()) ); @@ -680,7 +649,7 @@ fn test_approve_revoke() { deps.as_ref(), env.clone(), token_id.clone(), - String::from("random"), + deps.api.addr_make("random").to_string(), true, false, ) @@ -689,16 +658,16 @@ fn test_approve_revoke() { res, ApprovalResponse { approval: Approval { - spender: Addr::unchecked("random"), + spender: deps.api.addr_make("random").to_string(), expires: Expiration::Never {} } } ); // random can now transfer - let random = mock_info("random", &[]); - let transfer_msg = Cw721ExecuteMsg::TransferNft { - recipient: String::from("person"), + let random = mock_info(deps.api.addr_make("random").as_ref(), &[]); + let transfer_msg = ExecuteMsg::TransferNft { + recipient: deps.api.addr_make("person").to_string(), token_id: token_id.clone(), }; contract @@ -720,18 +689,18 @@ fn test_approve_revoke() { assert_eq!( res, OwnerOfResponse { - owner: String::from("person"), + owner: deps.api.addr_make("person").to_string(), approvals: vec![], } ); // Approve, revoke, and check for empty, to test revoke let approve_msg = Cw721ExecuteMsg::Approve { - spender: String::from("random"), + spender: deps.api.addr_make("random").to_string(), token_id: token_id.clone(), expires: None, }; - let owner = mock_info("person", &[]); + let owner = mock_info(deps.api.addr_make("person").as_ref(), &[]); contract .execute( deps.as_mut(), @@ -742,7 +711,7 @@ fn test_approve_revoke() { .unwrap(); let revoke_msg = Cw721ExecuteMsg::Revoke { - spender: String::from("random"), + spender: deps.api.addr_make("random").to_string(), token_id: token_id.clone(), }; contract @@ -764,7 +733,7 @@ fn test_approve_revoke() { assert_eq!( res, OwnerOfResponse { - owner: String::from("person"), + owner: deps.api.addr_make("person").to_string(), approvals: vec![], } ); @@ -802,7 +771,9 @@ fn test_approve_revoke() { #[test] fn test_approve_all_revoke_all() { let mut deps = mock_dependencies(); - let contract = setup_contract(deps.as_mut(), 1); + let creator = deps.api.addr_make("creator"); + let minter = deps.api.addr_make(MINTER); + let contract = setup_contract(deps.as_mut(), 1, creator, minter.clone()); // Mint a couple tokens (from the same owner) let token_id1 = "grow1".to_string(); @@ -813,19 +784,19 @@ fn test_approve_all_revoke_all() { let mint_msg1 = Cw721ExecuteMsg::Mint { token_id: token_id1.clone(), - owner: String::from("demeter"), + owner: deps.api.addr_make("demeter").to_string(), token_uri: Some(token_uri1), extension: None, }; - let minter = mock_info(MINTER_ADDR, &[]); + let minter = mock_info(minter.as_ref(), &[]); contract .execute(deps.as_mut(), mock_env(), minter.clone(), mint_msg1) .unwrap(); let mint_msg2 = Cw721ExecuteMsg::Mint { token_id: token_id2.clone(), - owner: String::from("demeter"), + owner: deps.api.addr_make("demeter").to_string(), token_uri: Some(token_uri2), extension: None, }; @@ -854,10 +825,10 @@ fn test_approve_all_revoke_all() { // demeter gives random full (operator) power over her tokens let approve_all_msg = Cw721ExecuteMsg::ApproveAll { - operator: String::from("random"), + operator: deps.api.addr_make("random").to_string(), expires: None, }; - let owner = mock_info("demeter", &[]); + let owner = mock_info(deps.api.addr_make("demeter").as_ref(), &[]); let res = contract .execute(deps.as_mut(), mock_env(), owner, approve_all_msg) .unwrap(); @@ -865,14 +836,14 @@ fn test_approve_all_revoke_all() { res, Response::new() .add_attribute("action", "approve_all") - .add_attribute("sender", "demeter") - .add_attribute("operator", "random") + .add_attribute("sender", deps.api.addr_make("demeter").as_ref()) + .add_attribute("operator", deps.api.addr_make("random").as_ref()) ); // random can now transfer - let random = mock_info("random", &[]); + let random = mock_info(deps.api.addr_make("random").as_ref(), &[]); let transfer_msg = Cw721ExecuteMsg::TransferNft { - recipient: String::from("person"), + recipient: deps.api.addr_make("person").to_string(), token_id: token_id1, }; contract @@ -881,14 +852,14 @@ fn test_approve_all_revoke_all() { // random can now send let inner_msg = WasmMsg::Execute { - contract_addr: "another_contract".into(), + contract_addr: deps.api.addr_make("another_contract").into(), msg: to_json_binary("You now also have the growing power").unwrap(), funds: vec![], }; let msg: CosmosMsg = CosmosMsg::Wasm(inner_msg); let send_msg = Cw721ExecuteMsg::SendNft { - contract: String::from("another_contract"), + contract: deps.api.addr_make("another_contract").to_string(), token_id: token_id2, msg: to_json_binary(&msg).unwrap(), }; @@ -898,11 +869,11 @@ fn test_approve_all_revoke_all() { // Approve_all, revoke_all, and check for empty, to test revoke_all let approve_all_msg = Cw721ExecuteMsg::ApproveAll { - operator: String::from("operator"), + operator: deps.api.addr_make("operator").to_string(), expires: None, }; // person is now the owner of the tokens - let owner = mock_info("person", &[]); + let owner = mock_info(deps.api.addr_make("person").as_ref(), &[]); contract .execute(deps.as_mut(), mock_env(), owner, approve_all_msg) .unwrap(); @@ -913,8 +884,8 @@ fn test_approve_all_revoke_all() { .query_operator( deps.as_ref(), mock_env(), - String::from("person"), - String::from("operator"), + deps.api.addr_make("person").to_string(), + deps.api.addr_make("operator").to_string(), true, ) .unwrap(); @@ -922,7 +893,7 @@ fn test_approve_all_revoke_all() { res, OperatorResponse { approval: Approval { - spender: Addr::unchecked("operator"), + spender: deps.api.addr_make("operator").to_string(), expires: Expiration::Never {} } } @@ -932,12 +903,12 @@ fn test_approve_all_revoke_all() { let res = contract.base_contract.query_operator( deps.as_ref(), mock_env(), - String::from("person"), - String::from("other"), + deps.api.addr_make("person").to_string(), + deps.api.addr_make("other").to_string(), true, ); match res { - Err(StdError::NotFound { kind }) => assert_eq!(kind, "Approval not found"), + Err(StdError::NotFound { kind, .. }) => assert_eq!(kind, "Approval not found"), _ => panic!("Unexpected error"), } @@ -946,7 +917,7 @@ fn test_approve_all_revoke_all() { .query_operators( deps.as_ref(), mock_env(), - String::from("person"), + deps.api.addr_make("person").to_string(), true, None, None, @@ -956,7 +927,7 @@ fn test_approve_all_revoke_all() { res, OperatorsResponse { operators: vec![cw721::Approval { - spender: Addr::unchecked("operator"), + spender: deps.api.addr_make("operator").to_string(), expires: Expiration::Never {} }] } @@ -965,10 +936,10 @@ fn test_approve_all_revoke_all() { // second approval let buddy_expires = Expiration::AtHeight(1234567); let approve_all_msg = Cw721ExecuteMsg::ApproveAll { - operator: String::from("buddy"), + operator: deps.api.addr_make("buddy").to_string(), expires: Some(buddy_expires), }; - let owner = mock_info("person", &[]); + let owner = mock_info(deps.api.addr_make("person").as_ref(), &[]); contract .execute(deps.as_mut(), mock_env(), owner.clone(), approve_all_msg) .unwrap(); @@ -979,17 +950,18 @@ fn test_approve_all_revoke_all() { .query_operators( deps.as_ref(), mock_env(), - String::from("person"), + deps.api.addr_make("person").to_string(), true, None, Some(1), ) .unwrap(); + assert_eq!( res, OperatorsResponse { operators: vec![cw721::Approval { - spender: Addr::unchecked("buddy"), + spender: deps.api.addr_make("operator").to_string(), expires: buddy_expires, }] } @@ -999,9 +971,9 @@ fn test_approve_all_revoke_all() { .query_operators( deps.as_ref(), mock_env(), - String::from("person"), + deps.api.addr_make("person").to_string(), true, - Some(String::from("buddy")), + Some(deps.api.addr_make("operator").to_string()), Some(2), ) .unwrap(); @@ -1009,14 +981,14 @@ fn test_approve_all_revoke_all() { res, OperatorsResponse { operators: vec![cw721::Approval { - spender: Addr::unchecked("operator"), + spender: deps.api.addr_make("buddy").to_string(), expires: Expiration::Never {} }] } ); let revoke_all_msg = Cw721ExecuteMsg::RevokeAll { - operator: String::from("operator"), + operator: deps.api.addr_make("operator").to_string(), }; contract .execute(deps.as_mut(), mock_env(), owner, revoke_all_msg) @@ -1026,13 +998,13 @@ fn test_approve_all_revoke_all() { let res = contract.base_contract.query_operator( deps.as_ref(), mock_env(), - String::from("person"), - String::from("operator"), + deps.api.addr_make("person").to_string(), + deps.api.addr_make("operator").to_string(), true, ); match res { - Err(StdError::NotFound { kind }) => assert_eq!(kind, "Approval not found"), - _ => panic!("Unexpected error"), + Err(StdError::NotFound { kind, .. }) => assert_eq!(kind, "Approval not found"), + _ => panic!("Unexpected error {:?}", res), } // Approvals are removed / cleared without affecting others @@ -1041,7 +1013,7 @@ fn test_approve_all_revoke_all() { .query_operators( deps.as_ref(), mock_env(), - String::from("person"), + deps.api.addr_make("person").to_string(), false, None, None, @@ -1051,7 +1023,7 @@ fn test_approve_all_revoke_all() { res, OperatorsResponse { operators: vec![cw721::Approval { - spender: Addr::unchecked("buddy"), + spender: deps.api.addr_make("buddy").to_string(), expires: buddy_expires, }] } @@ -1065,7 +1037,7 @@ fn test_approve_all_revoke_all() { .query_operators( deps.as_ref(), late_env.clone(), - String::from("person"), + deps.api.addr_make("person").to_string(), false, None, None, @@ -1077,13 +1049,13 @@ fn test_approve_all_revoke_all() { let res = contract.base_contract.query_operator( deps.as_ref(), late_env, - String::from("person"), - String::from("buddy"), + deps.api.addr_make("person").to_string(), + deps.api.addr_make("buddy").to_string(), false, ); match res { - Err(StdError::NotFound { kind }) => assert_eq!(kind, "Approval not found"), + Err(StdError::NotFound { kind, .. }) => assert_eq!(kind, "Approval not found"), _ => panic!("Unexpected error"), } } @@ -1091,19 +1063,22 @@ fn test_approve_all_revoke_all() { #[test] fn test_tokens_by_owner() { let mut deps = mock_dependencies(); - let contract = setup_contract(deps.as_mut(), 1); - let minter = mock_info(MINTER_ADDR, &[]); + let creator = deps.api.addr_make("creator"); + let minter = deps.api.addr_make(MINTER); + let contract = setup_contract(deps.as_mut(), 1, creator, minter.clone()); + + let minter = mock_info(minter.as_ref(), &[]); // Mint a couple tokens (from the same owner) let token_id1 = "grow1".to_string(); - let demeter = String::from("demeter"); + let demeter = deps.api.addr_make("demeter"); let token_id2 = "grow2".to_string(); - let ceres = String::from("ceres"); + let ceres = deps.api.addr_make("ceres"); let token_id3 = "sing".to_string(); let mint_msg = Cw721ExecuteMsg::Mint { token_id: token_id1.clone(), - owner: demeter.clone(), + owner: demeter.to_string(), token_uri: None, extension: None, }; @@ -1113,7 +1088,7 @@ fn test_tokens_by_owner() { let mint_msg = Cw721ExecuteMsg::Mint { token_id: token_id2.clone(), - owner: ceres.clone(), + owner: ceres.to_string(), token_uri: None, extension: None, }; @@ -1123,7 +1098,7 @@ fn test_tokens_by_owner() { let mint_msg = Cw721ExecuteMsg::Mint { token_id: token_id3.clone(), - owner: demeter.clone(), + owner: demeter.to_string(), token_uri: None, extension: None, }; @@ -1161,7 +1136,7 @@ fn test_tokens_by_owner() { .query_tokens_include_expired_nft( deps.as_ref(), mock_env(), - demeter.clone(), + demeter.to_string(), None, None, false, @@ -1169,7 +1144,7 @@ fn test_tokens_by_owner() { .unwrap(); assert_eq!(&by_demeter, &tokens.tokens); let tokens = contract - .query_tokens_include_expired_nft(deps.as_ref(), mock_env(), ceres, None, None, false) + .query_tokens_include_expired_nft(deps.as_ref(), mock_env(), ceres.to_string(), None, None, false) .unwrap(); assert_eq!(&by_ceres, &tokens.tokens); @@ -1178,7 +1153,7 @@ fn test_tokens_by_owner() { .query_tokens_include_expired_nft( deps.as_ref(), mock_env(), - demeter.clone(), + demeter.to_string(), None, Some(1), false, @@ -1189,7 +1164,7 @@ fn test_tokens_by_owner() { .query_tokens_include_expired_nft( deps.as_ref(), mock_env(), - demeter, + demeter.to_string(), Some(by_demeter[0].clone()), Some(3), false, @@ -1201,11 +1176,13 @@ fn test_tokens_by_owner() { #[test] fn test_nft_info() { let mut deps = mock_dependencies(); - let contract = setup_contract(deps.as_mut(), 1); - let minter = mock_info(MINTER_ADDR, &[]); + let creator = deps.api.addr_make("creator"); + let minter = deps.api.addr_make(MINTER); + let contract = setup_contract(deps.as_mut(), 1, creator, minter.clone()); + let minter = mock_info(minter.as_ref(), &[]); let token_id = "grow1".to_string(); - let owner = String::from("ark"); + let owner = deps.api.addr_make("ark").to_string(); let mut env = mock_env(); let mint_msg = Cw721ExecuteMsg::Mint { @@ -1243,11 +1220,13 @@ fn test_nft_info() { #[test] fn test_all_nft_info() { let mut deps = mock_dependencies(); - let contract = setup_contract(deps.as_mut(), 1); - let minter = mock_info(MINTER_ADDR, &[]); + let creator = deps.api.addr_make("creator"); + let minter = deps.api.addr_make(MINTER); + let contract = setup_contract(deps.as_mut(), 1, creator, minter.clone()); + let minter = mock_info(minter.as_ref(), &[]); let token_id = "grow1".to_string(); - let owner = String::from("ark"); + let owner = deps.api.addr_make("ark").to_string(); let mut env = mock_env(); let mint_msg = Cw721ExecuteMsg::Mint { @@ -1291,11 +1270,13 @@ fn test_all_nft_info() { #[test] fn test_owner_of() { let mut deps = mock_dependencies(); - let contract = setup_contract(deps.as_mut(), 1); - let minter = mock_info(MINTER_ADDR, &[]); + let creator = deps.api.addr_make("creator"); + let minter = deps.api.addr_make(MINTER); + let contract = setup_contract(deps.as_mut(), 1, creator, minter.clone()); + let minter = mock_info(minter.as_ref(), &[]); let token_id = "grow1".to_string(); - let owner = String::from("ark"); + let owner = deps.api.addr_make("ark").to_string(); let mut env = mock_env(); let mint_msg = Cw721ExecuteMsg::Mint { @@ -1339,16 +1320,18 @@ fn test_owner_of() { #[test] fn test_approval() { let mut deps = mock_dependencies(); - let contract = setup_contract(deps.as_mut(), 1); - let minter = mock_info(MINTER_ADDR, &[]); + let creator = deps.api.addr_make("creator"); + let minter = deps.api.addr_make(MINTER); + let contract = setup_contract(deps.as_mut(), 1, creator, minter.clone()); + let minter = mock_info(minter.as_ref(), &[]); let token_id = "grow1".to_string(); - let owner = String::from("ark"); + let owner = deps.api.addr_make("ark"); let mut env = mock_env(); let mint_msg = Cw721ExecuteMsg::Mint { token_id: token_id.clone(), - owner: owner.clone(), + owner: owner.to_string(), token_uri: None, extension: None, }; @@ -1362,7 +1345,7 @@ fn test_approval() { deps.as_ref(), env.clone(), token_id.clone(), - owner.clone(), + owner.to_string(), false, false, ) @@ -1377,7 +1360,7 @@ fn test_approval() { deps.as_ref(), env, token_id.clone(), - owner, + owner.to_string(), false, false, ) @@ -1395,16 +1378,18 @@ fn test_approval() { #[test] fn test_approvals() { let mut deps = mock_dependencies(); - let contract = setup_contract(deps.as_mut(), 1); - let minter = mock_info(MINTER_ADDR, &[]); + let creator = deps.api.addr_make("creator"); + let minter = deps.api.addr_make(MINTER); + let contract = setup_contract(deps.as_mut(), 1, creator, minter.clone()); + let minter = mock_info(minter.as_ref(), &[]); let token_id = "grow1".to_string(); - let owner = String::from("ark"); + let owner = deps.api.addr_make("ark"); let mut env = mock_env(); let mint_msg = Cw721ExecuteMsg::Mint { token_id: token_id.clone(), - owner, + owner: owner.to_string(), token_uri: None, extension: None, }; @@ -1443,16 +1428,18 @@ fn test_approvals() { #[test] fn test_tokens() { let mut deps = mock_dependencies(); - let contract = setup_contract(deps.as_mut(), 1); - let minter = mock_info(MINTER_ADDR, &[]); + let creator = deps.api.addr_make("creator"); + let minter = deps.api.addr_make(MINTER); + let contract = setup_contract(deps.as_mut(), 1, creator, minter.clone()); + let minter = mock_info(minter.as_ref(), &[]); let token_id = "grow1".to_string(); - let owner = String::from("ark"); + let owner = deps.api.addr_make("ark"); let mut env = mock_env(); let mint_msg = Cw721ExecuteMsg::Mint { token_id: token_id.clone(), - owner: owner.clone(), + owner: owner.to_string(), token_uri: None, extension: None, }; @@ -1465,7 +1452,7 @@ fn test_tokens() { .query_tokens_include_expired_nft( deps.as_ref(), env.clone(), - owner.clone(), + owner.to_string(), None, None, false, @@ -1479,7 +1466,7 @@ fn test_tokens() { .query_tokens_include_expired_nft( deps.as_ref(), env.clone(), - owner.clone(), + owner.to_string(), None, None, false, @@ -1489,7 +1476,7 @@ fn test_tokens() { // assert invalid nft is returned let tokens = contract - .query_tokens_include_expired_nft(deps.as_ref(), env, owner, None, None, true) + .query_tokens_include_expired_nft(deps.as_ref(), env, owner.to_string(), None, None, true) .unwrap(); assert_eq!( tokens, @@ -1502,16 +1489,19 @@ fn test_tokens() { #[test] fn test_all_tokens() { let mut deps = mock_dependencies(); - let contract = setup_contract(deps.as_mut(), 1); - let minter = mock_info(MINTER_ADDR, &[]); + let creator = deps.api.addr_make("creator"); + let minter = deps.api.addr_make(MINTER); + let contract = setup_contract(deps.as_mut(), 1, creator, minter.clone()); + + let minter = mock_info(minter.as_ref(), &[]); let token_id = "grow1".to_string(); - let owner = String::from("ark"); + let owner = deps.api.addr_make("ark"); let mut env = mock_env(); let mint_msg = Cw721ExecuteMsg::Mint { token_id: token_id.clone(), - owner: owner.clone(), + owner: owner.to_string(), token_uri: None, extension: None, }; @@ -1528,7 +1518,7 @@ fn test_all_tokens() { let expiration = env.block.time.plus_days(1); env.block.time = expiration; let tokens = contract - .query_tokens_include_expired_nft(deps.as_ref(), env.clone(), owner, None, None, false) + .query_tokens_include_expired_nft(deps.as_ref(), env.clone(), owner.to_string(), None, None, false) .unwrap(); assert_eq!(tokens, TokensResponse { tokens: vec![] }); diff --git a/contracts/cw721-expiration/src/lib.rs b/contracts/cw721-expiration/src/lib.rs index cb0b1256d..2d4e775ea 100644 --- a/contracts/cw721-expiration/src/lib.rs +++ b/contracts/cw721-expiration/src/lib.rs @@ -87,17 +87,18 @@ mod tests { #[test] fn proper_cw2_initialization() { let mut deps = mock_dependencies(); - + let mrt = deps.api.addr_make("mrt"); + let minter = deps.api.addr_make("minter"); // assert min expiration let error = entry::instantiate( deps.as_mut(), mock_env(), - mock_info("mrt", &[]), + mock_info(mrt.as_ref(), &[]), InstantiateMsg { expiration_days: 0, name: "collection_name".into(), symbol: "collection_symbol".into(), - minter: Some("minter".into()), + minter: Some(minter.to_string()), withdraw_address: None, }, ) @@ -108,12 +109,12 @@ mod tests { entry::instantiate( deps.as_mut(), mock_env(), - mock_info("mrt", &[]), + mock_info(mrt.as_ref(), &[]), InstantiateMsg { expiration_days: 1, name: "".into(), symbol: "".into(), - minter: Some("minter".into()), + minter: Some(minter.to_string()), withdraw_address: None, }, ) diff --git a/contracts/cw721-expiration/src/state.rs b/contracts/cw721-expiration/src/state.rs index 4a4be1311..7ba101316 100644 --- a/contracts/cw721-expiration/src/state.rs +++ b/contracts/cw721-expiration/src/state.rs @@ -17,13 +17,13 @@ pub struct Cw721ExpirationContract< // Message passed for updating metadata. TMetadataExtensionMsg, > where - TMetadataExtension: Serialize + DeserializeOwned + Clone, - TMetadataExtensionMsg: CustomMsg, +TMetadataExtension: Serialize + DeserializeOwned + Clone, +TMetadataExtensionMsg: CustomMsg, { pub expiration_days: Item<'a, u16>, // max 65535 days pub mint_timestamps: Map<'a, &'a str, Timestamp>, pub base_contract: - Cw721Contract<'a, TMetadataExtension, TCustomResponseMessage, TMetadataExtensionMsg>, + Cw721Contract<'a, TMetadataExtension,TCustomResponseMessage, TMetadataExtensionMsg>, } impl Default diff --git a/contracts/cw721-fixed-price/Cargo.toml b/contracts/cw721-fixed-price/Cargo.toml index 82f018e28..9ebc6f3e3 100644 --- a/contracts/cw721-fixed-price/Cargo.toml +++ b/contracts/cw721-fixed-price/Cargo.toml @@ -12,8 +12,6 @@ documentation = { 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 = [] diff --git a/contracts/cw721-fixed-price/schema/cw721-fixed-price.json b/contracts/cw721-fixed-price/schema/cw721-fixed-price.json index 296c736a8..73c82dd7a 100644 --- a/contracts/cw721-fixed-price/schema/cw721-fixed-price.json +++ b/contracts/cw721-fixed-price/schema/cw721-fixed-price.json @@ -1,6 +1,6 @@ { "contract_name": "cw721-fixed-price", - "contract_version": "0.19.0", + "contract_version": "2.0.0", "idl_version": "1.0.0", "instantiate": { "$schema": "http://json-schema.org/draft-07/schema#", diff --git a/contracts/cw721-fixed-price/src/contract.rs b/contracts/cw721-fixed-price/src/contract.rs index da17f9c61..976d2a7cf 100644 --- a/contracts/cw721-fixed-price/src/contract.rs +++ b/contracts/cw721-fixed-price/src/contract.rs @@ -6,15 +6,16 @@ use crate::state::{Config, CONFIG}; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - to_json_binary, Addr, Binary, Deps, DepsMut, Empty, Env, MessageInfo, Reply, ReplyOn, Response, + to_json_binary, Addr, Binary, Deps, DepsMut, Empty, Env, MessageInfo, Reply, Response, StdResult, SubMsg, Uint128, WasmMsg, }; use cw2::set_contract_version; use cw20::Cw20ReceiveMsg; -use cw721::helpers::Cw721Contract; -use cw721::msg::{Cw721ExecuteMsg, Cw721InstantiateMsg}; -use cw721::state::DefaultOptionMetadataExtension; -use cw_utils::parse_reply_instantiate_data; +use cw721_base::{ + helpers::Cw721Contract, msg::ExecuteMsg as Cw721ExecuteMsg, + msg::InstantiateMsg as Cw721InstantiateMsg, +}; +use cw_utils::{parse_instantiate_response_data, ParseReplyError}; // version info for migration info const CONTRACT_NAME: &str = "crates.io:cw721-fixed-price"; @@ -54,8 +55,8 @@ pub fn instantiate( CONFIG.save(deps.storage, &config)?; - let sub_msg: Vec = vec![SubMsg { - msg: WasmMsg::Instantiate { + let sub_msg: Vec = vec![SubMsg::reply_on_success( + WasmMsg::Instantiate { code_id: msg.token_code_id, msg: to_json_binary(&Cw721InstantiateMsg { name: msg.name.clone(), @@ -66,12 +67,9 @@ pub fn instantiate( funds: vec![], admin: None, label: String::from("Instantiate fixed price NFT contract"), - } - .into(), - id: INSTANTIATE_TOKEN_REPLY_ID, - gas_limit: None, - reply_on: ReplyOn::Success, - }]; + }, + INSTANTIATE_TOKEN_REPLY_ID, + )]; Ok(Response::new().add_submessages(sub_msg)) } @@ -89,7 +87,16 @@ pub fn reply(deps: DepsMut, _env: Env, msg: Reply) -> Result(or: Option<&T>) -> String { + or.map_or_else(|| "none".to_string(), |or| or.to_string()) +} /// Migrates only in case collection_info is not present pub fn migrate_legacy_collection_info( storage: &mut dyn Storage, diff --git a/packages/cw721/src/query.rs b/packages/cw721/src/query.rs index 5bdf2ed69..06222272a 100644 --- a/packages/cw721/src/query.rs +++ b/packages/cw721/src/query.rs @@ -253,7 +253,7 @@ pub trait Cw721Query< .load(deps.storage, &token_id)?; // token owner has absolute approval - if token.owner == spender { + if token.owner.to_string() == spender { let approval = Approval { spender: token.owner, expires: Expiration::Never {}, @@ -264,7 +264,7 @@ pub trait Cw721Query< let filtered: Vec<_> = token .approvals .into_iter() - .filter(|t| t.spender == spender) + .filter(|t| t.spender.to_string() == spender) .filter(|t| include_expired_approval || !t.is_expired(&env.block)) .map(|a| Approval { spender: a.spender, diff --git a/packages/cw721/src/state.rs b/packages/cw721/src/state.rs index 9dc4ac097..9a5e8c88f 100644 --- a/packages/cw721/src/state.rs +++ b/packages/cw721/src/state.rs @@ -27,14 +27,14 @@ pub struct Cw721Config< TMetadataExtensionMsg: CustomMsg, { /// Note: replaces deprecated/legacy key "nft_info"! - pub collection_info: Item<'a, CollectionInfo>, - pub token_count: Item<'a, u64>, + pub collection_info: Item, + pub token_count: Item, /// Stored as (granter, operator) giving operator full control over granter's account. /// NOTE: granter is the owner, so operator has only control for NFTs owned by granter! - pub operators: Map<'a, (&'a Addr, &'a Addr), Expiration>, + pub operators: Map<(&'a Addr, &'a Addr), Expiration>, pub nft_info: - IndexedMap<'a, &'a str, NftInfo, TokenIndexes<'a, TMetadataExtension>>, - pub withdraw_address: Item<'a, String>, + IndexedMap< &'a str, NftInfo, TokenIndexes<'a, TMetadataExtension>>, + pub withdraw_address: Item, pub(crate) _custom_response: PhantomData, pub(crate) _custom_execute: PhantomData, @@ -65,22 +65,22 @@ where TMetadataExtensionMsg: CustomMsg, { fn new( - collection_info_key: &'a str, - token_count_key: &'a str, - operator_key: &'a str, - nft_info_key: &'a str, - nft_info_owner_key: &'a str, - withdraw_address_key: &'a str, + collection_info_key: &'static str, + token_count_key: &'static str, + operator_key: &'static str, + nft_info_key: &'static str, + nft_info_owner_key: &'static str, + withdraw_address_key: &'static str, ) -> Self { let indexes = TokenIndexes { - owner: MultiIndex::new(token_owner_idx, nft_info_key, nft_info_owner_key), + owner: MultiIndex::new(token_owner_idx, nft_info_key.clone(), nft_info_owner_key.clone()), }; Self { - collection_info: Item::new(collection_info_key), - token_count: Item::new(token_count_key), - operators: Map::new(operator_key), - nft_info: IndexedMap::new(nft_info_key, indexes), - withdraw_address: Item::new(withdraw_address_key), + collection_info: Item::new(collection_info_key.clone()), + token_count: Item::new(token_count_key.clone()), + operators: Map::new(operator_key.clone()), + nft_info: IndexedMap::new(nft_info_key.clone(), indexes), + withdraw_address: Item::new(withdraw_address_key.clone()), _custom_response: PhantomData, _custom_execute: PhantomData, } diff --git a/packages/cw721/src/testing/contract_tests.rs b/packages/cw721/src/testing/contract_tests.rs index e7c81d461..a0db6d73d 100644 --- a/packages/cw721/src/testing/contract_tests.rs +++ b/packages/cw721/src/testing/contract_tests.rs @@ -1,15 +1,13 @@ #![cfg(test)] -use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info}; +use cosmwasm_std::testing::{message_info, mock_dependencies, mock_env}; use cosmwasm_std::{ from_json, to_json_binary, Addr, Coin, CosmosMsg, DepsMut, Empty, Response, StdError, WasmMsg, }; use crate::error::Cw721ContractError; -use crate::msg::{ - ApprovalResponse, NftInfoResponse, OperatorResponse, OperatorsResponse, OwnerOfResponse, -}; +use crate::msg::{ApprovalResponse, MinterResponse, NftInfoResponse, OperatorResponse, OperatorsResponse, OwnerOfResponse}; use crate::msg::{Cw721ExecuteMsg, Cw721InstantiateMsg, Cw721QueryMsg}; use crate::receiver::Cw721ReceiveMsg; use crate::state::{CollectionInfo, DefaultOptionMetadataExtension, MINTER}; @@ -19,21 +17,23 @@ use cw_ownable::{Action, Ownership, OwnershipError}; use super::contract::Cw721Contract; const MINTER_ADDR: &str = "minter"; -const CREATOR_ADDR: &str = "creator"; +const CREATOR: &str = "creator"; const CONTRACT_NAME: &str = "Magic Power"; const SYMBOL: &str = "MGK"; fn setup_contract( deps: DepsMut<'_>, + creator: Addr, + minter: Addr, ) -> Cw721Contract<'static, DefaultOptionMetadataExtension, Empty, Empty> { let contract = Cw721Contract::default(); let msg = Cw721InstantiateMsg { name: CONTRACT_NAME.to_string(), symbol: SYMBOL.to_string(), - minter: Some(String::from(MINTER_ADDR)), + minter: Some(minter.to_string()), withdraw_address: None, }; - let info = mock_info("creator", &[]); + let info = message_info(&creator, &[]); let res = contract .instantiate( deps, @@ -52,14 +52,15 @@ fn setup_contract( fn proper_instantiation() { let mut deps = mock_dependencies(); let contract = Cw721Contract::::default(); - + let minter = deps.api.addr_make(MINTER_ADDR); + let creator = deps.api.addr_make(CREATOR); let msg = Cw721InstantiateMsg { name: CONTRACT_NAME.to_string(), symbol: SYMBOL.to_string(), - minter: Some(String::from(MINTER_ADDR)), - withdraw_address: Some(String::from(CREATOR_ADDR)), + minter: Some(minter.to_string()), + withdraw_address: Some(creator.to_string()), }; - let info = mock_info("creator", &[]); + let info = message_info(&creator, &[]); let env = mock_env(); // we can just call .unwrap() to assert this was a success @@ -76,8 +77,8 @@ fn proper_instantiation() { assert_eq!(0, res.messages.len()); // it worked, let's query the state - let minter_ownership = MINTER.get_ownership(deps.as_ref().storage).unwrap(); - assert_eq!(Some(Addr::unchecked(MINTER_ADDR)), minter_ownership.owner); + let res = contract.minter(deps.as_ref()).unwrap(); + assert_eq!(Some(minter.to_string()), res.minter); let collection_info = contract .query_collection_info(deps.as_ref(), env.clone()) .unwrap(); @@ -94,7 +95,7 @@ fn proper_instantiation() { .withdraw_address .may_load(deps.as_ref().storage) .unwrap(); - assert_eq!(Some(CREATOR_ADDR.to_string()), withdraw_address); + assert_eq!(Some(creator.to_string()), withdraw_address); let count = contract .query_num_tokens(deps.as_ref(), env.clone()) @@ -112,14 +113,15 @@ fn proper_instantiation() { fn proper_instantiation_with_collection_info() { let mut deps = mock_dependencies(); let contract = Cw721Contract::::default(); - + let creator = deps.api.addr_make(CREATOR); + let minter = deps.api.addr_make(MINTER_ADDR); let msg = Cw721InstantiateMsg { name: CONTRACT_NAME.to_string(), symbol: SYMBOL.to_string(), - minter: Some(String::from(MINTER_ADDR)), - withdraw_address: Some(String::from(CREATOR_ADDR)), + minter: Some(minter.to_string()), + withdraw_address: Some(creator.to_string()), }; - let collection_info = mock_info("creator", &[]); + let collection_info = message_info(&creator, &[]); let env = mock_env(); // we can just call .unwrap() to assert this was a success @@ -137,7 +139,7 @@ fn proper_instantiation_with_collection_info() { // it worked, let's query the state let minter_ownership = MINTER.get_ownership(deps.as_ref().storage).unwrap(); - assert_eq!(Some(Addr::unchecked(MINTER_ADDR)), minter_ownership.owner); + assert_eq!(Some(minter), minter_ownership.owner); let info = contract .query_collection_info(deps.as_ref(), env.clone()) .unwrap(); @@ -154,7 +156,7 @@ fn proper_instantiation_with_collection_info() { .withdraw_address .may_load(deps.as_ref().storage) .unwrap(); - assert_eq!(Some(CREATOR_ADDR.to_string()), withdraw_address); + assert_eq!(Some(creator.to_string()), withdraw_address); let count = contract .query_num_tokens(deps.as_ref(), env.clone()) @@ -171,20 +173,22 @@ fn proper_instantiation_with_collection_info() { #[test] fn minting() { let mut deps = mock_dependencies(); - let contract = setup_contract(deps.as_mut()); + let creator = deps.api.addr_make(CREATOR); + let minter = deps.api.addr_make(MINTER_ADDR); + let contract = setup_contract(deps.as_mut(), creator, minter.clone()); let token_id = "petrify".to_string(); let token_uri = "https://www.merriam-webster.com/dictionary/petrify".to_string(); let mint_msg = Cw721ExecuteMsg::Mint { token_id: token_id.clone(), - owner: String::from("medusa"), + owner: deps.api.addr_make("medusa").to_string(), token_uri: Some(token_uri.clone()), extension: None, }; // random cannot mint - let random = mock_info("random", &[]); + let random = message_info(&deps.api.addr_make("random"), &[]); let env = mock_env(); let err = contract .execute(deps.as_mut(), env.clone(), random, mint_msg.clone()) @@ -192,7 +196,7 @@ fn minting() { assert_eq!(err, Cw721ContractError::Ownership(OwnershipError::NotOwner)); // minter can mint - let allowed = mock_info(MINTER_ADDR, &[]); + let allowed = message_info(&minter, &[]); let _ = contract .execute(deps.as_mut(), env.clone(), allowed, mint_msg) .unwrap(); @@ -227,7 +231,7 @@ fn minting() { assert_eq!( owner, OwnerOfResponse { - owner: String::from("medusa"), + owner: deps.api.addr_make("medusa").to_string(), approvals: vec![], } ); @@ -235,12 +239,12 @@ fn minting() { // Cannot mint same token_id again let mint_msg2 = Cw721ExecuteMsg::Mint { token_id: token_id.clone(), - owner: String::from("hercules"), + owner: deps.api.addr_make("hercules").to_string(), token_uri: None, extension: None, }; - let allowed = mock_info(MINTER_ADDR, &[]); + let allowed = message_info(&minter, &[]); let err = contract .execute(deps.as_mut(), mock_env(), allowed, mint_msg2) .unwrap_err(); @@ -257,20 +261,23 @@ fn minting() { #[test] fn test_update_minter() { let mut deps = mock_dependencies(); - let contract = setup_contract(deps.as_mut()); + let creator = deps.api.addr_make("creator"); + let minter = deps.api.addr_make(MINTER_ADDR); + let random = deps.api.addr_make("random"); + let contract = setup_contract(deps.as_mut(), creator, minter.clone()); let token_id = "petrify".to_string(); let token_uri = "https://www.merriam-webster.com/dictionary/petrify".to_string(); let mint_msg = Cw721ExecuteMsg::Mint { token_id, - owner: String::from("medusa"), + owner: deps.api.addr_make("medusa").to_string(), token_uri: Some(token_uri.clone()), extension: None, }; // Minter can mint - let minter_info = mock_info(MINTER_ADDR, &[]); + let minter_info = message_info(&minter, &[]); let _ = contract .execute(deps.as_mut(), mock_env(), minter_info.clone(), mint_msg) .unwrap(); @@ -283,13 +290,21 @@ fn test_update_minter() { mock_env(), minter_info.clone(), Cw721ExecuteMsg::UpdateOwnership(Action::TransferOwnership { - new_owner: "random".to_string(), + new_owner: random.to_string(), expiry: None, }), ) .unwrap(); // Minter does not change until ownership transfer completes. + let minter_response: MinterResponse = from_json( + contract + .query(deps.as_ref(), mock_env(), Cw721QueryMsg::Minter {}) + .unwrap(), + ) + .unwrap(); + assert_eq!(minter_response.minter, Some(minter.to_string())); + // Pending ownership transfer should be discoverable via query. let ownership: Ownership = from_json( contract @@ -301,14 +316,14 @@ fn test_update_minter() { assert_eq!( ownership, Ownership:: { - owner: Some(Addr::unchecked(MINTER_ADDR)), - pending_owner: Some(Addr::unchecked("random")), + owner: Some(minter), + pending_owner: Some(random.clone()), pending_expiry: None, } ); // Accept the ownership transfer. - let random_info = mock_info("random", &[]); + let random_info = message_info(&random, &[]); contract .execute( deps.as_mut(), @@ -325,11 +340,11 @@ fn test_update_minter() { .unwrap(), ) .unwrap(); - assert_eq!(minter_ownership.owner, Some(random_info.sender.clone())); + assert_eq!(MINTER.minter, Some(random.to_string())); let mint_msg = Cw721ExecuteMsg::Mint { token_id: "randoms_token".to_string(), - owner: String::from("medusa"), + owner: deps.api.addr_make("medusa").to_string(), token_uri: Some(token_uri), extension: None, }; @@ -349,14 +364,16 @@ fn test_update_minter() { #[test] fn burning() { let mut deps = mock_dependencies(); - let contract = setup_contract(deps.as_mut()); + let creator = deps.api.addr_make(CREATOR); + let minter = deps.api.addr_make(MINTER_ADDR); + let contract = setup_contract(deps.as_mut(), creator, minter.clone()); let token_id = "petrify".to_string(); let token_uri = "https://www.merriam-webster.com/dictionary/petrify".to_string(); let mint_msg = Cw721ExecuteMsg::Mint { token_id: token_id.clone(), - owner: MINTER_ADDR.to_string(), + owner: minter.to_string(), token_uri: Some(token_uri), extension: None, }; @@ -364,14 +381,15 @@ fn burning() { let burn_msg = Cw721ExecuteMsg::Burn { token_id }; // mint some NFT - let allowed = mock_info(MINTER_ADDR, &[]); + let allowed = message_info(&minter, &[]); let _ = contract .execute(deps.as_mut(), mock_env(), allowed.clone(), mint_msg) .unwrap(); // random not allowed to burn - let random = mock_info("random", &[]); + let random = message_info(&deps.api.addr_make("random"), &[]); let env = mock_env(); + let err = contract .execute(deps.as_mut(), env.clone(), random, burn_msg.clone()) .unwrap_err(); @@ -403,7 +421,9 @@ fn burning() { #[test] fn transferring_nft() { let mut deps = mock_dependencies(); - let contract = setup_contract(deps.as_mut()); + let creator = deps.api.addr_make(CREATOR); + let minter = deps.api.addr_make(MINTER_ADDR); + let contract = setup_contract(deps.as_mut(), creator, minter.clone()); // Mint a token let token_id = "melt".to_string(); @@ -411,20 +431,20 @@ fn transferring_nft() { let mint_msg = Cw721ExecuteMsg::Mint { token_id: token_id.clone(), - owner: String::from("venus"), + owner: deps.api.addr_make("venus").to_string(), token_uri: Some(token_uri), extension: None, }; - let minter = mock_info(MINTER_ADDR, &[]); + let minter = message_info(&minter, &[]); contract .execute(deps.as_mut(), mock_env(), minter, mint_msg) .unwrap(); // random cannot transfer - let random = mock_info("random", &[]); + let random = message_info(&deps.api.addr_make("random"), &[]); let transfer_msg = Cw721ExecuteMsg::TransferNft { - recipient: String::from("random"), + recipient: deps.api.addr_make("random").to_string(), token_id: token_id.clone(), }; @@ -434,9 +454,9 @@ fn transferring_nft() { assert_eq!(err, Cw721ContractError::Ownership(OwnershipError::NotOwner)); // owner can - let random = mock_info("venus", &[]); + let random = message_info(&deps.api.addr_make("venus"), &[]); let transfer_msg = Cw721ExecuteMsg::TransferNft { - recipient: String::from("random"), + recipient: deps.api.addr_make("random").to_string(), token_id: token_id.clone(), }; @@ -448,8 +468,8 @@ fn transferring_nft() { res, Response::new() .add_attribute("action", "transfer_nft") - .add_attribute("sender", "venus") - .add_attribute("recipient", "random") + .add_attribute("sender", deps.api.addr_make("venus").as_ref()) + .add_attribute("recipient", deps.api.addr_make("random").as_ref()) .add_attribute("token_id", token_id) ); } @@ -457,7 +477,9 @@ fn transferring_nft() { #[test] fn sending_nft() { let mut deps = mock_dependencies(); - let contract = setup_contract(deps.as_mut()); + let creator = deps.api.addr_make(CREATOR); + let minter = deps.api.addr_make(MINTER_ADDR); + let contract = setup_contract(deps.as_mut(), creator, minter.clone()); // Mint a token let token_id = "melt".to_string(); @@ -465,38 +487,38 @@ fn sending_nft() { let mint_msg = Cw721ExecuteMsg::Mint { token_id: token_id.clone(), - owner: String::from("venus"), + owner: deps.api.addr_make("venus").to_string(), token_uri: Some(token_uri), extension: None, }; - let minter = mock_info(MINTER_ADDR, &[]); + let minter = message_info(&minter, &[]); contract .execute(deps.as_mut(), mock_env(), minter, mint_msg) .unwrap(); let msg = to_json_binary("You now have the melting power").unwrap(); - let target = String::from("another_contract"); + let target = deps.api.addr_make("another_contract"); let send_msg = Cw721ExecuteMsg::SendNft { - contract: target.clone(), + contract: target.to_string(), token_id: token_id.clone(), msg: msg.clone(), }; - let random = mock_info("random", &[]); + let random = message_info(&deps.api.addr_make("random"), &[]); let err = contract .execute(deps.as_mut(), mock_env(), random, send_msg.clone()) .unwrap_err(); assert_eq!(err, Cw721ContractError::Ownership(OwnershipError::NotOwner)); // but owner can - let random = mock_info("venus", &[]); + let random = message_info(&deps.api.addr_make("venus"), &[]); let res = contract .execute(deps.as_mut(), mock_env(), random, send_msg) .unwrap(); let payload = Cw721ReceiveMsg { - sender: String::from("venus"), + sender: deps.api.addr_make("venus").to_string(), token_id: token_id.clone(), msg, }; @@ -504,9 +526,9 @@ fn sending_nft() { // ensure expected serializes as we think it should match &expected { CosmosMsg::Wasm(WasmMsg::Execute { contract_addr, .. }) => { - assert_eq!(contract_addr, &target) + assert_eq!(contract_addr, target.as_ref()) } - m => panic!("Unexpected message type: {m:?}"), + _m => panic!("Unexpected message type: {_m:?}"), } // and make sure this is the request sent by the contract assert_eq!( @@ -514,8 +536,8 @@ fn sending_nft() { Response::new() .add_message(expected) .add_attribute("action", "send_nft") - .add_attribute("sender", "venus") - .add_attribute("recipient", "another_contract") + .add_attribute("sender", deps.api.addr_make("venus").as_ref()) + .add_attribute("recipient", deps.api.addr_make("another_contract").as_ref()) .add_attribute("token_id", token_id) ); } @@ -523,7 +545,9 @@ fn sending_nft() { #[test] fn approving_revoking() { let mut deps = mock_dependencies(); - let contract = setup_contract(deps.as_mut()); + let creator = deps.api.addr_make(CREATOR); + let minter = deps.api.addr_make(MINTER_ADDR); + let contract = setup_contract(deps.as_mut(), creator, minter.clone()); // Mint a token let token_id = "grow".to_string(); @@ -531,12 +555,12 @@ fn approving_revoking() { let mint_msg = Cw721ExecuteMsg::Mint { token_id: token_id.clone(), - owner: String::from("demeter"), + owner: deps.api.addr_make("demeter").to_string(), token_uri: Some(token_uri), extension: None, }; - let minter = mock_info(MINTER_ADDR, &[]); + let minter = message_info(&minter, &[]); contract .execute(deps.as_mut(), mock_env(), minter, mint_msg) .unwrap(); @@ -547,7 +571,7 @@ fn approving_revoking() { deps.as_ref(), mock_env(), token_id.clone(), - String::from("demeter"), + deps.api.addr_make("demeter").to_string(), false, ) .unwrap(); @@ -555,7 +579,7 @@ fn approving_revoking() { res, ApprovalResponse { approval: Approval { - spender: Addr::unchecked("demeter"), + spender: deps.api.addr_make("demeter"), expires: Expiration::Never {} } } @@ -563,11 +587,11 @@ fn approving_revoking() { // Give random transferring power let approve_msg = Cw721ExecuteMsg::Approve { - spender: String::from("random"), + spender: deps.api.addr_make("random").to_string(), token_id: token_id.clone(), expires: None, }; - let owner = mock_info("demeter", &[]); + let owner = message_info(&deps.api.addr_make("demeter"), &[]); let res = contract .execute(deps.as_mut(), mock_env(), owner, approve_msg) .unwrap(); @@ -575,8 +599,8 @@ fn approving_revoking() { res, Response::new() .add_attribute("action", "approve") - .add_attribute("sender", "demeter") - .add_attribute("spender", "random") + .add_attribute("sender", deps.api.addr_make("demeter").as_ref()) + .add_attribute("spender", deps.api.addr_make("random").as_ref()) .add_attribute("token_id", token_id.clone()) ); @@ -586,7 +610,7 @@ fn approving_revoking() { deps.as_ref(), mock_env(), token_id.clone(), - String::from("random"), + deps.api.addr_make("random").to_string(), true, ) .unwrap(); @@ -594,16 +618,16 @@ fn approving_revoking() { res, ApprovalResponse { approval: Approval { - spender: Addr::unchecked("random"), + spender: deps.api.addr_make("random"), expires: Expiration::Never {} } } ); // random can now transfer - let random = mock_info("random", &[]); + let random = message_info(&deps.api.addr_make("random"), &[]); let transfer_msg = Cw721ExecuteMsg::TransferNft { - recipient: String::from("person"), + recipient: deps.api.addr_make("person").to_string(), token_id: token_id.clone(), }; contract @@ -624,24 +648,24 @@ fn approving_revoking() { assert_eq!( res, OwnerOfResponse { - owner: String::from("person"), + owner: deps.api.addr_make("person").to_string(), approvals: vec![], } ); // Approve, revoke, and check for empty, to test revoke let approve_msg = Cw721ExecuteMsg::Approve { - spender: String::from("random"), + spender: deps.api.addr_make("random").to_string(), token_id: token_id.clone(), expires: None, }; - let owner = mock_info("person", &[]); + let owner = message_info(&deps.api.addr_make("person"), &[]); contract .execute(deps.as_mut(), mock_env(), owner.clone(), approve_msg) .unwrap(); let revoke_msg = Cw721ExecuteMsg::Revoke { - spender: String::from("random"), + spender: deps.api.addr_make("random").to_string(), token_id, }; contract @@ -658,7 +682,7 @@ fn approving_revoking() { assert_eq!( res, OwnerOfResponse { - owner: String::from("person"), + owner: deps.api.addr_make("person").to_string(), approvals: vec![], } ); @@ -667,7 +691,9 @@ fn approving_revoking() { #[test] fn approving_all_revoking_all() { let mut deps = mock_dependencies(); - let contract = setup_contract(deps.as_mut()); + let creator = deps.api.addr_make(CREATOR); + let minter = deps.api.addr_make(MINTER_ADDR); + let contract = setup_contract(deps.as_mut(), creator, minter); // Mint a couple tokens (from the same owner) let token_id1 = "grow1".to_string(); @@ -678,19 +704,19 @@ fn approving_all_revoking_all() { let mint_msg1 = Cw721ExecuteMsg::Mint { token_id: token_id1.clone(), - owner: String::from("demeter"), + owner: deps.api.addr_make("demeter").to_string(), token_uri: Some(token_uri1), extension: None, }; - let minter = mock_info(MINTER_ADDR, &[]); + let minter = message_info(&deps.api.addr_make(MINTER_ADDR), &[]); contract .execute(deps.as_mut(), mock_env(), minter.clone(), mint_msg1) .unwrap(); let mint_msg2 = Cw721ExecuteMsg::Mint { token_id: token_id2.clone(), - owner: String::from("demeter"), + owner: deps.api.addr_make("demeter").to_string(), token_uri: Some(token_uri2), extension: None, }; @@ -714,10 +740,10 @@ fn approving_all_revoking_all() { // demeter gives random full (operator) power over her tokens let approve_all_msg = Cw721ExecuteMsg::ApproveAll { - operator: String::from("random"), + operator: deps.api.addr_make("random").to_string(), expires: None, }; - let owner = mock_info("demeter", &[]); + let owner = message_info(&deps.api.addr_make("demeter"), &[]); let res = contract .execute(deps.as_mut(), mock_env(), owner, approve_all_msg) .unwrap(); @@ -725,14 +751,14 @@ fn approving_all_revoking_all() { res, Response::new() .add_attribute("action", "approve_all") - .add_attribute("sender", "demeter") - .add_attribute("operator", "random") + .add_attribute("sender", deps.api.addr_make("demeter").as_ref()) + .add_attribute("operator", deps.api.addr_make("random").as_ref()) ); // random can now transfer - let random = mock_info("random", &[]); + let random = message_info(&deps.api.addr_make("random"), &[]); let transfer_msg = Cw721ExecuteMsg::TransferNft { - recipient: String::from("person"), + recipient: deps.api.addr_make("person").to_string(), token_id: token_id1, }; contract @@ -748,7 +774,7 @@ fn approving_all_revoking_all() { let msg: CosmosMsg = CosmosMsg::Wasm(inner_msg); let send_msg = Cw721ExecuteMsg::SendNft { - contract: String::from("another_contract"), + contract: deps.api.addr_make("another_contract").to_string(), token_id: token_id2, msg: to_json_binary(&msg).unwrap(), }; @@ -758,11 +784,11 @@ fn approving_all_revoking_all() { // Approve_all, revoke_all, and check for empty, to test revoke_all let approve_all_msg = Cw721ExecuteMsg::ApproveAll { - operator: String::from("operator"), + operator: deps.api.addr_make("operator").to_string(), expires: None, }; // person is now the owner of the tokens - let owner = mock_info("person", &[]); + let owner = message_info(&deps.api.addr_make("person"), &[]); contract .execute(deps.as_mut(), mock_env(), owner, approve_all_msg) .unwrap(); @@ -772,8 +798,8 @@ fn approving_all_revoking_all() { .query_operator( deps.as_ref(), mock_env(), - String::from("person"), - String::from("operator"), + deps.api.addr_make("person").to_string(), + deps.api.addr_make("operator").to_string(), true, ) .unwrap(); @@ -781,7 +807,7 @@ fn approving_all_revoking_all() { res, OperatorResponse { approval: Approval { - spender: Addr::unchecked("operator"), + spender: deps.api.addr_make("operator"), expires: Expiration::Never {} } } @@ -791,12 +817,12 @@ fn approving_all_revoking_all() { let res = contract.query_operator( deps.as_ref(), mock_env(), - String::from("person"), - String::from("other"), + deps.api.addr_make("person").to_string(), + deps.api.addr_make("other").to_string(), true, ); match res { - Err(StdError::NotFound { kind }) => assert_eq!(kind, "Approval not found"), + Err(StdError::NotFound { kind, .. }) => assert_eq!(kind, "Approval not found"), _ => panic!("Unexpected error"), } @@ -804,7 +830,7 @@ fn approving_all_revoking_all() { .query_operators( deps.as_ref(), mock_env(), - String::from("person"), + deps.api.addr_make("person").to_string(), true, None, None, @@ -814,7 +840,7 @@ fn approving_all_revoking_all() { res, OperatorsResponse { operators: vec![Approval { - spender: Addr::unchecked("operator"), + spender: deps.api.addr_make("operator"), expires: Expiration::Never {} }] } @@ -823,10 +849,10 @@ fn approving_all_revoking_all() { // second approval let buddy_expires = Expiration::AtHeight(1234567); let approve_all_msg = Cw721ExecuteMsg::ApproveAll { - operator: String::from("buddy"), + operator: deps.api.addr_make("buddy").to_string(), expires: Some(buddy_expires), }; - let owner = mock_info("person", &[]); + let owner = message_info(&deps.api.addr_make("person"), &[]); contract .execute(deps.as_mut(), mock_env(), owner.clone(), approve_all_msg) .unwrap(); @@ -836,17 +862,19 @@ fn approving_all_revoking_all() { .query_operators( deps.as_ref(), mock_env(), - String::from("person"), + deps.api.addr_make("person").to_string(), true, None, Some(1), ) .unwrap(); + // addr_make actually makes the buddy address *after* the operator one + assert_eq!( res, OperatorsResponse { operators: vec![Approval { - spender: Addr::unchecked("buddy"), + spender: deps.api.addr_make("buddy"), expires: buddy_expires, }] } @@ -855,24 +883,25 @@ fn approving_all_revoking_all() { .query_operators( deps.as_ref(), mock_env(), - String::from("person"), + deps.api.addr_make("person").to_string(), true, - Some(String::from("buddy")), + Some(deps.api.addr_make("buddy").to_string()), Some(2), ) .unwrap(); + assert_eq!( res, OperatorsResponse { operators: vec![Approval { - spender: Addr::unchecked("operator"), + spender: deps.api.addr_make("operator"), expires: Expiration::Never {} }] } ); let revoke_all_msg = Cw721ExecuteMsg::RevokeAll { - operator: String::from("operator"), + operator: deps.api.addr_make("operator").to_string(), }; contract .execute(deps.as_mut(), mock_env(), owner, revoke_all_msg) @@ -882,12 +911,12 @@ fn approving_all_revoking_all() { let res = contract.query_operator( deps.as_ref(), mock_env(), - String::from("person"), - String::from("operator"), + deps.api.addr_make("person").to_string(), + deps.api.addr_make("operator").to_string(), true, ); match res { - Err(StdError::NotFound { kind }) => assert_eq!(kind, "Approval not found"), + Err(StdError::NotFound { kind, .. }) => assert_eq!(kind, "Approval not found"), _ => panic!("Unexpected error"), } @@ -896,7 +925,7 @@ fn approving_all_revoking_all() { .query_operators( deps.as_ref(), mock_env(), - String::from("person"), + deps.api.addr_make("person").to_string(), false, None, None, @@ -906,7 +935,7 @@ fn approving_all_revoking_all() { res, OperatorsResponse { operators: vec![Approval { - spender: Addr::unchecked("buddy"), + spender: deps.api.addr_make("buddy"), expires: buddy_expires, }] } @@ -919,7 +948,7 @@ fn approving_all_revoking_all() { .query_operators( deps.as_ref(), late_env.clone(), - String::from("person"), + deps.api.addr_make("person").to_string(), false, None, None, @@ -931,13 +960,13 @@ fn approving_all_revoking_all() { let res = contract.query_operator( deps.as_ref(), late_env, - String::from("person"), - String::from("buddy"), + deps.api.addr_make("person").to_string(), + deps.api.addr_make("buddy").to_string(), false, ); match res { - Err(StdError::NotFound { kind }) => assert_eq!(kind, "Approval not found"), + Err(StdError::NotFound { kind, .. }) => assert_eq!(kind, "Approval not found"), _ => panic!("Unexpected error"), } } @@ -945,11 +974,15 @@ fn approving_all_revoking_all() { #[test] fn test_set_withdraw_address() { let mut deps = mock_dependencies(); - let contract = setup_contract(deps.as_mut()); - // other than minter cant set + let creator = deps.api.addr_make("creator"); + let minter = deps.api.addr_make(MINTER_ADDR); + let contract = setup_contract(deps.as_mut(), creator, minter.clone()); + let other = deps.api.addr_make("other"); + // other cant set + let foo = deps.api.addr_make("foo"); let err = contract - .set_withdraw_address(deps.as_mut(), &Addr::unchecked("other"), "foo".to_string()) + .set_withdraw_address(deps.as_mut(), &other, foo.to_string()) .unwrap_err(); assert_eq!(err, Cw721ContractError::Ownership(OwnershipError::NotOwner)); @@ -957,7 +990,7 @@ fn test_set_withdraw_address() { contract .set_withdraw_address( deps.as_mut(), - &Addr::unchecked(MINTER_ADDR), + &minter, "foo".to_string(), ) .unwrap(); @@ -967,23 +1000,27 @@ fn test_set_withdraw_address() { .withdraw_address .load(deps.as_ref().storage) .unwrap(); - assert_eq!(withdraw_address, "foo".to_string()) + assert_eq!(withdraw_address, foo.to_string()) } #[test] fn test_remove_withdraw_address() { let mut deps = mock_dependencies(); - let contract = setup_contract(deps.as_mut()); + let creator = deps.api.addr_make(CREATOR); + let minter = deps.api.addr_make(MINTER_ADDR); + let contract = setup_contract(deps.as_mut(), creator, minter.clone()); + let other = deps.api.addr_make("other"); + let foo = deps.api.addr_make("foo"); // other than creator cant remove let err = contract - .remove_withdraw_address(deps.as_mut().storage, &Addr::unchecked("other")) + .remove_withdraw_address(deps.as_mut().storage, &other) .unwrap_err(); assert_eq!(err, Cw721ContractError::Ownership(OwnershipError::NotOwner)); // no withdraw address set yet let err = contract - .remove_withdraw_address(deps.as_mut().storage, &Addr::unchecked(MINTER_ADDR)) + .remove_withdraw_address(deps.as_mut().storage, &minter) .unwrap_err(); assert_eq!(err, Cw721ContractError::NoWithdrawAddress {}); @@ -991,12 +1028,12 @@ fn test_remove_withdraw_address() { contract .set_withdraw_address( deps.as_mut(), - &Addr::unchecked(MINTER_ADDR), - "foo".to_string(), + &minter, + foo.to_string(), ) .unwrap(); contract - .remove_withdraw_address(deps.as_mut().storage, &Addr::unchecked(MINTER_ADDR)) + .remove_withdraw_address(deps.as_mut().storage, &minter) .unwrap(); assert!(!contract .config @@ -1005,60 +1042,58 @@ fn test_remove_withdraw_address() { // test that we can set again contract - .set_withdraw_address( - deps.as_mut(), - &Addr::unchecked(MINTER_ADDR), - "foo".to_string(), - ) + .set_withdraw_address(deps.as_mut(), &minter, foo.to_string()) .unwrap(); let withdraw_address = contract .config .withdraw_address .load(deps.as_ref().storage) .unwrap(); - assert_eq!(withdraw_address, "foo".to_string()) + assert_eq!(withdraw_address, foo.to_string()) } #[test] fn test_withdraw_funds() { let mut deps = mock_dependencies(); - let contract = setup_contract(deps.as_mut()); + let creator = deps.api.addr_make("creator"); + let minter = deps.api.addr_make(MINTER_ADDR); + let foo = deps.api.addr_make("foo"); + let contract = setup_contract(deps.as_mut(), creator, minter.clone()); // no withdraw address set let err = contract - .withdraw_funds(deps.as_mut().storage, &Coin::new(100, "uark")) + .withdraw_funds(deps.as_mut().storage, &Coin::new(100u32, "uark")) .unwrap_err(); assert_eq!(err, Cw721ContractError::NoWithdrawAddress {}); // set and withdraw by non-owner contract - .set_withdraw_address( - deps.as_mut(), - &Addr::unchecked(MINTER_ADDR), - "foo".to_string(), - ) + .set_withdraw_address(deps.as_mut(), &minter, foo.to_string()) .unwrap(); contract - .withdraw_funds(deps.as_mut().storage, &Coin::new(100, "uark")) + .withdraw_funds(deps.as_mut().storage, &Coin::new(100u32, "uark")) .unwrap(); } #[test] fn query_tokens_by_owner() { let mut deps = mock_dependencies(); - let contract = setup_contract(deps.as_mut()); - let minter = mock_info(MINTER_ADDR, &[]); + let creator = deps.api.addr_make(CREATOR); + let minter = deps.api.addr_make(MINTER_ADDR); + let contract = setup_contract(deps.as_mut(), creator, minter.clone()); + + let minter = message_info(&minter, &[]); // Mint a couple tokens (from the same owner) let token_id1 = "grow1".to_string(); - let demeter = String::from("demeter"); + let demeter = deps.api.addr_make("demeter"); let token_id2 = "grow2".to_string(); - let ceres = String::from("ceres"); + let ceres = deps.api.addr_make("ceres"); let token_id3 = "sing".to_string(); let mint_msg = Cw721ExecuteMsg::Mint { token_id: token_id1.clone(), - owner: demeter.clone(), + owner: demeter.to_string(), token_uri: None, extension: None, }; @@ -1068,7 +1103,7 @@ fn query_tokens_by_owner() { let mint_msg = Cw721ExecuteMsg::Mint { token_id: token_id2.clone(), - owner: ceres.clone(), + owner: ceres.to_string(), token_uri: None, extension: None, }; @@ -1078,7 +1113,7 @@ fn query_tokens_by_owner() { let mint_msg = Cw721ExecuteMsg::Mint { token_id: token_id3.clone(), - owner: demeter.clone(), + owner: demeter.to_string(), token_uri: None, extension: None, }; @@ -1108,24 +1143,24 @@ fn query_tokens_by_owner() { let by_demeter = vec![token_id1, token_id3]; // all tokens by owner let tokens = contract - .query_tokens(deps.as_ref(), env.clone(), demeter.clone(), None, None) + .query_tokens(deps.as_ref(), env.clone(), demeter.to_string(), None, None) .unwrap(); assert_eq!(&by_demeter, &tokens.tokens); let tokens = contract - .query_tokens(deps.as_ref(), env.clone(), ceres, None, None) + .query_tokens(deps.as_ref(), env.clone(), ceres.to_string(), None, None) .unwrap(); assert_eq!(&by_ceres, &tokens.tokens); // paginate for demeter let tokens = contract - .query_tokens(deps.as_ref(), env.clone(), demeter.clone(), None, Some(1)) + .query_tokens(deps.as_ref(), env.clone(), demeter.to_string(), None, Some(1)) .unwrap(); assert_eq!(&by_demeter[..1], &tokens.tokens[..]); let tokens = contract .query_tokens( deps.as_ref(), env, - demeter, + demeter.to_string(), Some(by_demeter[0].clone()), Some(3), ) diff --git a/packages/cw721/src/testing/multi_tests.rs b/packages/cw721/src/testing/multi_tests.rs index 4bbd08228..5bc5bc7e7 100644 --- a/packages/cw721/src/testing/multi_tests.rs +++ b/packages/cw721/src/testing/multi_tests.rs @@ -65,7 +65,7 @@ fn cw721_base_latest_contract() -> Box> { let contract = ContractWrapper::new(execute, instantiate, query).with_migrate(migrate); Box::new(contract) } - +/* cw16 not supported fn cw721_base_016_contract() -> Box> { use cw721_base_016 as v16; let contract = ContractWrapper::new( @@ -76,6 +76,8 @@ fn cw721_base_016_contract() -> Box> { Box::new(contract) } + */ + fn cw721_base_017_contract() -> Box> { use cw721_base_017 as v17; let contract = ContractWrapper::new( @@ -124,7 +126,7 @@ fn mint_transfer_and_burn(app: &mut App, cw721: Addr, sender: Addr, token_id: St .unwrap(); let owner = query_owner(app.wrap(), &cw721, token_id.clone()); - assert_eq!(owner, sender.to_string()); + assert_eq!(owner.to_string(), sender.to_string()); app.execute_contract( sender, @@ -138,7 +140,7 @@ fn mint_transfer_and_burn(app: &mut App, cw721: Addr, sender: Addr, token_id: St .unwrap(); let owner = query_owner(app.wrap(), &cw721, token_id.clone()); - assert_eq!(owner, "burner".to_string()); + assert_eq!(owner.to_string(), "burner".to_string()); app.execute_contract( Addr::unchecked("burner"), @@ -334,20 +336,20 @@ fn test_operator() { fn test_migration_legacy_to_latest() { // case 1: migrate from v0.16 to latest by using existing minter addr { - use cw721_base_016 as v16; + use cw721_base_017 as v17; let mut app = App::default(); let admin = Addr::unchecked("admin"); - let code_id_016 = app.store_code(cw721_base_016_contract()); + let code_id_017 = app.store_code(cw721_base_017_contract()); let code_id_latest = app.store_code(cw721_base_latest_contract()); let legacy_creator_and_minter = Addr::unchecked("legacy_creator_and_minter"); let cw721 = app .instantiate_contract( - code_id_016, + code_id_017, legacy_creator_and_minter.clone(), - &v16::InstantiateMsg { + &v17::InstantiateMsg { name: "collection".to_string(), symbol: "symbol".to_string(), minter: legacy_creator_and_minter.to_string(), @@ -417,11 +419,11 @@ fn test_migration_legacy_to_latest() { // check that the new response is backwards compatable when minter // is not None. - let m: v16::MinterResponse = app + let m: v17::MinterResponse = app .wrap() .query_wasm_smart(&cw721, &Cw721QueryMsg::::Minter {}) .unwrap(); - assert_eq!(m.minter, legacy_creator_and_minter.to_string()); + assert_eq!(m.minter, Some(legacy_creator_and_minter.to_string())); // check minter ownership query works let minter_ownership: Ownership = app @@ -432,20 +434,20 @@ fn test_migration_legacy_to_latest() { } // case 2: migrate from v0.16 to latest by providing new creator and minter addr { - use cw721_base_016 as v16; + use cw721_base_017 as v17; let mut app = App::default(); let admin = Addr::unchecked("admin"); - let code_id_016 = app.store_code(cw721_base_016_contract()); + let code_id_017 = app.store_code(cw721_base_017_contract()); let code_id_latest = app.store_code(cw721_base_latest_contract()); let legacy_creator_and_minter = Addr::unchecked("legacy_creator_and_minter"); let cw721 = app .instantiate_contract( - code_id_016, + code_id_017, legacy_creator_and_minter.clone(), - &v16::InstantiateMsg { + &v17::InstantiateMsg { name: "collection".to_string(), symbol: "symbol".to_string(), minter: legacy_creator_and_minter.to_string(), @@ -510,11 +512,11 @@ fn test_migration_legacy_to_latest() { // check that the new response is backwards compatable when minter // is not None. - let m: v16::MinterResponse = app + let m: v17::MinterResponse = app .wrap() .query_wasm_smart(&cw721, &Cw721QueryMsg::::Minter {}) .unwrap(); - assert_eq!(m.minter, minter.to_string()); + assert_eq!(m.minter,Some(minter.to_string())); // check minter ownership query works let minter_ownership: Ownership = app diff --git a/packages/cw721/src/testing/unit_tests.rs b/packages/cw721/src/testing/unit_tests.rs index dcac842f0..636480539 100644 --- a/packages/cw721/src/testing/unit_tests.rs +++ b/packages/cw721/src/testing/unit_tests.rs @@ -1,15 +1,15 @@ use crate::{ execute::Cw721Execute, msg::{Cw721ExecuteMsg, Cw721InstantiateMsg}, - query::{Cw721Query, MAX_LIMIT}, - state::{CollectionInfo, DefaultOptionMetadataExtension, Metadata, MINTER}, + query::{Cw721Query, }, + state::{DefaultOptionMetadataExtension, Metadata, MINTER}, }; use cosmwasm_std::{ - testing::{mock_dependencies, mock_env, mock_info}, - Addr, Empty, + testing::{mock_dependencies, mock_env}, + Empty, }; +use cosmwasm_std::testing::message_info; use cw2::ContractVersion; -use cw_storage_plus::Item; use unit_tests::{contract::Cw721Contract, multi_tests::CREATOR_ADDR}; use super::*; @@ -23,7 +23,7 @@ fn proper_cw2_initialization() { .instantiate( deps.as_mut(), mock_env(), - mock_info("larry", &[]), + message_info(&deps.api.addr_make("larry"), &[]), Cw721InstantiateMsg { name: "collection_name".into(), symbol: "collection_symbol".into(), @@ -56,7 +56,7 @@ fn proper_cw2_initialization() { fn proper_owner_initialization() { let mut deps = mock_dependencies(); - let info_owner = mock_info("owner", &[]); + let info_owner = message_info(&deps.api.addr_make("owner"), &[]); Cw721Contract::::default() .instantiate( deps.as_mut(), @@ -82,7 +82,7 @@ fn use_metadata_extension() { let mut deps = mock_dependencies(); let contract = Cw721Contract::::default(); - let info = mock_info(CREATOR_ADDR, &[]); + let info = message_info(&deps.api.addr_make(CREATOR_ADDR), &[]); let init_msg = Cw721InstantiateMsg { name: "collection_name".into(), symbol: "collection_symbol".into(), @@ -125,6 +125,7 @@ fn use_metadata_extension() { assert_eq!(res.extension, extension); } +/* v16 Migrations aren't supported. #[test] fn test_migrate() { let mut deps = mock_dependencies(); @@ -134,7 +135,7 @@ fn test_migrate() { v16::entry::instantiate( deps.as_mut(), env.clone(), - mock_info("owner", &[]), + message_info(&deps.api.addr_make("owner"), &[]), v16::InstantiateMsg { name: "legacy_name".into(), symbol: "legacy_symbol".into(), @@ -145,7 +146,7 @@ fn test_migrate() { // mint 200 NFTs before migration for i in 0..200 { - let info = mock_info("legacy_minter", &[]); + let info = message_info(&deps.api.addr_make("legacy_minter"), &[]); let msg = v16::ExecuteMsg::Mint(v16::msg::MintMsg { token_id: i.to_string(), owner: "owner".into(), @@ -252,4 +253,6 @@ fn test_migrate() { .unwrap(); assert_eq!(token.owner.as_str(), "owner"); } + } + */