Skip to content

Commit

Permalink
add TLS ignore in order to connect to CRIB, add debug (#1088)
Browse files Browse the repository at this point in the history
  • Loading branch information
skudasov authored Aug 23, 2024
1 parent df8e03c commit 4a0c9a0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
5 changes: 3 additions & 2 deletions client/miner.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package client

import (
"net/http"
"strconv"
"time"

Expand All @@ -18,9 +19,9 @@ type RemoteAnvilMiner struct {
}

// NewRemoteAnvilMiner creates a new remote miner client
func NewRemoteAnvilMiner(url string) *RemoteAnvilMiner {
func NewRemoteAnvilMiner(url string, headers http.Header) *RemoteAnvilMiner {
return &RemoteAnvilMiner{
Client: NewRPCClient(url),
Client: NewRPCClient(url, headers),
stop: make(chan struct{}),
}
}
Expand Down
20 changes: 18 additions & 2 deletions client/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package client

import (
"context"
"crypto/tls"
"encoding/json"
"fmt"
"net/http"
"os"
"strconv"
"time"

Expand All @@ -24,8 +27,21 @@ type RPCClient struct {
}

// NewRPCClient creates Anvil client
func NewRPCClient(url string) *RPCClient {
return &RPCClient{URL: url, client: resty.New()}
func NewRPCClient(url string, headers http.Header) *RPCClient {
isDebug := os.Getenv("RESTY_DEBUG") == "true"
h := make(map[string]string)
for k, v := range headers {
h[k] = v[0]
}
// TODO: use proper certificated in CRIB
//nolint
return &RPCClient{
URL: url,
client: resty.New().
SetDebug(isDebug).
SetHeaders(h).
SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true}),
}
}

// AnvilMine calls "evm_mine", mines one or more blocks, see the reference on RPCClient
Expand Down
2 changes: 1 addition & 1 deletion client/rpc_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestRPCSuite(t *testing.T) {
require.NoError(t, err)
printGasPrices(t, client)
// set a base fee
anvilClient := NewRPCClient(ac.URL)
anvilClient := NewRPCClient(ac.URL, nil)
// set fee for the next block
err = anvilClient.AnvilSetNextBlockBaseFeePerGas([]interface{}{"2000000000"})
require.NoError(t, err)
Expand Down
12 changes: 6 additions & 6 deletions client/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func TestRPCAPI(t *testing.T) {
bnBefore, err := client.BlockNumber(context.Background())
require.NoError(t, err)

ac := NewRPCClient(url)
ac := NewRPCClient(url, nil)
err = ac.GethSetHead(10)
require.NoError(t, err)
bnAfter, err := client.BlockNumber(context.Background())
Expand All @@ -121,7 +121,7 @@ func TestRPCAPI(t *testing.T) {
tx, err := sendTestTransaction(t, client, big.NewInt(1e9), big.NewInt(1e9), false)
require.NoError(t, err)

anvilClient := NewRPCClient(ac.URL)
anvilClient := NewRPCClient(ac.URL, nil)
err = anvilClient.AnvilDropTransaction([]interface{}{tx.Hash().String()})
require.NoError(t, err)
status, err := anvilClient.AnvilTxPoolStatus(nil)
Expand All @@ -136,7 +136,7 @@ func TestRPCAPI(t *testing.T) {
client, err := ethclient.Dial(ac.URL)
require.NoError(t, err)

anvilClient := NewRPCClient(ac.URL)
anvilClient := NewRPCClient(ac.URL, nil)
err = anvilClient.AnvilSetBlockGasLimit([]interface{}{"1"})
require.NoError(t, err)

Expand All @@ -157,7 +157,7 @@ func TestRPCAPI(t *testing.T) {
require.NoError(t, err)
printGasPrices(t, client)

anvilClient := NewRPCClient(ac.URL)
anvilClient := NewRPCClient(ac.URL, nil)
err = anvilClient.AnvilSetNextBlockBaseFeePerGas([]interface{}{"10000000000"})
require.NoError(t, err)
printGasPrices(t, client)
Expand All @@ -182,7 +182,7 @@ func TestRPCAPI(t *testing.T) {
require.NoError(t, err)
client, err := ethclient.Dial(ac.URL)
require.NoError(t, err)
pm := NewRemoteAnvilMiner(ac.URL)
pm := NewRemoteAnvilMiner(ac.URL, nil)
pm.MinePeriodically(500 * time.Millisecond)
time.Sleep(period * time.Duration(iterations))
pm.Stop()
Expand All @@ -201,7 +201,7 @@ func TestRPCAPI(t *testing.T) {
client, err := ethclient.Dial(ac.URL)
require.NoError(t, err)
stopTxns, errCh := sendTestTransactions(t, client, sendTransactionEvery, big.NewInt(1e9), big.NewInt(1e9), false)
pm := NewRemoteAnvilMiner(ac.URL)
pm := NewRemoteAnvilMiner(ac.URL, nil)
pm.MineBatch(txnInBlock, 1*time.Second, 1*time.Minute)
time.Sleep(sendTransactionEvery * time.Duration(iterations) * 2)
pm.Stop()
Expand Down

0 comments on commit 4a0c9a0

Please sign in to comment.