Skip to content

Commit

Permalink
SetHttpClient
Browse files Browse the repository at this point in the history
  • Loading branch information
serichoi65 committed Feb 21, 2025
1 parent ba9e318 commit 9e681ad
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
9 changes: 5 additions & 4 deletions pkg/clients/ethereum/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,10 @@ func DefaultChunkedCallEthereumClientConfig() *EthereumClientConfig {
}
}

func NewClient(cfg *EthereumClientConfig, l *zap.Logger, hc ...*http.Client) *Client {
func NewClient(cfg *EthereumClientConfig, l *zap.Logger) *Client {
client := &http.Client{
Timeout: time.Second * 10,
}
if len(hc) > 0 && hc[0] != nil {
client = hc[0]
}

l.Sugar().Infow("Creating new Ethereum client", zap.Any("config", cfg))

Expand All @@ -113,6 +110,10 @@ func NewClient(cfg *EthereumClientConfig, l *zap.Logger, hc ...*http.Client) *Cl
}
}

func (c *Client) SetHttpClient(client *http.Client) {
c.httpClient = client
}

func (c *Client) GetEthereumContractCaller() (*ethclient.Client, error) {
d, err := ethclient.Dial(c.clientConfig.BaseUrl)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion pkg/contractManager/contractManager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ func Test_ContractManager(t *testing.T) {
ethConfig := ethereum.DefaultNativeCallEthereumClientConfig()
ethConfig.BaseUrl = baseUrl

client := ethereum.NewClient(ethConfig, l, mockHttpClient)
client := ethereum.NewClient(ethConfig, l)
client.SetHttpClient(mockHttpClient)

af := abiFetcher.NewAbiFetcher(client, &http.Client{Timeout: 5 * time.Second}, l, cfg)

Expand Down

0 comments on commit 9e681ad

Please sign in to comment.