Skip to content

Commit

Permalink
Basic Integration Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeHartnell committed Dec 29, 2023
1 parent a3a8243 commit 9a5881c
Show file tree
Hide file tree
Showing 16 changed files with 1,084 additions and 24 deletions.
9 changes: 9 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ cw-wormhole = { path = "./packages/cw-wormhole", version = "2.4.0" }
cw20-stake = { path = "./contracts/staking/cw20-stake", version = "2.4.0" }
cw721-controllers = { path = "./packages/cw721-controllers", version = "2.4.0" }
cw721-roles = { path = "./contracts/external/cw721-roles", version = "2.4.0" }
dao-abc-factory = { path = "/contracts/external/dao-abc-factory", version = "*" }
dao-abc-factory = { path = "./contracts/external/dao-abc-factory", version = "*" }
dao-cw721-extensions = { path = "./packages/dao-cw721-extensions", version = "2.4.0" }
dao-dao-core = { path = "./contracts/dao-dao-core", version = "2.4.0" }
dao-dao-macros = { path = "./packages/dao-dao-macros", version = "2.4.0" }
Expand Down
5 changes: 2 additions & 3 deletions contracts/external/cw-abc/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,11 @@ pub fn instantiate(
// Initialize owner to sender
cw_ownable::initialize_owner(deps.storage, deps.api, Some(info.sender.as_str()))?;

// TODO Potential renounce admin?
// Tnstantiate cw-token-factory-issuer contract
// Sender is set as contract admin
// Contract is immutable, no admin
let issuer_instantiate_msg = SubMsg::reply_always(
WasmMsg::Instantiate {
admin: Some(info.sender.to_string()),
admin: None,
code_id: token_issuer_code_id,
msg: to_json_binary(&IssuerInstantiateMsg::NewToken {
subdenom: supply.subdenom.clone(),
Expand Down
14 changes: 14 additions & 0 deletions contracts/external/dao-abc-factory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ crate-type = ["cdylib", "rlib"]
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 @@ -32,4 +37,13 @@ dao-voting = { workspace = true }
cw-tokenfactory-issuer = { workspace = true, features = ["library"] }

[dev-dependencies]
anyhow = { workspace = true }
cw-multi-test = { workspace = true }
cw-tokenfactory-issuer = { workspace = true }
dao-proposal-single = { workspace = true }
dao-proposal-hook-counter = { workspace = true }
dao-testing = { workspace = true, features = ["test-tube"] }
dao-voting-token-staked = { workspace = true }
osmosis-std = { workspace = true }
osmosis-test-tube = { workspace = true }
serde = { workspace = true }
18 changes: 16 additions & 2 deletions contracts/external/dao-abc-factory/schema/dao-abc-factory.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,28 @@
"title": "ExecuteMsg",
"oneOf": [
{
"description": "Example Factory Implementation",
"type": "object",
"required": [
"abc_factory"
],
"properties": {
"abc_factory": {
"$ref": "#/definitions/InstantiateMsg"
"type": "object",
"required": [
"code_id",
"instantiate_msg"
],
"properties": {
"code_id": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
},
"instantiate_msg": {
"$ref": "#/definitions/InstantiateMsg"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
Expand Down
69 changes: 55 additions & 14 deletions contracts/external/dao-abc-factory/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
to_json_binary, Addr, Binary, Deps, DepsMut, Empty, Env, MessageInfo, Order, Reply, Response,
StdResult, SubMsg, WasmMsg,
to_json_binary, Addr, Binary, CosmosMsg, Deps, DepsMut, Empty, Env, MessageInfo, Order, Reply,
Response, StdResult, SubMsg, WasmMsg,
};
use cw2::set_contract_version;
use cw_abc::msg::{InstantiateMsg as AbcInstantiateMsg, QueryMsg as AbcQueryMsg};
use cw_abc::msg::{
DenomResponse, ExecuteMsg as AbcExecuteMsg, InstantiateMsg as AbcInstantiateMsg,
QueryMsg as AbcQueryMsg,
};
use cw_storage_plus::{Bound, Item, Map};
use cw_utils::parse_reply_instantiate_data;
use dao_interface::{token::TokenFactoryCallback, voting::Query as VotingModuleQueryMsg};
use dao_interface::{
state::ModuleInstantiateCallback, token::TokenFactoryCallback,
voting::Query as VotingModuleQueryMsg,
};

use crate::{
error::ContractError,
Expand All @@ -21,6 +27,7 @@ const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
const INSTANTIATE_ABC_REPLY_ID: u64 = 1;

const DAOS: Map<Addr, Empty> = Map::new("daos");
const CURRENT_DAO: Item<Addr> = Item::new("current_dao");
const VOTING_MODULE: Item<Addr> = Item::new("voting_module");

#[cfg_attr(not(feature = "library"), entry_point)]
Expand All @@ -43,14 +50,18 @@ pub fn execute(
msg: ExecuteMsg,
) -> Result<Response, ContractError> {
match msg {
ExecuteMsg::AbcFactory(msg) => execute_token_factory_factory(deps, env, info, msg),
ExecuteMsg::AbcFactory {
code_id,
instantiate_msg,
} => execute_token_factory_factory(deps, env, info, code_id, instantiate_msg),
}
}

pub fn execute_token_factory_factory(
deps: DepsMut,
_env: Env,
info: MessageInfo,
code_id: u64,
msg: AbcInstantiateMsg,
) -> Result<Response, ContractError> {
// Save voting module address
Expand All @@ -61,15 +72,16 @@ pub fn execute_token_factory_factory(
.querier
.query_wasm_smart(info.sender, &VotingModuleQueryMsg::Dao {})?;

DAOS.save(deps.storage, dao, &Empty {})?;
DAOS.save(deps.storage, dao.clone(), &Empty {})?;
CURRENT_DAO.save(deps.storage, &dao)?;

// Instantiate new contract, further setup is handled in the
// SubMsg reply.
let msg = SubMsg::reply_on_success(
WasmMsg::Instantiate {
// No admin as we want the bonding curve contract to be immutable
admin: None,
code_id: msg.token_issuer_code_id,
code_id,
msg: to_json_binary(&msg)?,
funds: vec![],
label: "cw_abc".to_string(),
Expand Down Expand Up @@ -118,11 +130,14 @@ pub fn query_daos(
pub fn reply(deps: DepsMut, _env: Env, msg: Reply) -> Result<Response, ContractError> {
match msg.id {
INSTANTIATE_ABC_REPLY_ID => {
// Load DAO
let dao = CURRENT_DAO.load(deps.storage)?;

// Parse issuer address from instantiate reply
let abc_addr = parse_reply_instantiate_data(msg)?.contract_address;

// Query for denom
let denom = deps
let denom: DenomResponse = deps
.querier
.query_wasm_smart(abc_addr.clone(), &AbcQueryMsg::Denom {})?;

Expand All @@ -131,15 +146,41 @@ pub fn reply(deps: DepsMut, _env: Env, msg: Reply) -> Result<Response, ContractE
.querier
.query_wasm_smart(abc_addr.clone(), &AbcQueryMsg::TokenContract {})?;

// Update the owner to be the DAO
let msg = WasmMsg::Execute {
contract_addr: abc_addr.clone(),
msg: to_json_binary(&AbcExecuteMsg::UpdateOwnership(
cw_ownable::Action::TransferOwnership {
new_owner: dao.to_string(),
expiry: None,
},
))?,
funds: vec![],
};

// DAO must accept ownership transfer. Here we include a
// ModuleInstantiateCallback message that will be called by the
// dao-dao-core contract when voting module instantiation is
// complete.
let callback = ModuleInstantiateCallback {
msgs: vec![CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: abc_addr.clone(),
msg: to_json_binary(&AbcExecuteMsg::UpdateOwnership(
cw_ownable::Action::AcceptOwnership {},
))?,
funds: vec![],
})],
};

// Responses for `dao-voting-token-staked` MUST include a
// TokenFactoryCallback.
Ok(
Response::new().set_data(to_json_binary(&TokenFactoryCallback {
denom,
Ok(Response::new()
.add_message(msg)
.set_data(to_json_binary(&TokenFactoryCallback {
denom: denom.denom,
token_contract: Some(token_contract.to_string()),
module_instantiate_callback: None,
})?),
)
module_instantiate_callback: Some(callback),
})?))
}
_ => Err(ContractError::UnknownReplyId { id: msg.id }),
}
Expand Down
3 changes: 3 additions & 0 deletions contracts/external/dao-abc-factory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ mod error;
pub mod msg;

pub use crate::error::ContractError;

#[cfg(test)]
mod test_tube;
6 changes: 4 additions & 2 deletions contracts/external/dao-abc-factory/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ pub struct InstantiateMsg {}

#[cw_serde]
pub enum ExecuteMsg {
/// Example Factory Implementation
AbcFactory(AbcInstantiateMsg),
AbcFactory {
instantiate_msg: AbcInstantiateMsg,
code_id: u64,
},
}

#[cw_serde]
Expand Down
Loading

0 comments on commit 9a5881c

Please sign in to comment.