Skip to content

Commit

Permalink
Royalty increase update for v1 collections (#631)
Browse files Browse the repository at this point in the history
* Modify royalty update logic

* Update unit tests

* Bump version for sg721-updatable

* Address linter issues

* Update schema files

* Address clippy issues

* Update rust version for CI

* Update parameter name for sg721-updatable/migrate()

* Update rust version for CI
  • Loading branch information
MightOfOaks authored Jan 18, 2024
1 parent f9b1c54 commit 2a10b3a
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 157 deletions.
54 changes: 27 additions & 27 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ workflows:
jobs:
contract_sg721:
docker:
- image: rust:1.64.0
- image: rust:1.68.0
working_directory: ~/project/contracts/sg721
steps:
- checkout:
Expand All @@ -34,7 +34,7 @@ jobs:
command: rustc --version; cargo --version; rustup --version
- restore_cache:
keys:
- cargocache-sg721-rust:1.64.0-{{ checksum "~/project/Cargo.lock" }}
- cargocache-sg721-rust:1.68.0-{{ checksum "~/project/Cargo.lock" }}
- run:
name: Unit Tests
environment:
Expand All @@ -56,10 +56,10 @@ jobs:
paths:
- /usr/local/cargo/registry
- target
key: cargocache-sg721-rust:1.64.0-{{ checksum "~/project/Cargo.lock" }}
key: cargocache-sg721-rust:1.68.0-{{ checksum "~/project/Cargo.lock" }}
contract_sg721_updatable:
docker:
- image: rust:1.64.0
- image: rust:1.68.0
working_directory: ~/project/contracts/sg721-updatable
steps:
- checkout:
Expand All @@ -69,7 +69,7 @@ jobs:
command: rustc --version; cargo --version; rustup --version
- restore_cache:
keys:
- cargocache-sg721-rust:1.64.0-{{ checksum "~/project/Cargo.lock" }}
- cargocache-sg721-rust:1.68.0-{{ checksum "~/project/Cargo.lock" }}
- run:
name: Unit Tests
environment:
Expand All @@ -91,11 +91,11 @@ jobs:
paths:
- /usr/local/cargo/registry
- target
key: cargocache-sg721-updatable-rust:1.64.0-{{ checksum "~/project/Cargo.lock" }}
key: cargocache-sg721-updatable-rust:1.68.0-{{ checksum "~/project/Cargo.lock" }}

contract_minter:
docker:
- image: rust:1.64.0
- image: rust:1.68.0
working_directory: ~/project/contracts/minter
steps:
- checkout:
Expand All @@ -105,7 +105,7 @@ jobs:
command: rustc --version; cargo --version; rustup --version
- restore_cache:
keys:
- cargocache-minter-rust:1.64.0-{{ checksum "~/project/Cargo.lock" }}
- cargocache-minter-rust:1.68.0-{{ checksum "~/project/Cargo.lock" }}
- run:
name: Unit Tests
environment:
Expand All @@ -127,11 +127,11 @@ jobs:
paths:
- /usr/local/cargo/registry
- target
key: cargocache-minter-rust:1.64.0-{{ checksum "~/project/Cargo.lock" }}
key: cargocache-minter-rust:1.68.0-{{ checksum "~/project/Cargo.lock" }}

contract_whitelist:
docker:
- image: rust:1.64.0
- image: rust:1.68.0
working_directory: ~/project/contracts/whitelist
steps:
- checkout:
Expand All @@ -141,7 +141,7 @@ jobs:
command: rustc --version; cargo --version; rustup --version
- restore_cache:
keys:
- cargocache-whitelist-rust:1.64.0-{{ checksum "~/project/Cargo.lock" }}
- cargocache-whitelist-rust:1.68.0-{{ checksum "~/project/Cargo.lock" }}
- run:
name: Unit Tests
environment:
Expand All @@ -163,11 +163,11 @@ jobs:
paths:
- /usr/local/cargo/registry
- target
key: cargocache-whitelist-rust:1.64.0-{{ checksum "~/project/Cargo.lock" }}
key: cargocache-whitelist-rust:1.68.0-{{ checksum "~/project/Cargo.lock" }}

contract_royalty_group:
docker:
- image: rust:1.64.0
- image: rust:1.68.0
working_directory: ~/project/contracts/royalty-group
steps:
- checkout:
Expand All @@ -177,7 +177,7 @@ jobs:
command: rustc --version; cargo --version; rustup --version
- restore_cache:
keys:
- cargocache-royalty-rust:1.64.0-{{ checksum "~/project/Cargo.lock" }}
- cargocache-royalty-rust:1.68.0-{{ checksum "~/project/Cargo.lock" }}
- run:
name: Unit Tests
environment:
Expand All @@ -199,11 +199,11 @@ jobs:
paths:
- /usr/local/cargo/registry
- target
key: cargocache-royalty-rust:1.64.0-{{ checksum "~/project/Cargo.lock" }}
key: cargocache-royalty-rust:1.68.0-{{ checksum "~/project/Cargo.lock" }}

package_sg_std:
docker:
- image: rust:1.64.0
- image: rust:1.68.0
working_directory: ~/project/package/sg-std
steps:
- checkout:
Expand All @@ -213,7 +213,7 @@ jobs:
command: rustc --version; cargo --version; rustup --version
- restore_cache:
keys:
- cargocache-sg-std-rust:1.64.0-{{ checksum "~/project/Cargo.lock" }}
- cargocache-sg-std-rust:1.68.0-{{ checksum "~/project/Cargo.lock" }}
- run:
name: Unit Tests
environment:
Expand All @@ -223,11 +223,11 @@ jobs:
paths:
- /usr/local/cargo/registry
- target
key: cargocache-sg-std-rust:1.64.0-{{ checksum "~/project/Cargo.lock" }}
key: cargocache-sg-std-rust:1.68.0-{{ checksum "~/project/Cargo.lock" }}

package_sg_utils:
docker:
- image: rust:1.64.0
- image: rust:1.68.0
working_directory: ~/project/package/sg-utils
steps:
- checkout:
Expand All @@ -237,7 +237,7 @@ jobs:
command: rustc --version; cargo --version; rustup --version
- restore_cache:
keys:
- cargocache-sg-utils-rust:1.64.0-{{ checksum "~/project/Cargo.lock" }}
- cargocache-sg-utils-rust:1.68.0-{{ checksum "~/project/Cargo.lock" }}
- run:
name: Unit Tests
environment:
Expand All @@ -247,19 +247,19 @@ jobs:
paths:
- /usr/local/cargo/registry
- target
key: cargocache-sg-utils-rust:1.64.0-{{ checksum "~/project/Cargo.lock" }}
key: cargocache-sg-utils-rust:1.68.0-{{ checksum "~/project/Cargo.lock" }}

lint:
docker:
- image: rust:1.64.0
- image: rust:1.68.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.64.0-{{ checksum "Cargo.lock" }}
- cargocache-v2-lint-rust:1.68.0-{{ checksum "Cargo.lock" }}
- run:
name: Add rustfmt component
command: rustup component add rustfmt
Expand All @@ -278,15 +278,15 @@ jobs:
- target/debug/.fingerprint
- target/debug/build
- target/debug/deps
key: cargocache-v2-lint-rust:1.64.0-{{ checksum "Cargo.lock" }}
key: cargocache-v2-lint-rust:1.68.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.64.0
- image: rust:1.68.0
steps:
- checkout:
path: ~/project
Expand All @@ -295,7 +295,7 @@ jobs:
command: rustc --version; cargo --version; rustup --version
- restore_cache:
keys:
- cargocache-wasm-rust:1.64.0-{{ checksum "~/project/Cargo.lock" }}
- cargocache-wasm-rust:1.68.0-{{ checksum "~/project/Cargo.lock" }}
- run:
name: Add wasm32 target
command: rustup target add wasm32-unknown-unknown
Expand All @@ -315,7 +315,7 @@ jobs:
paths:
- /usr/local/cargo/registry
- target
key: cargocache-wasm-rust:1.64.0-{{ checksum "~/project/Cargo.lock" }}
key: cargocache-wasm-rust:1.68.0-{{ checksum "~/project/Cargo.lock" }}
- run:
name: Check wasm contracts
command: |
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

101 changes: 68 additions & 33 deletions contracts/minter/src/contract_updatable_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1538,7 +1538,10 @@ fn test_update_none_royalties() {

assert_eq!(
err.source().unwrap().to_string(),
sg721_updatable::ContractError::RoyaltyShareIncreasedTooMuch {}.to_string()
sg721_updatable::ContractError::InvalidRoyalties(
"Share percentage cannot be greater than 10%".to_string()
)
.to_string()
);

let update_royalty_msg: Sg721UpdatableExecuteMsg<Extension> =
Expand All @@ -1547,6 +1550,29 @@ fn test_update_none_royalties() {
share_bps: 400,
};

let res = router.execute_contract(
creator.clone(),
Addr::unchecked(sg71_address.clone()),
&update_royalty_msg,
&[],
);

let err = res.unwrap_err();

assert_eq!(
err.source().unwrap().to_string(),
sg721_updatable::ContractError::InvalidRoyalties(
"Share increase cannot be greater than 2%".to_string()
)
.to_string()
);

let update_royalty_msg: Sg721UpdatableExecuteMsg<Extension> =
Sg721UpdatableExecuteMsg::UpdateRoyaltyInfo {
payment_address: "creator2".to_string(),
share_bps: 100,
};

let res = router
.execute_contract(
creator.clone(),
Expand All @@ -1563,7 +1589,7 @@ fn test_update_none_royalties() {
assert_eq!(res.events[1].attributes[2].key, "payment_address");
assert_eq!(res.events[1].attributes[2].value, "creator2");
assert_eq!(res.events[1].attributes[3].key, "share");
assert_eq!(res.events[1].attributes[3].value, "0.04");
assert_eq!(res.events[1].attributes[3].value, "0.01");

let update_royalty_msg: Sg721UpdatableExecuteMsg<Extension> =
Sg721UpdatableExecuteMsg::UpdateRoyaltyInfo {
Expand All @@ -1586,6 +1612,29 @@ fn test_update_none_royalties() {

setup_block_time(&mut router, GENESIS_MINT_START_TIME + 86400000000000);

let res = router.execute_contract(
creator.clone(),
Addr::unchecked(sg71_address.clone()),
&update_royalty_msg,
&[],
);

let err = res.unwrap_err();

assert_eq!(
err.source().unwrap().to_string(),
sg721_updatable::ContractError::InvalidRoyalties(
"Share increase cannot be greater than 2%".to_string()
)
.to_string()
);

let update_royalty_msg: Sg721UpdatableExecuteMsg<Extension> =
Sg721UpdatableExecuteMsg::UpdateRoyaltyInfo {
payment_address: "creator2".to_string(),
share_bps: 200,
};

let res = router
.execute_contract(
creator.clone(),
Expand All @@ -1602,9 +1651,9 @@ fn test_update_none_royalties() {
assert_eq!(res.events[1].attributes[2].key, "payment_address");
assert_eq!(res.events[1].attributes[2].value, "creator2");
assert_eq!(res.events[1].attributes[3].key, "share");
assert_eq!(res.events[1].attributes[3].value, "0.05");
assert_eq!(res.events[1].attributes[3].value, "0.02");

setup_block_time(&mut router, GENESIS_MINT_START_TIME + 86500000000000);
setup_block_time(&mut router, GENESIS_MINT_START_TIME + 186500000000000);

let update_royalty_msg: Sg721UpdatableExecuteMsg<Extension> =
Sg721UpdatableExecuteMsg::UpdateRoyaltyInfo {
Expand Down Expand Up @@ -1699,13 +1748,16 @@ fn test_update_royalties() {

assert_eq!(
err.source().unwrap().to_string(),
sg721_updatable::ContractError::RoyaltyShareIncreasedTooMuch {}.to_string()
sg721_updatable::ContractError::InvalidRoyalties(
"Share percentage cannot be greater than 10%".to_string()
)
.to_string()
);

let update_royalty_msg: sg721_updatable::msg::ExecuteMsg<Extension> =
sg721_updatable::msg::ExecuteMsg::UpdateRoyaltyInfo {
payment_address: "creator2".to_string(),
share_bps: 900,
share_bps: 200,
};
let res = router.execute_contract(
creator.clone(),
Expand All @@ -1731,12 +1783,12 @@ fn test_update_royalties() {
);
assert!(res.is_ok());

setup_block_time(&mut router, GENESIS_MINT_START_TIME + 86500000000000);
setup_block_time(&mut router, GENESIS_MINT_START_TIME + 186500000000000);

let update_royalty_msg: sg721_updatable::msg::ExecuteMsg<Extension> =
sg721_updatable::msg::ExecuteMsg::UpdateRoyaltyInfo {
payment_address: "creator2".to_string(),
share_bps: 800,
share_bps: 300,
};
let res = router.execute_contract(
creator,
Expand Down Expand Up @@ -1860,7 +1912,7 @@ fn try_migrate() {
);

// // no op when same version
set_contract_version(&mut deps.storage, "crates.io:sg-721", "0.8.4").unwrap();
set_contract_version(&mut deps.storage, "crates.io:sg-721", "0.8.5").unwrap();
sg721_updatable::contract::migrate(deps.as_mut(), env, Empty {}).unwrap();

// Migration happy path
Expand Down Expand Up @@ -1915,29 +1967,12 @@ fn try_migrate() {

let sg721_base_address = config.sg721_address;

let collection_info: CollectionInfo<sg721_updatable::msg::RoyaltyInfoResponse> = router
.wrap()
.query_wasm_smart(
sg721_base_address.clone(),
&sg721::msg::QueryMsg::CollectionInfo {},
)
.unwrap();

assert!(collection_info.royalty_info.unwrap().updated_at.is_none());

router
.migrate_contract(
creator,
Addr::unchecked(sg721_base_address.clone()),
&Empty {},
sg721_code_id,
)
.unwrap();

let collection_info: CollectionInfo<sg721_updatable::msg::RoyaltyInfoResponse> = router
.wrap()
.query_wasm_smart(sg721_base_address, &sg721::msg::QueryMsg::CollectionInfo {})
.unwrap();
let res = router.migrate_contract(
creator,
Addr::unchecked(sg721_base_address),
&Empty {},
sg721_code_id,
);

assert!(collection_info.royalty_info.unwrap().updated_at.is_some(),);
assert!(res.is_ok());
}
Loading

0 comments on commit 2a10b3a

Please sign in to comment.