Browse Source

minor fixes and cleanups

The MMGen Project 3 years ago
parent
commit
0b80ab0f26
3 changed files with 27 additions and 24 deletions
  1. 19 17
      mmgen/base_proto/bitcoin/rpc.py
  2. 2 2
      mmgen/util.py
  3. 6 5
      test/unit_tests_d/ut_rpc.py

+ 19 - 17
mmgen/base_proto/bitcoin/rpc.py

@@ -74,17 +74,28 @@ class BitcoinRPCClient(RPCClient,metaclass=AsyncInit):
 		self.set_backend(backend) # backend requires self.auth
 
 		self.cached = {}
+
+		self.caps = ('full_node',)
+		for func,cap in (
+			('setlabel','label_api'),
+			('signrawtransactionwithkey','sign_with_key') ):
+			if len((await self.call('help',func)).split('\n')) > 3:
+				self.caps += (cap,)
+
+		call_group = [
+			('getblockcount',()),
+			('getblockhash',(0,)),
+			('getnetworkinfo',()),
+			('getblockchaininfo',()),
+		]
+
 		(
-			self.cached['networkinfo'],
 			self.blockcount,
+			block0,
+			self.cached['networkinfo'],
 			self.cached['blockchaininfo'],
-			block0
-		) = await self.gathered_call(None, (
-				('getnetworkinfo',()),
-				('getblockcount',()),
-				('getblockchaininfo',()),
-				('getblockhash',(0,)),
-			))
+		) = await self.gathered_call(None,tuple(call_group))
+
 		self.daemon_version = self.cached['networkinfo']['version']
 		self.daemon_version_str = self.cached['networkinfo']['subversion']
 		self.chain = self.cached['blockchaininfo']['chain']
@@ -110,13 +121,6 @@ class BitcoinRPCClient(RPCClient,metaclass=AsyncInit):
 		if self.chain == 'mainnet': # skip this for testnet, as Genesis block may change
 			await check_chainfork_mismatch(block0)
 
-		self.caps = ('full_node',)
-		for func,cap in (
-			('setlabel','label_api'),
-			('signrawtransactionwithkey','sign_with_key') ):
-			if len((await self.call('help',func)).split('\n')) > 3:
-				self.caps += (cap,)
-
 		if not self.chain == 'regtest':
 			await self.check_tracking_wallet()
 
@@ -177,8 +181,6 @@ class BitcoinRPCClient(RPCClient,metaclass=AsyncInit):
 
 		def segwit_is_active():
 			d = self.cached['blockchaininfo']
-			if d['chain'] == 'regtest':
-				return True
 
 			try:
 				if d['softforks']['segwit']['active'] == True:

+ 2 - 2
mmgen/util.py

@@ -349,11 +349,11 @@ def decode_timestamp(s):
 
 def make_timestamp(secs=None):
 	return '{:04d}{:02d}{:02d}_{:02d}{:02d}{:02d}'.format(*time.gmtime(
-		int(secs) if secs else time.time() )[:6])
+		int(secs) if secs != None else time.time() )[:6])
 
 def make_timestr(secs=None):
 	return '{}-{:02d}-{:02d} {:02d}:{:02d}:{:02d}'.format(*time.gmtime(
-		int(secs) if secs else time.time() )[:6])
+		int(secs) if secs != None else time.time() )[:6])
 
 def secs_to_dhms(secs):
 	hrs = secs // 3600

+ 6 - 5
test/unit_tests_d/ut_rpc.py

@@ -30,14 +30,15 @@ def cfg_file_auth_test(proto,d):
 	run_session(do())
 	d.stop()
 
-def do_msg(rpc):
-	qmsg('  Testing backend {!r}'.format( type(rpc.backend).__name__ ))
+def do_msg(rpc,backend):
+	bname = type(rpc.backend).__name__
+	qmsg('  Testing backend {!r}{}'.format( bname, '' if backend == bname else f' [{backend}]' ))
 
 class init_test:
 
 	async def btc(proto,backend,daemon):
 		rpc = await rpc_init(proto,backend,daemon)
-		do_msg(rpc)
+		do_msg(rpc,backend)
 
 		bh = (await rpc.call('getblockchaininfo',timeout=300))['bestblockhash']
 		await rpc.gathered_call('getblock',((bh,),(bh,1)),timeout=300)
@@ -45,13 +46,13 @@ class init_test:
 
 	async def bch(proto,backend,daemon):
 		rpc = await rpc_init(proto,backend,daemon)
-		do_msg(rpc)
+		do_msg(rpc,backend)
 
 	ltc = bch
 
 	async def eth(proto,backend,daemon):
 		rpc = await rpc_init(proto,backend,daemon)
-		do_msg(rpc)
+		do_msg(rpc,backend)
 		await rpc.call('eth_blockNumber',timeout=300)
 
 	etc = eth