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

Fixup in parseSignature for functions with no args #72

Merged
merged 2 commits into from
Jan 21, 2019

Conversation

JAG-UK
Copy link
Contributor

@JAG-UK JAG-UK commented Dec 15, 2018

Previously passing “functionWithNoArgs()” for binary encoding would fail. Now it works and produces correct function hashes that match the exported functions from solidity contracts.

Two things required to make this work:

  • Fixed the first regex to deal with tight braces
  • Slightly naive 'special case' fixup prior to return if there were no args. I don't really like special cases like this but on the plus side, it makes the fix very self-contained - everything else based on regexs, split(), and array comparison continues to work so it's very low-risk
    Testing evidence:
*** In a plain node console:
    var abi = require('ethereumjs-abi')
undefined
//First test we didn’t break the existing functionality!
abi.simpleEncode("inc(uint)", "0x13").toString("hex")
‘812600df0000000000000000000000000000000000000000000000000000000000000013'
//Now test the new one
abi.simpleEncode("meaningOfLife()").toString("hex")
'5353455a'
.exit
    *** Then with a running network and a contract deployed with a 'meaningOfLife()' function exported:
root@77d32569caa0:/project/sawtooth-seth/contracts/examples/simple_intkey# seth contract call --wait jag_x9 46ae4ccf394274f606a3e0bb397ee9fb3ad90e06 5353455a
Enter Password to unlock jag_x9:
Contract called
Transaction Receipt: {
"TransactionID": "ea5e92b0eab77bae858a632e0606989a600fe6563f2aceff9d6634b47137e0a169e10400915d3be1e4e2d8de0770f1f32dc916ee4296693e6ecb86c1193a0387",
"GasUsed": 86,
"ReturnValue": "000000000000000000000000000000000000000000000000000000000000002a"
}

@coveralls
Copy link

coveralls commented Dec 16, 2018

Coverage Status

Coverage increased (+3.3%) to 90.145% when pulling 1cec899 on JAG-UK:patch-1 into 5117e51 on ethereumjs:master.

@holgerd77
Copy link
Member

Hi @JAG-UK, thanks for the PR! 😄

Can you re-format your initial comment a bit, this is really really hard to read.

Also, can you add a simple test case to the test file which would fail before and work after the fix?

@JAG-UK
Copy link
Contributor Author

JAG-UK commented Jan 18, 2019

Can you re-format your initial comment a bit

For sure. It looked much clearer when I originally wrote it on a monospace console with more whitespace...it is pretty grotty now, I agree. I'll remove all the testing evidence actually, since adding a test will make that unnecessary - the CI can speak for itself.

@holgerd77
Copy link
Member

There is currently still a linting (code formatting) error, which prevents the tests from passing, see also the respective section in our organizational documentation.

Can you please fix and optimally squash the commit afterwards and also squash 2b89c8a to end up with a cleaner commit history (if you haven't done before I would recommend testing this with local copy of your working directory, since things can easily go wrong)?

test/index.js Outdated
@@ -787,3 +787,17 @@ describe('decoding (uint[][3], uint)', function () {
assert.equal(a[0][2][1].toString(10), 6)
})
})

//Homebrew tests for simpleEncode() family
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for adding the test case, great! 👍

(side question: what is a "homebrew test"?? 😄)

Copy link
Contributor Author

@JAG-UK JAG-UK Jan 21, 2019

Choose a reason for hiding this comment

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

what is a "homebrew test"

One we made at home, in contrast with standard or other verified external test vectors such as the official Ethereum ones used in the very first tests. There are various words for this but Alex Beregszaszi (if git blame be believed) already chose 'Homebrew' earlier in the file so I stuck with the convention :-)

@JAG-UK
Copy link
Contributor Author

JAG-UK commented Jan 21, 2019

There is currently still a linting (code formatting) error

Sorry, that's me and my tight comment style again :-/ Fixing now.

Can you please fix and optimally squash the commit afterwards and also squash 2b89c8a

Sure

(if you haven't done before I would recommend testing this with local copy of your working directory, since things can easily go wrong)

I've done it before, and I've done it wrong before ;-) On it.

Previously passing “functionWithNoArgs()” for binary encoding would fail with errors.
Now it works and produces correct function hashes that match the exported functions from solidity contracts.

Includes a slightly naive 'special case' fixup prior to return - not the most beautiful thing but it makes the fix very self-contained and low-risk
@JAG-UK
Copy link
Contributor Author

JAG-UK commented Jan 21, 2019

All done now I think. lints and tests clean with just 2 commits: one for the fix (including all format compliance squashed); and one for the test similarly squashed

Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@holgerd77 holgerd77 merged commit d84a967 into ethereumjs:master Jan 21, 2019
@JAG-UK
Copy link
Contributor Author

JAG-UK commented Jan 21, 2019

Thanks @holgerd77 , for a very pleasant and professional PR experience :-)
I'll delete the branch now.

@JAG-UK JAG-UK deleted the patch-1 branch January 21, 2019 13:10
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.

None yet

3 participants