Skip to content

Commit 1cc7c43

Browse files
committed
python: contrib: fix linter issues
1 parent 70a3403 commit 1cc7c43

File tree

6 files changed

+17
-19
lines changed

6 files changed

+17
-19
lines changed

src/swig_python/contrib/elements_tx.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ def test_tx(self):
8686
tx_add_output(tx, tx_output)
8787
ct_value = tx_confidential_value_from_satoshi(20000)
8888
tx_add_elements_raw_output(tx, script, None, ct_value, None, None, None, 0)
89-
size = tx_get_length(tx, 0)
90-
vsize = tx_vsize_from_weight(tx_get_weight(tx))
89+
tx_get_length(tx, 0)
90+
tx_vsize_from_weight(tx_get_weight(tx))
9191
for extra_flags in (0, WALLY_TX_FLAG_USE_ELEMENTS, WALLY_TX_FLAG_ALLOW_PARTIAL):
9292
tx_hex = tx_to_hex(tx, WALLY_TX_FLAG_USE_WITNESS | extra_flags)
9393
tx_bytes = tx_to_bytes(tx, WALLY_TX_FLAG_USE_WITNESS | extra_flags)

src/swig_python/contrib/mnemonic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ def to_seed(self, mnemonic, passphrase = ''):
5050
try:
5151
m.generate(BIP39_ENTROPY_LEN_256 - 1)
5252
assert False
53-
except:
53+
except Exception as _:
5454
pass
5555
try:
5656
m.check(phrase + ' foo')
5757
assert False
58-
except:
58+
except Exception as _:
5959
pass
6060
assert m.to_entropy(phrase) == m.to_entropy(phrase.split())
6161
assert m.to_mnemonic(m.to_entropy(phrase)) == phrase

src/swig_python/contrib/psbt.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def test_add_remove_tx_items(self):
150150
asset = hex_to_bytes('77' * 32)
151151
explicit_asset = hex_to_bytes('01' + '77' * 32)
152152
blinded_asset = hex_to_bytes('0a' + '77' * 32) # Dummy value
153-
explicit_value = tx_confidential_value_from_satoshi(1234)
153+
explicit_value = tx_confidential_value_from_satoshi(value)
154154
blinded_value = hex_to_bytes('08' + '55' * 32) # Dummy value
155155

156156
# Inputs: BTC
@@ -166,9 +166,9 @@ def test_add_remove_tx_items(self):
166166

167167
# Outputs: BTC
168168
psbt2 = psbt_init(2, 0, 0, 0, 0)
169-
tx_output = tx_output_init(1234, script)
169+
tx_output = tx_output_init(value, script)
170170
psbt_add_tx_output_at(psbt2, 0, 0, tx_output)
171-
self.assertEqual(psbt_get_output_amount(psbt2, 0), 1234)
171+
self.assertEqual(psbt_get_output_amount(psbt2, 0), value)
172172
self.assertEqual(psbt_get_output_script(psbt2, 0), script)
173173

174174
if is_elements_build():
@@ -180,7 +180,7 @@ def test_add_remove_tx_items(self):
180180
# txout has explicit value/asset: Expect the values
181181
# set and no commitments in the PSET
182182
self.assertEqual(psbt_has_output_amount(pset2, 0), 1)
183-
self.assertEqual(psbt_get_output_amount(pset2, 0), 1234)
183+
self.assertEqual(psbt_get_output_amount(pset2, 0), value)
184184
self.assertEqual(psbt_get_output_value_commitment_len(pset2, 0), 0)
185185
self.assertTrue(not psbt_get_output_value_commitment(pset2, 0))
186186
self.assertEqual(psbt_get_output_script(pset2, 0), script)
@@ -339,7 +339,6 @@ def test_psbt(self):
339339
dummy_tap_internal_key = bytearray(b'\x01' * 32) # Untweaked x-only pubkey
340340
if is_elements_build():
341341
dummy_nonce = bytearray(b'\x00' * WALLY_TX_ASSET_CT_NONCE_LEN)
342-
dummy_bf = bytearray(b'\x00' * BLINDING_FACTOR_LEN)
343342
dummy_blind_asset = bytearray(b'\x0a' * ASSET_COMMITMENT_LEN)
344343
dummy_blind_value = bytearray(b'\x08' * WALLY_TX_ASSET_CT_VALUE_UNBLIND_LEN)
345344
dummy_nonce = bytearray(b'\x02' * ASSET_COMMITMENT_LEN)

src/swig_python/contrib/reconcile_sigs.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
except ImportError:
99
have_pycoin = False
1010

11-
USE_WITNESS = 1
1211

1312
class TxTests(unittest.TestCase):
1413

1514
def do_test_tx(self, sighash, index_, flags):
16-
txhash, seq, script, witness_script = b'0' * 32, 0xffffffff, b'\x51', b'000000'
15+
txhash, seq, script = b'0' * 32, 0xffffffff, b'\x51'
1716
out_script, spend_script, locktime = b'\x00\x00\x51', b'\x00\x51', 999999
1817
txs_in = [TxIn(txhash, 0, script, seq),
1918
TxIn(txhash, 1, script+b'\x51', seq-1),
@@ -29,7 +28,7 @@ def do_test_tx(self, sighash, index_, flags):
2928
3: TxOut(5003, spend_script)}
3029
unspent = pytx.unspents[index_]
3130
pytx_hex = pytx.as_hex()
32-
if flags & USE_WITNESS:
31+
if flags & WALLY_TX_FLAG_USE_WITNESS:
3332
pytx_hash = pytx.signature_for_hash_type_segwit(unspent.script, index_, sighash)
3433
else:
3534
pytx_hash = pytx.signature_hash(spend_script, index_, sighash)
@@ -44,7 +43,6 @@ def do_test_tx(self, sighash, index_, flags):
4443
tx_add_raw_output(tx, 54, out_script+b'\x51', 0)
4544
tx_add_raw_output(tx, 53, out_script+b'\x51\x51', 0)
4645
tx_hex = tx_to_hex(tx, 0)
47-
amount = (index_ + 1) * 5000
4846
tx_hash = tx_get_btc_signature_hash(tx, index_,
4947
unspent.script, unspent.coin_value,
5048
sighash, flags)
@@ -57,7 +55,7 @@ def test_tx(self):
5755
for sighash in [WALLY_SIGHASH_ALL, WALLY_SIGHASH_NONE, WALLY_SIGHASH_SINGLE]:
5856
for index_ in [0, 1, 2, 3]:
5957
for anyonecanpay in [0, WALLY_SIGHASH_ANYONECANPAY]:
60-
for flags in [0, USE_WITNESS]:
58+
for flags in [0, WALLY_TX_FLAG_USE_WITNESS]:
6159
self.do_test_tx(sighash | anyonecanpay, index_, flags)
6260

6361

src/swig_python/contrib/signmessage.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ def test_signmessage(self):
2727
message = 'This is just a test message'.encode('ascii')
2828
priv_key_wif = 'cUeKHd5orzT3mz8P9pxyREHfsWtVfgsfDjiZZBcjUBAaGk1BTj7N'
2929
address = 'mpLQjfK79b7CCV4VMJWEWAj5Mpx8Up5zxB'
30-
expected_signature = 'INbVnW4e6PeRmsv2Qgu8NuopvrVjkcxob+sX8OcZG0SALhWybUjzMLPdAsXI46YZGb0KQTRii+wWIQzRpG/U+S0='
30+
expected_signature = b'INbVnW4e6PeRmsv2Qgu8NuopvrVjkcxob+sX8OcZG0SALhWybUjzMLPdAsXI46YZGb0KQTRii+wWIQzRpG/U+S0='
3131

3232
signature = self.signmessage(priv_key_wif, message)
33+
self.assertEqual(signature, expected_signature)
3334
self.assertTrue(self.verifymessage(address, signature, message))
3435

3536

src/swig_python/contrib/tx.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_tx_witness(self):
1919

2020
with self.assertRaises(ValueError):
2121
tx_witness_stack_clone(None)
22-
cloned = tx_witness_stack_clone(witness)
22+
tx_witness_stack_clone(witness)
2323

2424
def test_tx_input(self):
2525
# Test invalid inputs
@@ -101,9 +101,9 @@ def test_tx(self):
101101
self.assertEqual(tx_get_total_output_satoshi(tx), 10000)
102102
tx_add_raw_output(tx, 20000, script, 0)
103103
self.assertEqual(tx_get_total_output_satoshi(tx), 30000)
104-
size = tx_get_length(tx, 0)
105-
vsize = tx_vsize_from_weight(tx_get_weight(tx))
106-
tx_hex = tx_to_hex(tx, FLAG_USE_WITNESS)
104+
tx_get_length(tx, 0)
105+
tx_vsize_from_weight(tx_get_weight(tx))
106+
tx_to_hex(tx, FLAG_USE_WITNESS)
107107

108108
with self.assertRaises(ValueError):
109109
tx_add_raw_output(tx, WALLY_SATOSHI_MAX + 1, script, 0)

0 commit comments

Comments
 (0)