Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
rename blast integration tests and update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
aemil145 committed Mar 1, 2022
1 parent 42b37a4 commit 4c0b231
Show file tree
Hide file tree
Showing 17 changed files with 74 additions and 94 deletions.
78 changes: 0 additions & 78 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ By using this tool you can also spin up a local [`Cudos node`](https://github.co
* [Adding a new local node account](#adding-a-new-local-node-account)
* [Removing an existing local node account](#removing-an-existing-local-node-account)
* [Funding an existing local node account](#funding-an-existing-local-node-account)
* [Development](#development)
* [Running tests](#running-tests)
* [Sample test](#sample-test)

## Installation

Expand Down Expand Up @@ -335,78 +332,3 @@ blast keys fund myAccount1 --tokens 1000000
```
The tokens are funded from the default local node faucet in `acudos`.
---
## Development
### Running tests
You can run tests that ensure `blast` commands are working correctly.
```bash
npm test
```
You can also specify the test file name to run a single test. Test files are located in `{repo_root}/packages/blast-tests/integration-tests/tests/`
```bash
npm test init.test.sh
```
---
### Sample test
The following sample test contains a detailed explanation of the commands and syntax. It is recommended to execute `npm test` first to get a general idea of the behavior. New tests should be placed in `{repo_root}/packages/blast-tests/integration-tests/tests/` folder. Lets take a look at `init.test.sh`. It covers `blast init` command which should initialize a project inside the current directory. The tests follow the classic Arrange-Act-Assert pattern.
```bash
# our files start with "#!/bin/bash", which tells your terminal it should use bash to execute the file
#!/bin/bash
# "source" lets you use the contents of a file
source ./packages/blast-tests/integration-tests/vars.sh
# 'echo' prints out the string
# -n flag tells your terminal to stay on the same line after printing out the message
echo -n 'blast init...'
# ARRANGE
# "mkdir" creates a folder at the path specified in INIT_FOLDER variable
# "cd" navigates to the specified directory
# "&&" lets you execute the command that follows it only if the first command is successful
mkdir $INIT_FOLDER && cd $INIT_FOLDER
# ACT
# "&>" hides the output of the command
blast init &> /dev/null
# ASSERT
# "ls -R" lists directory content
# `` executes the command placed inside and provides its output
# we compare the output with the expected folder structure defined in TEMPLATE_FILES
if [[ ! `ls` == $TEMPLATE_FILES || ! `ls scripts` == $TEMPLATE_SCRIPTS_FILES ]]; then
# if the output doesn't match we print a fail message
# FAILED variable defines a red colored message
# -e flag escapes special characters, we need it in order to have colored messages
# 1>&2 redirects the output to stderr
echo -e "$FAILED\nGenerated folder is invalid!" 1>&2
# we are defining a variable with status 1
# in bash status code 1 means the script was not successful
exit_status=1
else
# otherwise we print pass message
echo -e $PASSED
fi
# we are cleaning up the files generated by the test
# "rm -r" removes the specified directory
rm -r ../$INIT_FOLDER &> /dev/null
# EXIT the script
# if the test fails and exit_status is assigned, the program will exit with status 1
# otherwise the exit_status will be undefined and the program will exit without a status, which means it was successful
exit $exit_status
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "",
"main": "./packages/blast-cmd/blast-cmd.js",
"scripts": {
"test": "./packages/blast-tests/integration-tests/run-tests.sh"
"test": "./packages/blast-tests/e2e-test/run-tests.sh"
},
"bin": {
"blast": "./packages/blast-cmd/blast-cmd.js"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
source ./packages/blast-tests/integration-tests/vars.sh
source ./packages/blast-tests/e2e-test/vars.sh
compose='docker compose -f ./packages/blast-config/docker-compose-start.yaml -f ./packages/blast-config/docker-compose-init.yaml'
start_node() {
$compose up --build -d &> /dev/null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
source ./packages/blast-tests/integration-tests/vars.sh
source ./packages/blast-tests/e2e-test/vars.sh
if [[ ! $? == 0 ]]; then
echo -e "Invalid source!" 1>&2
exit $?
Expand All @@ -16,7 +16,7 @@ start_node() {
}

if [[ $1 ]]; then
./packages/blast-tests/integration-tests/run-single-test.sh $1
./packages/blast-tests/e2e-test/run-single-test.sh $1
exit $?
fi

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
source ./packages/blast-tests/integration-tests/vars.sh
source ./packages/blast-tests/e2e-test/vars.sh

init_folder="$INIT_FOLDER-compile"
echo -n 'blast compile...'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
source ./packages/blast-tests/integration-tests/vars.sh
source ./packages/blast-tests/e2e-test/vars.sh

echo -n 'blast init -d...'
blast init -d $INIT_FOLDER &> /dev/null && cd $INIT_FOLDER
Expand Down
58 changes: 58 additions & 0 deletions packages/blast-tests/e2e-test/tests/init.sample-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# The following sample test contains a detailed explanation of the commands and syntax. It is recommended to execute
# `npm test` first to get a general idea of the behavior.
# New tests should be placed in `{repo_root}/packages/blast-tests/e2e-test/tests/` folder.
# `init.test.sh` covers `blast init` command which should initialize a project inside the current directory. The tests
# follow the classic Arrange-Act-Assert pattern.

# Command to run all tests: npm test
# Command to run a single test: npm test init.test.sh


# our files start with "#!/bin/bash", which tells your terminal it should use bash to execute the file
#!/bin/bash

# "source" lets you use the contents of a file
source ./packages/blast-tests/e2e-test/vars.sh

# 'echo' prints out the string
# -n flag tells your terminal to stay on the same line after printing out the message
echo -n 'blast init...'

# ARRANGE
# "mkdir" creates a folder at the path specified in INIT_FOLDER variable
# "cd" navigates to the specified directory
# "&&" lets you execute the command that follows it only if the first command is successful
mkdir $INIT_FOLDER && cd $INIT_FOLDER

# ACT
# "&>" hides the output of the command
blast init &> /dev/null

# ASSERT
# "ls -R" lists directory content
# `` executes the command placed inside and provides its output
# we compare the output with the expected folder structure defined in TEMPLATE_FILES
if [[ ! `ls` == $TEMPLATE_FILES || ! `ls scripts` == $TEMPLATE_SCRIPTS_FILES ]]; then

# if the output doesn't match we print a fail message
# FAILED variable defines a red colored message
# -e flag escapes special characters, we need it in order to have colored messages
# 1>&2 redirects the output to stderr
echo -e "$FAILED\nGenerated folder is invalid!" 1>&2

# we are defining a variable with status 1
# in bash status code 1 means the script was not successful
exit_status=1
else
# otherwise we print pass message
echo -e $PASSED
fi

# we are cleaning up the files generated by the test
# "rm -r" removes the specified directory
rm -r ../$INIT_FOLDER &> /dev/null

# EXIT the script
# if the test fails and exit_status is assigned, the program will exit with status 1
# otherwise the exit_status will be undefined and the program will exit without a status, which means it was successful
exit $exit_status
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
source ./packages/blast-tests/integration-tests/vars.sh
source ./packages/blast-tests/e2e-test/vars.sh

echo -n 'blast init...'
mkdir $INIT_FOLDER && cd $INIT_FOLDER
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
source ./packages/blast-tests/integration-tests/vars.sh
source ./packages/blast-tests/e2e-test/vars.sh

echo -n 'blast keys add...'
cd template
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
source ./packages/blast-tests/integration-tests/vars.sh
source ./packages/blast-tests/e2e-test/vars.sh

echo -n 'blast keys fund...'
$COMPOSE cudos-noded keys add $TEST_KEY --keyring-backend test &> /dev/null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
source ./packages/blast-tests/integration-tests/vars.sh
source ./packages/blast-tests/e2e-test/vars.sh

echo -n 'blast keys ls...'
$COMPOSE cudos-noded keys add $TEST_KEY --keyring-backend test &> /dev/null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
source ./packages/blast-tests/integration-tests/vars.sh
source ./packages/blast-tests/e2e-test/vars.sh

echo -n 'blast keys rm...'
$COMPOSE keys add $TEST_KEY &> /dev/null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
source ./packages/blast-tests/integration-tests/vars.sh
source ./packages/blast-tests/e2e-test/vars.sh

echo -n 'blast node start...'
cd template
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
source ./packages/blast-tests/integration-tests/vars.sh
source ./packages/blast-tests/e2e-test/vars.sh

echo -n 'blast node stop...'
cd template
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
source ./packages/blast-tests/integration-tests/vars.sh
source ./packages/blast-tests/e2e-test/vars.sh
init_folder="$INIT_FOLDER-rusttest"

echo -n 'blast rusttest...'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
source ./packages/blast-tests/integration-tests/vars.sh
source ./packages/blast-tests/e2e-test/vars.sh
init_folder="$INIT_FOLDER-test"

echo -n 'blast test...'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

export TESTS_FOLDER='./packages/blast-tests/integration-tests/tests'
export TESTS_FOLDER='./packages/blast-tests/e2e-test/tests'
export INIT_FOLDER='./test-blast-init'
export CONTAINER_NAME='cudos_blast_node'
export COMPOSE='docker compose -f ./packages/blast-config/docker-compose-start.yaml -f ./packages/blast-config/docker-compose-init.yaml exec -T cudos-node'
Expand Down

0 comments on commit 4c0b231

Please sign in to comment.