Skip to content

Commit

Permalink
Fix lint errors by replacing deprecated function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
songge-cb committed Mar 8, 2024
1 parent dbfb279 commit c468102
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 33 deletions.
1 change: 0 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,6 @@ func (ec *SDKClient) BlockRewardTransaction(
minerReward.Add(minerReward, uint256.MustFromBig(rewardInt))
}

const base = 10
miningRewardOp := &RosettaTypes.Operation{
OperationIdentifier: &RosettaTypes.OperationIdentifier{
Index: 0,
Expand Down
14 changes: 7 additions & 7 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"strconv"
"testing"

Expand Down Expand Up @@ -54,7 +54,7 @@ func TestOpenEthTraceAPI_EmptyTrace(t *testing.T) {
func(args mock.Arguments) {
r := args.Get(1).(*json.RawMessage)

file, err := ioutil.ReadFile(
file, err := os.ReadFile(
"testdata/trace_block_empty.json",
)
assert.NoError(t, err)
Expand Down Expand Up @@ -95,7 +95,7 @@ func TestTraceBlockByHash(t *testing.T) {
func(args mock.Arguments) {
r := args.Get(1).(*json.RawMessage)

file, err := ioutil.ReadFile(
file, err := os.ReadFile(
"testdata/block_trace_0xd88e8376ec3eef899d9fbc6349e8330ebfc102b245fef784a999ac854091cb64.json",
)
assert.NoError(t, err)
Expand Down Expand Up @@ -154,7 +154,7 @@ func TestOpenEthTraceAPI_1Txn(t *testing.T) {
func(args mock.Arguments) {
r := args.Get(1).(*json.RawMessage)

file, err := ioutil.ReadFile(
file, err := os.ReadFile(
"testdata/trace_block_1_tx.json",
)
assert.NoError(t, err)
Expand Down Expand Up @@ -206,7 +206,7 @@ func TestOpenEthTraceAPI_MultiTxns(t *testing.T) {
func(args mock.Arguments) {
r := args.Get(1).(*json.RawMessage)

file, err := ioutil.ReadFile(
file, err := os.ReadFile(
"testdata/trace_block_many_traces.json",
)
assert.NoError(t, err)
Expand Down Expand Up @@ -257,7 +257,7 @@ func TestBalance(t *testing.T) {
func(args mock.Arguments) {
r := args.Get(1).(**types.Header)

file, err := ioutil.ReadFile("testdata/block_10992.json")
file, err := os.ReadFile("testdata/block_10992.json")
assert.NoError(t, err)
err = json.Unmarshal(file, &r)
assert.NoError(t, err)
Expand Down Expand Up @@ -308,7 +308,7 @@ func TestBalance(t *testing.T) {
func(args mock.Arguments) {
r := args.Get(1).(*string)
var expected map[string]interface{}
file, err := ioutil.ReadFile("testdata/call_balance_token_10992.json")
file, err := os.ReadFile("testdata/call_balance_token_10992.json")
assert.NoError(t, err)

err = json.Unmarshal(file, &expected)
Expand Down
8 changes: 7 additions & 1 deletion client/rpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,16 @@ func NewRPCClient(endpoint string) (*RPCClient, error) {
defaultTransport.MaxIdleConns = DefaultMaxConnections
defaultTransport.MaxIdleConnsPerHost = DefaultMaxConnections

client, err := rpc.DialHTTPWithClient(endpoint, &http.Client{
clientOptions := rpc.WithHTTPClient(&http.Client{
Timeout: gethHTTPTimeout,
Transport: defaultTransport,
})
ctx := context.Background()
client, err := rpc.DialOptions(ctx, endpoint, clientOptions)
/*client, err := rpc.DialHTTPWithClient(endpoint, &http.Client{
Timeout: gethHTTPTimeout,
Transport: defaultTransport,
})*/
if err != nil {
return nil, fmt.Errorf("unable to dial node: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions client/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ package client
import (
"encoding/json"
"fmt"
"io/ioutil"
"math/big"
"os"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
Expand Down Expand Up @@ -47,7 +47,7 @@ func GetTraceConfig(useNative bool) (*tracers.TraceConfig, error) {
}

func loadTraceConfig() (*tracers.TraceConfig, error) {
loadedFile, err := ioutil.ReadFile(tracerPath)
loadedFile, err := os.ReadFile(tracerPath)
if err != nil {
return nil, fmt.Errorf("could not load tracer file: %w", err)
}
Expand Down
44 changes: 22 additions & 22 deletions services/block_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ package services
import (
"context"
"encoding/json"
"io/ioutil"
"log"
"os"

EthTypes "github.com/ethereum/go-ethereum/core/types"

Expand All @@ -40,11 +40,11 @@ import (
)

const (
hsh = "0xd83b1dcf7d47c4115d78ce0361587604e8157591b118bd64ada02e86c9d5ca7e"
hsh = "0xd83b1dcf7d47c4115d78ce0361587604e8157591b118bd64ada02e86c9d5ca7e"
)

func loadTokenWhiteList() []configuration.Token {
content, err := ioutil.ReadFile("testdata/tokenList.json")
content, err := os.ReadFile("testdata/tokenList.json")
if err != nil {
log.Fatal("Error when opening file: ", err)
}
Expand Down Expand Up @@ -111,7 +111,7 @@ func TestBlockService_Online(t *testing.T) {
func(args mock.Arguments) {
r := args.Get(1).(*json.RawMessage)

file, err := ioutil.ReadFile("testdata/block_10992.json")
file, err := os.ReadFile("testdata/block_10992.json")
assert.NoError(t, err)

*r = json.RawMessage(file)
Expand Down Expand Up @@ -180,7 +180,7 @@ func TestBlockService_Online(t *testing.T) {
func(args mock.Arguments) {
r := args.Get(1).(*json.RawMessage)

file, err := ioutil.ReadFile("testdata/block_10992.json")
file, err := os.ReadFile("testdata/block_10992.json")
assert.NoError(t, err)

*r = json.RawMessage(file)
Expand Down Expand Up @@ -221,7 +221,7 @@ func TestBlockService_Online(t *testing.T) {
func(args mock.Arguments) {
r := args.Get(1).(*json.RawMessage)

file, err := ioutil.ReadFile("testdata/block_10994.json")
file, err := os.ReadFile("testdata/block_10994.json")
assert.NoError(t, err)

*r = json.RawMessage(file)
Expand All @@ -230,15 +230,15 @@ func TestBlockService_Online(t *testing.T) {

m := make(map[string][]*client.FlatCall)
m[hsh] = append(m[hsh], &client.FlatCall{
Type: "call",
Type: "call",
BeforeEVMTransfers: nil,
AfterEVMTransfers: nil,
From: common.HexToAddress("0x1234"),
To: common.HexToAddress("0x4566"),
Value: big.NewInt(900000),
GasUsed: big.NewInt(10000),
Revert: false,
ErrorMessage: "",
From: common.HexToAddress("0x1234"),
To: common.HexToAddress("0x4566"),
Value: big.NewInt(900000),
GasUsed: big.NewInt(10000),
Revert: false,
ErrorMessage: "",
})

// TraceBlockByHash returns valid traces map
Expand Down Expand Up @@ -279,12 +279,12 @@ func TestBlockService_Online(t *testing.T) {
OperationIdentifier: &RosettaTypes.OperationIdentifier{
Index: 0,
},
Type: AssetTypes.CallOpType,
Status: RosettaTypes.String(AssetTypes.SuccessStatus),
Type: AssetTypes.CallOpType,
Status: RosettaTypes.String(AssetTypes.SuccessStatus),
Account: &RosettaTypes.AccountIdentifier{
Address: mock.Anything,
},
Amount: client.Amount(big.NewInt(-1), AssetTypes.Currency),
Amount: client.Amount(big.NewInt(-1), AssetTypes.Currency),
},

{
Expand Down Expand Up @@ -351,7 +351,7 @@ func TestBlockService_Online(t *testing.T) {
func(args mock.Arguments) {
r := args.Get(1).(*json.RawMessage)

file, err := ioutil.ReadFile("testdata/block_10994.json")
file, err := os.ReadFile("testdata/block_10994.json")
assert.NoError(t, err)

*r = json.RawMessage(file)
Expand Down Expand Up @@ -440,12 +440,12 @@ func TestBlockService_Online(t *testing.T) {
OperationIdentifier: &RosettaTypes.OperationIdentifier{
Index: 0,
},
Type: AssetTypes.FeeOpType,
Status: RosettaTypes.String(AssetTypes.SuccessStatus),
Type: AssetTypes.FeeOpType,
Status: RosettaTypes.String(AssetTypes.SuccessStatus),
Account: &RosettaTypes.AccountIdentifier{
Address: "0x0000000000000000000000000000000000001234",
},
Amount: client.Amount(big.NewInt(-10000), AssetTypes.Currency),
Amount: client.Amount(big.NewInt(-10000), AssetTypes.Currency),
},

{
Expand Down Expand Up @@ -489,9 +489,9 @@ func TestBlockService_Online(t *testing.T) {
"GetRosettaConfig",
).Return(
configuration.RosettaConfig{
FilterTokens: true,
FilterTokens: true,
TokenWhiteList: loadTokenWhiteList(),
TracePrefix: "arbtrace",
TracePrefix: "arbtrace",
},
)

Expand Down

0 comments on commit c468102

Please sign in to comment.