@@ -2,25 +2,23 @@ use std::ops::{Deref, DerefMut};
22
33use cosmwasm_std:: { Addr , Decimal , Uint128 } ;
44use dao_interface:: helpers:: { OptionalUpdate , Update } ;
5- use dao_testing:: { Cw4TestDao , DaoTestingSuite , DaoTestingSuiteBase } ;
5+ use dao_testing:: DaoTestingSuiteBase ;
66
77use 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 ) ;
0 commit comments