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

add robot tests #921

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 27 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,30 @@ jobs:
echo "wallet not deleted"
exit 1
fi
robot-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/install
- name: build
run: go build -tags desktop,production -ldflags "-w -s" -o build/test_wallet main.go
- name: Set up wallet
run: |
mkdir -p $HOME/.config/massa-station-wallet/
echo "$WALLET_TEST_WALLET" > $HOME/.config/massa-station-wallet/wallet_fullpower.yaml
- name: Run app
run: STANDALONE=1 xvfb-run ./build/test_wallet > logs.txt &
env:
WALLET_PASSWORD: ${{ secrets.WALLET_TEST_PASSWORD }}
- name: Wait for server to be up
uses: juliangruber/sleep-action@v1
with:
time: 5s
- name: Run RobotFramework tests
working-directory: api/test
run: |
mkdir results
robot --outputdir results robot_tests
- name: Print logs
if: always()
run: cat logs.txt
5 changes: 5 additions & 0 deletions api/test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
log.html
output.xml
report.html
*.log
selenium-screenshot-*.png
56 changes: 56 additions & 0 deletions api/test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# API Tests

This directory contains tests for the API.

## Prerequisites

The tests are written using the [Robot Framework](https://robotframework.org/) and the [Requests Library](http://marketsquare.github.io/robotframework-requests/). To install the dependencies, you need to have [Python 3](https://www.python.org/downloads/) and [Pip](https://pip.pypa.io/en/stable/installation/) installed.

Once you have `Python 3` and `Pip` installed, you can install the others dependencies by running the following command:

```bash
pip install -r requirements.txt
```

## Running the tests

To run the tests, you need to have a running instance of the API. You can run the API locally. See the [CONTRIBUTING](../../CONTRIBUTING.md) for instructions on how to do that.

> ⚠️ Note that some tests might modify or delete from your computer some files such as Wallets and Plugins. Please make sure you have a backup of your files before running the tests. ⚠️

Once you have a running instance of the API, you can run the tests with:

```bash
robot robot_tests
```

To run a specific test suite, you can run the following command:

```bash
robot robot_tests/<scope>/<test_file>.robot
```

To run a specific test case, you can run the following command:

```bash
robot -t <test_case_name> robot_tests/<scope>/<test_file>.robot
```

> To know more about the Robot Framework, you can read the [User Guide](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html).

## Adding new tests

To add new tests, you can simply write your tests in the corresponding `.robot` file. If the corresponding file doesn't exist, create the corresponding directory and then create the corresponding `.robot` file by following the style of the other `.robot` tests files.

You can add new variables in a `variables.resource` file.
If the variable is specific to a given scope, you can add it in the `variables.resource` file of the corresponding scope directory.

> To learn more about the Request Library, you can read the [documentation](https://marketsquare.github.io/robotframework-requests/doc/RequestsLibrary.html).

## Architecture

This directory contains multiple components that are used to run the tests:

- `robot_tests`: This directory contains the tests and the resources used by the tests.
- `robot_tests/lib`: This directory contains the custom libraries used by the tests.
- `testSC`: This directory contains a custom Smart Contract used by the tests. It is used for the tests related to the Smart Contracts such as `deploySC`, `executeFunction`...
6 changes: 6 additions & 0 deletions api/test/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
robotframework==6.0.2
robotframework-requests==0.9.4
robotframework-seleniumlibrary==6.1.0
robotframework-archivelibrary==0.4.2
robotframework-async-keyword==1.1.6
selenium==4.9.1
19 changes: 19 additions & 0 deletions api/test/robot_tests/sign/sign.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
*** Settings ***
Documentation This is a test suite for Massa Wallet /sign endpoints.

Library RequestsLibrary
Library Collections
Resource ../variables.resource


*** Test Cases ***
POST Sign CallSC
${data}= Create Dictionary
... description=this is the description
... operation=lQbAxAcEwIQ9uWAAAC5IN91TH6nQKZLSUhsico2f9dG9KI1+e5zfu81A7Ci4D2V4YW1wbGVGdW5jdGlvbhFleGFtcGxlUGFyYW1ldGVycw==
... batch=${false}
... chainId=${CHAIN_ID}
${response}= POST ${API_URL}/sign json=${data} expected_status=any
Log To Console json response: ${response.json()} # Print the response content to the test log for debugging
Should Be Equal As Integers ${response.status_code} ${STATUS_OK} # Assert the status code is 200 OK

15 changes: 15 additions & 0 deletions api/test/robot_tests/variables.resource
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*** Variables ***
${API_URL}= http://localhost:8080/api/accounts/fullpower

${STATUS_OK}= 200
${STATUS_CREATED}= 201
${STATUS_ACCEPTED}= 202
${STATUS_NO_CONTENT}= 204
${STATUS_BAD_REQUEST}= 400
${STATUS_NOT_FOUND}= 404
${STATUS_UNPROCESSABLE_ENTITY}= 422
${STATUS_INTERNAL_SERVER_ERROR}= 500
${STATUS_NOT_IMPLEMENTED}= 501

# buildnet
${CHAIN_ID}= ${77658366}
Loading