Skip to content

Commit

Permalink
Merge pull request #823 from EYBlockchain/zepedro/ping-pong-mocha
Browse files Browse the repository at this point in the history
Stuffing ping-pong in a mocha test
  • Loading branch information
signorecello authored Sep 11, 2022
2 parents 51b1fd0 + df09d57 commit e642e5c
Show file tree
Hide file tree
Showing 38 changed files with 884 additions and 13,193 deletions.
36 changes: 12 additions & 24 deletions .github/workflows/check-PRs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -241,49 +241,37 @@ jobs:

- name: Start Containers
run: |
docker build --no-cache -t ghcr.io/eyblockchain/local-zokrates:0.7.13 -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
./setup-nightfall
./start-nightfall -g -d &> ping-pong-test.log &disown
- name: Wait for images to be ready
uses: Wandalen/wretry.action@v1.0.11
with:
command: |
docker wait ping-pong_deployer_1
docker wait nightfall_3_deployer_1
attempt_limit: 100
attempt_delay: 20000

- name: Debug logs - after image builds
if: always()
run: cat ping-pong-test.log

- name: Run ping-pong test
run: |
cd test/ping-pong
./pong-apps
- name: debug logs - after integration test run
if: always()
run:
results=$(cat test/ping-pong/ping-pong-test.log | grep passed); if [ ! -z "${results}" ];
then exit 0; else exit 1; fi
npm ci
docker wait nightfall_3_deployer_1
npm run ping-pong
- name: If integration test failed, shutdown the Containers
if: failure()
run: |
cd test/ping-pong
./pong-down -v
./ganache-standalone -d
run: docker-compose -f docker-compose.yml -f docker-compose.ganache.yml down -v

- 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
path: ./ping-pong-test.log

test-gas:
name: check gas for 32 transactions per block
Expand Down
13 changes: 0 additions & 13 deletions apps/proposer/config/default.js

This file was deleted.

5,194 changes: 768 additions & 4,426 deletions apps/proposer/package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions apps/proposer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
"description": "'makes a container with proposer functionality'",
"main": "index.js",
"scripts": {
"start": "export $(cat ../../nightfall-optimist/optimist.env | xargs) && node --trace-warnings src/app.mjs",
"start": "node --trace-warnings src/app.mjs",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "westlad",
"license": "CC0-1.0",
"dependencies": {
"async-mutex": "^0.3.2",
"body-parser": "^1.19.2",
"common-files": "file:../../common-files",
"common-files": "file:../common-files",
"config": "^3.3.1",
"cors": "^2.8.5",
"express": "^4.17.3",
Expand Down
41 changes: 13 additions & 28 deletions apps/proposer/src/app.mjs
Original file line number Diff line number Diff line change
@@ -1,40 +1,23 @@
/* ignore unused exports */
/* eslint-disable import/no-unresolved */

import express from 'express';
import bodyParser from 'body-parser';
import config from 'config';
import cors from 'cors';
import fileUpload from 'express-fileupload';
import { proposer, contracts } from './routes/index.mjs';
import startProposer from './proposer.mjs';
import Nf3 from '../../../cli/lib/nf3.mjs';

const { SIGNING_KEY, PROPOSER_PORT } = config;
const {
CLIENT_URL = '',
OPTIMIST_HTTP_URL = '',
OPTIMIST_WS_URL = '',
BLOCKCHAIN_URL = '',
PROPOSER_URL = '',
} = process.env;
const environment = {
clientApiUrl:
`${CLIENT_URL}` !== '' ? `${CLIENT_URL}` : `http://${config.CLIENT_HOST}:${config.CLIENT_PORT}`,
optimistApiUrl:
`${OPTIMIST_HTTP_URL}` !== ''
? `${OPTIMIST_HTTP_URL}`
: `http://${config.OPTIMIST_HOST}:${config.OPTIMIST_PORT}`,
optimistWsUrl: `${OPTIMIST_WS_URL}`
? `${OPTIMIST_WS_URL}`
: `ws://${config.OPTIMIST_HOST}:${config.OPTIMIST_WS_PORT}`,
web3WsUrl: `${BLOCKCHAIN_URL}`
? `${BLOCKCHAIN_URL}`
: `ws://${config.BLOCKCHAIN_WS_HOST}:${config.BLOCKCHAIN_PORT}`,
proposerBaseUrl: `${PROPOSER_URL}`
? `${PROPOSER_URL}`
: `http://${process.env.PROPOSER_HOST}:${process.env.PROPOSER_PORT}`,
};
import Nf3 from '../cli/lib/nf3.mjs';

const PROPOSER_PORT = process.env.PROPOSER_PORT || 8092;

const environment = config.ENVIRONMENTS[process.env.ENVIRONMENT] || config.ENVIRONMENTS.localhost;

console.log(environment);

const app = express();
const nf3 = new Nf3(SIGNING_KEY, environment);
const nf3 = new Nf3(environment.PROPOSER_KEY, environment);

app.set('nf3', nf3);

Expand All @@ -55,6 +38,8 @@ app.use(
app.get('/healthcheck', (req, res) => res.sendStatus(200));
app.use('/proposer', proposer);
app.use('/contract-address', contracts);
if (!PROPOSER_PORT) throw new Error('Please specify a proposer port');

app.listen(PROPOSER_PORT);

startProposer(nf3, environment.proposerBaseUrl);
Expand Down
7 changes: 2 additions & 5 deletions apps/proposer/src/proposer.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* eslint-disable import/no-unresolved */
/**
Module that runs up as a proposer
*/
import config from 'config';
import logger from '../../../common-files/utils/logger.mjs';

const { PROPOSER_PORT } = config;
import logger from '../common-files/utils/logger.mjs';

/**
Does the preliminary setup and starts listening on the websocket
Expand All @@ -20,7 +18,6 @@ export default async function startProposer(nf3, proposerBaseUrl) {
logger.info('Attempting to register proposer');

await nf3.registerProposer(proposerBaseUrl);
if (!PROPOSER_PORT) throw new Error('Please specify a proposer port');
logger.debug('Proposer healthcheck up');

// TODO subscribe to layer 1 blocks and call change proposer
Expand Down
4 changes: 3 additions & 1 deletion apps/proposer/src/routes/contract-address.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/* eslint-disable import/no-unresolved */

/**
Routes for managing a proposer.
Some transactions are so simple that, we don't split out a separate service
module but handle the entire request here.
*/
import express from 'express';
import logger from '../../../../common-files/utils/logger.mjs';
import logger from '../../common-files/utils/logger.mjs';

const router = express.Router();

Expand Down
4 changes: 3 additions & 1 deletion apps/proposer/src/routes/proposer.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/* eslint-disable import/no-unresolved */

/**
Routes for managing a proposer.
Some transactions are so simple that, we don't split out a separate service
module but handle the entire request here.
*/
import express from 'express';
import logger from '../../../../common-files/utils/logger.mjs';
import logger from '../../common-files/utils/logger.mjs';

const router = express.Router();

Expand Down
2 changes: 2 additions & 0 deletions cli/lib/nf3.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ class Nf3 {
rootKey: this.zkpKeys.rootKey,
fee,
});

if (res.data.error && res.data.error === 'No suitable commitments') {
throw new Error('No suitable commitments');
}
Expand Down Expand Up @@ -711,6 +712,7 @@ class Nf3 {
return new Promise((resolve, reject) => {
proposerQueue.push(async () => {
try {
console.log('receipt');
const receipt = await this.submitTransaction(
res.data.txDataToSign,
this.proposersContractAddress,
Expand Down
1 change: 0 additions & 1 deletion cli/lib/tokens.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ async function approve(
) {
const abi = getAbi(tokenType);
const ercContract = new provider.eth.Contract(abi, ercAddress);

switch (tokenType) {
case TOKEN_TYPE.ERC20: {
const allowance = await ercContract.methods.allowance(ownerAddress, spenderAddress).call();
Expand Down
19 changes: 14 additions & 5 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,23 @@ module.exports = {
: process.env.BLOCKCHAIN_WS_HOST
? `wss://${process.env.BLOCKCHAIN_WS_HOST}`
: 'ws://localhost:8546',
PROPOSER_KEY:
process.env.ETH_PRIVATE_KEY ||
'0x4775af73d6dc84a0ae76f8726bda4b9ecf187c377229cb39e1afa7a18236a69d', // owner's/deployer's private key
},
aws: {
name: 'AWS',
clientApiUrl: `http://${process.env.CLIENT_HOST}:${process.env.CLIENT_PORT}`,
optimistApiUrl: `https://${process.env.OPTIMIST_HTTP_HOST}`,
optimistWsUrl: `wss://${process.env.OPTIMIST_HOST}`,
proposerBaseUrl: `https://${process.env.PROPOSER_HOST}`,
web3WsUrl: `wss://${process.env.BLOCKCHAIN_WS_HOST}`,
chainId: 1337,
clientApiUrl: 'http://localhost:8080',
optimistApiUrl: 'https://optimist-api.staging.polygon-nightfall.technology',
optimistWsUrl: 'wss://optimist-ws.staging.polygon-nightfall.technology',
proposerBaseUrl: 'https://proposer.staging.polygon-nightfall.technology',
adversarialOptimistApiUrl: 'http://localhost:8088',
adversarialOptimistWsUrl: 'ws://localhost:8089',
web3WsUrl: 'wss://web3-ws.staging.polygon-nightfall.technology',
PROPOSER_KEY: '0x4775af73d6dc84a0ae76f8726bda4b9ecf187c377229cb39e1afa7a18236a69d',
PROPOSER_MNEMONIC:
'high return hold whale promote payment hat panel reduce oyster ramp mouse',
},
},
TEST_OPTIONS: {
Expand Down
10 changes: 4 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ services:
OPTIMIST_HOST: optimist
OPTIMIST_PORT: 80
USE_STUBS: 'false' # make sure this flag is the same as in deployer service
command: ['npm', 'run', 'dev']

command: [ 'npm', 'run', 'dev' ]
# Temporary container to deploy contracts and circuits and populate volumes
deployer:
#image: docker.pkg.github.com/eyblockchain/nightfall-deployer/nightfall_deployer:1.1.0
Expand Down Expand Up @@ -83,8 +82,8 @@ services:

optimist:
image: ghcr.io/eyblockchain/nightfall3-optimist:latest
# depends_on:
# - deployer
# depends_on:
# - deployer
networks:
- nightfall_network
ports:
Expand All @@ -103,7 +102,7 @@ services:
LOG_LEVEL: debug
IS_CHALLENGER: 'false'
TRANSACTIONS_PER_BLOCK: ${TRANSACTIONS_PER_BLOCK:-2}
command: ['npm', 'run', 'dev']
command: [ 'npm', 'run', 'dev' ]

rabbitmq:
image: rabbitmq
Expand All @@ -128,7 +127,6 @@ services:
environment:
LOG_LEVEL: info
MPC: ${MPC}

volumes:
mongodb: null
proving_files: null
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "Optimistic Nightfall",
"main": "./nightfall-client/src/index.mjs",
"scripts": {
"ping-pong": "mocha --timeout 0 --bail --exit test/ping-pong/ping-pong.test.mjs",
"lint": "eslint . --ext js,mjs,jsx,ts,tsx && find-unused-exports",
"prepare": "husky install",
"doc:build:sdk": "jsdoc -c jsdoc.json cli/lib/nf3.mjs",
Expand Down
24 changes: 10 additions & 14 deletions proposer.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
FROM node:16.17

RUN apt-get update -y
RUN apt-get install -y netcat-openbsd

# websocket port 8080
EXPOSE 8080

ENTRYPOINT ["/app/apps/proposer/docker-entrypoint.sh"]
FROM node:14.17

WORKDIR /app
COPY common-files common-files
COPY apps/proposer/config /app/apps/proposer/config
COPY cli cli

WORKDIR /app/common-files
RUN npm ci

WORKDIR /app/cli
RUN npm ci

WORKDIR /app/apps/proposer
WORKDIR /app
RUN apt-get update -y
RUN apt-get install -y netcat-openbsd
COPY apps/proposer/package*.json ./
COPY apps/proposer/src src
COPY apps/proposer/docker-entrypoint.sh docker-entrypoint.sh
COPY config config

RUN npm ci
# websocket port 8080
EXPOSE 8080

RUN npm i
ENTRYPOINT ["/app/docker-entrypoint.sh"]

CMD ["npm", "start"]
2 changes: 1 addition & 1 deletion start-nightfall
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,4 @@ if [[ -d "$DIR" ]]; then
fi
#docker-compose -f docker-compose.yml $FILE up -d deployer
docker-compose $FILE $STUBS $DEV $ADVERSARY up -d --remove-orphans
docker-compose logs -f client optimist worker deployer
docker-compose logs -f
2 changes: 1 addition & 1 deletion test/e2e/circuits.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('General Circuit Test', () => {
before(async () => {
await nf3Proposer.init(mnemonics.proposer);
// we must set the URL from the point of view of the client container
await nf3Proposer.registerProposer('http://optimist1');
await nf3Proposer.registerProposer('http://optimis1');

// Proposer listening for incoming events
const newGasBlockEmitter = await nf3Proposer.startProposer();
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/protocol/health-and-contracts.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ describe('Health and Contract Checks', () => {
});

it('should get the address of the test ERC721 mock contract', async function () {
if (process.env.ENVIRONMENT === 'aws') this.skip();
const res = await nf3User1.getContractAddress('ERC721Mock');
expect(res).to.be.a('string').and.to.include('0x');
});

it('should get the address of the test ERC1155 mock contract', async function () {
if (process.env.ENVIRONMENT === 'aws') this.skip();
const res = await nf3User1.getContractAddress('ERC1155Mock');
expect(res).to.be.a('string').and.to.include('0x');
});
Expand Down
Loading

0 comments on commit e642e5c

Please sign in to comment.