Skip to content

Commit

Permalink
Merge pull request #379 from Agusx1211/master
Browse files Browse the repository at this point in the history
Fix freeLogs, don't modify codes constant
  • Loading branch information
holgerd77 committed Nov 1, 2018
2 parents a67918b + 4836ea2 commit 41e3f63
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
6 changes: 4 additions & 2 deletions lib/opcodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,13 @@ module.exports = function (op, full, freeLogs) {
}
}

var fee = code[1]

if (freeLogs) {
if (opcode === 'LOG') {
code[1] = 0
fee = 0
}
}

return {name: opcode, opcode: op, fee: code[1], in: code[2], out: code[3], dynamic: code[4], async: code[5]}
return {name: opcode, opcode: op, fee: fee, in: code[2], out: code[3], dynamic: code[4], async: code[5]}
}
16 changes: 14 additions & 2 deletions tests/api/freeLogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,22 @@ tape('VM with free logs', async (t) => {
const vm = new VM({ emitFreeLogs: true })
vm.runCode({
code: code,
gasLimit: 810
gasLimit: 1000
}, function (err, val) {
st.notOk(err)
st.ok(val.runState.gasLeft >= 0x177, 'should expend less gas')
st.ok(val.runState.gasLeft >= 0x235, 'should expend less gas')
st.ok(val.logs.length === 1, 'should emit event')
st.end()
})
})
t.test('should charge normal gas if flag is not set', async (st) => {
const vm = new VM()
vm.runCode({
code: code,
gasLimit: 1000
}, function (err, val) {
st.notOk(err)
st.ok(val.runState.gasLeft < 0x235, 'should expend normal gas')
st.ok(val.logs.length === 1, 'should emit event')
st.end()
})
Expand Down

0 comments on commit 41e3f63

Please sign in to comment.