3 Commits cb42eaa8cd ... 30772b3699

Author SHA1 Message Date
  The MMGen Project 30772b3699 Update for MMGen Wallet 15.1.dev6 1 month ago
  The MMGen Project b9b289c56d directory rename: 1 month ago
  The MMGen Project dee57d8886 update for MMGen Wallet CoinAmt changes 1 month ago

+ 2 - 2
MANIFEST.in

@@ -4,7 +4,7 @@ include mmgen_node_tools/data/*
 
 include test/init.sh
 include test/test-release.d/*.sh
-include test/unit_tests_d/*.py
-include test/cmdtest_py_d/*.py
+include test/modtest_d/*.py
+include test/cmdtest_d/*.py
 include test/overlay/fakemods/mmgen_node_tools/*.py
 include test/ref/*/*

+ 19 - 8
mmgen_node_tools/BlocksInfo.py

@@ -23,6 +23,7 @@ mmgen_node_tools.BlocksInfo: Display information about a block or range of block
 import re,json
 from collections import namedtuple
 from time import strftime,gmtime
+from decimal import Decimal
 
 from mmgen.util import msg,Msg,Msg_r,die,suf,secs_to_ms,secs_to_dhms,is_int
 from mmgen.rpc import json_encoder
@@ -241,14 +242,14 @@ class BlocksInfo:
 			'tf': lambda arg: '{:.8f}'.format(arg * from_satoshi),
 			'su': lambda arg: str(arg * from_satoshi).rstrip('0').rstrip('.'),
 			'fe': lambda arg: str(arg),
-			'di': lambda arg: '{:.2e}'.format(arg),
+			'di': lambda arg: '{:.2e}'.format(Decimal(arg)),
 		}
 
 		if self.cfg.coin == 'BCH':
 			self.fmt_funcs.update({
 				'su': lambda arg: str(arg).rstrip('0').rstrip('.'),
-				'fe': lambda arg: str(int(arg * to_satoshi)),
-				'tf': lambda arg: '{:.8f}'.format(arg),
+				'fe': lambda arg: str(int(Decimal(arg) * to_satoshi)),
+				'tf': lambda arg: '{:.8f}'.format(Decimal(arg)),
 			})
 
 		self.fnames = tuple(
@@ -547,7 +548,7 @@ class BlocksInfo:
 		else:
 			sample_blks = min(min_sample_blks,self.tip)
 			start_hdr = await c.call('getblockheader',await c.call('getblockhash',self.tip-sample_blks))
-			diff_adj = float(tip_hdr['difficulty'] / start_hdr['difficulty'])
+			diff_adj = Decimal(tip_hdr['difficulty']) / Decimal(start_hdr['difficulty'])
 			time1 = rel_hdr['time'] - start_hdr['time']
 			time2 = tip_hdr['time'] - rel_hdr['time']
 			bdi = ((time1 * diff_adj) + time2) / sample_blks
@@ -570,17 +571,26 @@ class BlocksInfo:
 					'sample_blks':  ('{}',     sample_blks)
 				}
 			),
-			('Cur difficulty:    {}', 'cur_diff',            '{:.2e}',  tip_hdr['difficulty']),
+			('Cur difficulty:    {}', 'cur_diff',            '{:.2e}',  Decimal(tip_hdr['difficulty'])),
 			('Est. diff adjust: {}%', 'est_diff_adjust_pct', '{:+.2f}', ((600 / bdi) - 1) * 100),
 		))
 
+	def sum_field_avg(self, field):
+		return self.sum_field_total(field) // len(self.res)
+
+	def sum_field_total(self, field):
+		if isinstance(getattr(self.res[0], field), str):
+			return sum(Decimal(getattr(block, field)) for block in self.res)
+		else:
+			return sum(getattr(block, field) for block in self.res)
+
 	async def create_col_avg_stats(self):
 		def gen():
 			for field in self.fnames:
 				if field in self.avg_stats_skip:
 					yield ( field, ('{}','') )
 				else:
-					ret = sum(getattr(block,field) for block in self.res) // len(self.res)
+					ret = self.sum_field_avg(field)
 					func = self.fields[field].fmt_func
 					yield ( field, ( (self.fmt_funcs[func] if func else '{}'), ret ))
 		if not self.header_printed:
@@ -590,9 +600,10 @@ class BlocksInfo:
 
 	def avg_stats_data(self,data,spec_conv,spec_val):
 		coin = self.rpc.proto.coin
+
 		return data(
 			hdr = 'Averages for processed blocks:',
-			func = lambda field: sum(getattr(block,field) for block in self.res) // len(self.res),
+			func = self.sum_field_avg,
 			spec_sufs = { 'subsidy': f' {coin}', 'totalfee': f' {coin}' },
 			spec_convs = {
 				'interval':    spec_conv(0,  lambda arg: secs_to_ms(arg)),
@@ -616,7 +627,7 @@ class BlocksInfo:
 		coin = self.rpc.proto.coin
 		return data(
 			hdr = 'Totals for processed blocks:',
-			func = lambda field: sum(getattr(block,field) for block in self.res),
+			func = self.sum_field_total,
 			spec_sufs = { 'subsidy': f' {coin}', 'totalfee': f' {coin}', 'reward': f' {coin}' },
 			spec_convs = {
 				'interval': spec_conv(0,  lambda arg: secs_to_dhms(arg)),

+ 1 - 1
mmgen_node_tools/data/version

@@ -1 +1 @@
-3.5.dev2
+3.5.dev3

+ 2 - 2
mmgen_node_tools/main_addrbal.py

@@ -44,7 +44,7 @@ def do_output(proto,addr_data,blk_hdrs):
 			heights = { u['height'] for u in unspents }
 			Msg('{}Balance: {}'.format(
 				indent,
-				proto.coin_amt(sum(u['amount'] for u in unspents)).hl2(unit=True,fs='{:,}') )),
+				sum(proto.coin_amt(u['amount']) for u in unspents).hl2(unit=True, fs='{:,}'))),
 			Msg('{}{} unspent output{} in {} block{}'.format(
 				indent,
 				red(str(len(unspents))),
@@ -99,7 +99,7 @@ def do_output_tabular(proto,addr_data,blk_hdrs):
 				t = make_timestr( blk_hdrs[unspents[0]['height']]['time'] ),
 				B = unspents[-1]['height'],
 				T = make_timestr( blk_hdrs[unspents[-1]['height']]['time'] ),
-				A = proto.coin_amt(sum(u['amount'] for u in unspents)).fmt(color=True,iwidth=7,prec=8)
+				A = sum(proto.coin_amt(u['amount']) for u in unspents).fmt(color=True, iwidth=7, prec=8)
 			))
 		else:
 			Msg(fs.format(

+ 1 - 1
setup.cfg

@@ -38,7 +38,7 @@ python_requires = >=3.9
 include_package_data = True
 
 install_requires =
-	mmgen-wallet>=15.1.dev3
+	mmgen-wallet>=15.1.dev6
 	pyyaml
 	yahooquery
 

+ 1 - 1
test/cmdtest_py_d/cfg.py → test/cmdtest_d/cfg.py

@@ -9,7 +9,7 @@
 #   https://gitlab.com/mmgen/mmgen-node-tools
 
 """
-test.cmdtest_py_d.cfg: configuration data for cmdtest.py
+test.cmdtest_d.cfg: configuration data for cmdtest.py
 """
 
 cmd_groups_altcoin = []

+ 1 - 1
test/cmdtest_py_d/ct_main.py → test/cmdtest_d/ct_main.py

@@ -9,7 +9,7 @@
 #   https://gitlab.com/mmgen/mmgen-wallet
 
 """
-cmdtest_py_d.ct_main: Basic operations tests for the cmdtest.py test suite
+cmdtest_d.ct_main: Basic operations tests for the cmdtest.py test suite
 """
 
 import sys,time

+ 1 - 1
test/cmdtest_py_d/ct_misc.py → test/cmdtest_d/ct_misc.py

@@ -9,7 +9,7 @@
 #   https://gitlab.com/mmgen/mmgen-node-tools
 
 """
-test.cmdtest_py_d.ct_misc: Miscellaneous test groups for the cmdtest.py test suite
+test.cmdtest_d.ct_misc: Miscellaneous test groups for the cmdtest.py test suite
 """
 
 import os,shutil

+ 6 - 5
test/cmdtest_py_d/ct_regtest.py → test/cmdtest_d/ct_regtest.py

@@ -9,10 +9,11 @@
 #   https://gitlab.com/mmgen/mmgen-node-tools
 
 """
-test.cmdtest_py_d.ct_regtest: Regtest tests for the cmdtest.py test suite
+test.cmdtest_d.ct_regtest: Regtest tests for the cmdtest.py test suite
 """
 
 import sys,os
+from decimal import Decimal
 
 from mmgen.util import msg_r,die,gmsg
 from mmgen.protocol import init_proto
@@ -316,13 +317,13 @@ class CmdTestRegtest(CmdTestBase):
 
 			# very approximate tx size estimation:
 			ibytes,wbytes,obytes = (148,0,34) if self.proto.coin == 'BCH' else (43,108,31)
-			x = (ibytes + (wbytes//4) + (obytes * nPairs)) * self.proto.coin_amt(self.proto.coin_amt.satoshi)
+			x = (ibytes + (wbytes//4) + (obytes * nPairs)) * self.proto.coin_amt.satoshi
 
 			n = n_in - 1
 			vmax = high - low
 
 			for i in range(n_in):
-				yield (low + (i/n)**6 * vmax) * x
+				yield Decimal(low + (i/n)**6 * vmax) * x
 
 		async def do_tx(inputs,outputs,wif):
 			tx_hex = await r.rpc_call( 'createrawtransaction', inputs, outputs )
@@ -335,14 +336,14 @@ class CmdTestRegtest(CmdTestBase):
 			tx_input = us[7] # 25 BTC in coinbase -- us[0] could have < 25 BTC
 			fee = self.proto.coin_amt('0.001')
 			outputs = {p.addr:tx1_amt for p in pairs[:nTxs]}
-			outputs.update({burn_addr: tx_input['amount'] - (tx1_amt*nTxs) - fee})
+			outputs.update({burn_addr: self.proto.coin_amt(tx_input['amount']) - (tx1_amt*nTxs) - fee})
 			return await do_tx(
 				[{ 'txid': tx_input['txid'], 'vout': 0 }],
 				outputs,
 				await r.miner_wif)
 
 		async def do_tx2(tx,pairno):
-			fee = fees[pairno]
+			fee = self.proto.coin_amt(fees[pairno], from_decimal=True)
 			outputs = {p.addr:tx2_amt for p in pairs}
 			outputs.update({burn_addr: tx1_amt - (tx2_amt*len(pairs)) - fee})
 			return await do_tx(

+ 9 - 3
test/init.sh

@@ -77,6 +77,10 @@ create_dir_links() {
 	done
 }
 
+delete_old_stuff() {
+	rm -rf test/unit_tests.py
+}
+
 create_test_links() {
 	paths='
 		test/include                   symbolic
@@ -85,10 +89,10 @@ create_test_links() {
 		test/__init__.py               symbolic
 		test/clean.py                  symbolic
 		test/cmdtest.py                hard
-		test/unit_tests.py             hard
+		test/modtest.py                hard
 		test/test-release.sh           symbolic
-		test/cmdtest_py_d/common.py    symbolic
-		test/cmdtest_py_d/ct_base.py   symbolic
+		test/cmdtest_d/common.py       symbolic
+		test/cmdtest_d/ct_base.py      symbolic
 		cmds/mmgen-regtest             symbolic
 	'
 	while read path type; do
@@ -121,6 +125,8 @@ create_test_links() {
 
 becho 'Initializing MMGen Node Tools Test Suite'
 
+delete_old_stuff
+
 check_mmgen_repo || die "MMGen Wallet repository not found at $wallet_repo!"
 
 build_mmgen_extmod

+ 0 - 0
test/unit_tests_d/ut_BlocksInfo.py → test/modtest_d/ut_BlocksInfo.py


+ 0 - 0
test/unit_tests_d/ut_dep.py → test/modtest_d/ut_dep.py


+ 7 - 7
test/test-release.d/cfg.sh

@@ -18,7 +18,7 @@
 #  mmnode-ticker              OK
 #  mmnode-txfind              -
 
-all_tests='unit lint misc scripts btc btc_rt bch_rt ltc_rt'
+all_tests='mod lint misc scripts btc btc_rt bch_rt ltc_rt'
 
 groups_desc="
 	default  - All tests minus the extra tests
@@ -29,10 +29,10 @@ groups_desc="
 "
 
 init_groups() {
-	dfl_tests='unit misc scripts btc btc_rt bch_rt ltc_rt'
+	dfl_tests='mod misc scripts btc btc_rt bch_rt ltc_rt'
 	extra_tests='lint'
-	noalt_tests='unit misc scripts btc btc_rt'
-	quick_tests='unit misc scripts btc btc_rt'
+	noalt_tests='mod misc scripts btc btc_rt'
+	quick_tests='mod misc scripts btc btc_rt'
 	qskip_tests='lint bch_rt ltc_rt'
 }
 
@@ -42,11 +42,11 @@ init_tests() {
 	t_lint="
 		- $pylint --errors-only mmgen_node_tools
 		- $pylint --errors-only test
-		- $pylint --errors-only --disable=relative-beyond-top-level test/cmdtest_py_d
+		- $pylint --errors-only --disable=relative-beyond-top-level test/cmdtest_d
 	"
 
-	d_unit="low-level subsystems"
-	t_unit="- $unit_tests_py"
+	d_mod="low-level subsystems"
+	t_mod="- $modtest_py"
 
 	d_misc="miscellaneous features"
 	t_misc="- $cmdtest_py helpscreens"