Skip to content

Commit 75790a3

Browse files
committed
review changes
1 parent 9147127 commit 75790a3

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

tests/tx/test_scripts.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import struct
22
from unittest.mock import Mock, patch
33

4+
import pytest
45
from cryptography.hazmat.primitives import hashes
56
from cryptography.hazmat.primitives.asymmetric import ec
67

@@ -999,7 +1000,7 @@ def test_op_sighash_bitmask(self) -> None:
9991000
op_sighash_bitmask(ScriptContext(stack=[b''], extras=Mock(), logs=[], settings=Mock()))
10001001

10011002
with self.assertRaises(AssertionError):
1002-
op_sighash_bitmask(ScriptContext(stack=[0b111, 0b101], extras=Mock(), logs=[], settings=Mock()))
1003+
op_sighash_bitmask(ScriptContext(stack=[0b110, 0b101], extras=Mock(), logs=[], settings=Mock()))
10031004

10041005
stack: list[bytes | int | str] = [bytes([0b0]), bytes([0xFF, 0xFF])]
10051006
context = Mock(spec_set=ScriptContext)
@@ -1010,20 +1011,20 @@ def test_op_sighash_bitmask(self) -> None:
10101011
with self.assertRaises(CustomSighashModelInvalid):
10111012
op_sighash_bitmask(context)
10121013

1013-
context.stack = [bytes([0b111]), bytes([0b101])]
1014+
context.stack = [bytes([0b110]), bytes([0b101])]
10141015
extras.input_index = 3
10151016

10161017
with self.assertRaises(InputNotSelectedError):
10171018
op_sighash_bitmask(context)
10181019

1019-
context.stack = [bytes([0b111]), bytes([0b101])]
1020+
context.stack = [bytes([0b110]), bytes([0b101])]
10201021
extras.input_index = 2
10211022
op_sighash_bitmask(context)
10221023

10231024
self.assertEqual(stack, [])
10241025
context.set_sighash.assert_called_once_with(
10251026
SighashBitmask(
1026-
inputs=0b111,
1027+
inputs=0b110,
10271028
outputs=0b101
10281029
)
10291030
)
@@ -1073,16 +1074,20 @@ def test_execute_op_code(self) -> None:
10731074
# Test that when `is_opcode_valid` returns False, execution must fail, regardless of the opcode.
10741075
with (
10751076
patch('hathor.transaction.scripts.opcode.is_opcode_valid', lambda _: False),
1076-
self.assertRaises(ScriptError)
1077+
pytest.raises(ScriptError) as e
10771078
):
1078-
execute_op_code(opcode=Mock(), context=Mock())
1079+
opcode = Mock()
1080+
opcode.name = 'MyOp'
1081+
execute_op_code(opcode=opcode, context=Mock())
1082+
assert str(e.value) == 'Opcode "MyOp" is invalid.'
10791083

10801084
# Test that when `is_opcode_valid` returns True, execution must fail if it's not a "function opcode".
10811085
with (
10821086
patch('hathor.transaction.scripts.opcode.is_opcode_valid', lambda _: True),
1083-
self.assertRaises(ScriptError)
1087+
pytest.raises(ScriptError) as e
10841088
):
10851089
execute_op_code(opcode=Opcode.OP_0, context=Mock())
1090+
assert str(e.value) == f'unknown opcode: {Opcode.OP_0}'
10861091

10871092
# Test that a valid opcode is correctly executed.
10881093
with patch('hathor.transaction.scripts.opcode.op_dup') as op_mock:

0 commit comments

Comments
 (0)