24
24
from hathor .transaction .exceptions import InputOutputMismatch , InvalidInputData , InvalidScriptError
25
25
from hathor .transaction .scripts .p2pkh import P2PKH
26
26
from hathor .transaction .scripts .sighash import InputsOutputsLimit , SighashBitmask
27
+ from hathor .transaction .static_metadata import TransactionStaticMetadata
27
28
from hathor .util import not_none
28
29
from tests import unittest
29
30
from tests .utils import add_blocks_unlock_reward , create_tokens , get_genesis_key
30
31
31
32
32
- class BaseSighashTest (unittest .TestCase ):
33
- __test__ = False
34
-
33
+ class SighashTest (unittest .TestCase ):
35
34
def setUp (self ) -> None :
36
35
super ().setUp ()
37
36
self .manager1 : HathorManager = self .create_peer ('testnet' , unlock_wallet = True , wallet_index = True )
@@ -80,7 +79,6 @@ def test_sighash_bitmask(self) -> None:
80
79
storage = self .manager1 .tx_storage ,
81
80
timestamp = token_creation_tx .timestamp + 1
82
81
)
83
- self .manager1 .cpu_mining_service .resolve (atomic_swap_tx )
84
82
85
83
# Alice signs her input using sighash bitmasks, instead of sighash_all.
86
84
sighash_bitmask = SighashBitmask (inputs = 0b1 , outputs = 0b1 )
@@ -93,14 +91,19 @@ def test_sighash_bitmask(self) -> None:
93
91
sighash = sighash_bitmask ,
94
92
)
95
93
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
+
96
100
# At this point, the tx is partial. The inputs are valid, but they're mismatched with outputs
97
101
self .manager1 .verification_service .verifiers .tx .verify_inputs (atomic_swap_tx )
98
102
with pytest .raises (InputOutputMismatch ):
99
103
self .manager1 .verification_service .verify (atomic_swap_tx )
100
104
101
105
# Alice sends the tx bytes to Bob, represented here by cloning the tx
102
106
atomic_swap_tx_clone = cast (Transaction , atomic_swap_tx .clone ())
103
- self .manager1 .cpu_mining_service .resolve (atomic_swap_tx_clone )
104
107
105
108
# Bob creates an input spending all genesis HTR and adds it to the atomic swap tx
106
109
htr_input = TxInput (not_none (self .genesis_block .hash ), 0 , b'' )
@@ -122,6 +125,7 @@ def test_sighash_bitmask(self) -> None:
122
125
htr_input .data = P2PKH .create_input_data (public_bytes2 , signature2 )
123
126
124
127
# The atomic swap tx is now completed and valid, and can be propagated
128
+ self .manager1 .cpu_mining_service .resolve (atomic_swap_tx_clone )
125
129
self .manager1 .verification_service .verify (atomic_swap_tx_clone )
126
130
self .manager1 .propagate_tx (atomic_swap_tx_clone , fails_silently = False )
127
131
@@ -151,7 +155,6 @@ def test_sighash_bitmask_with_limit(self) -> None:
151
155
storage = self .manager1 .tx_storage ,
152
156
timestamp = token_creation_tx .timestamp + 1
153
157
)
154
- self .manager1 .cpu_mining_service .resolve (atomic_swap_tx )
155
158
156
159
# Alice signs her input using sighash bitmasks, instead of sighash_all.
157
160
# 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:
167
170
)
168
171
169
172
# 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 )
170
174
self .manager1 .verification_service .verifiers .tx .verify_inputs (atomic_swap_tx )
171
175
with pytest .raises (InputOutputMismatch ):
172
176
self .manager1 .verification_service .verify (atomic_swap_tx )
173
177
174
178
# Alice sends the tx bytes to Bob, represented here by cloning the tx
175
179
atomic_swap_tx_clone = cast (Transaction , atomic_swap_tx .clone ())
176
- self .manager1 .cpu_mining_service .resolve (atomic_swap_tx_clone )
177
180
178
181
# Bob creates an input spending all genesis HTR and adds it to the atomic swap tx
179
182
htr_input = TxInput (not_none (self .genesis_block .hash ), 0 , b'' )
@@ -197,6 +200,7 @@ def test_sighash_bitmask_with_limit(self) -> None:
197
200
htr_input .data = P2PKH .create_input_data (public_bytes2 , signature2 )
198
201
199
202
# The atomic swap tx is not valid and cannot be propagated
203
+ self .manager1 .cpu_mining_service .resolve (atomic_swap_tx_clone )
200
204
with pytest .raises (InvalidInputData ) as e :
201
205
self .manager1 .verification_service .verify (atomic_swap_tx_clone )
202
206
@@ -306,16 +310,3 @@ def test_sighash_bitmask_nonexistent_input(self) -> None:
306
310
307
311
with pytest .raises (InvalidScriptError ):
308
312
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