Skip to content

Commit

Permalink
Merge pull request #334 from EYBlockchain/liju.jose/configure-hosted-…
Browse files Browse the repository at this point in the history
…geth-for-blockchain-client

configuration for hosted geth implemented
  • Loading branch information
ChaitanyaKonda authored Jan 18, 2022
2 parents 2ffa2c4 + 3fea884 commit 6e61909
Show file tree
Hide file tree
Showing 19 changed files with 128 additions and 93 deletions.
5 changes: 4 additions & 1 deletion .env-cmdrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
},
"ropsten": {
"network": "ropsten",
"web3WsUrl": "wss://ropsten1-ws.testnet.nightfall3.com"
"web3WsUrl": "wss://ropsten1-ws.testnet.nightfall3.com",
"EVENT_RETRIEVE_RETRIES": "10",
"USE_ROPSTEN_NODE": "true",
"FROM_ADDRESS": "0x29100E7E3dA6654BF63d9E7804ADe518aCc5AaA5"
},
"production": {
"network": "mainnet",
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/check-PRs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ jobs:
docker-compose build
./start-nightfall -g &> ganache-test.log &disown
- name: wait 1500s for Containers startup and setup completion
run: sleep 1500
- name: wait 2000s for Containers startup and setup completion
run: sleep 2000

- name: debug logs - after container startup
if: always()
Expand Down
71 changes: 0 additions & 71 deletions .github/workflows/infura-ropsten-deploy-cron-job.yml

This file was deleted.

57 changes: 57 additions & 0 deletions .github/workflows/ropsten-deploy-cron-job.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: "ropsten deployment at end of every day"
on:
schedule:
- cron: "0 0 * * *"

jobs:
ropsten-test:
runs-on: ubuntu-18.04
environment: TESTNET_DEPLOYMENT
env:
ETH_PRIVATE_KEY: ${{ secrets.ETH_PRIVATE_KEY }}
ROPSTEN_NODE: ${{ secrets.ROPSTEN_NODE }}

steps:
- uses: actions/checkout@master
- uses: actions/setup-node@v1
with:
node-version: '14.17.0'

- name: Start Containers
run: |
docker-compose build
./start-nightfall -r &> ropsten-test.log &disown
- name: wait 7000s for Containers startup and setup completion
run: sleep 7000

# kept it for future debug
# - run: sleep 1000
# - name: debug logs - after container startup 1
# if: always()
# run: cat ropsten-test.log

# - run: sleep 1000
# - name: debug logs - after container startup 2
# if: always()
# run: cat ropsten-test.log

- name: Run integration test
run: |
npm ci
npm run ropsten-test
- name: debug logs - after integration test run
if: always()
run: cat ropsten-test.log

- name: If integration test failed, shutdown the Containers
if: failure()
run: docker-compose down -v

- name: If integration test failed, upload logs files as artifacts
if: failure()
uses: actions/upload-artifact@master
with:
name: ropsten-test-logs
path: ./ropsten-test.log
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ You need to run a setup script the first time that you use nightfall_3. This wi

If running for first time, do the setup as above and then run this script:
```sh
./start-nightfall -l | -g [-s]
./start-nightfall -l | -g | -r [-s]
```
This will bring up the application. You can run it either with a Ganache blockchain simulator or a real blockchain client which exposes a websocket connection on localHost:8546. See below for more details on how to do the latter as there are some additional considerations. Use -g for Ganache and -l for localhost. We recommend using Ganache first to check everything works, because it's considerably faster. Additionally, you can use the -s flag. If you do that, Nightfall_3 will run with stubbed ZKP circuits, which generate proofs that always verify. That's useful for development work because tests will run much faster but clearly you should run without stubs, as a final check.

This will bring up the application. You can run it either with a Ganache blockchain simulator, a real blockchain client which exposes a websocket connection on localHost:8546, or a public/private VM runing public testnet node (for example Ropsten, Rinkeby, Kovan, etc. Code is tested on Ropsten testnet, but ideally it should work on all testnet network). See below for more details on how to do the latter as there are some additional considerations. Use -g for Ganache, -l for localhost and -r for testnet node (Note: with option -r set environment variable $ROPSTEN_NODE, $FROM_ADDRESS and $ETH_PRIVATE_KEY to testnet node URL, EOA address and EOA address's private key, respectively). We recommend using Ganache first to check everything works, because it's considerably faster. Additionally, you can use the -s flag. If you do that, Nightfall_3 will run with stubbed ZKP circuits, which generate proofs that always verify. That's useful for development work because tests will run much faster but clearly you should run without stubs, as a final check.

Startup will take a minute or so, depending on your machine. You'll see lots of warnings as it runs up from the `optimist` and `timber` containers. That's entirely fine, they're just waiting for the other services that they need to start up. You should see no errors however. If you do, something has broken.

Expand Down
1 change: 1 addition & 0 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module.exports = {
USE_INFURA: process.env.USE_INFURA === 'true',
ETH_PRIVATE_KEY: process.env.ETH_PRIVATE_KEY, // owner's/deployer's private key
ETH_ADDRESS: process.env.ETH_ADDRESS,
USE_ROPSTEN_NODE: process.env.USE_ROPSTEN_NODE === 'true',
OPTIMIST_HOST: process.env.OPTIMIST_HOST || 'optimist',
OPTIMIST_PORT: process.env.OPTIMIST_PORT || 80,
clientBaseUrl: `http://${process.env.CLIENT_HOST}:${process.env.CLIENT_PORT}`,
Expand Down
File renamed without changes.
35 changes: 35 additions & 0 deletions docker-compose.ropsten.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: '3.5'
services:
client1:
environment:
BLOCKCHAIN_URL: $ROPSTEN_NODE
USE_ROPSTEN_NODE: 'true'
AUTOSTART_RETRIES: 600

client2:
environment:
BLOCKCHAIN_URL: $ROPSTEN_NODE
USE_ROPSTEN_NODE: 'true'
AUTOSTART_RETRIES: 600

deployer:
environment:
# ETH_NETWORK sets the network selected by Truffle from truffle-config.js
# startup routines will wait for a blockchain client to be reachable on this network
ETH_NETWORK: ropsten
BLOCKCHAIN_URL: $ROPSTEN_NODE
USE_ROPSTEN_NODE: 'true'
FROM_ADDRESS: ${FROM_ADDRESS:-0x29100E7E3dA6654BF63d9E7804ADe518aCc5AaA5}
ETH_PRIVATE_KEY: $ETH_PRIVATE_KEY

optimist1:
environment:
BLOCKCHAIN_URL: $ROPSTEN_NODE
USE_ROPSTEN_NODE: 'true'
AUTOSTART_RETRIES: 600

optimist2:
environment:
BLOCKCHAIN_URL: $ROPSTEN_NODE
USE_ROPSTEN_NODE: 'true'
AUTOSTART_RETRIES: 600
2 changes: 1 addition & 1 deletion nightfall-client/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mongod --dbpath /app/mongodb/ --fork --logpath /var/log/mongodb/mongod.log --bin
while ! nc -z localhost 27017; do sleep 3; done
echo 'mongodb started'

if [ -z "${USE_INFURA}" ]
if [ -z "${USE_INFURA}" ] && [ -z "${USE_ROPSTEN_NODE}" ];
then
# wait until there's a blockchain client up
while ! nc -z ${BLOCKCHAIN_WS_HOST} ${BLOCKCHAIN_PORT}; do sleep 3; done
Expand Down
2 changes: 1 addition & 1 deletion nightfall-deployer/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -o errexit
set -o pipefail

if [ -z "${USE_INFURA}" ] && [ -z "${ETH_PRIVATE_KEY}" ]; then
if [ -z "${USE_INFURA}" ] && [ -z "${ETH_PRIVATE_KEY}" ] && [ -z "${USE_ROPSTEN_NODE}" ]; then
# wait until there's a blockchain client up
while ! nc -z ${BLOCKCHAIN_WS_HOST} ${BLOCKCHAIN_PORT}; do sleep 3; done
fi
Expand Down
8 changes: 4 additions & 4 deletions nightfall-deployer/migrations/4_test_tokens_migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ const ERC20Mock = artifacts.require('ERC20Mock.sol');
const ERC721Mock = artifacts.require('ERC721Mock.sol');
const ERC1155Mock = artifacts.require('ERC1155Mock.sol');

const recipientAddress = '0x9c8b2276d490141ae1440da660e470e7c0349c63';
// const recipientAddress = '0x9c8b2276d490141ae1440da660e470e7c0349c63';
const walletTestAddress = '0xfCb059A4dB5B961d3e48706fAC91a55Bad0035C9';
const liquidityProviderAddress = '0x4789FD18D5d71982045d85d5218493fD69F55AC4';
const nERC721 = 100;

module.exports = function(deployer) {
module.exports = function(deployer, _, accounts) {
deployer.then(async () => {
await deployer.deploy(ERC20Mock, 1001010000000000); // initialSupply
await deployer.deploy(ERC721Mock);
Expand All @@ -33,15 +33,15 @@ module.exports = function(deployer) {
const ERC1155deployed = await ERC1155Mock.deployed();
// For e2e tests
for (let i=0; i < nERC721; i++){
await ERC721deployed.awardItem(recipientAddress, `https://erc721mock/item-id-${i}.json`);
await ERC721deployed.awardItem(accounts[0], `https://erc721mock/item-id-${i}.json`);
}
// For testing the wallet
await ERC20deployed.transfer(walletTestAddress, 10000000000);
await ERC20deployed.transfer(liquidityProviderAddress, 10000000000);
for (let i=0; i < 100; i++){
await ERC721deployed.awardItem(walletTestAddress, `https://erc721mock/item-id-${i}.json`);
}
await ERC1155deployed.safeBatchTransferFrom(recipientAddress, walletTestAddress, [0, 1, 4],
await ERC1155deployed.safeBatchTransferFrom(accounts[0], walletTestAddress, [0, 1, 4],
[5000000, 200000, 100000], []);
}
});
Expand Down
2 changes: 1 addition & 1 deletion nightfall-deployer/src/circuit-setup.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ async function setupCircuits() {

// when deploying on infura - do serial tx execution to avoid nonce issue
// when using a private key, we shouldn't assume an unlocked account and we sign the transaction directly
if (config.USE_INFURA || config.ETH_PRIVATE_KEY) {
if (config.USE_INFURA || config.ETH_PRIVATE_KEY || config.USE_ROPSTEN_NODE) {
await Web3.submitRawTransaction(await tx.encodeABI(), keyRegistryAddress);
} else await tx.send();
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion nightfall-deployer/src/contract-setup.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async function setupCircuits() {
// when deploying on infura
// do serial registration to predict nonce
// or, if we have the owner's private key, sign with that, rather than use an unlocked account
if (config.USE_INFURA || config.ETH_PRIVATE_KEY) {
if (config.USE_INFURA || config.ETH_PRIVATE_KEY || config.USE_ROPSTEN_NODE) {
await Web3.submitRawTransaction(
(await waitForContract('Proposers')).methods
.setStateContract(stateInstance.options.address)
Expand Down
2 changes: 1 addition & 1 deletion nightfall-optimist/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mongod --dbpath /app/mongodb/ --fork --logpath /var/log/mongodb/mongod.log --bin
while ! nc -z localhost 27017; do sleep 3; done
echo 'mongodb started'

if [ -z "${USE_INFURA}" ]
if [ -z "${USE_INFURA}" ] && [ -z "${USE_ROPSTEN_NODE}" ];
then
# wait until there's a blockchain client up
while ! nc -z ${BLOCKCHAIN_WS_HOST} ${BLOCKCHAIN_PORT}; do sleep 3; done
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "./nightfall-client/src/index.mjs",
"scripts": {
"test": "env-cmd -e development mocha --timeout 0 --bail test/http.mjs test/neg-http.mjs",
"testnet-test": "EVENT_RETRIEVE_RETRIES=10 USE_INFURA=true FROM_ADDRESS=0x29100E7E3dA6654BF63d9E7804ADe518aCc5AaA5 BLOCKCHAIN_URL=wss://ropsten.infura.io/ws/v3/INFURA_PROJECT_ID mocha --timeout 0 --bail test/http.mjs test/neg-http.mjs",
"infura-test": "EVENT_RETRIEVE_RETRIES=10 USE_INFURA=true FROM_ADDRESS=0x29100E7E3dA6654BF63d9E7804ADe518aCc5AaA5 BLOCKCHAIN_URL=wss://ropsten.infura.io/ws/v3/INFURA_PROJECT_ID mocha --timeout 0 --bail test/http.mjs test/neg-http.mjs",
"ropsten-test": "env-cmd -e ropsten mocha --timeout 0 --bail test/http.mjs test/neg-http.mjs",
"test-gas": "env-cmd -e development mocha --timeout 0 --bail test/tx-gas.mjs",
"test-chain-reorg": "env-cmd -e development mocha --timeout 0 --bail test/chain-reorg.mjs",
"test-e2e": "env-cmd -e development mocha --timeout 0 --bail test/e2e/nightfall-sdk.test.mjs",
Expand Down
7 changes: 5 additions & 2 deletions start-nightfall
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ usage()
echo " -l or --localhost; to connect to an already running blockchain on ws://localhost:8546"
echo " -s or --stubs; runs with circuits stubbed out (faster but no checking of ZKP code) - use with either -g or -l"
echo " -h or --help; to print this message"
echo " -t or --testnet; to connect infura ropsten testnet"
echo " -i or --infura; to connect infura ropsten testnet"
echo " -r or --ropsten to connect testnet node (Note: please set environment variable ROPSTEN_NODE, FROM_ADDRESS, and ETH_PRIVATE_KEY. Find more description in README.md)"
}

# select a Geth or Ganache client
Expand All @@ -39,7 +40,9 @@ while [ -n "$1" ]; do
;;
-l | --localhost ) FILE="-f docker-compose.yml -f docker-compose.host.docker.internal.yml"
;;
-t | --testnet ) FILE="-f docker-compose.yml -f docker-compose.testnet.yml"
-r | --ropsten ) FILE="-f docker-compose.yml -f docker-compose.ropsten.yml"
;;
-i | --infura ) FILE="-f docker-compose.yml -f docker-compose.infura.yml"
;;
-h | --help ) usage
;;
Expand Down
6 changes: 4 additions & 2 deletions test/http.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ describe('Testing the http API', () => {
let compressedPkd2;

const USE_INFURA = process.env.USE_INFURA === 'true';
const USE_ROPSTEN_NODE = process.env.USE_ROPSTEN_NODE === 'true';
const { ETH_PRIVATE_KEY, BLOCKCHAIN_URL } = process.env;
const web3WsUrl = BLOCKCHAIN_URL || process.env.web3WsUrl;

const senderUrl = 'http://localhost:8080';
const recipientUrl = 'http://localhost:8084';
Expand Down Expand Up @@ -87,9 +89,9 @@ describe('Testing the http API', () => {
const gasCostsTx = 5000000000000000;

before(async function () {
web3 = await connectWeb3(BLOCKCHAIN_URL);
web3 = await connectWeb3(web3WsUrl);

if (USE_INFURA) {
if (USE_INFURA || USE_ROPSTEN_NODE) {
if (!ETH_PRIVATE_KEY) {
throw Error(
'Cannot use default private key, please set environment variable ETH_PRIVATE_KEY',
Expand Down
6 changes: 4 additions & 2 deletions test/neg-http.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ describe('Testing the challenge http API', () => {
let compressedPkd1;

const USE_INFURA = process.env.USE_INFURA === 'true';
const USE_ROPSTEN_NODE = process.env.USE_ROPSTEN_NODE === 'true';
const { ETH_PRIVATE_KEY, BLOCKCHAIN_URL } = process.env;
const web3WsUrl = BLOCKCHAIN_URL || process.env.web3WsUrl;

const url = 'http://localhost:8080';
const optimistUrl = 'http://localhost:8081';
Expand Down Expand Up @@ -84,9 +86,9 @@ describe('Testing the challenge http API', () => {
};

before(async () => {
web3 = await connectWeb3(BLOCKCHAIN_URL);
web3 = await connectWeb3(web3WsUrl);

if (USE_INFURA) {
if (USE_INFURA || USE_ROPSTEN_NODE) {
if (!ETH_PRIVATE_KEY) {
throw Error(
'Cannot use default private key, please set environment variable ETH_PRIVATE_KEY',
Expand Down
3 changes: 2 additions & 1 deletion test/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ let web3;
// This will be a mapping of privateKeys to nonces;
const nonceDict = {};
const USE_INFURA = process.env.USE_INFURA === 'true';
const USE_ROPSTEN_NODE = process.env.USE_ROPSTEN_NODE === 'true';
const { INFURA_PROJECT_SECRET, INFURA_PROJECT_ID } = process.env;
let isSubmitTxLocked = false;

Expand Down Expand Up @@ -119,7 +120,7 @@ export async function submitTransaction(
const accountAddress = await web3.eth.accounts.privateKeyToAccount(privateKey);
nonce = await web3.eth.getTransactionCount(accountAddress.address);
}
if (USE_INFURA) {
if (USE_INFURA || USE_ROPSTEN_NODE) {
// get gaslimt from latest block as gaslimt may vary
gas = (await web3.eth.getBlock('latest')).gasLimit;
const blockGasPrice = Number(await web3.eth.getGasPrice());
Expand Down

0 comments on commit 6e61909

Please sign in to comment.