mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
all: replace uses of ioutil with io and os (#24869)
This commit is contained in:
parent
4f9501f12c
commit
47d27fed3b
6 changed files with 12 additions and 16 deletions
|
|
@ -20,7 +20,6 @@ import (
|
|||
"crypto/ecdsa"
|
||||
"errors"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math/big"
|
||||
|
||||
"github.com/XinFinOrg/XDPoSChain/accounts"
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ package rawdb
|
|||
import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"io/ioutil"
|
||||
"math/big"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/XinFinOrg/XDPoSChain/common"
|
||||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ import (
|
|||
"fmt"
|
||||
"hash"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math/big"
|
||||
"os"
|
||||
|
||||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ import (
|
|||
"bytes"
|
||||
"crypto/ecdsa"
|
||||
"encoding/hex"
|
||||
"io/ioutil"
|
||||
"math/big"
|
||||
"os"
|
||||
"reflect"
|
||||
|
|
@ -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)
|
||||
}
|
||||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ import (
|
|||
"crypto/sha256"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
|
@ -474,7 +473,7 @@ func RestoreAsset(dir, name string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
|
||||
err = os.WriteFile(_filePath(dir, name), data, info.Mode())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ package testing
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"math/big"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
|
@ -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)
|
||||
}
|
||||
|
|
@ -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)
|
||||
|
|
@ -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)
|
||||
}
|
||||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue