Skip to content

Commit 41e3f63

Browse files
authored
Merge pull request #379 from Agusx1211/master
Fix freeLogs, don't modify codes constant
2 parents a67918b + 4836ea2 commit 41e3f63

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

lib/opcodes.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,13 @@ module.exports = function (op, full, freeLogs) {
182182
}
183183
}
184184

185+
var fee = code[1]
186+
185187
if (freeLogs) {
186188
if (opcode === 'LOG') {
187-
code[1] = 0
189+
fee = 0
188190
}
189191
}
190192

191-
return {name: opcode, opcode: op, fee: code[1], in: code[2], out: code[3], dynamic: code[4], async: code[5]}
193+
return {name: opcode, opcode: op, fee: fee, in: code[2], out: code[3], dynamic: code[4], async: code[5]}
192194
}

tests/api/freeLogs.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,22 @@ tape('VM with free logs', async (t) => {
1717
const vm = new VM({ emitFreeLogs: true })
1818
vm.runCode({
1919
code: code,
20-
gasLimit: 810
20+
gasLimit: 1000
2121
}, function (err, val) {
2222
st.notOk(err)
23-
st.ok(val.runState.gasLeft >= 0x177, 'should expend less gas')
23+
st.ok(val.runState.gasLeft >= 0x235, 'should expend less gas')
24+
st.ok(val.logs.length === 1, 'should emit event')
25+
st.end()
26+
})
27+
})
28+
t.test('should charge normal gas if flag is not set', async (st) => {
29+
const vm = new VM()
30+
vm.runCode({
31+
code: code,
32+
gasLimit: 1000
33+
}, function (err, val) {
34+
st.notOk(err)
35+
st.ok(val.runState.gasLeft < 0x235, 'should expend normal gas')
2436
st.ok(val.logs.length === 1, 'should emit event')
2537
st.end()
2638
})

0 commit comments

Comments
 (0)