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

test(evm): more e2e test contracts for edge cases #1901

Merged
merged 5 commits into from
May 31, 2024
Merged

Conversation

onikonychev
Copy link
Contributor

Introduces 2 more test types:

  1. Sending native (non ERC-20) tokens via smart contract
  2. Executing smart contract with infinite loop to fail with "out of gas"

Copy link
Contributor

coderabbitai bot commented May 30, 2024

Walkthrough

The recent updates enhance the EVM testing suite by adding new end-to-end test contracts and cases, particularly focusing on edge scenarios and smart contract interactions involving ERC-20 tokens. Key changes include the introduction of new Solidity contracts for handling infinite loops and token transfers, updates to configuration files for better test management, and the inclusion of comprehensive test cases to validate these functionalities.

Changes

File(s) Change Summary
CHANGELOG.md Added a summary of new end-to-end test contracts for edge cases in the EVM testing suite.
e2e/evm/README.md Updated to include new test cases for smart contracts and ERC-20 contracts with results showing 6 tests passing.
e2e/evm/contracts/InfiniteLoopGas.sol Introduced a Solidity contract demonstrating infinite loop gas consumption.
e2e/evm/contracts/SendReceiveNibi.sol Added two Solidity contracts (ReceiveNibi and SendNibi) for handling Nibi token transfers.
e2e/evm/jest.config.js Updated testMatch configuration and added maxWorkers setting.
e2e/evm/test/basic_queries.test.js Introduced a test suite for basic EVM queries, including transfers, balance checks, and transaction validations.
e2e/evm/test/contract_infinite_loop_gas.test.js Added tests for handling infinite loop gas exhaustion in EVM contracts.
e2e/evm/test/contract_send_nibi.test.js Introduced tests for sending Nibi tokens using various methods in smart contracts.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant User
    participant EVM
    participant Contract as Smart Contract

    User->>Contract: Call sendViaTransfer()
    Contract->>EVM: Transfer Nibi
    EVM-->>Contract: Confirm transfer
    Contract-->>User: Transfer successful

    User->>Contract: Call forever()
    Contract->>EVM: Execute infinite loop
    EVM-->>Contract: Gas exhaustion, revert transaction
    Contract-->>User: Transaction failed
Loading

Poem

In the realm of code so wise,
New tests for EVM arise,
Infinite loops and tokens sent,
Through smart contracts, gas is spent.
With tests that pass and bugs that flee,
Our code runs smooth, as it should be.
🐇✨


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

@onikonychev onikonychev marked this pull request as ready for review May 30, 2024 17:59
@onikonychev onikonychev requested a review from a team as a code owner May 30, 2024 17:59
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: 6

Outside diff range and nitpick comments (1)
e2e/evm/README.md (1)

Line range hint 4-4: Fix markdown issues.

- Folder contains ethers.js test bundle which executes main
+ Folder contains ethers.js test bundle which executes main

- Contract is compiled via HardHat into [json file](./contracts/FunTokenCompiled.json)
+ Contract is compiled via HardHat into [json file](./contracts/FunTokenCompiled.json)

Also applies to: 12-12

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4256a18 and 2bcd9d8.

Files ignored due to path filters (3)
  • e2e/evm/contracts/InfiniteLoopGasCompiled.json is excluded by !**/*.json
  • e2e/evm/contracts/ReceiveNibiCompiled.json is excluded by !**/*.json
  • e2e/evm/contracts/SendNibiCompiled.json is excluded by !**/*.json
Files selected for processing (10)
  • CHANGELOG.md (1 hunks)
  • e2e/evm/README.md (1 hunks)
  • e2e/evm/contracts/InfiniteLoopGas.sol (1 hunks)
  • e2e/evm/contracts/SendReceiveNibi.sol (1 hunks)
  • e2e/evm/jest.config.js (1 hunks)
  • e2e/evm/test/basic_queries.test.js (1 hunks)
  • e2e/evm/test/contract_infinite_loop_gas.test.js (1 hunks)
  • e2e/evm/test/contract_send_nibi.test.js (1 hunks)
  • e2e/evm/test/erc20.test.js (1 hunks)
  • e2e/evm/test/setup.js (1 hunks)
Additional context used
Biome
e2e/evm/jest.config.js

[error] 5-5: The computed expression can be simplified without the use of a string literal.

e2e/evm/test/setup.js

[error] 3-3: A Node.js builtin module should be imported with the node: protocol.


[error] 18-18: The computed expression can be simplified without the use of a string literal.


[error] 19-19: The computed expression can be simplified without the use of a string literal.

e2e/evm/test/erc20.test.js

[error] 13-13: This let declares a variable that is only assigned once.


[error] 23-23: This let declares a variable that is only assigned once.

e2e/evm/test/contract_send_nibi.test.js

[error] 14-14: This let declares a variable that is only assigned once.

LanguageTool
e2e/evm/README.md

[uncategorized] ~7-~7: You might be missing the article “an” here.
Context: ...sol) represents simple ERC20 token with initial supply 1000,000 * 10e18 tokens. Cont...


[uncategorized] ~7-~7: Possible missing preposition found.
Context: ... simple ERC20 token with initial supply 1000,000 * 10e18 tokens. Contract is c...


[uncategorized] ~17-~17: You might be missing the article “a” here.
Context: ...Run ### Run Nibiru node Tests require Nibiru node running with JSON RPC enabled. Lo...

Markdownlint
e2e/evm/README.md

4-4: Expected: 0 or 2; Actual: 1
Trailing spaces


12-12: Expected: 1; Actual: 2
Multiple consecutive blank lines

Additional comments not posted (7)
e2e/evm/jest.config.js (1)

3-3: Updated testMatch pattern to include only .test.js files is a good practice for clarity and specificity in test execution.

e2e/evm/contracts/InfiniteLoopGas.sol (1)

4-17: The InfiniteLoopGas contract is well-implemented for its purpose of testing gas limit behavior in transactions. Good use of comments to explain the expected outcome when the gas runs out.

e2e/evm/test/contract_infinite_loop_gas.test.js (1)

3-23: The test for the InfiniteLoopGas contract is correctly implemented. It effectively checks for the 'out of gas' error and ensures that the state is not changed after failure, which is crucial for this scenario.

e2e/evm/test/setup.js (1)

2-2: Proper use of dotenv for environment configuration enhances maintainability and security by managing sensitive information outside of the codebase.

e2e/evm/contracts/SendReceiveNibi.sol (2)

21-29: LGTM! The ReceiveNibi contract functions are well implemented.


33-50: LGTM! The SendNibi contract methods are correctly implemented and documented.

CHANGELOG.md (1)

68-68: The changelog entry for PR #1901 is correctly formatted and provides the necessary information.

e2e/evm/jest.config.js Show resolved Hide resolved
@@ -0,0 +1,31 @@
const {ethers} = require("ethers");
const {config} = require('dotenv')
const fs = require("fs");
Copy link
Contributor

Choose a reason for hiding this comment

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

Import the fs module using the node: protocol to ensure compatibility and clarity.

- const fs = require("fs");
+ const fs = require("node:fs");

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.

Suggested change
const fs = require("fs");
const fs = require("node:fs");

Comment on lines +18 to +19
const bytecode = contractJSON['bytecode']
const abi = contractJSON['abi']
Copy link
Contributor

Choose a reason for hiding this comment

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

Simplify the access to JSON properties by removing the string literals.

- const bytecode = contractJSON['bytecode']
- const abi = contractJSON['abi']
+ const { bytecode, abi } = contractJSON

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.

Suggested change
const bytecode = contractJSON['bytecode']
const abi = contractJSON['abi']
const { bytecode, abi } = contractJSON


// Execute contract: ERC20 transfer
const shrimpAddress = ethers.Wallet.createRandom().address
let ownerInitialBalance = ethers.parseUnits("1000000", 18)
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using const instead of let for variables that are not reassigned, which enhances code clarity and intent.

- let ownerInitialBalance = ethers.parseUnits("1000000", 18)
- let tx = await contract.transfer(shrimpAddress, amountToSend)
+ const ownerInitialBalance = ethers.parseUnits("1000000", 18)
+ const tx = await contract.transfer(shrimpAddress, amountToSend)

Also applies to: 23-23

Committable suggestion was skipped due low confidence.

e2e/evm/test/contract_send_nibi.test.js Outdated Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

JavaScript is insanely slow

@NibiruChain NibiruChain deleted a comment from coderabbitai bot May 31, 2024
Unique-Divine and others added 2 commits May 31, 2024 00:49
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@Unique-Divine Unique-Divine enabled auto-merge (squash) May 31, 2024 05:50
@Unique-Divine Unique-Divine merged commit 282fbf7 into main May 31, 2024
9 checks passed
@Unique-Divine Unique-Divine deleted the test/evm-e2e branch May 31, 2024 05:50
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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2bcd9d8 and 6a2524e.

Files selected for processing (2)
  • e2e/evm/test/basic_queries.test.js (1 hunks)
  • e2e/evm/test/contract_send_nibi.test.js (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • e2e/evm/test/basic_queries.test.js
  • e2e/evm/test/contract_send_nibi.test.js

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