def testSaveAndRestoreWallet(do, be, cliForMultiNodePools, aliceMultiNodePools, earlMultiNodePools): be(cliForMultiNodePools) # No wallet should have been restored assert cliForMultiNodePools._activeWallet is None connectTo("pool1", do, cliForMultiNodePools, activeWalletPresents=True, identifiers=0, firstTimeConnect=True) createNewKey(do, cliForMultiNodePools, walletName="Default") switchEnv("pool2", do, cliForMultiNodePools, checkIfWalletRestored=False) createNewKey(do, cliForMultiNodePools, walletName="Default") createNewWallet("mykr0", do) createNewKey(do, cliForMultiNodePools, walletName="mykr0") createNewKey(do, cliForMultiNodePools, walletName="mykr0") useKeyring("Default", do) createNewKey(do, cliForMultiNodePools, walletName="Default") sleep(10) switchEnv("pool1", do, cliForMultiNodePools, checkIfWalletRestored=True, restoredWalletKeyName="Default", restoredIdentifiers=1) createNewWallet("mykr1", do) createNewKey(do, cliForMultiNodePools, walletName="mykr1") switchEnv("pool2", do, cliForMultiNodePools, checkIfWalletRestored=True, restoredWalletKeyName="Default", restoredIdentifiers=2) createNewWallet("mykr0", do, expectedMsgs=[ '"mykr0" conflicts with an existing wallet', 'Please choose a new name.']) filePath = getWalletFilePath( cliForMultiNodePools.getContextBasedWalletsBaseDir(), cliForMultiNodePools.walletFileName) switchEnv("pool1", do, cliForMultiNodePools, checkIfWalletRestored=True, restoredWalletKeyName="mykr1", restoredIdentifiers=1) useKeyring(filePath, do, expectedName="mykr0", expectedMsgs=[ "Given wallet file ({}) doesn't " "belong to current context.".format(filePath), "Please connect to 'pool2' environment and try again."]) # exit from current cli so that active wallet gets saved exitFromCli(do) # different tests for restoring saved wallet filePath = getWalletFilePath( cliForMultiNodePools.getContextBasedWalletsBaseDir(), cliForMultiNodePools.walletFileName) restartCli(aliceMultiNodePools, be, do, "mykr1", 1) restartCliWithCorruptedWalletFile(earlMultiNodePools, be, do, filePath)
def testSaveAndRestoreWallet(do, be, cliForMultiNodePools, aliceMultiNodePools, earlMultiNodePools): be(cliForMultiNodePools) # No wallet should have been restored assert cliForMultiNodePools._activeWallet is None connectTo("pool1", do, cliForMultiNodePools, activeWalletPresents=True, identifiers=0, firstTimeConnect=True) createNewKey(do, cliForMultiNodePools, keyringName="Default") switchEnv("pool2", do, cliForMultiNodePools, checkIfWalletRestored=False) createNewKey(do, cliForMultiNodePools, keyringName="Default") createNewKeyring("mykr0", do) createNewKey(do, cliForMultiNodePools, keyringName="mykr0") createNewKey(do, cliForMultiNodePools, keyringName="mykr0") useKeyring("Default", do) createNewKey(do, cliForMultiNodePools, keyringName="Default") sleep(10) switchEnv("pool1", do, cliForMultiNodePools, checkIfWalletRestored=True, restoredWalletKeyName="Default", restoredIdentifiers=1) createNewKeyring("mykr1", do) createNewKey(do, cliForMultiNodePools, keyringName="mykr1") switchEnv("pool2", do, cliForMultiNodePools, checkIfWalletRestored=True, restoredWalletKeyName="Default", restoredIdentifiers=2) createNewKeyring("mykr0", do, expectedMsgs = [ '"mykr0" conflicts with an existing keyring', 'Please choose a new name.']) filePath = getWalletFilePath(cliForMultiNodePools.getContextBasedKeyringsBaseDir(), cliForMultiNodePools.walletFileName) switchEnv("pool1", do, cliForMultiNodePools, checkIfWalletRestored=True, restoredWalletKeyName="mykr1", restoredIdentifiers=1) useKeyring(filePath, do, expectedName="mykr0", expectedMsgs=[ "Given wallet file ({}) doesn't " "belong to current context.".format(filePath), "Please connect to 'pool2' environment and try again."]) # exit from current cli so that active wallet gets saved exitFromCli(do) # different tests for restoring saved wallet filePath = getWalletFilePath(cliForMultiNodePools.getContextBasedKeyringsBaseDir(), cliForMultiNodePools.walletFileName) restartCli(aliceMultiNodePools, be, do, "mykr1", 1) restartCliWithCorruptedWalletFile(earlMultiNodePools, be, do, filePath)
def _saveWallet(self, wallet: Wallet, contextDir, walletName=None): try: walletName = walletName or wallet.name fileName = normalizedWalletFileName(walletName) walletFilePath = self.walletSaver.saveWallet( wallet, getWalletFilePath(contextDir, fileName)) self.logger.info('Active wallet "{}" saved ({})'.format( walletName, walletFilePath)) except IOError as ex: self.logger.info( "Error occurred while saving wallet. " + "error no.{}, error.{}".format(ex.errno, ex.strerror))
def testSaveAndRestoreWallet(do, be, cli, aliceCli): be(cli) assert cli._activeWallet is None createNewKey(do, cli, keyringName="Default") createNewKeyring("mykr0", do) useKeyring("Default", do) filePath = getWalletFilePath(cli.getContextBasedKeyringsBaseDir(), cli.walletFileName) exitFromCli(do) be(aliceCli) useKeyring(filePath, do, expectedName="Default") useKeyring("mykr0", do, expectedName="mykr0")
def _saveWallet(self, wallet: Wallet, contextDir, walletName=None): try: walletName = walletName or wallet.name fileName = normalizedWalletFileName(walletName) walletFilePath = self.walletSaver.saveWallet( wallet, getWalletFilePath(contextDir, fileName)) self.logger.info('Active wallet "{}" saved ({})'. format(walletName, walletFilePath)) except IOError as ex: self.logger.info("Error occurred while saving wallet. " + "error no.{}, error.{}" .format(ex.errno, ex.strerror))
def testSaveWallet(do, be, cli): be(cli) assert cli._activeWallet is None createNewKey(do, cli, keyringName="Default") saveAndAssertKeyring(do, "Default") filePath = getWalletFilePath(cli.getContextBasedKeyringsBaseDir(), cli.walletFileName) checkPermissions(cli.getKeyringsBaseDir(), cli.config.KEYRING_DIR_MODE) checkPermissions(cli.getContextBasedKeyringsBaseDir(), cli.config.KEYRING_DIR_MODE) checkWalletFilePersisted(filePath) checkPermissions(filePath, cli.config.KEYRING_FILE_MODE)
def getActiveWalletFilePath(cli): fileName = cli.getActiveWalletPersitentFileName() return getWalletFilePath(cli.getContextBasedKeyringsBaseDir(), fileName)
def testSaveAndRestoreWallet(do, be, cliForMultiNodePools, aliceMultiNodePools, earlMultiNodePools): be(cliForMultiNodePools) # No wallet should have been restored assert cliForMultiNodePools._activeWallet is None connectTo("pool1", do, cliForMultiNodePools, activeWalletPresents=True, identifiers=0, firstTimeConnect=True) createNewKey(do, cliForMultiNodePools, walletName="Default") switchEnv("pool2", do, cliForMultiNodePools, checkIfWalletRestored=False) createNewKey(do, cliForMultiNodePools, walletName="Default") createNewWallet("mykr0", do) createNewKey(do, cliForMultiNodePools, walletName="mykr0") createNewKey(do, cliForMultiNodePools, walletName="mykr0") useKeyring("Default", do) createNewKey(do, cliForMultiNodePools, walletName="Default") sleep(10) switchEnv("pool1", do, cliForMultiNodePools, checkIfWalletRestored=True, restoredWalletKeyName="Default", restoredIdentifiers=1) createNewWallet("mykr1", do) createNewKey(do, cliForMultiNodePools, walletName="mykr1") switchEnv("pool2", do, cliForMultiNodePools, checkIfWalletRestored=True, restoredWalletKeyName="Default", restoredIdentifiers=2) createNewWallet("mykr0", do, expectedMsgs=[ '"mykr0" conflicts with an existing wallet', 'Please choose a new name.']) filePath = getWalletFilePath( cliForMultiNodePools.getContextBasedWalletsBaseDir(), cliForMultiNodePools.walletFileName) switchEnv("pool1", do, cliForMultiNodePools, checkIfWalletRestored=True, restoredWalletKeyName="mykr1", restoredIdentifiers=1) useKeyring(filePath, do, expectedName="mykr0", expectedMsgs=[ "Given wallet file ({}) doesn't " "belong to current context.".format(filePath), "Please connect to 'pool2' environment and try again."]) # exit from current cli so that active wallet gets saved exitFromCli(do) alice_wallets_dir = os.path.join(aliceMultiNodePools.getWalletsBaseDir(), "pool1") earl_wallets_dir = os.path.join(earlMultiNodePools.getWalletsBaseDir(), "pool1") os.makedirs(alice_wallets_dir, exist_ok=True) os.makedirs(earl_wallets_dir, exist_ok=True) alice_wallet_path = os.path.join(alice_wallets_dir, cliForMultiNodePools.walletFileName) earl_wallet_path = os.path.join(earl_wallets_dir, cliForMultiNodePools.walletFileName) # different tests for restoring saved wallet filePath = getWalletFilePath( cliForMultiNodePools.getContextBasedWalletsBaseDir(), "default.wallet") shutil.copy(filePath, alice_wallets_dir) shutil.copy(filePath, earl_wallets_dir) filePath = getWalletFilePath( cliForMultiNodePools.getContextBasedWalletsBaseDir(), cliForMultiNodePools.walletFileName) shutil.copy(filePath, alice_wallet_path) shutil.copy(filePath, earl_wallet_path) def _f(path): if not os.path.exists(path): raise FileNotFoundError("{}".format(path)) cliForMultiNodePools.looper.run(eventually(_f, alice_wallet_path)) cliForMultiNodePools.looper.run(eventually(_f, earl_wallet_path)) restartCli(aliceMultiNodePools, be, do, "mykr1", 1) restartCliWithCorruptedWalletFile(earlMultiNodePools, be, do, earl_wallet_path)
def testSaveAndRestoreWallet(do, be, cliForMultiNodePools, aliceMultiNodePools, earlMultiNodePools): be(cliForMultiNodePools) # No wallet should have been restored assert cliForMultiNodePools._activeWallet is None connectTo("pool1", do, cliForMultiNodePools, activeWalletPresents=True, identifiers=0, firstTimeConnect=True) createNewKey(do, cliForMultiNodePools, walletName="Default") switchEnv("pool2", do, cliForMultiNodePools, checkIfWalletRestored=False) createNewKey(do, cliForMultiNodePools, walletName="Default") createNewWallet("mykr0", do) createNewKey(do, cliForMultiNodePools, walletName="mykr0") createNewKey(do, cliForMultiNodePools, walletName="mykr0") useKeyring("Default", do) createNewKey(do, cliForMultiNodePools, walletName="Default") sleep(10) switchEnv("pool1", do, cliForMultiNodePools, checkIfWalletRestored=True, restoredWalletKeyName="Default", restoredIdentifiers=1) createNewWallet("mykr1", do) createNewKey(do, cliForMultiNodePools, walletName="mykr1") switchEnv("pool2", do, cliForMultiNodePools, checkIfWalletRestored=True, restoredWalletKeyName="Default", restoredIdentifiers=2) createNewWallet("mykr0", do, expectedMsgs=[ '"mykr0" conflicts with an existing wallet', 'Please choose a new name.' ]) filePath = getWalletFilePath( cliForMultiNodePools.getContextBasedWalletsBaseDir(), cliForMultiNodePools.walletFileName) switchEnv("pool1", do, cliForMultiNodePools, checkIfWalletRestored=True, restoredWalletKeyName="mykr1", restoredIdentifiers=1) useKeyring(filePath, do, expectedName="mykr0", expectedMsgs=[ "Given wallet file ({}) doesn't " "belong to current context.".format(filePath), "Please connect to 'pool2' environment and try again." ]) # exit from current cli so that active wallet gets saved exitFromCli(do) alice_wallets_dir = os.path.join(aliceMultiNodePools.getWalletsBaseDir(), "pool1") earl_wallets_dir = os.path.join(earlMultiNodePools.getWalletsBaseDir(), "pool1") os.makedirs(alice_wallets_dir, exist_ok=True) os.makedirs(earl_wallets_dir, exist_ok=True) alice_wallet_path = os.path.join(alice_wallets_dir, cliForMultiNodePools.walletFileName) earl_wallet_path = os.path.join(earl_wallets_dir, cliForMultiNodePools.walletFileName) # different tests for restoring saved wallet filePath = getWalletFilePath( cliForMultiNodePools.getContextBasedWalletsBaseDir(), "default.wallet") shutil.copy(filePath, alice_wallets_dir) shutil.copy(filePath, earl_wallets_dir) filePath = getWalletFilePath( cliForMultiNodePools.getContextBasedWalletsBaseDir(), cliForMultiNodePools.walletFileName) shutil.copy(filePath, alice_wallet_path) shutil.copy(filePath, earl_wallet_path) def _f(path): if not os.path.exists(path): raise FileNotFoundError("{}".format(path)) cliForMultiNodePools.looper.run(eventually(_f, alice_wallet_path)) cliForMultiNodePools.looper.run(eventually(_f, earl_wallet_path)) restartCli(aliceMultiNodePools, be, do, "mykr1", 1) restartCliWithCorruptedWalletFile(earlMultiNodePools, be, do, earl_wallet_path)