Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hardening overrule proposals with additional checks #NTRN-325 #32

Merged
merged 59 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
92ba326
wip
oldremez Jan 11, 2023
6413f49
wip
oldremez Jan 12, 2023
7d40f0c
wip
oldremez Jan 12, 2023
ee32d0a
messages refactoring
oldremez Jan 12, 2023
b73035f
temp commit
oldremez Jan 13, 2023
99603e3
query and config fixes
oldremez Jan 16, 2023
3257032
Merge branch 'neutron_audit_informal_17_01_2023' into feat/subdao-reg…
oldremez Mar 13, 2023
959bd60
wip
oldremez Mar 13, 2023
0570481
Merge branch 'neutron_audit_informal_17_01_2023' into feat/subdao-reg…
oldremez Mar 14, 2023
fb4ba65
most of the code is written
oldremez Mar 14, 2023
09f4917
positive test scenario pass
oldremez Mar 14, 2023
779bb0b
refactoring
oldremez Mar 14, 2023
794ac50
wip
oldremez Mar 14, 2023
7b66d5f
huge refactoring, overrule creation added, more tests
oldremez Mar 15, 2023
d3bb5c1
massive unit tests refactoring
oldremez Mar 16, 2023
8433023
overrule pre propose tests pass
oldremez Mar 16, 2023
06e1082
cleaning up some stuff
oldremez Mar 16, 2023
eb2388f
queries tests
oldremez Mar 16, 2023
8857a2c
QueryBase -> QueryExt
oldremez Mar 16, 2023
2c810b4
overrule proposal id query test
oldremez Mar 16, 2023
aab8ff0
fixing timelock tests wip
oldremez Mar 16, 2023
78159ae
timelock fixes and tests
oldremez Mar 17, 2023
a881fcb
schema fixes
oldremez Mar 17, 2023
ff6776f
clippy fixes
oldremez Mar 17, 2023
598b609
schema regen
oldremez Mar 17, 2023
51d7ef6
refactoring
oldremez Mar 21, 2023
c0def32
fix imports to make release build pass
oldremez Mar 22, 2023
2c69309
clippy fixes
oldremez Mar 23, 2023
b21d9d4
init msg fix
oldremez Mar 28, 2023
53df446
Merge branch 'main' into feat/subdao-registry
oldremez Mar 28, 2023
3192ee0
fix
oldremez Apr 3, 2023
cc5e3ec
removing redundant deps
oldremez Apr 3, 2023
f55bf39
timelock proposal tracks the overrule proposal status now
oldremez Apr 4, 2023
8f15c55
rustfmt
oldremez Apr 4, 2023
ad531cb
return commented tests
oldremez Apr 4, 2023
501cbea
clippy
oldremez Apr 4, 2023
ff3f197
fmt
oldremez Apr 4, 2023
ba6ad37
redundant deps
oldremez Apr 4, 2023
bb4cbb3
fixed proposalresponse
oldremez Apr 5, 2023
4b8b946
fixed preproposal hooks
oldremez Apr 6, 2023
82147dd
fmt
oldremez Apr 6, 2023
2dc5f6e
clippy
oldremez Apr 6, 2023
4076475
Merge branch 'main' into feat/subdao-registry
oldremez Apr 6, 2023
3036155
Merge branch 'main' into feat/subdao-registry
oldremez Apr 7, 2023
7d8dd6f
housekeeping
oldremez Apr 9, 2023
1a56936
error descriptions
oldremez Apr 9, 2023
8dd178e
more error descriptions
oldremez Apr 9, 2023
430ffe0
fmt
oldremez Apr 9, 2023
3ee3cab
refactoring+comments
oldremez Apr 10, 2023
9841bb0
format fix
oldremez Apr 10, 2023
d2a1fd6
tests fix
oldremez Apr 10, 2023
2b825b4
Merge branch 'main' into feat/subdao-registry
oldremez Apr 12, 2023
c63fad0
post-review error descriptions fixes
oldremez Apr 13, 2023
9fd4d73
post-review refactoring
oldremez Apr 13, 2023
0675ea3
post-review fmt
oldremez Apr 13, 2023
6f8dcfd
post-review refactoring
oldremez Apr 13, 2023
2d08e28
post-review get subdao query
oldremez Apr 13, 2023
d3b0160
post-review fmt
oldremez Apr 13, 2023
03421cc
post-review clippy
oldremez Apr 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
post-review fmt
  • Loading branch information
oldremez committed Apr 13, 2023
commit d3b01604699b9a5199357f99f6dbbfbe14a06966
11 changes: 3 additions & 8 deletions contracts/dao/cwd-core/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,7 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
QueryMsg::ListSubDaos { start_after, limit } => {
query_list_sub_daos(deps, start_after, limit)
}
QueryMsg::GetSubDao { address } => {
query_sub_dao(deps, address)
}
QueryMsg::GetSubDao { address } => query_sub_dao(deps, address),
QueryMsg::DaoURI {} => query_dao_uri(deps),
}
}
Expand Down Expand Up @@ -517,18 +515,15 @@ pub fn query_list_sub_daos(
to_binary(&subdaos)
}

pub fn query_sub_dao(
deps: Deps,
address: String,
) -> StdResult<Binary> {
pub fn query_sub_dao(deps: Deps, address: String) -> StdResult<Binary> {
let addr = deps.api.addr_validate(&address)?;
let item = SUBDAO_LIST.may_load(deps.storage, &addr)?;
match item {
None => Err(StdError::generic_err("SubDao not found")),
Some(charter) => to_binary(&SubDao {
addr: address,
charter,
})
}),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ fn is_subdao_legit(deps: &DepsMut, subdao_core: &Addr) -> Result<bool, PrePropos

match subdao {
Ok(subdao) => Ok(subdao.addr == *subdao_core),
Err(_) => Err(PreProposeOverruleError::ForbiddenSubdao {})
Err(_) => Err(PreProposeOverruleError::ForbiddenSubdao {}),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,12 @@ impl ContractQuerier for MockDaoQueries {
fn query(&self, msg: &Binary) -> QuerierResult {
let q: MainDaoQueryMsg = from_binary(msg).unwrap();
match q {
MainDaoQueryMsg::GetSubDao {
address,
} =>
match self.sub_dao_set.contains(&address) {
MainDaoQueryMsg::GetSubDao { address } => match self.sub_dao_set.contains(&address) {
true => SystemResult::Ok(ContractResult::from(to_binary(&SubDao {
addr: address.clone(),
charter: None,
}))),
false => SystemResult::Err(SystemError::Unknown {})
false => SystemResult::Err(SystemError::Unknown {}),
},
_ => SystemResult::Err(SystemError::Unknown {}),
}
Expand Down Expand Up @@ -247,9 +244,7 @@ pub fn get_properly_initialized_dao() -> HashMap<String, Box<dyn ContractQuerier
contracts.insert(
MOCK_DAO_CORE.to_string(),
Box::new(MockDaoQueries {
sub_dao_set: HashSet::from([
MOCK_SUBDAO_CORE.to_string()
]),
sub_dao_set: HashSet::from([MOCK_SUBDAO_CORE.to_string()]),
}),
);
contracts.insert(
Expand Down Expand Up @@ -306,4 +301,3 @@ pub fn get_dao_with_impostor_subdao() -> HashMap<String, Box<dyn ContractQuerier
);
contracts
}

Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ use neutron_dao_pre_propose_overrule::msg::{

use crate::error::PreProposeOverruleError;
use crate::testing::mock_querier::{
get_dao_with_impostor_subdao, get_dao_with_impostor_timelock,
get_properly_initialized_dao, ContractQuerier, MOCK_DAO_PROPOSE_MODULE,
MOCK_IMPOSTOR_TIMELOCK_CONTRACT, MOCK_SUBDAO_CORE, NON_TIMELOCKED_PROPOSAL_ID, PROPOSALS_COUNT,
SUBDAO_NAME, TIMELOCKED_PROPOSAL_ID,
get_dao_with_impostor_subdao, get_dao_with_impostor_timelock, get_properly_initialized_dao,
ContractQuerier, MOCK_DAO_PROPOSE_MODULE, MOCK_IMPOSTOR_TIMELOCK_CONTRACT, MOCK_SUBDAO_CORE,
NON_TIMELOCKED_PROPOSAL_ID, PROPOSALS_COUNT, SUBDAO_NAME, TIMELOCKED_PROPOSAL_ID,
};
use cwd_pre_propose_base::state::Config;
use cwd_proposal_single::msg::ExecuteMsg as ProposeMessageInternal;
Expand Down
54 changes: 40 additions & 14 deletions contracts/dao/proposal/cwd-proposal-single/src/testing/tests.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
use cosmwasm_std::{coins, testing::{mock_dependencies, mock_env}, to_binary, Addr, Attribute, BankMsg, ContractInfoResponse, CosmosMsg, Decimal, Empty, Reply, StdError, SubMsgResult, Uint128, WasmMsg, WasmQuery, StdResult};
use cosmwasm_std::{
coins,
testing::{mock_dependencies, mock_env},
to_binary, Addr, Attribute, BankMsg, ContractInfoResponse, CosmosMsg, Decimal, Empty, Reply,
StdError, StdResult, SubMsgResult, Uint128, WasmMsg, WasmQuery,
};
use cosmwasm_std::{Api, Storage};
use cw2::ContractVersion;
use cw20::Cw20Coin;
use cw_multi_test::{custom_app, BasicApp, Executor, Router};
use cw_utils::Duration;
use cwd_core::msg::{ExecuteMsg as DaoExecuteMsg, QueryMsg as DaoQueryMsg};
use cwd_core::query::SubDao;
use cwd_hooks::{HookError, HooksResponse};
use cwd_interface::voting::InfoResponse;
use cwd_voting::{
Expand All @@ -18,11 +25,6 @@ use cwd_voting::{
voting::{Vote, Votes},
};
use neutron_bindings::bindings::msg::NeutronMsg;
use cwd_core::msg::{
QueryMsg as DaoQueryMsg,
ExecuteMsg as DaoExecuteMsg,
};
use cwd_core::query::SubDao;

use crate::testing::execute::{execute_proposal, execute_proposal_should_fail};
use crate::{
Expand Down Expand Up @@ -1365,11 +1367,23 @@ fn test_subdao_queries() {
let core_addr = instantiate_with_native_bonded_balances_governance(&mut app, instantiate, None);

let subdao_addr = Addr::unchecked("subdao");
let res: StdResult<SubDao> = app.wrap()
.query_wasm_smart(core_addr.clone(), &DaoQueryMsg::GetSubDao { address: subdao_addr.to_string() });
let res: StdResult<SubDao> = app.wrap().query_wasm_smart(
core_addr.clone(),
&DaoQueryMsg::GetSubDao {
address: subdao_addr.to_string(),
},
);
assert!(res.is_err());
let res: Vec<SubDao> = app.wrap()
.query_wasm_smart(core_addr.clone(), &DaoQueryMsg::ListSubDaos { start_after: None, limit: None }).unwrap();
let res: Vec<SubDao> = app
.wrap()
.query_wasm_smart(
core_addr.clone(),
&DaoQueryMsg::ListSubDaos {
start_after: None,
limit: None,
},
)
.unwrap();
assert_eq!(res.len(), 0);

let res = app.execute_contract(
Expand All @@ -1385,11 +1399,23 @@ fn test_subdao_queries() {
&[],
);
assert!(res.is_ok());
let res: StdResult<SubDao> = app.wrap()
.query_wasm_smart(core_addr.clone(), &DaoQueryMsg::GetSubDao { address: subdao_addr.to_string() });
let res: StdResult<SubDao> = app.wrap().query_wasm_smart(
core_addr.clone(),
&DaoQueryMsg::GetSubDao {
address: subdao_addr.to_string(),
},
);
assert!(res.is_ok());
let res: Vec<SubDao> = app.wrap()
.query_wasm_smart(core_addr.clone(), &DaoQueryMsg::ListSubDaos { start_after: None, limit: None }).unwrap();
let res: Vec<SubDao> = app
.wrap()
.query_wasm_smart(
core_addr.clone(),
&DaoQueryMsg::ListSubDaos {
start_after: None,
limit: None,
},
)
.unwrap();
assert_eq!(res.len(), 1);
}

Expand Down