Skip to content

Commit

Permalink
transaction: fix remove_signatures
Browse files Browse the repository at this point in the history
closes #5491
  • Loading branch information
SomberNight committed Jul 5, 2019
1 parent cc9ad3a commit aadde9b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 13 deletions.
53 changes: 40 additions & 13 deletions electrum/tests/test_wallet_vertical.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,20 @@ def test_sending_between_p2sh_1of2_and_p2wpkh_p2sh(self, mock_write):

@needs_test_with_all_ecc_implementations
@mock.patch.object(storage.WalletStorage, '_write')
def test_bump_fee_p2pkh_when_there_is_a_change_address(self, mock_write):
def test_rbf(self, mock_write):
for simulate_moving_txs in (False, True):
with self.subTest(msg="_bump_fee_p2pkh_when_there_is_a_change_address", simulate_moving_txs=simulate_moving_txs):
self._bump_fee_p2pkh_when_there_is_a_change_address(simulate_moving_txs=simulate_moving_txs)
with self.subTest(msg="_bump_fee_p2wpkh_when_there_is_a_change_address", simulate_moving_txs=simulate_moving_txs):
self._bump_fee_p2wpkh_when_there_is_a_change_address(simulate_moving_txs=simulate_moving_txs)
with self.subTest(msg="_bump_fee_when_user_sends_max", simulate_moving_txs=simulate_moving_txs):
self._bump_fee_when_user_sends_max(simulate_moving_txs=simulate_moving_txs)
with self.subTest(msg="_bump_fee_when_new_inputs_need_to_be_added", simulate_moving_txs=simulate_moving_txs):
self._bump_fee_when_new_inputs_need_to_be_added(simulate_moving_txs=simulate_moving_txs)
with self.subTest(msg="_rbf_batching", simulate_moving_txs=simulate_moving_txs):
self._rbf_batching(simulate_moving_txs=simulate_moving_txs)

def _bump_fee_p2pkh_when_there_is_a_change_address(self, *, simulate_moving_txs):
wallet = self.create_standard_wallet_from_seed('fold object utility erase deputy output stadium feed stereo usage modify bean')

# bootstrap wallet
Expand All @@ -877,6 +890,8 @@ def test_bump_fee_p2pkh_when_there_is_a_change_address(self, mock_write):
tx.set_rbf(True)
tx.locktime = 1325501
tx.version = 1
if simulate_moving_txs:
tx = Transaction(str(tx))
wallet.sign_transaction(tx, password=None)

self.assertTrue(tx.is_complete())
Expand All @@ -899,6 +914,8 @@ def test_bump_fee_p2pkh_when_there_is_a_change_address(self, mock_write):
tx = wallet.bump_fee(tx=Transaction(tx.serialize()), new_fee_rate=70.0, config=self.config)
tx.locktime = 1325501
tx.version = 1
if simulate_moving_txs:
tx = Transaction(str(tx))
self.assertFalse(tx.is_complete())

wallet.sign_transaction(tx, password=None)
Expand Down Expand Up @@ -947,9 +964,7 @@ def test_cpfp_p2pkh(self, mock_write):
wallet.receive_tx_callback(tx.txid(), tx, TX_HEIGHT_UNCONFIRMED)
self.assertEqual((0, funding_output_value - 50000, 0), wallet.get_balance())

@needs_test_with_all_ecc_implementations
@mock.patch.object(storage.WalletStorage, '_write')
def test_bump_fee_p2wpkh_when_there_is_a_change_address(self, mock_write):
def _bump_fee_p2wpkh_when_there_is_a_change_address(self, *, simulate_moving_txs):
wallet = self.create_standard_wallet_from_seed('frost repair depend effort salon ring foam oak cancel receive save usage')

# bootstrap wallet
Expand All @@ -966,6 +981,8 @@ def test_bump_fee_p2wpkh_when_there_is_a_change_address(self, mock_write):
tx.set_rbf(True)
tx.locktime = 1325499
tx.version = 1
if simulate_moving_txs:
tx = Transaction(str(tx))
wallet.sign_transaction(tx, password=None)

self.assertTrue(tx.is_complete())
Expand All @@ -988,6 +1005,8 @@ def test_bump_fee_p2wpkh_when_there_is_a_change_address(self, mock_write):
tx = wallet.bump_fee(tx=Transaction(tx.serialize()), new_fee_rate=70.0, config=self.config)
tx.locktime = 1325500
tx.version = 1
if simulate_moving_txs:
tx = Transaction(str(tx))
self.assertFalse(tx.is_complete())

wallet.sign_transaction(tx, password=None)
Expand All @@ -1002,9 +1021,7 @@ def test_bump_fee_p2wpkh_when_there_is_a_change_address(self, mock_write):
wallet.receive_tx_callback(tx.txid(), tx, TX_HEIGHT_UNCONFIRMED)
self.assertEqual((0, 7490060, 0), wallet.get_balance())

@needs_test_with_all_ecc_implementations
@mock.patch.object(storage.WalletStorage, '_write')
def test_bump_fee_when_user_sends_max(self, mock_write):
def _bump_fee_when_user_sends_max(self, *, simulate_moving_txs):
wallet = self.create_standard_wallet_from_seed('frost repair depend effort salon ring foam oak cancel receive save usage')

# bootstrap wallet
Expand All @@ -1020,6 +1037,8 @@ def test_bump_fee_when_user_sends_max(self, mock_write):
tx.set_rbf(True)
tx.locktime = 1325499
tx.version = 1
if simulate_moving_txs:
tx = Transaction(str(tx))
wallet.sign_transaction(tx, password=None)

self.assertTrue(tx.is_complete())
Expand All @@ -1042,6 +1061,8 @@ def test_bump_fee_when_user_sends_max(self, mock_write):
tx = wallet.bump_fee(tx=Transaction(tx.serialize()), new_fee_rate=70.0, config=self.config)
tx.locktime = 1325500
tx.version = 1
if simulate_moving_txs:
tx = Transaction(str(tx))
self.assertFalse(tx.is_complete())

wallet.sign_transaction(tx, password=None)
Expand All @@ -1056,9 +1077,7 @@ def test_bump_fee_when_user_sends_max(self, mock_write):
wallet.receive_tx_callback(tx.txid(), tx, TX_HEIGHT_UNCONFIRMED)
self.assertEqual((0, 0, 0), wallet.get_balance())

@needs_test_with_all_ecc_implementations
@mock.patch.object(storage.WalletStorage, '_write')
def test_bump_fee_when_new_inputs_need_to_be_added(self, mock_write):
def _bump_fee_when_new_inputs_need_to_be_added(self, *, simulate_moving_txs):
wallet = self.create_standard_wallet_from_seed('frost repair depend effort salon ring foam oak cancel receive save usage')

# bootstrap wallet (incoming funding_tx1)
Expand All @@ -1075,6 +1094,8 @@ def test_bump_fee_when_new_inputs_need_to_be_added(self, mock_write):
tx.set_rbf(True)
tx.locktime = 1325499
tx.version = 1
if simulate_moving_txs:
tx = Transaction(str(tx))
wallet.sign_transaction(tx, password=None)

self.assertTrue(tx.is_complete())
Expand Down Expand Up @@ -1105,6 +1126,8 @@ def test_bump_fee_when_new_inputs_need_to_be_added(self, mock_write):
tx = wallet.bump_fee(tx=Transaction(tx.serialize()), new_fee_rate=70.0, config=self.config)
tx.locktime = 1325500
tx.version = 1
if simulate_moving_txs:
tx = Transaction(str(tx))
self.assertFalse(tx.is_complete())

wallet.sign_transaction(tx, password=None)
Expand All @@ -1119,9 +1142,7 @@ def test_bump_fee_when_new_inputs_need_to_be_added(self, mock_write):
wallet.receive_tx_callback(tx.txid(), tx, TX_HEIGHT_UNCONFIRMED)
self.assertEqual((0, 4_990_300, 0), wallet.get_balance())

@needs_test_with_all_ecc_implementations
@mock.patch.object(storage.WalletStorage, '_write')
def test_rbf_batching(self, mock_write):
def _rbf_batching(self, *, simulate_moving_txs):
wallet = self.create_standard_wallet_from_seed('frost repair depend effort salon ring foam oak cancel receive save usage')
config = SimpleConfig({'electrum_path': self.electrum_path, 'batch_rbf': True})

Expand All @@ -1139,6 +1160,8 @@ def test_rbf_batching(self, mock_write):
tx.set_rbf(True)
tx.locktime = 1325499
tx.version = 1
if simulate_moving_txs:
tx = Transaction(str(tx))
wallet.sign_transaction(tx, password=None)

self.assertTrue(tx.is_complete())
Expand Down Expand Up @@ -1173,6 +1196,8 @@ def test_rbf_batching(self, mock_write):
tx.set_rbf(True)
tx.locktime = 1325499
tx.version = 1
if simulate_moving_txs:
tx = Transaction(str(tx))
wallet.sign_transaction(tx, password=None)

self.assertTrue(tx.is_complete())
Expand All @@ -1199,6 +1224,8 @@ def test_rbf_batching(self, mock_write):
tx.set_rbf(True)
tx.locktime = 1325499
tx.version = 1
if simulate_moving_txs:
tx = Transaction(str(tx))
wallet.sign_transaction(tx, password=None)

self.assertTrue(tx.is_complete())
Expand Down
3 changes: 3 additions & 0 deletions electrum/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,10 @@ def add_inputs_info(self, wallet):
def remove_signatures(self):
for txin in self.inputs():
txin['signatures'] = [None] * len(txin['signatures'])
txin['scriptSig'] = None
txin['witness'] = None
assert not self.is_complete()
self.raw = None

def deserialize(self, force_full_parse=False):
if self.raw is None:
Expand Down

0 comments on commit aadde9b

Please sign in to comment.