diff --git a/.github/workflows/check-PRs.yml b/.github/workflows/check-PRs.yml index f9f4683a7..3d0639e54 100644 --- a/.github/workflows/check-PRs.yml +++ b/.github/workflows/check-PRs.yml @@ -61,6 +61,55 @@ jobs: name: ganache-test-logs path: ./ganache-test.log + ping-pong-test: + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@master + - uses: actions/setup-node@v1 + with: + node-version: '14.17.0' + + - name: Start Containers + run: | + docker build --no-cache -t ghcr.io/eyblockchain/local-zokrates -f zokrates.Dockerfile . + cd test/ping-pong + docker-compose build + ./ganache-standalone -s + sleep 10 + ./pong-nightfall -d -s &> ping-pong-test.log &disown + + - name: debug logs - after container startup + if: always() + run: cat test/ping-pong/ping-pong-test.log + + - name: wait 1200s for Containers startup and setup completion + run: sleep 1200 + + - name: Run ping-pong test + run: | + docker ps + docker wait ping-pong_deployer_1 + cd test/ping-pong + ./pong-apps + + - name: debug logs - after integration test run + if: always() + run: cat test/ping-pong/ping-pong-test.log + + - name: If integration test failed, shutdown the Containers + if: failure() + run: | + cd test/ping-pong + ./pong-down -v + ./ganache-standalone -d + + - name: If integration test failed, upload logs files as artifacts + if: failure() + uses: actions/upload-artifact@master + with: + name: ping-pong-test-logs + path: test/ping-pong/ping-pong-test.log + test-gas: name: check gas for 32 transactions per block runs-on: ubuntu-20.04 diff --git a/test/ping-pong/docker-compose.yml b/test/ping-pong/docker-compose.yml index 5f3fdffcc..ee726e206 100644 --- a/test/ping-pong/docker-compose.yml +++ b/test/ping-pong/docker-compose.yml @@ -128,6 +128,7 @@ services: CLIENT_PORT: 80 BLOCKCHAIN_WS_HOST: blockchain1 BLOCKCHAIN_PORT: 8546 + IS_TEST_RUNNER: 'yes' user-local2: image: ghcr.io/eyblockchain/nightfall3-user-local:latest diff --git a/test/ping-pong/pong-apps b/test/ping-pong/pong-apps index 2a43cece1..4bf311b2d 100755 --- a/test/ping-pong/pong-apps +++ b/test/ping-pong/pong-apps @@ -25,5 +25,5 @@ done # shut down cleanly in the event of a cntl-c etc. We don't want to leave containers running trap "exit 1" SIGHUP SIGINT SIGTERM -docker-compose -f docker-compose.yml $FILE up -d --remove-orphans proposer user-local1 user-local2 -docker-compose logs -f proposer user-local1 user-local2 +docker-compose -f docker-compose.yml $FILE up --abort-on-container-exit --exit-code-from user-local1 --remove-orphans proposer user-local1 user-local2 +# docker-compose logs -f proposer user-local1 user-local2 diff --git a/test/ping-pong/proposer/src/index.mjs b/test/ping-pong/proposer/src/index.mjs index 8f4876e1a..82f6d488e 100644 --- a/test/ping-pong/proposer/src/index.mjs +++ b/test/ping-pong/proposer/src/index.mjs @@ -12,8 +12,8 @@ Does the preliminary setup and starts listening on the websocket */ async function startProposer() { logger.info('Starting Proposer...'); - const nf3 = new Nf3(web3WsUrl, proposerEthereumSigningKey, { - // clientApiUrl: clientBaseUrl, + const nf3 = new Nf3(proposerEthereumSigningKey, { + web3WsUrl, optimistApiUrl: optimistBaseUrl, optimistWsUrl, }); diff --git a/test/ping-pong/user-local/Dockerfile b/test/ping-pong/user-local/Dockerfile deleted file mode 100644 index 1953e3fba..000000000 --- a/test/ping-pong/user-local/Dockerfile +++ /dev/null @@ -1,21 +0,0 @@ -FROM node:14.17 - -WORKDIR /app -RUN apt-get update -y -RUN apt-get install -y netcat-openbsd - -WORKDIR /common-files -RUN echo "{\"name\": \"common-files\"}" > package.json - -WORKDIR /test/ping-pong/user-local - -COPY src src -COPY docker-entrypoint.sh pre-start-script.sh package.json package-lock.json ./ - -RUN npm ci - -EXPOSE 80 - -ENTRYPOINT ["/test/ping-pong/user-local/docker-entrypoint.sh"] - -CMD ["npm", "start"] diff --git a/test/ping-pong/user-local/src/index.mjs b/test/ping-pong/user-local/src/index.mjs index 02f92f778..2d46f9fc2 100644 --- a/test/ping-pong/user-local/src/index.mjs +++ b/test/ping-pong/user-local/src/index.mjs @@ -19,7 +19,7 @@ const { TRANSACTIONS_PER_BLOCK, } = config; -const { TEST_LENGTH, ERC20_NAME, TX_WAIT = 10000 } = process.env; +const { TEST_LENGTH, ERC20_NAME, TX_WAIT = 1000, IS_TEST_RUNNER = '' } = process.env; const recipientPkd = process.env.RECIPIENT_PKD; // .split(','); /** @@ -31,7 +31,8 @@ async function localTest() { const tokenType = 'ERC20'; const value = 1; const tokenId = '0x0000000000000000000000000000000000000000000000000000000000000000'; - const nf3 = new Nf3(web3WsUrl, userEthereumSigningKey, { + const nf3 = new Nf3(userEthereumSigningKey, { + web3WsUrl, clientApiUrl: clientBaseUrl, optimistApiUrl: optimistBaseUrl, optimistWsUrl, @@ -75,24 +76,27 @@ async function localTest() { // Wait for sometime at the end to retrieve balance to include any transactions sent by the other use // This needs to be much longer than we may have waited for a transfer let loop = 0; + let loopMax = 10000; + if (IS_TEST_RUNNER) loopMax = 10; // the TEST_RUNNER must finish first so that its exit status is returned to the tester do { const endBalance = await retrieveL2Balance(nf3); - if (endBalance - startBalance === 2 * value + value * TEST_LENGTH) { + if (endBalance - startBalance === 2 * value + value * TEST_LENGTH && IS_TEST_RUNNER) { logger.info('Test passed'); logger.info('Balance of User (2*value (2*1) + value received) ', endBalance - startBalance); logger.info('Amount sent to other User', value * TEST_LENGTH); nf3.close(); - break; + process.exit(0); } else { logger.info( - 'The test has not yet passed because the L2 balance has not increased - waiting', + 'The test has not yet passed because the L2 balance has not increased, or I am not the test runner - waiting', endBalance - startBalance, 2 * value + value * TEST_LENGTH, ); await new Promise(resolving => setTimeout(resolving, 20 * TX_WAIT)); // TODO get balance waiting working well loop++; } - } while (loop < 10); + } while (loop < loopMax); + process.exit(1); } localTest(); diff --git a/test/ping-pong/user-local/src/utils.mjs b/test/ping-pong/user-local/src/utils.mjs index 60330b49e..defc8afcf 100644 --- a/test/ping-pong/user-local/src/utils.mjs +++ b/test/ping-pong/user-local/src/utils.mjs @@ -1,20 +1,13 @@ /** - function to retrieve balance of user because getLayer2Balances returns - balances of all users + function to retrieve balance of user */ export const retrieveL2Balance = async client => { const balances = await client.getLayer2Balances(); // if there are no balances - if (Object.keys(balances).length === 0) { + if (Object.values(balances).length === 0) { return 0; } - const clientBalances = balances[client.zkpKeys.compressedPkd]; - // if this user has no balance - if (clientBalances === undefined || Object.keys(clientBalances).length === 0) { - return 0; - } - // TODO return address by contract address - const balance = clientBalances[Object.keys(clientBalances)[0]]; + const { balance } = Object.values(balances)[0][0]; return balance; }; @@ -25,19 +18,9 @@ export const retrieveL2Balance = async client => { export const waitForSufficientBalance = (client, value) => { return new Promise(resolve => { async function isSufficientBalance() { - const balances = await client.getLayer2Balances(); - console.log('Balance', balances, value); - if ( - Object.keys(balances).length === 0 || - balances[client.zkpKeys.compressedPkd] === undefined || - Object.keys(balances[client.zkpKeys.compressedPkd]).length === 0 || - balances[client.zkpKeys.compressedPkd][ - Object.keys(balances[client.zkpKeys.compressedPkd])[0] - ] === undefined || - balances[client.zkpKeys.compressedPkd][ - Object.keys(balances[client.zkpKeys.compressedPkd])[0] - ] < value - ) { + const balance = await retrieveL2Balance(client); + console.log('Balance', balance, value); + if (balance < value) { await new Promise(resolving => setTimeout(resolving, 10000)); isSufficientBalance(); } else resolve();