-
Notifications
You must be signed in to change notification settings - Fork 782
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
runCode.js: add pc
to opt args | initial API tests
#406
Changes from 5 commits
2110211
02572c0
b30a5cd
92c9b0e
a3cfa79
46bbc10
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
const tape = require('tape') | ||
const async = require('async') | ||
const VM = require('../') | ||
|
||
const STOP = '00' | ||
const JUMP = '56' | ||
const JUMPDEST = '5b' | ||
const PUSH1 = '60' | ||
|
||
const testCases = [ | ||
{ code: [STOP, JUMPDEST, PUSH1, '05', JUMP, JUMPDEST], pc: 1, resultPC: 6 }, | ||
{ code: [STOP, JUMPDEST, PUSH1, '05', JUMP, JUMPDEST], pc: -1, error: 'invalid opcode' }, | ||
{ code: [STOP], pc: 3, error: 'invalid opcode' }, | ||
{ code: [STOP], resultPC: 1 } | ||
] | ||
|
||
tape('VM.runcode: initial program counter', function (t) { | ||
const vm = new VM() | ||
|
||
testCases.forEach(function (testData, i) { | ||
t.test('should start the execution at the specified pc or 0 #' + i, function (st) { | ||
const runCodeArgs = { | ||
code: Buffer.from(testData.code.join(''), 'hex'), | ||
pc: testData.pc, | ||
gasLimit: 0xffff | ||
} | ||
let result | ||
|
||
async.series([ | ||
function (done) { | ||
vm.runCode(runCodeArgs, function (err, res) { | ||
if (res) { | ||
result = res | ||
} | ||
|
||
done(err) | ||
}) | ||
}, | ||
function (done) { | ||
if (testData.resultPC !== undefined) { | ||
t.equals(result.runState.programCounter, testData.resultPC, 'runstate.programCounter') | ||
} | ||
|
||
done() | ||
} | ||
], function (err) { | ||
if (testData.error) { | ||
err = err ? err.error : 'no error thrown' | ||
t.equals(err, testData.error, 'error message should match') | ||
err = false | ||
} | ||
|
||
t.assert(!err) | ||
st.end() | ||
}) | ||
}) | ||
}) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -249,6 +249,7 @@ function runAll () { | |
require('./tester.js') | ||
require('./genesishashes.js') | ||
require('./constantinopleSstoreTest.js') | ||
require('./programCounter.js') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, this is really completely our fault and I have directly created a test cleanup PR #437 on this to avoid future confusion: The Can you just add a file to the Also: the naming with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done ;) |
||
async.series([ | ||
// runTests.bind(this, 'VMTests', {}), // VM tests disabled since we don't support Frontier gas costs | ||
runTests.bind(this, 'GeneralStateTests', {}), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Condition looks good.