|
1 | 1 | import pytest |
2 | 2 |
|
3 | 3 | from eth_utils import ( |
| 4 | + decode_hex, |
| 5 | + encode_hex, |
4 | 6 | to_canonical_address, |
| 7 | + int_to_big_endian, |
5 | 8 | ) |
6 | 9 |
|
7 | 10 | from eth import ( |
8 | 11 | constants |
9 | 12 | ) |
| 13 | +from eth.utils.padding import ( |
| 14 | + pad32 |
| 15 | +) |
10 | 16 | from eth.vm import ( |
11 | 17 | opcode_values |
12 | 18 | ) |
13 | | -from eth.vm.forks.byzantium.opcodes import ( |
14 | | - BYZANTIUM_OPCODES |
15 | | -) |
16 | 19 | from eth.vm.forks import ( |
| 20 | + ConstantinopleVM, |
17 | 21 | ByzantiumVM, |
18 | 22 | SpuriousDragonVM, |
19 | 23 | TangerineWhistleVM, |
@@ -98,3 +102,84 @@ def test_mul(vm_class, val1, val2, expected): |
98 | 102 | assert result == expected |
99 | 103 |
|
100 | 104 |
|
| 105 | +@pytest.mark.parametrize( |
| 106 | + # Testcases from https://github.com/ethereum/EIPs/blob/master/EIPS/eip-145.md#shl-shift-left |
| 107 | + 'vm_class, val1, val2, expected', |
| 108 | + ( |
| 109 | + ( |
| 110 | + ConstantinopleVM, |
| 111 | + '0x0000000000000000000000000000000000000000000000000000000000000001', |
| 112 | + '0x00', |
| 113 | + '0x0000000000000000000000000000000000000000000000000000000000000001', |
| 114 | + ), |
| 115 | + ( |
| 116 | + ConstantinopleVM, |
| 117 | + '0x0000000000000000000000000000000000000000000000000000000000000001', |
| 118 | + '0x01', |
| 119 | + '0x0000000000000000000000000000000000000000000000000000000000000002', |
| 120 | + ), |
| 121 | + ( |
| 122 | + ConstantinopleVM, |
| 123 | + '0x0000000000000000000000000000000000000000000000000000000000000001', |
| 124 | + '0xff', |
| 125 | + '0x8000000000000000000000000000000000000000000000000000000000000000', |
| 126 | + ), |
| 127 | + ( |
| 128 | + ConstantinopleVM, |
| 129 | + '0x0000000000000000000000000000000000000000000000000000000000000001', |
| 130 | + '0x0100', |
| 131 | + '0x0000000000000000000000000000000000000000000000000000000000000000', |
| 132 | + ), |
| 133 | + ( |
| 134 | + ConstantinopleVM, |
| 135 | + '0x0000000000000000000000000000000000000000000000000000000000000001', |
| 136 | + '0x0101', |
| 137 | + '0x0000000000000000000000000000000000000000000000000000000000000000', |
| 138 | + ), |
| 139 | + ( |
| 140 | + ConstantinopleVM, |
| 141 | + '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', |
| 142 | + '0x00', |
| 143 | + '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', |
| 144 | + ), |
| 145 | + ( |
| 146 | + ConstantinopleVM, |
| 147 | + '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', |
| 148 | + '0x01', |
| 149 | + '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe', |
| 150 | + ), |
| 151 | + ( |
| 152 | + ConstantinopleVM, |
| 153 | + '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', |
| 154 | + '0xff', |
| 155 | + '0x8000000000000000000000000000000000000000000000000000000000000000', |
| 156 | + ), |
| 157 | + ( |
| 158 | + ConstantinopleVM, |
| 159 | + '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', |
| 160 | + '0x0100', |
| 161 | + '0x0000000000000000000000000000000000000000000000000000000000000000', |
| 162 | + ), |
| 163 | + ( |
| 164 | + ConstantinopleVM, |
| 165 | + '0x0000000000000000000000000000000000000000000000000000000000000000', |
| 166 | + '0x01', |
| 167 | + '0x0000000000000000000000000000000000000000000000000000000000000000', |
| 168 | + ), |
| 169 | + ( |
| 170 | + ConstantinopleVM, |
| 171 | + '0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', |
| 172 | + '0x01', |
| 173 | + '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe', |
| 174 | + ), |
| 175 | + ) |
| 176 | +) |
| 177 | +def test_shl(vm_class, val1, val2, expected): |
| 178 | + computation = prepare_computation(vm_class) |
| 179 | + computation.stack_push(decode_hex(val1)) |
| 180 | + computation.stack_push(decode_hex(val2)) |
| 181 | + computation.opcodes[opcode_values.SHL](computation) |
| 182 | + |
| 183 | + result = computation.stack_pop(type_hint=constants.UINT256) |
| 184 | + |
| 185 | + assert encode_hex(pad32(int_to_big_endian(result))) == expected |
0 commit comments