diff --git a/.github/mining-test/bitcoind01.Dockerfile b/.github/mining-test/bitcoind01.Dockerfile new file mode 100644 index 00000000000..f93c1e49efb --- /dev/null +++ b/.github/mining-test/bitcoind01.Dockerfile @@ -0,0 +1,2 @@ +FROM kylemanna/bitcoind:latest +CMD ["/usr/local/bin/bitcoind", "-printtoconsole", "-regtest", "-debug", "-server", "-listen", "-port=31591", "-connect=localhost:31592", "-rpcbind=0.0.0.0:32591", "-rpcallowip=0.0.0.0/0", "-rpcuser=admin", "-rpcpassword=admin" ] diff --git a/.github/mining-test/bitcoind02.Dockerfile b/.github/mining-test/bitcoind02.Dockerfile new file mode 100644 index 00000000000..eaf0ca4d661 --- /dev/null +++ b/.github/mining-test/bitcoind02.Dockerfile @@ -0,0 +1,2 @@ +FROM kylemanna/bitcoind:latest +CMD ["/usr/local/bin/bitcoind", "-printtoconsole", "-regtest", "-debug", "-server", "-listen", "-port=31592", "-connect=localhost:31591", "-rpcbind=0.0.0.0:32592", "-rpcallowip=0.0.0.0/0", "-rpcuser=admin", "-rpcpassword=admin" ] diff --git a/.github/mining-test/run.sh b/.github/mining-test/run.sh new file mode 100755 index 00000000000..5275dd09e6e --- /dev/null +++ b/.github/mining-test/run.sh @@ -0,0 +1,12 @@ +sudo docker run -d --name bitcoind01 -p 31591:31591 --entrypoint "/usr/local/bin/bitcoind" kylemanna/bitcoind:latest -printtoconsole -regtest -debug -server -listen -port=31591 -connect=localhost:31592 -rpcbind=0.0.0.0:32591 -rpcallowip=0.0.0.0/0 -rpcuser=admin -rpcpassword=admin +sudo docker run -d --name bitcoind02 -p 31592:31592 --entrypoint "/usr/local/bin/bitcoind" kylemanna/bitcoind:latest -printtoconsole -regtest -debug -server -listen -port=31592 -connect=localhost:31591 -rpcbind=0.0.0.0:32592 -rpcallowip=0.0.0.0/0 -rpcuser=admin -rpcpassword=admin + +sleep 10 + +echo Test bitcoin node 1 +curl -s -u admin:admin --data-binary '{"jsonrpc":"1.0","id":"curltext","method":"getblockchaininfo","params":[]}' -H 'content-type:text/plain;' http://localhost:32591 +echo Test bitcoin node 2 +curl -s -u admin:admin --data-binary '{"jsonrpc":"1.0","id":"curltext","method":"getblockchaininfo","params":[]}' -H 'content-type:text/plain;' http://localhost:32592 + +(cd mining-integration-tests && node generateBtcBlocks.js || exit 1) + diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 1c20558c51b..ec25f6efe42 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -155,63 +155,158 @@ jobs: if: always() mining-tests: + needs: build runs-on: ubuntu-latest + defaults: + run: + working-directory: . + + services: + bitcoind01: + image: kylemanna/bitcoind:latest + env: + DISABLEWALLET: "0" + ports: + - 31591:31591 + # options: >- + # --entrypoint "/usr/local/bin/bitcoind + + bitcoind02: + image: kylemanna/bitcoind:latest + env: + DISABLEWALLET: "0" + ports: + - 31592:31592 + # options: >- + # --entrypoint "/usr/local/bin/bitcoind steps: - - name: Checkout code + # - name: Setup System Tools + # run: | + # sudo apt-get update -y + ## sudo apt-get install -y curl + # - name: Install Node 12 + # run: | + # sudo apt-get install -y fnm + + - name: Setup Node.js + uses: actions/setup-node@v2 + with: + node-version: '12' + - name: Check Node.js version + run: node --version + + - name: Checkout Mining Integration Tests Repository + uses: actions/checkout@v2 + with: + repository: rsksmart/mining-integration-tests +# ref: ${{ secrets.MINING_INTEGRATION_TESTS_REF }} +# token: ${{ secrets.GITHUB_TOKEN }} + path: mining-integration-tests + + # - uses: actions/cache@v4 + # name: Restore gradle cache + # with: + # path: | + # .gradle/caches + # gradle/wrapper + # key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + # restore-keys: | + # ${{ runner.os }}-gradle- + # + # - name: Get Gradle jar + # run: | + # ./configure.sh + + - uses: actions/cache@v2 + with: + path: | + node_modules + key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + + - name: Install Mining Integration Tests dependencies + working-directory: mining-integration-tests + run: | + npm install + # + # - name: Start Bitcoin nodes + # run: | + # docker run -itd bitcoind01 /usr/local/bin/bitcoind -printtoconsole -regtest -debug -server -listen -port=31591 -connect=localhost:31592 -rpcbind=0.0.0.0:32591 -rpcallowip=0.0.0.0/0 -rpcuser=admin -rpcpassword=admin + # docker run -itd bitcoind02 /usr/local/bin/bitcoind -printtoconsole -regtest -debug -server -listen -port=31592 -connect=localhost:31591 -rpcbind=0.0.0.0:32591 -rpcallowip=0.0.0.0/0 -rpcuser=admin -rpcpassword=admin +# - name: Start Bitcoin nodes +# run: | +# docker run -d --name bitcoind01 -p 31591:31591 --entrypoint "/usr/local/bin/bitcoind" kylemanna/bitcoind:latest -printtoconsole -regtest -debug -server -listen -port=31591 -connect=localhost:31592 -rpcbind=0.0.0.0:32591 -rpcallowip=0.0.0.0/0 -rpcuser=admin -rpcpassword=admin +# docker run -d --name bitcoind02 -p 31592:31592 --entrypoint "/usr/local/bin/bitcoind" kylemanna/bitcoind:latest -printtoconsole -regtest -debug -server -listen -port=31592 -connect=localhost:31591 -rpcbind=0.0.0.0:32592 -rpcallowip=0.0.0.0/0 -rpcuser=admin -rpcpassword=admin +# +# +# - name: Test bitcoin nodes +# run: | +# echo Test bitcoin node 1 +# curl -s -u admin:admin --data-binary '{"jsonrpc":"1.0","id":"curltext","method":"getblockchaininfo","params":[]}' -H 'content-type:text/plain;' http://localhost:32591 +# echo Test bitcoin node 2 +# curl -s -u admin:admin --data-binary '{"jsonrpc":"1.0","id":"curltext","method":"getblockchaininfo","params":[]}' -H 'content-type:text/plain;' http://localhost:32592 +# +# - name: Generate BTC blocks +# working-directory: mining-integration-tests +# run: | +# node generateBtcBlocks.js + + - name: Run Mining Integration Tests + run: | + chmod +x .github/mining-test/run.sh + sh /.github/mining-test/run.sh + + - name: Checkout RSKj uses: actions/checkout@v2 - - name: Setup - run: | - sudo apt-get update - sudo apt-get install -y curl jq - - - name: Mining integration tests - run: | - function wait_for_completion() { - build_number=$1 - poll_interval=60 - i=0 - max_count=20 - while [ $i -lt $max_count ]; do - res=$(curl -Ssfu "${{ secrets.GITHUB_TOKEN }}" \ - "https://circleci.com/api/v1.1/project/github/$MIT_ORGANIZATION/$MIT_PROJECT/$build_numbe" \ - | jq -r '[.status, .conclusion] | @tsv') - IFS=" " set -- $res - status=${1:-} - conclusion=${2:-} - if [ "$status" = "queued" ]; then - echo "Build is enqueued. Waiting..." - else - echo "[$i/$max_count] Waiting for build $build_url ..." - i=$((i + 1)) - fi - if [ "$status" = "completed" ]; then - echo "Build $build_number finished. Outcome: \"$conclusion\"." - test "$conclusion" = "success" - return $? - fi - sleep $poll_interval - done - return 1 - } - json_payload='{ - "ref": "'${{ github.ref }}'", - "inputs": { - "RSKJ_CIRCLE_BRANCH": "${{ github.ref }}", - "RSKJ_CIRCLE_USERNAME": "${{ github.actor }}", - "RSKJ_CIRCLE_REPONAME": "${{ github.repository }}", - "RSKJ_PR_NUMBER": "${{ github.event.pull_request.number }}", - "RSKJ_CIRCLE_SHA1": "${{ github.sha }}" - } - }' - res=$(curl -Ssf -u "${{ secrets.GITHUB_TOKEN }}:" \ - -H "Content-type: application/json" -d "$json_payload" \ - "https://circleci.com/api/v1.1/project/github/$MIT_ORGANIZATION/$MIT_PROJECT/tree/$MIT_BRANCH" \ - | jq -r '[.url, .id] | @tsv') - IFS=" " set -- $res - build_url=$1 - build_num=$2 - echo "Running mining integration tests. Follow it on:\n\n $build_url\n\n" - sleep 10 - wait_for_completion "$build_num" \ No newline at end of file + - name: Setup Java JDK + uses: actions/setup-java@v2 + with: + java-version: '17' + distribution: 'temurin' + + - name: Verify Java installation + run: java -version + + - name: Get RSKj version + run: | + version=$(tr -d "'\"" < rskj-core/src/main/resources/version.properties \ + | cut -d = -f 2- | paste -sd - -) + + - uses: actions/cache@v4 + name: Restore build + with: + path: | + build + key: ${{ runner.os }}-build-${{ hashFiles('build') }} + restore-keys: | + ${{ runner.os }}-build- + + - name: Start RSKj + run: | + java -Drsk.conf.file=./rsk-integration-test.conf -cp rskj-core/build/libs/rskj-core-"$version"-all.jar co.rsk.Start --regtest + rskpid=$! + echo "RSKj PID: $rskpid" + until nc -z 127.0.0.1 4444 + do + echo "Waiting for RskJ..." + sleep 1 + done + + - name: Run Mining Integration Tests + working-directory: mining-integration-tests + run: | + npm test + + - name: Stop RSKj + if: always() + run: | + kill $rskpid + + - name: Stop and Remove Docker Containers + if: always() + run: | + /usr/bin/docker stop bitcoind01 bitcoind02 + /usr/bin/docker rm bitcoind01 bitcoind02 \ No newline at end of file