Skip to content

Commit

Permalink
Add integration tests for dao-voting-cw721-staked
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeHartnell committed Oct 3, 2023
1 parent 017b9d4 commit ced780c
Show file tree
Hide file tree
Showing 7 changed files with 635 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Cargo.lock

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

15 changes: 14 additions & 1 deletion contracts/voting/dao-voting-cw721-staked/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@ 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 = []
# use test tube feature to enable test-tube integration tests, for example
# cargo test --features "test-tube"
test-tube = []
# when writing tests you may wish to enable test-tube as a default feature
default = ["test-tube"]


[dependencies]
cosmwasm-std = { workspace = true }
Expand All @@ -35,5 +43,10 @@ thiserror = { workspace = true }
[dev-dependencies]
anyhow = { workspace = true }
cw-multi-test = { workspace = true }
dao-testing = { workspace = true }
dao-proposal-single = { workspace = true }
dao-proposal-hook-counter = { workspace = true }
dao-test-custom-factory = { workspace = true }
dao-testing = { workspace = true, features = ["test-tube"] }
osmosis-std = { workpsace = true }
osmosis-test-tube = { workspace = true }
serde = { workspace = true }
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
use cosmwasm_std::{to_binary, Addr, Coin, Decimal, Empty, Uint128, WasmMsg};
use cw721_base::{
msg::{
ExecuteMsg as Cw721ExecuteMsg, InstantiateMsg as Cw721InstantiateMsg,
QueryMsg as Cw721QueryMsg,
},
MinterResponse,
};
use cw_utils::Duration;
use dao_interface::{
msg::QueryMsg as DaoQueryMsg,
state::{Admin, ModuleInstantiateInfo},
};
use dao_testing::test_tube::{cw721_base::Cw721Base, dao_dao_core::DaoCore};
use dao_voting::{
pre_propose::PreProposeInfo,
threshold::{ActiveThreshold, PercentageThreshold, Threshold},
};
use osmosis_test_tube::{Account, OsmosisTestApp, RunnerError};

use crate::{
msg::{InstantiateMsg, NftContract, QueryMsg},
state::Config,
testing::test_tube_env::Cw721VotingContract,
};

use super::test_tube_env::{TestEnv, TestEnvBuilder};

#[test]
fn test_full_integration_with_factory() {
let app = OsmosisTestApp::new();
let env = TestEnvBuilder::new();

// Setup defaults to creating a NFT DAO with the factory contract
// This does not use funds when instantiating the NFT contract.
// We will test that below.
let TestEnv {
vp_contract,
proposal_single,
custom_factory,
accounts,
cw721,
..
} = env.setup(&app);

// Test instantiating a DAO with a factory contract that requires funds
let msg = dao_interface::msg::InstantiateMsg {
dao_uri: None,
admin: None,
name: "DAO DAO".to_string(),
description: "A DAO that makes DAO tooling".to_string(),
image_url: None,
automatically_add_cw20s: false,
automatically_add_cw721s: false,
voting_module_instantiate_info: ModuleInstantiateInfo {
code_id: vp_contract.code_id,
msg: to_binary(&InstantiateMsg {
nft_contract: NftContract::Factory(
to_binary(&WasmMsg::Execute {
contract_addr: custom_factory.contract_addr.clone(),
msg: to_binary(
&dao_test_custom_factory::msg::ExecuteMsg::NftFactoryWithFunds {
code_id: cw721.code_id,
cw721_instantiate_msg: Cw721InstantiateMsg {
name: "Test NFT".to_string(),
symbol: "TEST".to_string(),
minter: accounts[0].address(),
},
initial_nfts: vec![to_binary(
&Cw721ExecuteMsg::<Empty, Empty>::Mint {
owner: accounts[0].address(),
token_uri: Some("https://example.com".to_string()),
token_id: "1".to_string(),
extension: Empty {},
},
)
.unwrap()],
},
)
.unwrap(),
funds: vec![Coin {
amount: Uint128::new(1000),
denom: "uosmo".to_string(),
}],
})
.unwrap(),
),
unstaking_duration: None,
active_threshold: Some(ActiveThreshold::Percentage {
percent: Decimal::percent(1),
}),
})
.unwrap(),
admin: Some(Admin::CoreModule {}),
funds: vec![Coin {
amount: Uint128::new(1000),
denom: "uosmo".to_string(),
}],
label: "DAO DAO Voting Module".to_string(),
},
proposal_modules_instantiate_info: vec![ModuleInstantiateInfo {
code_id: proposal_single.code_id,
msg: to_binary(&dao_proposal_single::msg::InstantiateMsg {
min_voting_period: None,
threshold: Threshold::ThresholdQuorum {
threshold: PercentageThreshold::Majority {},
quorum: PercentageThreshold::Percent(Decimal::percent(35)),
},
max_voting_period: Duration::Time(432000),
allow_revoting: false,
only_members_execute: true,
close_proposal_on_execution_failure: false,
pre_propose_info: PreProposeInfo::AnyoneMayPropose {},
})
.unwrap(),
admin: Some(Admin::CoreModule {}),
funds: vec![],
label: "DAO DAO Proposal Module".to_string(),
}],
initial_items: None,
};

// Instantiating without funds fails
let err = DaoCore::new(&app, &msg, &accounts[0], &[]).unwrap_err();

// Error is insufficient funds as no funds were sent
assert_eq!(
RunnerError::ExecuteError {
msg: "failed to execute message; message index: 0: dispatch: submessages: 0uosmo is smaller than 1000uosmo: insufficient funds".to_string()
},
err
);

// Instantiate DAO succeeds with funds
let dao = DaoCore::new(
&app,
&msg,
&accounts[0],
&[Coin {
amount: Uint128::new(1000),
denom: "uosmo".to_string(),
}],
)
.unwrap();

let vp_addr: Addr = dao.query(&DaoQueryMsg::VotingModule {}).unwrap();
let vp_contract =
Cw721VotingContract::new_with_values(&app, vp_contract.code_id, vp_addr.to_string())
.unwrap();

let vp_config: Config = vp_contract.query(&QueryMsg::Config {}).unwrap();
let cw721_contract =
Cw721Base::new_with_values(&app, cw721.code_id, vp_config.nft_address.to_string()).unwrap();

// Check DAO was initialized to minter
let minter: MinterResponse = cw721_contract.query(&Cw721QueryMsg::Minter {}).unwrap();
assert_eq!(minter.minter, Some(dao.contract_addr.to_string()));
}
10 changes: 10 additions & 0 deletions contracts/voting/dao-voting-cw721-staked/src/testing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ mod instantiate;
mod queries;
mod tests;

// Integrationg tests using an actual chain binary, requires
// the "test-tube" feature to be enabled
// cargo test --features test-tube
#[cfg(test)]
#[cfg(feature = "test-tube")]
mod integration_tests;
#[cfg(test)]
#[cfg(feature = "test-tube")]
mod test_tube_env;

use cosmwasm_std::Addr;
use cw_multi_test::{App, Executor};
use cw_utils::Duration;
Expand Down
Loading

0 comments on commit ced780c

Please sign in to comment.