Skip to content

Commit

Permalink
Merge pull request #270 from forta-network/caner/fix-linter-errors
Browse files Browse the repository at this point in the history
Fix linter errors
  • Loading branch information
canercidam authored Oct 19, 2023
2 parents 3b887fe + 9b10fd5 commit bc9d843
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 22 deletions.
2 changes: 1 addition & 1 deletion ethereum/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ type rpcClient struct {
}

func (rc *rpcClient) Subscribe(ctx context.Context, namespace string, channel interface{}, args ...interface{}) (domain.ClientSubscription, error) {
sub, err := rc.Subscribe(ctx, namespace, channel, args...)
sub, err := rc.Client.Subscribe(ctx, namespace, channel, args...)
return sub, err
}

Expand Down
23 changes: 18 additions & 5 deletions inspect/proxy_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,15 @@ func (pai *ProxyAPIInspector) Inspect(ctx context.Context, inspectionCfg Inspect
results = NewInspectionResults()
results.Indicators = defaultIndicators(proxyAPIIndicators)

proxyRPCClient, err := RPCDialContext(ctx, inspectionCfg.ProxyAPIURL)
if err != nil {
resultErr = multierror.Append(resultErr, fmt.Errorf("can't dial json-rpc api %w", err))

proxyRPCClient, rpcErr := RPCDialContext(ctx, inspectionCfg.ProxyAPIURL)
proxyClient, clientErr := EthClientDialContext(ctx, inspectionCfg.ProxyAPIURL)
if rpcErr != nil {
resultErr = multierror.Append(resultErr, fmt.Errorf("can't dial json-rpc api: %v", rpcErr))
}
if clientErr != nil {
resultErr = multierror.Append(resultErr, fmt.Errorf("can't dial json-rpc api: %v", clientErr))
}
if rpcErr != nil || clientErr != nil {
results.Indicators[IndicatorProxyAPIAccessible] = ResultFailure
results.Indicators[IndicatorProxyAPIModuleWeb3] = ResultFailure
results.Indicators[IndicatorProxyAPIModuleEth] = ResultFailure
Expand All @@ -84,7 +89,6 @@ func (pai *ProxyAPIInspector) Inspect(ctx context.Context, inspectionCfg Inspect
results.Indicators[IndicatorProxyAPIAccessible] = ResultSuccess
}

proxyClient, err := EthClientDialContext(ctx, inspectionCfg.ProxyAPIURL)
if id, err := GetChainOrNetworkID(ctx, proxyRPCClient); err != nil {
resultErr = multierror.Append(resultErr, fmt.Errorf("can't query chain id: %v", err))
results.Indicators[IndicatorProxyAPIChainID] = ResultFailure
Expand Down Expand Up @@ -123,6 +127,15 @@ func (pai *ProxyAPIInspector) Inspect(ctx context.Context, inspectionCfg Inspect
}

scanClient, err := EthClientDialContext(ctx, inspectionCfg.ScanAPIURL)
if err != nil {
resultErr = multierror.Append(resultErr, fmt.Errorf("can't calculate scan-proxy offset because failed to dial scan api: %w", err))
results.Indicators[IndicatorProxyAPIOffsetScanMean] = ResultUnknown
results.Indicators[IndicatorProxyAPIOffsetScanMedian] = ResultUnknown
results.Indicators[IndicatorProxyAPIOffsetScanMax] = ResultUnknown
results.Indicators[IndicatorProxyAPIOffsetScanSamples] = ResultUnknown
return // early return
}

stats, err := calculateOffsetStats(ctx, proxyClient, scanClient)
if err != nil {
resultErr = multierror.Append(resultErr, fmt.Errorf("can't calculate scan-proxy offset: %w", err))
Expand Down
8 changes: 4 additions & 4 deletions inspect/proxy_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ func TestProxyAPIInspection(t *testing.T) {

rpcClient.EXPECT().CallContext(gomock.Any(), gomock.Any(), "net_version").
DoAndReturn(func(ctx interface{}, result interface{}, method interface{}, args ...interface{}) error {
json.Unmarshal([]byte(`"0x5"`), result)
_ = json.Unmarshal([]byte(`"0x5"`), result)
return nil
}).AnyTimes()
rpcClient.EXPECT().CallContext(gomock.Any(), gomock.Any(), "eth_chainId").
DoAndReturn(func(ctx interface{}, result interface{}, method interface{}, args ...interface{}) error {
json.Unmarshal([]byte(`"0x5"`), result)
_ = json.Unmarshal([]byte(`"0x5"`), result)
return nil
}).AnyTimes()
rpcClient.EXPECT().CallContext(gomock.Any(), gomock.Any(), "web3_clientVersion").Return(nil)
ethClient.EXPECT().BlockNumber(gomock.Any()).Return(uint64(123), nil)
rpcClient.EXPECT().CallContext(gomock.Any(), gomock.Any(), "eth_getBlockByNumber", gomock.Any()).
DoAndReturn(func(ctx interface{}, result interface{}, method interface{}, args ...interface{}) error {
json.Unmarshal([]byte(`"{}"`), result)
_ = json.Unmarshal([]byte(`"{}"`), result)
return nil
})

Expand All @@ -60,7 +60,7 @@ func TestProxyAPIInspection(t *testing.T) {
// eth2 support inspection calls
rpcClient.EXPECT().CallContext(gomock.Any(), gomock.Any(), "eth_getBlockByNumber", "latest", true).
DoAndReturn(func(ctx interface{}, result interface{}, method interface{}, args ...interface{}) error {
json.Unmarshal([]byte(`{"difficulty":"0x0","nonce":"0x0000000000000000"}`), result)
_ = json.Unmarshal([]byte(`{"difficulty":"0x0","nonce":"0x0000000000000000"}`), result)
return nil
})

Expand Down
8 changes: 4 additions & 4 deletions inspect/scan_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,26 @@ func TestScanAPIInspection(t *testing.T) {

rpcClient.EXPECT().CallContext(gomock.Any(), gomock.Any(), "net_version").
DoAndReturn(func(ctx interface{}, result interface{}, method interface{}, args ...interface{}) error {
json.Unmarshal([]byte(`"0x5"`), result)
_ = json.Unmarshal([]byte(`"0x5"`), result)
return nil
}).AnyTimes()
rpcClient.EXPECT().CallContext(gomock.Any(), gomock.Any(), "eth_chainId").
DoAndReturn(func(ctx interface{}, result interface{}, method interface{}, args ...interface{}) error {
json.Unmarshal([]byte(`"0x5"`), result)
_ = json.Unmarshal([]byte(`"0x5"`), result)
return nil
}).AnyTimes()

// block response hash inspection
rpcClient.EXPECT().CallContext(gomock.Any(), gomock.Any(), "eth_getBlockByNumber", gomock.Any()).
DoAndReturn(func(ctx interface{}, result interface{}, method interface{}, args ...interface{}) error {
json.Unmarshal([]byte(`"{}"`), result)
_ = json.Unmarshal([]byte(`"{}"`), result)
return nil
})

// eth2 support inspection calls
rpcClient.EXPECT().CallContext(gomock.Any(), gomock.Any(), "eth_getBlockByNumber", "latest", true).
DoAndReturn(func(ctx interface{}, result interface{}, method interface{}, args ...interface{}) error {
json.Unmarshal([]byte(`{"difficulty":"0x0","nonce":"0x0000000000000000"}`), result)
_ = json.Unmarshal([]byte(`{"difficulty":"0x0","nonce":"0x0000000000000000"}`), result)
return nil
})

Expand Down
8 changes: 4 additions & 4 deletions inspect/trace_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,26 @@ func TestTraceAPIInspection(t *testing.T) {

rpcClient.EXPECT().CallContext(gomock.Any(), gomock.Any(), "net_version").
DoAndReturn(func(ctx interface{}, result interface{}, method interface{}, args ...interface{}) error {
json.Unmarshal([]byte(`"4002"`), result)
_ = json.Unmarshal([]byte(`"4002"`), result)
return nil
}).AnyTimes()
rpcClient.EXPECT().CallContext(gomock.Any(), gomock.Any(), "eth_chainId").
DoAndReturn(func(ctx interface{}, result interface{}, method interface{}, args ...interface{}) error {
json.Unmarshal([]byte(`"4002"`), result)
_ = json.Unmarshal([]byte(`"4002"`), result)
return nil
}).AnyTimes()

// trace response hash inspection
rpcClient.EXPECT().CallContext(gomock.Any(), gomock.Any(), "trace_block", gomock.Any()).
DoAndReturn(func(ctx interface{}, result interface{}, method interface{}, args ...interface{}) error {
json.Unmarshal([]byte(`"{}"`), result)
_ = json.Unmarshal([]byte(`"{}"`), result)
return nil
})

// block response hash inspection
rpcClient.EXPECT().CallContext(gomock.Any(), gomock.Any(), "eth_getBlockByNumber", gomock.Any()).
DoAndReturn(func(ctx interface{}, result interface{}, method interface{}, args ...interface{}) error {
json.Unmarshal([]byte(`"{}"`), result)
_ = json.Unmarshal([]byte(`"{}"`), result)
return nil
})

Expand Down
8 changes: 4 additions & 4 deletions inspect/validation/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ func TestValidateInspectionSuccess(t *testing.T) {
// trace response hash inspection
rpcClient.EXPECT().CallContext(gomock.Any(), gomock.Any(), "trace_block", gomock.Any()).
DoAndReturn(func(ctx interface{}, result interface{}, method interface{}, args ...interface{}) error {
json.Unmarshal([]byte(`"{}"`), result)
_ = json.Unmarshal([]byte(`"{}"`), result)
return nil
})

// block response hash inspection
rpcClient.EXPECT().CallContext(gomock.Any(), gomock.Any(), "eth_getBlockByNumber", gomock.Any()).
DoAndReturn(func(ctx interface{}, result interface{}, method interface{}, args ...interface{}) error {
json.Unmarshal([]byte(`"{}"`), result)
_ = json.Unmarshal([]byte(`"{}"`), result)
return nil
}).Times(3)

Expand Down Expand Up @@ -82,14 +82,14 @@ func TestValidateInspectionFail(t *testing.T) {
// trace response hash inspection
rpcClient.EXPECT().CallContext(gomock.Any(), gomock.Any(), "trace_block", gomock.Any()).
DoAndReturn(func(ctx interface{}, result interface{}, method interface{}, args ...interface{}) error {
json.Unmarshal([]byte(`"{}"`), result)
_ = json.Unmarshal([]byte(`"{}"`), result)
return nil
})

// block response hash inspection
rpcClient.EXPECT().CallContext(gomock.Any(), gomock.Any(), "eth_getBlockByNumber", gomock.Any()).
DoAndReturn(func(ctx interface{}, result interface{}, method interface{}, args ...interface{}) error {
json.Unmarshal([]byte(`"{}"`), result)
_ = json.Unmarshal([]byte(`"{}"`), result)
return nil
}).Times(3)

Expand Down

0 comments on commit bc9d843

Please sign in to comment.