File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change
1
+ const tape = require ( 'tape' )
2
+ const VM = require ( '../../lib/index' )
3
+
4
+ /*
5
+ contract Contract1 {
6
+ event Event();
7
+ function() external {
8
+ emit Event();
9
+ }
10
+ }
11
+ */
12
+
13
+ const code = Buffer . from ( '6080604052348015600f57600080fd5b506040517f57050ab73f6b9ebdd9f76b8d4997793f48cf956e965ee070551b9ca0bb71584e90600090a10000a165627a7a72305820f80265dc41ca5376abe548a02070b68b91119b77dc54c76563b9c19a758cf26f0029' , 'hex' )
14
+
15
+ tape ( 'VM with free logs' , async ( t ) => {
16
+ t . test ( 'should run code without charging for log opcode' , async ( st ) => {
17
+ const vm = new VM ( { emitFreeLogs : true } )
18
+ vm . runCode ( {
19
+ code : code ,
20
+ gasLimit : 810
21
+ } , function ( err , val ) {
22
+ st . notOk ( err )
23
+ st . ok ( val . runState . gasLeft >= 0x177 , 'should expend less gas' )
24
+ st . ok ( val . logs . length === 1 , 'should emit event' )
25
+ st . end ( )
26
+ } )
27
+ } )
28
+ t . test ( 'should emit event on static context' , async ( st ) => {
29
+ const vm = new VM ( { emitFreeLogs : true } )
30
+ vm . runCode ( {
31
+ code : code ,
32
+ gasLimit : 24000 ,
33
+ static : true
34
+ } , function ( err , val ) {
35
+ st . notOk ( err )
36
+ st . ok ( val . logs . length === 1 , 'should emit event' )
37
+ st . end ( )
38
+ } )
39
+ } )
40
+ t . test ( 'should not emit event on static context if flag is not set' , async ( st ) => {
41
+ const vm = new VM ( )
42
+ vm . runCode ( {
43
+ code : code ,
44
+ gasLimit : 24000 ,
45
+ static : true
46
+ } , function ( err , val ) {
47
+ st . ok ( err )
48
+ st . ok ( val . logs . length === 0 , 'should emit zero events' )
49
+ st . end ( )
50
+ } )
51
+ } )
52
+ } )
You can’t perform that action at this time.
0 commit comments