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(evm): tx receipt proper marshalling #2101

Merged
merged 6 commits into from
Oct 31, 2024
Merged

fix(evm): tx receipt proper marshalling #2101

merged 6 commits into from
Oct 31, 2024

Conversation

onikonychev
Copy link
Contributor

@onikonychev onikonychev commented Oct 30, 2024

Fixes the issue of the missing fields: to, from, effectiveGasPrice and contractAddress in the transaction receipt.
As soon as TransactionReceipt struct is inherited from gethcore.Receipt - its MarshalJSON ignores the extra fields.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added support for foundry and templates for Nibiru EVM development.
    • Introduced validation for FunToken creation fees.
    • New EventsEmitter contract for logging events.
    • New TransactionReverter contract demonstrating transaction reversion methods.
    • Comprehensive test suite for transaction receipts.
  • Bug Fixes

    • Improved ERC20 metadata handling during FunToken creation.
    • Adjusted gas fee calculations for RefundGas.
    • Enhanced state consistency in precompile execution.
    • Fixed ERC20 transfer success value representation.
  • Documentation

    • Updated CHANGELOG.md to reflect recent changes and improvements.
  • Tests

    • Added tests for transaction receipts, including ETH transfers and contract deployments.
    • Enhanced testing for race conditions and state database interactions.
  • Chores

    • Transitioned from bun to npm for package management and formatting.

Copy link
Contributor

coderabbitai bot commented Oct 30, 2024

Walkthrough

The pull request introduces significant updates across various files in the Nibiru EVM project. Key changes include enhancements to the TransactionReceipt structure, updates to the CHANGELOG.md for bug fixes and feature additions, and the introduction of new contracts like EventsEmitter and TransactionReverter. Several obsolete files and interfaces have been removed, simplifying the codebase. Additionally, a new configuration for the Hardhat environment has been established, and numerous test files have been reformatted for consistency, ensuring that the overall functionality remains intact while improving code quality.

Changes

File Path Change Summary
CHANGELOG.md Updated to reflect bug fixes, feature additions, and refactoring efforts.
eth/rpc/backend/tx_info.go Modified TransactionReceipt structure; added custom JSON marshaling method.
eth/rpc/backend/tx_info_test.go Updated tests to reflect changes in TransactionReceipt; adjusted assertions for new types.
evm-e2e/.prettierrc New configuration file for code formatting rules.
evm-e2e/contracts/EventsEmitter.sol Added new contract with an event and a function to emit it.
evm-e2e/contracts/InfiniteLoopGasCompiled.json Removed compiled artifact for InfiniteLoopGas contract.
evm-e2e/contracts/ReceiveNibiCompiled.json Removed compiled artifact for ReceiveNibi contract.
evm-e2e/contracts/SendNibiCompiled.json Removed compiled artifact for SendNibi contract.
evm-e2e/contracts/TestERC20Compiled.json Removed compiled artifact for TestERC20 contract.
evm-e2e/contracts/TransactionReverter.sol Added new contract demonstrating transaction reversion methods.
evm-e2e/hardhat.config.js New configuration file for Hardhat setup, specifying compiler version and TypeChain settings.
evm-e2e/justfile Simplified install recipe; removed gen-types recipe.
evm-e2e/package.json Updated dependencies; removed bun and added several new development dependencies.
evm-e2e/test/*.test.ts Multiple test files reformatted for consistency; no functional changes.
evm-e2e/test/tx_receipt.test.ts New test suite for transaction receipts with multiple test cases.
evm-e2e/types/ethers-contracts/*.ts Removed multiple TypeScript interfaces and factory classes for various contracts.
evm-e2e/types/ethers-contracts/factories/index.ts Removed index file for factory exports.
evm-e2e/types/ethers-contracts/index.ts Removed index file for contract types and factory exports.

Poem

🐇 In the meadow, changes bloom,
Contracts new, and bugs meet doom.
With a hop and a skip, we refine,
Code so neat, like a well-aged wine.
Celebrate the updates, let’s cheer and play,
For a brighter codebase, hip-hip-hooray! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Oct 31, 2024

Codecov Report

Attention: Patch coverage is 58.33333% with 10 lines in your changes missing coverage. Please review.

Project coverage is 64.57%. Comparing base (7b7beb7) to head (316493b).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
eth/rpc/backend/tx_info.go 58.33% 7 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2101      +/-   ##
==========================================
- Coverage   64.58%   64.57%   -0.02%     
==========================================
  Files         271      271              
  Lines       21237    21246       +9     
==========================================
+ Hits        13716    13719       +3     
- Misses       6574     6575       +1     
- Partials      947      952       +5     
Files with missing lines Coverage Δ
eth/rpc/backend/tx_info.go 45.89% <58.33%> (+1.12%) ⬆️

... and 3 files with indirect coverage changes

@onikonychev onikonychev marked this pull request as ready for review October 31, 2024 16:18
@onikonychev onikonychev requested a review from a team as a code owner October 31, 2024 16:18
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 9

🧹 Outside diff range and nitpick comments (13)
evm-e2e/contracts/EventsEmitter.sol (3)

1-2: Consider pinning the exact Solidity version.

Using ^0.8.24 allows minor version updates which could potentially introduce subtle differences in behavior. For test contracts, it's safer to pin the exact version to ensure consistent behavior across different environments.

-pragma solidity ^0.8.24;
+pragma solidity 0.8.24;

4-5: LGTM! Consider a more specific event name.

The event structure is well-designed with proper indexing of the sender address. However, since this is a test contract, consider renaming TestEvent to something more specific like TransactionReceiptTestEvent to better indicate its purpose in testing transaction receipt marshalling.

-    event TestEvent(address indexed sender, uint256 value);
+    event TransactionReceiptTestEvent(address indexed sender, uint256 value);

4-10: Well-designed test contract for transaction receipt verification.

This contract is well-suited for testing the transaction receipt marshalling fix. Its simple event emission allows for easy verification of receipt fields like from address, while keeping the test focused and isolated.

evm-e2e/hardhat.config.js (1)

6-6: Consider pinning the exact Solidity version.

While using "0.8.24" works, it's recommended to use the exact version format (^0.8.24) to ensure consistent behavior across different environments.

-  solidity: "0.8.24",
+  solidity: "^0.8.24",
evm-e2e/contracts/TransactionReverter.sol (3)

1-5: Add NatSpec documentation for the contract and state variable.

Consider adding comprehensive NatSpec documentation to improve code clarity and maintainability.

 // SPDX-License-Identifier: MIT
 pragma solidity ^0.8.20;
 
+/// @title TransactionReverter
+/// @notice Contract for testing various transaction reversion scenarios
+/// @dev Used for testing transaction receipt handling in the EVM
 contract TransactionReverter {
+    /// @notice Public state variable that gets modified before reverts
     uint256 public value;

7-7: Add a descriptive parameter name to the custom error.

The custom error parameter should have a descriptive name for better clarity.

-    error CustomRevertReason(uint256 providedValue);
+    error CustomRevertReason(uint256 attemptedValue);

16-19: LGTM! Consider adding input validation if needed.

The implementation correctly uses custom errors for gas efficiency.

Consider adding input validation if there are any constraints on the newValue parameter.

evm-e2e/package.json (1)

Line range hint 14-30: Consider adding peer dependency versions

While the direct dependencies are specified with version constraints, you might want to add peerDependencies for critical relationships, especially between Hardhat and its plugins.

Add this section to ensure version compatibility:

  "devDependencies": {
    ...
  },
+ "peerDependencies": {
+   "hardhat": "^2.22.15",
+   "ethers": "^6.12.1"
+ },
  "scripts": {
evm-e2e/test/utils.ts (1)

57-68: Review production readiness of the utility function.

A few concerns with the sendTestNibi function:

  1. Console logging should be removed or wrapped in a debug flag
  2. The 10s confirmation timeout might be too short for some networks
-  await txResponse.wait(1, 10e3);
-  console.log(txResponse);
+  await txResponse.wait(1, 30e3); // Increase timeout to 30s
   return txResponse;
evm-e2e/test/tx_receipt.test.ts (2)

25-37: Consider adding effectiveGasPrice validation.

While this test effectively validates the contractAddress field (one of the PR objectives), consider adding validation for the effectiveGasPrice field, which was also mentioned as a missing field in the PR objectives.

   assertBaseReceiptFields(receipt);
   expect(receipt.to).toBeNull(); // Contract creation has no 'to' address
   expect(receipt.contractAddress).toBeDefined();
+  expect(receipt.effectiveGasPrice).toBeDefined();
+  expect(receipt.effectiveGasPrice).toBeGreaterThan(0n);

66-99: Add effectiveGasPrice validation to base assertions.

The helper function provides comprehensive validation of receipt fields, but it should also validate the effectiveGasPrice field since it was one of the missing fields mentioned in the PR objectives.

   // Gas fields
   expect(typeof receipt.gasUsed).toBe('bigint');
   expect(receipt.gasUsed).toBeGreaterThan(0n);
   expect(typeof receipt.cumulativeGasUsed).toBe('bigint');
   expect(receipt.cumulativeGasUsed).toBeGreaterThanOrEqual(receipt.gasUsed);
+  expect(typeof receipt.effectiveGasPrice).toBe('bigint');
+  expect(receipt.effectiveGasPrice).toBeGreaterThan(0n);
eth/rpc/backend/tx_info_test.go (1)

Line range hint 194-220: Enhance test coverage for receipt marshalling.

While the test verifies basic marshalling/unmarshalling, consider adding these improvements to align with the PR objectives:

  1. Verify the JSON output contains all required fields:
    • Add assertions to check the presence of to, from, effectiveGasPrice, and contractAddress
  2. Verify field values are preserved after unmarshalling:
    • Add assertions comparing the original and unmarshalled values

Here's a suggested enhancement:

 jsonBz, err := tr.MarshalJSON()
 s.Require().NoError(err)

+// Verify JSON contains all required fields
+var jsonMap map[string]interface{}
+s.Require().NoError(json.Unmarshal(jsonBz, &jsonMap))
+s.Require().Contains(jsonMap, "to")
+s.Require().Contains(jsonMap, "from")
+s.Require().Contains(jsonMap, "effectiveGasPrice")
+s.Require().Contains(jsonMap, "contractAddress")

 gethReceipt := new(gethcore.Receipt)
 err = json.Unmarshal(jsonBz, gethReceipt)
 s.Require().NoError(err)

 receipt := new(backend.TransactionReceipt)
 err = json.Unmarshal(jsonBz, receipt)
 s.Require().NoError(err)
+
+// Verify field values are preserved
+s.Require().Equal(tr.From, receipt.From)
+s.Require().Equal(tr.To, receipt.To)
+s.Require().Equal(tr.EffectiveGasPrice, receipt.EffectiveGasPrice)
+s.Require().Equal(tr.ContractAddress, receipt.ContractAddress)
CHANGELOG.md (1)

87-87: Enhance the changelog entry for PR #2101.

The current entry "fix(evm): tx receipt proper marshalling" is too terse. Consider expanding it to describe what was fixed and the impact:

-  - [#2101](https://github.com/NibiruChain/nibiru/pull/2101) - fix(evm): tx receipt proper marshalling
+  - [#2101](https://github.com/NibiruChain/nibiru/pull/2101) - fix(evm): Add missing fields in transaction receipt marshalling (`to`, `from`, `effectiveGasPrice`, `contractAddress`). This ensures complete transaction data is returned to clients.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0afb08f and 316493b.

⛔ Files ignored due to path filters (1)
  • evm-e2e/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (33)
  • CHANGELOG.md (1 hunks)
  • eth/rpc/backend/tx_info.go (3 hunks)
  • eth/rpc/backend/tx_info_test.go (1 hunks)
  • evm-e2e/.prettierrc (1 hunks)
  • evm-e2e/contracts/EventsEmitter.sol (1 hunks)
  • evm-e2e/contracts/InfiniteLoopGasCompiled.json (0 hunks)
  • evm-e2e/contracts/ReceiveNibiCompiled.json (0 hunks)
  • evm-e2e/contracts/SendNibiCompiled.json (0 hunks)
  • evm-e2e/contracts/TestERC20Compiled.json (0 hunks)
  • evm-e2e/contracts/TransactionReverter.sol (1 hunks)
  • evm-e2e/hardhat.config.js (1 hunks)
  • evm-e2e/justfile (1 hunks)
  • evm-e2e/package.json (2 hunks)
  • evm-e2e/test/contract_infinite_loop_gas.test.ts (1 hunks)
  • evm-e2e/test/contract_send_nibi.test.ts (2 hunks)
  • evm-e2e/test/debug_queries.test.ts (1 hunks)
  • evm-e2e/test/erc20.test.ts (1 hunks)
  • evm-e2e/test/eth_queries.test.ts (1 hunks)
  • evm-e2e/test/native_transfer.test.ts (1 hunks)
  • evm-e2e/test/setup.ts (1 hunks)
  • evm-e2e/test/tx_receipt.test.ts (1 hunks)
  • evm-e2e/test/utils.ts (1 hunks)
  • evm-e2e/types/ethers-contracts/InfiniteLoopGasCompiled.ts (0 hunks)
  • evm-e2e/types/ethers-contracts/ReceiveNibiCompiled.ts (0 hunks)
  • evm-e2e/types/ethers-contracts/SendNibiCompiled.ts (0 hunks)
  • evm-e2e/types/ethers-contracts/TestERC20Compiled.ts (0 hunks)
  • evm-e2e/types/ethers-contracts/common.ts (0 hunks)
  • evm-e2e/types/ethers-contracts/factories/InfiniteLoopGasCompiled__factory.ts (0 hunks)
  • evm-e2e/types/ethers-contracts/factories/ReceiveNibiCompiled__factory.ts (0 hunks)
  • evm-e2e/types/ethers-contracts/factories/SendNibiCompiled__factory.ts (0 hunks)
  • evm-e2e/types/ethers-contracts/factories/TestERC20Compiled__factory.ts (0 hunks)
  • evm-e2e/types/ethers-contracts/factories/index.ts (0 hunks)
  • evm-e2e/types/ethers-contracts/index.ts (0 hunks)
💤 Files with no reviewable changes (15)
  • evm-e2e/contracts/InfiniteLoopGasCompiled.json
  • evm-e2e/contracts/ReceiveNibiCompiled.json
  • evm-e2e/contracts/SendNibiCompiled.json
  • evm-e2e/contracts/TestERC20Compiled.json
  • evm-e2e/types/ethers-contracts/InfiniteLoopGasCompiled.ts
  • evm-e2e/types/ethers-contracts/ReceiveNibiCompiled.ts
  • evm-e2e/types/ethers-contracts/SendNibiCompiled.ts
  • evm-e2e/types/ethers-contracts/TestERC20Compiled.ts
  • evm-e2e/types/ethers-contracts/common.ts
  • evm-e2e/types/ethers-contracts/factories/InfiniteLoopGasCompiled__factory.ts
  • evm-e2e/types/ethers-contracts/factories/ReceiveNibiCompiled__factory.ts
  • evm-e2e/types/ethers-contracts/factories/SendNibiCompiled__factory.ts
  • evm-e2e/types/ethers-contracts/factories/TestERC20Compiled__factory.ts
  • evm-e2e/types/ethers-contracts/factories/index.ts
  • evm-e2e/types/ethers-contracts/index.ts
✅ Files skipped from review due to trivial changes (8)
  • evm-e2e/.prettierrc
  • evm-e2e/test/contract_infinite_loop_gas.test.ts
  • evm-e2e/test/contract_send_nibi.test.ts
  • evm-e2e/test/debug_queries.test.ts
  • evm-e2e/test/erc20.test.ts
  • evm-e2e/test/eth_queries.test.ts
  • evm-e2e/test/native_transfer.test.ts
  • evm-e2e/test/setup.ts
🔇 Additional comments (17)
evm-e2e/contracts/EventsEmitter.sol (1)

7-9: LGTM! Implementation is appropriate for testing purposes.

The function correctly emits the event with the caller's address and provided value. The simple implementation is sufficient for testing transaction receipt marshalling.

evm-e2e/hardhat.config.js (2)

1-4: LGTM: Dependencies and TypeScript setup are well configured.

The required dependencies and TypeScript type annotation are correctly set up. The hardhat-toolbox provides a comprehensive set of development tools, and TypeChain integration enables type-safe contract interactions.


5-13: Verify network configuration for EVM compatibility.

The configuration lacks network settings which might be needed for connecting to the Nibiru EVM network.

Let's verify if there are any network configurations in other files:

Consider adding network configuration if needed:

networks: {
  nibiru: {
    url: process.env.NIBIRU_RPC_URL || "http://localhost:8545",
    chainId: process.env.NIBIRU_CHAIN_ID || 1,
  },
}
evm-e2e/justfile (1)

21-21: LGTM! Format command updated.

The format command has been correctly updated to use npm, maintaining consistency with the project's transition from bun to npm.

evm-e2e/package.json (2)

25-25: LGTM: Good addition of code formatting tools

The addition of Prettier with specific scripts for formatting TypeScript test files is a good practice for maintaining consistent code style. The configuration targets test files appropriately with "test/**/*.ts".

Also applies to: 34-35


27-27: Verify TypeChain integration with OpenZeppelin contracts

The addition of TypeChain for generating TypeScript bindings is good, but we should ensure it's properly configured to work with OpenZeppelin contracts.

Let's check the TypeChain setup:

#!/bin/bash
# Verify TypeChain configuration and contract imports

# Check for TypeChain artifacts directory in gitignore
if ! rg -q "typechain-types" .gitignore; then
  echo "Warning: typechain-types directory should be added to .gitignore"
fi

# Look for OpenZeppelin contract imports
rg -l "@openzeppelin/contracts" .
evm-e2e/test/utils.ts (2)

1-9: LGTM! Imports are properly organized.

The new factory imports for EventsEmitter and TransactionReverter align with the introduction of new contracts, maintaining consistency with the codebase changes.


43-55: Verify test coverage for transaction receipt fields.

Since this PR fixes transaction receipt marshalling, ensure that the new EventsEmitter and TransactionReverter contracts include tests that verify the presence of to, from, effectiveGasPrice, and contractAddress fields in their transaction receipts.

✅ Verification successful

Let me check the content of these test files to verify the coverage of transaction receipt fields.


Transaction receipt fields are thoroughly tested

The test coverage for transaction receipt fields is comprehensive and well-structured:

  • tx_receipt.test.ts contains thorough assertions in assertBaseReceiptFields:
    • Validates all basic fields including status, type, hash, index
    • Verifies block-related fields: blockNumber, blockHash
    • Checks address fields: from, to, contractAddress
    • Tests gas-related fields: gasUsed, cumulativeGasUsed
    • Validates logs: logsBloom, logs
  • Tests cover different scenarios:
    • Contract creation (null to, valid contractAddress)
    • Contract interactions (valid to, event logs)
    • ETH transfers (valid to, no logs)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for receipt field assertions in test files
rg -l "receipt\.[to|from|effectiveGasPrice|contractAddress]" "evm-e2e/test/"

Length of output: 148


Script:

#!/bin/bash
# Check the content of test files for receipt field assertions
echo "=== contract_send_nibi.test.ts ==="
rg "receipt\." -A 2 -B 2 "evm-e2e/test/contract_send_nibi.test.ts"
echo -e "\n=== tx_receipt.test.ts ==="
rg "receipt\." -A 2 -B 2 "evm-e2e/test/tx_receipt.test.ts"

Length of output: 2674

evm-e2e/test/tx_receipt.test.ts (5)

1-6: LGTM! Well-structured imports.

The imports are properly organized with clear separation between testing framework, external libraries, and local utilities.


7-11: LGTM! Appropriate test suite configuration.

The 15-second timeout is reasonable for e2e tests involving blockchain transactions, and using a random recipient address helps ensure test isolation.


12-23: LGTM! Well-crafted test for basic transaction receipt.

This test case effectively validates the to field, which was one of the missing fields mentioned in the PR objectives. The test provides a good baseline for the simplest transaction type.


39-63: LGTM! Thorough validation of event logs.

The test provides comprehensive validation of event logs, including proper verification of event signatures, topics, and indexed parameters. This helps ensure the integrity of transaction receipts with events.


101-123: LGTM! Comprehensive event log validation.

The helper function provides thorough validation of all event log fields with proper format checking for addresses, hashes, and topics.

eth/rpc/backend/tx_info_test.go (1)

Line range hint 15-192: LGTM! Comprehensive test coverage for transaction retrieval.

The test suite thoroughly covers various transaction retrieval scenarios and includes proper assertions for all relevant fields, including those mentioned in the PR objectives (to, from).

eth/rpc/backend/tx_info.go (2)

138-142: LGTM: TransactionReceipt struct properly extended

The added fields properly complement the embedded gethcore.Receipt struct, ensuring all essential transaction information is captured. The field types are appropriately chosen to handle null cases and hex serialization.


286-286: LGTM: Proper effective gas price calculation

The effective gas price is correctly calculated and converted to hexutil.Big for proper JSON serialization. The error handling for pruned nodes is appropriate.

CHANGELOG.md (1)

Line range hint 1-24: LGTM! Well-structured changelog.

The changelog follows best practices:

  • Clear sections for different types of changes
  • Chronological ordering with newest changes first
  • Links to PRs for traceability
  • Follows Keep a Changelog format

Comment on lines +7 to +12
typechain: {
outDir: "types",
target: "ethers-v6",
alwaysGenerateOverloads: false,
dontOverrideCompile: false,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider enhancing TypeChain configuration for better developer experience.

The current TypeChain configuration could be improved:

  1. Setting alwaysGenerateOverloads: true would provide better TypeScript support for overloaded functions
  2. Consider adding dontOverrideCompile: true to prevent unnecessary recompilation during development
   typechain: {
     outDir: "types",
     target: "ethers-v6",
-    alwaysGenerateOverloads: false,
-    dontOverrideCompile: false,
+    alwaysGenerateOverloads: true,
+    dontOverrideCompile: true,
   },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
typechain: {
outDir: "types",
target: "ethers-v6",
alwaysGenerateOverloads: false,
dontOverrideCompile: false,
},
typechain: {
outDir: "types",
target: "ethers-v6",
alwaysGenerateOverloads: true,
dontOverrideCompile: true,
},

Comment on lines +11 to +13
install:
npm install
npx hardhat typechain
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Update required: Add typechain script to package.json

The install recipe in the justfile runs npx hardhat typechain, but there's no corresponding script in package.json. While all required dependencies are present (hardhat, typechain, @typechain/hardhat, @typechain/ethers-v6), you should add a dedicated script for type generation to ensure consistency and maintainability.

Add the following to the "scripts" section in package.json:

"typechain": "hardhat typechain"

Then update the justfile to use this script:

install:
  npm install
  npm run typechain
🔗 Analysis chain

LGTM! Verify package.json scripts.

The simplified install recipe looks good, consolidating dependency installation and type generation into a single step.

Let's verify the corresponding npm scripts are properly configured:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that package.json contains the required scripts and dependencies

# Check if package.json exists and contains required dependencies
rg -A 5 '"dependencies"|"devDependencies"' package.json

# Check if hardhat and typechain are configured
rg '"scripts"' package.json -A 10

Length of output: 199


Script:

#!/bin/bash
# Let's check the correct path by finding package.json in the evm-e2e directory
fd package.json evm-e2e

# If found, let's check its contents
fd package.json evm-e2e --exec cat {}

Length of output: 1106

Comment on lines +22 to +27
event ValueUpdateAttempted(address sender, uint256 value);
function emitAndRevert(uint256 newValue) public {
emit ValueUpdateAttempted(msg.sender, newValue);
value = newValue;
revert("Reverted after event emission");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve event emission timing and error handling.

Consider the following improvements:

  1. Emit the event after the state change to maintain logical order
  2. Use a custom error instead of a string message
     event ValueUpdateAttempted(address sender, uint256 value);
+    error EventEmissionReverted(address sender, uint256 attemptedValue);
+
     function emitAndRevert(uint256 newValue) public {
-        emit ValueUpdateAttempted(msg.sender, newValue);
         value = newValue;
-        revert("Reverted after event emission");
+        emit ValueUpdateAttempted(msg.sender, newValue);
+        revert EventEmissionReverted(msg.sender, newValue);
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
event ValueUpdateAttempted(address sender, uint256 value);
function emitAndRevert(uint256 newValue) public {
emit ValueUpdateAttempted(msg.sender, newValue);
value = newValue;
revert("Reverted after event emission");
}
event ValueUpdateAttempted(address sender, uint256 value);
error EventEmissionReverted(address sender, uint256 attemptedValue);
function emitAndRevert(uint256 newValue) public {
value = newValue;
emit ValueUpdateAttempted(msg.sender, newValue);
revert EventEmissionReverted(msg.sender, newValue);
}

Comment on lines +10 to +13
function setAndRevert(uint256 newValue) public {
value = newValue;
revert("Transaction reverted after state change");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider using custom error and add input validation.

The function could be improved by:

  1. Using a custom error instead of a string message for gas efficiency
  2. Adding input validation if there are any value constraints
+    error StateChangeReverted(uint256 attemptedValue);
+
     function setAndRevert(uint256 newValue) public {
+        // Add any necessary input validation here
         value = newValue;
-        revert("Transaction reverted after state change");
+        revert StateChangeReverted(newValue);
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function setAndRevert(uint256 newValue) public {
value = newValue;
revert("Transaction reverted after state change");
}
error StateChangeReverted(uint256 attemptedValue);
function setAndRevert(uint256 newValue) public {
// Add any necessary input validation here
value = newValue;
revert StateChangeReverted(newValue);
}

Comment on lines +1 to +28
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract TransactionReverter {
uint256 public value;

error CustomRevertReason(uint256 providedValue);

// Will try to set state and revert unconditionally
function setAndRevert(uint256 newValue) public {
value = newValue;
revert("Transaction reverted after state change");
}

// Will revert with custom error
function revertWithCustomError(uint256 newValue) public {
value = newValue;
revert CustomRevertReason(newValue);
}

// Will emit event and then revert
event ValueUpdateAttempted(address sender, uint256 value);
function emitAndRevert(uint256 newValue) public {
emit ValueUpdateAttempted(msg.sender, newValue);
value = newValue;
revert("Reverted after event emission");
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Missing test coverage for transaction reversion scenarios

The test suite lacks coverage for the reversion scenarios implemented in TransactionReverter.sol. While there are tests for successful transactions and event emissions, the following test cases are missing:

  • State changes before reversion (setAndRevert)
  • Custom error data handling (revertWithCustomError)
  • Event emission followed by reversion (emitAndRevert)

These scenarios are critical for verifying proper transaction receipt marshalling in error cases.

Locations needing attention:

  • evm-e2e/test/tx_receipt.test.ts: Add test cases for reversion scenarios
  • Consider adding assertions for:
    • Receipt status field for failed transactions
    • Proper error data capture
    • Event persistence in reverted transactions
🔗 Analysis chain

Verify test coverage for transaction receipt marshalling.

The contract provides good test scenarios for transaction receipt marshalling. Ensure that tests cover all reversion cases and verify the correct marshalling of:

  • State changes before reversion
  • Custom error data
  • Emitted events
  • Transaction status
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for comprehensive test coverage of this contract

# Look for test files that use this contract
rg -l "TransactionReverter" --type ts

# Check for test cases covering each reversion scenario
rg -A 5 "setAndRevert|revertWithCustomError|emitAndRevert" --type ts

Length of output: 162


Script:

#!/bin/bash
# Let's examine the test files more closely
cat evm-e2e/test/tx_receipt.test.ts

Length of output: 4355


Script:

#!/bin/bash
# Also check the utils file for any helper functions
cat evm-e2e/test/utils.ts

Length of output: 2046

@@ -11,9 +11,8 @@
"devDependencies": {
"@jest/globals": "^29.7.0",
"@typechain/ethers-v6": "^0.5.1",
"@typechain/hardhat": "^9.1.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Migration to Hardhat tooling needs completion

The verification reveals an incomplete migration from Bun to Hardhat/Jest:

  • Hardhat and TypeChain are properly configured in hardhat.config.js
  • Test files are present and using Jest (jest.config.js exists)
  • However, Bun references still remain in:
    • tsconfig.json still includes "bun-types"
    • README.md still shows Bun test execution instructions
    • No TypeChain types directory is set up yet

Please:

  1. Remove "bun-types" from tsconfig.json
  2. Update README.md with new Jest test instructions
  3. Add a script to generate TypeChain types
  4. Add "types" directory to .gitignore
🔗 Analysis chain

Verify Hardhat tooling compatibility with existing tests

The addition of Hardhat and its toolchain represents a significant change in the testing infrastructure. While this is a good modernization step, we should ensure:

  1. The transition from the previous testing setup is complete
  2. All existing tests are compatible with the new Hardhat environment

Let's verify the test setup:

Also applies to: 28-30

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for any remaining references to the old testing infrastructure
# and verify the presence of Hardhat configuration

# Look for Hardhat config file
if ! fd -t f "hardhat.config.ts"; then
  echo "Warning: Hardhat config file is missing"
fi

# Check for any remaining references to old test setup
rg -l 'bun' .

Length of output: 815


Script:

#!/bin/bash
# Let's verify the test setup more thoroughly

# Check for Hardhat config and test files
echo "=== Checking Hardhat Setup ==="
fd -t f "hardhat.config" .
fd -t f -e test.ts -e spec.ts evm-e2e/

# Check for any remaining bun configurations
echo -e "\n=== Checking Bun References ==="
rg -l "bun" evm-e2e/
rg -l "bunx" evm-e2e/

# Check test scripts in package.json
echo -e "\n=== Package.json Test Scripts ==="
cat evm-e2e/package.json | jq .scripts

# Look for typechain generated files/configs
echo -e "\n=== TypeChain Setup ==="
fd typechain evm-e2e/

Length of output: 1035


Script:

#!/bin/bash
# Let's check the specific test setup and migrations

# Check the content of hardhat config
echo "=== Hardhat Config Content ==="
cat evm-e2e/hardhat.config.js

# Check for test files in correct location
echo -e "\n=== Test Files ==="
fd -e ts . evm-e2e/test/

# Check remaining bun references in specific files
echo -e "\n=== Bun Reference Details ==="
echo "--- tsconfig.json ---"
cat evm-e2e/tsconfig.json | grep -A 5 -B 5 "bun"
echo "--- README.md ---"
cat evm-e2e/README.md | grep -A 5 -B 5 "bun"

# Check Jest configuration
echo -e "\n=== Jest Config ==="
fd -t f "jest.config" evm-e2e/

Length of output: 1693

evm-e2e/test/utils.ts Show resolved Hide resolved
evm-e2e/test/utils.ts Show resolved Hide resolved
eth/rpc/backend/tx_info.go Show resolved Hide resolved
@k-yang k-yang merged commit bf70839 into main Oct 31, 2024
16 checks passed
@k-yang k-yang deleted the fix/evm-tx-receipt branch October 31, 2024 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants