1
1
import struct
2
2
from unittest .mock import Mock , patch
3
3
4
+ import pytest
4
5
from cryptography .hazmat .primitives import hashes
5
6
from cryptography .hazmat .primitives .asymmetric import ec
6
7
@@ -999,7 +1000,7 @@ def test_op_sighash_bitmask(self) -> None:
999
1000
op_sighash_bitmask (ScriptContext (stack = [b'' ], extras = Mock (), logs = [], settings = Mock ()))
1000
1001
1001
1002
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 ()))
1003
1004
1004
1005
stack : list [bytes | int | str ] = [bytes ([0b0 ]), bytes ([0xFF , 0xFF ])]
1005
1006
context = Mock (spec_set = ScriptContext )
@@ -1010,20 +1011,20 @@ def test_op_sighash_bitmask(self) -> None:
1010
1011
with self .assertRaises (CustomSighashModelInvalid ):
1011
1012
op_sighash_bitmask (context )
1012
1013
1013
- context .stack = [bytes ([0b111 ]), bytes ([0b101 ])]
1014
+ context .stack = [bytes ([0b110 ]), bytes ([0b101 ])]
1014
1015
extras .input_index = 3
1015
1016
1016
1017
with self .assertRaises (InputNotSelectedError ):
1017
1018
op_sighash_bitmask (context )
1018
1019
1019
- context .stack = [bytes ([0b111 ]), bytes ([0b101 ])]
1020
+ context .stack = [bytes ([0b110 ]), bytes ([0b101 ])]
1020
1021
extras .input_index = 2
1021
1022
op_sighash_bitmask (context )
1022
1023
1023
1024
self .assertEqual (stack , [])
1024
1025
context .set_sighash .assert_called_once_with (
1025
1026
SighashBitmask (
1026
- inputs = 0b111 ,
1027
+ inputs = 0b110 ,
1027
1028
outputs = 0b101
1028
1029
)
1029
1030
)
@@ -1073,16 +1074,20 @@ def test_execute_op_code(self) -> None:
1073
1074
# Test that when `is_opcode_valid` returns False, execution must fail, regardless of the opcode.
1074
1075
with (
1075
1076
patch ('hathor.transaction.scripts.opcode.is_opcode_valid' , lambda _ : False ),
1076
- self . assertRaises (ScriptError )
1077
+ pytest . raises (ScriptError ) as e
1077
1078
):
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.'
1079
1083
1080
1084
# Test that when `is_opcode_valid` returns True, execution must fail if it's not a "function opcode".
1081
1085
with (
1082
1086
patch ('hathor.transaction.scripts.opcode.is_opcode_valid' , lambda _ : True ),
1083
- self . assertRaises (ScriptError )
1087
+ pytest . raises (ScriptError ) as e
1084
1088
):
1085
1089
execute_op_code (opcode = Opcode .OP_0 , context = Mock ())
1090
+ assert str (e .value ) == f'unknown opcode: { Opcode .OP_0 } '
1086
1091
1087
1092
# Test that a valid opcode is correctly executed.
1088
1093
with patch ('hathor.transaction.scripts.opcode.op_dup' ) as op_mock :
0 commit comments