44 "crypto/ecdsa"
55 "math/big"
66 "os"
7+ "strings"
78 "testing"
89 "time"
910
@@ -26,10 +27,7 @@ import (
2627func 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-
5844func 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
133116func 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`
226209func 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) {
251231func 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) {
368345func 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) {
420400func 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) {
806783func 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 .
0 commit comments