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

SYS-334 - Testing and Coverage Report Generation #47

Open
wants to merge 53 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
11e5a63
add unit test
kenny-io May 22, 2024
5314535
update testing logic, leverage json rpc server, test counts and count…
kenny-io May 23, 2024
559b336
added test cases for api/health and api/subscribe
soniasingla May 23, 2024
189394a
Add new integration tests
kenny-io May 28, 2024
88ad534
increse test timeout, organize test files
kenny-io May 28, 2024
b0399c1
use global config port
kenny-io May 29, 2024
2a4b3bf
added new integration test cases for eth_blockNumber, eth_chainId and…
soniasingla May 29, 2024
01cd262
added script to initialize localtestnet
soniasingla Jun 5, 2024
d505ae7
set up local test env with local shardeum network
kenny-io Jun 13, 2024
48e73f9
modify the script
soniasingla Jun 25, 2024
ea24455
add new test cases (#33)
kenny-io Jun 26, 2024
2f0f1bc
add remaining test cases
soniasingla Jun 26, 2024
b6f899e
SYS-254 fixes race condition in clearing stats collection (#32)
asyed94 Jun 26, 2024
9d68944
'Refactor test cases, improve test coverage, and better error handling
kenny-io Jun 26, 2024
0b769d1
update params
soniasingla Jun 27, 2024
ffad851
Add new transaction test cases (#35)
kenny-io Jun 27, 2024
6bafed3
updated parameters and added new test cases
soniasingla Jun 27, 2024
5b6ff9e
Add new test cases (#36)
kenny-io Jun 27, 2024
e5e930a
update the failing tests
soniasingla Jun 28, 2024
13ca845
update the failing tests part 2
soniasingla Jun 28, 2024
a65bb7f
use env for txn tests (#37)
kenny-io Jun 28, 2024
6f77097
rename test files for consistency
soniasingla Jun 28, 2024
7e9ce31
update setup script
kenny-io Jun 28, 2024
4746c8b
update txn tests
kenny-io Jun 28, 2024
b784980
add readme, update script and test
soniasingla Jun 28, 2024
76ee177
Update testing instructions
kenny-io Jun 28, 2024
df11ba3
fine-tune test script to execute gracefully
kenny-io Jul 1, 2024
55164b4
start jrpc server in the background so tests can run
kenny-io Jul 1, 2024
1cd0f75
update readme for testing instructions
kenny-io Jul 1, 2024
ec32f93
update testing instructions
kenny-io Jul 1, 2024
598099a
remove the unsupported methods
soniasingla Jul 2, 2024
0bef7ff
optimize test script
kenny-io Jul 3, 2024
9309a55
optimize test script
kenny-io Jul 3, 2024
f204805
update testing instructions
kenny-io Jul 3, 2024
cfdb15e
mod: change URL to PATH
kenny-io Jul 4, 2024
1ce3fcb
Merge branch 'dev' into localtest
soniasingla Jul 5, 2024
35bbba9
Remove gitlab instances from readme (#38)
soniasingla Jul 5, 2024
e8621dc
Merge branch 'dev' into localtest
chrischabot Jul 5, 2024
2487e9a
optimize tests and formatting
kenny-io Jul 5, 2024
7c89191
Merge remote-tracking branch 'origin/localtest' into localtest
kenny-io Jul 5, 2024
f5aab0c
remove unused deps
kenny-io Jul 15, 2024
0c2a3e9
reauthorize gated apis
kenny-io Jul 15, 2024
3abed89
shutdown script gracefully
kenny-io Jul 15, 2024
4fe7188
reformat to the original version
soniasingla Jul 16, 2024
b420c5d
update test script
kenny-io Jul 16, 2024
3448cff
add test docs
kenny-io Jul 16, 2024
c6c26f3
update README.md - add Shardeum branding
kenny-io Jul 16, 2024
f289260
updating configs for coverage report generation
paulgs9988 Jul 16, 2024
273e07a
update test docs - document test account
kenny-io Jul 18, 2024
4c58e21
remove carrots, use strict versions
kenny-io Jul 18, 2024
da6c2b6
fix identation
kenny-io Jul 18, 2024
38a3dc7
rmv test script
kenny-io Jul 18, 2024
121cc46
exec test script with npm test
kenny-io Jul 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"presets": [
Copy link
Contributor

Choose a reason for hiding this comment

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

What was the source for this?

Copy link
Contributor

Choose a reason for hiding this comment

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

@paulgs9988 added the file with this commit f289260

["@babel/preset-env", { "targets": { "node": "current" } }],
"@babel/preset-typescript"
]
}

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ config.js
dist/
.idea/
.DS_Store
.test/
59 changes: 53 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
<p align="center">
<img src="https://github.com/shardeum/.github/raw/dev/shardeum-white-bg.png" alt="Shardeum Logo" width="70%">
</p>

<p align="center">
<h2 align="center">Shardeum is an EVM based autoscaling blockchain</h2>
</p>

# Overview

The Shardeum JSON-RPC Server enables developers to interact with the Shardeum blockchain network. It allows dapps to post request, retrieve information, and other related operations, using JSON-RPC over HTTP. Additionally, the Shardeum JSON-RPC Server comes with an added REST API for debugging and monitoring purposes.
Expand Down Expand Up @@ -29,15 +37,15 @@ docker compose logs -f
docker compose down
```

# Developer Environment Setup
## Developer Environment Setup

For end users, such as exchanges and large decentralized applications (dApps), seeking to deploy their own RPC server, it is recommended to run the Shardeum JSON-RPC server using Docker. It ensures all dependencies are installed and the server is running in a consistent environment. For developers who want to contribute to this project, running the server from source is recommended. You can use `npm` for installing the server locally.

## Requirements
### Requirements

If you are using `Docker`, in order to run the Shardeum JSON-RPC server, you must have the [Docker](https://docs.docker.com/get-docker/) daemon installed.

## Installing project source code
### Installing project source code

Let’s install the project source code, switch to `dev` branch and follow the below instructions:

Expand Down Expand Up @@ -86,7 +94,42 @@ port: 8080

The RPC URL for using Metamask with Remix IDE and for running scripts is <http://localhost:port> (default: <http://localhost:8080>)

If you are contributing to this project, use Shardeum server to create the network from within the [validator repo](https://gitlab.com/shardus/archive/archive-server). You can find more details [here](https://github.com/shardeum/shardeum)
If you are contributing to this project, use Shardeum server to create the network. You can find more details [here](https://github.com/shardeum/shardeum)

## Running Tests

There are two ways to set up the testing environment for the JSON RPC Server: Manual setup and using a Bash script.

### Setting Up the Test Environment Manually

Follow these steps to set up your local environment for testing:

1. Run the Shardeum network locally (find instructions in the [Shardeum Readme.md](https://github.com/shardeum/shardeum/blob/dev/README.md) file).
2. Once your network is running, visit `localhost:4000/cycleinfo/1` to see your network's details.
3. Wait until the network enters processing mode, which happens when the active nodes in the network equals the minimum amount of nodes required (usually around cycle counter 12-14).
4. Once the network is in processing mode, start the JSON RPC server with `npm run start`.
5. Open a new terminal tab and run the tests with `npm run test` to see the test results.

### Using the Bash Script

The Bash script simplifies the process of setting up the test environment. It's particularly useful if you haven't already configured the Shardeum network and the JSON RPC server locally, though it can also be used if you have. The script will manage both situations and execute the tests for you.

To run the script:

1. Clone and set up the JSON RPC Server locally.
2. Navigate to the root of the project: `cd json-rpc-server`.
3. Execute the script:
- Run `npm local:test ~/root/path/to/your/shardeum/project` - If you already have the Shardeum repo installed locally.
- Run `npm local:test` - If you'd prefer the script to set one up for you.
- The script will creat a test environment path `/.test` and set up the Shardeum network there.
4. It will then start a network of 10 nodes along with the JSON RPC server, and finally run the test suite.
5. Tests involving transactions on the network will fail if your local network has fewer than 5 active nodes.
To address this, you can increase the wait time in the script to more than 10 minutes.
This will give the network sufficient time to reach processing mode with at least 5 active nodes.

A test account with a hardcoded private key is provided in the tests, ensuring that your tests should pass without any extra configuration.

> For detailed information about the tests, check the test document in the `src/__tests__/integration/TEST.md` file and the individual test files located in `src/__tests__`. Each test file contains specific tests for different parts of the JSON-RPC methods.

## Cleanup

Expand All @@ -104,7 +147,7 @@ make clean

This will remove all docker images created by the server during the build process.

# DEBUG Endpoints
## DEBUG Endpoints

These api are protected preventing general public to wiping out debug data to authenticate use `/authenticate/:passphrase`. `passphrase` is set in `config.ts` config file or within the system env variable.

Expand All @@ -127,6 +170,10 @@ GET `/cleanStatTable` this endpoint trigger purging of table that store interfac

GET `/cleanTxTable` this endpoint trigger purging of table that store transaction logging

# Contributing
## Contributing

Contributions are very welcome! Everyone interacting in our codebases, issue trackers, and any other form of communication, including chat rooms and mailing lists, is expected to follow our [code of conduct](CODE_OF_CONDUCT.md) so we can all enjoy the effort we put into this project.

## Community

For chatting with others using Shardeum: [Join the Shardeum Discord Server](https://discord.com/invite/shardeum)
53 changes: 53 additions & 0 deletions TEST.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Shardeum Automated Testing Documentation

## Overview

This documentation covers the setup and execution of automated tests for JSON-RPC methods in the Shardeum JSON RPC Server. The goal is to ensure that Shardeum's implementation adheres to expected behaviors in handling blockchain transactions via JSON-RPC.

## Goals

- Test all JSON-RPC functions to ensure that they perform as expected.
- Verify the Shardus network connectivity and functionality.
- Ensure proper transaction handling and balance updates.

## Test Script Overview

The test script is designed to prepare an environment that is suitable for running the JSON RPC tests. Here is a breakdown of its functionality:

1. **Environment Preparation**:

- Checks for and uses NVM (Node Version Manager).
- Installs Node.js v18.16.1 if not present.
- Installs Rust if missing (version 1.74.1).
- Installs necessary build tools (build-essential on Linux, gcc on macOS).

2. **Repository Management**:

- Uses an existing Shardeum project if specified, otherwise it clones a fresh copy from the Shardeum repository.
- Applies a debug patch for 10-node setup.

3. **Dependency Installation**:

- Runs `npm ci` to install all project dependencies.
- Installs the Shardus CLI tool and the Shardus Archiver if not found.

4. **Network Initialization**:
- Starts a Shardus network with 10 nodes.
- Waits for 4 minutes to allow network stabilization.
- Runs the tests

### Test Execution

Once the environment is set up, the tests are executed using Jest. These tests primarily interact with the `extendedServer` instance defined in the `server.ts` file. It handles JSON-RPC requests and performs the blockchain operations in the tests. Each test file imports its own instance of the RPC server and executes against it.

Each RPC call has its own test file in the `src/__tests__` directory. Each file contains multiple test cases covering different aspects and edge cases for each RPC method.

### Run Tests

The tests typically run automatically through the test script, however, you can run the tests manually by executing the `npm test` command in the JSON RPC Server project. [More on how to run tests here ](https://github.com/shardeum/json-rpc-server/blob/localtest/README.md#running-tests).

## Expand the Test Suite

- **Add New Tests**: New tests can be added by creating new test files under the `src/__tests__` directory. Each new file should mimic the structure of existing tests, initializing its setup, defining the RPC calls, and tearing down after tests.
- **Modifying Existing Tests**: To modify existing tests, locate the relevant test file and add or adjust test cases as needed. Be mindful of potential side effects on other tests due to shared state or network conditions.
- **Enhancing Test Coverage**: Increase coverage by adding more scenarios and edge cases, particularly focusing on error handling and failure modes.
21 changes: 21 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['**/__tests__/**/*.test.ts'],
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1'
},
testTimeout: 20000,
collectCoverage: true,
coverageDirectory: 'coverage',
coverageReporters: ['text', 'lcov'],
coveragePathIgnorePatterns: [
"/node_modules/",
"/dist/",
"/src/server.js"
],
transform: {
"^.+\\.(ts|tsx)$": "ts-jest",
},
};

Loading