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

fix: Populate null values in transactions. #2467

Closed

Conversation

ebadiere
Copy link
Contributor

@ebadiere ebadiere commented May 8, 2024

Populates null values in transactions.

Related issue(s):

Fixes #2451

@ebadiere ebadiere added the bug Something isn't working label May 8, 2024
@ebadiere ebadiere added this to the 0.48.0 milestone May 8, 2024
@ebadiere ebadiere self-assigned this May 8, 2024
@ebadiere ebadiere requested review from AlfredoG87, lukelee-sl and a team as code owners May 8, 2024 23:27
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 0% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 77.79%. Comparing base (07cb2d7) to head (62a04d7).
Report is 2 commits behind head on main.

❗ Current head 62a04d7 differs from pull request most recent head 374e8fd. Consider uploading reports for the commit 374e8fd to get more accurate results

Files Patch % Lines
packages/relay/src/lib/eth.ts 0.00% 0 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

Copy link

github-actions bot commented May 8, 2024

Acceptance Tests

  20 files  263 suites   24m 53s ⏱️
586 tests 579 ✔️ 3 💤 4
904 runs  889 ✔️ 7 💤 8

Results for commit d3f4f64.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented May 9, 2024

Tests

    2 files  147 suites   13s ⏱️
821 tests 820 ✔️ 1 💤 0
833 runs  832 ✔️ 1 💤 0

Results for commit d3f4f64.

♻️ This comment has been updated with latest results.

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]>
@ebadiere ebadiere force-pushed the 2451-maxPriorityFeePerGas-missing-getBlockByNumber branch from bd765e0 to d3f4f64 Compare May 10, 2024 14:14
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
3.2% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

Copy link
Member

@quiet-node quiet-node left a 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
Copy link
Member

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

Copy link
Contributor Author

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
Copy link
Member

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

Copy link
Contributor Author

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');
Copy link
Member

@quiet-node quiet-node May 10, 2024

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?

Copy link
Collaborator

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;
Copy link
Member

Choose a reason for hiding this comment

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

Just a suggestion

Suggested change
contractResult.chain_id = contractResult.chain_id == null ? this.chain : contractResult.chain_id;
contractResult.chain_id = contractResult.chain_id || this.chain

Copy link
Contributor Author

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.');
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 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.

Copy link
Contributor Author

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) {
Copy link
Member

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.

Copy link
Collaborator

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) {...

Copy link
Contributor Author

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;
Copy link
Member

Choose a reason for hiding this comment

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

Just a suggestion

Suggested change
contractResult.chain_id = contractResult.chain_id == null ? this.chain : contractResult.chain_id;
contractResult.chain_id = contractResult.chain_id || this.chain

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Collaborator

@AlfredoG87 AlfredoG87 left a 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) {
Copy link
Collaborator

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');
Copy link
Collaborator

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

@ebadiere
Copy link
Contributor Author

Replaced by #2495

@ebadiere ebadiere closed this May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Error from GoEthClient when calling getBlockByNumber on certain specific blocks
4 participants