Skip to content

Commit

Permalink
all: replace uses of ioutil with io and os (ethereum#24869)
Browse files Browse the repository at this point in the history
  • Loading branch information
JukLee0ira committed Sep 27, 2024
1 parent 4f9501f commit bbf1d72
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 16 deletions.
3 changes: 1 addition & 2 deletions accounts/abi/bind/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"crypto/ecdsa"
"errors"
"io"
"io/ioutil"
"math/big"

"github.com/XinFinOrg/XDPoSChain/accounts"
Expand Down Expand Up @@ -80,7 +79,7 @@ func NewKeyedTransactor(key *ecdsa.PrivateKey) *TransactOpts {
// NewTransactorWithChainID is a utility method to easily create a transaction signer from
// an encrypted json key stream and the associated passphrase.
func NewTransactorWithChainID(keyin io.Reader, passphrase string, chainID *big.Int) (*TransactOpts, error) {
json, err := ioutil.ReadAll(keyin)
json, err := io.ReadAll(keyin)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions core/rawdb/accessors_chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package rawdb
import (
"bytes"
"encoding/hex"
"io/ioutil"
"math/big"
"os"
"testing"

"github.com/XinFinOrg/XDPoSChain/common"
Expand Down Expand Up @@ -214,7 +214,7 @@ func TestDeriveLogFields(t *testing.T) {

func BenchmarkDecodeRLPLogs(b *testing.B) {
// Encoded receipts from block 0x14ee094309fbe8f70b65f45ebcc08fb33f126942d97464aad5eb91cfd1e2d269
buf, err := ioutil.ReadFile("testdata/stored_receipts.bin")
buf, err := os.ReadFile("testdata/stored_receipts.bin")
if err != nil {
b.Fatal(err)
}
Expand Down
3 changes: 1 addition & 2 deletions crypto/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"fmt"
"hash"
"io"
"io/ioutil"
"math/big"
"os"

Expand Down Expand Up @@ -250,7 +249,7 @@ func checkKeyFileEnd(r *bufio.Reader) error {
// restrictive permissions. The key data is saved hex-encoded.
func SaveECDSA(file string, key *ecdsa.PrivateKey) error {
k := hex.EncodeToString(FromECDSA(key))
return ioutil.WriteFile(file, []byte(k), 0600)
return os.WriteFile(file, []byte(k), 0600)
}

// GenerateKey generates a new private key.
Expand Down
5 changes: 2 additions & 3 deletions crypto/crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"bytes"
"crypto/ecdsa"
"encoding/hex"
"io/ioutil"
"math/big"
"os"
"reflect"
Expand Down Expand Up @@ -175,7 +174,7 @@ func TestLoadECDSA(t *testing.T) {
}

for _, test := range tests {
f, err := ioutil.TempFile("", "loadecdsa_test.*.txt")
f, err := os.CreateTemp("", "loadecdsa_test.*.txt")
if err != nil {
t.Fatal(err)
}
Expand All @@ -196,7 +195,7 @@ func TestLoadECDSA(t *testing.T) {
}

func TestSaveECDSA(t *testing.T) {
f, err := ioutil.TempFile("", "saveecdsa_test.*.txt")
f, err := os.CreateTemp("", "saveecdsa_test.*.txt")
if err != nil {
t.Fatal(err)
}
Expand Down
3 changes: 1 addition & 2 deletions eth/tracers/internal/tracers/assets.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions eth/tracers/testing/calltrace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package testing

import (
"encoding/json"
"io/ioutil"
"math/big"
"os"
"path/filepath"
"reflect"
"strings"
Expand Down Expand Up @@ -66,7 +66,7 @@ func TestCallTracer(t *testing.T) {
}

func testCallTracer(tracerName string, dirPath string, t *testing.T) {
files, err := ioutil.ReadDir(filepath.Join("..", "testdata", dirPath))
files, err := os.ReadDir(filepath.Join("..", "testdata", dirPath))
if err != nil {
t.Fatalf("failed to retrieve tracer test suite: %v", err)
}
Expand All @@ -83,7 +83,7 @@ func testCallTracer(tracerName string, dirPath string, t *testing.T) {
tx = new(types.Transaction)
)
// Call tracer test found, read if from disk
if blob, err := ioutil.ReadFile(filepath.Join("..", "testdata", dirPath, file.Name())); err != nil {
if blob, err := os.ReadFile(filepath.Join("..", "testdata", dirPath, file.Name())); err != nil {
t.Fatalf("failed to read testcase: %v", err)
} else if err := json.Unmarshal(blob, test); err != nil {
t.Fatalf("failed to parse testcase: %v", err)
Expand Down Expand Up @@ -171,7 +171,7 @@ func camel(str string) string {
return strings.Join(pieces, "")
}
func BenchmarkTracers(b *testing.B) {
files, err := ioutil.ReadDir(filepath.Join("..", "testdata", "call_tracer"))
files, err := os.ReadDir(filepath.Join("..", "testdata", "call_tracer"))
if err != nil {
b.Fatalf("failed to retrieve tracer test suite: %v", err)
}
Expand All @@ -181,7 +181,7 @@ func BenchmarkTracers(b *testing.B) {
}
file := file // capture range variable
b.Run(camel(strings.TrimSuffix(file.Name(), ".json")), func(b *testing.B) {
blob, err := ioutil.ReadFile(filepath.Join("..", "testdata", "call_tracer", file.Name()))
blob, err := os.ReadFile(filepath.Join("..", "testdata", "call_tracer", file.Name()))
if err != nil {
b.Fatalf("failed to read testcase: %v", err)
}
Expand Down

0 comments on commit bbf1d72

Please sign in to comment.