44# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
66from test_framework .test_framework import NavCoinTestFramework
7- from test_framework .util import *
7+ from test_framework .cfund_util import *
88
99import time
1010
@@ -17,23 +17,23 @@ def __init__(self):
1717 self .num_nodes = 1
1818
1919 def setup_network (self , split = False ):
20- self .nodes = start_nodes ( self .num_nodes , self . options . tmpdir )
21- self .is_network_split = False
20+ self .nodes = self .setup_nodes ( )
21+ self .is_network_split = split
2222
2323 def run_test (self ):
24- self .slow_gen ( 300 )
24+ activate_cfund ( self .nodes [ 0 ] )
2525 self .nodes [0 ].donatefund (100 )
2626
2727 # Create a proposal and accept by voting
2828 proposalid0 = self .nodes [0 ].createproposal (self .nodes [0 ].getnewaddress (), 10 , 3600 , "test" )["hash" ]
2929 locked_before = self .nodes [0 ].cfundstats ()["funds" ]["locked" ]
30- self .start_new_cycle ( )
30+ end_cycle ( self .nodes [ 0 ] )
3131
3232 time .sleep (0.2 )
3333
3434 self .nodes [0 ].proposalvote (proposalid0 , "yes" )
35- self . slow_gen (1 )
36- self .start_new_cycle ( )
35+ slow_gen (self . nodes [ 0 ], 1 )
36+ end_cycle ( self .nodes [ 0 ] )
3737 locked_accepted = self .nodes [0 ].cfundstats ()["funds" ]["locked" ]
3838
3939 time .sleep (0.2 )
@@ -46,7 +46,7 @@ def run_test(self):
4646
4747 # Create a payment request
4848 paymentrequestid0 = self .nodes [0 ].createpaymentrequest (proposalid0 , 1 , "test0" )["hash" ]
49- self . slow_gen (1 )
49+ slow_gen (self . nodes [ 0 ], 1 )
5050
5151 # Payment request initial state at beginning of cycle
5252
@@ -61,9 +61,9 @@ def run_test(self):
6161 yes_votes = int (total_votes * min_yes_votes ) + 1
6262
6363 self .nodes [0 ].paymentrequestvote (paymentrequestid0 , "yes" )
64- self . slow_gen (yes_votes )
64+ slow_gen (self . nodes [ 0 ], yes_votes )
6565 self .nodes [0 ].paymentrequestvote (paymentrequestid0 , "no" )
66- self . slow_gen (total_votes - yes_votes )
66+ slow_gen (self . nodes [ 0 ], total_votes - yes_votes )
6767 self .nodes [0 ].paymentrequestvote (paymentrequestid0 , "remove" )
6868
6969 # Should still be in pending
@@ -72,7 +72,7 @@ def run_test(self):
7272 assert (self .nodes [0 ].getpaymentrequest (paymentrequestid0 )["status" ] == "pending" )
7373 assert (self .nodes [0 ].cfundstats ()["funds" ]["locked" ] == locked_accepted )
7474
75- self .start_new_cycle ( )
75+ end_cycle ( self .nodes [ 0 ] )
7676 time .sleep (0.2 )
7777
7878 # Payment request initial state at beginning of cycle
@@ -87,16 +87,16 @@ def run_test(self):
8787 yes_votes = int (total_votes * min_yes_votes )
8888
8989 self .nodes [0 ].paymentrequestvote (paymentrequestid0 , "yes" )
90- self . slow_gen (yes_votes )
90+ slow_gen (self . nodes [ 0 ], yes_votes )
9191 self .nodes [0 ].paymentrequestvote (paymentrequestid0 , "no" )
92- self . slow_gen (total_votes - yes_votes )
92+ slow_gen (self . nodes [ 0 ], total_votes - yes_votes )
9393 self .nodes [0 ].paymentrequestvote (paymentrequestid0 , "remove" )
9494
9595 assert (self .nodes [0 ].getpaymentrequest (paymentrequestid0 )["state" ] == 0 )
9696 assert (self .nodes [0 ].getpaymentrequest (paymentrequestid0 )["status" ] == "pending" )
9797 assert (self .nodes [0 ].cfundstats ()["funds" ]["locked" ] == locked_accepted )
9898
99- self .start_new_cycle ( )
99+ end_cycle ( self .nodes [ 0 ] )
100100 time .sleep (0.2 )
101101
102102 # Payment request initial state at beginning of cycle
@@ -111,9 +111,9 @@ def run_test(self):
111111 yes_votes = int (total_votes * min_yes_votes ) + 1
112112
113113 self .nodes [0 ].paymentrequestvote (paymentrequestid0 , "yes" )
114- self . slow_gen (yes_votes )
114+ slow_gen (self . nodes [ 0 ], yes_votes )
115115 self .nodes [0 ].paymentrequestvote (paymentrequestid0 , "no" )
116- blocks = self . slow_gen (total_votes - yes_votes )
116+ blocks = slow_gen (self . nodes [ 0 ], total_votes - yes_votes )
117117 self .nodes [0 ].paymentrequestvote (paymentrequestid0 , "remove" )
118118
119119 assert (self .nodes [0 ].getpaymentrequest (paymentrequestid0 )["state" ] == 0 )
@@ -133,15 +133,15 @@ def run_test(self):
133133 # Vote again
134134
135135 self .nodes [0 ].paymentrequestvote (paymentrequestid0 , "yes" )
136- self . slow_gen (1 )
136+ slow_gen (self . nodes [ 0 ], 1 )
137137 self .nodes [0 ].paymentrequestvote (paymentrequestid0 , "remove" )
138138
139139
140140 # Move to a new cycle...
141141 time .sleep (0.2 )
142142
143- self .start_new_cycle ( )
144- blocks = self . slow_gen (1 )
143+ end_cycle ( self .nodes [ 0 ] )
144+ blocks = slow_gen (self . nodes [ 0 ], 1 )
145145 locked_after_payment = float (locked_accepted ) - float (self .nodes [0 ].getpaymentrequest (paymentrequestid0 )["requestedAmount" ])
146146
147147 # Paymentrequest must be accepted now
@@ -155,7 +155,7 @@ def run_test(self):
155155
156156 paymentrequestid1 = self .nodes [0 ].createpaymentrequest (proposalid0 , 4 , "test1" )["hash" ]
157157 paymentrequestid2 = self .nodes [0 ].createpaymentrequest (proposalid0 , 4 , "test2" )["hash" ]
158- self . slow_gen (1 )
158+ slow_gen (self . nodes [ 0 ], 1 )
159159
160160 assert (self .nodes [0 ].getpaymentrequest (paymentrequestid1 )["state" ] == 0 )
161161 assert (self .nodes [0 ].getpaymentrequest (paymentrequestid1 )["status" ] == "pending" )
@@ -164,10 +164,10 @@ def run_test(self):
164164
165165 self .nodes [0 ].paymentrequestvote (paymentrequestid1 , "yes" )
166166 self .nodes [0 ].paymentrequestvote (paymentrequestid2 , "yes" )
167- self . slow_gen (yes_votes )
167+ slow_gen (self . nodes [ 0 ], yes_votes )
168168 self .nodes [0 ].paymentrequestvote (paymentrequestid1 , "no" )
169169 self .nodes [0 ].paymentrequestvote (paymentrequestid2 , "no" )
170- blocks = self . slow_gen (total_votes - yes_votes )
170+ blocks = slow_gen (self . nodes [ 0 ], total_votes - yes_votes )
171171 self .nodes [0 ].paymentrequestvote (paymentrequestid1 , "remove" )
172172 self .nodes [0 ].paymentrequestvote (paymentrequestid2 , "remove" )
173173
@@ -178,8 +178,8 @@ def run_test(self):
178178
179179 time .sleep (0.2 )
180180
181- self .start_new_cycle ( )
182- blocks = self . slow_gen (1 )
181+ end_cycle ( self .nodes [ 0 ] )
182+ blocks = slow_gen (self . nodes [ 0 ], 1 )
183183
184184 # Check status after acceptance
185185
@@ -201,20 +201,5 @@ def run_test(self):
201201 pass
202202
203203
204- def start_new_cycle (self ):
205- # Move to the end of the cycle
206- self .slow_gen (self .nodes [0 ].cfundstats ()["votingPeriod" ]["ending" ] - self .nodes [0 ].cfundstats ()["votingPeriod" ]["current" ])
207-
208-
209- def slow_gen (self , count ):
210- total = count
211- blocks = []
212- while total > 0 :
213- now = min (total , 10 )
214- blocks .extend (self .nodes [0 ].generate (now ))
215- total -= now
216- time .sleep (0.1 )
217- return blocks
218-
219204if __name__ == '__main__' :
220205 CommunityFundPaymentRequestsTest ().main ()
0 commit comments