Skip to content

Commit 9147127

Browse files
committed
fix tests
1 parent 890c630 commit 9147127

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

tests/tx/scripts/test_sighash.py

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@
2424
from hathor.transaction.exceptions import InputOutputMismatch, InvalidInputData, InvalidScriptError
2525
from hathor.transaction.scripts.p2pkh import P2PKH
2626
from hathor.transaction.scripts.sighash import InputsOutputsLimit, SighashBitmask
27+
from hathor.transaction.static_metadata import TransactionStaticMetadata
2728
from hathor.util import not_none
2829
from tests import unittest
2930
from tests.utils import add_blocks_unlock_reward, create_tokens, get_genesis_key
3031

3132

32-
class BaseSighashTest(unittest.TestCase):
33-
__test__ = False
34-
33+
class SighashTest(unittest.TestCase):
3534
def setUp(self) -> None:
3635
super().setUp()
3736
self.manager1: HathorManager = self.create_peer('testnet', unlock_wallet=True, wallet_index=True)
@@ -80,7 +79,6 @@ def test_sighash_bitmask(self) -> None:
8079
storage=self.manager1.tx_storage,
8180
timestamp=token_creation_tx.timestamp + 1
8281
)
83-
self.manager1.cpu_mining_service.resolve(atomic_swap_tx)
8482

8583
# Alice signs her input using sighash bitmasks, instead of sighash_all.
8684
sighash_bitmask = SighashBitmask(inputs=0b1, outputs=0b1)
@@ -93,14 +91,19 @@ def test_sighash_bitmask(self) -> None:
9391
sighash=sighash_bitmask,
9492
)
9593

94+
self.manager1.cpu_mining_service.resolve(atomic_swap_tx)
95+
static_metadata = TransactionStaticMetadata.create_from_storage(
96+
atomic_swap_tx, self._settings, self.manager1.tx_storage
97+
)
98+
atomic_swap_tx.set_static_metadata(static_metadata)
99+
96100
# At this point, the tx is partial. The inputs are valid, but they're mismatched with outputs
97101
self.manager1.verification_service.verifiers.tx.verify_inputs(atomic_swap_tx)
98102
with pytest.raises(InputOutputMismatch):
99103
self.manager1.verification_service.verify(atomic_swap_tx)
100104

101105
# Alice sends the tx bytes to Bob, represented here by cloning the tx
102106
atomic_swap_tx_clone = cast(Transaction, atomic_swap_tx.clone())
103-
self.manager1.cpu_mining_service.resolve(atomic_swap_tx_clone)
104107

105108
# Bob creates an input spending all genesis HTR and adds it to the atomic swap tx
106109
htr_input = TxInput(not_none(self.genesis_block.hash), 0, b'')
@@ -122,6 +125,7 @@ def test_sighash_bitmask(self) -> None:
122125
htr_input.data = P2PKH.create_input_data(public_bytes2, signature2)
123126

124127
# The atomic swap tx is now completed and valid, and can be propagated
128+
self.manager1.cpu_mining_service.resolve(atomic_swap_tx_clone)
125129
self.manager1.verification_service.verify(atomic_swap_tx_clone)
126130
self.manager1.propagate_tx(atomic_swap_tx_clone, fails_silently=False)
127131

@@ -151,7 +155,6 @@ def test_sighash_bitmask_with_limit(self) -> None:
151155
storage=self.manager1.tx_storage,
152156
timestamp=token_creation_tx.timestamp + 1
153157
)
154-
self.manager1.cpu_mining_service.resolve(atomic_swap_tx)
155158

156159
# Alice signs her input using sighash bitmasks, instead of sighash_all.
157160
# She also sets max inputs and max outputs limits, including one output for change.
@@ -167,13 +170,13 @@ def test_sighash_bitmask_with_limit(self) -> None:
167170
)
168171

169172
# At this point, the tx is partial. The inputs are valid, but they're mismatched with outputs
173+
self.manager1.cpu_mining_service.resolve(atomic_swap_tx)
170174
self.manager1.verification_service.verifiers.tx.verify_inputs(atomic_swap_tx)
171175
with pytest.raises(InputOutputMismatch):
172176
self.manager1.verification_service.verify(atomic_swap_tx)
173177

174178
# Alice sends the tx bytes to Bob, represented here by cloning the tx
175179
atomic_swap_tx_clone = cast(Transaction, atomic_swap_tx.clone())
176-
self.manager1.cpu_mining_service.resolve(atomic_swap_tx_clone)
177180

178181
# Bob creates an input spending all genesis HTR and adds it to the atomic swap tx
179182
htr_input = TxInput(not_none(self.genesis_block.hash), 0, b'')
@@ -197,6 +200,7 @@ def test_sighash_bitmask_with_limit(self) -> None:
197200
htr_input.data = P2PKH.create_input_data(public_bytes2, signature2)
198201

199202
# The atomic swap tx is not valid and cannot be propagated
203+
self.manager1.cpu_mining_service.resolve(atomic_swap_tx_clone)
200204
with pytest.raises(InvalidInputData) as e:
201205
self.manager1.verification_service.verify(atomic_swap_tx_clone)
202206

@@ -306,16 +310,3 @@ def test_sighash_bitmask_nonexistent_input(self) -> None:
306310

307311
with pytest.raises(InvalidScriptError):
308312
self.manager1.verification_service.verify(atomic_swap_tx)
309-
310-
311-
class SyncV1SighashTest(unittest.SyncV1Params, BaseSighashTest):
312-
__test__ = True
313-
314-
315-
class SyncV2SighashTest(unittest.SyncV2Params, BaseSighashTest):
316-
__test__ = True
317-
318-
319-
# sync-bridge should behave like sync-v2
320-
class SyncBridgeSighashTest(unittest.SyncBridgeParams, SyncV2SighashTest):
321-
pass

0 commit comments

Comments
 (0)