diff --git a/.circleci/config.yml b/.circleci/config.yml index 91cd7f62..3bfb23c5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -63,27 +63,6 @@ commands: - run: name: Prettier command: npm run prettier - run_rskj_test: - description: 'Execute the parameter test against RSKj node' - parameters: - test: - type: string - steps: - - run: - name: 'Execute << parameters.test >>' - command: | - java -Dminer.client.autoMine=true -Drpc.providers.web.ws.enabled=true -Drsk.conf.file=~/gls/rsknode/node.conf -Dminer.minGasPrice=1 << pipeline.parameters.hardfork >> -cp ~/rsksmart/rskj/rskj-core/build/libs/rskj-core-<< pipeline.parameters.version >>-all.jar co.rsk.Start --regtest --reset nohup & - until nc -z 127.0.0.1 4444 - do - echo "Waiting for RskJ..." - sleep 1 - done - cp -r node_modules/@rsksmart/rif-relay-contracts/contracts . - cp -r node_modules/@rsksmart/rif-relay-contracts/migrations . - npx truffle test --network regtest << parameters.test >> - rm -rf contracts - rm -rf migrations - rm -rf contract-addresses.json jobs: # a collection of steps CodeStyle Checks: # Lint and other pre-checks thread working_directory: ~/gls # directory where steps will run @@ -100,75 +79,44 @@ jobs: # a collection of steps steps: # a collection of executable commands - prepare - run: - name: Tests without DB reset Set B + name: Tests Thread 1 command: | - java -Dminer.client.autoMine=true -Drsk.conf.file=~/gls/rsknode/node.conf -Dminer.minGasPrice=1 << pipeline.parameters.hardfork >> -cp ~/rsksmart/rskj/rskj-core/build/libs/rskj-core-<< pipeline.parameters.version >>-all.jar co.rsk.Start --regtest --reset nohup & - until nc -z 127.0.0.1 4444 - do - echo "Waiting for RskJ..." - sleep 1 - done - cp -r node_modules/@rsksmart/rif-relay-contracts/contracts . - cp -r node_modules/@rsksmart/rif-relay-contracts/migrations . - npx truffle test --network regtest test/Verifiers.test.ts - npx truffle test --network regtest test/RelayHubPenalizations.test.ts - npx truffle test --network regtest test/RelayHubRegistrationsManagement.test.ts - npx truffle test --network regtest test/TxStoreManager.test.ts - npx truffle test --network regtest test/Utils.test.ts - npx truffle test --network regtest test/common/VersionManager.test.ts - npx truffle test --network regtest test/regressions/PayableWithEmit.test.ts - npx truffle test --network regtest test/relayclient/AccountManager.test.ts - npx truffle test --network regtest test/relayclient/ContractInteractor.test.ts - npx truffle test --network regtest test/relayclient/Configurator.test.ts - rm -rf contracts - rm -rf migrations - rm -rf contract-addresses.json + RSKJ_HARD_FORK="<>" + RSKJ_VERSION="<>" + source "scripts/utils.sh" + run_test_suite_on_ci $TEST_SUITE_1 - store_artifacts: path: ~/gls/logs - Test Thread 2: # Test thread working_directory: ~/gls # directory where steps will run docker: # run the steps with Docker - image: cimg/openjdk:8.0-node steps: # a collection of executable commands - prepare - - run_rskj_test: - test: 'test/relayclient/RelaySelectionManager.test.ts' - - run_rskj_test: - test: 'test/relayserver/RelayServerRequestsProfiling.test.ts' - - run_rskj_test: - test: 'test/relayserver/ServerConfigParams.test.ts' - - run_rskj_test: - test: 'test/relayserver/TransactionManager.test.ts' - - run_rskj_test: - test: 'test/relayclient/KnownRelaysManager.test.ts' - - run_rskj_test: - test: 'test/smartwallet/SmartWallet.test.ts' - - run_rskj_test: - test: 'test/smartwallet/CustomSmartWallet.test.ts' + - run: + name: Tests Thread 2 + command: | + RSKJ_HARD_FORK="<>" + RSKJ_VERSION="<>" + source "scripts/utils.sh" + run_test_suite_on_ci $TEST_SUITE_2 - store_artifacts: path: ~/gls/logs - Test Thread 3: # Test thread working_directory: ~/gls # directory where steps will run docker: # run the steps with Docker - image: cimg/openjdk:8.0-node - steps: # a collection of executable commands - prepare - - run_rskj_test: - test: 'test/SampleRecipient.test.ts' - - run_rskj_test: - test: 'test/StakeManagement.test.ts' - - run_rskj_test: - test: 'test/RSKAddressValidator.test.ts' - - run_rskj_test: - test: 'test/EnvelopingUtils.test.ts' - - run_rskj_test: - test: 'test/relayclient/SmartWalletDiscovery.test.ts' + - run: + name: Tests Thread 3 + command: | + RSKJ_HARD_FORK="<>" + RSKJ_VERSION="<>" + source "scripts/utils.sh" + run_test_suite_on_ci $TEST_SUITE_3 - store_artifacts: path: ~/gls/logs - Test Thread 4: # Test thread working_directory: ~/gls # directory where steps will run docker: # run the steps with Docker @@ -176,27 +124,14 @@ jobs: # a collection of steps steps: # a collection of executable commands - prepare - run: - name: Tests without DB reset Set A + name: Tests Thread 4 command: | - java -Dminer.client.autoMine=true -Drsk.conf.file=~/gls/rsknode/node.conf -Dminer.minGasPrice=1 << pipeline.parameters.hardfork >> -cp ~/rsksmart/rskj/rskj-core/build/libs/rskj-core-<< pipeline.parameters.version >>-all.jar co.rsk.Start --regtest --reset nohup & - until nc -z 127.0.0.1 4444 - do - echo "Waiting for RskJ..." - sleep 1 - done - cp -r node_modules/@rsksmart/rif-relay-contracts/contracts . - cp -r node_modules/@rsksmart/rif-relay-contracts/migrations . - npx truffle test --network regtest test/Flows.test.ts - npx truffle test --network regtest test/TestEnvironment.test.ts - npx truffle test --network regtest test/HttpWrapper.test.ts - npx truffle test --network regtest test/KeyManager.test.ts - npx truffle test --network regtest test/WalletFactory.test.ts - rm -rf contracts - rm -rf migrations - rm -rf contract-addresses.json + RSKJ_HARD_FORK="<>" + RSKJ_VERSION="<>" + source "scripts/utils.sh" + run_test_suite_on_ci $TEST_SUITE_4 - store_artifacts: path: ~/gls/logs - Test Thread 5: # Test thread working_directory: ~/gls # directory where steps will run docker: # run the steps with Docker @@ -204,45 +139,14 @@ jobs: # a collection of steps steps: # a collection of executable commands - prepare - run: - name: Tests without DB reset Set C + name: Tests Thread 5 command: | - java -Dminer.client.autoMine=true -Drpc.providers.web.ws.enabled=true -Drsk.conf.file=~/gls/rsknode/node.conf -Dminer.minGasPrice=1 << pipeline.parameters.hardfork >> -cp ~/rsksmart/rskj/rskj-core/build/libs/rskj-core-<< pipeline.parameters.version >>-all.jar co.rsk.Start --regtest --reset nohup & - until nc -z 127.0.0.1 4444 - do - echo "Waiting for RskJ..." - sleep 1 - done - cp -r node_modules/@rsksmart/rif-relay-contracts/contracts . - cp -r node_modules/@rsksmart/rif-relay-contracts/migrations . - npx truffle test --network regtest test/relayclient/RelayClient.test.ts - npx truffle test --network regtest test/relayserver/NetworkSimulation.test.ts - npx truffle test --network regtest test/relayserver/RegistrationManager.test.ts - npx truffle test --network regtest test/relayserver/RelayServer.test.ts - rm -rf contracts - rm -rf migrations - rm -rf contract-addresses.json - - store_artifacts: - path: ~/gls/logs - - Test Thread 6: # Test thread - working_directory: ~/gls # directory where steps will run - docker: # run the steps with Docker - - image: cimg/openjdk:8.0-node - steps: # a collection of executable commands - - prepare - - run_rskj_test: - test: 'test/RelayHub.test.ts' - - run_rskj_test: - test: 'test/VersionRegistry.test.ts' - - run_rskj_test: - test: 'test/relayclient/RelayProvider.test.ts' - - run_rskj_test: - test: 'test/relayclient/RelaySelectionManager.test.ts' + RSKJ_HARD_FORK="<>" + RSKJ_VERSION="<>" + source "scripts/utils.sh" + run_test_suite_on_ci $TEST_SUITE_5 - store_artifacts: path: ~/gls/logs - - store_artifacts: - path: ~/rsksmart/rskj/rskj-core/build/libs/logs - destination: ~/rskj/logs workflows: commit: jobs: @@ -252,4 +156,3 @@ workflows: - Test Thread 3 - Test Thread 4 - Test Thread 5 - - Test Thread 6 diff --git a/scripts/test b/scripts/test index 69daee7f..2dcb616b 100755 --- a/scripts/test +++ b/scripts/test @@ -6,6 +6,8 @@ #trap 'exec 2>&4 1>&3' 0 1 2 3 #exec 1>${TEST_LOG} 2>&1 +source "scripts/utils.sh" + trap ctrl_c INT function ctrl_c() { @@ -19,90 +21,8 @@ if [ -z "${NETWORK}" ]; then docker network create rif-relay-testing fi -function run_batch() { - TESTS=("$@") - unset TESTS[0] - BATCH_NAME=$1 - echo "#################################################################################### Starting Batch ${BATCH_NAME} ####################################################################################" - docker-compose -f docker/docker-compose.yml build - docker-compose -f docker/docker-compose.yml up -d - cp -r node_modules/@rsksmart/rif-relay-contracts/contracts . - cp -r node_modules/@rsksmart/rif-relay-contracts/migrations . - - _i=0 - while [ $_i -lt 30 ]; do - curl -Ss -H "Content-type: application/json" \ - -d '{"jsonrpc":"2.0","method":"eth_blockNumber","id":"boot-test"}' \ - http://127.0.0.1:4444/ 2>/dev/null | grep -q result && break - sleep 1 - _i=$((_i + 1)) - done - if [ $_i -eq 30 ]; then - echo "No response from rskj after 30 seconds; aborting..." >&2 - exit 1 - fi - sleep 5 - - echo "#################################################################################### START BATCH TESTS ####################################################################################" - TEST_FAIL=0 - npx truffle test --network regtest "${TESTS[@]}" || TEST_FAIL=1 - echo "#################################################################################### END BATCH TESTS ####################################################################################" - rm -rf contracts - rm -rf migrations - rm -rf contract-addresses.json - - docker-compose -f docker/docker-compose.yml down - echo "#################################################################################### Ending Batch ${BATCH_NAME} ####################################################################################" - - if [ "${TEST_FAIL}" == "1" ]; then - exit 1 - fi -} - -# Test_Group_1 -run_batch Test_Group_1 \ - test/Verifiers.test.ts \ - test/RelayHubPenalizations.test.ts \ - test/RelayHubRegistrationsManagement.test.ts \ - test/TxStoreManager.test.ts \ - test/Utils.test.ts \ - test/common/VersionManager.test.ts \ - test/regressions/PayableWithEmit.test.ts \ - test/relayclient/AccountManager.test.ts \ - test/relayclient/ContractInteractor.test.ts \ - test/relayclient/Configurator.test.ts - -# Test_Group_2 -run_batch RelaySelectionManager test/relayclient/RelaySelectionManager.test.ts -run_batch RelayServerRequestsProfiling test/relayserver/RelayServerRequestsProfiling.test.ts -run_batch ServerConfigParams test/relayserver/ServerConfigParams.test.ts -run_batch TransactionManager test/relayserver/TransactionManager.test.ts -run_batch KnownRelaysManager test/relayclient/KnownRelaysManager.test.ts -run_batch SmartWallet test/smartwallet/SmartWallet.test.ts -run_batch SampleRecipient test/SampleRecipient.test.ts -run_batch StakeManagement test/StakeManagement.test.ts -run_batch RSKAddressValidator test/RSKAddressValidator.test.ts -run_batch EnvelopingUtils test/EnvelopingUtils.test.ts -run_batch SmartWalletDiscovery test/relayclient/SmartWalletDiscovery.test.ts -run_batch CustomSmartWallet test/smartwallet/CustomSmartWallet.test.ts - -# Test_Group_3 -run_batch Test_Group_3 \ - test/Flows.test.ts \ - test/TestEnvironment.test.ts \ - test/HttpWrapper.test.ts \ - test/KeyManager.test.ts \ - test/WalletFactory.test.ts - -# Test_Group_4 -run_batch Test_Group_4 \ - test/relayclient/RelayClient.test.ts \ - test/relayserver/NetworkSimulation.test.ts \ - test/relayserver/RegistrationManager.test.ts \ - test/relayserver/RelayServer.test.ts - -# Test_Group_5 -run_batch RelayHub test/RelayHub.test.ts -run_batch VersionRegistry test/VersionRegistry.test.ts -run_batch RelayProvider test/relayclient/RelayProvider.test.ts -run_batch RelaySelectionManager test/relayclient/RelaySelectionManager.test.ts +run_test_suite_against_docker $TEST_SUITE_1 +run_test_suite_against_docker $TEST_SUITE_2 +run_test_suite_against_docker $TEST_SUITE_3 +run_test_suite_against_docker $TEST_SUITE_4 +run_test_suite_against_docker $TEST_SUITE_5 diff --git a/scripts/utils.sh b/scripts/utils.sh new file mode 100644 index 00000000..16bc2487 --- /dev/null +++ b/scripts/utils.sh @@ -0,0 +1,186 @@ +#! /bin/bash + + +TEST_SUITE_BATCH="batch" +TEST_SUITE_SEQUENTIAL="sequential" +STOP_ON_FAIL=${FAIL_FAST:-1} + +function wait_rsk_node() { + _i=0 + while [ $_i -lt 30 ]; do + curl -Ss -H "Content-type: application/json" \ + -d '{"jsonrpc":"2.0","method":"eth_blockNumber","id":"boot-test"}' \ + http://127.0.0.1:4444/ 2>/dev/null | grep -q result && break + sleep 1 + _i=$((_i + 1)) + done + if [ $_i -eq 30 ]; then + echo "No response from rskj after 30 seconds; aborting..." >&2 + exit 1 + fi + + sleep 5 +} + +function run_batch() { + TESTS=("$@") + unset TESTS[0] + BATCH_NAME=$1 + + echo "#################################################################################### Starting Batch ${BATCH_NAME} ####################################################################################" + + cp -r node_modules/@rsksmart/rif-relay-contracts/contracts . + cp -r node_modules/@rsksmart/rif-relay-contracts/migrations . + + echo "#################################################################################### START BATCH TESTS ####################################################################################" + + TEST_FAIL=0 + npx truffle test --network regtest "${TESTS[@]}" || TEST_FAIL=1 + + echo "#################################################################################### END BATCH TESTS ####################################################################################" + + rm -rf contracts + rm -rf migrations + rm -rf contract-addresses.json + + echo "#################################################################################### Ending Batch ${BATCH_NAME} ####################################################################################" + + if [ "${TEST_FAIL}" == "1" ]; then + exit 1 + fi +} + +# It requires two env variables: +# HARD_FORK = the RSKj node hard fork +# RSKJ_VERSION = the RSKj node version +function run_batch_on_ci() { + rskj_hard_fork=${RSKJ_HARD_FORK:?"RSKj hardfork is required"} + rskj_version=${RSKJ_VERSION:?"RSKj version is required"} + java -Dminer.client.autoMine=true -Drpc.providers.web.ws.enabled=true -Drsk.conf.file=~/gls/rsknode/node.conf -Dminer.minGasPrice=1 $rskj_hard_fork -cp ~/rsksmart/rskj/rskj-core/build/libs/rskj-core-${rskj_version}-all.jar co.rsk.Start --regtest --reset nohup & + rskj_pid=$! + + wait_rsk_node + + run_batch $@ + + kill -TERM $rskj_pid + sleep 5 +} + +function run_test_suite_on_ci() { + TESTS=("$@") + unset TESTS[0] + TEST_TYPE=$1 + unset TESTS[1] + TEST_NAME=$2 + + TEST_FAIL=0 + if [ "$TEST_TYPE" = "$TEST_SUITE_BATCH" ] + then + run_batch_on_ci "${TESTS[@]}" || TEST_FAIL=1 + elif [ "$TEST_TYPE" = "$TEST_SUITE_SEQUENTIAL" ] + then + for test_case in "${TESTS[@]}" + do + run_batch_on_ci "${TEST_NAME} ${test_case}" || TEST_FAIL=1 + if [[ "${TEST_FAIL}" == "1" && "${STOP_ON_FAIL}" == "1" ]]; then + break + fi + done + + else + echo "Unsupported test type: accepted values are ${TEST_SUITE_BATCH} or ${TEST_SUITE_SEQUENTIAL}" + exit 1 + fi + + if [ "${TEST_FAIL}" == "1" ]; then + exit 1 + fi +} + + +function run_batch_against_docker() { + docker-compose -f docker/docker-compose.yml build + docker-compose -f docker/docker-compose.yml up -d + + wait_rsk_node + + run_batch $@ + + docker-compose -f docker/docker-compose.yml down +} + +function run_test_suite_against_docker() { + TESTS=("$@") + unset TESTS[0] + TEST_TYPE=$1 + unset TESTS[1] + TEST_NAME=$1 + + if [ "$TEST_TYPE" = "$TEST_SUITE_BATCH" ] + then + run_batch_against_docker "${TESTS[@]}" + elif [ "$TEST_TYPE" = "$TEST_SUITE_SEQUENTIAL" ] + then + for test_case in "${TESTS[@]}" + do + run_batch_against_docker "${TEST_NAME} ${test_case}" || TEST_FAIL=1 + if [[ "${TEST_FAIL}" == "1" && "${STOP_ON_FAIL}" == "1" ]]; then + exit 1 + fi + done + else + echo "Unsupported test type: accepted values are ${TEST_SUITE_BATCH} or ${TEST_SUITE_SEQUENTIAL}" + exit 1 + fi +} + +# Test suite format: " test_file_1 test_file_2 ... test_file_n" +TEST_SUITE_1="${TEST_SUITE_BATCH} \ + Test_Group_1 \ + test/Verifiers.test.ts \ + test/RelayHubPenalizations.test.ts \ + test/RelayHubRegistrationsManagement.test.ts \ + test/TxStoreManager.test.ts \ + test/Utils.test.ts \ + test/common/VersionManager.test.ts \ + test/regressions/PayableWithEmit.test.ts \ + test/relayclient/AccountManager.test.ts \ + test/relayclient/ContractInteractor.test.ts \ + test/relayclient/Configurator.test.ts" + +TEST_SUITE_2="${TEST_SUITE_SEQUENTIAL} \ + RelaySelectionManager|RelayServerRequestsProfiling|ServerConfigParams|TransactionManager|KnownRelaysManager|SmartWallet|SampleRecipient|StakeManagement|RSKAddressValidator|EnvelopingUtils|SmartWalletDiscovery|CustomSmartWallet \ + test/relayclient/RelaySelectionManager.test.ts \ + test/relayserver/RelayServerRequestsProfiling.test.ts \ + test/relayserver/ServerConfigParams.test.ts \ + test/relayserver/TransactionManager.test.ts \ + test/relayclient/KnownRelaysManager.test.ts \ + test/smartwallet/SmartWallet.test.ts \ + test/SampleRecipient.test.ts \ + test/StakeManagement.test.ts \ + test/RSKAddressValidator.test.ts \ + test/EnvelopingUtils.test.ts \ + test/relayclient/SmartWalletDiscovery.test.ts \ + test/smartwallet/CustomSmartWallet.test.ts" + +TEST_SUITE_3="${TEST_SUITE_BATCH} \ + Test_Group_3 \ + test/Flows.test.ts \ + test/TestEnvironment.test.ts \ + test/HttpWrapper.test.ts \ + test/KeyManager.test.ts \ + test/WalletFactory.test.ts" + +TEST_SUITE_4="${TEST_SUITE_BATCH} \ + Test_Group_4 \ + test/relayclient/RelayClient.test.ts \ + test/relayserver/NetworkSimulation.test.ts \ + test/relayserver/RegistrationManager.test.ts \ + test/relayserver/RelayServer.test.ts" + +TEST_SUITE_5="${TEST_SUITE_SEQUENTIAL} \ + RelayHub|VersionRegistry|RelayProvider|RelaySelectionManager \ + test/RelayHub.test.ts + test/VersionRegistry.test.ts + test/relayclient/RelayProvider.test.ts" \ No newline at end of file