Skip to content

Commit

Permalink
cw-orch test suite for contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
hard-nett authored and Jake Hartnell committed Aug 14, 2024
1 parent c255d1e commit 0cc80ce
Show file tree
Hide file tree
Showing 21 changed files with 428 additions and 12 deletions.
4 changes: 2 additions & 2 deletions packages/cw-orch/src/distribution/cw_fund_distributor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use cw_fund_distributor::contract::{execute, instantiate, query};
use cw_fund_distributor::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};

#[interface(InstantiateMsg, ExecuteMsg, QueryMsg, Empty)]
pub struct CwFundDistributor;
pub struct DaoFundsDistributor;

impl<Chain> Uploadable for CwFundDistributor<Chain> {
impl<Chain> Uploadable for DaoFundsDistributor<Chain> {
/// Return the path to the wasm file corresponding to the contract
fn wasm(_chain: &ChainInfoOwned) -> WasmPath {
artifacts_dir_from_workspace!()
Expand Down
2 changes: 1 addition & 1 deletion packages/cw-orch/src/distribution/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod cw_fund_distributor;
mod dao_rewards_distributor;

pub use cw_fund_distributor::CwFundDistributor;
pub use cw_fund_distributor::DaoFundsDistributor;
pub use dao_rewards_distributor::DaoRewardsDistributor;
4 changes: 2 additions & 2 deletions packages/cw-orch/src/staking/cw20_stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use cw20_stake::contract::{execute, instantiate, migrate, query};
use cw20_stake::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg};

#[interface(InstantiateMsg, ExecuteMsg, QueryMsg, MigrateMsg)]
pub struct Cw20Stake;
pub struct DaoStakingCw20;

impl<Chain> Uploadable for Cw20Stake<Chain> {
impl<Chain> Uploadable for DaoStakingCw20<Chain> {
/// Return the path to the wasm file corresponding to the contract
fn wasm(_chain: &ChainInfoOwned) -> WasmPath {
artifacts_dir_from_workspace!()
Expand Down
4 changes: 2 additions & 2 deletions packages/cw-orch/src/staking/external_rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use cw20_stake_external_rewards::contract::{execute, instantiate, migrate, query
use cw20_stake_external_rewards::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg};

#[interface(InstantiateMsg, ExecuteMsg, QueryMsg, MigrateMsg)]
pub struct Cw20StakeExternalRewards;
pub struct DaoStakingCw20ExternalRewards;

impl<Chain> Uploadable for Cw20StakeExternalRewards<Chain> {
impl<Chain> Uploadable for DaoStakingCw20ExternalRewards<Chain> {
/// Return the path to the wasm file corresponding to the contract
fn wasm(_chain: &ChainInfoOwned) -> WasmPath {
artifacts_dir_from_workspace!()
Expand Down
6 changes: 3 additions & 3 deletions packages/cw-orch/src/staking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ mod cw20_stake;
mod external_rewards;
mod reward_distributor;

pub use cw20_stake::Cw20Stake;
pub use external_rewards::Cw20StakeExternalRewards;
pub use reward_distributor::Cw20StakeRewardDistributor;
pub use cw20_stake::DaoStakingCw20;
pub use external_rewards::DaoStakingCw20ExternalRewards;
pub use reward_distributor::DaoStakingCw20RewardDistributor;
4 changes: 2 additions & 2 deletions packages/cw-orch/src/staking/reward_distributor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use cw20_stake_reward_distributor::contract::{execute, instantiate, migrate, que
use cw20_stake_reward_distributor::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg};

#[interface(InstantiateMsg, ExecuteMsg, QueryMsg, MigrateMsg)]
pub struct Cw20StakeRewardDistributor;
pub struct DaoStakingCw20RewardDistributor;

impl<Chain> Uploadable for Cw20StakeRewardDistributor<Chain> {
impl<Chain> Uploadable for DaoStakingCw20RewardDistributor<Chain> {
/// Return the path to the wasm file corresponding to the contract
fn wasm(_chain: &ChainInfoOwned) -> WasmPath {
artifacts_dir_from_workspace!()
Expand Down
23 changes: 23 additions & 0 deletions scripts/src/distribution.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use cw_orch::prelude::*;
use dao_cw_orch::*;

// cw-funds-distributor
pub struct DaoDistributionSuite<Chain> {
pub fund_distr: DaoFundsDistributor<Chain>,
pub reward_distr: DaoRewardsDistributor<Chain>,
}

impl<Chain: CwEnv> DaoDistributionSuite<Chain> {
pub fn new(chain: Chain) -> DaoDistributionSuite<Chain> {
DaoDistributionSuite::<Chain> {
fund_distr: DaoFundsDistributor::new("cw_funds_distributor", chain.clone()),
reward_distr: DaoRewardsDistributor::new("dao_rewards_distributor", chain.clone()),
}
}

pub fn upload(&self) -> Result<(), CwOrchError> {
self.fund_distr.upload()?;
self.reward_distr.upload()?;
Ok(())
}
}
9 changes: 9 additions & 0 deletions scripts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@ fn main() {}

mod dao;
mod external;
mod distribution;
mod propose;
mod staking;
mod voting;

pub use dao::*;
pub use external::*;
pub use distribution::*;
pub use propose::*;
pub use staking::*;
pub use voting::*;

#[cfg(test)]
mod tests;
61 changes: 61 additions & 0 deletions scripts/src/propose.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
use cw_orch::prelude::*;
use dao_cw_orch::*;

pub struct DaoPreProposeSuite<Chain> {
pub pre_prop_approval_single: DaoPreProposeApprovalSingle<Chain>,
pub pre_prop_approver: DaoPreProposeApprover<Chain>,
pub pre_prop_multiple: DaoPreProposeMultiple<Chain>,
pub pre_prop_single: DaoPreProposeSingle<Chain>,
}

impl<Chain: CwEnv> DaoPreProposeSuite<Chain> {
pub fn new(chain: Chain) -> DaoPreProposeSuite<Chain> {
DaoPreProposeSuite::<Chain> {
pre_prop_approval_single: DaoPreProposeApprovalSingle::new(
"dao_pre_propose_approval_single",
chain.clone(),
),
pre_prop_approver: DaoPreProposeApprover::new(
"dao_pre_propose_approver",
chain.clone(),
),
pre_prop_multiple: DaoPreProposeMultiple::new(
"dao_pre_propose_multiple",
chain.clone(),
),
pre_prop_single: DaoPreProposeSingle::new("dao_pre_propose_single", chain.clone()),
}
}

pub fn upload(&self) -> Result<(), CwOrchError> {
self.pre_prop_approval_single.upload()?;
self.pre_prop_approver.upload()?;
self.pre_prop_multiple.upload()?;

Ok(())
}
}

pub struct DaoProposalSuite<Chain> {
pub prop_single: DaoProposalSingle<Chain>,
pub prop_multiple: DaoProposalMultiple<Chain>,
pub prop_condocert: DaoProposalCondorcet<Chain>,
}

impl<Chain: CwEnv> DaoProposalSuite<Chain> {
pub fn new(chain: Chain) -> DaoProposalSuite<Chain> {
DaoProposalSuite::<Chain> {
prop_single: DaoProposalSingle::new("dao_proposal_single", chain.clone()),
prop_multiple: DaoProposalMultiple::new("dao_proposal_multiple", chain.clone()),
prop_condocert: DaoProposalCondorcet::new("dao_proposal_condocert", chain.clone()),
}
}

pub fn upload(&self) -> Result<(), CwOrchError> {
self.prop_single.upload()?;
self.prop_multiple.upload()?;
self.prop_condocert.upload()?;
Ok(())
}
}

31 changes: 31 additions & 0 deletions scripts/src/staking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use cw_orch::prelude::*;
use dao_cw_orch::*;

pub struct DaoStakingSuite<Chain> {
pub cw20_stake: DaoStakingCw20<Chain>,
pub exteral_rewards: DaoStakingCw20ExternalRewards<Chain>,
pub rewards_distributor: DaoStakingCw20RewardDistributor<Chain>,
}

impl<Chain: CwEnv> DaoStakingSuite<Chain> {
pub fn new(chain: Chain) -> DaoStakingSuite<Chain> {
DaoStakingSuite::<Chain> {
cw20_stake: DaoStakingCw20::new("cw20_stake", chain.clone()),
exteral_rewards: DaoStakingCw20ExternalRewards::new(
"cw20_external_rewards",
chain.clone(),
),
rewards_distributor: DaoStakingCw20RewardDistributor::new(
"cw20_reward_distributor",
chain.clone(),
),
}
}

pub fn upload(&self) -> Result<(), CwOrchError> {
self.cw20_stake.upload()?;
self.exteral_rewards.upload()?;
self.rewards_distributor.upload()?;
Ok(())
}
}
37 changes: 37 additions & 0 deletions scripts/src/tests/deploy/distribution.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use crate::DaoDistributionSuite;
use cw_orch::prelude::*;

// distribution suite
impl<Chain: CwEnv> cw_orch::contract::Deploy<Chain> for DaoDistributionSuite<Chain> {
// We don't have a custom error type
type Error = CwOrchError;
type DeployData = Addr;

fn store_on(chain: Chain) -> Result<Self, Self::Error> {
let suite = DaoDistributionSuite::new(chain.clone());
suite.upload()?;
Ok(suite)
}

fn deployed_state_file_path() -> Option<String> {
None
}

fn get_contracts_mut(&mut self) -> Vec<Box<&mut dyn ContractInstance<Chain>>> {
vec![
Box::new(&mut self.fund_distr),
Box::new(&mut self.reward_distr),
]
}

fn load_from(chain: Chain) -> Result<Self, Self::Error> {
let suite = Self::new(chain.clone());
Ok(suite)
}

fn deploy_on(chain: Chain, _data: Self::DeployData) -> Result<Self, Self::Error> {
// ########### Upload ##############
let suite: DaoDistributionSuite<Chain> = DaoDistributionSuite::store_on(chain.clone())?;
Ok(suite)
}
}
4 changes: 4 additions & 0 deletions scripts/src/tests/deploy/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
mod external;
mod distribution;
mod voting;
mod propose;
mod staking;
76 changes: 76 additions & 0 deletions scripts/src/tests/deploy/propose.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
use crate::propose::*;
use cw_orch::prelude::*;


// pre-proposal suite
impl<Chain: CwEnv> cw_orch::contract::Deploy<Chain> for DaoPreProposeSuite<Chain> {
// We don't have a custom error type
type Error = CwOrchError;
type DeployData = Addr;

fn store_on(chain: Chain) -> Result<Self, Self::Error> {
let suite = DaoPreProposeSuite::new(chain.clone());
suite.upload()?;
Ok(suite)
}

fn deployed_state_file_path() -> Option<String> {
None
}

fn get_contracts_mut(&mut self) -> Vec<Box<&mut dyn ContractInstance<Chain>>> {
vec![
Box::new(&mut self.pre_prop_approval_single),
Box::new(&mut self.pre_prop_approver),
Box::new(&mut self.pre_prop_multiple),
Box::new(&mut self.pre_prop_single),
]
}

fn load_from(chain: Chain) -> Result<Self, Self::Error> {
let factory = Self::new(chain.clone());
Ok(factory)
}

fn deploy_on(chain: Chain, _data: Self::DeployData) -> Result<Self, Self::Error> {
// ########### Upload ##############
let suite: DaoPreProposeSuite<Chain> = DaoPreProposeSuite::store_on(chain.clone())?;
Ok(suite)
}
}

// proposal suite
impl<Chain: CwEnv> cw_orch::contract::Deploy<Chain> for DaoProposalSuite<Chain> {
// We don't have a custom error type
type Error = CwOrchError;
type DeployData = Addr;

fn store_on(chain: Chain) -> Result<Self, Self::Error> {
let suite = DaoProposalSuite::new(chain.clone());
suite.upload()?;
Ok(suite)
}

fn deployed_state_file_path() -> Option<String> {
None
}

fn get_contracts_mut(&mut self) -> Vec<Box<&mut dyn ContractInstance<Chain>>> {
vec![
Box::new(&mut self.prop_single),
Box::new(&mut self.prop_multiple),
Box::new(&mut self.prop_condocert),
]
}

fn load_from(chain: Chain) -> Result<Self, Self::Error> {
let factory = Self::new(chain.clone());
Ok(factory)
}

fn deploy_on(chain: Chain, _data: Self::DeployData) -> Result<Self, Self::Error> {
// ########### Upload ##############
let suite: DaoProposalSuite<Chain> = DaoProposalSuite::store_on(chain.clone())?;
Ok(suite)
}
}
38 changes: 38 additions & 0 deletions scripts/src/tests/deploy/staking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use crate::staking::*;
use cw_orch::prelude::*;

// staking suite
impl<Chain: CwEnv> cw_orch::contract::Deploy<Chain> for DaoStakingSuite<Chain> {
// We don't have a custom error type
type Error = CwOrchError;
type DeployData = Addr;

fn store_on(chain: Chain) -> Result<Self, Self::Error> {
let suite = DaoStakingSuite::new(chain.clone());
suite.upload()?;
Ok(suite)
}

fn deployed_state_file_path() -> Option<String> {
None
}

fn get_contracts_mut(&mut self) -> Vec<Box<&mut dyn ContractInstance<Chain>>> {
vec![
Box::new(&mut self.cw20_stake),
Box::new(&mut self.exteral_rewards),
Box::new(&mut self.rewards_distributor),
]
}

fn load_from(chain: Chain) -> Result<Self, Self::Error> {
let factory = Self::new(chain.clone());
Ok(factory)
}

fn deploy_on(chain: Chain, _data: Self::DeployData) -> Result<Self, Self::Error> {
// ########### Upload ##############
let suite: DaoStakingSuite<Chain> = DaoStakingSuite::store_on(chain.clone())?;
Ok(suite)
}
}
Loading

0 comments on commit 0cc80ce

Please sign in to comment.