Skip to content

Commit

Permalink
Remove miner, dev.period
Browse files Browse the repository at this point in the history
  • Loading branch information
martonp committed Feb 5, 2025
1 parent 7588212 commit b6ba4cd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 43 deletions.
31 changes: 1 addition & 30 deletions dex/testing/eth/create-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,6 @@ geth --datadir="${NODE_DIR}" \$*
EOF
chmod +x "${NODES_ROOT}/harness-ctl/${NAME}"

# The mining script may end up mining more or less blocks than specified. It
# also sends a transaction which must be done in --dev mode.
cat > "${NODES_ROOT}/harness-ctl/mine-${NAME}" <<EOF
#!/usr/bin/env bash
NUM=1
case \$1 in
''|*[!0-9]*|[0-1]) ;;
*) NUM=\$1 ;;
esac
echo "Mining..."
for i in \$(seq 1 \$NUM)
do
BEFORE=\$("${NODES_ROOT}/harness-ctl/${NAME}" attach --exec 'eth.blockNumber')
"${NODES_ROOT}/harness-ctl/${NAME}" attach --exec 'eth.sendTransaction({from:eth.accounts[0],to:eth.accounts[0],value:1})' > /dev/null
while true
do
AFTER=\$("${NODES_ROOT}/harness-ctl/${NAME}" attach --exec 'eth.blockNumber')
sleep 1
DIFF=\$((AFTER-BEFORE))
if [ \$DIFF -gt 0 ]; then
break
fi
done
echo \$AFTER
"${NODES_ROOT}/harness-ctl/${NAME}" attach --exec 'eth.getHeaderByNumber('\$AFTER').hash'
done
EOF
chmod +x "${NODES_ROOT}/harness-ctl/mine-${NAME}"

cat > "${NODE_DIR}/eth.conf" <<EOF
[Eth]
SyncMode = "snap"
Expand All @@ -74,4 +45,4 @@ echo "Starting simnet ${NAME} node"
tmux send-keys -t "$TMUX_WIN_ID" "${NODES_ROOT}/harness-ctl/${NAME} " \
"--config ${NODE_DIR}/eth.conf --verbosity 5 --vmdebug --http --http.port " \
"${HTTP_PORT} --ws --ws.port ${WS_PORT} --ws.api ${WS_MODULES} " \
"--dev 2>&1 | tee ${NODE_DIR}/${NAME}.log" C-m
"--dev --dev.period 5 2>&1 | tee ${NODE_DIR}/${NAME}.log" C-m
33 changes: 20 additions & 13 deletions dex/testing/eth/harness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ echo "Starting simnet alpha node"
"$ALPHA_AUTHRPC_PORT" "$ALPHA_HTTP_PORT" "$ALPHA_WS_PORT" \
"$ALPHA_WS_MODULES"

sleep 1
sleep 10

SEND_AMT=5000000000000000000000
echo "Sending 5000 eth to testing."
Expand All @@ -130,13 +130,28 @@ MULTIBALANCE_CONTRACT_HASH=$("${NODES_ROOT}/harness-ctl/alpha" "attach --preload

mine_pending_txs() {
while true
do
do
TXSLEN=$("${NODES_ROOT}/harness-ctl/alpha" "attach --exec eth.pendingTransactions.length")
if [ "$TXSLEN" -eq 0 ]; then
break
fi
echo "Waiting for transactions to be mined."
"${NODES_ROOT}/harness-ctl/mine-alpha" "5"
echo "Waiting for transactions to be mined. TXSLEN: ${TXSLEN}"
sleep 1
done
}

get_block_hash() {
BLOCK_NUM=$1
while true
do
CURRENT_BLOCK=$("${NODES_ROOT}/harness-ctl/alpha" "attach --exec eth.blockNumber")
if [ "$CURRENT_BLOCK" -ge "$BLOCK_NUM" ]; then
BLOCK_HASH=$("${NODES_ROOT}/harness-ctl/alpha" "attach --exec eth.getHeaderByNumber(${BLOCK_NUM}).hash" | sed 's/"//g')
echo "$BLOCK_HASH"
break
fi
echo "Waiting for block $BLOCK_NUM. Current height: $CURRENT_BLOCK"
sleep 1
done
}

Expand Down Expand Up @@ -226,22 +241,14 @@ EOF
"${NODES_ROOT}/harness-ctl/alpha" "attach --preload ${NODES_ROOT}/harness-ctl/loadTestToken.js --exec setSenderBalance(\"${TEST_USDC_CONTRACT_ADDR}\",4400000000000)"
"${NODES_ROOT}/harness-ctl/alpha" "attach --preload ${NODES_ROOT}/harness-ctl/loadTestToken.js --exec setSenderBalance(\"${TEST_USDT_CONTRACT_ADDR}\",4400000000000)"

# Mine to block 10 to take the hash for tests.
"${NODES_ROOT}/harness-ctl/mine-alpha" "4"

cd "${NODES_ROOT}/harness-ctl"

TEST_BLOCK10_HASH=$("${NODES_ROOT}/harness-ctl/alpha" "attach --exec eth.getHeaderByNumber(10).hash" | sed 's/"//g')
TEST_BLOCK10_HASH=$(get_block_hash 10)
echo "ETH block 10 hash to use in tests is ${TEST_BLOCK10_HASH}. Saving to ${NODES_ROOT}/test_block10_hash.txt"
cat > "${NODES_ROOT}/test_block10_hash.txt" <<EOF
${TEST_BLOCK10_HASH}
EOF

# Miner
tmux new-window -t $SESSION:5 -n "miner" $SHELL
tmux send-keys -t $SESSION:5 "cd ${NODES_ROOT}/harness-ctl" C-m
tmux send-keys -t $SESSION:5 "watch -n 15 ./mine-alpha 1" C-m

# Reenable history and attach to the control session.
tmux select-window -t $SESSION:0
tmux send-keys -t $SESSION:0 "set -o history" C-m
Expand Down

0 comments on commit b6ba4cd

Please sign in to comment.