Skip to content

Commit 6719ee9

Browse files
committed
run TestConfig without -race
1 parent acc4642 commit 6719ee9

File tree

5 files changed

+70
-66
lines changed

5 files changed

+70
-66
lines changed

.github/workflows/seth-test.yml

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,41 +12,61 @@ jobs:
1212
- regex: TestSmoke
1313
network-type: Geth
1414
url: "ws://localhost:8546"
15+
extra_flags: "-race"
1516
- regex: TestSmoke
1617
network-type: Anvil
1718
url: "http://localhost:8545"
19+
extra_flags: "-race"
1820
- regex: TestAPI
1921
network-type: Geth
2022
url: "ws://localhost:8546"
23+
extra_flags: "-race"
2124
- regex: TestAPI
2225
network-type: Anvil
2326
url: "http://localhost:8545"
27+
extra_flags: "-race"
2428
- regex: TestTrace
2529
network-type: Geth
2630
url: "ws://localhost:8546"
31+
extra_flags: "-race"
2732
- regex: TestTrace
2833
network-type: Anvil
2934
url: "http://localhost:8545"
35+
extra_flags: "-race"
3036
- regex: TestCLI
3137
network-type: Geth
3238
url: "ws://localhost:8546"
39+
extra_flags: "-race"
3340
- regex: TestCLI
3441
network-type: Anvil
3542
url: "http://localhost:8545"
43+
extra_flags: "-race"
3644
# TODO: wasn't stable before, fix if possible
3745
# - regex: TestGasBumping
3846
# network-type: Geth
3947
# url: "ws://localhost:8546"
4048
# - regex: TestGasBumping
4149
# network-type: Anvil
4250
# url: "http://localhost:8545"
43-
- regex: "'TestContractMap|TestGasEstimator|TestRPCHealthCheck|TestUtil|TestContract|TestConfig'"
51+
# Some test config tests use Simualted Backend, which is not has data races...
52+
- regex: "'TestConfig'"
4453
network-type: Geth
4554
url: "ws://localhost:8546"
55+
extra_flags: "''"
4656
# TODO: still expects Geth WS URL for some reason
47-
# - regex: "'TestContractMap|TestGasEstimator|TestRPCHealthCheck|TestUtil|TestContract|TestConfig'"
48-
# network-type: Anvil
49-
# url: "http://localhost:8545"
57+
- regex: "'TestConfig'"
58+
network-type: Anvil
59+
url: "http://localhost:8545"
60+
extra_flags: "''"
61+
- regex: "'TestContractMap|TestGasEstimator|TestRPCHealthCheck|TestUtil|TestContract'"
62+
network-type: Geth
63+
url: "ws://localhost:8546"
64+
extra_flags: "-race"
65+
# TODO: still expects Geth WS URL for some reason
66+
- regex: "'TestContractMap|TestGasEstimator|TestRPCHealthCheck|TestUtil|TestContract'"
67+
network-type: Anvil
68+
url: "http://localhost:8545"
69+
extra_flags: "-race"
5070
defaults:
5171
run:
5272
working-directory: seth
@@ -86,4 +106,4 @@ jobs:
86106
just-version: '1.39.0'
87107
- name: Run tests
88108
run: |
89-
devbox run -- just seth-test ${{ matrix.test.network-type }} ${{ matrix.test.url }} ${{ matrix.test.regex }}
109+
devbox run -- just seth-test ${{ matrix.test.network-type }} ${{ matrix.test.url }} ${{ matrix.test.regex }} ${{ matrix.test.extra_flags}}

justfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ seth-Geth:
120120
geth --graphql --http --http.api admin,debug,web3,eth,txpool,personal,miner,net --http.corsdomain "*" --ws --ws.api admin,debug,web3,eth,txpool,personal,miner,net --ws.origins "*" --mine --miner.etherbase 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --unlock f39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --allow-insecure-unlock --datadir ./geth_data --password geth_data/password.txt --nodiscover --vmdebug --networkid 1337 > /dev/null 2>&1 &
121121

122122
# Seth: run Seth tests, example: just seth-test Anvil http://localhost:8545 "TestAPI"
123-
seth-test network url test_regex:
123+
seth-test network url test_regex extra_flags:
124124
@just seth-{{network}}
125-
cd seth && SETH_URL={{url}} SETH_NETWORK={{network}} SETH_ROOT_PRIVATE_KEY=ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 go test -v -race `go list ./... | grep -v examples` -run "{{test_regex}}" || pkill -f {{network}}
125+
cd seth && SETH_URL={{url}} SETH_NETWORK={{network}} SETH_ROOT_PRIVATE_KEY=ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 go test -v "{{extra_flags}}" `go list ./... | grep -v examples` -run "{{test_regex}}" || pkill -f {{network}}
126126

127127
# Run pre-commit hooks, build, lint, tidy, check typos
128128
pre-commit:

seth/client_builder_test.go

Lines changed: 23 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"crypto/ecdsa"
55
"math/big"
66
"os"
7+
"strings"
78
"testing"
89
"time"
910

@@ -26,10 +27,7 @@ import (
2627
func TestConfig_MinimalBuilder(t *testing.T) {
2728
builder := seth.NewClientBuilder()
2829

29-
url, err := getRpc()
30-
require.NoError(t, err, "failed to get rpc url")
31-
32-
client, err := builder.WithRpcUrl(url).
30+
client, err := builder.WithRpcUrl(os.Getenv("SETH_URL")).
3331
WithPrivateKeys([]string{"ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"}).
3432
Build()
3533
require.NoError(t, err, "failed to build client")
@@ -43,18 +41,6 @@ func TestConfig_MinimalBuilder(t *testing.T) {
4341
require.NoError(t, err, "failed to deploy LINK contract")
4442
}
4543

46-
func getRpc() (string, error) {
47-
if os.Getenv("SETH_NETWORK") == "" {
48-
return "", errors.New("SETH_NETWORK is not set")
49-
}
50-
url := "ws://localhost:8546"
51-
if os.Getenv("SETH_NETWORK") == "anvil" {
52-
url = "ws://localhost:8545"
53-
}
54-
55-
return url, nil
56-
}
57-
5844
func TestConfig_MaximalBuilder(t *testing.T) {
5945
builder := seth.NewClientBuilder()
6046

@@ -73,9 +59,6 @@ func TestConfig_MaximalBuilder(t *testing.T) {
7359
GasPriceEstimationAttemptCount: seth.DefaultGasPriceEstimationsAttemptCount,
7460
}
7561

76-
url, err := getRpc()
77-
require.NoError(t, err, "failed to get rpc url")
78-
7962
secondNetwork := &seth.Network{
8063
Name: "Second",
8164
EIP1559DynamicFees: true,
@@ -89,7 +72,7 @@ func TestConfig_MaximalBuilder(t *testing.T) {
8972
GasFeeCap: seth.DefaultGasFeeCap,
9073
GasTipCap: seth.DefaultGasTipCap,
9174
GasPriceEstimationAttemptCount: seth.DefaultGasPriceEstimationsAttemptCount,
92-
URLs: []string{url},
75+
URLs: []string{os.Getenv("SETH_URL")},
9376
}
9477

9578
client, err := builder.
@@ -131,6 +114,9 @@ func TestConfig_MaximalBuilder(t *testing.T) {
131114
}
132115

133116
func TestConfig_ModifyExistingConfigWithBuilder(t *testing.T) {
117+
if strings.EqualFold(os.Getenv("SETH_NETWORK"), "anvil") {
118+
t.Skip("skipping test in anvil network")
119+
}
134120
configPath := os.Getenv(seth.CONFIG_FILE_ENV_VAR)
135121
require.NotEmpty(t, configPath, "expected config file path to be set")
136122

@@ -204,12 +190,9 @@ func TestConfig_ModifyExistingConfigWithBuilder_UnknownChainId_UseDefault(t *tes
204190
err = toml.Unmarshal(d, &sethConfig)
205191
require.NoError(t, err, "failed to unmarshal config file")
206192

207-
url, err := getRpc()
208-
require.NoError(t, err, "failed to get rpc url")
209-
210193
_, err = seth.NewClientBuilderWithConfig(&sethConfig).
211194
UseNetworkWithChainId(225).
212-
WithRpcUrl(url).
195+
WithRpcUrl(os.Getenv("SETH_URL")).
213196
WithPrivateKeys([]string{"ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"}).
214197
Build()
215198

@@ -226,13 +209,10 @@ you need to set the Network`
226209
func TestConfig_LegacyGas_No_Estimations(t *testing.T) {
227210
builder := seth.NewClientBuilder()
228211

229-
url, err := getRpc()
230-
require.NoError(t, err, "failed to get rpc url")
231-
232212
client, err := builder.
233213
// network
234214
WithNetworkName("my network").
235-
WithRpcUrl(url).
215+
WithRpcUrl(os.Getenv("SETH_URL")).
236216
WithPrivateKeys([]string{"ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"}).
237217
// Gas price and estimations
238218
WithLegacyGasPrice(710_000_000).
@@ -251,13 +231,10 @@ func TestConfig_LegacyGas_No_Estimations(t *testing.T) {
251231
func TestConfig_Eip1559Gas_With_Estimations(t *testing.T) {
252232
builder := seth.NewClientBuilder()
253233

254-
url, err := getRpc()
255-
require.NoError(t, err, "failed to get rpc url")
256-
257234
client, err := builder.
258235
// network
259236
WithNetworkName("my network").
260-
WithRpcUrl(url).
237+
WithRpcUrl(os.Getenv("SETH_URL")).
261238
WithPrivateKeys([]string{"ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"}).
262239
// Gas price and estimations
263240
WithEIP1559DynamicFees(true).
@@ -281,7 +258,7 @@ func TestConfig_NoPrivateKeys_RpcHealthEnabled(t *testing.T) {
281258
_, err := builder.
282259
// network
283260
WithNetworkName("my network").
284-
WithRpcUrl("ws://localhost:8546").
261+
WithRpcUrl(os.Getenv("SETH_URL")).
285262
// Gas price and estimations
286263
WithEIP1559DynamicFees(true).
287264
WithDynamicGasPrices(120_000_000_000, 44_000_000_000).
@@ -298,7 +275,7 @@ func TestConfig_NoPrivateKeys_PendingNonce(t *testing.T) {
298275
_, err := builder.
299276
// network
300277
WithNetworkName("my network").
301-
WithRpcUrl("ws://localhost:8546").
278+
WithRpcUrl(os.Getenv("SETH_URL")).
302279
// Gas price and estimations
303280
WithEIP1559DynamicFees(true).
304281
WithDynamicGasPrices(120_000_000_000, 44_000_000_000).
@@ -316,7 +293,7 @@ func TestConfig_NoPrivateKeys_EphemeralKeys(t *testing.T) {
316293
_, err := builder.
317294
// network
318295
WithNetworkName("my network").
319-
WithRpcUrl("ws://localhost:8546").
296+
WithRpcUrl(os.Getenv("SETH_URL")).
320297
WithEphemeralAddresses(10, 1000).
321298
// Gas price and estimations
322299
WithEIP1559DynamicFees(true).
@@ -334,7 +311,7 @@ func TestConfig_NoPrivateKeys_GasEstimations(t *testing.T) {
334311

335312
_, err := builder.
336313
WithNetworkName("my network").
337-
WithRpcUrl("ws://localhost:8546").
314+
WithRpcUrl(os.Getenv("SETH_URL")).
338315
WithGasPriceEstimations(true, 10, seth.Priority_Fast, 2).
339316
WithProtections(false, false, seth.MustMakeDuration(1*time.Minute)).
340317
Build()
@@ -349,7 +326,7 @@ func TestConfig_NoPrivateKeys_TxOpts(t *testing.T) {
349326
client, err := builder.
350327
// network
351328
WithNetworkName("my network").
352-
WithRpcUrl("ws://localhost:8546").
329+
WithRpcUrl(os.Getenv("SETH_URL")).
353330
// Gas price and estimations
354331
WithEIP1559DynamicFees(true).
355332
WithDynamicGasPrices(120_000_000_000, 44_000_000_000).
@@ -368,12 +345,15 @@ func TestConfig_NoPrivateKeys_TxOpts(t *testing.T) {
368345
func TestConfig_NoPrivateKeys_Tracing(t *testing.T) {
369346
builder := seth.NewClientBuilder()
370347

371-
url, err := getRpc()
372-
require.NoError(t, err, "failed to get rpc url")
348+
var chainId uint64 = 1337
349+
if strings.EqualFold(os.Getenv("SETH_NETWORK"), "anvil") {
350+
chainId = 31337
351+
}
373352

374353
client, err := builder.
375354
WithNetworkName("my network").
376-
WithRpcUrl(url).
355+
WithRpcUrl(os.Getenv("SETH_URL")).
356+
WithNetworkChainId(chainId).
377357
WithEIP1559DynamicFees(true).
378358
WithDynamicGasPrices(120_000_000_000, 44_000_000_000).
379359
WithGasPriceEstimations(false, 10, seth.Priority_Fast, 2).
@@ -384,7 +364,7 @@ func TestConfig_NoPrivateKeys_Tracing(t *testing.T) {
384364
require.NoError(t, err, "failed to the client")
385365
require.Equal(t, 0, len(client.PrivateKeys), "expected 0 private keys")
386366

387-
ethClient, err := ethclient.Dial("ws://localhost:8546")
367+
ethClient, err := ethclient.Dial(os.Getenv("SETH_URL"))
388368
require.NoError(t, err, "failed to dial eth client")
389369

390370
pk, err := crypto.HexToECDSA("ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80")
@@ -420,12 +400,9 @@ func TestConfig_NoPrivateKeys_Tracing(t *testing.T) {
420400
func TestConfig_ReadOnlyMode(t *testing.T) {
421401
builder := seth.NewClientBuilder()
422402

423-
url, err := getRpc()
424-
require.NoError(t, err, "failed to get rpc url")
425-
426403
client, err := builder.
427404
WithNetworkName("my network").
428-
WithRpcUrl(url).
405+
WithRpcUrl(os.Getenv("SETH_URL")).
429406
WithEphemeralAddresses(10, 1000).
430407
WithPrivateKeys([]string{"ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"}).
431408
WithGasPriceEstimations(true, 10, seth.Priority_Fast, 2).
@@ -806,10 +783,7 @@ func TestConfig_EthClient_DoesntAllowRpcUrl(t *testing.T) {
806783
func TestConfig_EthClient(t *testing.T) {
807784
builder := seth.NewClientBuilder()
808785

809-
url, err := getRpc()
810-
require.NoError(t, err, "failed to get rpc url")
811-
812-
ethclient, err := ethclient.Dial(url)
786+
ethclient, err := ethclient.Dial(os.Getenv("SETH_URL"))
813787
require.NoError(t, err, "failed to dial eth client")
814788

815789
client, err := builder.

seth/config_test.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package seth_test
22

33
import (
44
"crypto/ecdsa"
5+
"os"
56
"testing"
67
"time"
78

@@ -15,7 +16,7 @@ import (
1516
)
1617

1718
func TestConfig_DefaultClient(t *testing.T) {
18-
client, err := seth.DefaultClient("ws://localhost:8546", []string{"ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"})
19+
client, err := seth.DefaultClient(os.Getenv("SETH_URL"), []string{"ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"})
1920
require.NoError(t, err, "failed to create client with default config")
2021
require.Equal(t, 1, len(client.PrivateKeys), "expected 1 private key")
2122

@@ -27,7 +28,7 @@ func TestConfig_DefaultClient(t *testing.T) {
2728
}
2829

2930
func TestConfig_Default_TwoPks(t *testing.T) {
30-
client, err := seth.DefaultClient("ws://localhost:8546", []string{"ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80", "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"})
31+
client, err := seth.DefaultClient(os.Getenv("SETH_URL"), []string{"ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80", "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"})
3132
require.NoError(t, err, "failed to create client with default config")
3233
require.Equal(t, 2, len(client.PrivateKeys), "expected 2 private keys")
3334

@@ -122,7 +123,7 @@ func TestConfig_ReadOnly_WithPk(t *testing.T) {
122123
ReadOnly: true,
123124
Network: &seth.Network{
124125
Name: "some_other",
125-
URLs: []string{"ws://localhost:8546"},
126+
URLs: []string{os.Getenv("SETH_URL")},
126127
},
127128
}
128129

@@ -150,7 +151,7 @@ func TestConfig_ReadOnly_GasBumping(t *testing.T) {
150151
ReadOnly: true,
151152
Network: &seth.Network{
152153
Name: "some_other",
153-
URLs: []string{"ws://localhost:8546"},
154+
URLs: []string{os.Getenv("SETH_URL")},
154155
DialTimeout: &seth.Duration{D: 10 * time.Second},
155156
},
156157
GasBump: &seth.GasBumpConfig{
@@ -169,7 +170,7 @@ func TestConfig_ReadOnly_RpcHealth(t *testing.T) {
169170
CheckRpcHealthOnStart: true,
170171
Network: &seth.Network{
171172
Name: "some_other",
172-
URLs: []string{"ws://localhost:8546"},
173+
URLs: []string{os.Getenv("SETH_URL")},
173174
DialTimeout: &seth.Duration{D: 10 * time.Second},
174175
},
175176
}
@@ -185,7 +186,7 @@ func TestConfig_ReadOnly_PendingNonce(t *testing.T) {
185186
PendingNonceProtectionEnabled: true,
186187
Network: &seth.Network{
187188
Name: "some_other",
188-
URLs: []string{"ws://localhost:8546"},
189+
URLs: []string{os.Getenv("SETH_URL")},
189190
DialTimeout: &seth.Duration{D: 10 * time.Second},
190191
},
191192
}
@@ -202,7 +203,7 @@ func TestConfig_ReadOnly_EphemeralKeys(t *testing.T) {
202203
EphemeralAddrs: &ten,
203204
Network: &seth.Network{
204205
Name: "some_other",
205-
URLs: []string{"ws://localhost:8546"},
206+
URLs: []string{os.Getenv("SETH_URL")},
206207
DialTimeout: &seth.Duration{D: 10 * time.Second},
207208
},
208209
}

0 commit comments

Comments
 (0)