Browse Source

regtest: return daemon datadir to its former location under MMGen datadir

Affected coins: BTC,LTC,BCH

Fixes a regression introduced by commit `ca8b4dc31` on Aug 5.

During this period, use of the `mmgen-regtest` script would have overwritten
the user bitcoin/litecoin.conf and regtest dir.  Other files in the daemon
datadir were unaffected.
The MMGen Project 3 years ago
parent
commit
ae3c65ec81
4 changed files with 8 additions and 8 deletions
  1. 7 1
      mmgen/daemon.py
  2. 0 2
      mmgen/globalvars.py
  3. 1 1
      mmgen/regtest.py
  4. 0 4
      test/test_py_d/ts_regtest.py

+ 7 - 1
mmgen/daemon.py

@@ -390,7 +390,7 @@ class CoinDaemon(Daemon):
 
 		# user-set values take precedence
 		self.datadir = os.path.abspath(datadir or g.daemon_data_dir or self.init_datadir())
-		self.non_dfl_datadir = bool(datadir or g.daemon_data_dir or test_suite)
+		self.non_dfl_datadir = bool(datadir or g.daemon_data_dir or test_suite or self.network == 'regtest')
 
 		# init_datadir() may have already initialized logdir
 		self.logdir = os.path.abspath(getattr(self,'logdir',self.datadir))
@@ -485,6 +485,12 @@ class bitcoin_core_daemon(CoinDaemon):
 		'win':   [os.getenv('APPDATA'),'Bitcoin']
 	}
 
+	def init_datadir(self):
+		if self.network == 'regtest' and not self.test_suite:
+			return os.path.join( g.data_dir_root, 'regtest', g.coin.lower() )
+		else:
+			return super().init_datadir()
+
 	@property
 	def network_datadir(self):
 		"location of the network's blockchain data and authentication cookie"

+ 0 - 2
mmgen/globalvars.py

@@ -127,7 +127,6 @@ class GlobalContext(Lockable):
 	traceback            = False
 	test_suite           = False
 	test_suite_deterministic = False
-	test_suite_regtest   = False
 	test_suite_popen_spawn = False
 	terminal_width       = 0
 
@@ -205,7 +204,6 @@ class GlobalContext(Lockable):
 
 		'MMGEN_TEST_SUITE',
 		'MMGEN_TEST_SUITE_DETERMINISTIC',
-		'MMGEN_TEST_SUITE_REGTEST',
 		'MMGEN_TEST_SUITE_POPEN_SPAWN',
 		'MMGEN_TERMINAL_WIDTH',
 		'MMGEN_BOGUS_SEND',

+ 1 - 1
mmgen/regtest.py

@@ -53,7 +53,7 @@ class MMGenRegtest(MMGenObject):
 
 		from .daemon import CoinDaemon
 		self.proto = init_proto(self.coin,regtest=True)
-		self.d = CoinDaemon(self.coin+'_rt',test_suite=g.test_suite_regtest)
+		self.d = CoinDaemon(self.coin+'_rt',test_suite=g.test_suite)
 
 	async def generate(self,blocks=1,silent=False):
 

+ 0 - 4
test/test_py_d/ts_regtest.py

@@ -248,7 +248,6 @@ class TestSuiteRegtest(TestSuiteBase,TestSuiteShared):
 
 	def __init__(self,trunner,cfgs,spawn):
 		TestSuiteBase.__init__(self,trunner,cfgs,spawn)
-		os.environ['MMGEN_TEST_SUITE_REGTEST'] = '1'
 		if self.proto.testnet:
 			die(2,'--testnet and --regtest options incompatible with regtest test suite')
 		self.proto = init_proto(self.proto.coin,network='regtest')
@@ -259,7 +258,6 @@ class TestSuiteRegtest(TestSuiteBase,TestSuiteShared):
 		os.environ['MMGEN_BOGUS_SEND'] = ''
 
 	def __del__(self):
-		os.environ['MMGEN_TEST_SUITE_REGTEST'] = ''
 		os.environ['MMGEN_BOGUS_SEND'] = '1'
 
 	def _add_comments_to_addr_file(self,addrfile,outfile,use_labels=False):
@@ -278,9 +276,7 @@ class TestSuiteRegtest(TestSuiteBase,TestSuiteShared):
 	def setup(self):
 		try: shutil.rmtree(joinpath(self.tr.data_dir,'regtest'))
 		except: pass
-		os.environ['MMGEN_TEST_SUITE'] = '' # mnemonic is piped to stdin, so stop being a terminal
 		t = self.spawn('mmgen-regtest',['-n','setup'])
-		os.environ['MMGEN_TEST_SUITE'] = '1'
 		for s in ('Starting','Creating','Creating','Creating','Mined','Setup complete'):
 			t.expect(s)
 		return t