From 8d9810f7dffa26d6423e7b2d3d702c1e3ea7f1ee Mon Sep 17 00:00:00 2001 From: Nathan Seva Date: Tue, 23 Apr 2024 16:38:10 -0500 Subject: [PATCH 1/2] add robot tests --- .github/workflows/e2e-tests.yml | 25 +++++++++++ api/test/.gitignore | 5 +++ api/test/README.md | 56 +++++++++++++++++++++++++ api/test/requirements.txt | 6 +++ api/test/robot_tests/sign/sign.robot | 19 +++++++++ api/test/robot_tests/variables.resource | 15 +++++++ 6 files changed, 126 insertions(+) create mode 100644 api/test/.gitignore create mode 100644 api/test/README.md create mode 100644 api/test/requirements.txt create mode 100644 api/test/robot_tests/sign/sign.robot create mode 100644 api/test/robot_tests/variables.resource diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index aebc2bb6c..2e7d5126c 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -38,3 +38,28 @@ 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: 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 diff --git a/api/test/.gitignore b/api/test/.gitignore new file mode 100644 index 000000000..159dc94bf --- /dev/null +++ b/api/test/.gitignore @@ -0,0 +1,5 @@ +log.html +output.xml +report.html +*.log +selenium-screenshot-*.png diff --git a/api/test/README.md b/api/test/README.md new file mode 100644 index 000000000..230c3ea9a --- /dev/null +++ b/api/test/README.md @@ -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//.robot +``` + +To run a specific test case, you can run the following command: + +```bash +robot -t robot_tests//.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`... diff --git a/api/test/requirements.txt b/api/test/requirements.txt new file mode 100644 index 000000000..21253673b --- /dev/null +++ b/api/test/requirements.txt @@ -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 \ No newline at end of file diff --git a/api/test/robot_tests/sign/sign.robot b/api/test/robot_tests/sign/sign.robot new file mode 100644 index 000000000..451c29e06 --- /dev/null +++ b/api/test/robot_tests/sign/sign.robot @@ -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 + diff --git a/api/test/robot_tests/variables.resource b/api/test/robot_tests/variables.resource new file mode 100644 index 000000000..b764ed949 --- /dev/null +++ b/api/test/robot_tests/variables.resource @@ -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} \ No newline at end of file From c3432acec99f23a6e7264353b45c9842edc5a245 Mon Sep 17 00:00:00 2001 From: Nathan Seva Date: Tue, 23 Apr 2024 17:07:24 -0500 Subject: [PATCH 2/2] fixup ci --- .github/workflows/e2e-tests.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index 2e7d5126c..8c18e428e 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -46,7 +46,9 @@ jobs: - name: build run: go build -tags desktop,production -ldflags "-w -s" -o build/test_wallet main.go - name: Set up wallet - run: echo "$WALLET_TEST_WALLET" > $HOME/.config/massa-station-wallet/wallet_fullpower.yaml + 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: