-
Notifications
You must be signed in to change notification settings - Fork 75
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
Expand eth_call
validation to support blockParam object
#817
Expand eth_call
validation to support blockParam object
#817
Conversation
Signed-off-by: georgi-l95 <[email protected]>
Signed-off-by: georgi-l95 <[email protected]>
Signed-off-by: georgi-l95 <[email protected]>
Codecov ReportBase: 72.62% // Head: 73.88% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #817 +/- ##
==========================================
+ Coverage 72.62% 73.88% +1.26%
==========================================
Files 29 29
Lines 1746 1773 +27
Branches 319 322 +3
==========================================
+ Hits 1268 1310 +42
+ Misses 387 371 -16
- Partials 91 92 +1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
expect(res).to.eq(BASIC_CONTRACT_PING_RESULT); | ||
}); | ||
|
||
it('should fail to execute "eth_call" with correct block hash', async function () { |
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.
is this test calling with blockNumber rather than blockHash?
Succeed rather than fail?
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.
Fixed.
@@ -1299,6 +1299,101 @@ describe('@api RPC Server Acceptance Tests', function () { | |||
const res = await relay.call('eth_call', [callData, 'latest'], requestId); | |||
expect(res).to.eq(BASIC_CONTRACT_PING_RESULT); | |||
}); | |||
|
|||
it('should fail to execute "eth_call" with correct block number', async function () { |
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.
It looks like this test is supposed to succeed rather than fail?
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.
Fixed.
expect(res).to.eq(BASIC_CONTRACT_PING_RESULT); | ||
}); | ||
|
||
it('should fail to execute "eth_call" with correct block hash', async function () { |
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.
Succeed rather than fail?
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.
Aw, yes. Copy paste error on my side. Thanks for the feedback. Those are positive cases.
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.
Fixed.
} | ||
return new Validator.BlockNumberObject(param).validate(); | ||
} | ||
return /^0[xX]([1-9A-Fa-f]+[0-9A-Fa-f]{0,13}|0)$/.test(param) && Number.MAX_SAFE_INTEGER >= Number(param) || ["earliest", "latest", "pending"].includes(param) |
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.
The regex seems odd to me. It allows for 12 bytes and the first nibble cannot be 0? I tested 0x1204567890abcdef123456 for example and the regex does not match for me.
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.
Maybe also add some of the test cases noted in the EIP for additional coverage
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.
First nibble cannot be 0, because block numbers are not starting with 0, that would mean to be padded, which we have to trim afterwards. For example infura doesn't accepts padded blocknumbers, but alchemy accepts them. We can change the regex to accepts, but we may have to trim it afterwards. I mean it could work both ways.
It allows for this many bytes only, because otherwise it will exceeds javascript max integer size, this is the reason your example is not working. If you cut it down to 0x1204567890abcde
, it should work with this regular expression.
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.
I guess my question is whether the regex should not be /^0[xX]([1-9A-Fa-f][0-9A-Fa-f]{0,13}|0)$/
? Unless I am misunderstanding the purpose of what the regex is trying to test. My guess is that it is trying to say the first nibble should not be zero but should be any other hex character and the next up to 13 characters can be any hex character.
Because of the + after [1-9A-Fa-f] I think this allows for any number of hex characters as long as they are not 0 to be part of the first match group. So things like 0x123456789abcedf123456789abcedf123456789abcedf123456789abcedf123456789abcedf123456789abcedf
will still match (which I don't think is the intention but correct me if I am wrong). The count of up to 13 characters starts after the first 0
is encountered.
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.
I may have "over-insured" in this case. Generally it should be fine to have a longer than 16 character hex for block number, my reason was that at one point all hex values will always convert to JS's MAX_SAFE_INTEGER, but then again it would take quite the long amout of time until we reach that point, so in the end that size limit may be uneeded.
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.
Yes, you're right, I'll change the regex to /^0[xX]([1-9A-Fa-f][0-9A-Fa-f]{0,13}|0)$/
, which will work for our needs.
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.
Thanks for double checking.
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.
Thank you for the feedback, Luke.
} | ||
return new Validator.BlockNumberObject(param).validate(); | ||
} | ||
return /^0[xX]([1-9A-Fa-f]+[0-9A-Fa-f]{0,13}|0)$/.test(param) && Number.MAX_SAFE_INTEGER >= Number(param) || ["earliest", "latest", "pending"].includes(param) |
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.
Maybe also add some of the test cases noted in the EIP for additional coverage
Signed-off-by: georgi-l95 <[email protected]>
Signed-off-by: georgi-l95 <[email protected]>
Signed-off-by: georgi-l95 <[email protected]>
@Nana-EC Tests case examples in the EIP are about
But only |
Signed-off-by: georgi-l95 <[email protected]>
@georgi-l95 Let's match Alchemy and Infura for now. |
Signed-off-by: georgi-l95 <[email protected]>
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
LGTM |
Expand `eth_call` validation to support `blockParam` object, introduced with [EIP-1898](https://eips.ethereum.org/EIPS/eip-1898). The Graph is passing blockHash as parameter and currently validations only accepts `blockNumber` or `tag`. More info can be found in this issue from this [comment](#626 (comment)) onwards. Fix some minor intermittent bugs in ERC20 tests. Bump network images to `0.33.2` and mirror-node images to `0.72.0`. Signed-off-by: georgi-l95 <[email protected]>
Expand `eth_call` validation to support `blockParam` object, introduced with [EIP-1898](https://eips.ethereum.org/EIPS/eip-1898). The Graph is passing blockHash as parameter and currently validations only accepts `blockNumber` or `tag`. More info can be found in this issue from this [comment](#626 (comment)) onwards. Fix some minor intermittent bugs in ERC20 tests. Bump network images to `0.33.2` and mirror-node images to `0.72.0`. Signed-off-by: georgi-l95 <[email protected]> Signed-off-by: georgi-l95 <[email protected]>
Signed-off-by: georgi-l95 [email protected]
Description:
Expand
eth_call
validation to supportblockParam
object, introduced with EIP-1898. The Graph is passing blockHash as parameter and currently validations only acceptsblockNumber
ortag
. More info can be found in this issue from this comment onwards.Fix some minor intermittent bugs in ERC20 tests.
Bump network images to
0.33.2
and mirror-node images to0.72.0
.Related issue(s):
Fixes #816
Notes for reviewer:
Checklist