cmdtest autosign: reorganize paths
This commit is contained in:
parent
4000ec3238
commit
272f6a4ec3
6 changed files with 87 additions and 69 deletions
|
|
@ -213,9 +213,8 @@ class Autosign:
|
|||
dfl_mountpoint = '/mnt/mmgen_autosign'
|
||||
dfl_wallet_dir = '/dev/shm/autosign'
|
||||
old_dfl_mountpoint = '/mnt/tx'
|
||||
|
||||
dfl_dev_disk_path = '/dev/disk/by-label/MMGEN_TX'
|
||||
fake_dev_disk_path = '/tmp/mmgen-test-suite-dev.disk.by-label.MMGEN_TX'
|
||||
dfl_dev_label_dir = '/dev/disk/by-label'
|
||||
dev_label = 'MMGEN_TX'
|
||||
|
||||
old_dfl_mountpoint_errmsg = f"""
|
||||
Mountpoint '{old_dfl_mountpoint}' is no longer supported!
|
||||
|
|
@ -246,11 +245,20 @@ class Autosign:
|
|||
cfg.mnemonic_fmt,
|
||||
fmt_list( self.mn_fmts, fmt='no_spc' ) ))
|
||||
|
||||
self.dev_disk_path = Path(
|
||||
self.fake_dev_disk_path if cfg.test_suite_xmr_autosign else
|
||||
self.dfl_dev_disk_path )
|
||||
self.mountpoint = Path(cfg.mountpoint or self.dfl_mountpoint)
|
||||
self.wallet_dir = Path(cfg.wallet_dir or self.dfl_wallet_dir)
|
||||
if pfx := cfg.test_suite_root_pfx:
|
||||
subdir = 'online'
|
||||
self.mountpoint = Path(f'{pfx}/{subdir}/{self.dfl_mountpoint}')
|
||||
self.wallet_dir = Path(f'{pfx}/{subdir}/{self.dfl_wallet_dir}')
|
||||
self.dev_label_path = Path(f'{pfx}/{subdir}/{self.dfl_dev_label_dir}') / self.dev_label
|
||||
# mount --type=fuse-ext2 --options=rw+ ### current fuse-ext2 (0.4 29) is buggy - can’t use
|
||||
self.mount_cmd = f'sudo mount {pfx}/removable_device'
|
||||
self.umount_cmd = 'sudo umount'
|
||||
else:
|
||||
self.mountpoint = Path(cfg.mountpoint or self.dfl_mountpoint)
|
||||
self.wallet_dir = Path(cfg.wallet_dir or self.dfl_wallet_dir)
|
||||
self.dev_label_path = Path(self.dfl_dev_label_dir) / self.dev_label
|
||||
self.mount_cmd = 'mount'
|
||||
self.umount_cmd = 'umount'
|
||||
|
||||
self.tx_dir = self.mountpoint / 'tx'
|
||||
self.msg_dir = self.mountpoint / 'msg'
|
||||
|
|
@ -332,7 +340,10 @@ class Autosign:
|
|||
do_die(self.mountpoint_errmsg_fs.format(self.mountpoint))
|
||||
|
||||
if not self.mountpoint.is_mount():
|
||||
if run( ['mount',self.mountpoint], stderr=DEVNULL, stdout=DEVNULL ).returncode == 0:
|
||||
if run(
|
||||
self.mount_cmd.split() + [str(self.mountpoint)],
|
||||
stderr = DEVNULL,
|
||||
stdout = DEVNULL).returncode == 0:
|
||||
if not silent:
|
||||
msg(f"Mounting '{self.mountpoint}'")
|
||||
elif not self.cfg.test_suite:
|
||||
|
|
@ -353,7 +364,7 @@ class Autosign:
|
|||
run( ['sync'], check=True )
|
||||
if not silent:
|
||||
msg(f"Unmounting '{self.mountpoint}'")
|
||||
run( ['umount',self.mountpoint], check=True )
|
||||
run(self.umount_cmd.split() + [str(self.mountpoint)], check=True)
|
||||
if not silent:
|
||||
bmsg('It is now safe to extract the removable device')
|
||||
|
||||
|
|
@ -512,6 +523,7 @@ class Autosign:
|
|||
'autosign': True,
|
||||
'autosign_mountpoint': str(self.mountpoint),
|
||||
'outdir': str(self.xmr_dir), # required by vkal.write()
|
||||
'offline': False,
|
||||
})
|
||||
return self._xmrwallet_cfg
|
||||
|
||||
|
|
@ -587,7 +599,7 @@ class Autosign:
|
|||
bmsg(f'{count} file{suf(count)} shredded')
|
||||
|
||||
def get_insert_status(self):
|
||||
return self.cfg.no_insert_check or self.dev_disk_path.exists()
|
||||
return self.cfg.no_insert_check or self.dev_label_path.exists()
|
||||
|
||||
async def main_loop(self):
|
||||
if not self.cfg.stealth_led:
|
||||
|
|
@ -603,8 +615,8 @@ class Autosign:
|
|||
msg('Device insertion detected')
|
||||
await self.do_sign()
|
||||
if testing_xmr:
|
||||
if self.dev_disk_path.exists():
|
||||
self.dev_disk_path.unlink()
|
||||
if self.dev_label_path.exists():
|
||||
self.dev_label_path.unlink()
|
||||
prev_status = status
|
||||
if not n % 10:
|
||||
msg_r(f"\r{' '*17}\rWaiting")
|
||||
|
|
|
|||
|
|
@ -208,6 +208,7 @@ class Config(Lockable):
|
|||
test_suite_deterministic = False
|
||||
test_suite_pexpect = False
|
||||
test_suite_popen_spawn = False
|
||||
test_suite_root_pfx = ''
|
||||
hold_protect_disable = False
|
||||
no_daemon_autostart = False
|
||||
names = False
|
||||
|
|
@ -292,6 +293,7 @@ class Config(Lockable):
|
|||
'MMGEN_TEST_SUITE_ENABLE_COLOR',
|
||||
'MMGEN_TEST_SUITE_PEXPECT',
|
||||
'MMGEN_TEST_SUITE_POPEN_SPAWN',
|
||||
'MMGEN_TEST_SUITE_ROOT_PFX',
|
||||
'MMGEN_BLACKLIST_DAEMONS',
|
||||
'MMGEN_BOGUS_SEND',
|
||||
'MMGEN_BOGUS_UNSPENT_DATA',
|
||||
|
|
|
|||
|
|
@ -82,7 +82,9 @@ def get_autosign_obj(cfg):
|
|||
Config({
|
||||
'mountpoint': cfg.autosign_mountpoint,
|
||||
'test_suite': cfg.test_suite,
|
||||
'test_suite_root_pfx': cfg.test_suite_root_pfx,
|
||||
'coins': 'xmr',
|
||||
'online': True,
|
||||
})
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -68,7 +68,6 @@ class CmdTestAutosignBase(CmdTestBase):
|
|||
networks = ('btc',)
|
||||
tmpdir_nums = [18]
|
||||
color = True
|
||||
mountpoint_basename = 'mmgen_autosign'
|
||||
no_insert_check = True
|
||||
win_skip = True
|
||||
|
||||
|
|
@ -82,22 +81,9 @@ class CmdTestAutosignBase(CmdTestBase):
|
|||
self.silent = self.live or not (cfg.exact_output or cfg.verbose)
|
||||
self.network_ids = [c+'_tn' for c in self.daemon_coins] + self.daemon_coins
|
||||
|
||||
if not self.live:
|
||||
self.wallet_dir = Path( self.tmpdir, 'dev.shm.autosign' )
|
||||
self._create_autosign_instances(create_dirs=not cfg.skipping_deps)
|
||||
|
||||
self.asi = Autosign(
|
||||
Config({
|
||||
'coins': ','.join(self.coins),
|
||||
'mountpoint': (
|
||||
None if self.live else
|
||||
os.path.join(self.tmpdir,self.mountpoint_basename)
|
||||
),
|
||||
'wallet_dir': None if self.live else self.wallet_dir,
|
||||
'test_suite': True,
|
||||
'test_suite_xmr_autosign': self.name == 'CmdTestXMRAutosign',
|
||||
})
|
||||
)
|
||||
self.mountpoint = self.asi.mountpoint
|
||||
(self.asi_ts.mountpoint / 'tx').mkdir()
|
||||
|
||||
if self.simulate_led and not cfg.exact_output:
|
||||
die(1,red('This command must be run with --exact-output enabled!'))
|
||||
|
|
@ -110,15 +96,8 @@ class CmdTestAutosignBase(CmdTestBase):
|
|||
|
||||
if self.live:
|
||||
init_led(self.simulate_led)
|
||||
else:
|
||||
self.asi.tx_dir.mkdir(parents=True,exist_ok=True) # creates mountpoint
|
||||
self.wallet_dir.mkdir(parents=True,exist_ok=True)
|
||||
self.opts.extend([
|
||||
f'--mountpoint={self.mountpoint}',
|
||||
f'--wallet-dir={self.wallet_dir}',
|
||||
])
|
||||
if self.no_insert_check:
|
||||
self.opts.append('--no-insert-check')
|
||||
elif self.no_insert_check:
|
||||
self.opts.append('--no-insert-check')
|
||||
|
||||
self.tx_file_ops('set_count') # initialize tx_count here so we can resume anywhere
|
||||
|
||||
|
|
@ -136,6 +115,30 @@ class CmdTestAutosignBase(CmdTestBase):
|
|||
self.good_msg_count = 0
|
||||
self.bad_msg_count = 0
|
||||
|
||||
if not self.live:
|
||||
self.spawn_env['MMGEN_TEST_SUITE_ROOT_PFX'] = self.tmpdir
|
||||
|
||||
def _create_autosign_instances(self,create_dirs):
|
||||
d = {
|
||||
'offline': {'name':'asi'},
|
||||
'online': {'name':'asi_ts'}
|
||||
}
|
||||
for subdir,data in d.items():
|
||||
if create_dirs and not self.live:
|
||||
for k in ('mountpoint','wallet_dir','dev_label_dir'):
|
||||
if k == 'wallet_dir' and subdir == 'online':
|
||||
continue
|
||||
(Path(self.tmpdir) / (subdir + getattr(Autosign,'dfl_'+k))).mkdir(parents=True,exist_ok=True)
|
||||
setattr(self,data['name'],
|
||||
Autosign(
|
||||
Config({
|
||||
'coins': ','.join(self.coins),
|
||||
'test_suite': True,
|
||||
'test_suite_xmr_autosign': self.name == 'CmdTestXMRAutosign',
|
||||
'test_suite_root_pfx': None if self.live else self.tmpdir,
|
||||
'online': True,
|
||||
})))
|
||||
|
||||
def __del__(self):
|
||||
if sys.platform == 'win32' or self.tr is None:
|
||||
return
|
||||
|
|
@ -241,7 +244,7 @@ class CmdTestAutosignBase(CmdTestBase):
|
|||
if cfg.debug_utf8:
|
||||
ext = '.testnet.rawtx' if fn.endswith('.testnet.rawtx') else '.rawtx'
|
||||
fn = fn[:-len(ext)] + '-α' + ext
|
||||
target = joinpath(self.asi.mountpoint,'tx',fn)
|
||||
target = joinpath(self.asi_ts.mountpoint,'tx',fn)
|
||||
if not op == 'remove_signed':
|
||||
shutil.copyfile(src,target)
|
||||
try:
|
||||
|
|
@ -265,7 +268,7 @@ class CmdTestAutosignBase(CmdTestBase):
|
|||
self.asi.do_mount(self.silent)
|
||||
# create or delete 2 bad tx files
|
||||
self.spawn('',msg_only=True)
|
||||
fns = [joinpath(self.mountpoint,'tx',f'bad{n}.rawtx') for n in (1,2)]
|
||||
fns = [joinpath(self.asi_ts.mountpoint,'tx',f'bad{n}.rawtx') for n in (1,2)]
|
||||
if op == 'create':
|
||||
for fn in fns:
|
||||
with open(fn,'w') as fp:
|
||||
|
|
@ -294,7 +297,7 @@ class CmdTestAutosignBase(CmdTestBase):
|
|||
|
||||
def msgfile_ops(self,op):
|
||||
self.spawn('',msg_only=True)
|
||||
destdir = joinpath(self.mountpoint,'msg')
|
||||
destdir = joinpath(self.asi_ts.mountpoint,'msg')
|
||||
os.makedirs(destdir,exist_ok=True)
|
||||
if op.endswith('_invalid'):
|
||||
fn = os.path.join(destdir,'DEADBE[BTC].rawmsg.json')
|
||||
|
|
@ -352,7 +355,7 @@ class CmdTestAutosignBase(CmdTestBase):
|
|||
return t
|
||||
|
||||
def insert_device(self):
|
||||
self.asi.dev_disk_path.touch()
|
||||
self.asi.dev_label_path.touch()
|
||||
|
||||
class CmdTestAutosign(CmdTestAutosignBase):
|
||||
'autosigning transactions for all supported coins'
|
||||
|
|
@ -477,7 +480,7 @@ class CmdTestAutosignLive(CmdTestAutosignBTC):
|
|||
|
||||
omsg(purple(f'Running autosign test with {opts_msg}'))
|
||||
|
||||
self.asi.do_umount(self.silent)
|
||||
self.asi_ts.do_umount(self.silent)
|
||||
prompt_remove()
|
||||
omsg(green(info_msg))
|
||||
t = self.spawn(
|
||||
|
|
@ -487,7 +490,7 @@ class CmdTestAutosignLive(CmdTestAutosignBTC):
|
|||
omsg('')
|
||||
prompt_insert_sign(t)
|
||||
|
||||
self.asi.do_mount(self.silent) # race condition due to device insertion detection
|
||||
self.asi_ts.do_mount(self.silent) # race condition due to device insertion detection
|
||||
self.remove_signed_txfiles()
|
||||
self.asi_ts.do_umount(self.silent)
|
||||
|
||||
|
|
|
|||
|
|
@ -125,8 +125,8 @@ class CmdTestXMRAutosign(CmdTestXMRWallet,CmdTestAutosignBase):
|
|||
|
||||
self.burn_addr = make_burn_addr()
|
||||
|
||||
self.opts.append('--xmrwallets={}'.format( self.users['alice'].kal_range )) # mmgen-autosign opts
|
||||
self.autosign_opts = [f'--autosign-mountpoint={self.mountpoint}'] # mmgen-xmrwallet opts
|
||||
self.opts.append('--xmrwallets={}'.format(self.users['alice'].kal_range)) # mmgen-autosign opts
|
||||
self.autosign_opts = ['--autosign'] # mmgen-xmrwallet opts
|
||||
self.tx_count = 1
|
||||
self.spawn_env['MMGEN_TEST_SUITE_XMR_AUTOSIGN'] = '1'
|
||||
|
||||
|
|
@ -223,8 +223,8 @@ class CmdTestXMRAutosign(CmdTestXMRWallet,CmdTestAutosignBase):
|
|||
|
||||
def autosign_setup(self):
|
||||
self.insert_device()
|
||||
Path(self.autosign_xmr_dir).mkdir(parents=True,exist_ok=True)
|
||||
Path(self.autosign_xmr_dir,'old.vkeys').touch()
|
||||
Path(self.asi_ts.xmr_dir).mkdir(parents=True,exist_ok=True)
|
||||
Path(self.asi_ts.xmr_dir,'old.vkeys').touch()
|
||||
t = self.run_setup(
|
||||
mn_type = 'mmgen',
|
||||
mn_file = self.users['alice'].mmwords,
|
||||
|
|
@ -234,8 +234,8 @@ class CmdTestXMRAutosign(CmdTestXMRWallet,CmdTestAutosignBase):
|
|||
return t
|
||||
|
||||
def autosign_start_thread(self):
|
||||
if self.asi.dev_disk_path.exists():
|
||||
self.asi.dev_disk_path.unlink()
|
||||
if self.asi.dev_label_path.exists():
|
||||
self.asi.dev_label_path.unlink()
|
||||
def run():
|
||||
t = self.spawn('mmgen-autosign', self.opts + ['wait'], direct_exec=True)
|
||||
self.write_to_tmpfile('autosign_thread_pid',str(t.ep.pid))
|
||||
|
|
@ -272,15 +272,15 @@ class CmdTestXMRAutosign(CmdTestXMRWallet,CmdTestAutosignBase):
|
|||
return self._create_transfer_tx('0.124')
|
||||
|
||||
def create_transfer_tx2(self):
|
||||
get_file_with_ext(self.asi.xmr_tx_dir,'rawtx',delete_all=True)
|
||||
get_file_with_ext(self.asi.xmr_tx_dir,'sigtx',delete_all=True)
|
||||
get_file_with_ext(self.asi_ts.xmr_tx_dir,'rawtx',delete_all=True)
|
||||
get_file_with_ext(self.asi_ts.xmr_tx_dir,'sigtx',delete_all=True)
|
||||
return self._create_transfer_tx('0.257')
|
||||
|
||||
def _wait_signed(self,dtype):
|
||||
oqmsg_r(gray(f'→ offline wallet{"s" if dtype.endswith("s") else ""} signing {dtype}'))
|
||||
while True:
|
||||
oqmsg_r(gray('.'))
|
||||
if not self.asi.dev_disk_path.exists():
|
||||
if not self.asi.dev_label_path.exists():
|
||||
break
|
||||
time.sleep(0.5)
|
||||
oqmsg(gray('done'))
|
||||
|
|
@ -337,7 +337,7 @@ class CmdTestXMRAutosign(CmdTestXMRWallet,CmdTestAutosignBase):
|
|||
f'{desc} balance 0 < 1.234567891234' )
|
||||
|
||||
def submit_transfer_tx1(self):
|
||||
return self._submit_transfer_tx( ext='sigtx' )
|
||||
return self._submit_transfer_tx()
|
||||
|
||||
def resubmit_transfer_tx1(self):
|
||||
return self._submit_transfer_tx(
|
||||
|
|
@ -396,10 +396,10 @@ class CmdTestXMRAutosign(CmdTestXMRWallet,CmdTestAutosignBase):
|
|||
def create_fake_tx_files(self):
|
||||
imsg('Creating fake transaction files')
|
||||
|
||||
self.asi.msg_dir.mkdir(exist_ok=True)
|
||||
self.asi.xmr_dir.mkdir(exist_ok=True)
|
||||
self.asi.xmr_tx_dir.mkdir(exist_ok=True)
|
||||
self.asi.xmr_outputs_dir.mkdir(exist_ok=True)
|
||||
self.asi_ts.msg_dir.mkdir(exist_ok=True)
|
||||
self.asi_ts.xmr_dir.mkdir(exist_ok=True)
|
||||
self.asi_ts.xmr_tx_dir.mkdir(exist_ok=True)
|
||||
self.asi_ts.xmr_outputs_dir.mkdir(exist_ok=True)
|
||||
|
||||
for fn in (
|
||||
'a.rawtx', 'a.sigtx',
|
||||
|
|
@ -407,7 +407,7 @@ class CmdTestXMRAutosign(CmdTestXMRWallet,CmdTestAutosignBase):
|
|||
'c.rawtx',
|
||||
'd.sigtx',
|
||||
):
|
||||
(self.asi.tx_dir / fn).touch()
|
||||
(self.asi_ts.tx_dir / fn).touch()
|
||||
|
||||
for fn in (
|
||||
'a.rawmsg.json', 'a.sigmsg.json',
|
||||
|
|
@ -415,7 +415,7 @@ class CmdTestXMRAutosign(CmdTestXMRWallet,CmdTestAutosignBase):
|
|||
'c.sigmsg.json',
|
||||
'd.rawmsg.json', 'd.sigmsg.json',
|
||||
):
|
||||
(self.asi.msg_dir / fn).touch()
|
||||
(self.asi_ts.msg_dir / fn).touch()
|
||||
|
||||
for fn in (
|
||||
'a.rawtx', 'a.sigtx', 'a.subtx',
|
||||
|
|
@ -425,23 +425,23 @@ class CmdTestXMRAutosign(CmdTestXMRWallet,CmdTestAutosignBase):
|
|||
'e.rawtx',
|
||||
'f.sigtx','f.subtx',
|
||||
):
|
||||
(self.asi.xmr_tx_dir / fn).touch()
|
||||
(self.asi_ts.xmr_tx_dir / fn).touch()
|
||||
|
||||
for fn in (
|
||||
'a.raw', 'a.sig',
|
||||
'b.raw',
|
||||
'c.sig',
|
||||
):
|
||||
(self.asi.xmr_outputs_dir / fn).touch()
|
||||
(self.asi_ts.xmr_outputs_dir / fn).touch()
|
||||
|
||||
return 'ok'
|
||||
|
||||
def _gen_listing(self):
|
||||
for k in ('tx_dir','msg_dir','xmr_tx_dir','xmr_outputs_dir'):
|
||||
d = getattr(self.asi,k)
|
||||
d = getattr(self.asi_ts,k)
|
||||
if d.is_dir():
|
||||
yield '{:12} {}'.format(
|
||||
str(Path(*d.parts[4:])) + ':',
|
||||
str(Path(*d.parts[6:])) + ':',
|
||||
' '.join(sorted(i.name for i in d.iterdir()))).strip()
|
||||
|
||||
def autosign_clean(self):
|
||||
|
|
@ -460,8 +460,8 @@ class CmdTestXMRAutosign(CmdTestXMRWallet,CmdTestAutosignBase):
|
|||
xmr/outputs:
|
||||
"""
|
||||
|
||||
shutil.rmtree(self.asi.mountpoint)
|
||||
self.asi.tx_dir.mkdir(parents=True)
|
||||
shutil.rmtree(self.asi_ts.mountpoint)
|
||||
self.asi_ts.tx_dir.mkdir(parents=True)
|
||||
|
||||
imsg(f'\nBefore cleaning:\n{before}')
|
||||
imsg(f'\nAfter cleaning:\n{after}')
|
||||
|
|
|
|||
|
|
@ -124,7 +124,6 @@ class CmdTestXMRWallet(CmdTestBase):
|
|||
from mmgen.protocol import init_proto
|
||||
self.proto = init_proto( cfg, 'XMR', network='mainnet' )
|
||||
self.extra_opts = ['--wallet-rpc-password=passw0rd']
|
||||
self.autosign_xmr_dir = os.path.join(self.tmpdir,'mmgen_autosign','xmr')
|
||||
self.init_users()
|
||||
self.init_daemon_args()
|
||||
|
||||
|
|
@ -298,7 +297,7 @@ class CmdTestXMRWallet(CmdTestBase):
|
|||
if autosign:
|
||||
kafile_suf = 'vkeys'
|
||||
fn_stem = 'MoneroWatchOnlyWallet'
|
||||
kafile_dir = self.autosign_xmr_dir
|
||||
kafile_dir = self.asi_ts.xmr_dir
|
||||
else:
|
||||
kafile_suf = 'akeys'
|
||||
fn_stem = 'MoneroWallet'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue