File tree Expand file tree Collapse file tree 4 files changed +32
-4
lines changed Expand file tree Collapse file tree 4 files changed +32
-4
lines changed Original file line number Diff line number Diff line change
1
+ import Common from 'ethereumjs-common'
2
+
1
3
export interface Opcode {
2
4
name : string
3
5
fee : number
@@ -180,8 +182,8 @@ const istanbulOpcodes: OpcodeList = {
180
182
0x54 : { name : 'SLOAD' , fee : 800 , isAsync : true } ,
181
183
}
182
184
183
- export function getOpcodesForHF ( hf : string ) {
184
- if ( hf === 'istanbul' ) {
185
+ export function getOpcodesForHF ( common : Common ) {
186
+ if ( common . gteHardfork ( 'istanbul' ) ) {
185
187
return { ...opcodes , ...istanbulOpcodes }
186
188
} else {
187
189
return { ...opcodes }
Original file line number Diff line number Diff line change @@ -110,7 +110,7 @@ export default class VM extends AsyncEventEmitter {
110
110
}
111
111
112
112
// Set list of opcodes based on HF
113
- this . _opcodes = getOpcodesForHF ( this . _common . hardfork ( ) ! )
113
+ this . _opcodes = getOpcodesForHF ( this . _common )
114
114
115
115
if ( opts . stateManager ) {
116
116
this . stateManager = opts . stateManager
Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ tape('VM with default blockchain', (t) => {
43
43
} )
44
44
45
45
t . test ( 'should accept a common object as option' , ( st ) => {
46
- const common = new Common ( 'mainnet' )
46
+ const common = new Common ( 'mainnet' , 'istanbul' )
47
47
48
48
const vm = new VM ( { common } )
49
49
st . equal ( vm . _common , common )
Original file line number Diff line number Diff line change
1
+ const tape = require ( 'tape' )
2
+ const { getOpcodesForHF } = require ( '../../dist/evm/opcodes' )
3
+ const Common = require ( 'ethereumjs-common' ) . default
4
+
5
+ const CHAINID = 0x46
6
+
7
+ tape ( 'getOpcodesForHF' , ( t ) => {
8
+ t . test ( 'shouldnt apply istanbul opcode changes for petersburg' , ( st ) => {
9
+ const c = new Common ( 'mainnet' , 'petersburg' )
10
+ const opcodes = getOpcodesForHF ( c )
11
+ st . assert ( opcodes [ CHAINID ] === undefined )
12
+ st . end ( )
13
+ } )
14
+
15
+ t . test ( 'should correctly apply istanbul opcode when hf >= istanbul' , ( st ) => {
16
+ let c = new Common ( 'mainnet' , 'istanbul' )
17
+ let opcodes = getOpcodesForHF ( c )
18
+ st . equal ( opcodes [ CHAINID ] . name , 'CHAINID' )
19
+
20
+ c = new Common ( 'mainnet' , 'muirGlacier' )
21
+ opcodes = getOpcodesForHF ( c )
22
+ st . equal ( opcodes [ CHAINID ] . name , 'CHAINID' )
23
+
24
+ st . end ( )
25
+ } )
26
+ } )
You can’t perform that action at this time.
0 commit comments