Skip to content

Commit 19c255c

Browse files
fix: wip
1 parent fc97ebd commit 19c255c

16 files changed

+1309
-115
lines changed

‎config/default.js

+19
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,31 @@ module.exports = {
4141
process.env.USER_ETHEREUM_SIGNING_KEY ||
4242
'0x4775af73d6dc84a0ae76f8726bda4b9ecf187c377229cb39e1afa7a18236a69e',
4343
userAddress: process.env.USER_ADDRESS,
44+
user1EthereumSigningKey:
45+
process.env.USER_ETHEREUM_SIGNING_KEY ||
46+
'0xb0fa8745bd6e77a67ec6a27e701971d659937140cc3159d9f85210da3444eb45', // Change associated user1EthereumAddress
47+
user2EthereumSigningKey:
48+
process.env.USER2_ETHEREUM_SIGNING_KEY ||
49+
'0xd42905d0582c476c4b74757be6576ec323d715a0c7dcff231b6348b7ab0190eb', // Change associated user2EthereumAddress
50+
userEthereumAddress: process.env.ETHEREUM_ADDRESS || '0x9c8b2276d490141ae1440da660e470e7c0349c63', // Change associated userEthereumSigningKey
51+
user1EthereumAddress:
52+
process.env.ETHEREUM_ADDRESS || '0x4ca4902a6f456b488947074ad4140317c7e21996', // Change associated user1EthereumSigningKey
53+
user2EthereumAddress:
54+
process.env.ETHEREUM_ADDRESS || '0xfCb059A4dB5B961d3e48706fAC91a55Bad0035C9', // Change associated user2EthereumSigningKey
4455
zkpMnemonic:
4556
process.env.ZKP_MNEMONIC ||
4657
'hurt labor ketchup seven scan swap dirt brown brush path goat together',
4758
proposerEthereumSigningKey:
4859
process.env.PROPOSER_ETHEREUM_SIGNING_KEY ||
4960
'0x4775af73d6dc84a0ae76f8726bda4b9ecf187c377229cb39e1afa7a18236a69d',
61+
user1Pkd: process.env.RECIPIENT_PKD || [
62+
'0x193a37cd7973373aceae05d133f3d69ab6e7ef2f4321461173871ec7611244e2',
63+
'0x27234a8721e73c9aa160154ee63d2470101fc5fd841221eeb675a91ec2d66e78',
64+
],
65+
user2Pkd: process.env.RECIPIENT_PKD || [
66+
'0x105651c0c5bb97582b3270e0f5a07ca81410ffd1920e86697efddaec03dccef8',
67+
'0x1ac3b61ecba1448e697b23d37efe290fb86554b2f905aaca3a6df59805eca366',
68+
],
5069
WEB3_OPTIONS: {
5170
gas: process.env.GAS || 8000000,
5271
gasPrice: process.env.GAS_PRICE || '20000000000',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.0;
3+
4+
import '@openzeppelin/contracts/token/ERC20/ERC20.sol';
5+
6+
contract ERC20Mock1 is ERC20 {
7+
constructor(uint256 initialSupply) ERC20('ERC20Mock1', 'E1_20') {
8+
_mint(msg.sender, initialSupply);
9+
}
10+
11+
function decimals() public view virtual override returns (uint8) {
12+
return 9;
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.0;
3+
4+
import '@openzeppelin/contracts/token/ERC20/ERC20.sol';
5+
6+
contract ERC20Mock2 is ERC20 {
7+
constructor(uint256 initialSupply) ERC20('ERC20Mock2', 'E2_20') {
8+
_mint(msg.sender, initialSupply);
9+
}
10+
11+
function decimals() public view virtual override returns (uint8) {
12+
return 9;
13+
}
14+
}

‎nightfall-deployer/migrations/4_test_tokens_migration.js

+17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1+
const config = require('config');
2+
3+
const {
4+
userEthereumAddress,
5+
user1EthereumAddress,
6+
user2EthereumAddress
7+
} = config;
8+
19
const ERC20Mock = artifacts.require('ERC20Mock.sol');
10+
const ERC20Mock1 = artifacts.require('ERC20Mock1.sol');
11+
const ERC20Mock2 = artifacts.require('ERC20Mock2.sol');
212
const ERC721Mock = artifacts.require('ERC721Mock.sol');
313
const ERC1155Mock = artifacts.require('ERC1155Mock.sol');
414
const config = require('config');
@@ -9,12 +19,19 @@ const walletTestAddress = config.userAddress || '0xfCb059A4dB5B961d3e48706fAC91a
919
module.exports = function(deployer) {
1020
deployer.then(async () => {
1121
await deployer.deploy(ERC20Mock, 100000000000); // initialSupply
22+
await deployer.deploy(ERC20Mock1, 100000000000); // initialSupply
23+
await deployer.deploy(ERC20Mock2, 100000000000); // initialSupply
1224
await deployer.deploy(ERC721Mock);
1325
await deployer.deploy(ERC1155Mock);
1426

1527
const ERC20deployed = await ERC20Mock.deployed();
28+
const ERC20deployed1 = await ERC20Mock1.deployed();
29+
const ERC20deployed2 = await ERC20Mock2.deployed();
1630
const ERC721deployed = await ERC721Mock.deployed();
1731
const ERC1155deployed = await ERC1155Mock.deployed();
32+
// For ping pong tests
33+
await ERC20deployed1.transfer(user1EthereumAddress, 100000000000);
34+
await ERC20deployed2.transfer(user2EthereumAddress, 100000000000);
1835
// For e2e tests
1936
await ERC721deployed.awardItem(recipientAddress, 'https://erc721mock/item-id-1.json');
2037
await ERC721deployed.awardItem(recipientAddress, 'https://erc721mock/item-id-2.json');

‎test/ping-pong/docker-compose.host.docker.internal.yml

+9-2
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,17 @@ services:
4646
# user-local:
4747
# environment:
4848
# BLOCKCHAIN_WS_HOST: host.docker.internal
49+
# BLOCKCHAIN_PORT: 8546
50+
# USER_ETHEREUM_SIGNING_KEY: abf4ed9f30bd1e4a290310d726c7bbdf39cd75a25eebd9a3a4874e10b4a0c4ce
4951

5052
user-local1:
5153
environment:
5254
BLOCKCHAIN_WS_HOST: host.docker.internal
5355
BLOCKCHAIN_PORT: 8546
54-
USER_ETHEREUM_SIGNING_KEY: abf4ed9f30bd1e4a290310d726c7bbdf39cd75a25eebd9a3a4874e10b4a0c4ce
55-
USER_ADDRESS: '0xdb080dC48961bC1D67a0A4151572eCb824cC76E8'
56+
USER_ETHEREUM_SIGNING_KEY: b0fa8745bd6e77a67ec6a27e701971d659937140cc3159d9f85210da3444eb45
57+
58+
user-local2:
59+
environment:
60+
BLOCKCHAIN_WS_HOST: host.docker.internal
61+
BLOCKCHAIN_PORT: 8546
62+
USER_ETHEREUM_SIGNING_KEY: d42905d0582c476c4b74757be6576ec323d715a0c7dcff231b6348b7ab0190eb

‎test/ping-pong/docker-compose.standalone.ganache.yml

+2
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ services:
1111
ganache-cli --defaultBalanceEther=0 --gasLimit=0xbebc20 --deterministic -i 4378921 -p 8546
1212
--account="0xabf4ed9f30bd1e4a290310d726c7bbdf39cd75a25eebd9a3a4874e10b4a0c4ce,10000000000000000000000"
1313
--account="0x645ac79fa9fd87dd1cf30bdca51d326bd501cd328d6dbc9f5f517c7da0dafa6f,10000000000000000000000"
14+
--account="0xb0fa8745bd6e77a67ec6a27e701971d659937140cc3159d9f85210da3444eb45,10000000000000000000000"
15+
--account="0xd42905d0582c476c4b74757be6576ec323d715a0c7dcff231b6348b7ab0190eb,10000000000000000000000"

‎test/ping-pong/docker-compose.yml

+72
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,25 @@ services:
6767
TIMBER_PORT: 80
6868
command: ['npm', 'run', 'dev']
6969

70+
# # Temporary container to deploy contracts and circuits and populate volumes
71+
# deployer:
72+
# image: ghcr.io/eyblockchain/nightfall3-deployer
73+
# volumes:
74+
# - type: volume
75+
# source: build
76+
# target: /app/build/
77+
# networks:
78+
# - nightfall_network
79+
# environment:
80+
# LOG_LEVEL: debug
81+
# # ETH_NETWORK sets the network selected by Truffle from truffle-config.js
82+
# # startup routines will wait for a blockchain client to be reachable on this network
83+
# ETH_NETWORK: blockchain1
84+
# BLOCKCHAIN_WS_HOST: blockchain1
85+
# BLOCKCHAIN_PORT: 8546
86+
# ZOKRATES_WORKER_HOST: worker
87+
# USE_STUBS: 'false'
88+
7089
# Temporary container to deploy contracts and circuits and populate volumes
7190
deployer:
7291
image: ghcr.io/eyblockchain/nightfall3-deployer:latest
@@ -77,6 +96,30 @@ services:
7796
- type: volume
7897
source: build
7998
target: /app/build/
99+
- type: bind
100+
source: ../../nightfall-deployer/contracts
101+
target: /app/contracts/
102+
- type: bind
103+
source: ../../nightfall-deployer/circuits
104+
target: /app/circuits/
105+
- type: bind
106+
source: ../../nightfall-deployer/src
107+
target: /app/src/
108+
- type: bind
109+
source: ../../common-files
110+
target: /common-files
111+
- type: bind
112+
source: ../../config/default.js
113+
target: /app/config/default.js
114+
- type: bind
115+
source: ../../nightfall-deployer/migrations
116+
target: /app/migrations
117+
- type: bind
118+
source: ../../nightfall-deployer/truffle-config.js
119+
target: /app/truffle-config.js
120+
- type: bind
121+
source: ../../nightfall-deployer/entrypoint.sh
122+
target: /app/entrypoint.sh
80123
networks:
81124
- pong_network
82125
environment:
@@ -148,6 +191,7 @@ services:
148191
# CLIENT_PORT: 80
149192
# BLOCKCHAIN_WS_HOST: blockchain1
150193
# BLOCKCHAIN_PORT: 8546
194+
# ZKP_MNEMONIC: tiger victory velvet tank ritual column horse conduct athlete position soul shaft
151195

152196
user-local1:
153197
build:
@@ -170,6 +214,34 @@ services:
170214
CLIENT_PORT: 80
171215
BLOCKCHAIN_WS_HOST: blockchain1
172216
BLOCKCHAIN_PORT: 8546
217+
RECIPIENT_PKD: 0x105651c0c5bb97582b3270e0f5a07ca81410ffd1920e86697efddaec03dccef8,0x1ac3b61ecba1448e697b23d37efe290fb86554b2f905aaca3a6df59805eca366
218+
ZKP_MNEMONIC: tone shadow woman critic glare utility brass scheme edge brisk enforce champion
219+
command: ['npm', 'run', 'dev']
220+
221+
user-local2:
222+
build:
223+
dockerfile: user-local2.Dockerfile
224+
context: ../../
225+
networks:
226+
- nightfall_network
227+
volumes:
228+
- type: bind
229+
source: ../../common-files
230+
target: /app/common-files
231+
- type: bind
232+
source: ./user-local2/src
233+
target: /app/test/ping-pong/user-local2/src
234+
environment:
235+
OPTIMIST_HOST: optimist
236+
OPTIMIST_WS_PORT: 8080
237+
OPTIMIST_HTTP_PORT: 80
238+
CLIENT_HOST: client
239+
CLIENT_PORT: 80
240+
BLOCKCHAIN_WS_HOST: blockchain1
241+
BLOCKCHAIN_PORT: 8546
242+
RECIPIENT_PKD: 0x193a37cd7973373aceae05d133f3d69ab6e7ef2f4321461173871ec7611244e2,0x27234a8721e73c9aa160154ee63d2470101fc5fd841221eeb675a91ec2d66e78
243+
ZKP_MNEMONIC:
244+
tiger victory velvet tank ritual column horse conduct athlete position soul shaft
173245
command: ['npm', 'run', 'dev']
174246

175247
volumes:

‎test/ping-pong/pong-apps

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ done
2525
# shut down cleanly in the event of a cntl-c etc. We don't want to leave containers running
2626
trap "exit 1" SIGHUP SIGINT SIGTERM
2727

28-
docker-compose -f docker-compose.yml $FILE up -d --remove-orphans proposer user-local1
29-
docker-compose logs -f proposer user-local1
28+
docker-compose -f docker-compose.yml $FILE up -d --remove-orphans proposer user-local1 user-local2
29+
docker-compose logs -f proposer user-local1 user-local2

‎test/ping-pong/user-local1/src/index.mjs

+22-47
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,30 @@ Module that runs up as a user
55
/* eslint-disable no-await-in-loop */
66
/* eslint no-constant-condition: ["error", { "checkLoops": false } ] */
77

8-
import logger from 'common-files/utils/logger.mjs';
8+
// import logger from 'common-files/utils/logger.mjs';
99
import config from 'config';
10-
import inquirer from 'inquirer';
1110
import Nf3 from '../../../../cli/lib/nf3.mjs';
12-
import waitForSufficientBalance from './utils.mjs';
11+
import { waitForSufficientBalance, retrieveL2Balance } from './utils.mjs';
1312

1413
const {
1514
zkpMnemonic,
16-
userEthereumSigningKey,
15+
user1EthereumSigningKey,
1716
optimistWsUrl,
1817
web3WsUrl,
1918
clientBaseUrl,
2019
optimistBaseUrl,
2120
TRANSACTIONS_PER_BLOCK,
2221
} = config;
2322

24-
/**
25-
Asks CLI questions
26-
*/
27-
async function promptUser() {
28-
return new Promise(resolve => {
29-
setTimeout(function () {
30-
resolve(true);
31-
}, 10000);
32-
resolve(
33-
inquirer.prompt([
34-
{
35-
name: 'isContinue',
36-
type: 'confirm',
37-
message: 'Continue the test',
38-
default: true,
39-
},
40-
]),
41-
);
42-
});
43-
}
23+
const TEST_LENGTH = 1;
24+
const recipientPkd = process.env.RECIPIENT_PKD.split(',');
4425

4526
/**
4627
Does the preliminary setup and starts listening on the websocket
4728
*/
4829
async function localTest() {
49-
logger.info('Starting local test...');
30+
// logger.info('Starting local test...');
31+
console.log('Starting local test...');
5032

5133
const tokenType = 'ERC20';
5234
const value = 1;
@@ -56,46 +38,39 @@ async function localTest() {
5638
optimistBaseUrl,
5739
optimistWsUrl,
5840
web3WsUrl,
59-
userEthereumSigningKey,
41+
user1EthereumSigningKey,
6042
);
6143

6244
await nf3.init(zkpMnemonic);
63-
if (await nf3.healthcheck('client')) logger.info('Healthcheck passed');
45+
if (await nf3.healthcheck('client')) console.log('Healthcheck passed');
6446
else throw new Error('Healthcheck failed');
6547

66-
const ercAddress = await nf3.getContractAddress('ERC20Mock'); // TODO use proper mock contracts
67-
const startBalance = await nf3.getLayer2Balances();
68-
48+
const ercAddress = await nf3.getContractAddress('ERC20Mock1');
49+
const startBalance = await retrieveL2Balance(nf3);
6950
console.log('HERE startBalance', startBalance);
7051

7152
// To start with create a block of deposits such that, we do a transfer in the next block
7253
for (let i = 0; i < TRANSACTIONS_PER_BLOCK; i++) {
7354
await nf3.deposit(ercAddress, tokenType, value, tokenId);
7455
}
7556

76-
while (true) {
77-
const { isContinue } = await promptUser();
78-
if (isContinue) {
79-
for (let j = 0; j < TRANSACTIONS_PER_BLOCK; j++) {
80-
// ensure there is sufficient balance for transfer.
81-
// this function relies on a prior deposit of
82-
// similar value being made
83-
await waitForSufficientBalance(nf3, value);
84-
await nf3.transfer(false, ercAddress, tokenType, value, tokenId, nf3.zkpKeys.pkd);
85-
await new Promise(resolve => setTimeout(resolve, 20000));
86-
}
87-
} else break;
57+
for (let i = 0; i < TEST_LENGTH; i++) {
58+
await waitForSufficientBalance(nf3, value);
59+
await nf3.transfer(false, ercAddress, tokenType, value, tokenId, recipientPkd);
60+
await nf3.deposit(ercAddress, tokenType, value, tokenId);
61+
await new Promise(resolve => setTimeout(resolve, 20000));
8862
}
8963

90-
const endBalance = await nf3.getLayer2Balances();
64+
const endBalance = await retrieveL2Balance(nf3);
9165
console.log('HERE endBalance', endBalance);
9266

93-
if (Object.keys(startBalance).length >= Object.keys(endBalance).length) {
94-
logger.warn('The test failed because the L2 balance has not increased');
67+
if (endBalance - startBalance === 2 * value) {
68+
console.log('Test passed');
69+
nf3.close();
70+
} else {
71+
console.log('The test failed because the L2 balance has not increased');
9572
process.exit(1);
9673
}
97-
logger.info('Test passed');
98-
nf3.close();
9974
}
10075

10176
localTest();

‎test/ping-pong/user-local1/src/utils.mjs

+22-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,28 @@
1+
/**
2+
function to retrieve balance of user because getLayer2Balances returns
3+
balances of all users
4+
*/
5+
export const retrieveL2Balance = async client => {
6+
const balances = await client.getLayer2Balances();
7+
// if there are no balances
8+
if (Object.keys(balances).length === 0) {
9+
return 0;
10+
}
11+
const clientBalances = balances[client.zkpKeys.compressedPkd];
12+
// if this user has no balance
13+
if (clientBalances === undefined || Object.keys(clientBalances).length === 0) {
14+
return 0;
15+
}
16+
// TODO return address by contract address
17+
const balance = clientBalances[Object.keys(clientBalances)[0]];
18+
return balance;
19+
};
20+
121
/**
222
function to wait until sufficient balance is achieved from
323
transactions
424
*/
5-
const waitForSufficientBalance = (client, value) => {
25+
export const waitForSufficientBalance = (client, value) => {
626
return new Promise(resolve => {
727
async function isSufficientBalance() {
828
const balances = await client.getLayer2Balances();
@@ -17,6 +37,7 @@ const waitForSufficientBalance = (client, value) => {
1737
await new Promise(resolving => setTimeout(resolving, 10000));
1838
isSufficientBalance();
1939
}
40+
console.log('HERE clientBalances', clientBalances);
2041
const balance = clientBalances[Object.keys(clientBalances)[0]];
2142
// if client has layer 2 balances and if it is equal to value required
2243
if (balance > value) {
@@ -31,5 +52,3 @@ const waitForSufficientBalance = (client, value) => {
3152
isSufficientBalance();
3253
});
3354
};
34-
35-
export default waitForSufficientBalance;

0 commit comments

Comments
 (0)