Skip to content
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

add --jsontrace flag for state tests #194

Merged
merged 3 commits into from
Sep 14, 2017

Conversation

cdetrio
Copy link
Contributor

@cdetrio cdetrio commented Sep 7, 2017

squashed #170 with authorship retained.

vm.on('step', function (e) {
let hexStack = []
hexStack = e.stack.map(item => {
return '0x' + new BN(item).toString(16, 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the 0 argument?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was from your suggestion in #170 . But it doesn't look toString takes a second argument so I will remove it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry, looked it up now. The second parameter is for padding (defaults to 1) where 0 means disable padding, i.e. it will not add a second nibble if the number of nibbles is odd.

e.g. 0x0 is not presented as 0x01

Not sure which one is needed according the tracing specs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see. Looks like there is no padding according to the example trace here: ethereum/tests#249

lib/opcodes.js Outdated
@@ -175,5 +175,5 @@ module.exports = function (op, full) {
}
}

return {name: opcode, fee: code[1], in: code[2], out: code[3], dynamic: code[4], async: code[5]}
return {name: opcode, rawOp: op, fee: code[1], in: code[2], out: code[3], dynamic: code[4], async: code[5]}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not name rawOp as opcode?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I think that is a better name.

@@ -54,6 +77,9 @@ function runTestCase (testData, t, cb) {
}
},
function (done) {
if (options.jsontrace) {
console.log('{ "steps": [' + steps + ']}')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you'd need to use JSON.stringify(steps) here too? Perhaps:

JSON.stringify({ "steps": steps })

I am also wondering which is faster / uses less memory (not sure which we are optimising for), keeping the array elements stringified or as a map?

Copy link
Contributor

@jwasinger jwasinger Sep 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. That is preferable. I do seem to remember discovering test cases which produce enough steps to crash ethereumjs-vm when trying to print so many steps in one statement.

To use less memory, it might be good to loop through each element in steps and print individually.

However, I think this suggestion is good for now until I can identify which tests causes the VM to crash with tracing on. I think it's actually just preferable to print steps in place and not collect them into an array.

@axic axic mentioned this pull request Sep 7, 2017
@cdetrio
Copy link
Contributor Author

cdetrio commented Sep 7, 2017

also it turns out some of this already in the Metro/byz working branch.. c4cb02b

@holgerd77
Copy link
Member

Yes, added this some time ago for debugging, but not with standard trace in mind and not on such a high-level. Just ignore for the moment, will be removed on next rebase when this PR is merged.

@@ -77,9 +76,6 @@ function runTestCase (options, testData, t, cb) {
}
},
function (done) {
if (options.jsontrace) {
console.log('{ "steps": [' + steps + ']}')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you print it in place, you need to print { "steps":[ here, the comma in place and ]} at the end.

Copy link
Contributor

@jwasinger jwasinger Sep 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made the changes to make the output conform to the example here: ethereum/tests#249 .

There are no commas between steps. Each step is logged on its own line.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this PR still far away (sorry, didn't really follow discussion)? Would be really useful, I always monkey-path this stuff together again and again...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jwasinger ah, that original issue isn't really clear on a spec.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@holgerd77 This is ready to merge.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably @cdetrio should review this, since he has started the initiative. Casey?

Copy link
Contributor

@jwasinger jwasinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jwasinger jwasinger merged commit d108d59 into ethereumjs:master Sep 14, 2017
@axic
Copy link
Member

axic commented Sep 14, 2017

@jwasinger @holgerd77 can you please avoid the "sync" button on the purge request because that creates a merge from master and then a merge into master. Just ignore it if you are certain or rebase it properly otherwise.

@jwasinger
Copy link
Contributor

I did not notice that until now. Thanks for informing me @axic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants