Skip to content

Commit f34258c

Browse files
committed
added token DAO delegation test
1 parent f80833e commit f34258c

File tree

6 files changed

+468
-125
lines changed

6 files changed

+468
-125
lines changed
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
pub mod suite;
22
pub mod tests;
3-
4-
pub use suite::*;

contracts/delegation/dao-vote-delegation/src/testing/suite.rs renamed to contracts/delegation/dao-vote-delegation/src/testing/suite/base.rs

Lines changed: 20 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,23 @@ use std::ops::{Deref, DerefMut};
22

33
use cosmwasm_std::{Addr, Decimal, Uint128};
44
use dao_interface::helpers::{OptionalUpdate, Update};
5-
use dao_testing::{Cw4TestDao, DaoTestingSuite, DaoTestingSuiteBase};
5+
use dao_testing::DaoTestingSuiteBase;
66

77
use crate::ContractError;
88

9-
use super::tests::dao_vote_delegation_contract;
9+
use super::super::tests::dao_vote_delegation_contract;
1010

11-
pub struct DaoVoteDelegationTestingSuite {
11+
pub struct DaoVoteDelegationTestingSuiteBase {
1212
/// base testing suite that we're extending
1313
pub base: DaoTestingSuiteBase,
1414

1515
// initial config
16-
vp_cap_percent: Option<Decimal>,
17-
delegation_validity_blocks: Option<u64>,
18-
max_delegations: Option<u64>,
16+
pub vp_cap_percent: Option<Decimal>,
17+
pub delegation_validity_blocks: Option<u64>,
18+
pub max_delegations: Option<u64>,
1919

20-
/// cw4-group voting DAO
21-
pub dao: Cw4TestDao,
22-
/// members of the DAO
23-
pub members: Vec<cw4::Member>,
20+
/// DAO core address
21+
pub dao_core_addr: Addr,
2422

2523
/// delegation code ID
2624
pub delegation_code_id: u64,
@@ -29,7 +27,7 @@ pub struct DaoVoteDelegationTestingSuite {
2927
}
3028

3129
// allow direct access to base testing suite methods
32-
impl Deref for DaoVoteDelegationTestingSuite {
30+
impl Deref for DaoVoteDelegationTestingSuiteBase {
3331
type Target = DaoTestingSuiteBase;
3432

3533
fn deref(&self) -> &Self::Target {
@@ -38,21 +36,18 @@ impl Deref for DaoVoteDelegationTestingSuite {
3836
}
3937

4038
// allow direct access to base testing suite methods
41-
impl DerefMut for DaoVoteDelegationTestingSuite {
39+
impl DerefMut for DaoVoteDelegationTestingSuiteBase {
4240
fn deref_mut(&mut self) -> &mut Self::Target {
4341
&mut self.base
4442
}
4543
}
4644

4745
// CONSTRUCTOR
48-
impl DaoVoteDelegationTestingSuite {
46+
impl DaoVoteDelegationTestingSuiteBase {
4947
pub fn new() -> Self {
5048
let mut base = DaoTestingSuiteBase::base();
5149
let mut suite = base.cw4();
5250

53-
let members = suite.members.clone();
54-
let dao = suite.dao();
55-
5651
let delegation_code_id = suite.store(dao_vote_delegation_contract);
5752

5853
Self {
@@ -62,84 +57,16 @@ impl DaoVoteDelegationTestingSuite {
6257
delegation_validity_blocks: None,
6358
max_delegations: None,
6459

65-
dao,
66-
members,
60+
dao_core_addr: Addr::unchecked(""),
6761

6862
delegation_code_id,
6963
delegation_addr: Addr::unchecked(""),
7064
}
7165
}
72-
73-
pub fn with_vp_cap_percent(mut self, vp_cap_percent: Decimal) -> Self {
74-
self.vp_cap_percent = Some(vp_cap_percent);
75-
self
76-
}
77-
78-
pub fn with_delegation_validity_blocks(mut self, delegation_validity_blocks: u64) -> Self {
79-
self.delegation_validity_blocks = Some(delegation_validity_blocks);
80-
self
81-
}
82-
83-
pub fn with_max_delegations(mut self, max_delegations: u64) -> Self {
84-
self.max_delegations = Some(max_delegations);
85-
self
86-
}
87-
88-
pub fn build(mut self) -> Self {
89-
let code_id = self.delegation_code_id;
90-
let core_addr = self.dao.core_addr.clone();
91-
let group_addr = self.dao.x.group_addr.to_string();
92-
let vp_cap_percent = self.vp_cap_percent;
93-
let delegation_validity_blocks = self.delegation_validity_blocks;
94-
let max_delegations = self.max_delegations;
95-
96-
self.delegation_addr = self.instantiate(
97-
code_id,
98-
&core_addr,
99-
&crate::msg::InstantiateMsg {
100-
dao: None,
101-
vp_hook_callers: Some(vec![group_addr]),
102-
no_sync_proposal_modules: None,
103-
vp_cap_percent,
104-
delegation_validity_blocks,
105-
max_delegations,
106-
},
107-
&[],
108-
"delegation",
109-
Some(core_addr.to_string()),
110-
);
111-
112-
self.setup_delegation_module();
113-
114-
self
115-
}
11666
}
11767

11868
// EXECUTIONS
119-
impl DaoVoteDelegationTestingSuite {
120-
/// set up delegation module by adding necessary hooks and adding it to the
121-
/// proposal modules
122-
pub fn setup_delegation_module(&mut self) {
123-
let dao = self.dao.clone();
124-
let delegation_addr = self.delegation_addr.to_string();
125-
126-
// add voting power changed hook to cw4-group
127-
self.execute_smart_ok(
128-
&dao.core_addr,
129-
&dao.x.group_addr,
130-
&cw4::Cw4ExecuteMsg::AddHook {
131-
addr: delegation_addr.clone(),
132-
},
133-
&[],
134-
);
135-
136-
// add vote hook to all proposal modules
137-
self.add_vote_hook(&dao, &delegation_addr);
138-
139-
// set the delegation module for all proposal modules
140-
self.set_delegation_module(&dao, &delegation_addr);
141-
}
142-
69+
impl DaoVoteDelegationTestingSuiteBase {
14370
/// register a user as a delegate
14471
pub fn register(&mut self, delegate: impl Into<String>) {
14572
let delegation_addr = self.delegation_addr.clone();
@@ -219,7 +146,7 @@ impl DaoVoteDelegationTestingSuite {
219146
add: Option<Vec<String>>,
220147
remove: Option<Vec<String>>,
221148
) {
222-
let core_addr = self.dao.core_addr.clone();
149+
let core_addr = self.dao_core_addr.clone();
223150
let delegation_addr = self.delegation_addr.clone();
224151
self.execute_smart_ok(
225152
core_addr,
@@ -231,7 +158,7 @@ impl DaoVoteDelegationTestingSuite {
231158

232159
/// sync proposal modules
233160
pub fn sync_proposal_modules(&mut self, start_after: Option<String>, limit: Option<u32>) {
234-
let core_addr = self.dao.core_addr.clone();
161+
let core_addr = self.dao_core_addr.clone();
235162
let delegation_addr = self.delegation_addr.clone();
236163
self.execute_smart_ok(
237164
core_addr,
@@ -243,7 +170,7 @@ impl DaoVoteDelegationTestingSuite {
243170

244171
/// update VP cap percent
245172
pub fn update_vp_cap_percent(&mut self, vp_cap_percent: Option<Decimal>) {
246-
let core_addr = self.dao.core_addr.clone();
173+
let core_addr = self.dao_core_addr.clone();
247174
let delegation_addr = self.delegation_addr.clone();
248175
self.execute_smart_ok(
249176
core_addr,
@@ -261,7 +188,7 @@ impl DaoVoteDelegationTestingSuite {
261188

262189
/// update delegation validity blocks
263190
pub fn update_delegation_validity_blocks(&mut self, delegation_validity_blocks: Option<u64>) {
264-
let core_addr = self.dao.core_addr.clone();
191+
let core_addr = self.dao_core_addr.clone();
265192
let delegation_addr = self.delegation_addr.clone();
266193
self.execute_smart_ok(
267194
core_addr,
@@ -279,7 +206,7 @@ impl DaoVoteDelegationTestingSuite {
279206

280207
/// update max delegations
281208
pub fn update_max_delegations(&mut self, max_delegations: u64) {
282-
let core_addr = self.dao.core_addr.clone();
209+
let core_addr = self.dao_core_addr.clone();
283210
let delegation_addr = self.delegation_addr.clone();
284211
self.execute_smart_ok(
285212
core_addr,
@@ -295,7 +222,7 @@ impl DaoVoteDelegationTestingSuite {
295222
}
296223

297224
/// QUERIES
298-
impl DaoVoteDelegationTestingSuite {
225+
impl DaoVoteDelegationTestingSuiteBase {
299226
/// get whether a delegate is registered
300227
pub fn registered(&self, delegate: impl Into<String>, height: Option<u64>) -> bool {
301228
self.querier()
@@ -400,7 +327,7 @@ impl DaoVoteDelegationTestingSuite {
400327
}
401328

402329
/// ASSERTIONS
403-
impl DaoVoteDelegationTestingSuite {
330+
impl DaoVoteDelegationTestingSuiteBase {
404331
/// assert that there are N delegations
405332
pub fn assert_delegations_count(&self, delegator: impl Into<String>, count: u32) {
406333
let delegations = self.delegations(delegator, None, None, None);
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
use std::ops::{Deref, DerefMut};
2+
3+
use cosmwasm_std::Decimal;
4+
use dao_testing::{Cw4TestDao, DaoTestingSuite};
5+
6+
use super::base::DaoVoteDelegationTestingSuiteBase;
7+
8+
pub struct Cw4DaoVoteDelegationTestingSuite {
9+
/// base testing suite that we're extending
10+
pub base: DaoVoteDelegationTestingSuiteBase,
11+
12+
/// cw4-group voting DAO
13+
pub dao: Cw4TestDao,
14+
/// members of the DAO
15+
pub members: Vec<cw4::Member>,
16+
}
17+
18+
// allow direct access to base testing suite methods
19+
impl Deref for Cw4DaoVoteDelegationTestingSuite {
20+
type Target = DaoVoteDelegationTestingSuiteBase;
21+
22+
fn deref(&self) -> &Self::Target {
23+
&self.base
24+
}
25+
}
26+
27+
// allow direct access to base testing suite methods
28+
impl DerefMut for Cw4DaoVoteDelegationTestingSuite {
29+
fn deref_mut(&mut self) -> &mut Self::Target {
30+
&mut self.base
31+
}
32+
}
33+
34+
// CONSTRUCTOR
35+
impl Cw4DaoVoteDelegationTestingSuite {
36+
pub fn new() -> Self {
37+
let mut base = DaoVoteDelegationTestingSuiteBase::new();
38+
let mut suite = base.cw4();
39+
40+
let members = suite.members.clone();
41+
let dao = suite.dao();
42+
43+
base.dao_core_addr = dao.core_addr.clone();
44+
45+
Self { base, dao, members }
46+
}
47+
48+
pub fn with_vp_cap_percent(mut self, vp_cap_percent: Decimal) -> Self {
49+
self.vp_cap_percent = Some(vp_cap_percent);
50+
self
51+
}
52+
53+
pub fn with_delegation_validity_blocks(mut self, delegation_validity_blocks: u64) -> Self {
54+
self.delegation_validity_blocks = Some(delegation_validity_blocks);
55+
self
56+
}
57+
58+
pub fn with_max_delegations(mut self, max_delegations: u64) -> Self {
59+
self.max_delegations = Some(max_delegations);
60+
self
61+
}
62+
63+
pub fn build(mut self) -> Self {
64+
let code_id = self.delegation_code_id;
65+
let core_addr = self.dao.core_addr.clone();
66+
let group_addr = self.dao.x.group_addr.to_string();
67+
let vp_cap_percent = self.vp_cap_percent;
68+
let delegation_validity_blocks = self.delegation_validity_blocks;
69+
let max_delegations = self.max_delegations;
70+
71+
self.delegation_addr = self.instantiate(
72+
code_id,
73+
&core_addr,
74+
&crate::msg::InstantiateMsg {
75+
dao: None,
76+
vp_hook_callers: Some(vec![group_addr]),
77+
no_sync_proposal_modules: None,
78+
vp_cap_percent,
79+
delegation_validity_blocks,
80+
max_delegations,
81+
},
82+
&[],
83+
"delegation",
84+
Some(core_addr.to_string()),
85+
);
86+
87+
self.setup_delegation_module();
88+
89+
self
90+
}
91+
92+
/// set up delegation module by adding necessary hooks and adding it to the
93+
/// proposal modules
94+
pub fn setup_delegation_module(&mut self) {
95+
let dao = self.dao.clone();
96+
let delegation_addr = self.delegation_addr.to_string();
97+
98+
// add voting power changed hook to cw4-group
99+
self.execute_smart_ok(
100+
&dao.core_addr,
101+
&dao.x.group_addr,
102+
&cw4::Cw4ExecuteMsg::AddHook {
103+
addr: delegation_addr.clone(),
104+
},
105+
&[],
106+
);
107+
108+
// add vote hook to all proposal modules
109+
self.add_vote_hook(&dao, &delegation_addr);
110+
111+
// set the delegation module for all proposal modules
112+
self.set_delegation_module(&dao, &delegation_addr);
113+
}
114+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub mod base;
2+
pub mod cw4;
3+
pub mod token;

0 commit comments

Comments
 (0)