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

Adds revert reason test + error logging #1616

Merged
merged 6 commits into from
Oct 23, 2023
Merged

Conversation

otherview
Copy link
Contributor

Why this change is needed

As per title.

What changes were made as part of this PR

Please provide a high level list of the changes made

PR checks pre-merging

Please indicate below by ticking the checkbox that you have read and performed the required
PR checks

  • PR checks reviewed and performed

@coderabbitai
Copy link

coderabbitai bot commented Oct 20, 2023

Walkthrough

The changes primarily focus on enhancing error handling and testing for Ethereum smart contracts. A new package faucet has been introduced, which includes code related to an Ethereum smart contract. The error handling has been improved in the walletextension API, and a new test function has been added to the obscurogateway package to test error scenarios.

Changes

File Summary
integration/obscurogateway/errors_contract.go Introduced a new package faucet with Ethereum smart contract related code. The contract's ABI and bytecode are initialized, and several functions for setting and retrieving a key are defined.
integration/obscurogateway/obscurogateway_test.go Added a new test function testErrorsRevertedArePassed to test error handling. The test function TestObscuroGateway has been updated to include this new test.
tools/walletextension/api/routes.go A minor change where a line of code is moved within a function.
tools/walletextension/api/utils.go Enhanced error handling by adding logging statements and forwarding error responses to the user. The handleEthError function has been updated to handle a new type of error (errutil.EVMSerialisableError).
integration/common/utils.go Added a new function AwaitReceiptEth to wait for a transaction receipt on the Ethereum network. The AwaitReceipt function has been modified to use the AwaitReceiptEth function internally.
tools/walletextension/common/json.go The import statement has been updated to include the "encoding/json" package.

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • Mention @coderabbitai in any review comment for bot assistance.
  • Note: Review comments are made on code diffs or files, not on the PR overview.

Pause Incremental Reviews

  • Insert @coderabbitai: ignore in the PR description to halt the bot's ongoing reviews. Remove the line to resume.
  • Additionally, enter @coderabbitai pause to halt the bot's ongoing reviews as any issue or review comment. To
    resume reviews, enter @coderabbitai resume as any issue or review comment.

Copy link

@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.

Review Status

Actionable comments generated: 4

Commits Files that changed from the base of the PR and between 85f05f9 and 0fe06e8.
Files selected for processing (4)
  • integration/obscurogateway/errors_contract.go (1 hunks)
  • integration/obscurogateway/obscurogateway_test.go (3 hunks)
  • tools/walletextension/api/routes.go (1 hunks)
  • tools/walletextension/api/utils.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • tools/walletextension/api/routes.go
Additional comments (Suppressed): 5
tools/walletextension/api/utils.go (3)
  • 118-118: The logging statement has been moved up to log the error response before it is forwarded to the user. This is a good practice as it ensures that the error is logged even if the forwarding fails for any reason.

  • 126-126: The error message in the logging statement has been updated to provide more context about the error. This is a good practice as it makes the logs more informative and easier to understand.

  • 128-130: The error handling in the handleEthError and handleError functions has been updated to log an error message if writing the response back to the user fails. This is a good practice as it ensures that all errors are logged and can be investigated if necessary.

integration/obscurogateway/obscurogateway_test.go (2)
  • 15-18: The import statement github.com/ethereum/go-ethereum seems to be unused in the new hunks. Please verify if it's necessary or remove it to avoid unnecessary imports.

  • 86-92: The addition of the new test function testErrorsRevertedArePassed is noted. Ensure that this function is implemented correctly and that it is being called with the correct parameters.

integration/obscurogateway/errors_contract.go Outdated Show resolved Hide resolved
integration/obscurogateway/errors_contract.go Show resolved Hide resolved
integration/obscurogateway/obscurogateway_test.go Outdated Show resolved Hide resolved
Copy link

@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.

Review Status

Actionable comments generated: 3

Commits Files that changed from the base of the PR and between 0fe06e8 and ae1f863.
Files selected for processing (1)
  • integration/obscurogateway/errors_contract.go (1 hunks)

Copy link

@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.

Review Status

Actionable comments generated: 1

Commits Files that changed from the base of the PR and between ae1f863 and adfd06b.
Files selected for processing (1)
  • tools/walletextension/api/utils.go (2 hunks)
Additional comments (Suppressed): 4
tools/walletextension/api/utils.go (4)
  • 8-14: The import github.com/obscuronet/go-obscuro/go/common/errutil has been added. Ensure that this package is available and accessible in the project's dependencies.

  • 112-114: The error is being type-checked and cast to errutil.EVMSerialisableError. This is a good practice for handling specific error types. However, it's important to ensure that all errors that can be cast to errutil.EVMSerialisableError have a Reason field, otherwise this could lead to a runtime panic.

  • 130-130: The error message is being logged before writing the response. This is a good practice as it ensures that all errors are logged even if there is a failure when writing the response.

  • 132-134: The error message is being written as the response. This is a good practice for providing feedback to the user. However, ensure that no sensitive information is being exposed in the error messages.

Copy link

@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.

Review Status

Actionable comments generated: 0

Commits Files that changed from the base of the PR and between adfd06b and 48ac5dc.
Files selected for processing (3)
  • integration/common/utils.go (2 hunks)
  • integration/obscurogateway/obscurogateway_test.go (5 hunks)
  • tools/walletextension/api/utils.go (2 hunks)
Additional comments (Suppressed): 11
tools/walletextension/api/utils.go (4)
  • 8-13: The import statements have been updated to include the errutil package from go-obscuro/go/common. This package is used for handling Ethereum Virtual Machine (EVM) errors.

  • 111-114: The error handling has been enhanced to specifically handle errutil.EVMSerialisableError type errors. This is a good practice as it allows for more granular error handling and logging.

  • 122-126: The error response is logged before being written back to the client. This is a good practice as it allows for better tracking and debugging of errors.

  • 129-134: The handleError function has been updated to log the error before writing the response. This is a good practice as it allows for better tracking and debugging of errors.

integration/common/utils.go (2)
  • 12-17: The new imports github.com/ethereum/go-ethereum/ethclient and github.com/obscuronet/go-obscuro/go/common/errutil are introduced to handle Ethereum client and error utility respectively. Ensure these packages are properly installed and available in the project's dependencies.

  • 64-88: The new function AwaitReceiptEth is introduced to wait for a transaction receipt on the Ethereum network. It uses the Ethereum client to fetch the transaction receipt and retries if the transaction is not found. It returns an error if the transaction fails or times out. The function also checks the receipt status and returns an error if the status is failed. This function seems to be a good addition for handling Ethereum transactions and their receipts.

69, 76:
The use of fmt.Println for logging is not recommended in production code. Consider using a structured logging library that can provide more control over log levels and formats. This will help in filtering and analyzing logs more effectively.

- fmt.Println("Fetching receipt for tx: ", txHash.Hex())
+ log.Info().Str("txHash", txHash.Hex()).Msg("Fetching receipt for tx")

- fmt.Println("No tx receipt after: ", time.Since(startTime))
+ log.Info().Dur("timeElapsed", time.Since(startTime)).Msg("No tx receipt after")
integration/obscurogateway/obscurogateway_test.go (5)
  • 4-10: The import of github.com/obscuronet/go-obscuro/go/common/errutil is new. Ensure that this package is available and correctly imported.

  • 16-19: The import of github.com/ethereum/go-ethereum is new. Ensure that this package is available and correctly imported.

  • 26-29: The import of integrationCommon "github.com/obscuronet/go-obscuro/integration/common" is new. Ensure that this package is available and correctly imported.

  • 89-94: A new test function testErrorsRevertedArePassed is added to the test suite. Ensure that this function is implemented correctly and that it is called with the correct parameters.

  • 174-244: The new function testErrorsRevertedArePassed tests the error handling of the Obscuro Gateway when Ethereum smart contract errors are encountered. It deploys a contract, calls functions that force errors, and checks that the errors are correctly handled and returned. This is a good addition to the test suite as it verifies the robustness of the error handling mechanism. However, ensure that the error messages checked in lines 219, 231, and 243 are the expected ones.

Copy link

@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.

Review Status

Actionable comments generated: 3

Commits Files that changed from the base of the PR and between 48ac5dc and f681fbe.
Files selected for processing (3)
  • integration/obscurogateway/obscurogateway_test.go (6 hunks)
  • tools/walletextension/api/utils.go (2 hunks)
  • tools/walletextension/common/json.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • tools/walletextension/common/json.go
Additional comments (Suppressed): 7
tools/walletextension/api/utils.go (3)
  • 5-13: The new import github.com/obscuronet/go-obscuro/go/common/errutil is introduced to handle a new type of error (errutil.EVMSerialisableError). Ensure that this package is available and updated in your dependencies.

  • 111-114: The error type checking and handling for errutil.EVMSerialisableError is a good practice. It allows for more specific error handling and can provide more detailed error information.

  • 129-134: The handleError function is updated to log the error before writing the response. This is a good practice as it ensures that all errors are logged even if there is a failure in writing the response.

integration/obscurogateway/obscurogateway_test.go (4)
  • 22-28: The import statement for the github.com/obscuronet/go-obscuro/integration/common package is added. Ensure that the new import does not conflict with existing code and is used appropriately.

  • 88-91: The testAreTxsMinted function is commented out and a new test function testErrorsRevertedArePassed is added. Ensure that the new test function covers all the necessary test cases and does not break existing functionality. Also, if testAreTxsMinted is no longer needed, consider removing it instead of commenting it out.

  • 173-247: A new test function testErrorsRevertedArePassed is added. This function tests the error handling capabilities of the Obscuro Gateway by making various requests to a Geth server and the Obscuro Gateway server. It compares the responses and ensures that the Obscuro Gateway returns the expected error format. This is a good addition to the test suite as it enhances the error handling tests.

  • 270-278: The AwaitReceiptEth function is used to wait for transaction receipts instead of the previous loop-based approach. This is a good change as it simplifies the code and makes it more readable. However, ensure that the AwaitReceiptEth function handles all edge cases and timeouts correctly.

tools/walletextension/api/utils.go Show resolved Hide resolved
@otherview otherview merged commit 20e5799 into main Oct 23, 2023
2 checks passed
@otherview otherview deleted the pedro/gw_errors_test_plus_log branch October 23, 2023 09:55
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