Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait one block confirmation in tests #1438

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/lib/nf3.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1597,7 +1597,7 @@ class Nf3 {

this.web3 = new Web3(provider);
this.web3.eth.transactionBlockTimeout = 2000;
this.web3.eth.transactionConfirmationBlocks = 12;
this.web3.eth.transactionConfirmationBlocks = process.env.CONFIRMATIONS || 12;
if (typeof window !== 'undefined') {
if (window.ethereum && this.ethereumSigningKey === '') {
this.web3 = new Web3(window.ethereum);
Expand Down
2 changes: 2 additions & 0 deletions docker/docker-compose.adversary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ services:
source: ../config/default.js
target: /app/config/default.js
environment:
CONFIRMATIONS: ${CONFIRMATIONS}
ENVIRONMENT: ${ENVIRONMENT:-localhost}
WEBSOCKET_PORT: ${WEBSOCKET_PORT:-8080}
BLOCKCHAIN_WS_HOST: ${BLOCKCHAIN_WS_HOST:-blockchain}
Expand Down Expand Up @@ -70,6 +71,7 @@ services:
source: ../config/default.js
target: /app/config/default.js
environment:
CONFIRMATIONS: ${CONFIRMATIONS}
ENVIRONMENT: ${ENVIRONMENT:-localhost}
LOG_LEVEL: ${LOG_LEVEL:-debug}
LOG_HTTP_PAYLOAD_ENABLED: ${LOG_HTTP_PAYLOAD_ENABLED:-true}
Expand Down
4 changes: 3 additions & 1 deletion docker/docker-compose.apps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ services:
BLOCKCHAIN_PORT: ${BLOCKCHAIN_PORT:-8546}
CLIENT_HOST: ${CLIENT_HOST:-client}
CLIENT_PORT: ${CLIENT_PORT:-8080}
CONFIRMATIONS: ${CONFIRMATIONS}
ENABLE_QUEUE: ${ENABLE_QUEUE:-1}
ENVIRONMENT: ${ENVIRONMENT:-localhost}
LOG_LEVEL: ${LOG_LEVEL:-debug}
Expand All @@ -38,7 +39,7 @@ services:
- type: bind
source: ../apps/proposer/src
target: /app/app/src

challenger:
build:
dockerfile: docker/challenger.Dockerfile
Expand All @@ -50,6 +51,7 @@ services:
extra_hosts:
- 'host.docker.internal:host-gateway'
environment:
CONFIRMATIONS: ${CONFIRMATIONS}
ENVIRONMENT: ${ENVIRONMENT:-localhost}
LOG_LEVEL: ${LOG_LEVEL:-debug}
LOG_HTTP_PAYLOAD_ENABLED: ${LOG_HTTP_PAYLOAD_ENABLED:-true}
Expand Down
1 change: 1 addition & 0 deletions docker/docker-compose.client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ services:
- worker_1
- mongodb_client_1
environment:
CONFIRMATIONS: ${CONFIRMATIONS}
ENVIRONMENT: ${ENVIRONMENT:-localhost}
LOG_LEVEL: ${LOG_LEVEL:-debug}
LOG_HTTP_PAYLOAD_ENABLED: ${LOG_HTTP_PAYLOAD_ENABLED:-true}
Expand Down
2 changes: 2 additions & 0 deletions docker/docker-compose.deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ services:
AUTOSTART_RETRIES: ${AUTOSTART_RETRIES:-600}
BLOCKCHAIN_URL: ${BLOCKCHAIN_URL:?BLOCKCHAIN_URL-cannot-be-blank}
CIRCOM_WORKER_HOST: ${CIRCOM_WORKER_HOST:-worker}
CONFIRMATIONS: ${CONFIRMATIONS}
ENDPOINTS_WHITELISTED: ${ENDPOINTS_WHITELISTED}
ENABLE_QUEUE: ${ENABLE_QUEUE:-1}
ENVIRONMENT: ${ENVIRONMENT:?ENVIRONMENT-cannot-be-blank}
Expand Down Expand Up @@ -132,6 +133,7 @@ services:
environment:
AUTOSTART_RETRIES: ${AUTOSTART_RETRIES:-600}
BLOCKCHAIN_URL: ${BLOCKCHAIN_URL:?BLOCKCHAIN_URL-cannot-be-blank}
CONFIRMATIONS: ${CONFIRMATIONS}
ENVIRONMENT: ${ENVIRONMENT:?ENVIRONMENT-cannot-be-blank}
HASH_TYPE: poseidon
IS_CHALLENGER: 'false'
Expand Down
7 changes: 7 additions & 0 deletions docker/docker-compose.multiproposer-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ services:
- optimist_mongodb_1
- client_rabbitmq_1
environment:
CONFIRMATIONS: ${CONFIRMATIONS}
ENVIRONMENT: ${ENVIRONMENT:-localhost}
ETH_NETWORK: ${ETH_NETWORK:-blockchain}
LOG_LEVEL: ${LOG_LEVEL:-debug}
Expand Down Expand Up @@ -164,6 +165,7 @@ services:
- optimist_mongodb_2
- client_rabbitmq_2
environment:
CONFIRMATIONS: ${CONFIRMATIONS}
ENVIRONMENT: ${ENVIRONMENT:-localhost}
LOG_LEVEL: ${LOG_LEVEL:-debug}
LOG_HTTP_PAYLOAD_ENABLED: ${LOG_HTTP_PAYLOAD_ENABLED:-true}
Expand Down Expand Up @@ -202,6 +204,7 @@ services:
source: build
target: /app/build/
environment:
CONFIRMATIONS: ${CONFIRMATIONS}
ENVIRONMENT: ${ENVIRONMENT:-localhost}
WEBSOCKET_PORT: ${WEBSOCKET_PORT:-8080}
BLOCKCHAIN_WS_HOST: ${BLOCKCHAIN_WS_HOST:-blockchain}
Expand Down Expand Up @@ -245,6 +248,7 @@ services:
source: ../config/default.js
target: /app/config/default.js
environment:
CONFIRMATIONS: ${CONFIRMATIONS}
ENVIRONMENT: ${ENVIRONMENT:-localhost}
WEBSOCKET_PORT: ${WEBSOCKET_PORT:-8080}
BLOCKCHAIN_WS_HOST: ${BLOCKCHAIN_WS_HOST:-blockchain}
Expand Down Expand Up @@ -304,6 +308,7 @@ services:
environment:
BLOCKCHAIN_WS_HOST: ${BLOCKCHAIN_WS_HOST:-blockchain}
BLOCKCHAIN_PORT: 8546
CONFIRMATIONS: ${CONFIRMATIONS}
ENABLE_QUEUE: 1
OPTIMIST_HOST: proposer_optimist_1
OPTIMIST_PORT: 80
Expand Down Expand Up @@ -336,6 +341,7 @@ services:
environment:
BLOCKCHAIN_WS_HOST: ${BLOCKCHAIN_WS_HOST:-blockchain}
BLOCKCHAIN_PORT: 8546
CONFIRMATIONS: ${CONFIRMATIONS}
ENABLE_QUEUE: 1
OPTIMIST_HOST: proposer_optimist_2
OPTIMIST_PORT: 80
Expand Down Expand Up @@ -368,6 +374,7 @@ services:
environment:
BLOCKCHAIN_WS_HOST: ${BLOCKCHAIN_WS_HOST:-blockchain}
BLOCKCHAIN_PORT: 8546
CONFIRMATIONS: ${CONFIRMATIONS}
ENABLE_QUEUE: 1
OPTIMIST_HOST: proposer_optimist_1
OPTIMIST_PORT: 80
Expand Down
1 change: 1 addition & 0 deletions docker/docker-compose.optimist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ services:
source: build_optimist_1
target: /app/build/
environment:
CONFIRMATIONS: ${CONFIRMATIONS}
ENVIRONMENT: ${ENVIRONMENT:-localhost}
WEBSOCKET_PORT: 8080
BLOCKCHAIN_WS_HOST: ${BLOCKCHAIN_WS_HOST:-blockchain}
Expand Down
10 changes: 6 additions & 4 deletions docker/docker-compose.polygon-edge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ services:
BLOCKCHAIN_WS_HOST: host.docker.internal
BLOCKCHAIN_PORT: 10002
BLOCKCHAIN_PATH: /ws
CONFIRMATIONS: ${CONFIRMATIONS}
USE_EXTERNAL_NODE: 'true'
AUTOSTART_RETRIES: 600
FROM_ADDRESS: "0xfeEDA3882Dd44aeb394caEEf941386E7ed88e0E0"
FROM_ADDRESS: '0xfeEDA3882Dd44aeb394caEEf941386E7ed88e0E0'
ETH_NETWORK: staging_edge

deployer:
Expand All @@ -16,18 +17,19 @@ services:
BLOCKCHAIN_PORT: 10002
BLOCKCHAIN_PATH: /ws
USE_EXTERNAL_NODE: 'true'
FROM_ADDRESS: "0xfeEDA3882Dd44aeb394caEEf941386E7ed88e0E0"
ETH_PRIVATE_KEY: "0x4775af73d6dc84a0ae76f8726bda4b9ecf187c377229cb39e1afa7a18236a69d"
FROM_ADDRESS: '0xfeEDA3882Dd44aeb394caEEf941386E7ed88e0E0'
ETH_PRIVATE_KEY: '0x4775af73d6dc84a0ae76f8726bda4b9ecf187c377229cb39e1afa7a18236a69d'
ETH_NETWORK: staging_edge

optimist:
environment:
BLOCKCHAIN_WS_HOST: host.docker.internal
BLOCKCHAIN_PORT: 10002
BLOCKCHAIN_PATH: /ws
CONFIRMATIONS: ${CONFIRMATIONS}
USE_EXTERNAL_NODE: 'true'
AUTOSTART_RETRIES: 600
FROM_ADDRESS: "0xfeEDA3882Dd44aeb394caEEf941386E7ed88e0E0"
FROM_ADDRESS: '0xfeEDA3882Dd44aeb394caEEf941386E7ed88e0E0'
ETH_NETWORK: staging_edge

administrator:
Expand Down
6 changes: 4 additions & 2 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ services:
environment:
AUTHENTICATION_KEY: ${AUTHENTICATION_KEY}
AUTOSTART_RETRIES: ${AUTOSTART_RETRIES:-600}
BLOCKCHAIN_URL: ${BLOCKCHAIN_URL}
BLOCKCHAIN_URL: ${BLOCKCHAIN_URL}
BLOCKCHAIN_WS_HOST: ${BLOCKCHAIN_WS_HOST:-blockchain}
BLOCKCHAIN_PORT: ${BLOCKCHAIN_PORT:-8546}
CIRCOM_WORKER_HOST: ${CIRCOM_WORKER_HOST:-worker}
CONFIRMATIONS: ${CONFIRMATIONS}
ENDPOINTS_WHITELISTED: ${ENDPOINTS_WHITELISTED}
ENABLE_QUEUE: ${ENABLE_QUEUE:-1}
ENVIRONMENT: ${ENVIRONMENT:-localhost}
Expand Down Expand Up @@ -104,7 +105,7 @@ services:
USDC_RESTRICT: ${USDC_RESTRICT}
UPGRADE: ${UPGRADE_CONTRACTS}
WHITELISTING: ${WHITELISTING}
WETH_RESTRICT: ${WETH_RESTRICT}
WETH_RESTRICT: ${WETH_RESTRICT}

hosted-utils-api-server:
build:
Expand Down Expand Up @@ -142,6 +143,7 @@ services:
BLOCKCHAIN_URL: ${BLOCKCHAIN_URL}
BLOCKCHAIN_WS_HOST: ${BLOCKCHAIN_WS_HOST:-blockchain}
BLOCKCHAIN_PORT: ${BLOCKCHAIN_PORT:-8546}
CONFIRMATIONS: ${CONFIRMATIONS}
ENVIRONMENT: ${ENVIRONMENT:-localhost}
HASH_TYPE: poseidon
IS_CHALLENGER: ${IS_CHALLENGER:-true}
Expand Down
8 changes: 4 additions & 4 deletions test/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import mongo from 'common-files/utils/mongo.mjs';
import { rand } from 'common-files/utils/crypto/crypto-random.mjs';

const { expect } = chai;
const { WEB3_PROVIDER_OPTIONS } = config;
const { WEB3_PROVIDER_OPTIONS, CONFIRMATIONS } = config;

const ENVIRONMENT = config.ENVIRONMENTS[config.ENVIRONMENT];

Expand Down Expand Up @@ -145,13 +145,13 @@ export class Web3Client {
// receipt = await web3.eth.sendSignedTransaction(signed.rawTransaction);
receipt = await this.web3.eth.sendSignedTransaction(signed.rawTransaction);
// the confirmations Promivent doesn't seem to terminate in Ganache, so we'll
// just count 12 blocks before returning. TODO this won't handle a chain reorg.
// just count <CONFIRMATIONS> blocks before returning. TODO this won't handle a chain reorg.
// console.log('waiting for twelve confirmations of transaction');
const startBlock = await this.web3.eth.getBlock('latest');
await new Promise(resolve => {
const id = setInterval(async () => {
const block = await this.web3.eth.getBlock('latest');
if (block.number - startBlock.number > 12) {
if (block.number - startBlock.number > CONFIRMATIONS) {
clearInterval(id);
resolve();
}
Expand Down Expand Up @@ -237,7 +237,7 @@ export class Web3Client {

await this.subscribeTo('newBlockHeaders', blockHeaders);

while (blockHeaders.length < 12) {
while (blockHeaders.length < CONFIRMATIONS) {
await waitForTimeout(3000);
}

Expand Down