Skip to content

Commit

Permalink
Audit fixups and improvements related to factories
Browse files Browse the repository at this point in the history
- Extends dao-test-custom-factory to mint NFTs
- Validate ActiveThreshold in NFT factory test contract
- Add ModuleInstantiateCallback to nft factory call backs
- Fix transfer ownership in factory test contract
- Add ModuleInstantiateCallback to nft factory callbacks
- Test ownership set correctly in token factory factory
- Test for module instantiate callback in NFT factory
- Include note that custom factory contracts MUST handle validation logic

The most important change here is the that both
`dao-voting-cw721-staked` and `dao-voting-token-staked` implement
ModuleInstantiateCallback now, which allows for more complicated setup possibilities.
  • Loading branch information
JakeHartnell committed Sep 29, 2023
1 parent ac38d6e commit 6da90ef
Show file tree
Hide file tree
Showing 15 changed files with 374 additions and 21 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions ci/integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dao-dao-core = { workspace = true }
dao-interface = { workspace = true }
dao-pre-propose-single = { workspace = true }
dao-proposal-single = { workspace = true }
dao-test-custom-factory = { workspace = true }
dao-voting = { workspace = true }
dao-voting-cw20-staked = { workspace = true }
dao-voting-cw721-staked = { workspace = true }
Expand Down
148 changes: 145 additions & 3 deletions ci/integration-tests/src/tests/dao_voting_cw721_staked_test.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
use cosm_orc::config::cfg::Config;
use cosm_orc::orchestrator::{ExecReq, SigningKey};
use cosmwasm_std::{Binary, Empty, Uint128};
use cosm_tome::chain::coin::Coin;
use cosmwasm_std::{to_binary, Binary, Decimal, Empty, Uint128, WasmMsg};
use cw721_base::msg::{ExecuteMsg as Cw721ExecuteMsg, InstantiateMsg as Cw721InstantiateMsg};
use cw_utils::Duration;
use test_context::test_context;

use dao_interface::state::{Admin, ModuleInstantiateInfo};
use dao_voting::{
deposit::{DepositRefundPolicy, DepositToken, UncheckedDepositInfo},
pre_propose::PreProposeInfo,
threshold::{PercentageThreshold, Threshold},
};
use dao_voting_cw721_staked as module;
use std::env;
use test_context::test_context;

use crate::helpers::chain::Chain;

Expand Down Expand Up @@ -265,3 +274,136 @@ fn cw721_stake_max_claims_works(chain: &mut Chain) {
// NFTs get returned as a result of this.
claim_nfts(chain, &user_key);
}

#[test_context(Chain)]
#[test]
#[ignore]
fn full_integration_test(chain: &mut Chain) {
let user_addr = chain.users["user1"].account.address.clone();
let user_key = chain.users["user1"].key.clone();

let config = env::var("CONFIG").expect("missing yaml CONFIG env var");
let cfg = Config::from_yaml(&config).unwrap();

let factory_addr: String = chain
.orc
.instantiate(
"dao_test_custom_factory",
"instantiate_dao_voting_cw721_staked",
&dao_test_custom_factory::msg::InstantiateMsg {},
&user_key,
None,
vec![],
)
.unwrap()
.address
.into();

let msg = dao_interface::msg::InstantiateMsg {
admin: Some(user_addr.clone()),
name: "DAO DAO".to_string(),
description: "A DAO that makes DAO tooling".to_string(),
image_url: Some("https://zmedley.com/raw_logo.png".to_string()),
dao_uri: None,
automatically_add_cw20s: false,
automatically_add_cw721s: false,
voting_module_instantiate_info: ModuleInstantiateInfo {
code_id: chain
.orc
.contract_map
.code_id("dao_voting_cw721_staked")
.unwrap(),
msg: to_binary(&module::msg::InstantiateMsg {
nft_contract: module::msg::NftContract::Factory(
to_binary(&WasmMsg::Execute {
contract_addr: factory_addr.to_string(),
msg: to_binary(&dao_test_custom_factory::msg::ExecuteMsg::NftFactory {
code_id: chain.orc.contract_map.code_id("cw721_base").unwrap(),
cw721_instantiate_msg: Cw721InstantiateMsg {
name: "Test NFT".to_string(),
symbol: "TEST".to_string(),
minter: user_addr.clone(),
},
initial_nfts: vec![to_binary(&Cw721ExecuteMsg::<Empty, Empty>::Mint {
owner: user_addr.clone(),
token_uri: Some("https://example.com".to_string()),
token_id: "1".to_string(),
extension: Empty {},
})
.unwrap()],
})
.unwrap(),
funds: vec![],
})
.unwrap(),
),
unstaking_duration: Some(Duration::Height(3)),
active_threshold: None,
})
.unwrap(),
funds: vec![],
admin: Some(Admin::CoreModule {}),
label: "DAO DAO Voting Module".to_string(),
},
proposal_modules_instantiate_info: vec![ModuleInstantiateInfo {
code_id: chain
.orc
.contract_map
.code_id("dao_proposal_single")
.unwrap(),
msg: to_binary(&dao_proposal_single::msg::InstantiateMsg {
min_voting_period: None,
threshold: Threshold::ThresholdQuorum {
threshold: PercentageThreshold::Majority {},
quorum: PercentageThreshold::Percent(Decimal::percent(10)),
},
max_voting_period: cw_utils::Duration::Time(432000),
allow_revoting: false,
only_members_execute: true,
pre_propose_info: PreProposeInfo::ModuleMayPropose {
info: ModuleInstantiateInfo {
code_id: chain
.orc
.contract_map
.code_id("dao_pre_propose_single")
.unwrap(),
msg: to_binary(&dao_pre_propose_single::InstantiateMsg {
deposit_info: Some(UncheckedDepositInfo {
denom: DepositToken::VotingModuleToken {},
amount: Uint128::new(1000000000),
refund_policy: DepositRefundPolicy::OnlyPassed,
}),
open_proposal_submission: false,
extension: Empty::default(),
})
.unwrap(),
admin: Some(Admin::CoreModule {}),
funds: vec![],
label: "DAO DAO Pre-Propose Module".to_string(),
},
},
close_proposal_on_execution_failure: false,
})
.unwrap(),
admin: Some(Admin::CoreModule {}),
funds: vec![],
label: "DAO DAO Proposal Module".to_string(),
}],
initial_items: None,
};

chain
.orc
.instantiate(
"dao_dao_core",
"dao_init",
&msg,
&user_key,
Some(user_addr.parse().unwrap()),
vec![Coin {
denom: cfg.chain_cfg.denom.parse().unwrap(),
amount: 9000000,
}],
)
.unwrap();
}
1 change: 1 addition & 0 deletions contracts/test/dao-test-custom-factory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ cosmwasm-std = { workspace = true }
cosmwasm-schema = { workspace = true }
cosmwasm-storage = { workspace = true }
cw2 = { workspace = true }
cw721 = { workspace = true }
cw721-base = { workspace = true, features = ["library"] }
cw-ownable = { workspace = true }
cw-storage-plus = { workspace = true }
Expand Down
Loading

0 comments on commit 6da90ef

Please sign in to comment.