From f3c053fead347cebbb015eafe358ca490cc37d47 Mon Sep 17 00:00:00 2001 From: Jorge Hernandez <3452489+jhernandezb@users.noreply.github.com> Date: Thu, 25 Jan 2024 10:20:52 -0600 Subject: [PATCH] skip duplicates (#637) * skip duplicates * fix lint * bump rust version * bump rust * change cosmwasm check * fix cache key --- .circleci/config.yml | 94 +++++++++---------- .../whitelists/whitelist/src/contract.rs | 8 +- .../src/sg721_base/tests/integration_tests.rs | 2 +- test-suite/src/whitelist/tests/unit_tests.rs | 13 ++- ts/src/Sg721Updatable.types.ts | 1 + 5 files changed, 64 insertions(+), 54 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 013d362de..3e1d23ed2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -31,7 +31,7 @@ workflows: jobs: contract_sg721_base: docker: - - image: rust:1.69.0 + - image: rust:1.73.0 working_directory: ~/project/contracts/collections/sg721-base steps: - checkout: @@ -41,7 +41,7 @@ jobs: command: rustc --version; cargo --version; rustup --version - restore_cache: keys: - - cargocache-sg721-rust:1.69.0-{{ checksum "~/project/Cargo.lock" }} + - cargocache-sg721-rust:1.73.0-{{ checksum "~/project/Cargo.lock" }} - run: name: Unit Tests environment: @@ -63,11 +63,11 @@ jobs: paths: - /usr/local/cargo/registry - target - key: cargocache-sg721-rust:1.69.0-{{ checksum "~/project/Cargo.lock" }} + key: cargocache-sg721-rust:1.73.0-{{ checksum "~/project/Cargo.lock" }} contract_sg721_nt: docker: - - image: rust:1.69.0 + - image: rust:1.73.0 working_directory: ~/project/contracts/collections/sg721-nt steps: - checkout: @@ -77,7 +77,7 @@ jobs: command: rustc --version; cargo --version; rustup --version - restore_cache: keys: - - cargocache-sg721-nt-rust:1.69.0-{{ checksum "~/project/Cargo.lock" }} + - cargocache-sg721-nt-rust:1.73.0-{{ checksum "~/project/Cargo.lock" }} - run: name: Unit Tests environment: @@ -99,11 +99,11 @@ jobs: paths: - /usr/local/cargo/registry - target - key: cargocache-sg721-nt-rust:1.69.0-{{ checksum "~/project/Cargo.lock" }} + key: cargocache-sg721-nt-rust:1.73.0-{{ checksum "~/project/Cargo.lock" }} contract_base_factory: docker: - - image: rust:1.69.0 + - image: rust:1.73.0 working_directory: ~/project/contracts/factories/base-factory steps: - checkout: @@ -113,7 +113,7 @@ jobs: command: rustc --version; cargo --version; rustup --version - restore_cache: keys: - - cargocache-base-factory-rust:1.69.0-{{ checksum "~/project/Cargo.lock" }} + - cargocache-base-factory-rust:1.73.0-{{ checksum "~/project/Cargo.lock" }} - run: name: Unit Tests environment: @@ -135,11 +135,11 @@ jobs: paths: - /usr/local/cargo/registry - target - key: cargocache-base-factory-rust:1.69.0-{{ checksum "~/project/Cargo.lock" }} + key: cargocache-base-factory-rust:1.73.0-{{ checksum "~/project/Cargo.lock" }} contract_base_minter: docker: - - image: rust:1.69.0 + - image: rust:1.73.0 working_directory: ~/project/contracts/minters/base-minter steps: - checkout: @@ -149,7 +149,7 @@ jobs: command: rustc --version; cargo --version; rustup --version - restore_cache: keys: - - cargocache-base-minter-rust:1.69.0-{{ checksum "~/project/Cargo.lock" }} + - cargocache-base-minter-rust:1.73.0-{{ checksum "~/project/Cargo.lock" }} - run: name: Unit Tests environment: @@ -171,11 +171,11 @@ jobs: paths: - /usr/local/cargo/registry - target - key: cargocache-base-minter-rust:1.69.0-{{ checksum "~/project/Cargo.lock" }} + key: cargocache-base-minter-rust:1.73.0-{{ checksum "~/project/Cargo.lock" }} contract_vending_factory: docker: - - image: rust:1.69.0 + - image: rust:1.73.0 working_directory: ~/project/contracts/factories/vending-factory steps: - checkout: @@ -185,7 +185,7 @@ jobs: command: rustc --version; cargo --version; rustup --version - restore_cache: keys: - - cargocache-vending-factory-rust:1.69.0-{{ checksum "~/project/Cargo.lock" }} + - cargocache-vending-factory-rust:1.73.0-{{ checksum "~/project/Cargo.lock" }} - run: name: Unit Tests environment: @@ -207,11 +207,11 @@ jobs: paths: - /usr/local/cargo/registry - target - key: cargocache-vending-factory-rust:1.69.0-{{ checksum "~/project/Cargo.lock" }} + key: cargocache-vending-factory-rust:1.73.0-{{ checksum "~/project/Cargo.lock" }} contract_vending_minter: docker: - - image: rust:1.69.0 + - image: rust:1.73.0 working_directory: ~/project/contracts/minters/vending-minter steps: - checkout: @@ -221,7 +221,7 @@ jobs: command: rustc --version; cargo --version; rustup --version - restore_cache: keys: - - cargocache-vending-minter-rust:1.69.0-{{ checksum "~/project/Cargo.lock" }} + - cargocache-vending-minter-rust:1.73.0-{{ checksum "~/project/Cargo.lock" }} - run: name: Unit Tests environment: @@ -243,11 +243,11 @@ jobs: paths: - /usr/local/cargo/registry - target - key: cargocache-vending-minter-rust:1.69.0-{{ checksum "~/project/Cargo.lock" }} + key: cargocache-vending-minter-rust:1.73.0-{{ checksum "~/project/Cargo.lock" }} contract_open_edition_factory: docker: - - image: rust:1.69.0 + - image: rust:1.73.0 working_directory: ~/project/contracts/factories/open-edition-factory steps: - checkout: @@ -257,7 +257,7 @@ jobs: command: rustc --version; cargo --version; rustup --version - restore_cache: keys: - - cargocache-open-edition-factory-rust:1.69.0-{{ checksum "~/project/Cargo.lock" }} + - cargocache-open-edition-factory-rust:1.73.0-{{ checksum "~/project/Cargo.lock" }} - run: name: Unit Tests environment: @@ -279,11 +279,11 @@ jobs: paths: - /usr/local/cargo/registry - target - key: cargocache-open-edition-factory-rust:1.69.0-{{ checksum "~/project/Cargo.lock" }} + key: cargocache-open-edition-factory-rust:1.73.0-{{ checksum "~/project/Cargo.lock" }} contract_open_edition_minter: docker: - - image: rust:1.69.0 + - image: rust:1.73.0 working_directory: ~/project/contracts/minters/open-edition-minter steps: - checkout: @@ -293,7 +293,7 @@ jobs: command: rustc --version; cargo --version; rustup --version - restore_cache: keys: - - cargocache-open-edition-minter-rust:1.69.0-{{ checksum "~/project/Cargo.lock" }} + - cargocache-open-edition-minter-rust:1.73.0-{{ checksum "~/project/Cargo.lock" }} - run: name: Unit Tests environment: @@ -315,11 +315,11 @@ jobs: paths: - /usr/local/cargo/registry - target - key: cargocache-open-edition-minter-rust:1.69.0-{{ checksum "~/project/Cargo.lock" }} + key: cargocache-open-edition-minter-rust:1.73.0-{{ checksum "~/project/Cargo.lock" }} contract_whitelist: docker: - - image: rust:1.69.0 + - image: rust:1.73.0 working_directory: ~/project/contracts/whitelists/whitelist steps: - checkout: @@ -329,7 +329,7 @@ jobs: command: rustc --version; cargo --version; rustup --version - restore_cache: keys: - - cargocache-whitelist-rust:1.69.0-{{ checksum "~/project/Cargo.lock" }} + - cargocache-whitelist-rust:1.73.0-{{ checksum "~/project/Cargo.lock" }} - run: name: Unit Tests environment: @@ -351,10 +351,10 @@ jobs: paths: - /usr/local/cargo/registry - target - key: cargocache-whitelist-rust:1.69.0-{{ checksum "~/project/Cargo.lock" }} + key: cargocache-whitelist-rust:1.73.0-{{ checksum "~/project/Cargo.lock" }} test-suite: docker: - - image: rust:1.69.0 + - image: rust:1.73.0 working_directory: ~/project/test-suite steps: - checkout: @@ -364,7 +364,7 @@ jobs: command: rustc --version; cargo --version; rustup --version - restore_cache: keys: - - cargocache-test-suite-rust:1.69.0-{{ checksum "~/project/Cargo.lock" }} + - cargocache-test-suite-rust:1.73.0-{{ checksum "~/project/Cargo.lock" }} - run: name: Unit Tests environment: @@ -374,11 +374,11 @@ jobs: paths: - /usr/local/cargo/registry - target - key: cargocache-test-suite-rust:1.69.0-{{ checksum "~/project/Cargo.lock" }} + key: cargocache-test-suite-rust:1.73.0-{{ checksum "~/project/Cargo.lock" }} package_sg_std: docker: - - image: rust:1.69.0 + - image: rust:1.73.0 working_directory: ~/project/package/sg-std steps: - checkout: @@ -388,7 +388,7 @@ jobs: command: rustc --version; cargo --version; rustup --version - restore_cache: keys: - - cargocache-sg-std-rust:1.69.0-{{ checksum "~/project/Cargo.lock" }} + - cargocache-sg-std-rust:1.73.0-{{ checksum "~/project/Cargo.lock" }} - run: name: Unit Tests environment: @@ -398,11 +398,11 @@ jobs: paths: - /usr/local/cargo/registry - target - key: cargocache-sg-std-rust:1.69.0-{{ checksum "~/project/Cargo.lock" }} + key: cargocache-sg-std-rust:1.73.0-{{ checksum "~/project/Cargo.lock" }} package_sg_utils: docker: - - image: rust:1.69.0 + - image: rust:1.73.0 working_directory: ~/project/package/sg-utils steps: - checkout: @@ -412,7 +412,7 @@ jobs: command: rustc --version; cargo --version; rustup --version - restore_cache: keys: - - cargocache-sg-utils-rust:1.69.0-{{ checksum "~/project/Cargo.lock" }} + - cargocache-sg-utils-rust:1.73.0-{{ checksum "~/project/Cargo.lock" }} - run: name: Unit Tests environment: @@ -422,11 +422,11 @@ jobs: paths: - /usr/local/cargo/registry - target - key: cargocache-sg-utils-rust:1.69.0-{{ checksum "~/project/Cargo.lock" }} + key: cargocache-sg-utils-rust:1.73.0-{{ checksum "~/project/Cargo.lock" }} sg-eth-airdrop: docker: - - image: rust:1.69.0 + - image: rust:1.73.0 working_directory: ~/project/contracts/sg-eth-airdrop steps: - checkout: @@ -436,7 +436,7 @@ jobs: command: rustc --version; cargo --version; rustup --version - restore_cache: keys: - - cargocache-sg-eth-airdrop-rust:1.69.0-{{ checksum "~/project/Cargo.lock" }} + - cargocache-sg-eth-airdrop-rust:1.73.0-{{ checksum "~/project/Cargo.lock" }} - run: name: Unit Tests environment: @@ -458,11 +458,11 @@ jobs: paths: - /usr/local/cargo/registry - target - key: cargocache-sg-eth-airdrop-rust:1.69.0-{{ checksum "~/project/Cargo.lock" }} + key: cargocache-sg-eth-airdrop-rust:1.73.0-{{ checksum "~/project/Cargo.lock" }} lint: docker: - - image: rust:1.69.0 + - image: rust:1.73.0 steps: - checkout - run: @@ -470,7 +470,7 @@ jobs: command: rustc --version; cargo --version; rustup --version; rustup target list --installed - restore_cache: keys: - - cargocache-v2-lint-rust:1.69.0-{{ checksum "Cargo.lock" }} + - cargocache-v2-lint-rust:1.73.0-{{ checksum "Cargo.lock" }} - run: name: Add rustfmt component command: rustup component add rustfmt @@ -489,7 +489,7 @@ jobs: - target/debug/.fingerprint - target/debug/build - target/debug/deps - key: cargocache-v2-lint-rust:1.69.0-{{ checksum "Cargo.lock" }} + key: cargocache-v2-lint-rust:1.73.0-{{ checksum "Cargo.lock" }} # This runs one time on the top level to ensure all contracts compile properly into wasm. # We don't run the wasm build per contract build, and then reuse a lot of the same dependencies, so this speeds up CI time @@ -497,7 +497,7 @@ jobs: # We also sanity-check the resultant wasm files. wasm-build: docker: - - image: rust:1.69.0 + - image: rust:1.73.0 steps: - checkout: path: ~/project @@ -506,7 +506,7 @@ jobs: command: rustc --version; cargo --version; rustup --version - restore_cache: keys: - - cargocache-wasm-rust-no-wasm:1.67.1-{{ checksum "~/project/Cargo.lock" }} + - cargocache-wasm-rust-no-wasm:1.73.0-{{ checksum "~/project/Cargo.lock" }} - run: name: Add wasm32 target command: rustup target add wasm32-unknown-unknown @@ -546,21 +546,21 @@ jobs: - run: name: Install check_contract # Uses --debug for compilation speed - command: cargo install --debug --version 1.0.0 --features iterator --example check_contract -- cosmwasm-vm + command: cargo install cosmwasm-check - save_cache: paths: - /usr/local/cargo/registry - /target/debug - /target/release - /target/tarpaulin - key: cargocache-wasm-rust-no-wasm:1.67.1-{{ checksum "~/project/Cargo.lock" }} + key: cargocache-wasm-rust-no-wasm:1.73.0-{{ checksum "~/project/Cargo.lock" }} - run: name: Check wasm contracts command: | for W in ./target/wasm32-unknown-unknown/release/*.wasm do echo -n "Checking `basename $W`... " - check_contract --supported-features iterator,staking,stargate,stargaze $W + cosmwasm-check --available-capabilities iterator,staking,stargate,stargaze $W done # This job roughly follows the instructions from https://circleci.com/blog/publishing-to-github-releases-via-circleci/ diff --git a/contracts/whitelists/whitelist/src/contract.rs b/contracts/whitelists/whitelist/src/contract.rs index 9ed35b6d2..c00007195 100644 --- a/contracts/whitelists/whitelist/src/contract.rs +++ b/contracts/whitelists/whitelist/src/contract.rs @@ -237,7 +237,7 @@ pub fn execute_add_members( // remove duplicate members msg.to_add.sort_unstable(); msg.to_add.dedup(); - + let mut members_added = 0; for add in msg.to_add.into_iter() { if config.num_members >= config.member_limit { return Err(ContractError::MembersExceeded { @@ -246,9 +246,11 @@ pub fn execute_add_members( }); } let addr = deps.api.addr_validate(&add)?; + // if already whitelisted, skip it if WHITELIST.has(deps.storage, addr.clone()) { - return Err(ContractError::DuplicateMember(addr.to_string())); + continue; } + members_added += 1; WHITELIST.save(deps.storage, addr, &true)?; config.num_members += 1; } @@ -257,6 +259,8 @@ pub fn execute_add_members( Ok(Response::new() .add_attribute("action", "add_members") + .add_attribute("num_members", config.num_members.to_string()) + .add_attribute("members_added", members_added.to_string()) .add_attribute("sender", info.sender)) } diff --git a/test-suite/src/sg721_base/tests/integration_tests.rs b/test-suite/src/sg721_base/tests/integration_tests.rs index dc09ea2f9..454b24e0b 100644 --- a/test-suite/src/sg721_base/tests/integration_tests.rs +++ b/test-suite/src/sg721_base/tests/integration_tests.rs @@ -455,7 +455,7 @@ mod tests { // update explicit content with new creator let res = app.execute_contract( - creator.clone(), + creator, contract.clone(), &Sg721ExecuteMsg::::UpdateCollectionInfo { collection_info: UpdateCollectionInfoMsg { diff --git a/test-suite/src/whitelist/tests/unit_tests.rs b/test-suite/src/whitelist/tests/unit_tests.rs index df461bd9f..a716d473b 100644 --- a/test-suite/src/whitelist/tests/unit_tests.rs +++ b/test-suite/src/whitelist/tests/unit_tests.rs @@ -199,11 +199,14 @@ fn update_members() { let msg = ExecuteMsg::AddMembers(add_msg); let info = mock_info(ADMIN, &[]); let res = execute(deps.as_mut(), mock_env(), info.clone(), msg.clone()).unwrap(); - assert_eq!(res.attributes.len(), 2); + assert_eq!(res.attributes.len(), 4); let res = query_members(deps.as_ref(), None, None).unwrap(); assert_eq!(res.members.len(), 2); - execute(deps.as_mut(), mock_env(), info.clone(), msg).unwrap_err(); + // adding duplicate members should succeed + execute(deps.as_mut(), mock_env(), info.clone(), msg).unwrap(); + let res = query_members(deps.as_ref(), None, None).unwrap(); + assert_eq!(res.members.len(), 2); let remove_msg = RemoveMembersMsg { to_remove: vec!["adsfsa1".to_string()], @@ -422,11 +425,13 @@ fn add_members_with_specified_admin(admin: &str) { let msg = ExecuteMsg::AddMembers(add_msg); let info = mock_info(admin, &[]); let res = execute(deps.as_mut(), mock_env(), info.clone(), msg.clone()).unwrap(); - assert_eq!(res.attributes.len(), 2); + assert_eq!(res.attributes.len(), 4); let res = query_members(deps.as_ref(), None, None).unwrap(); assert_eq!(res.members.len(), 2); - execute(deps.as_mut(), mock_env(), info.clone(), msg).unwrap_err(); + execute(deps.as_mut(), mock_env(), info.clone(), msg).unwrap(); + let res = query_members(deps.as_ref(), None, None).unwrap(); + assert_eq!(res.members.len(), 2); let remove_msg = RemoveMembersMsg { to_remove: vec!["adsfsa1".to_string()], diff --git a/ts/src/Sg721Updatable.types.ts b/ts/src/Sg721Updatable.types.ts index 32de4ea64..be126655c 100644 --- a/ts/src/Sg721Updatable.types.ts +++ b/ts/src/Sg721Updatable.types.ts @@ -128,6 +128,7 @@ export type ExecuteMsgForNullable_EmptyAndEmpty = { }; export type Binary = string; export interface UpdateCollectionInfoMsgForRoyaltyInfoResponse { + creator?: string | null; description?: string | null; explicit_content?: boolean | null; external_link?: string | null;