3636from random import randint
3737import shutil
3838
39- from test_framework .blocktools import COINBASE_MATURITY , COINBASE_MATURITY_2
39+ from test_framework .blocktools import COINBASE_MATURITY_2
4040from test_framework .test_framework import DigiByteTestFramework
4141from test_framework .util import (
4242 assert_equal ,
@@ -53,11 +53,12 @@ def set_test_params(self):
5353 self .setup_clean_chain = True
5454 # nodes 1, 2,3 are spenders, let's give them a keypool=100
5555 # whitelist all peers to speed up tx relay / mempool sync
56+ # DigiByte: Use higher wallet minimum fee to match network requirements
5657 self .extra_args = [
57- ["-whitelist=noban@127.0.0.1" , "-keypool=100" ],
58- ["-whitelist=noban@127.0.0.1" , "-keypool=100" ],
59- ["-whitelist=noban@127.0.0.1" , "-keypool=100" ],
60- ["-whitelist=noban@127.0.0.1" ],
58+ ["-whitelist=noban@127.0.0.1" , "-keypool=100" , "-mintxfee=0.001" , "-fallbackfee=0.001" , "-dandelion=0" , "-minrelaytxfee=0.001" ],
59+ ["-whitelist=noban@127.0.0.1" , "-keypool=100" , "-mintxfee=0.001" , "-fallbackfee=0.001" , "-dandelion=0" , "-minrelaytxfee=0.001" ],
60+ ["-whitelist=noban@127.0.0.1" , "-keypool=100" , "-mintxfee=0.001" , "-fallbackfee=0.001" , "-dandelion=0" , "-minrelaytxfee=0.001" ],
61+ ["-whitelist=noban@127.0.0.1" , "-mintxfee=0.001" , "-fallbackfee=0.001" , "-dandelion=0" , "-minrelaytxfee=0.001" ],
6162 ]
6263 self .rpc_timeout = 120
6364
@@ -93,18 +94,19 @@ def do_one_round(self):
9394 # Must sync mempools before mining.
9495 self .sync_mempools ()
9596 self .generate (self .nodes [3 ], 1 )
97+ self .sync_blocks ()
9698
9799 def run_test (self ):
98100 self .log .info ("Generating initial blockchain" )
99101 self .generate (self .nodes [0 ], 1 )
102+ self .sync_blocks ()
100103 self .generate (self .nodes [1 ], 1 )
104+ self .sync_blocks ()
101105 self .generate (self .nodes [2 ], 1 )
106+ self .sync_blocks ()
102107 # DigiByte: Need enough blocks for all coinbases to mature
103- # Node 0 mined at height 0, needs height 8 (COINBASE_MATURITY)
104- # Node 1 mined at height 1, needs height 9
105- # Node 2 mined at height 2, needs height 10
106- # So we need to mine to at least height 10
107- self .generate (self .nodes [3 ], COINBASE_MATURITY + 2 )
108+ self .generate (self .nodes [3 ], COINBASE_MATURITY_2 )
109+ self .sync_blocks ()
108110
109111 # Debug: Check block count and balances
110112 self .log .info (f"Block count: { self .nodes [0 ].getblockcount ()} " )
@@ -125,12 +127,14 @@ def run_test(self):
125127
126128 self .log .info ("Backing up" )
127129
128- self .nodes [0 ].backupwallet (os .path .join (self .nodes [0 ].datadir , 'wallet.bak' ))
129- self .nodes [0 ].dumpwallet (os .path .join (self .nodes [0 ].datadir , 'wallet.dump' ))
130- self .nodes [1 ].backupwallet (os .path .join (self .nodes [1 ].datadir , 'wallet.bak' ))
131- self .nodes [1 ].dumpwallet (os .path .join (self .nodes [1 ].datadir , 'wallet.dump' ))
132- self .nodes [2 ].backupwallet (os .path .join (self .nodes [2 ].datadir , 'wallet.bak' ))
133- self .nodes [2 ].dumpwallet (os .path .join (self .nodes [2 ].datadir , 'wallet.dump' ))
130+ self .nodes [0 ].backupwallet (os .path .join (self .nodes [0 ].datadir_path , 'wallet.bak' ))
131+ self .nodes [1 ].backupwallet (os .path .join (self .nodes [1 ].datadir_path , 'wallet.bak' ))
132+ self .nodes [2 ].backupwallet (os .path .join (self .nodes [2 ].datadir_path , 'wallet.bak' ))
133+
134+ if not self .options .descriptors :
135+ self .nodes [0 ].dumpwallet (os .path .join (self .nodes [0 ].datadir_path , 'wallet.dump' ))
136+ self .nodes [1 ].dumpwallet (os .path .join (self .nodes [1 ].datadir_path , 'wallet.dump' ))
137+ self .nodes [2 ].dumpwallet (os .path .join (self .nodes [2 ].datadir_path , 'wallet.dump' ))
134138
135139 self .log .info ("More transactions" )
136140 for _ in range (5 ):
@@ -139,17 +143,18 @@ def run_test(self):
139143 # Generate 101 more blocks, so any fees paid mature
140144 # DigiByte: Use COINBASE_MATURITY_2 instead of hardcoded 101
141145 self .generate (self .nodes [3 ], COINBASE_MATURITY_2 + 1 )
146+ self .sync_all ()
142147
143148 balance0 = self .nodes [0 ].getbalance ()
144149 balance1 = self .nodes [1 ].getbalance ()
145150 balance2 = self .nodes [2 ].getbalance ()
146151 balance3 = self .nodes [3 ].getbalance ()
147152 total = balance0 + balance1 + balance2 + balance3
148153
149- # At this point, there are 121 blocks ( 3 for setup, then 10 rounds, then 101.)
150- # 22 are mature, so the sum of all wallets should be 22 * 72000 = 1584000.
151- # DigiByte: Adjusted for 72000 DGB block reward
152- assert_equal (total , 22 * 72000 )
154+ # At this point, there are blocks: 3 for setup (nodes 0,1,2), 100 more (node 3), 10 rounds, 101 more
155+ # Total blocks: 3 + 100 + 10 + 101 = 214 blocks
156+ # 114 are mature (all but the last 100), so the sum should be 114 * 72000 = 8,208,000
157+ assert_equal (total , 114 * 72000 )
153158
154159 ##
155160 # Test restoring spender wallets from backups
@@ -161,21 +166,21 @@ def run_test(self):
161166 self .stop_node (3 )
162167
163168 # Start node2 with no chain
164- shutil .rmtree (os .path .join (self .nodes [2 ].datadir , self .chain , 'blocks' ))
165- shutil .rmtree (os .path .join (self .nodes [2 ].datadir , self .chain , 'chainstate' ))
169+ shutil .rmtree (os .path .join (self .nodes [2 ].datadir_path , self .chain , 'blocks' ))
170+ shutil .rmtree (os .path .join (self .nodes [2 ].datadir_path , self .chain , 'chainstate' ))
166171
167172 # Restore wallets from backup
168173 shutil .copyfile (
169- os .path .join (self .nodes [0 ].datadir , 'wallet.bak' ),
170- os .path .join (self .nodes [0 ].datadir , self .chain , 'wallets' , self .default_wallet_name , self .wallet_data_filename )
174+ os .path .join (self .nodes [0 ].datadir_path , 'wallet.bak' ),
175+ os .path .join (self .nodes [0 ].datadir_path , self .chain , 'wallets' , self .default_wallet_name , self .wallet_data_filename )
171176 )
172177 shutil .copyfile (
173- os .path .join (self .nodes [1 ].datadir , 'wallet.bak' ),
174- os .path .join (self .nodes [1 ].datadir , self .chain , 'wallets' , self .default_wallet_name , self .wallet_data_filename )
178+ os .path .join (self .nodes [1 ].datadir_path , 'wallet.bak' ),
179+ os .path .join (self .nodes [1 ].datadir_path , self .chain , 'wallets' , self .default_wallet_name , self .wallet_data_filename )
175180 )
176181 shutil .copyfile (
177- os .path .join (self .nodes [2 ].datadir , 'wallet.bak' ),
178- os .path .join (self .nodes [2 ].datadir , self .chain , 'wallets' , self .default_wallet_name , self .wallet_data_filename )
182+ os .path .join (self .nodes [2 ].datadir_path , 'wallet.bak' ),
183+ os .path .join (self .nodes [2 ].datadir_path , self .chain , 'wallets' , self .default_wallet_name , self .wallet_data_filename )
179184 )
180185
181186 self .log .info ("Re-starting nodes" )
@@ -187,6 +192,9 @@ def run_test(self):
187192 self .connect_nodes (1 , 3 )
188193 self .connect_nodes (2 , 3 )
189194 self .connect_nodes (2 , 0 )
195+
196+ # Sync blocks so node 2 can see the blockchain
197+ self .sync_all ()
190198
191199 assert_equal (self .nodes [0 ].getbalance (), balance0 )
192200 assert_equal (self .nodes [1 ].getbalance (), balance1 )
@@ -198,9 +206,9 @@ def run_test(self):
198206 self .stop_node (2 )
199207
200208 # Get wallet file paths
201- wallet_file_0 = os .path .join (self .nodes [0 ].datadir , self .chain , 'wallets' , self .default_wallet_name , self .wallet_data_filename )
202- wallet_file_1 = os .path .join (self .nodes [1 ].datadir , self .chain , 'wallets' , self .default_wallet_name , self .wallet_data_filename )
203- wallet_file_2 = os .path .join (self .nodes [2 ].datadir , self .chain , 'wallets' , self .default_wallet_name , self .wallet_data_filename )
209+ wallet_file_0 = os .path .join (self .nodes [0 ].datadir_path , self .chain , 'wallets' , self .default_wallet_name , self .wallet_data_filename )
210+ wallet_file_1 = os .path .join (self .nodes [1 ].datadir_path , self .chain , 'wallets' , self .default_wallet_name , self .wallet_data_filename )
211+ wallet_file_2 = os .path .join (self .nodes [2 ].datadir_path , self .chain , 'wallets' , self .default_wallet_name , self .wallet_data_filename )
204212
205213 # Remove the wallet files
206214 os .remove (wallet_file_0 )
@@ -215,28 +223,29 @@ def run_test(self):
215223 assert_equal (self .nodes [1 ].getbalance (), 0 )
216224 assert_equal (self .nodes [2 ].getbalance (), 0 )
217225
218- self .nodes [0 ].importwallet (os .path .join (self .nodes [0 ].datadir , 'wallet.dump' ))
219- self .nodes [1 ].importwallet (os .path .join (self .nodes [1 ].datadir , 'wallet.dump' ))
220- self .nodes [2 ].importwallet (os .path .join (self .nodes [2 ].datadir , 'wallet.dump' ))
226+ if not self .options .descriptors :
227+ self .nodes [0 ].importwallet (os .path .join (self .nodes [0 ].datadir_path , 'wallet.dump' ))
228+ self .nodes [1 ].importwallet (os .path .join (self .nodes [1 ].datadir_path , 'wallet.dump' ))
229+ self .nodes [2 ].importwallet (os .path .join (self .nodes [2 ].datadir_path , 'wallet.dump' ))
221230
222- self .sync_blocks ()
231+ self .sync_blocks ()
223232
224- assert_equal (self .nodes [0 ].getbalance (), balance0 )
225- assert_equal (self .nodes [1 ].getbalance (), balance1 )
226- assert_equal (self .nodes [2 ].getbalance (), balance2 )
233+ assert_equal (self .nodes [0 ].getbalance (), balance0 )
234+ assert_equal (self .nodes [1 ].getbalance (), balance1 )
235+ assert_equal (self .nodes [2 ].getbalance (), balance2 )
227236
228237 # Backup to a different file
229- self .nodes [2 ].backupwallet (os .path .join (self .nodes [2 ].datadir , 'wallet.bak2' ))
238+ self .nodes [2 ].backupwallet (os .path .join (self .nodes [2 ].datadir_path , 'wallet.bak2' ))
230239
231240 self .stop_node (2 )
232241
233242 # Remove the wallet file
234- wallet_file_2 = os .path .join (self .nodes [2 ].datadir , self .chain , 'wallets' , self .default_wallet_name , self .wallet_data_filename )
243+ wallet_file_2 = os .path .join (self .nodes [2 ].datadir_path , self .chain , 'wallets' , self .default_wallet_name , self .wallet_data_filename )
235244 os .remove (wallet_file_2 )
236245
237246 # Restore from the second backup
238247 shutil .copyfile (
239- os .path .join (self .nodes [2 ].datadir , 'wallet.bak2' ),
248+ os .path .join (self .nodes [2 ].datadir_path , 'wallet.bak2' ),
240249 wallet_file_2
241250 )
242251
@@ -246,7 +255,7 @@ def run_test(self):
246255 assert_equal (self .nodes [2 ].getbalance (), balance2 )
247256
248257 # Test backup to invalid path
249- target_dir = os .path .join (self .nodes [0 ].datadir , "invalid_backup_path" )
258+ target_dir = os .path .join (self .nodes [0 ].datadir_path , "invalid_backup_path" )
250259 assert_raises_rpc_error (- 4 , "backup failed" , self .nodes [0 ].backupwallet , target_dir )
251260
252261 self .log .info ("Backup and restore tests completed successfully!" )
0 commit comments