From 01b5e3f8e03f9025e8ba55fcf223fe7e17e454f1 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Mon, 31 Oct 2022 16:13:22 +0000 Subject: [PATCH] flake8: enable more mandatory tests --- .cirrus.yml | 5 +- contrib/android/apkdiff.py | 4 +- electrum/coinchooser.py | 2 +- electrum/contacts.py | 2 +- electrum/gui/kivy/nfc_scanner/__init__.py | 2 +- .../gui/kivy/nfc_scanner/scanner_android.py | 8 +- electrum/gui/kivy/uix/__init__.py | 1 - electrum/gui/kivy/uix/drawer.py | 4 +- electrum/gui/kivy/util.py | 4 +- electrum/gui/qml/__init__.py | 4 +- electrum/gui/qml/qeaddressdetails.py | 2 +- electrum/gui/qml/qedaemon.py | 16 +- electrum/gui/qml/qeqr.py | 2 +- electrum/gui/qml/qetransactionlistmodel.py | 2 +- .../gui/qt/qrreader/qtmultimedia/validator.py | 2 +- electrum/gui/stdio.py | 2 +- electrum/lnaddr.py | 2 +- electrum/pem.py | 14 +- electrum/plugins/coldcard/coldcard.py | 6 +- electrum/plugins/coldcard/qt.py | 2 +- .../plugins/digitalbitbox/digitalbitbox.py | 6 +- electrum/plugins/ledger/auth2fa.py | 26 +-- electrum/plugins/ledger/ledger.py | 2 +- electrum/plugins/revealer/qt.py | 2 +- electrum/ripemd.py | 184 +++++++++--------- electrum/rsakey.py | 4 +- electrum/scripts/ln_features.py | 2 +- electrum/tests/test_commands.py | 4 +- electrum/tests/test_lnutil.py | 10 +- electrum/tests/test_util.py | 6 +- electrum/transaction.py | 8 +- electrum/wizard.py | 6 +- 32 files changed, 174 insertions(+), 172 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 293c1880b..f1d6fc490 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -149,7 +149,10 @@ task: matrix: - name: Flake8 Mandatory env: - ELECTRUM_LINTERS: E9,F63,F7,F82,W191 + # list of error codes: + # - https://flake8.pycqa.org/en/latest/user/error-codes.html + # - https://pycodestyle.pycqa.org/en/latest/intro.html#error-codes + ELECTRUM_LINTERS: E9,E101,E129,E273,E274,E703,E71,F63,F7,F82,W191,W29 - name: Flake8 Non-Mandatory env: ELECTRUM_LINTERS: E,F,W,C90 diff --git a/contrib/android/apkdiff.py b/contrib/android/apkdiff.py index 2bad4d601..09ac241c0 100755 --- a/contrib/android/apkdiff.py +++ b/contrib/android/apkdiff.py @@ -11,7 +11,7 @@ class ApkDiff: sourceZip = ZipFile(sourceApk, 'r') destinationZip = ZipFile(destinationApk, 'r') - if self.compareManifests(sourceZip, destinationZip) and self.compareEntries(sourceZip, destinationZip) == True: + if self.compareManifests(sourceZip, destinationZip) and self.compareEntries(sourceZip, destinationZip): print("APKs match!") return True else: @@ -50,7 +50,7 @@ class ApkDiff: sourceEntry = sourceZip.open(sourceEntryInfo, 'r') destinationEntry = destinationZip.open(destinationEntryInfo, 'r') - if self.compareFiles(sourceEntry, destinationEntry) != True: + if not self.compareFiles(sourceEntry, destinationEntry): print("APK entry %s does not match %s!" % (sourceEntryInfo.filename, destinationEntryInfo.filename)) return False diff --git a/electrum/coinchooser.py b/electrum/coinchooser.py index 4cdf8bfe3..67137b693 100644 --- a/electrum/coinchooser.py +++ b/electrum/coinchooser.py @@ -482,7 +482,7 @@ COIN_CHOOSERS = { def get_name(config): kind = config.get('coin_chooser') - if not kind in COIN_CHOOSERS: + if kind not in COIN_CHOOSERS: kind = 'Privacy' return kind diff --git a/electrum/contacts.py b/electrum/contacts.py index 3957e8359..0649ff7a3 100644 --- a/electrum/contacts.py +++ b/electrum/contacts.py @@ -134,7 +134,7 @@ class Contacts(dict, Logger): return regex.search(haystack).groups()[0] except AttributeError: return None - + def _validate(self, data): for k, v in list(data.items()): if k == 'contacts': diff --git a/electrum/gui/kivy/nfc_scanner/__init__.py b/electrum/gui/kivy/nfc_scanner/__init__.py index d9935d231..07ed411d4 100644 --- a/electrum/gui/kivy/nfc_scanner/__init__.py +++ b/electrum/gui/kivy/nfc_scanner/__init__.py @@ -12,7 +12,7 @@ class NFCBase(Widget): ''' payload = ObjectProperty(None) - '''This is the data gotten from the tag. + '''This is the data gotten from the tag. ''' def nfc_init(self): diff --git a/electrum/gui/kivy/nfc_scanner/scanner_android.py b/electrum/gui/kivy/nfc_scanner/scanner_android.py index 84e6d4184..699ec8863 100644 --- a/electrum/gui/kivy/nfc_scanner/scanner_android.py +++ b/electrum/gui/kivy/nfc_scanner/scanner_android.py @@ -46,7 +46,7 @@ class ScannerAndroid(NFCBase): global app app = App.get_running_app() - # Make sure we are listening to new intent + # Make sure we are listening to new intent activity.bind(on_new_intent=self.on_new_intent) # Configure nfc @@ -55,7 +55,7 @@ class ScannerAndroid(NFCBase): # Check if adapter exists if not self.nfc_adapter: return False - + # specify that we want our activity to remain on top when a new intent # is fired self.nfc_pending_intent = PendingIntent.getActivity(context, 0, @@ -131,7 +131,7 @@ class ScannerAndroid(NFCBase): ''' This function is called when the application receives a new intent, for the ones the application has registered previously, either in the manifest or in the foreground dispatch setup in the - nfc_init function above. + nfc_init function above. ''' action_list = (NfcAdapter.ACTION_NDEF_DISCOVERED,) @@ -214,7 +214,7 @@ class ScannerAndroid(NFCBase): ndef_record = NdefRecord( NdefRecord.TNF_MIME_MEDIA, 'org.electrum.kivy', '', data) - + # Create message ndef_message = NdefMessage([ndef_record]) diff --git a/electrum/gui/kivy/uix/__init__.py b/electrum/gui/kivy/uix/__init__.py index 8d1c8b69c..e69de29bb 100644 --- a/electrum/gui/kivy/uix/__init__.py +++ b/electrum/gui/kivy/uix/__init__.py @@ -1 +0,0 @@ - diff --git a/electrum/gui/kivy/uix/drawer.py b/electrum/gui/kivy/uix/drawer.py index 324d2343a..f70c56806 100644 --- a/electrum/gui/kivy/uix/drawer.py +++ b/electrum/gui/kivy/uix/drawer.py @@ -135,7 +135,7 @@ class Drawer(Factory.RelativeLayout): return def on_touch_move(self, touch): - if not touch.grab_current is self: + if touch.grab_current is not self: return self._touch = False # skip on tablet mode @@ -175,7 +175,7 @@ class Drawer(Factory.RelativeLayout): return def on_touch_up(self, touch): - if not touch.grab_current is self: + if touch.grab_current is not self: return self._triigger_gc() diff --git a/electrum/gui/kivy/util.py b/electrum/gui/kivy/util.py index b6d80192c..7320a1fae 100644 --- a/electrum/gui/kivy/util.py +++ b/electrum/gui/kivy/util.py @@ -3,12 +3,12 @@ from kivy.utils import get_color_from_hex, platform def address_colors(wallet, addr): """ - Chooses the appropriate text color and background color to + Chooses the appropriate text color and background color to mark receiving, change and billing addresses. Returns: color, background_color """ - + # modified colors (textcolor, background_color) from electrum/gui/qt/util.py GREEN = ("#000000", "#8af296") YELLOW = ("#000000", "#ffff00") diff --git a/electrum/gui/qml/__init__.py b/electrum/gui/qml/__init__.py index 250dc7b58..8d2434426 100644 --- a/electrum/gui/qml/__init__.py +++ b/electrum/gui/qml/__init__.py @@ -52,9 +52,9 @@ class ElectrumGui(Logger): if hasattr(QGuiApplication, 'setDesktopFileName'): QGuiApplication.setDesktopFileName('electrum.desktop') if hasattr(QtCore.Qt, "AA_EnableHighDpiScaling"): - QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling); + QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling) - if not "QT_QUICK_CONTROLS_STYLE" in os.environ: + if "QT_QUICK_CONTROLS_STYLE" not in os.environ: os.environ["QT_QUICK_CONTROLS_STYLE"] = "Material" self.gui_thread = threading.current_thread() diff --git a/electrum/gui/qml/qeaddressdetails.py b/electrum/gui/qml/qeaddressdetails.py index 16af6165a..5b137bc59 100644 --- a/electrum/gui/qml/qeaddressdetails.py +++ b/electrum/gui/qml/qeaddressdetails.py @@ -125,5 +125,5 @@ class QEAddressDetails(QObject): if self._wallet.derivationPrefix: self._derivationPath = self._derivationPath.replace('m', self._wallet.derivationPrefix) self._numtx = self._wallet.wallet.adb.get_address_history_len(self._address) - assert(self._numtx == self.historyModel.rowCount(0)) + assert self._numtx == self.historyModel.rowCount(0) self.detailsChanged.emit() diff --git a/electrum/gui/qml/qedaemon.py b/electrum/gui/qml/qedaemon.py index 5ae0e8232..489667b36 100644 --- a/electrum/gui/qml/qedaemon.py +++ b/electrum/gui/qml/qedaemon.py @@ -44,25 +44,25 @@ class QEWalletListModel(QAbstractListModel): if role_name == 'path': return wallet_path if role_name == 'active': - return wallet != None + return wallet is not None def add_wallet(self, wallet_path = None, wallet: Abstract_Wallet = None): - if wallet_path == None and wallet == None: + if wallet_path is None and wallet is None: return # only add wallet instance if instance not yet in model if wallet: for name,path,w in self.wallets: if w == wallet: return - self.beginInsertRows(QModelIndex(), len(self.wallets), len(self.wallets)); - if wallet == None: + self.beginInsertRows(QModelIndex(), len(self.wallets), len(self.wallets)) + if wallet is None: wallet_name = os.path.basename(wallet_path) else: wallet_name = wallet.basename() wallet_path = standardize_path(wallet_path) item = (wallet_name, wallet_path, wallet) - self.wallets.append(item); - self.endInsertRows(); + self.wallets.append(item) + self.endInsertRows() def remove_wallet(self, path): i = 0 @@ -148,7 +148,7 @@ class QEDaemon(AuthMixin, QObject): @pyqtSlot(str) @pyqtSlot(str, str) def load_wallet(self, path=None, password=None): - if path == None: + if path is None: self._path = self.daemon.config.get('wallet_path') # command line -w option if self._path is None: self._path = self.daemon.config.get('gui_last_wallet') @@ -175,7 +175,7 @@ class QEDaemon(AuthMixin, QObject): try: wallet = self.daemon.load_wallet(self._path, password) - if wallet != None: + if wallet is not None: self._current_wallet = QEWallet.getInstanceFor(wallet) if not wallet_already_open: self._loaded_wallets.add_wallet(wallet_path=self._path, wallet=wallet) diff --git a/electrum/gui/qml/qeqr.py b/electrum/gui/qml/qeqr.py index ee80e2a7b..3d23ecf7f 100644 --- a/electrum/gui/qml/qeqr.py +++ b/electrum/gui/qml/qeqr.py @@ -37,7 +37,7 @@ class QEQRParser(QObject): self._logger.warning("Already processing an image. Check 'busy' property before calling scanImage") return - if image == None: + if image is None: self._logger.warning("No image to decode") return diff --git a/electrum/gui/qml/qetransactionlistmodel.py b/electrum/gui/qml/qetransactionlistmodel.py index 04cc1c9db..71237701b 100644 --- a/electrum/gui/qml/qetransactionlistmodel.py +++ b/electrum/gui/qml/qetransactionlistmodel.py @@ -59,7 +59,7 @@ class QETransactionListModel(QAbstractListModel): item['key'] = item['txid'] if 'txid' in item else item['payment_hash'] - if not 'lightning' in item: + if 'lightning' not in item: item['lightning'] = False if item['lightning']: diff --git a/electrum/gui/qt/qrreader/qtmultimedia/validator.py b/electrum/gui/qt/qrreader/qtmultimedia/validator.py index f8f8de950..58b311539 100644 --- a/electrum/gui/qt/qrreader/qtmultimedia/validator.py +++ b/electrum/gui/qt/qrreader/qtmultimedia/validator.py @@ -79,7 +79,7 @@ class QrReaderValidatorCounting(AbstractQrReaderValidator): for result in results: # Increment the detection count - if not result in self.result_counts: + if result not in self.result_counts: self.result_counts[result] = 0 self.result_counts[result] += 1 diff --git a/electrum/gui/stdio.py b/electrum/gui/stdio.py index 447577003..4f30faddb 100644 --- a/electrum/gui/stdio.py +++ b/electrum/gui/stdio.py @@ -138,7 +138,7 @@ class ElectrumGui(BaseElectrumGui, EventListener): else: msg = _("Not connected") - return(msg) + return msg def print_contacts(self): diff --git a/electrum/lnaddr.py b/electrum/lnaddr.py index f78defec8..adaadde58 100644 --- a/electrum/lnaddr.py +++ b/electrum/lnaddr.py @@ -246,7 +246,7 @@ def lnencode(addr: 'LnAddr', privkey) -> str: # both. if 'd' in tags_set and 'h' in tags_set: raise ValueError("Cannot include both 'd' and 'h'") - if not 'd' in tags_set and not 'h' in tags_set: + if 'd' not in tags_set and 'h' not in tags_set: raise ValueError("Must include either 'd' or 'h'") # We actually sign the hrp, then data (padded to 8 bits with zeroes). diff --git a/electrum/pem.py b/electrum/pem.py index 40390081b..ff7b16772 100644 --- a/electrum/pem.py +++ b/electrum/pem.py @@ -46,7 +46,7 @@ def b2a_base64(b): def dePem(s, name): """Decode a PEM string into a bytearray of its payload. - + The input must contain an appropriate PEM prefix and postfix based on the input name string, e.g. for name="CERTIFICATE": @@ -54,13 +54,13 @@ def dePem(s, name): MIIBXDCCAUSgAwIBAgIBADANBgkqhkiG9w0BAQUFADAPMQ0wCwYDVQQDEwRUQUNL ... KoZIhvcNAQEFBQADAwA5kw== - -----END CERTIFICATE----- + -----END CERTIFICATE----- The first such PEM block in the input will be found, and its payload will be base64 decoded and returned. """ prefix = "-----BEGIN %s-----" % name - postfix = "-----END %s-----" % name + postfix = "-----END %s-----" % name start = s.find(prefix) if start == -1: raise SyntaxError("Missing PEM prefix") @@ -90,7 +90,7 @@ def dePemList(s, name): YMEBdw69PUP8JB4AdqA3K6BVCWfcjN36lx6JwxmZQncS6sww7DecFO/qjSePCxwM +kdDqX/9/183nmjx6bf0ewhPXkA0nVXsDYZaydN8rJU1GaMlnjcIYxY= -----END TACK BREAK SIG----- " - + All such PEM blocks will be found, decoded, and return in an ordered list of bytearrays, which may have zero elements if not PEM blocks are found. """ @@ -111,15 +111,15 @@ def dePemList(s, name): def pem(b, name): """Encode a payload bytearray into a PEM string. - + The input will be base64 encoded, then wrapped in a PEM prefix/postfix based on the name string, e.g. for name="CERTIFICATE": - + -----BEGIN CERTIFICATE----- MIIBXDCCAUSgAwIBAgIBADANBgkqhkiG9w0BAQUFADAPMQ0wCwYDVQQDEwRUQUNL ... KoZIhvcNAQEFBQADAwA5kw== - -----END CERTIFICATE----- + -----END CERTIFICATE----- """ s1 = b2a_base64(b)[:-1] # remove terminating \n s2 = b"" diff --git a/electrum/plugins/coldcard/coldcard.py b/electrum/plugins/coldcard/coldcard.py index 7a9dd4ab0..c68b7a542 100644 --- a/electrum/plugins/coldcard/coldcard.py +++ b/electrum/plugins/coldcard/coldcard.py @@ -241,7 +241,7 @@ class CKCCClient(HardwareClientBase): # get a file return self.dev.download_file(length, checksum, file_number=file_number) - + class Coldcard_KeyStore(Hardware_KeyStore): hw_type = 'coldcard' @@ -311,7 +311,7 @@ class Coldcard_KeyStore(Hardware_KeyStore): except (UnicodeError, AssertionError): # there are other restrictions on message content, # but let the device enforce and report those - self.handler.show_error('Only short (%d max) ASCII messages can be signed.' + self.handler.show_error('Only short (%d max) ASCII messages can be signed.' % MSG_SIGNING_MAX_LENGTH) return b'' @@ -382,7 +382,7 @@ class Coldcard_KeyStore(Hardware_KeyStore): break rlen, rsha = resp - + # download the resulting txn. raw_resp = client.download_file(rlen, rsha) diff --git a/electrum/plugins/coldcard/qt.py b/electrum/plugins/coldcard/qt.py index 924ef81f3..dccaf2c55 100644 --- a/electrum/plugins/coldcard/qt.py +++ b/electrum/plugins/coldcard/qt.py @@ -233,7 +233,7 @@ class CKCCSettingsDialog(WindowModalDialog): self.window.show_error("Does not appear to be a Coldcard firmware file.\n\n%s" % exc) return - # TODO: + # TODO: # - detect if they are trying to downgrade; aint gonna work # - warn them about the reboot? # - length checks diff --git a/electrum/plugins/digitalbitbox/digitalbitbox.py b/electrum/plugins/digitalbitbox/digitalbitbox.py index 562722ec5..629d35b8a 100644 --- a/electrum/plugins/digitalbitbox/digitalbitbox.py +++ b/electrum/plugins/digitalbitbox/digitalbitbox.py @@ -350,8 +350,8 @@ class DigitalBitbox_Client(HardwareClientBase): HWW_CID = 0xFF000000 HWW_CMD = 0x80 + 0x40 + 0x01 data_len = len(data) - seq = 0; - idx = 0; + seq = 0 + idx = 0 write = [] while idx < data_len: if idx == 0: @@ -373,7 +373,7 @@ class DigitalBitbox_Client(HardwareClientBase): cmd = read[4] data_len = read[5] * 256 + read[6] data = read[7:] - idx = len(read) - 7; + idx = len(read) - 7 while idx < data_len: # CONT response read = bytearray(self.dbb_hid.read(self.usbReportSize)) diff --git a/electrum/plugins/ledger/auth2fa.py b/electrum/plugins/ledger/auth2fa.py index 638285e2d..aa7a07a19 100644 --- a/electrum/plugins/ledger/auth2fa.py +++ b/electrum/plugins/ledger/auth2fa.py @@ -44,14 +44,14 @@ class LedgerAuthDialog(QDialog): self.cfg = copy.deepcopy(self.handler.win.wallet.get_keystore().cfg) self.dongle = client.dongleObject.dongle self.pin = '' - + self.devmode = self.getDevice2FAMode() if self.devmode == 0x11 or self.txdata['confirmationType'] == 1: self.cfg['mode'] = 0 - + vbox = QVBoxLayout() self.setLayout(vbox) - + def on_change_mode(idx): self.cfg['mode'] = 0 if self.devmode == 0x11 else idx if idx > 0 else 1 if self.cfg['mode'] > 0: @@ -59,11 +59,11 @@ class LedgerAuthDialog(QDialog): self.handler.win.wallet.save_keystore() self.update_dlg() def return_pin(): - self.pin = self.pintxt.text() if self.txdata['confirmationType'] == 1 else self.cardtxt.text() + self.pin = self.pintxt.text() if self.txdata['confirmationType'] == 1 else self.cardtxt.text() if self.cfg['mode'] == 1: self.pin = ''.join(chr(int(str(i),16)) for i in self.pin) self.accept() - + self.modebox = QWidget() modelayout = QHBoxLayout() self.modebox.setLayout(modelayout) @@ -73,7 +73,7 @@ class LedgerAuthDialog(QDialog): modelayout.addStretch(1) self.modebox.setMaximumHeight(50) vbox.addWidget(self.modebox) - + self.populate_modes() self.modes.currentIndexChanged.connect(on_change_mode) @@ -81,7 +81,7 @@ class LedgerAuthDialog(QDialog): self.helpmsg.setStyleSheet("QTextEdit { color:black; background-color: lightgray; }") self.helpmsg.setReadOnly(True) vbox.addWidget(self.helpmsg) - + self.pinbox = QWidget() pinlayout = QHBoxLayout() self.pinbox.setLayout(pinlayout) @@ -94,7 +94,7 @@ class LedgerAuthDialog(QDialog): pinlayout.addStretch(1) self.pinbox.setVisible(self.cfg['mode'] == 0) vbox.addWidget(self.pinbox) - + self.cardbox = QWidget() card = QVBoxLayout() self.cardbox.setLayout(card) @@ -107,7 +107,7 @@ class LedgerAuthDialog(QDialog): self.addrtext.setReadOnly(True) self.addrtext.setMaximumHeight(130) card.addWidget(self.addrtext) - + def pin_changed(s): if len(s) < len(self.idxs): i = self.idxs[len(s)] @@ -122,8 +122,8 @@ class LedgerAuthDialog(QDialog): self.addrtext.setHtml(str(text)) else: self.addrtext.setHtml(_("Press Enter")) - - pin_changed('') + + pin_changed('') cardpin = QHBoxLayout() cardpin.addWidget(QLabel(_("Enter PIN:"))) self.cardtxt = PasswordLineEdit() @@ -136,7 +136,7 @@ class LedgerAuthDialog(QDialog): card.addLayout(cardpin) self.cardbox.setVisible(self.cfg['mode'] == 1) vbox.addWidget(self.cardbox) - + self.update_dlg() def populate_modes(self): @@ -146,7 +146,7 @@ class LedgerAuthDialog(QDialog): if self.txdata['confirmationType'] > 1: self.modes.addItem(_("Security Card Challenge")) self.modes.blockSignals(False) - + def update_dlg(self): self.modes.setCurrentIndex(self.cfg['mode']) self.modebox.setVisible(True) diff --git a/electrum/plugins/ledger/ledger.py b/electrum/plugins/ledger/ledger.py index 91ae41b12..cb0a1c2ab 100644 --- a/electrum/plugins/ledger/ledger.py +++ b/electrum/plugins/ledger/ledger.py @@ -333,7 +333,7 @@ class Ledger_KeyStore(Hardware_KeyStore): # Pad r and s points with 0x00 bytes when the point is small to get valid signature. r_padded = bytes([0x00]) * (32 - len(r)) + r s_padded = bytes([0x00]) * (32 - len(s)) + s - + return bytes([27 + 4 + (signature[0] & 0x01)]) + r_padded + s_padded @runs_in_hwd_thread diff --git a/electrum/plugins/revealer/qt.py b/electrum/plugins/revealer/qt.py index e6124341d..52c975d6b 100644 --- a/electrum/plugins/revealer/qt.py +++ b/electrum/plugins/revealer/qt.py @@ -330,7 +330,7 @@ class Plugin(RevealerPlugin): painter.end() img = bitmap.toImage() - if (self.rawnoise == False): + if not self.rawnoise: self.make_rawnoise() self.make_cypherseed(img, self.rawnoise, False, is_seed) diff --git a/electrum/ripemd.py b/electrum/ripemd.py index 96b258b27..b39cdc17b 100644 --- a/electrum/ripemd.py +++ b/electrum/ripemd.py @@ -159,96 +159,96 @@ def RMD160Transform(state, block): #uint32 state[5], uchar block[64] e = state[4] #/* Round 1 */ - a, c = R(a, b, c, d, e, F0, K0, 11, 0, x); - e, b = R(e, a, b, c, d, F0, K0, 14, 1, x); - d, a = R(d, e, a, b, c, F0, K0, 15, 2, x); - c, e = R(c, d, e, a, b, F0, K0, 12, 3, x); - b, d = R(b, c, d, e, a, F0, K0, 5, 4, x); - a, c = R(a, b, c, d, e, F0, K0, 8, 5, x); - e, b = R(e, a, b, c, d, F0, K0, 7, 6, x); - d, a = R(d, e, a, b, c, F0, K0, 9, 7, x); - c, e = R(c, d, e, a, b, F0, K0, 11, 8, x); - b, d = R(b, c, d, e, a, F0, K0, 13, 9, x); - a, c = R(a, b, c, d, e, F0, K0, 14, 10, x); - e, b = R(e, a, b, c, d, F0, K0, 15, 11, x); - d, a = R(d, e, a, b, c, F0, K0, 6, 12, x); - c, e = R(c, d, e, a, b, F0, K0, 7, 13, x); - b, d = R(b, c, d, e, a, F0, K0, 9, 14, x); - a, c = R(a, b, c, d, e, F0, K0, 8, 15, x); #/* #15 */ + a, c = R(a, b, c, d, e, F0, K0, 11, 0, x) + e, b = R(e, a, b, c, d, F0, K0, 14, 1, x) + d, a = R(d, e, a, b, c, F0, K0, 15, 2, x) + c, e = R(c, d, e, a, b, F0, K0, 12, 3, x) + b, d = R(b, c, d, e, a, F0, K0, 5, 4, x) + a, c = R(a, b, c, d, e, F0, K0, 8, 5, x) + e, b = R(e, a, b, c, d, F0, K0, 7, 6, x) + d, a = R(d, e, a, b, c, F0, K0, 9, 7, x) + c, e = R(c, d, e, a, b, F0, K0, 11, 8, x) + b, d = R(b, c, d, e, a, F0, K0, 13, 9, x) + a, c = R(a, b, c, d, e, F0, K0, 14, 10, x) + e, b = R(e, a, b, c, d, F0, K0, 15, 11, x) + d, a = R(d, e, a, b, c, F0, K0, 6, 12, x) + c, e = R(c, d, e, a, b, F0, K0, 7, 13, x) + b, d = R(b, c, d, e, a, F0, K0, 9, 14, x) + a, c = R(a, b, c, d, e, F0, K0, 8, 15, x) #/* #15 */ #/* Round 2 */ - e, b = R(e, a, b, c, d, F1, K1, 7, 7, x); - d, a = R(d, e, a, b, c, F1, K1, 6, 4, x); - c, e = R(c, d, e, a, b, F1, K1, 8, 13, x); - b, d = R(b, c, d, e, a, F1, K1, 13, 1, x); - a, c = R(a, b, c, d, e, F1, K1, 11, 10, x); - e, b = R(e, a, b, c, d, F1, K1, 9, 6, x); - d, a = R(d, e, a, b, c, F1, K1, 7, 15, x); - c, e = R(c, d, e, a, b, F1, K1, 15, 3, x); - b, d = R(b, c, d, e, a, F1, K1, 7, 12, x); - a, c = R(a, b, c, d, e, F1, K1, 12, 0, x); - e, b = R(e, a, b, c, d, F1, K1, 15, 9, x); - d, a = R(d, e, a, b, c, F1, K1, 9, 5, x); - c, e = R(c, d, e, a, b, F1, K1, 11, 2, x); - b, d = R(b, c, d, e, a, F1, K1, 7, 14, x); - a, c = R(a, b, c, d, e, F1, K1, 13, 11, x); - e, b = R(e, a, b, c, d, F1, K1, 12, 8, x); #/* #31 */ + e, b = R(e, a, b, c, d, F1, K1, 7, 7, x) + d, a = R(d, e, a, b, c, F1, K1, 6, 4, x) + c, e = R(c, d, e, a, b, F1, K1, 8, 13, x) + b, d = R(b, c, d, e, a, F1, K1, 13, 1, x) + a, c = R(a, b, c, d, e, F1, K1, 11, 10, x) + e, b = R(e, a, b, c, d, F1, K1, 9, 6, x) + d, a = R(d, e, a, b, c, F1, K1, 7, 15, x) + c, e = R(c, d, e, a, b, F1, K1, 15, 3, x) + b, d = R(b, c, d, e, a, F1, K1, 7, 12, x) + a, c = R(a, b, c, d, e, F1, K1, 12, 0, x) + e, b = R(e, a, b, c, d, F1, K1, 15, 9, x) + d, a = R(d, e, a, b, c, F1, K1, 9, 5, x) + c, e = R(c, d, e, a, b, F1, K1, 11, 2, x) + b, d = R(b, c, d, e, a, F1, K1, 7, 14, x) + a, c = R(a, b, c, d, e, F1, K1, 13, 11, x) + e, b = R(e, a, b, c, d, F1, K1, 12, 8, x) #/* #31 */ #/* Round 3 */ - d, a = R(d, e, a, b, c, F2, K2, 11, 3, x); - c, e = R(c, d, e, a, b, F2, K2, 13, 10, x); - b, d = R(b, c, d, e, a, F2, K2, 6, 14, x); - a, c = R(a, b, c, d, e, F2, K2, 7, 4, x); - e, b = R(e, a, b, c, d, F2, K2, 14, 9, x); - d, a = R(d, e, a, b, c, F2, K2, 9, 15, x); - c, e = R(c, d, e, a, b, F2, K2, 13, 8, x); - b, d = R(b, c, d, e, a, F2, K2, 15, 1, x); - a, c = R(a, b, c, d, e, F2, K2, 14, 2, x); - e, b = R(e, a, b, c, d, F2, K2, 8, 7, x); - d, a = R(d, e, a, b, c, F2, K2, 13, 0, x); - c, e = R(c, d, e, a, b, F2, K2, 6, 6, x); - b, d = R(b, c, d, e, a, F2, K2, 5, 13, x); - a, c = R(a, b, c, d, e, F2, K2, 12, 11, x); - e, b = R(e, a, b, c, d, F2, K2, 7, 5, x); - d, a = R(d, e, a, b, c, F2, K2, 5, 12, x); #/* #47 */ + d, a = R(d, e, a, b, c, F2, K2, 11, 3, x) + c, e = R(c, d, e, a, b, F2, K2, 13, 10, x) + b, d = R(b, c, d, e, a, F2, K2, 6, 14, x) + a, c = R(a, b, c, d, e, F2, K2, 7, 4, x) + e, b = R(e, a, b, c, d, F2, K2, 14, 9, x) + d, a = R(d, e, a, b, c, F2, K2, 9, 15, x) + c, e = R(c, d, e, a, b, F2, K2, 13, 8, x) + b, d = R(b, c, d, e, a, F2, K2, 15, 1, x) + a, c = R(a, b, c, d, e, F2, K2, 14, 2, x) + e, b = R(e, a, b, c, d, F2, K2, 8, 7, x) + d, a = R(d, e, a, b, c, F2, K2, 13, 0, x) + c, e = R(c, d, e, a, b, F2, K2, 6, 6, x) + b, d = R(b, c, d, e, a, F2, K2, 5, 13, x) + a, c = R(a, b, c, d, e, F2, K2, 12, 11, x) + e, b = R(e, a, b, c, d, F2, K2, 7, 5, x) + d, a = R(d, e, a, b, c, F2, K2, 5, 12, x) #/* #47 */ #/* Round 4 */ - c, e = R(c, d, e, a, b, F3, K3, 11, 1, x); - b, d = R(b, c, d, e, a, F3, K3, 12, 9, x); - a, c = R(a, b, c, d, e, F3, K3, 14, 11, x); - e, b = R(e, a, b, c, d, F3, K3, 15, 10, x); - d, a = R(d, e, a, b, c, F3, K3, 14, 0, x); - c, e = R(c, d, e, a, b, F3, K3, 15, 8, x); - b, d = R(b, c, d, e, a, F3, K3, 9, 12, x); - a, c = R(a, b, c, d, e, F3, K3, 8, 4, x); - e, b = R(e, a, b, c, d, F3, K3, 9, 13, x); - d, a = R(d, e, a, b, c, F3, K3, 14, 3, x); - c, e = R(c, d, e, a, b, F3, K3, 5, 7, x); - b, d = R(b, c, d, e, a, F3, K3, 6, 15, x); - a, c = R(a, b, c, d, e, F3, K3, 8, 14, x); - e, b = R(e, a, b, c, d, F3, K3, 6, 5, x); - d, a = R(d, e, a, b, c, F3, K3, 5, 6, x); - c, e = R(c, d, e, a, b, F3, K3, 12, 2, x); #/* #63 */ + c, e = R(c, d, e, a, b, F3, K3, 11, 1, x) + b, d = R(b, c, d, e, a, F3, K3, 12, 9, x) + a, c = R(a, b, c, d, e, F3, K3, 14, 11, x) + e, b = R(e, a, b, c, d, F3, K3, 15, 10, x) + d, a = R(d, e, a, b, c, F3, K3, 14, 0, x) + c, e = R(c, d, e, a, b, F3, K3, 15, 8, x) + b, d = R(b, c, d, e, a, F3, K3, 9, 12, x) + a, c = R(a, b, c, d, e, F3, K3, 8, 4, x) + e, b = R(e, a, b, c, d, F3, K3, 9, 13, x) + d, a = R(d, e, a, b, c, F3, K3, 14, 3, x) + c, e = R(c, d, e, a, b, F3, K3, 5, 7, x) + b, d = R(b, c, d, e, a, F3, K3, 6, 15, x) + a, c = R(a, b, c, d, e, F3, K3, 8, 14, x) + e, b = R(e, a, b, c, d, F3, K3, 6, 5, x) + d, a = R(d, e, a, b, c, F3, K3, 5, 6, x) + c, e = R(c, d, e, a, b, F3, K3, 12, 2, x) #/* #63 */ #/* Round 5 */ - b, d = R(b, c, d, e, a, F4, K4, 9, 4, x); - a, c = R(a, b, c, d, e, F4, K4, 15, 0, x); - e, b = R(e, a, b, c, d, F4, K4, 5, 5, x); - d, a = R(d, e, a, b, c, F4, K4, 11, 9, x); - c, e = R(c, d, e, a, b, F4, K4, 6, 7, x); - b, d = R(b, c, d, e, a, F4, K4, 8, 12, x); - a, c = R(a, b, c, d, e, F4, K4, 13, 2, x); - e, b = R(e, a, b, c, d, F4, K4, 12, 10, x); - d, a = R(d, e, a, b, c, F4, K4, 5, 14, x); - c, e = R(c, d, e, a, b, F4, K4, 12, 1, x); - b, d = R(b, c, d, e, a, F4, K4, 13, 3, x); - a, c = R(a, b, c, d, e, F4, K4, 14, 8, x); - e, b = R(e, a, b, c, d, F4, K4, 11, 11, x); - d, a = R(d, e, a, b, c, F4, K4, 8, 6, x); - c, e = R(c, d, e, a, b, F4, K4, 5, 15, x); - b, d = R(b, c, d, e, a, F4, K4, 6, 13, x); #/* #79 */ - - aa = a; - bb = b; - cc = c; - dd = d; - ee = e; + b, d = R(b, c, d, e, a, F4, K4, 9, 4, x) + a, c = R(a, b, c, d, e, F4, K4, 15, 0, x) + e, b = R(e, a, b, c, d, F4, K4, 5, 5, x) + d, a = R(d, e, a, b, c, F4, K4, 11, 9, x) + c, e = R(c, d, e, a, b, F4, K4, 6, 7, x) + b, d = R(b, c, d, e, a, F4, K4, 8, 12, x) + a, c = R(a, b, c, d, e, F4, K4, 13, 2, x) + e, b = R(e, a, b, c, d, F4, K4, 12, 10, x) + d, a = R(d, e, a, b, c, F4, K4, 5, 14, x) + c, e = R(c, d, e, a, b, F4, K4, 12, 1, x) + b, d = R(b, c, d, e, a, F4, K4, 13, 3, x) + a, c = R(a, b, c, d, e, F4, K4, 14, 8, x) + e, b = R(e, a, b, c, d, F4, K4, 11, 11, x) + d, a = R(d, e, a, b, c, F4, K4, 8, 6, x) + c, e = R(c, d, e, a, b, F4, K4, 5, 15, x) + b, d = R(b, c, d, e, a, F4, K4, 6, 13, x) #/* #79 */ + + aa = a + bb = b + cc = c + dd = d + ee = e a = state[0] b = state[1] @@ -342,12 +342,12 @@ def RMD160Transform(state, block): #uint32 state[5], uchar block[64] c, e = R(c, d, e, a, b, F0, KK4, 11, 9, x) b, d = R(b, c, d, e, a, F0, KK4, 11, 11, x) #/* #79 */ - t = (state[1] + cc + d) % 0x100000000; - state[1] = (state[2] + dd + e) % 0x100000000; - state[2] = (state[3] + ee + a) % 0x100000000; - state[3] = (state[4] + aa + b) % 0x100000000; - state[4] = (state[0] + bb + c) % 0x100000000; - state[0] = t % 0x100000000; + t = (state[1] + cc + d) % 0x100000000 + state[1] = (state[2] + dd + e) % 0x100000000 + state[2] = (state[3] + ee + a) % 0x100000000 + state[3] = (state[4] + aa + b) % 0x100000000 + state[4] = (state[0] + bb + c) % 0x100000000 + state[0] = t % 0x100000000 pass diff --git a/electrum/rsakey.py b/electrum/rsakey.py index 3bac8e9db..da87076fe 100644 --- a/electrum/rsakey.py +++ b/electrum/rsakey.py @@ -49,11 +49,11 @@ def SHA1(x): # Check that os.urandom works import zlib length = len(zlib.compress(os.urandom(1000))) -assert(length > 900) +assert length > 900 def getRandomBytes(howMany): b = bytearray(os.urandom(howMany)) - assert(len(b) == howMany) + assert len(b) == howMany return b prngName = "os.urandom" diff --git a/electrum/scripts/ln_features.py b/electrum/scripts/ln_features.py index af2f94a1b..773eb84e4 100644 --- a/electrum/scripts/ln_features.py +++ b/electrum/scripts/ln_features.py @@ -69,7 +69,7 @@ async def worker(work_queue: asyncio.Queue, results_queue: asyncio.Queue, flag): # only check non-onion addresses addr = None for a in work['addrs']: - if not "onion" in a[0]: + if "onion" not in a[0]: addr = a if not addr: await results_queue.put(None) diff --git a/electrum/tests/test_commands.py b/electrum/tests/test_commands.py index 18295a3af..99ab167c6 100644 --- a/electrum/tests/test_commands.py +++ b/electrum/tests/test_commands.py @@ -305,8 +305,8 @@ class TestCommandsTestnet(TestCaseForTestnet): cmds = Commands(config=self.config) tx = "02000000000101b9723dfc69af058ef6613539a000d2cd098a2c8a74e802b6d8739db708ba8c9a0100000000fdffffff02a00f00000000000016001429e1fd187f0cac845946ae1b11dc136c536bfc0fe8b2000000000000160014100611bcb3aee7aad176936cf4ed56ade03027aa02473044022063c05e2347f16251922830ccc757231247b3c2970c225f988e9204844a1ab7b802204652d2c4816707e3d3bea2609b83b079001a435bad2a99cc2e730f276d07070c012102ee3f00141178006c78b0b458aab21588388335078c655459afe544211f15aee050721f00" - self.assertEqual("02000000000101b9723dfc69af058ef6613539a000d2cd098a2c8a74e802b6d8739db708ba8c9a0100000000fdffffff02a00f00000000000016001429e1fd187f0cac845946ae1b11dc136c536bfc0f84b2000000000000160014100611bcb3aee7aad176936cf4ed56ade03027aa0247304402203aa63539b673a3bd70a76482b17f35f8843974fab28f84143a00450789010bc40220779c2ce2d0217f973f1f6c9f718e19fc7ebd14dd8821a962f002437cda3082ec012102ee3f00141178006c78b0b458aab21588388335078c655459afe544211f15aee000000000", + self.assertEqual("02000000000101b9723dfc69af058ef6613539a000d2cd098a2c8a74e802b6d8739db708ba8c9a0100000000fdffffff02a00f00000000000016001429e1fd187f0cac845946ae1b11dc136c536bfc0f84b2000000000000160014100611bcb3aee7aad176936cf4ed56ade03027aa0247304402203aa63539b673a3bd70a76482b17f35f8843974fab28f84143a00450789010bc40220779c2ce2d0217f973f1f6c9f718e19fc7ebd14dd8821a962f002437cda3082ec012102ee3f00141178006c78b0b458aab21588388335078c655459afe544211f15aee000000000", cmds._run('bumpfee', (), tx=tx, new_fee_rate='1.6', wallet=wallet)) - self.assertEqual("02000000000101b9723dfc69af058ef6613539a000d2cd098a2c8a74e802b6d8739db708ba8c9a0100000000fdffffff02a00f00000000000016001429e1fd187f0cac845946ae1b11dc136c536bfc0f84b2000000000000160014100611bcb3aee7aad176936cf4ed56ade03027aa0247304402203aa63539b673a3bd70a76482b17f35f8843974fab28f84143a00450789010bc40220779c2ce2d0217f973f1f6c9f718e19fc7ebd14dd8821a962f002437cda3082ec012102ee3f00141178006c78b0b458aab21588388335078c655459afe544211f15aee000000000", + self.assertEqual("02000000000101b9723dfc69af058ef6613539a000d2cd098a2c8a74e802b6d8739db708ba8c9a0100000000fdffffff02a00f00000000000016001429e1fd187f0cac845946ae1b11dc136c536bfc0f84b2000000000000160014100611bcb3aee7aad176936cf4ed56ade03027aa0247304402203aa63539b673a3bd70a76482b17f35f8843974fab28f84143a00450789010bc40220779c2ce2d0217f973f1f6c9f718e19fc7ebd14dd8821a962f002437cda3082ec012102ee3f00141178006c78b0b458aab21588388335078c655459afe544211f15aee000000000", cmds._run('bumpfee', (), tx=tx, new_fee_rate='1.6', from_coins="9a8cba08b79d73d8b602e8748a2c8a09cdd200a0393561f68e05af69fc3d72b9:1", wallet=wallet)) diff --git a/electrum/tests/test_lnutil.py b/electrum/tests/test_lnutil.py index 0483e8b8e..e099f9b87 100644 --- a/electrum/tests/test_lnutil.py +++ b/electrum/tests/test_lnutil.py @@ -504,10 +504,10 @@ class TestLNUtil(ElectrumTestCase): htlc_obj = {} for num, msat in [(0, 1000 * 1000), - (2, 2000 * 1000), - (1, 2000 * 1000), - (3, 3000 * 1000), - (4, 4000 * 1000)]: + (2, 2000 * 1000), + (1, 2000 * 1000), + (3, 3000 * 1000), + (4, 4000 * 1000)]: htlc_obj[num] = UpdateAddHtlc(amount_msat=msat, payment_hash=bitcoin.sha256(htlc_payment_preimage[num]), cltv_expiry=0, htlc_id=None, timestamp=0) htlcs = [ScriptHtlc(htlc[x], htlc_obj[x]) for x in range(5)] @@ -901,4 +901,4 @@ class TestLNUtil(ElectrumTestCase): # ignore unknown channel types channel_type = ChannelType(0b10000000001000000000010).discard_unknown_and_check() - self.assertEqual(ChannelType(0b10000000001000000000000), channel_type) \ No newline at end of file + self.assertEqual(ChannelType(0b10000000001000000000000), channel_type) diff --git a/electrum/tests/test_util.py b/electrum/tests/test_util.py index 4968ca66f..3aab2e60f 100644 --- a/electrum/tests/test_util.py +++ b/electrum/tests/test_util.py @@ -71,14 +71,14 @@ class TestUtil(ElectrumTestCase): def test_format_satoshis_diff_negative(self): self.assertEqual("-0.00001234", format_satoshis(-1234, is_diff=True)) self.assertEqual("-456789.00001234", format_satoshis(-45678900001234, is_diff=True)) - + def test_format_satoshis_add_thousands_sep(self): self.assertEqual("178 890 000.", format_satoshis(Decimal(178890000), decimal_point=0, add_thousands_sep=True)) self.assertEqual("458 312.757 48", format_satoshis(Decimal("45831275.748"), decimal_point=2, add_thousands_sep=True, precision=5)) # is_diff self.assertEqual("+4 583 127.574 8", format_satoshis(Decimal("45831275.748"), decimal_point=1, is_diff=True, add_thousands_sep=True, precision=4)) - self.assertEqual("+456 789 112.004 56", format_satoshis(Decimal("456789112.00456"), decimal_point=0, is_diff=True, add_thousands_sep=True, precision=5)) - self.assertEqual("-0.000 012 34", format_satoshis(-1234, is_diff=True, add_thousands_sep=True)) + self.assertEqual("+456 789 112.004 56", format_satoshis(Decimal("456789112.00456"), decimal_point=0, is_diff=True, add_thousands_sep=True, precision=5)) + self.assertEqual("-0.000 012 34", format_satoshis(-1234, is_diff=True, add_thousands_sep=True)) self.assertEqual("-456 789.000 012 34", format_satoshis(-45678900001234, is_diff=True, add_thousands_sep=True)) # num_zeros self.assertEqual("-456 789.123 400", format_satoshis(-45678912340000, num_zeros=6, add_thousands_sep=True)) diff --git a/electrum/transaction.py b/electrum/transaction.py index f23eb22a9..4926f9887 100644 --- a/electrum/transaction.py +++ b/electrum/transaction.py @@ -1931,17 +1931,17 @@ class PartialTransaction(Transaction): if txin.is_segwit(): if bip143_shared_txdigest_fields is None: bip143_shared_txdigest_fields = self._calc_bip143_shared_txdigest_fields() - if not(sighash & Sighash.ANYONECANPAY): + if not (sighash & Sighash.ANYONECANPAY): hashPrevouts = bip143_shared_txdigest_fields.hashPrevouts else: hashPrevouts = '00' * 32 - if (not(sighash & Sighash.ANYONECANPAY) and (sighash & 0x1f) != Sighash.SINGLE and (sighash & 0x1f) != Sighash.NONE): + if not (sighash & Sighash.ANYONECANPAY) and (sighash & 0x1f) != Sighash.SINGLE and (sighash & 0x1f) != Sighash.NONE: hashSequence = bip143_shared_txdigest_fields.hashSequence else: hashSequence = '00' * 32 - if ((sighash & 0x1f) != Sighash.SINGLE and (sighash & 0x1f) != Sighash.NONE): + if (sighash & 0x1f) != Sighash.SINGLE and (sighash & 0x1f) != Sighash.NONE: hashOutputs = bip143_shared_txdigest_fields.hashOutputs - elif ((sighash & 0x1f) == Sighash.SINGLE and txin_index < len(outputs)): + elif (sighash & 0x1f) == Sighash.SINGLE and txin_index < len(outputs): hashOutputs = bh2u(sha256d(outputs[txin_index].serialize_to_network())) else: hashOutputs = '00' * 32 diff --git a/electrum/wizard.py b/electrum/wizard.py index 8f8d6378c..ca083336a 100644 --- a/electrum/wizard.py +++ b/electrum/wizard.py @@ -61,7 +61,7 @@ class AbstractWizard: else: self._logger.error(f'accept handler for view {view} not callable') - if not 'next' in nav: + if 'next' not in nav: # finished self.finished(wizard_data) return (None, wizard_data, {}) @@ -107,7 +107,7 @@ class AbstractWizard: nav = self.navmap[view] - if not 'last' in nav: + if 'last' not in nav: return False lastnav = nav['last'] @@ -219,7 +219,7 @@ class NewWalletWizard(AbstractWizard): storage = WalletStorage(path) k = None - if not 'keystore_type' in data: + if 'keystore_type' not in data: assert data['wallet_type'] == 'imported' addresses = {} if 'private_key_list' in data: