forked from DA0-DA0/dao-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
hard-nett
committed
Jul 9, 2024
1 parent
24bb87c
commit 2f94dba
Showing
11 changed files
with
432 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[package] | ||
name = "test-suite" | ||
authors = [""] | ||
description = "A package for test coverage of DAO DAO contracts." | ||
edition = { workspace = true } | ||
license = { workspace = true } | ||
repository = { workspace = true } | ||
version = { workspace = true } | ||
|
||
[dependencies] | ||
cosmwasm-std = { workspace = true } | ||
cosmwasm-schema = { workspace = true } | ||
cw2 = { workspace = true } | ||
cw20 = { workspace = true } | ||
cw721 = { workspace = true } | ||
cw-utils = { workspace = true } | ||
gauge-adapter = { workspace = true } | ||
cw-orch = { workspace = true } | ||
cw-orch-core = { workspace = true } | ||
dao-cw-orch = { version = "2.4.2", path = "../packages/cw-orch" } | ||
abstract-cw-plus-interface = "2.0.1" | ||
abstract-cw20 = "2.0.0" | ||
abstract-cw20-base = "2.0.0" | ||
|
||
[dev-dependencies] | ||
cosmwasm-schema = { workspace = true } |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
mod adapter; | ||
// mod orchestrator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod test; | ||
pub mod helpers; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
use std::ptr::eq; | ||
|
||
use abstract_cw20::{Cw20Coin as AbsCw20Coin, MinterResponse}; | ||
use abstract_cw_plus_interface::cw20_base::Cw20Base; | ||
use cosmwasm_schema::cw_serde; | ||
use cosmwasm_std::{coin, Addr, Coin, Uint128}; | ||
use cw20::Cw20Coin; | ||
use cw_orch::{ | ||
contract::interface_traits::{CwOrchExecute, CwOrchInstantiate, CwOrchUpload}, | ||
environment::IndexResponse, | ||
mock::{cw_multi_test::AppResponse, MockBech32}, | ||
prelude::TxHandler, | ||
}; | ||
use cw_orch_core::CwEnvError; | ||
use dao_cw_orch::GaugeAdapter; | ||
use gauge_adapter::{ | ||
msg::{AdapterQueryMsgFns, InstantiateMsg}, | ||
state::{AssetInfo, Config}, | ||
}; | ||
|
||
pub const DEFAULT_AMOUNT: u128 = 1_000u128; | ||
pub const NATIVE: &str = "juno"; | ||
pub const CW20_ADDR: &str = "cw20-contract"; | ||
pub const COMMUNITY_POOL: &str = "mock1fawgu2qh6zu8j5e5t83fvwr0lxdp200mjkh8j5aguytl6x7qs2lsyx2wfn"; | ||
|
||
pub fn create_gauge_helpers( | ||
mock: MockBech32, | ||
gauge_adapter: GaugeAdapter<MockBech32>, | ||
required_deposit: Option<AssetInfo>, | ||
reward: AssetInfo, | ||
) { | ||
gauge_adapter.upload().unwrap(); | ||
let admin = mock.sender().to_string(); | ||
let community_pool = mock.addr_make("commuity-pool").to_string(); | ||
let instantiate = InstantiateMsg { | ||
admin: admin.clone(), | ||
required_deposit, | ||
community_pool, | ||
reward: reward.clone(), | ||
}; | ||
gauge_adapter.instantiate(&instantiate, None, None).unwrap(); | ||
} | ||
pub fn setup_default_accounts(mock: MockBech32) { | ||
let default_amt = coin(100_000, "juno"); | ||
mock.addr_make_with_balance("owner", [default_amt.clone()].to_vec()) | ||
.unwrap(); | ||
mock.addr_make_with_balance("einstein", [default_amt.clone()].to_vec()) | ||
.unwrap(); | ||
mock.add_balance(&mock.sender, [default_amt.clone()].to_vec()) | ||
.unwrap(); | ||
} | ||
|
||
// creates default testing environment for GaugeAdapter. | ||
pub fn create_default( | ||
mock: MockBech32, | ||
required_deposit: Option<AssetInfo>, | ||
) -> (GaugeAdapter<MockBech32>) { | ||
// create new gauge adapter inside simulation | ||
let gauge_adapter = GaugeAdapter::new("gauge_adapter", mock.clone()); | ||
// create default acccounts | ||
setup_default_accounts(mock.clone()); | ||
|
||
// default simulation reward | ||
let reward = AssetInfo::Native(Coin { | ||
denom: "juno".to_string(), | ||
amount: Uint128::new(1_000_000u128), | ||
}); | ||
|
||
match required_deposit.clone() { | ||
Some(required) => match required { | ||
AssetInfo::Cw20(coin) => { | ||
create_gauge_helpers( | ||
mock.clone(), | ||
gauge_adapter.clone(), | ||
Some(AssetInfo::Cw20(Cw20Coin { | ||
address: coin.address, | ||
amount: coin.amount, | ||
})), | ||
reward.clone(), | ||
); | ||
} | ||
AssetInfo::Native(token) => { | ||
create_gauge_helpers( | ||
mock.clone(), | ||
gauge_adapter.clone(), | ||
Some(AssetInfo::Native(token)), | ||
reward.clone(), | ||
); | ||
} | ||
}, | ||
None => { | ||
create_gauge_helpers(mock.clone(), gauge_adapter.clone(), None, reward.clone()); | ||
} | ||
}; | ||
|
||
let state = gauge_adapter.clone().config().unwrap(); | ||
|
||
(gauge_adapter) | ||
} | ||
|
||
// | ||
pub fn create_native_submission_helper( | ||
gauge: GaugeAdapter<MockBech32>, | ||
sender: Addr, | ||
native_tokens: Option<Coin>, | ||
) -> Result<AppResponse, CwEnvError> { | ||
if let Some(assets) = native_tokens.clone() { | ||
let assets_info = AssetInfo::Native(assets.clone()); | ||
let res = gauge.execute( | ||
&gauge_adapter::msg::ExecuteMsg::CreateSubmission { | ||
name: "DAOers".to_string(), | ||
url: "https://daodao.zone".to_string(), | ||
address: sender.to_string(), | ||
assets: Some(assets_info.clone()), | ||
}, | ||
Some(&[assets]), | ||
); | ||
res | ||
} else { | ||
let res = gauge.execute( | ||
&gauge_adapter::msg::ExecuteMsg::CreateSubmission { | ||
name: "DAOers".to_string(), | ||
url: "https://daodao.zone".to_string(), | ||
address: sender.to_string(), | ||
assets: None, | ||
}, | ||
None, | ||
); | ||
res | ||
} | ||
} | ||
|
||
pub fn cw20_helper(mock: MockBech32) -> (Cw20Base<MockBech32>, Addr) { | ||
let cw20 = Cw20Base::new("cw20", mock.clone()); | ||
let cw20_code_id = cw20.upload().unwrap().uploaded_code_id().unwrap(); | ||
let res = init_cw20(cw20.clone(), cw20_code_id, mock.sender.to_string()); | ||
(cw20, Addr::unchecked(res)) | ||
} | ||
|
||
pub fn init_cw20(mock: Cw20Base<MockBech32>, code_id: u64, minter: String) -> String { | ||
let init_msg = abstract_cw20_base::msg::InstantiateMsg { | ||
name: "test".to_string(), | ||
symbol: "TEST".to_string(), | ||
decimals: 6u8, | ||
initial_balances: vec![AbsCw20Coin { | ||
address: minter.clone(), | ||
amount: Uint128::from(1_000_000u128), | ||
}], | ||
mint: Some(MinterResponse { minter, cap: None }), | ||
marketing: None, | ||
}; | ||
let res = mock.instantiate(&init_msg, None, None).unwrap(); | ||
println!("{:#?}", res); | ||
let addr = res | ||
.event_attr_value("instantiate", "_contract_address") | ||
.unwrap(); | ||
addr | ||
} |
Oops, something went wrong.