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

Commit

Permalink
rename unit/integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aemil145 committed Feb 28, 2022
1 parent c60d1af commit 42b37a4
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 30 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,16 @@ The contracts have to be in `{project_root}/contracts/` folder. Cudos Blast come
---
## Running Rust tests

Rust tests are organized by the Rust convention for writing tests. You can check them in their corresponding contracts in `{project_root}/contracts/{contract_name}/`. To run smart contracts' unit tests:
Rust tests are organized by the Rust convention for writing tests. You can check them in their corresponding contracts in `{project_root}/contracts/{contract_name}/`. To run smart contracts' Rust tests:

```bash
blast unittest
blast rusttest
```

To run unit tests without printing cargo log messages use `--quiet` or `-q`
To run the Rust tests without printing cargo log messages use `--quiet` or `-q`

```bash
blast unittest -q
blast rusttest -q
```

---
Expand Down
2 changes: 1 addition & 1 deletion packages/blast-cmd/blast-cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async function main() {
.command(commands.initInfo)
.command(commands.compileInfo)
.command(commands.testInfo)
.command(commands.unitTestInfo)
.command(commands.rustTestInfo)
.command(commands.nodeInfo)
.command(commands.runInfo)
.command(commands.keysInfo)
Expand Down
14 changes: 7 additions & 7 deletions packages/blast-cmd/commands.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { initCmd } = require('./init/init.js')
const { compileCmd } = require('./compile/compile.js')
const { testCmd } = require('./test/test.js')
const { unitTestCmd } = require('./unittest/unittest.js')
const { rustTestCmd } = require('./rusttest/rusttest.js')
const { runCmd } = require('./run/run.js')
const keys = require('./keys/keys.js')
const node = require('./node/node.js')
Expand Down Expand Up @@ -30,16 +30,16 @@ const compileInfo = {

const testInfo = {
command: 'test',
describe: 'Run the integration tests',
describe: 'Run the JavaScript tests',
builder: (yargs) => {
yargs.version(false)
},
handler: testCmd
}

const unitTestInfo = {
command: 'unittest',
describe: 'Run smart contracts\' unit tests',
const rustTestInfo = {
command: 'rusttest',
describe: 'Run smart contracts\' rust tests',
builder: (yargs) => {
yargs.option('quiet', {
alias: 'q',
Expand All @@ -49,7 +49,7 @@ const unitTestInfo = {
})
.version(false)
},
handler: unitTestCmd
handler: rustTestCmd
}

const runInfo = {
Expand Down Expand Up @@ -133,7 +133,7 @@ module.exports = {
initInfo: initInfo,
compileInfo: compileInfo,
testInfo: testInfo,
unitTestInfo: unitTestInfo,
rustTestInfo: rustTestInfo,
runInfo: runInfo,
keysInfo: keysInfo,
nodeInfo: nodeInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const path = require('path')

const { executeRun } = require('../../blast-utilities/run-docker-commands')

function runUnitTests(argv) {
function runRustTests(argv) {
// TODO: the slimbuster img is 604 mb, can we reuse the rust-optimizer to call the test? - So far could not make it
// work on each test run the docker is downloading the packages again, how can we cache them?
let cmd = `-v "${path.resolve('.')}":/usr/src/cudos-blast -w /usr/src/cudos-blast ` +
Expand All @@ -13,9 +13,9 @@ function runUnitTests(argv) {
executeRun(cmd)
}

async function unitTestCmd(argv) {
console.log('Running contract unit tests...')
runUnitTests(argv)
async function rustTestCmd(argv) {
console.log('Running contract rust tests...')
runRustTests(argv)
}

module.exports = { unitTestCmd: unitTestCmd }
module.exports = { rustTestCmd: rustTestCmd }
10 changes: 5 additions & 5 deletions packages/blast-cmd/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ const {
getProjectRootPath
} = require('../../blast-utilities/package-info')

const INTEGRATION_TESTS_FOLDER_NAME = 'integration_tests'
const JS_TESTS_FOLDER_NAME = 'tests'
const GLOBAL_FUNCTIONS = path.join(getPackageRootPath(), 'packages/blast-utilities/global-functions.js')
const JEST_BINARY = path.join(getPackageRootPath(), 'node_modules/.bin/jest')

function testCmd(argv) {
const TEST_DIR = path.join(getProjectRootPath(), INTEGRATION_TESTS_FOLDER_NAME)
const TEST_DIR = path.join(getProjectRootPath(), JS_TESTS_FOLDER_NAME)
if (!fs.existsSync(TEST_DIR)) {
throw new BlastError('No integration tests folder found! Make sure to place your integration tests in /' +
INTEGRATION_TESTS_FOLDER_NAME)
throw new BlastError('No tests folder found! Make sure to place your JavaScript tests in /' +
JS_TESTS_FOLDER_NAME)
}
console.log('Running integration tests...')
console.log('Running JavaScript tests...')

spawnSync(`${JEST_BINARY} ${TEST_DIR} --setupFilesAfterEnv=${GLOBAL_FUNCTIONS} --testTimeout=15000 --silent`, {
stdio: 'inherit',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/bin/bash
source ./packages/blast-tests/integration-tests/vars.sh
init_folder="$INIT_FOLDER-unittest"
init_folder="$INIT_FOLDER-rusttest"

echo -n 'blast unittest...'
echo -n 'blast rusttest...'
cp -R template $init_folder &> /dev/null && cd $init_folder

blast unittest -q &> cargo.logs.json
blast rusttest -q &> cargo.logs.json
result=`cat cargo.logs.json`
if [[ ! $result =~ $UNITTEST_RESULT ]]; then
echo -e "$FAILED\n$EXPECTED\n$UNITTEST_RESULT\n$ACTUAL\n$result" 1>&2
if [[ ! $result =~ $RUSTTEST_RESULT ]]; then
echo -e "$FAILED\n$EXPECTED\n$RUSTTEST_RESULT\n$ACTUAL\n$result" 1>&2
exit_status=1
else
echo -e $PASSED
Expand Down
6 changes: 3 additions & 3 deletions packages/blast-tests/integration-tests/vars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export VALID_BLOCK_STATUS='"height":'
export TEST_KEY='testtest'
export KEY_REMOVED_MSG='Key deleted forever'
export BALANCE_AFTER_FUND='amount: "1"'
export UNITTEST_RESULT='test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out'
export RUSTTEST_RESULT='test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out'
export TEST_RESULT='3 passed, 3 total'
export COMPILE_FILES='alpha.wasm
beta.wasm
Expand All @@ -26,11 +26,11 @@ Cargo.toml
accounts.json
blast.config.js
contracts
integration_tests
jsconfig.json
package.json
private-accounts.json
scripts'
scripts
tests'

export TEMPLATE_SCRIPTS_FILES='deploy.js
interact.js'
File renamed without changes.

0 comments on commit 42b37a4

Please sign in to comment.