Skip to content

Commit 06d301a

Browse files
committed
harness: Update eth to work with geth 1.14 and up.
1 parent 7b5430b commit 06d301a

12 files changed

Lines changed: 122 additions & 402 deletions

File tree

client/asset/eth/chaincfg.go

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"strings"
1212

1313
"decred.org/dcrdex/dex"
14-
dexeth "decred.org/dcrdex/dex/networks/eth"
1514
"github.com/ethereum/go-ethereum/common"
1615
ethcore "github.com/ethereum/go-ethereum/core"
1716
"github.com/ethereum/go-ethereum/eth/ethconfig"
@@ -103,10 +102,8 @@ func ETHConfig(net dex.Network) (c ethconfig.Config, err error) {
103102
case dex.Testnet:
104103
c.Genesis = ethcore.DefaultSepoliaGenesisBlock()
105104
case dex.Simnet:
106-
c.Genesis, err = readSimnetGenesisFile()
107-
if err != nil {
108-
return c, fmt.Errorf("readSimnetGenesisFile error: %w", err)
109-
}
105+
// Args are gasLimit, faucet address.
106+
c.Genesis = ethcore.DeveloperGenesisBlock(30000000, nil)
110107
default:
111108
return c, fmt.Errorf("unknown network %d", net)
112109

@@ -123,19 +120,3 @@ func ChainConfig(net dex.Network) (c *params.ChainConfig, err error) {
123120
}
124121
return cfg.Genesis.Config, nil
125122
}
126-
127-
// readSimnetGenesisFile reads the simnet genesis file.
128-
func readSimnetGenesisFile() (*ethcore.Genesis, error) {
129-
dataDir, err := simnetDataDir()
130-
if err != nil {
131-
return nil, err
132-
}
133-
134-
genesisFile := filepath.Join(dataDir, "genesis.json")
135-
genesisCfg, err := dexeth.LoadGenesisFile(genesisFile)
136-
if err != nil {
137-
return nil, fmt.Errorf("error reading genesis file: %v", err)
138-
}
139-
140-
return genesisCfg, nil
141-
}

client/asset/eth/eth_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4927,11 +4927,11 @@ func testMaxSwapRedeemLots(t *testing.T, assetID uint32) {
49274927
t.Fatalf("expected 63 for max redemptions but got %d", info.MaxRedeemsInTx)
49284928
}
49294929
} else {
4930-
if info.MaxSwapsInTx != 20 {
4931-
t.Fatalf("expected 20 for max swaps but got %d", info.MaxSwapsInTx)
4930+
if info.MaxSwapsInTx != 24 {
4931+
t.Fatalf("expected 24 for max swaps but got %d", info.MaxSwapsInTx)
49324932
}
4933-
if info.MaxRedeemsInTx != 45 {
4934-
t.Fatalf("expected 45 for max redemptions but got %d", info.MaxRedeemsInTx)
4933+
if info.MaxRedeemsInTx != 55 {
4934+
t.Fatalf("expected 55 for max redemptions but got %d", info.MaxRedeemsInTx)
49354935
}
49364936
}
49374937
}

client/asset/eth/nodeclient_harness_test.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ var (
7272
testnetParticipantWalletDir string
7373

7474
alphaNodeDir = filepath.Join(homeDir, "dextest", "eth", "alpha", "node")
75-
alphaIPCFile = filepath.Join(alphaNodeDir, "geth.ipc")
76-
betaNodeDir = filepath.Join(homeDir, "dextest", "eth", "beta", "node")
77-
betaIPCFile = filepath.Join(betaNodeDir, "geth.ipc")
75+
alphaWSEndpoint = "ws://127.0.0.1:38557"
7876
ctx context.Context
7977
tLogger = dex.StdOutLogger("ETHTEST", dex.LevelWarn)
8078
simnetWalletSeed = "0812f5244004217452059e2fd11603a511b5d0870ead753df76c966ce3c71531"
@@ -208,23 +206,23 @@ func prepareRPCClient(name, dataDir string, providers []string, net dex.Network)
208206
return c, c.creds.acct, nil
209207
}
210208

211-
func rpcEndpoints(net dex.Network) ([]string, []string) {
209+
func rpcEndpoints(net dex.Network) []string {
212210
if net == dex.Testnet {
213-
return rpcProviders, rpcProviders
211+
return rpcProviders
214212
}
215-
return []string{alphaIPCFile}, []string{betaIPCFile}
213+
return []string{alphaWSEndpoint}
216214
}
217215

218216
func prepareTestRPCClients(initiatorDir, participantDir string, net dex.Network) (err error) {
219-
initiatorEndpoints, participantEndpoints := rpcEndpoints(net)
217+
endpoints := rpcEndpoints(net)
220218

221-
ethClient, simnetAcct, err = prepareRPCClient("initiator", initiatorDir, initiatorEndpoints, net)
219+
ethClient, simnetAcct, err = prepareRPCClient("initiator", initiatorDir, endpoints, net)
222220
if err != nil {
223221
return err
224222
}
225223
fmt.Println("initiator address is", ethClient.address())
226224

227-
participantEthClient, participantAcct, err = prepareRPCClient("participant", participantDir, participantEndpoints, net)
225+
participantEthClient, participantAcct, err = prepareRPCClient("participant", participantDir, endpoints, net)
228226
if err != nil {
229227
ethClient.shutdown()
230228
return err
@@ -258,14 +256,14 @@ func runSimnet(m *testing.M) (int, error) {
258256

259257
ethSwapContractAddr = dexeth.ContractAddresses[contractVer][dex.Simnet]
260258

261-
initiatorProviders, participantProviders := rpcEndpoints(dex.Simnet)
259+
providers := rpcEndpoints(dex.Simnet)
262260

263-
err = setupWallet(simnetWalletDir, simnetWalletSeed, "localhost:30355", initiatorProviders, dex.Simnet)
261+
err = setupWallet(simnetWalletDir, simnetWalletSeed, "localhost:30355", providers, dex.Simnet)
264262
if err != nil {
265263
return 1, err
266264
}
267265

268-
err = setupWallet(participantWalletDir, participantWalletSeed, "localhost:30356", participantProviders, dex.Simnet)
266+
err = setupWallet(participantWalletDir, participantWalletSeed, "localhost:30356", providers, dex.Simnet)
269267
if err != nil {
270268
return 1, err
271269
}
@@ -390,13 +388,13 @@ func runTestnet(m *testing.M) (int, error) {
390388
ethSwapContractAddr = dexeth.ContractAddresses[contractVer][dex.Testnet]
391389
fmt.Printf("ETH swap contract address is %v\n", ethSwapContractAddr)
392390

393-
initiatorRPC, participantRPC := rpcEndpoints(dex.Testnet)
391+
rpc := rpcEndpoints(dex.Testnet)
394392

395-
err = setupWallet(testnetWalletDir, testnetWalletSeed, "localhost:30355", initiatorRPC, dex.Testnet)
393+
err = setupWallet(testnetWalletDir, testnetWalletSeed, "localhost:30355", rpc, dex.Testnet)
396394
if err != nil {
397395
return 1, err
398396
}
399-
err = setupWallet(testnetParticipantWalletDir, testnetParticipantWalletSeed, "localhost:30356", participantRPC, dex.Testnet)
397+
err = setupWallet(testnetParticipantWalletDir, testnetParticipantWalletSeed, "localhost:30356", rpc, dex.Testnet)
400398
if err != nil {
401399
return 1, err
402400
}

dex/networks/eth/params.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ const (
3232
// These are the chain IDs of the various Ethereum network supported.
3333
const (
3434
MainnetChainID = 1
35-
TestnetChainID = 5 // Görli
36-
SimnetChainID = 42 // see dex/testing/eth/harness.sh
35+
TestnetChainID = 11155111 // Sepolia
36+
SimnetChainID = 1337 // see dex/testing/eth/harness.sh
3737
)
3838

3939
var (

dex/networks/eth/tokens.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,13 @@ var Tokens = map[uint32]*Token{
168168
0: {
169169
Address: common.Address{},
170170
Gas: Gases{
171-
Swap: 242_000,
172-
SwapAdd: 146_400,
173-
Redeem: 109_000,
174-
RedeemAdd: 31_600,
175-
Refund: 77_000,
176-
Approve: 78_400,
177-
Transfer: 85_100,
171+
Swap: 203_317,
172+
SwapAdd: 146_368,
173+
Redeem: 90_775,
174+
RedeemAdd: 41_117,
175+
Refund: 65_448,
176+
Approve: 32_303,
177+
Transfer: 66_953,
178178
}},
179179
},
180180
},
@@ -266,13 +266,13 @@ var Tokens = map[uint32]*Token{
266266
0: {
267267
Address: common.Address{},
268268
Gas: Gases{
269-
Swap: 242_000,
270-
SwapAdd: 146_400,
271-
Redeem: 109_000,
272-
RedeemAdd: 31_600,
273-
Refund: 77_000,
274-
Approve: 78_400,
275-
Transfer: 85_100,
269+
Swap: 203_317,
270+
SwapAdd: 146_368,
271+
Redeem: 90_775,
272+
RedeemAdd: 41_117,
273+
Refund: 65_448,
274+
Approve: 32_303,
275+
Transfer: 66_953,
276276
}},
277277
},
278278
},

dex/testing/eth/README.md

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,32 @@ sandboxed environment for testing dex swap transactions.
66
## Dependencies
77

88
The harness depends on [geth](https://github.com/ethereum/go-ethereum/tree/master/cmd/geth)
9-
to run. geth v1.13.4+ is recommended.
9+
to run. geth v1.14.12+ is recommended.
1010

1111
It also requires tmux and bc.
1212

1313
## Using
1414

1515
You must have `geth` in `PATH` to use the harness.
1616

17-
The harness script will create four connected private nodes. Two, alpha and
18-
beta, have mining abilities and pre-funded addresses with syncmode set to
19-
"fast". They are meant to be used with server functions. Two more, gamma and
20-
delta, are "light" nodes without mining abilites and with addresses that have
21-
been sent funds. They are intenended to be used with client functions.
17+
The harness script will create one private node, alpha, running in --dev mode.
18+
alpha has scripts to send coins and tokens to any address. Blocks are mined
19+
every 10 seconds in the mining tmux session.
2220

2321
## Harness control scripts
2422

2523
The `./harness.sh` script will drop you into a tmux window in a directory
2624
called `harness-ctl`. Inside of this directory are a number of scripts to
2725
allow you to perform RPC calls against each wallet.
2826

29-
`./alpha`, `./beta`, `./gamma`, and `./delta` are just `geth` configured for
30-
their respective data directories.
27+
`./alpha` is just `geth` configured for its data directory.
3128

3229
Try `./alpha attach`, for example. This will put you in an interactive console
3330
with the alpha node.
3431

3532
`./quit` shuts down the nodes and closes the tmux session.
3633

37-
`./mine-alpha n` and `./mine-beta n` will mine n blocks on the respective node.
34+
`./mine-alpha n` will mine about n blocks. It is not precise.
3835

3936
## Dev Stuff
4037

@@ -46,4 +43,4 @@ change to the alpha node window. Examining the node output to look for errors
4643
is usually a good first debugging step.
4744

4845
If you encouter a problem, the harness can be killed from another terminal with
49-
`tmux kill-session -t eth-harness`.
46+
`tmux kill-session -t eth-harness`. Nodes can be killed with `sudo pkill -9 geth`.

0 commit comments

Comments
 (0)