Skip to content

Commit

Permalink
Merge pull request #526 from EYBlockchain/westlad/ping-pong-fix
Browse files Browse the repository at this point in the history
Westlad/ping pong fix
  • Loading branch information
Westlad authored Feb 25, 2022
2 parents 2ce68f1 + 312645d commit d189ebb
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 54 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/check-PRs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/ping-pong/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/ping-pong/pong-apps
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions test/ping-pong/proposer/src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
21 changes: 0 additions & 21 deletions test/ping-pong/user-local/Dockerfile

This file was deleted.

16 changes: 10 additions & 6 deletions test/ping-pong/user-local/src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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(',');

/**
Expand All @@ -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,
Expand Down Expand Up @@ -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();
29 changes: 6 additions & 23 deletions test/ping-pong/user-local/src/utils.mjs
Original file line number Diff line number Diff line change
@@ -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;
};

Expand All @@ -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();
Expand Down

0 comments on commit d189ebb

Please sign in to comment.