Skip to content

Commit

Permalink
skip duplicates (#637)
Browse files Browse the repository at this point in the history
* skip duplicates

* fix lint

* bump rust version

* bump rust

* change cosmwasm check

* fix cache key
  • Loading branch information
jhernandezb authored Jan 25, 2024
1 parent 111b025 commit f3c053f
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 54 deletions.
94 changes: 47 additions & 47 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -458,19 +458,19 @@ 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:
name: Version information
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
Expand All @@ -489,15 +489,15 @@ 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
# for all the other tests.
# 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
Expand All @@ -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
Expand Down Expand Up @@ -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/
Expand Down
8 changes: 6 additions & 2 deletions contracts/whitelists/whitelist/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
}
Expand All @@ -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))
}

Expand Down
Loading

0 comments on commit f3c053f

Please sign in to comment.