-
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
fix: Populate null values in transactions. #2467
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2467 +/- ##
==========================================
+ Coverage 77.29% 77.79% +0.50%
==========================================
Files 40 27 -13
Lines 3228 2585 -643
Branches 663 546 -117
==========================================
- Hits 2495 2011 -484
+ Misses 524 409 -115
+ Partials 209 165 -44 ☔ View full report in Codecov by Sentry. |
Signed-off-by: ebadiere <[email protected]> fix: Added chainId handling and missed file. Signed-off-by: ebadiere <[email protected]> fix: Added ganache encode hex fix. Signed-off-by: ebadiere <[email protected]> fix: Include the ethereumjs-utils in the relay build Signed-off-by: ebadiere <[email protected]> fix: Include package-lock.json. Signed-off-by: ebadiere <[email protected]>
bd765e0
to
d3f4f64
Compare
Quality Gate failedFailed conditions |
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.
Nice work. Some questions and suggestions
return addHexPrefix(val); | ||
}; | ||
|
||
// ganache solution |
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.
nit: maybe leave a link to the reference
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.
Done.
@@ -245,26 +280,73 @@ const isValidEthereumAddress = (address: string): boolean => { | |||
return new RegExp(constants.BASE_HEX_REGEX + '{40}$').test(address); | |||
}; | |||
|
|||
// ganache solution |
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.
nit: maybe leave a link to the reference
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.
Done.
} | ||
|
||
if (typeof val === 'object') { | ||
val = val.toString('hex'); |
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.
still confused by this. How can an object be casted into a string using .toString()? Is val
expected to be a special object that has a .toString() method?
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.
there should be a unit test to cover this case in any case, but agree with @quiet-node point
@@ -1888,6 +1889,8 @@ export class EthImpl implements Eth { | |||
const fromAddress = await this.resolveEvmAddress(contractResult.from, requestIdPrefix, [constants.TYPE_ACCOUNT]); | |||
const toAddress = await this.resolveEvmAddress(contractResult.to, requestIdPrefix); | |||
|
|||
contractResult.chain_id = contractResult.chain_id == null ? this.chain : contractResult.chain_id; |
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.
Just a suggestion
contractResult.chain_id = contractResult.chain_id == null ? this.chain : contractResult.chain_id; | |
contractResult.chain_id = contractResult.chain_id || this.chain |
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.
Done.
} | ||
|
||
// Throw error if input type is unexpected | ||
throw new Error('Invalid input type. Expected number, string, or null.'); |
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 think this is not necessary. The value
argument itself only accept number | string | null
, and your if statements
already cover all those three scenarios, so this error will never be reached.
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.
Removed.
|
||
const convertToHex = (value: number | string | null): string => { | ||
// Check for null value | ||
if (value === null || value === undefined) { |
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.
since value
only accepts number|string|null, value === undefined would not make sense.
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.
good point @quiet-node,
anyways, the simples way to eval for both null
, undefined
and empty string
would be:
if (!value) {...
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.
Removed value === undefined
@@ -2143,6 +2146,7 @@ export class EthImpl implements Eth { | |||
constants.TYPE_ACCOUNT, | |||
]); | |||
contractResult.to = await this.resolveEvmAddress(contractResult.to, requestIdPrefix); | |||
contractResult.chain_id = contractResult.chain_id == null ? this.chain : contractResult.chain_id; |
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.
Just a suggestion
contractResult.chain_id = contractResult.chain_id == null ? this.chain : contractResult.chain_id; | |
contractResult.chain_id = contractResult.chain_id || this.chain |
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.
Done.
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.
LG, agreed with a few nits from @quiet-node otherwise looking good.
|
||
const convertToHex = (value: number | string | null): string => { | ||
// Check for null value | ||
if (value === null || value === undefined) { |
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.
good point @quiet-node,
anyways, the simples way to eval for both null
, undefined
and empty string
would be:
if (!value) {...
} | ||
|
||
if (typeof val === 'object') { | ||
val = val.toString('hex'); |
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.
there should be a unit test to cover this case in any case, but agree with @quiet-node point
Replaced by #2495 |
Populates null values in transactions.
Related issue(s):
Fixes #2451