Skip to content

Commit

Permalink
harness: Update eth to work with geth 1.14 and up.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeGruffins committed Dec 19, 2024
1 parent 0030e49 commit bc85cd5
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 309 deletions.
23 changes: 2 additions & 21 deletions client/asset/eth/chaincfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"strings"

"decred.org/dcrdex/dex"
dexeth "decred.org/dcrdex/dex/networks/eth"
"github.com/ethereum/go-ethereum/common"
ethcore "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/eth/ethconfig"
Expand Down Expand Up @@ -103,10 +102,8 @@ func ETHConfig(net dex.Network) (c ethconfig.Config, err error) {
case dex.Testnet:
c.Genesis = ethcore.DefaultSepoliaGenesisBlock()
case dex.Simnet:
c.Genesis, err = readSimnetGenesisFile()
if err != nil {
return c, fmt.Errorf("readSimnetGenesisFile error: %w", err)
}
// Args are gasLimit, faucet address.
c.Genesis = ethcore.DeveloperGenesisBlock(30000000, nil)
default:
return c, fmt.Errorf("unknown network %d", net)

Expand All @@ -123,19 +120,3 @@ func ChainConfig(net dex.Network) (c *params.ChainConfig, err error) {
}
return cfg.Genesis.Config, nil
}

// readSimnetGenesisFile reads the simnet genesis file.
func readSimnetGenesisFile() (*ethcore.Genesis, error) {
dataDir, err := simnetDataDir()
if err != nil {
return nil, err
}

genesisFile := filepath.Join(dataDir, "genesis.json")
genesisCfg, err := dexeth.LoadGenesisFile(genesisFile)
if err != nil {
return nil, fmt.Errorf("error reading genesis file: %v", err)
}

return genesisCfg, nil
}
10 changes: 6 additions & 4 deletions dex/networks/erc20/contracts/TestToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// This is a simplified version of OpenZeppelin Contracts v4.4.0 (token/ERC20/ERC20.sol).

pragma solidity = 0.8.18;
pragma solidity = 0.8.28;

contract TestToken {
event Transfer(address indexed _from, address indexed _to, uint256 _value);
Expand Down Expand Up @@ -31,9 +31,11 @@ contract TestToken {
_decimals = dec;

_totalSupply = 44000000000000000000000;
_balances[0x18D65FB8d60c1199bb1Ad381bE47aA692b482605] = 11000000000000000000000; // alpha
_balances[0x4F8eF3892B65ED7fc356fF473a2eF2aE5EC27A06] = 11000000000000000000000; // beta
_balances[0xd12aB7cf72CCf1f3882eC99DDc53CD415635C3bE] = 11000000000000000000000; // delta
}

function setBalance(address addr, uint256 amt) public virtual returns (bool) {
_balances[addr] = amt;
return true;
}

/**
Expand Down
91 changes: 14 additions & 77 deletions dex/testing/eth/create-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,10 @@ set -ex
# The following are required script arguments.
TMUX_WIN_ID=$1
NAME=$2
NODE_PORT=$3
CHAIN_ADDRESS=$4
CHAIN_PASSWORD=$5
CHAIN_ADDRESS_JSON=$6
CHAIN_ADDRESS_JSON_FILE_NAME=$7
ADDRESS_JSON=$8
ADDRESS_JSON_FILE_NAME=$9
NODE_KEY=${10}
SYNC_MODE=${11}
AUTHRPC_PORT=${12}
HTTP_PORT=${13}
WS_PORT=${14}
WS_MODULES=${15}
AUTHRPC_PORT=${3}
HTTP_PORT=${4}
WS_PORT=${5}
WS_MODULES=${6}

GROUP_DIR="${NODES_ROOT}/${NAME}"
MINE_JS="${GROUP_DIR}/mine.js"
Expand All @@ -33,10 +24,8 @@ geth --datadir="${NODE_DIR}" \$*
EOF
chmod +x "${NODES_ROOT}/harness-ctl/${NAME}"

# Write mine script if CHAIN_ADDRESS is present.
if [ "${CHAIN_ADDRESS}" != "_" ]; then
# The mining script may end up mining more or less blocks than specified.
cat > "${NODES_ROOT}/harness-ctl/mine-${NAME}" <<EOF
# The mining script may end up mining more or less blocks than specified.
cat > "${NODES_ROOT}/harness-ctl/mine-${NAME}" <<EOF
#!/usr/bin/env bash
NUM=2
case \$1 in
Expand All @@ -60,17 +49,10 @@ if [ "${CHAIN_ADDRESS}" != "_" ]; then
EOF
chmod +x "${NODES_ROOT}/harness-ctl/mine-${NAME}"

# Write password file to unlock accounts later.
cat > "${GROUP_DIR}/password" <<EOF
$CHAIN_PASSWORD
EOF

fi

cat > "${NODE_DIR}/eth.conf" <<EOF
[Eth]
NetworkId = 42
SyncMode = "${SYNC_MODE}"
SyncMode = "snap"
[Node]
DataDir = "${NODE_DIR}"
Expand All @@ -80,67 +62,22 @@ AuthPort = ${AUTHRPC_PORT}
NoDiscovery = true
BootstrapNodes = []
BootstrapNodesV5 = []
ListenAddr = ":${NODE_PORT}"
NetRestrict = [ "127.0.0.1/8", "::1/128" ]
EOF

# Add etherbase if mining.
if [ "${CHAIN_ADDRESS}" != "_" ]; then
cat >> "${NODE_DIR}/eth.conf" <<EOF
[Eth.Miner]
Etherbase = "0x${CHAIN_ADDRESS}"
GasFloor = 30000000
GasCeil = 30000000
EOF
fi

# Create a tmux window.
tmux new-window -t "$TMUX_WIN_ID" -n "${NAME}" "${SHELL}"
tmux send-keys -t "$TMUX_WIN_ID" "set +o history" C-m
tmux send-keys -t "$TMUX_WIN_ID" "cd ${NODE_DIR}" C-m

# Create and wait for a node initiated with a predefined genesis json.
echo "Creating simnet ${NAME} node"
tmux send-keys -t "$TMUX_WIN_ID" "${NODES_ROOT}/harness-ctl/${NAME} init "\
"$GENESIS_JSON_FILE_LOCATION; tmux wait-for -S ${NAME}" C-m
tmux wait-for "${NAME}"

# Create two accounts. The first is used to mine blocks. The second contains
# funds.
if [ "${CHAIN_ADDRESS}" != "_" ]; then
echo "Creating account"
cat > "${NODE_DIR}/keystore/$CHAIN_ADDRESS_JSON_FILE_NAME" <<EOF
$CHAIN_ADDRESS_JSON
EOF
fi

cat > "${NODE_DIR}/keystore/$ADDRESS_JSON_FILE_NAME" <<EOF
$ADDRESS_JSON
EOF

# The node key lets us control the enode address value.
echo "Setting node key"
cat > "${NODE_DIR}/geth/nodekey" <<EOF
$NODE_KEY
EOF

echo "Starting simnet ${NAME} node"
if [ "${SYNC_MODE}" = "snap" ]; then
# Start the eth node with the chain account unlocked, listening restricted to
# localhost, and our custom configuration file.
tmux send-keys -t "$TMUX_WIN_ID" "${NODES_ROOT}/harness-ctl/${NAME} " \
"--config ${NODE_DIR}/eth.conf --unlock ${CHAIN_ADDRESS} " \
"--password ${GROUP_DIR}/password --light.serve 25 --datadir.ancient " \
"${NODE_DIR}/geth-ancient --verbosity 5 --vmdebug --http --http.port " \
"${HTTP_PORT} --ws --ws.port ${WS_PORT} --ws.api " \
"${WS_MODULES} --allow-insecure-unlock --rpc.enabledeprecatedpersonal " \
"2>&1 | tee ${NODE_DIR}/${NAME}.log" C-m

else
# Start the eth node listening restricted to localhost and our custom
# configuration file.
tmux send-keys -t "$TMUX_WIN_ID" "${NODES_ROOT}/harness-ctl/${NAME} --allow-insecure-unlock --rpc.enabledeprecatedpersonal " \
"--config ${NODE_DIR}/eth.conf --verbosity 5 ${HTTP_OPT} 2>&1 | tee " \
"${NODE_DIR}/${NAME}.log" C-m
fi
# Start the eth node with the chain account unlocked, listening restricted to
# localhost, and our custom configuration file.
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 --dev.period 5 2>&1 | tee ${NODE_DIR}/${NAME}.log" C-m
Loading

0 comments on commit bc85cd5

Please sign in to comment.