Skip to content

Commit 86d10b4

Browse files
committed
review changes
1 parent fc82733 commit 86d10b4

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

tests/tx/scripts/test_script_context.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@
1717

1818
import pytest
1919

20+
from hathor.conf.settings import HathorSettings
2021
from hathor.transaction import Transaction, TxInput, TxOutput
2122
from hathor.transaction.exceptions import ScriptError
2223
from hathor.transaction.scripts.script_context import ScriptContext
2324
from hathor.transaction.scripts.sighash import SighashAll, SighashBitmask
2425

2526

26-
def test_defaults() -> None:
27-
settings = Mock()
28-
settings.MAX_NUM_OUTPUTS = 99
27+
@pytest.mark.parametrize(['max_num_outputs'], [(99,), (255,)])
28+
def test_defaults(max_num_outputs) -> None:
29+
settings = Mock(spec_set=HathorSettings)
30+
settings.MAX_NUM_OUTPUTS = max_num_outputs
2931

3032
context = ScriptContext(settings=settings, stack=Mock(), logs=[], extras=Mock())
3133

@@ -42,7 +44,7 @@ def test_defaults() -> None:
4244

4345
assert context._sighash == SighashAll()
4446
assert context.get_tx_sighash_data(tx) == tx.get_sighash_all_data()
45-
assert context.get_selected_outputs() == set(range(99))
47+
assert context.get_selected_outputs() == set(range(max_num_outputs))
4648

4749

4850
def test_set_sighash() -> None:

tests/tx/scripts/test_sighash.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ def test_sighash_bitmask_with_limit(self) -> None:
185185
atomic_swap_tx_clone.outputs.append(tokens_output)
186186

187187
# Bob adds two change outputs for his HTR, which violates the maximum tx outputs set by Alice
188-
htr_output1 = TxOutput(int(genesis_utxo.value / 4), bob_output_script)
189-
htr_output2 = TxOutput(int(genesis_utxo.value / 4), bob_output_script)
188+
htr_output1 = TxOutput(genesis_utxo.value // 4, bob_output_script)
189+
htr_output2 = TxOutput(genesis_utxo.value // 4, bob_output_script)
190190
atomic_swap_tx_clone.outputs.append(htr_output1)
191191
atomic_swap_tx_clone.outputs.append(htr_output2)
192192

tests/tx/test_scripts.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,18 +1062,21 @@ def test_op_max_inputs_outputs(self) -> None:
10621062
self.assertEqual(context.stack, [])
10631063

10641064
def test_execute_op_code(self) -> None:
1065+
# Test that when `is_opcode_valid` returns False, execution must fail, regardless of the opcode.
10651066
with (
10661067
patch('hathor.transaction.scripts.opcode.is_opcode_valid', lambda _: False),
10671068
self.assertRaises(ScriptError)
10681069
):
10691070
execute_op_code(opcode=Mock(), context=Mock())
10701071

1072+
# Test that when `is_opcode_valid` returns True, execution must fail if it's not a "function opcode".
10711073
with (
10721074
patch('hathor.transaction.scripts.opcode.is_opcode_valid', lambda _: True),
10731075
self.assertRaises(ScriptError)
10741076
):
10751077
execute_op_code(opcode=Opcode.OP_0, context=Mock())
10761078

1079+
# Test that a valid opcode is correctly executed.
10771080
with patch('hathor.transaction.scripts.opcode.op_dup') as op_mock:
10781081
execute_op_code(opcode=Opcode.OP_DUP, context=Mock())
10791082

0 commit comments

Comments
 (0)