Browse Source

migrate away from deprecated ioutil APIs (#7175)

Co-authored-by: Callum Waters <cmwaters19@gmail.com>
Co-authored-by: M. J. Fromberger <fromberger@interchain.io>
pull/7187/head
Sharad Chand 3 years ago
committed by GitHub
parent
commit
8441b3715a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
58 changed files with 158 additions and 192 deletions
  1. +4
    -4
      abci/example/kvstore/kvstore_test.go
  2. +1
    -2
      cmd/priv_val_server/main.go
  3. +1
    -2
      cmd/tendermint/commands/debug/dump.go
  4. +1
    -2
      cmd/tendermint/commands/debug/io.go
  5. +1
    -2
      cmd/tendermint/commands/debug/kill.go
  6. +3
    -3
      cmd/tendermint/commands/debug/util.go
  7. +1
    -2
      cmd/tendermint/commands/root_test.go
  8. +1
    -2
      config/config.go
  9. +2
    -3
      config/toml.go
  10. +3
    -4
      config/toml_test.go
  11. +3
    -4
      internal/consensus/common_test.go
  12. +4
    -5
      internal/consensus/replay_test.go
  13. +2
    -2
      internal/consensus/state.go
  14. +6
    -7
      internal/libs/autofile/autofile_test.go
  15. +4
    -5
      internal/libs/autofile/group_test.go
  16. +8
    -9
      internal/libs/tempfile/tempfile_test.go
  17. +1
    -2
      internal/p2p/conn/secret_connection_test.go
  18. +3
    -3
      internal/p2p/upnp/upnp.go
  19. +5
    -6
      internal/state/indexer/indexer_service_test.go
  20. +1
    -2
      internal/state/indexer/sink/psql/psql_test.go
  21. +2
    -2
      internal/state/indexer/tx/kv/kv_bench_test.go
  22. +2
    -3
      internal/state/indexer/tx/kv/kv_test.go
  23. +2
    -2
      internal/state/state.go
  24. +3
    -4
      internal/statesync/chunks.go
  25. +3
    -4
      internal/statesync/chunks_test.go
  26. +1
    -2
      libs/cli/helper.go
  27. +2
    -2
      libs/cli/setup_test.go
  28. +8
    -9
      libs/os/os_test.go
  29. +1
    -2
      light/example_test.go
  30. +2
    -3
      light/light_test.go
  31. +2
    -2
      light/mbt/driver_test.go
  32. +3
    -3
      privval/file.go
  33. +12
    -13
      privval/file_test.go
  34. +2
    -3
      privval/grpc/util.go
  35. +1
    -2
      privval/socket_listeners_test.go
  36. +1
    -2
      rpc/client/main_test.go
  37. +3
    -3
      rpc/jsonrpc/client/http_json_client.go
  38. +2
    -2
      rpc/jsonrpc/client/http_json_client_test.go
  39. +2
    -2
      rpc/jsonrpc/client/http_uri_client.go
  40. +2
    -2
      rpc/jsonrpc/server/http_json_handler.go
  41. +7
    -7
      rpc/jsonrpc/server/http_json_handler_test.go
  42. +5
    -5
      rpc/jsonrpc/server/http_server_test.go
  43. +4
    -5
      test/e2e/app/snapshots.go
  44. +2
    -3
      test/e2e/app/state.go
  45. +2
    -2
      test/e2e/runner/evidence.go
  46. +4
    -5
      test/e2e/runner/setup.go
  47. +2
    -2
      test/fuzz/mempool/v0/fuzz_test.go
  48. +2
    -2
      test/fuzz/mempool/v1/fuzz_test.go
  49. +2
    -2
      test/fuzz/p2p/secretconnection/fuzz_test.go
  50. +1
    -2
      test/fuzz/p2p/secretconnection/init-corpus/main.go
  51. +2
    -2
      test/fuzz/rpc/jsonrpc/server/fuzz_test.go
  52. +3
    -3
      test/fuzz/rpc/jsonrpc/server/handler.go
  53. +1
    -2
      tools/tm-signer-harness/internal/test_harness_test.go
  54. +1
    -2
      tools/tm-signer-harness/main.go
  55. +3
    -3
      types/genesis.go
  56. +1
    -2
      types/genesis_test.go
  57. +3
    -3
      types/node_key.go
  58. +2
    -2
      types/part_set_test.go

+ 4
- 4
abci/example/kvstore/kvstore_test.go View File

@ -3,7 +3,7 @@ package kvstore
import ( import (
"context" "context"
"fmt" "fmt"
"io/ioutil"
"os"
"sort" "sort"
"testing" "testing"
@ -74,7 +74,7 @@ func TestKVStoreKV(t *testing.T) {
} }
func TestPersistentKVStoreKV(t *testing.T) { func TestPersistentKVStoreKV(t *testing.T) {
dir, err := ioutil.TempDir("/tmp", "abci-kvstore-test") // TODO
dir, err := os.MkdirTemp("/tmp", "abci-kvstore-test") // TODO
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -90,7 +90,7 @@ func TestPersistentKVStoreKV(t *testing.T) {
} }
func TestPersistentKVStoreInfo(t *testing.T) { func TestPersistentKVStoreInfo(t *testing.T) {
dir, err := ioutil.TempDir("/tmp", "abci-kvstore-test") // TODO
dir, err := os.MkdirTemp("/tmp", "abci-kvstore-test") // TODO
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -122,7 +122,7 @@ func TestPersistentKVStoreInfo(t *testing.T) {
// add a validator, remove a validator, update a validator // add a validator, remove a validator, update a validator
func TestValUpdates(t *testing.T) { func TestValUpdates(t *testing.T) {
dir, err := ioutil.TempDir("/tmp", "abci-kvstore-test") // TODO
dir, err := os.MkdirTemp("/tmp", "abci-kvstore-test") // TODO
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }


+ 1
- 2
cmd/priv_val_server/main.go View File

@ -6,7 +6,6 @@ import (
"crypto/x509" "crypto/x509"
"flag" "flag"
"fmt" "fmt"
"io/ioutil"
"net" "net"
"net/http" "net/http"
"os" "os"
@ -78,7 +77,7 @@ func main() {
} }
certPool := x509.NewCertPool() certPool := x509.NewCertPool()
bs, err := ioutil.ReadFile(*rootCA)
bs, err := os.ReadFile(*rootCA)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "failed to read client ca cert: %s", err) fmt.Fprintf(os.Stderr, "failed to read client ca cert: %s", err)
os.Exit(1) os.Exit(1)


+ 1
- 2
cmd/tendermint/commands/debug/dump.go View File

@ -3,7 +3,6 @@ package debug
import ( import (
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"time" "time"
@ -82,7 +81,7 @@ func dumpCmdHandler(_ *cobra.Command, args []string) error {
func dumpDebugData(outDir string, conf *config.Config, rpc *rpchttp.HTTP) { func dumpDebugData(outDir string, conf *config.Config, rpc *rpchttp.HTTP) {
start := time.Now().UTC() start := time.Now().UTC()
tmpDir, err := ioutil.TempDir(outDir, "tendermint_debug_tmp")
tmpDir, err := os.MkdirTemp(outDir, "tendermint_debug_tmp")
if err != nil { if err != nil {
logger.Error("failed to create temporary directory", "dir", tmpDir, "error", err) logger.Error("failed to create temporary directory", "dir", tmpDir, "error", err)
return return


+ 1
- 2
cmd/tendermint/commands/debug/io.go View File

@ -5,7 +5,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
@ -111,5 +110,5 @@ func writeStateJSONToFile(state interface{}, dir, filename string) error {
return fmt.Errorf("failed to encode state dump: %w", err) return fmt.Errorf("failed to encode state dump: %w", err)
} }
return ioutil.WriteFile(path.Join(dir, filename), stateJSON, os.ModePerm)
return os.WriteFile(path.Join(dir, filename), stateJSON, os.ModePerm)
} }

+ 1
- 2
cmd/tendermint/commands/debug/kill.go View File

@ -3,7 +3,6 @@ package debug
import ( import (
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@ -56,7 +55,7 @@ func killCmdHandler(cmd *cobra.Command, args []string) error {
// Create a temporary directory which will contain all the state dumps and // Create a temporary directory which will contain all the state dumps and
// relevant files and directories that will be compressed into a file. // relevant files and directories that will be compressed into a file.
tmpDir, err := ioutil.TempDir(os.TempDir(), "tendermint_debug_tmp")
tmpDir, err := os.MkdirTemp(os.TempDir(), "tendermint_debug_tmp")
if err != nil { if err != nil {
return fmt.Errorf("failed to create temporary directory: %w", err) return fmt.Errorf("failed to create temporary directory: %w", err)
} }


+ 3
- 3
cmd/tendermint/commands/debug/util.go View File

@ -3,7 +3,7 @@ package debug
import ( import (
"context" "context"
"fmt" "fmt"
"io/ioutil"
"io"
"net/http" "net/http"
"os" "os"
"path" "path"
@ -73,10 +73,10 @@ func dumpProfile(dir, addr, profile string, debug int) error {
} }
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return fmt.Errorf("failed to read %s profile response body: %w", profile, err) return fmt.Errorf("failed to read %s profile response body: %w", profile, err)
} }
return ioutil.WriteFile(path.Join(dir, fmt.Sprintf("%s.out", profile)), body, os.ModePerm)
return os.WriteFile(path.Join(dir, fmt.Sprintf("%s.out", profile)), body, os.ModePerm)
} }

+ 1
- 2
cmd/tendermint/commands/root_test.go View File

@ -2,7 +2,6 @@ package commands
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strconv" "strconv"
@ -167,5 +166,5 @@ func WriteConfigVals(dir string, vals map[string]string) error {
data += fmt.Sprintf("%s = \"%s\"\n", k, v) data += fmt.Sprintf("%s = \"%s\"\n", k, v)
} }
cfile := filepath.Join(dir, "config.toml") cfile := filepath.Join(dir, "config.toml")
return ioutil.WriteFile(cfile, []byte(data), 0600)
return os.WriteFile(cfile, []byte(data), 0600)
} }

+ 1
- 2
config/config.go View File

@ -4,7 +4,6 @@ import (
"encoding/hex" "encoding/hex"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"net/http" "net/http"
"os" "os"
"path/filepath" "path/filepath"
@ -269,7 +268,7 @@ func (cfg BaseConfig) NodeKeyFile() string {
// LoadNodeKey loads NodeKey located in filePath. // LoadNodeKey loads NodeKey located in filePath.
func (cfg BaseConfig) LoadNodeKeyID() (types.NodeID, error) { func (cfg BaseConfig) LoadNodeKeyID() (types.NodeID, error) {
jsonBytes, err := ioutil.ReadFile(cfg.NodeKeyFile())
jsonBytes, err := os.ReadFile(cfg.NodeKeyFile())
if err != nil { if err != nil {
return "", err return "", err
} }


+ 2
- 3
config/toml.go View File

@ -3,7 +3,6 @@ package config
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -515,7 +514,7 @@ func ResetTestRoot(testName string) (*Config, error) {
func ResetTestRootWithChainID(testName string, chainID string) (*Config, error) { func ResetTestRootWithChainID(testName string, chainID string) (*Config, error) {
// create a unique, concurrency-safe test directory under os.TempDir() // create a unique, concurrency-safe test directory under os.TempDir()
rootDir, err := ioutil.TempDir("", fmt.Sprintf("%s-%s_", chainID, testName))
rootDir, err := os.MkdirTemp("", fmt.Sprintf("%s-%s_", chainID, testName))
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -559,7 +558,7 @@ func ResetTestRootWithChainID(testName string, chainID string) (*Config, error)
} }
func writeFile(filePath string, contents []byte, mode os.FileMode) error { func writeFile(filePath string, contents []byte, mode os.FileMode) error {
if err := ioutil.WriteFile(filePath, contents, mode); err != nil {
if err := os.WriteFile(filePath, contents, mode); err != nil {
return fmt.Errorf("failed to write file: %w", err) return fmt.Errorf("failed to write file: %w", err)
} }
return nil return nil


+ 3
- 4
config/toml_test.go View File

@ -1,7 +1,6 @@
package config package config
import ( import (
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -23,7 +22,7 @@ func TestEnsureRoot(t *testing.T) {
require := require.New(t) require := require.New(t)
// setup temp dir for test // setup temp dir for test
tmpDir, err := ioutil.TempDir("", "config-test")
tmpDir, err := os.MkdirTemp("", "config-test")
require.NoError(err) require.NoError(err)
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
@ -33,7 +32,7 @@ func TestEnsureRoot(t *testing.T) {
require.NoError(WriteConfigFile(tmpDir, DefaultConfig())) require.NoError(WriteConfigFile(tmpDir, DefaultConfig()))
// make sure config is set properly // make sure config is set properly
data, err := ioutil.ReadFile(filepath.Join(tmpDir, defaultConfigFilePath))
data, err := os.ReadFile(filepath.Join(tmpDir, defaultConfigFilePath))
require.NoError(err) require.NoError(err)
checkConfig(t, string(data)) checkConfig(t, string(data))
@ -53,7 +52,7 @@ func TestEnsureTestRoot(t *testing.T) {
rootDir := cfg.RootDir rootDir := cfg.RootDir
// make sure config is set properly // make sure config is set properly
data, err := ioutil.ReadFile(filepath.Join(rootDir, defaultConfigFilePath))
data, err := os.ReadFile(filepath.Join(rootDir, defaultConfigFilePath))
require.Nil(err) require.Nil(err)
checkConfig(t, string(data)) checkConfig(t, string(data))


+ 3
- 4
internal/consensus/common_test.go View File

@ -5,7 +5,6 @@ import (
"context" "context"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
@ -800,11 +799,11 @@ func randConsensusNetWithPeers(
if i < nValidators { if i < nValidators {
privVal = privVals[i] privVal = privVals[i]
} else { } else {
tempKeyFile, err := ioutil.TempFile("", "priv_validator_key_")
tempKeyFile, err := os.CreateTemp("", "priv_validator_key_")
if err != nil { if err != nil {
panic(err) panic(err)
} }
tempStateFile, err := ioutil.TempFile("", "priv_validator_state_")
tempStateFile, err := os.CreateTemp("", "priv_validator_state_")
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -892,7 +891,7 @@ func (m *mockTicker) Chan() <-chan timeoutInfo {
func (*mockTicker) SetLogger(log.Logger) {} func (*mockTicker) SetLogger(log.Logger) {}
func newPersistentKVStore() abci.Application { func newPersistentKVStore() abci.Application {
dir, err := ioutil.TempDir("", "persistent-kvstore")
dir, err := os.MkdirTemp("", "persistent-kvstore")
if err != nil { if err != nil {
panic(err) panic(err)
} }


+ 4
- 5
internal/consensus/replay_test.go View File

@ -5,7 +5,6 @@ import (
"context" "context"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"math/rand" "math/rand"
"os" "os"
"path/filepath" "path/filepath"
@ -70,7 +69,7 @@ func startNewStateAndWaitForBlock(t *testing.T, consensusReplayConfig *config.Co
) )
cs.SetLogger(logger) cs.SetLogger(logger)
bytes, _ := ioutil.ReadFile(cs.config.WalFile())
bytes, _ := os.ReadFile(cs.config.WalFile())
t.Logf("====== WAL: \n\r%X\n", bytes) t.Logf("====== WAL: \n\r%X\n", bytes)
err = cs.Start() err = cs.Start()
@ -665,7 +664,7 @@ func TestMockProxyApp(t *testing.T) {
} }
func tempWALWithData(data []byte) string { func tempWALWithData(data []byte) string {
walFile, err := ioutil.TempFile("", "wal")
walFile, err := os.CreateTemp("", "wal")
if err != nil { if err != nil {
panic(fmt.Sprintf("failed to create temp WAL file: %v", err)) panic(fmt.Sprintf("failed to create temp WAL file: %v", err))
} }
@ -1072,7 +1071,7 @@ func makeBlockchainFromWAL(wal WAL) ([]*types.Block, []*types.Commit, error) {
// if its not the first one, we have a full block // if its not the first one, we have a full block
if thisBlockParts != nil { if thisBlockParts != nil {
var pbb = new(tmproto.Block) var pbb = new(tmproto.Block)
bz, err := ioutil.ReadAll(thisBlockParts.GetReader())
bz, err := io.ReadAll(thisBlockParts.GetReader())
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -1111,7 +1110,7 @@ func makeBlockchainFromWAL(wal WAL) ([]*types.Block, []*types.Commit, error) {
} }
} }
// grab the last block too // grab the last block too
bz, err := ioutil.ReadAll(thisBlockParts.GetReader())
bz, err := io.ReadAll(thisBlockParts.GetReader())
if err != nil { if err != nil {
panic(err) panic(err)
} }


+ 2
- 2
internal/consensus/state.go View File

@ -5,7 +5,7 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"io"
"os" "os"
"runtime/debug" "runtime/debug"
"time" "time"
@ -1897,7 +1897,7 @@ func (cs *State) addProposalBlockPart(msg *BlockPartMessage, peerID types.NodeID
) )
} }
if added && cs.ProposalBlockParts.IsComplete() { if added && cs.ProposalBlockParts.IsComplete() {
bz, err := ioutil.ReadAll(cs.ProposalBlockParts.GetReader())
bz, err := io.ReadAll(cs.ProposalBlockParts.GetReader())
if err != nil { if err != nil {
return added, err return added, err
} }


+ 6
- 7
internal/libs/autofile/autofile_test.go View File

@ -1,7 +1,6 @@
package autofile package autofile
import ( import (
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"syscall" "syscall"
@ -22,7 +21,7 @@ func TestSIGHUP(t *testing.T) {
}) })
// First, create a temporary directory and move into it // First, create a temporary directory and move into it
dir, err := ioutil.TempDir("", "sighup_test")
dir, err := os.MkdirTemp("", "sighup_test")
require.NoError(t, err) require.NoError(t, err)
t.Cleanup(func() { t.Cleanup(func() {
_ = os.RemoveAll(dir) _ = os.RemoveAll(dir)
@ -45,7 +44,7 @@ func TestSIGHUP(t *testing.T) {
require.NoError(t, os.Rename(name, name+"_old")) require.NoError(t, os.Rename(name, name+"_old"))
// Move into a different temporary directory // Move into a different temporary directory
otherDir, err := ioutil.TempDir("", "sighup_test_other")
otherDir, err := os.MkdirTemp("", "sighup_test_other")
require.NoError(t, err) require.NoError(t, err)
t.Cleanup(func() { os.RemoveAll(otherDir) }) t.Cleanup(func() { os.RemoveAll(otherDir) })
require.NoError(t, os.Chdir(otherDir)) require.NoError(t, os.Chdir(otherDir))
@ -72,7 +71,7 @@ func TestSIGHUP(t *testing.T) {
} }
// The current directory should be empty // The current directory should be empty
files, err := ioutil.ReadDir(".")
files, err := os.ReadDir(".")
require.NoError(t, err) require.NoError(t, err)
assert.Empty(t, files) assert.Empty(t, files)
} }
@ -80,7 +79,7 @@ func TestSIGHUP(t *testing.T) {
// // Manually modify file permissions, close, and reopen using autofile: // // Manually modify file permissions, close, and reopen using autofile:
// // We expect the file permissions to be changed back to the intended perms. // // We expect the file permissions to be changed back to the intended perms.
// func TestOpenAutoFilePerms(t *testing.T) { // func TestOpenAutoFilePerms(t *testing.T) {
// file, err := ioutil.TempFile("", "permission_test")
// file, err := os.CreateTemp("", "permission_test")
// require.NoError(t, err) // require.NoError(t, err)
// err = file.Close() // err = file.Close()
// require.NoError(t, err) // require.NoError(t, err)
@ -106,7 +105,7 @@ func TestSIGHUP(t *testing.T) {
func TestAutoFileSize(t *testing.T) { func TestAutoFileSize(t *testing.T) {
// First, create an AutoFile writing to a tempfile dir // First, create an AutoFile writing to a tempfile dir
f, err := ioutil.TempFile("", "sighup_test")
f, err := os.CreateTemp("", "sighup_test")
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, f.Close()) require.NoError(t, f.Close())
@ -139,7 +138,7 @@ func TestAutoFileSize(t *testing.T) {
} }
func mustReadFile(t *testing.T, filePath string) []byte { func mustReadFile(t *testing.T, filePath string) []byte {
fileBytes, err := ioutil.ReadFile(filePath)
fileBytes, err := os.ReadFile(filePath)
require.NoError(t, err) require.NoError(t, err)
return fileBytes return fileBytes


+ 4
- 5
internal/libs/autofile/group_test.go View File

@ -2,7 +2,6 @@ package autofile
import ( import (
"io" "io"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"testing" "testing"
@ -122,7 +121,7 @@ func TestRotateFile(t *testing.T) {
} }
}() }()
dir, err := ioutil.TempDir("", "rotate_test")
dir, err := os.MkdirTemp("", "rotate_test")
require.NoError(t, err) require.NoError(t, err)
defer os.RemoveAll(dir) defer os.RemoveAll(dir)
err = os.Chdir(dir) err = os.Chdir(dir)
@ -151,21 +150,21 @@ func TestRotateFile(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
// Read g.Head.Path+"000" // Read g.Head.Path+"000"
body1, err := ioutil.ReadFile(g.Head.Path + ".000")
body1, err := os.ReadFile(g.Head.Path + ".000")
assert.NoError(t, err, "Failed to read first rolled file") assert.NoError(t, err, "Failed to read first rolled file")
if string(body1) != "Line 1\nLine 2\nLine 3\n" { if string(body1) != "Line 1\nLine 2\nLine 3\n" {
t.Errorf("got unexpected contents: [%v]", string(body1)) t.Errorf("got unexpected contents: [%v]", string(body1))
} }
// Read g.Head.Path // Read g.Head.Path
body2, err := ioutil.ReadFile(g.Head.Path)
body2, err := os.ReadFile(g.Head.Path)
assert.NoError(t, err, "Failed to read first rolled file") assert.NoError(t, err, "Failed to read first rolled file")
if string(body2) != "Line 4\nLine 5\nLine 6\n" { if string(body2) != "Line 4\nLine 5\nLine 6\n" {
t.Errorf("got unexpected contents: [%v]", string(body2)) t.Errorf("got unexpected contents: [%v]", string(body2))
} }
// Make sure there are no files in the current, temporary directory // Make sure there are no files in the current, temporary directory
files, err := ioutil.ReadDir(".")
files, err := os.ReadDir(".")
require.NoError(t, err) require.NoError(t, err)
assert.Empty(t, files) assert.Empty(t, files)


+ 8
- 9
internal/libs/tempfile/tempfile_test.go View File

@ -5,10 +5,9 @@ package tempfile
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io/ioutil"
mrand "math/rand" mrand "math/rand"
"os" "os"
testing "testing"
"testing"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@ -22,13 +21,13 @@ func TestWriteFileAtomic(t *testing.T) {
perm os.FileMode = 0600 perm os.FileMode = 0600
) )
f, err := ioutil.TempFile("/tmp", "write-atomic-test-")
f, err := os.CreateTemp("/tmp", "write-atomic-test-")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer os.Remove(f.Name()) defer os.Remove(f.Name())
if err = ioutil.WriteFile(f.Name(), old, 0600); err != nil {
if err = os.WriteFile(f.Name(), old, 0600); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -36,7 +35,7 @@ func TestWriteFileAtomic(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
rData, err := ioutil.ReadFile(f.Name())
rData, err := os.ReadFile(f.Name())
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -81,11 +80,11 @@ func TestWriteFileAtomicDuplicateFile(t *testing.T) {
err = WriteFileAtomic(fileToWrite, []byte(expectedString), 0777) err = WriteFileAtomic(fileToWrite, []byte(expectedString), 0777)
require.NoError(t, err) require.NoError(t, err)
// Check that the first atomic file was untouched // Check that the first atomic file was untouched
firstAtomicFileBytes, err := ioutil.ReadFile(fname)
firstAtomicFileBytes, err := os.ReadFile(fname)
require.NoError(t, err, "Error reading first atomic file") require.NoError(t, err, "Error reading first atomic file")
require.Equal(t, []byte(testString), firstAtomicFileBytes, "First atomic file was overwritten") require.Equal(t, []byte(testString), firstAtomicFileBytes, "First atomic file was overwritten")
// Check that the resultant file is correct // Check that the resultant file is correct
resultantFileBytes, err := ioutil.ReadFile(fileToWrite)
resultantFileBytes, err := os.ReadFile(fileToWrite)
require.NoError(t, err, "Error reading resultant file") require.NoError(t, err, "Error reading resultant file")
require.Equal(t, []byte(expectedString), resultantFileBytes, "Written file had incorrect bytes") require.Equal(t, []byte(expectedString), resultantFileBytes, "Written file had incorrect bytes")
@ -132,14 +131,14 @@ func TestWriteFileAtomicManyDuplicates(t *testing.T) {
for i := 0; i < atomicWriteFileMaxNumConflicts+2; i++ { for i := 0; i < atomicWriteFileMaxNumConflicts+2; i++ {
fileRand := randWriteFileSuffix() fileRand := randWriteFileSuffix()
fname := "/tmp/" + atomicWriteFilePrefix + fileRand fname := "/tmp/" + atomicWriteFilePrefix + fileRand
firstAtomicFileBytes, err := ioutil.ReadFile(fname)
firstAtomicFileBytes, err := os.ReadFile(fname)
require.Nil(t, err, "Error reading first atomic file") require.Nil(t, err, "Error reading first atomic file")
require.Equal(t, []byte(fmt.Sprintf(testString, i)), firstAtomicFileBytes, require.Equal(t, []byte(fmt.Sprintf(testString, i)), firstAtomicFileBytes,
"atomic write file %d was overwritten", i) "atomic write file %d was overwritten", i)
} }
// Check that the resultant file is correct // Check that the resultant file is correct
resultantFileBytes, err := ioutil.ReadFile(fileToWrite)
resultantFileBytes, err := os.ReadFile(fileToWrite)
require.Nil(t, err, "Error reading resultant file") require.Nil(t, err, "Error reading resultant file")
require.Equal(t, []byte(expectedString), resultantFileBytes, "Written file had incorrect bytes") require.Equal(t, []byte(expectedString), resultantFileBytes, "Written file had incorrect bytes")
} }

+ 1
- 2
internal/p2p/conn/secret_connection_test.go View File

@ -6,7 +6,6 @@ import (
"flag" "flag"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"log" "log"
mrand "math/rand" mrand "math/rand"
"os" "os"
@ -229,7 +228,7 @@ func TestDeriveSecretsAndChallengeGolden(t *testing.T) {
if *update { if *update {
t.Logf("Updating golden test vector file %s", goldenFilepath) t.Logf("Updating golden test vector file %s", goldenFilepath)
data := createGoldenTestVectors(t) data := createGoldenTestVectors(t)
require.NoError(t, ioutil.WriteFile(goldenFilepath, []byte(data), 0644))
require.NoError(t, os.WriteFile(goldenFilepath, []byte(data), 0644))
} }
f, err := os.Open(goldenFilepath) f, err := os.Open(goldenFilepath)
if err != nil { if err != nil {


+ 3
- 3
internal/p2p/upnp/upnp.go View File

@ -10,7 +10,7 @@ import (
"encoding/xml" "encoding/xml"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"io"
"net" "net"
"net/http" "net/http"
"strconv" "strconv"
@ -312,7 +312,7 @@ func (n *upnpNAT) getExternalIPAddress() (info statusInfo, err error) {
return return
} }
var envelope Envelope var envelope Envelope
data, err := ioutil.ReadAll(response.Body)
data, err := io.ReadAll(response.Body)
if err != nil { if err != nil {
return return
} }
@ -374,7 +374,7 @@ func (n *upnpNAT) AddPortMapping(
// TODO: check response to see if the port was forwarded // TODO: check response to see if the port was forwarded
// log.Println(message, response) // log.Println(message, response)
// JAE: // JAE:
// body, err := ioutil.ReadAll(response.Body)
// body, err := io.ReadAll(response.Body)
// fmt.Println(string(body), err) // fmt.Println(string(body), err)
mappedExternalPort = externalPort mappedExternalPort = externalPort
_ = response _ = response


+ 5
- 6
internal/state/indexer/indexer_service_test.go View File

@ -3,22 +3,21 @@ package indexer_test
import ( import (
"database/sql" "database/sql"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"testing" "testing"
"time" "time"
"github.com/adlio/schema" "github.com/adlio/schema"
dockertest "github.com/ory/dockertest"
"github.com/ory/dockertest"
"github.com/ory/dockertest/docker" "github.com/ory/dockertest/docker"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
dbm "github.com/tendermint/tm-db" dbm "github.com/tendermint/tm-db"
abci "github.com/tendermint/tendermint/abci/types" abci "github.com/tendermint/tendermint/abci/types"
indexer "github.com/tendermint/tendermint/internal/state/indexer"
kv "github.com/tendermint/tendermint/internal/state/indexer/sink/kv"
psql "github.com/tendermint/tendermint/internal/state/indexer/sink/psql"
"github.com/tendermint/tendermint/internal/state/indexer"
"github.com/tendermint/tendermint/internal/state/indexer/sink/kv"
"github.com/tendermint/tendermint/internal/state/indexer/sink/psql"
tmlog "github.com/tendermint/tendermint/libs/log" tmlog "github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
@ -114,7 +113,7 @@ func TestIndexerServiceIndexesBlocks(t *testing.T) {
func readSchema() ([]*schema.Migration, error) { func readSchema() ([]*schema.Migration, error) {
filename := "./sink/psql/schema.sql" filename := "./sink/psql/schema.sql"
contents, err := ioutil.ReadFile(filename)
contents, err := os.ReadFile(filename)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to read sql file from '%s': %w", filename, err) return nil, fmt.Errorf("failed to read sql file from '%s': %w", filename, err)
} }


+ 1
- 2
internal/state/indexer/sink/psql/psql_test.go View File

@ -5,7 +5,6 @@ import (
"database/sql" "database/sql"
"flag" "flag"
"fmt" "fmt"
"io/ioutil"
"log" "log"
"os" "os"
"os/signal" "os/signal"
@ -227,7 +226,7 @@ func newTestBlockHeader() types.EventDataNewBlockHeader {
// readSchema loads the indexing database schema file // readSchema loads the indexing database schema file
func readSchema() ([]*schema.Migration, error) { func readSchema() ([]*schema.Migration, error) {
const filename = "schema.sql" const filename = "schema.sql"
contents, err := ioutil.ReadFile(filename)
contents, err := os.ReadFile(filename)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to read sql file from '%s': %w", filename, err) return nil, fmt.Errorf("failed to read sql file from '%s': %w", filename, err)
} }


+ 2
- 2
internal/state/indexer/tx/kv/kv_bench_test.go View File

@ -4,7 +4,7 @@ import (
"context" "context"
"crypto/rand" "crypto/rand"
"fmt" "fmt"
"io/ioutil"
"os"
"testing" "testing"
dbm "github.com/tendermint/tm-db" dbm "github.com/tendermint/tm-db"
@ -15,7 +15,7 @@ import (
) )
func BenchmarkTxSearch(b *testing.B) { func BenchmarkTxSearch(b *testing.B) {
dbDir, err := ioutil.TempDir("", "benchmark_tx_search_test")
dbDir, err := os.MkdirTemp("", "benchmark_tx_search_test")
if err != nil { if err != nil {
b.Errorf("failed to create temporary directory: %s", err) b.Errorf("failed to create temporary directory: %s", err)
} }


+ 2
- 3
internal/state/indexer/tx/kv/kv_test.go View File

@ -3,7 +3,6 @@ package kv
import ( import (
"context" "context"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"testing" "testing"
@ -13,7 +12,7 @@ import (
dbm "github.com/tendermint/tm-db" dbm "github.com/tendermint/tm-db"
abci "github.com/tendermint/tendermint/abci/types" abci "github.com/tendermint/tendermint/abci/types"
indexer "github.com/tendermint/tendermint/internal/state/indexer"
"github.com/tendermint/tendermint/internal/state/indexer"
"github.com/tendermint/tendermint/libs/pubsub/query" "github.com/tendermint/tendermint/libs/pubsub/query"
tmrand "github.com/tendermint/tendermint/libs/rand" tmrand "github.com/tendermint/tendermint/libs/rand"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
@ -334,7 +333,7 @@ func txResultWithEvents(events []abci.Event) *abci.TxResult {
} }
func benchmarkTxIndex(txsCount int64, b *testing.B) { func benchmarkTxIndex(txsCount int64, b *testing.B) {
dir, err := ioutil.TempDir("", "tx_index_db")
dir, err := os.MkdirTemp("", "tx_index_db")
require.NoError(b, err) require.NoError(b, err)
defer os.RemoveAll(dir) defer os.RemoveAll(dir)


+ 2
- 2
internal/state/state.go View File

@ -4,7 +4,7 @@ import (
"bytes" "bytes"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"os"
"time" "time"
"github.com/gogo/protobuf/proto" "github.com/gogo/protobuf/proto"
@ -323,7 +323,7 @@ func MakeGenesisStateFromFile(genDocFile string) (State, error) {
// MakeGenesisDocFromFile reads and unmarshals genesis doc from the given file. // MakeGenesisDocFromFile reads and unmarshals genesis doc from the given file.
func MakeGenesisDocFromFile(genDocFile string) (*types.GenesisDoc, error) { func MakeGenesisDocFromFile(genDocFile string) (*types.GenesisDoc, error) {
genDocJSON, err := ioutil.ReadFile(genDocFile)
genDocJSON, err := os.ReadFile(genDocFile)
if err != nil { if err != nil {
return nil, fmt.Errorf("couldn't read GenesisDoc file: %v", err) return nil, fmt.Errorf("couldn't read GenesisDoc file: %v", err)
} }


+ 3
- 4
internal/statesync/chunks.go View File

@ -3,7 +3,6 @@ package statesync
import ( import (
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strconv" "strconv"
@ -42,7 +41,7 @@ type chunkQueue struct {
// newChunkQueue creates a new chunk queue for a snapshot, using a temp dir for storage. // newChunkQueue creates a new chunk queue for a snapshot, using a temp dir for storage.
// Callers must call Close() when done. // Callers must call Close() when done.
func newChunkQueue(snapshot *snapshot, tempDir string) (*chunkQueue, error) { func newChunkQueue(snapshot *snapshot, tempDir string) (*chunkQueue, error) {
dir, err := ioutil.TempDir(tempDir, "tm-statesync")
dir, err := os.MkdirTemp(tempDir, "tm-statesync")
if err != nil { if err != nil {
return nil, fmt.Errorf("unable to create temp dir for state sync chunks: %w", err) return nil, fmt.Errorf("unable to create temp dir for state sync chunks: %w", err)
} }
@ -87,7 +86,7 @@ func (q *chunkQueue) Add(chunk *chunk) (bool, error) {
} }
path := filepath.Join(q.dir, strconv.FormatUint(uint64(chunk.Index), 10)) path := filepath.Join(q.dir, strconv.FormatUint(uint64(chunk.Index), 10))
err := ioutil.WriteFile(path, chunk.Chunk, 0600)
err := os.WriteFile(path, chunk.Chunk, 0600)
if err != nil { if err != nil {
return false, fmt.Errorf("failed to save chunk %v to file %v: %w", chunk.Index, path, err) return false, fmt.Errorf("failed to save chunk %v to file %v: %w", chunk.Index, path, err)
} }
@ -229,7 +228,7 @@ func (q *chunkQueue) load(index uint32) (*chunk, error) {
return nil, nil return nil, nil
} }
body, err := ioutil.ReadFile(path)
body, err := os.ReadFile(path)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to load chunk %v: %w", index, err) return nil, fmt.Errorf("failed to load chunk %v: %w", index, err)
} }


+ 3
- 4
internal/statesync/chunks_test.go View File

@ -1,7 +1,6 @@
package statesync package statesync
import ( import (
"io/ioutil"
"os" "os"
"testing" "testing"
@ -36,20 +35,20 @@ func TestNewChunkQueue_TempDir(t *testing.T) {
Hash: []byte{7}, Hash: []byte{7},
Metadata: nil, Metadata: nil,
} }
dir, err := ioutil.TempDir("", "newchunkqueue")
dir, err := os.MkdirTemp("", "newchunkqueue")
require.NoError(t, err) require.NoError(t, err)
defer os.RemoveAll(dir) defer os.RemoveAll(dir)
queue, err := newChunkQueue(snapshot, dir) queue, err := newChunkQueue(snapshot, dir)
require.NoError(t, err) require.NoError(t, err)
files, err := ioutil.ReadDir(dir)
files, err := os.ReadDir(dir)
require.NoError(t, err) require.NoError(t, err)
assert.Len(t, files, 1) assert.Len(t, files, 1)
err = queue.Close() err = queue.Close()
require.NoError(t, err) require.NoError(t, err)
files, err = ioutil.ReadDir(dir)
files, err = os.ReadDir(dir)
require.NoError(t, err) require.NoError(t, err)
assert.Len(t, files, 0) assert.Len(t, files, 0)
} }


+ 1
- 2
libs/cli/helper.go View File

@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
@ -19,7 +18,7 @@ func WriteConfigVals(dir string, vals map[string]string) error {
data += fmt.Sprintf("%s = \"%s\"\n", k, v) data += fmt.Sprintf("%s = \"%s\"\n", k, v)
} }
cfile := filepath.Join(dir, "config.toml") cfile := filepath.Join(dir, "config.toml")
return ioutil.WriteFile(cfile, []byte(data), 0600)
return os.WriteFile(cfile, []byte(data), 0600)
} }
// RunWithArgs executes the given command with the specified command line args // RunWithArgs executes the given command with the specified command line args


+ 2
- 2
libs/cli/setup_test.go View File

@ -2,7 +2,7 @@ package cli
import ( import (
"fmt" "fmt"
"io/ioutil"
"os"
"strconv" "strconv"
"strings" "strings"
"testing" "testing"
@ -55,7 +55,7 @@ func TestSetupEnv(t *testing.T) {
} }
func tempDir() string { func tempDir() string {
cdir, err := ioutil.TempDir("", "test-cli")
cdir, err := os.MkdirTemp("", "test-cli")
if err != nil { if err != nil {
panic(err) panic(err)
} }


+ 8
- 9
libs/os/os_test.go View File

@ -3,7 +3,6 @@ package os_test
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@ -16,7 +15,7 @@ import (
) )
func TestCopyFile(t *testing.T) { func TestCopyFile(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "example")
tmpfile, err := os.CreateTemp("", "example")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -33,7 +32,7 @@ func TestCopyFile(t *testing.T) {
if _, err := os.Stat(copyfile); os.IsNotExist(err) { if _, err := os.Stat(copyfile); os.IsNotExist(err) {
t.Fatal("copy should exist") t.Fatal("copy should exist")
} }
data, err := ioutil.ReadFile(copyfile)
data, err := os.ReadFile(copyfile)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -70,7 +69,7 @@ func TestTrapSignal(t *testing.T) {
} }
func TestEnsureDir(t *testing.T) { func TestEnsureDir(t *testing.T) {
tmp, err := ioutil.TempDir("", "ensure-dir")
tmp, err := os.MkdirTemp("", "ensure-dir")
require.NoError(t, err) require.NoError(t, err)
defer os.RemoveAll(tmp) defer os.RemoveAll(tmp)
@ -84,7 +83,7 @@ func TestEnsureDir(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
// Should fail on file. // Should fail on file.
err = ioutil.WriteFile(filepath.Join(tmp, "file"), []byte{}, 0644)
err = os.WriteFile(filepath.Join(tmp, "file"), []byte{}, 0644)
require.NoError(t, err) require.NoError(t, err)
err = tmos.EnsureDir(filepath.Join(tmp, "file"), 0755) err = tmos.EnsureDir(filepath.Join(tmp, "file"), 0755)
require.Error(t, err) require.Error(t, err)
@ -140,7 +139,7 @@ func newTestProgram(t *testing.T, environVar string) (cmd *exec.Cmd, stdout *byt
// the origin is positively a non-directory and that it is ready for copying. // the origin is positively a non-directory and that it is ready for copying.
// See https://github.com/tendermint/tendermint/issues/6427 // See https://github.com/tendermint/tendermint/issues/6427
func TestTrickedTruncation(t *testing.T) { func TestTrickedTruncation(t *testing.T) {
tmpDir, err := ioutil.TempDir(os.TempDir(), "pwn_truncate")
tmpDir, err := os.MkdirTemp(os.TempDir(), "pwn_truncate")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -148,12 +147,12 @@ func TestTrickedTruncation(t *testing.T) {
originalWALPath := filepath.Join(tmpDir, "wal") originalWALPath := filepath.Join(tmpDir, "wal")
originalWALContent := []byte("I AM BECOME DEATH, DESTROYER OF ALL WORLDS!") originalWALContent := []byte("I AM BECOME DEATH, DESTROYER OF ALL WORLDS!")
if err := ioutil.WriteFile(originalWALPath, originalWALContent, 0755); err != nil {
if err := os.WriteFile(originalWALPath, originalWALContent, 0755); err != nil {
t.Fatal(err) t.Fatal(err)
} }
// 1. Sanity check. // 1. Sanity check.
readWAL, err := ioutil.ReadFile(originalWALPath)
readWAL, err := os.ReadFile(originalWALPath)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -168,7 +167,7 @@ func TestTrickedTruncation(t *testing.T) {
} }
// 3. Check the WAL's content // 3. Check the WAL's content
reReadWAL, err := ioutil.ReadFile(originalWALPath)
reReadWAL, err := os.ReadFile(originalWALPath)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }


+ 1
- 2
light/example_test.go View File

@ -2,7 +2,6 @@ package light_test
import ( import (
"context" "context"
"io/ioutil"
stdlog "log" stdlog "log"
"os" "os"
"time" "time"
@ -38,7 +37,7 @@ func ExampleClient() {
} }
defer func() { _ = closer(ctx) }() defer func() { _ = closer(ctx) }()
dbDir, err := ioutil.TempDir("", "light-client-example")
dbDir, err := os.MkdirTemp("", "light-client-example")
if err != nil { if err != nil {
stdlog.Fatal(err) stdlog.Fatal(err)
} }


+ 2
- 3
light/light_test.go View File

@ -2,7 +2,6 @@ package light_test
import ( import (
"context" "context"
"io/ioutil"
"os" "os"
"testing" "testing"
"time" "time"
@ -41,7 +40,7 @@ func TestClientIntegration_Update(t *testing.T) {
// give Tendermint time to generate some blocks // give Tendermint time to generate some blocks
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
dbDir, err := ioutil.TempDir("", "light-client-test-update-example")
dbDir, err := os.MkdirTemp("", "light-client-test-update-example")
require.NoError(t, err) require.NoError(t, err)
defer os.RemoveAll(dbDir) defer os.RemoveAll(dbDir)
@ -100,7 +99,7 @@ func TestClientIntegration_VerifyLightBlockAtHeight(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
defer func() { require.NoError(t, closer(ctx)) }() defer func() { require.NoError(t, closer(ctx)) }()
dbDir, err := ioutil.TempDir("", "light-client-test-verify-example")
dbDir, err := os.MkdirTemp("", "light-client-test-verify-example")
require.NoError(t, err) require.NoError(t, err)
defer os.RemoveAll(dbDir) defer os.RemoveAll(dbDir)


+ 2
- 2
light/mbt/driver_test.go View File

@ -1,7 +1,7 @@
package mbt package mbt
import ( import (
"io/ioutil"
"os"
"path/filepath" "path/filepath"
"testing" "testing"
"time" "time"
@ -22,7 +22,7 @@ func TestVerify(t *testing.T) {
filename := filename filename := filename
t.Run(filename, func(t *testing.T) { t.Run(filename, func(t *testing.T) {
jsonBlob, err := ioutil.ReadFile(filename)
jsonBlob, err := os.ReadFile(filename)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }


+ 3
- 3
privval/file.go View File

@ -5,7 +5,7 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"os"
"time" "time"
"github.com/gogo/protobuf/proto" "github.com/gogo/protobuf/proto"
@ -200,7 +200,7 @@ func LoadFilePVEmptyState(keyFilePath, stateFilePath string) (*FilePV, error) {
// If loadState is true, we load from the stateFilePath. Otherwise, we use an empty LastSignState. // If loadState is true, we load from the stateFilePath. Otherwise, we use an empty LastSignState.
func loadFilePV(keyFilePath, stateFilePath string, loadState bool) (*FilePV, error) { func loadFilePV(keyFilePath, stateFilePath string, loadState bool) (*FilePV, error) {
keyJSONBytes, err := ioutil.ReadFile(keyFilePath)
keyJSONBytes, err := os.ReadFile(keyFilePath)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -218,7 +218,7 @@ func loadFilePV(keyFilePath, stateFilePath string, loadState bool) (*FilePV, err
pvState := FilePVLastSignState{} pvState := FilePVLastSignState{}
if loadState { if loadState {
stateJSONBytes, err := ioutil.ReadFile(stateFilePath)
stateJSONBytes, err := os.ReadFile(stateFilePath)
if err != nil { if err != nil {
return nil, err return nil, err
} }


+ 12
- 13
privval/file_test.go View File

@ -4,7 +4,6 @@ import (
"context" "context"
"encoding/base64" "encoding/base64"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"testing" "testing"
"time" "time"
@ -24,9 +23,9 @@ import (
func TestGenLoadValidator(t *testing.T) { func TestGenLoadValidator(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
tempKeyFile, err := ioutil.TempFile("", "priv_validator_key_")
tempKeyFile, err := os.CreateTemp("", "priv_validator_key_")
require.Nil(t, err) require.Nil(t, err)
tempStateFile, err := ioutil.TempFile("", "priv_validator_state_")
tempStateFile, err := os.CreateTemp("", "priv_validator_state_")
require.Nil(t, err) require.Nil(t, err)
privVal, err := GenFilePV(tempKeyFile.Name(), tempStateFile.Name(), "") privVal, err := GenFilePV(tempKeyFile.Name(), tempStateFile.Name(), "")
@ -44,9 +43,9 @@ func TestGenLoadValidator(t *testing.T) {
} }
func TestResetValidator(t *testing.T) { func TestResetValidator(t *testing.T) {
tempKeyFile, err := ioutil.TempFile("", "priv_validator_key_")
tempKeyFile, err := os.CreateTemp("", "priv_validator_key_")
require.Nil(t, err) require.Nil(t, err)
tempStateFile, err := ioutil.TempFile("", "priv_validator_state_")
tempStateFile, err := os.CreateTemp("", "priv_validator_state_")
require.Nil(t, err) require.Nil(t, err)
privVal, err := GenFilePV(tempKeyFile.Name(), tempStateFile.Name(), "") privVal, err := GenFilePV(tempKeyFile.Name(), tempStateFile.Name(), "")
@ -76,9 +75,9 @@ func TestResetValidator(t *testing.T) {
func TestLoadOrGenValidator(t *testing.T) { func TestLoadOrGenValidator(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
tempKeyFile, err := ioutil.TempFile("", "priv_validator_key_")
tempKeyFile, err := os.CreateTemp("", "priv_validator_key_")
require.Nil(t, err) require.Nil(t, err)
tempStateFile, err := ioutil.TempFile("", "priv_validator_state_")
tempStateFile, err := os.CreateTemp("", "priv_validator_state_")
require.Nil(t, err) require.Nil(t, err)
tempKeyFilePath := tempKeyFile.Name() tempKeyFilePath := tempKeyFile.Name()
@ -165,9 +164,9 @@ func TestUnmarshalValidatorKey(t *testing.T) {
func TestSignVote(t *testing.T) { func TestSignVote(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
tempKeyFile, err := ioutil.TempFile("", "priv_validator_key_")
tempKeyFile, err := os.CreateTemp("", "priv_validator_key_")
require.Nil(t, err) require.Nil(t, err)
tempStateFile, err := ioutil.TempFile("", "priv_validator_state_")
tempStateFile, err := os.CreateTemp("", "priv_validator_state_")
require.Nil(t, err) require.Nil(t, err)
privVal, err := GenFilePV(tempKeyFile.Name(), tempStateFile.Name(), "") privVal, err := GenFilePV(tempKeyFile.Name(), tempStateFile.Name(), "")
@ -219,9 +218,9 @@ func TestSignVote(t *testing.T) {
func TestSignProposal(t *testing.T) { func TestSignProposal(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
tempKeyFile, err := ioutil.TempFile("", "priv_validator_key_")
tempKeyFile, err := os.CreateTemp("", "priv_validator_key_")
require.Nil(t, err) require.Nil(t, err)
tempStateFile, err := ioutil.TempFile("", "priv_validator_state_")
tempStateFile, err := os.CreateTemp("", "priv_validator_state_")
require.Nil(t, err) require.Nil(t, err)
privVal, err := GenFilePV(tempKeyFile.Name(), tempStateFile.Name(), "") privVal, err := GenFilePV(tempKeyFile.Name(), tempStateFile.Name(), "")
@ -268,9 +267,9 @@ func TestSignProposal(t *testing.T) {
} }
func TestDifferByTimestamp(t *testing.T) { func TestDifferByTimestamp(t *testing.T) {
tempKeyFile, err := ioutil.TempFile("", "priv_validator_key_")
tempKeyFile, err := os.CreateTemp("", "priv_validator_key_")
require.Nil(t, err) require.Nil(t, err)
tempStateFile, err := ioutil.TempFile("", "priv_validator_state_")
tempStateFile, err := os.CreateTemp("", "priv_validator_state_")
require.Nil(t, err) require.Nil(t, err)
privVal, err := GenFilePV(tempKeyFile.Name(), tempStateFile.Name(), "") privVal, err := GenFilePV(tempKeyFile.Name(), tempStateFile.Name(), "")


+ 2
- 3
privval/grpc/util.go View File

@ -4,7 +4,6 @@ import (
"context" "context"
"crypto/tls" "crypto/tls"
"crypto/x509" "crypto/x509"
"io/ioutil"
"os" "os"
"time" "time"
@ -14,7 +13,7 @@ import (
"github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/log"
tmnet "github.com/tendermint/tendermint/libs/net" tmnet "github.com/tendermint/tendermint/libs/net"
grpc "google.golang.org/grpc"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials" "google.golang.org/grpc/credentials"
"google.golang.org/grpc/keepalive" "google.golang.org/grpc/keepalive"
) )
@ -65,7 +64,7 @@ func GenerateTLS(certPath, keyPath, ca string, log log.Logger) grpc.DialOption {
} }
certPool := x509.NewCertPool() certPool := x509.NewCertPool()
bs, err := ioutil.ReadFile(ca)
bs, err := os.ReadFile(ca)
if err != nil { if err != nil {
log.Error("failed to read ca cert:", "error", err) log.Error("failed to read ca cert:", "error", err)
os.Exit(1) os.Exit(1)


+ 1
- 2
privval/socket_listeners_test.go View File

@ -1,7 +1,6 @@
package privval package privval
import ( import (
"io/ioutil"
"net" "net"
"os" "os"
"testing" "testing"
@ -29,7 +28,7 @@ type listenerTestCase struct {
// testUnixAddr will attempt to obtain a platform-independent temporary file // testUnixAddr will attempt to obtain a platform-independent temporary file
// name for a Unix socket // name for a Unix socket
func testUnixAddr() (string, error) { func testUnixAddr() (string, error) {
f, err := ioutil.TempFile("", "tendermint-privval-test-*")
f, err := os.CreateTemp("", "tendermint-privval-test-*")
if err != nil { if err != nil {
return "", err return "", err
} }


+ 1
- 2
rpc/client/main_test.go View File

@ -3,7 +3,6 @@ package client_test
import ( import (
"context" "context"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"testing" "testing"
@ -24,7 +23,7 @@ func NodeSuite(t *testing.T) (service.Service, *config.Config) {
require.NoError(t, err) require.NoError(t, err)
// start a tendermint node in the background to test against // start a tendermint node in the background to test against
dir, err := ioutil.TempDir("/tmp", fmt.Sprint("rpc-client-test-", t.Name()))
dir, err := os.MkdirTemp("/tmp", fmt.Sprint("rpc-client-test-", t.Name()))
require.NoError(t, err) require.NoError(t, err)
app := kvstore.NewPersistentKVStoreApplication(dir) app := kvstore.NewPersistentKVStoreApplication(dir)


+ 3
- 3
rpc/jsonrpc/client/http_json_client.go View File

@ -6,7 +6,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"io"
"net" "net"
"net/http" "net/http"
"net/url" "net/url"
@ -219,7 +219,7 @@ func (c *Client) Call(
defer httpResponse.Body.Close() defer httpResponse.Body.Close()
responseBytes, err := ioutil.ReadAll(httpResponse.Body)
responseBytes, err := io.ReadAll(httpResponse.Body)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to read response body: %w", err) return nil, fmt.Errorf("failed to read response body: %w", err)
} }
@ -267,7 +267,7 @@ func (c *Client) sendBatch(ctx context.Context, requests []*jsonRPCBufferedReque
defer httpResponse.Body.Close() defer httpResponse.Body.Close()
responseBytes, err := ioutil.ReadAll(httpResponse.Body)
responseBytes, err := io.ReadAll(httpResponse.Body)
if err != nil { if err != nil {
return nil, fmt.Errorf("read response body: %w", err) return nil, fmt.Errorf("read response body: %w", err)
} }


+ 2
- 2
rpc/jsonrpc/client/http_json_client_test.go View File

@ -1,7 +1,7 @@
package client package client
import ( import (
"io/ioutil"
"io"
"log" "log"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
@ -21,7 +21,7 @@ func TestHTTPClientMakeHTTPDialer(t *testing.T) {
defer tsTLS.Close() defer tsTLS.Close()
// This silences a TLS handshake error, caused by the dialer just immediately // This silences a TLS handshake error, caused by the dialer just immediately
// disconnecting, which we can just ignore. // disconnecting, which we can just ignore.
tsTLS.Config.ErrorLog = log.New(ioutil.Discard, "", 0)
tsTLS.Config.ErrorLog = log.New(io.Discard, "", 0)
for _, testURL := range []string{ts.URL, tsTLS.URL} { for _, testURL := range []string{ts.URL, tsTLS.URL} {
u, err := newParsedURL(testURL) u, err := newParsedURL(testURL)


+ 2
- 2
rpc/jsonrpc/client/http_uri_client.go View File

@ -3,7 +3,7 @@ package client
import ( import (
"context" "context"
"fmt" "fmt"
"io/ioutil"
"io"
"net/http" "net/http"
"strings" "strings"
@ -76,7 +76,7 @@ func (c *URIClient) Call(ctx context.Context, method string,
} }
defer resp.Body.Close() defer resp.Body.Close()
responseBytes, err := ioutil.ReadAll(resp.Body)
responseBytes, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, fmt.Errorf("read response body: %w", err) return nil, fmt.Errorf("read response body: %w", err)
} }


+ 2
- 2
rpc/jsonrpc/server/http_json_handler.go View File

@ -5,7 +5,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"io"
"net/http" "net/http"
"reflect" "reflect"
"sort" "sort"
@ -21,7 +21,7 @@ import (
// jsonrpc calls grab the given method's function info and runs reflect.Call // jsonrpc calls grab the given method's function info and runs reflect.Call
func makeJSONRPCHandler(funcMap map[string]*RPCFunc, logger log.Logger) http.HandlerFunc { func makeJSONRPCHandler(funcMap map[string]*RPCFunc, logger log.Logger) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
if err != nil { if err != nil {
res := rpctypes.RPCInvalidRequestError(nil, res := rpctypes.RPCInvalidRequestError(nil,
fmt.Errorf("error reading request body: %w", err), fmt.Errorf("error reading request body: %w", err),


+ 7
- 7
rpc/jsonrpc/server/http_json_handler_test.go View File

@ -2,7 +2,7 @@ package server
import ( import (
"encoding/json" "encoding/json"
"io/ioutil"
"io"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"strings" "strings"
@ -65,7 +65,7 @@ func TestRPCParams(t *testing.T) {
defer res.Body.Close() defer res.Body.Close()
// Always expecting back a JSONRPCResponse // Always expecting back a JSONRPCResponse
assert.NotZero(t, res.StatusCode, "#%d: should always return code", i) assert.NotZero(t, res.StatusCode, "#%d: should always return code", i)
blob, err := ioutil.ReadAll(res.Body)
blob, err := io.ReadAll(res.Body)
if err != nil { if err != nil {
t.Errorf("#%d: err reading body: %v", i, err) t.Errorf("#%d: err reading body: %v", i, err)
continue continue
@ -112,7 +112,7 @@ func TestJSONRPCID(t *testing.T) {
res := rec.Result() res := rec.Result()
// Always expecting back a JSONRPCResponse // Always expecting back a JSONRPCResponse
assert.NotZero(t, res.StatusCode, "#%d: should always return code", i) assert.NotZero(t, res.StatusCode, "#%d: should always return code", i)
blob, err := ioutil.ReadAll(res.Body)
blob, err := io.ReadAll(res.Body)
if err != nil { if err != nil {
t.Errorf("#%d: err reading body: %v", i, err) t.Errorf("#%d: err reading body: %v", i, err)
continue continue
@ -142,7 +142,7 @@ func TestRPCNotification(t *testing.T) {
// Always expecting back a JSONRPCResponse // Always expecting back a JSONRPCResponse
require.True(t, statusOK(res.StatusCode), "should always return 2XX") require.True(t, statusOK(res.StatusCode), "should always return 2XX")
blob, err := ioutil.ReadAll(res.Body)
blob, err := io.ReadAll(res.Body)
res.Body.Close() res.Body.Close()
require.Nil(t, err, "reading from the body should not give back an error") require.Nil(t, err, "reading from the body should not give back an error")
require.Equal(t, len(blob), 0, "a notification SHOULD NOT be responded to by the server") require.Equal(t, len(blob), 0, "a notification SHOULD NOT be responded to by the server")
@ -178,7 +178,7 @@ func TestRPCNotificationInBatch(t *testing.T) {
res := rec.Result() res := rec.Result()
// Always expecting back a JSONRPCResponse // Always expecting back a JSONRPCResponse
assert.True(t, statusOK(res.StatusCode), "#%d: should always return 2XX", i) assert.True(t, statusOK(res.StatusCode), "#%d: should always return 2XX", i)
blob, err := ioutil.ReadAll(res.Body)
blob, err := io.ReadAll(res.Body)
if err != nil { if err != nil {
t.Errorf("#%d: err reading body: %v", i, err) t.Errorf("#%d: err reading body: %v", i, err)
continue continue
@ -239,7 +239,7 @@ func TestRPCResponseCache(t *testing.T) {
require.True(t, statusOK(res.StatusCode), "should always return 2XX") require.True(t, statusOK(res.StatusCode), "should always return 2XX")
require.Equal(t, "max-age=31536000", res.Header.Get("Cache-control")) require.Equal(t, "max-age=31536000", res.Header.Get("Cache-control"))
_, err := ioutil.ReadAll(res.Body)
_, err := io.ReadAll(res.Body)
res.Body.Close() res.Body.Close()
require.Nil(t, err, "reading from the body should not give back an error") require.Nil(t, err, "reading from the body should not give back an error")
@ -254,7 +254,7 @@ func TestRPCResponseCache(t *testing.T) {
require.True(t, statusOK(res.StatusCode), "should always return 2XX") require.True(t, statusOK(res.StatusCode), "should always return 2XX")
require.Equal(t, "", res.Header.Get("Cache-control")) require.Equal(t, "", res.Header.Get("Cache-control"))
_, err = ioutil.ReadAll(res.Body)
_, err = io.ReadAll(res.Body)
res.Body.Close() res.Body.Close()
require.Nil(t, err, "reading from the body should not give back an error") require.Nil(t, err, "reading from the body should not give back an error")
} }

+ 5
- 5
rpc/jsonrpc/server/http_server_test.go View File

@ -4,7 +4,7 @@ import (
"crypto/tls" "crypto/tls"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"io"
"net" "net"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
@ -101,7 +101,7 @@ func TestServeTLS(t *testing.T) {
defer res.Body.Close() defer res.Body.Close()
assert.Equal(t, http.StatusOK, res.StatusCode) assert.Equal(t, http.StatusOK, res.StatusCode)
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, []byte("some body"), body) assert.Equal(t, []byte("some body"), body)
} }
@ -114,7 +114,7 @@ func TestWriteRPCResponseHTTP(t *testing.T) {
err := WriteRPCResponseHTTP(w, true, rpctypes.NewRPCSuccessResponse(id, &sampleResult{"hello"})) err := WriteRPCResponseHTTP(w, true, rpctypes.NewRPCSuccessResponse(id, &sampleResult{"hello"}))
require.NoError(t, err) require.NoError(t, err)
resp := w.Result() resp := w.Result()
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
_ = resp.Body.Close() _ = resp.Body.Close()
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, 200, resp.StatusCode) assert.Equal(t, 200, resp.StatusCode)
@ -136,7 +136,7 @@ func TestWriteRPCResponseHTTP(t *testing.T) {
rpctypes.NewRPCSuccessResponse(id, &sampleResult{"world"})) rpctypes.NewRPCSuccessResponse(id, &sampleResult{"world"}))
require.NoError(t, err) require.NoError(t, err)
resp = w.Result() resp = w.Result()
body, err = ioutil.ReadAll(resp.Body)
body, err = io.ReadAll(resp.Body)
_ = resp.Body.Close() _ = resp.Body.Close()
require.NoError(t, err) require.NoError(t, err)
@ -165,7 +165,7 @@ func TestWriteRPCResponseHTTPError(t *testing.T) {
err := WriteRPCResponseHTTPError(w, rpctypes.RPCInternalError(rpctypes.JSONRPCIntID(-1), errors.New("foo"))) err := WriteRPCResponseHTTPError(w, rpctypes.RPCInternalError(rpctypes.JSONRPCIntID(-1), errors.New("foo")))
require.NoError(t, err) require.NoError(t, err)
resp := w.Result() resp := w.Result()
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
_ = resp.Body.Close() _ = resp.Body.Close()
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, http.StatusInternalServerError, resp.StatusCode) assert.Equal(t, http.StatusInternalServerError, resp.StatusCode)


+ 4
- 5
test/e2e/app/snapshots.go View File

@ -5,7 +5,6 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"math" "math"
"os" "os"
"path/filepath" "path/filepath"
@ -48,7 +47,7 @@ func (s *SnapshotStore) loadMetadata() error {
file := filepath.Join(s.dir, "metadata.json") file := filepath.Join(s.dir, "metadata.json")
metadata := []abci.Snapshot{} metadata := []abci.Snapshot{}
bz, err := ioutil.ReadFile(file)
bz, err := os.ReadFile(file)
switch { switch {
case errors.Is(err, os.ErrNotExist): case errors.Is(err, os.ErrNotExist):
case err != nil: case err != nil:
@ -75,7 +74,7 @@ func (s *SnapshotStore) saveMetadata() error {
// save the file to a new file and move it to make saving atomic. // save the file to a new file and move it to make saving atomic.
newFile := filepath.Join(s.dir, "metadata.json.new") newFile := filepath.Join(s.dir, "metadata.json.new")
file := filepath.Join(s.dir, "metadata.json") file := filepath.Join(s.dir, "metadata.json")
err = ioutil.WriteFile(newFile, bz, 0644) // nolint: gosec
err = os.WriteFile(newFile, bz, 0644) // nolint: gosec
if err != nil { if err != nil {
return err return err
} }
@ -96,7 +95,7 @@ func (s *SnapshotStore) Create(state *State) (abci.Snapshot, error) {
Hash: hashItems(state.Values), Hash: hashItems(state.Values),
Chunks: byteChunks(bz), Chunks: byteChunks(bz),
} }
err = ioutil.WriteFile(filepath.Join(s.dir, fmt.Sprintf("%v.json", state.Height)), bz, 0644)
err = os.WriteFile(filepath.Join(s.dir, fmt.Sprintf("%v.json", state.Height)), bz, 0644)
if err != nil { if err != nil {
return abci.Snapshot{}, err return abci.Snapshot{}, err
} }
@ -146,7 +145,7 @@ func (s *SnapshotStore) LoadChunk(height uint64, format uint32, chunk uint32) ([
defer s.RUnlock() defer s.RUnlock()
for _, snapshot := range s.metadata { for _, snapshot := range s.metadata {
if snapshot.Height == height && snapshot.Format == format { if snapshot.Height == height && snapshot.Format == format {
bz, err := ioutil.ReadFile(filepath.Join(s.dir, fmt.Sprintf("%v.json", height)))
bz, err := os.ReadFile(filepath.Join(s.dir, fmt.Sprintf("%v.json", height)))
if err != nil { if err != nil {
return nil, err return nil, err
} }


+ 2
- 3
test/e2e/app/state.go View File

@ -6,7 +6,6 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"sort" "sort"
"sync" "sync"
@ -45,7 +44,7 @@ func NewState(file string, persistInterval uint64) (*State, error) {
// load loads state from disk. It does not take out a lock, since it is called // load loads state from disk. It does not take out a lock, since it is called
// during construction. // during construction.
func (s *State) load() error { func (s *State) load() error {
bz, err := ioutil.ReadFile(s.file)
bz, err := os.ReadFile(s.file)
if err != nil { if err != nil {
return fmt.Errorf("failed to read state from %q: %w", s.file, err) return fmt.Errorf("failed to read state from %q: %w", s.file, err)
} }
@ -66,7 +65,7 @@ func (s *State) save() error {
// We write the state to a separate file and move it to the destination, to // We write the state to a separate file and move it to the destination, to
// make it atomic. // make it atomic.
newFile := fmt.Sprintf("%v.new", s.file) newFile := fmt.Sprintf("%v.new", s.file)
err = ioutil.WriteFile(newFile, bz, 0644)
err = os.WriteFile(newFile, bz, 0644)
if err != nil { if err != nil {
return fmt.Errorf("failed to write state to %q: %w", s.file, err) return fmt.Errorf("failed to write state to %q: %w", s.file, err)
} }


+ 2
- 2
test/e2e/runner/evidence.go View File

@ -5,8 +5,8 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"math/rand" "math/rand"
"os"
"path/filepath" "path/filepath"
"time" "time"
@ -232,7 +232,7 @@ func getRandomValidatorIndex(privVals []types.MockPV, vals *types.ValidatorSet)
} }
func readPrivKey(keyFilePath string) (crypto.PrivKey, error) { func readPrivKey(keyFilePath string) (crypto.PrivKey, error) {
keyJSONBytes, err := ioutil.ReadFile(keyFilePath)
keyJSONBytes, err := os.ReadFile(keyFilePath)
if err != nil { if err != nil {
return nil, err return nil, err
} }


+ 4
- 5
test/e2e/runner/setup.go View File

@ -7,7 +7,6 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"regexp" "regexp"
@ -51,7 +50,7 @@ func Setup(testnet *e2e.Testnet) error {
if err != nil { if err != nil {
return err return err
} }
err = ioutil.WriteFile(filepath.Join(testnet.Dir, "docker-compose.yml"), compose, 0644)
err = os.WriteFile(filepath.Join(testnet.Dir, "docker-compose.yml"), compose, 0644)
if err != nil { if err != nil {
return err return err
} }
@ -92,7 +91,7 @@ func Setup(testnet *e2e.Testnet) error {
if err != nil { if err != nil {
return err return err
} }
err = ioutil.WriteFile(filepath.Join(nodeDir, "config", "app.toml"), appCfg, 0644)
err = os.WriteFile(filepath.Join(nodeDir, "config", "app.toml"), appCfg, 0644)
if err != nil { if err != nil {
return err return err
} }
@ -410,11 +409,11 @@ func UpdateConfigStateSync(node *e2e.Node, height int64, hash []byte) error {
// FIXME Apparently there's no function to simply load a config file without // FIXME Apparently there's no function to simply load a config file without
// involving the entire Viper apparatus, so we'll just resort to regexps. // involving the entire Viper apparatus, so we'll just resort to regexps.
bz, err := ioutil.ReadFile(cfgPath)
bz, err := os.ReadFile(cfgPath)
if err != nil { if err != nil {
return err return err
} }
bz = regexp.MustCompile(`(?m)^trust-height =.*`).ReplaceAll(bz, []byte(fmt.Sprintf(`trust-height = %v`, height))) bz = regexp.MustCompile(`(?m)^trust-height =.*`).ReplaceAll(bz, []byte(fmt.Sprintf(`trust-height = %v`, height)))
bz = regexp.MustCompile(`(?m)^trust-hash =.*`).ReplaceAll(bz, []byte(fmt.Sprintf(`trust-hash = "%X"`, hash))) bz = regexp.MustCompile(`(?m)^trust-hash =.*`).ReplaceAll(bz, []byte(fmt.Sprintf(`trust-hash = "%X"`, hash)))
return ioutil.WriteFile(cfgPath, bz, 0644)
return os.WriteFile(cfgPath, bz, 0644)
} }

+ 2
- 2
test/fuzz/mempool/v0/fuzz_test.go View File

@ -1,7 +1,7 @@
package v0_test package v0_test
import ( import (
"io/ioutil"
"io"
"os" "os"
"path/filepath" "path/filepath"
"testing" "testing"
@ -25,7 +25,7 @@ func TestMempoolTestdataCases(t *testing.T) {
}() }()
f, err := os.Open(filepath.Join(testdataCasesDir, entry.Name())) f, err := os.Open(filepath.Join(testdataCasesDir, entry.Name()))
require.NoError(t, err) require.NoError(t, err)
input, err := ioutil.ReadAll(f)
input, err := io.ReadAll(f)
require.NoError(t, err) require.NoError(t, err)
mempoolv0.Fuzz(input) mempoolv0.Fuzz(input)
}) })


+ 2
- 2
test/fuzz/mempool/v1/fuzz_test.go View File

@ -1,7 +1,7 @@
package v1_test package v1_test
import ( import (
"io/ioutil"
"io"
"os" "os"
"path/filepath" "path/filepath"
"testing" "testing"
@ -25,7 +25,7 @@ func TestMempoolTestdataCases(t *testing.T) {
}() }()
f, err := os.Open(filepath.Join(testdataCasesDir, entry.Name())) f, err := os.Open(filepath.Join(testdataCasesDir, entry.Name()))
require.NoError(t, err) require.NoError(t, err)
input, err := ioutil.ReadAll(f)
input, err := io.ReadAll(f)
require.NoError(t, err) require.NoError(t, err)
mempoolv1.Fuzz(input) mempoolv1.Fuzz(input)
}) })


+ 2
- 2
test/fuzz/p2p/secretconnection/fuzz_test.go View File

@ -1,7 +1,7 @@
package secretconnection_test package secretconnection_test
import ( import (
"io/ioutil"
"io"
"os" "os"
"path/filepath" "path/filepath"
"testing" "testing"
@ -25,7 +25,7 @@ func TestSecretConnectionTestdataCases(t *testing.T) {
}() }()
f, err := os.Open(filepath.Join(testdataCasesDir, entry.Name())) f, err := os.Open(filepath.Join(testdataCasesDir, entry.Name()))
require.NoError(t, err) require.NoError(t, err)
input, err := ioutil.ReadAll(f)
input, err := io.ReadAll(f)
require.NoError(t, err) require.NoError(t, err)
secretconnection.Fuzz(input) secretconnection.Fuzz(input)
}) })


+ 1
- 2
test/fuzz/p2p/secretconnection/init-corpus/main.go View File

@ -4,7 +4,6 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"io/ioutil"
"log" "log"
"os" "os"
"path/filepath" "path/filepath"
@ -39,7 +38,7 @@ func initCorpus(baseDir string) {
for i, datum := range data { for i, datum := range data {
filename := filepath.Join(corpusDir, fmt.Sprintf("%d", i)) filename := filepath.Join(corpusDir, fmt.Sprintf("%d", i))
if err := ioutil.WriteFile(filename, []byte(datum), 0644); err != nil {
if err := os.WriteFile(filename, []byte(datum), 0644); err != nil {
log.Fatalf("can't write %v to %q: %v", datum, filename, err) log.Fatalf("can't write %v to %q: %v", datum, filename, err)
} }


+ 2
- 2
test/fuzz/rpc/jsonrpc/server/fuzz_test.go View File

@ -1,7 +1,7 @@
package server_test package server_test
import ( import (
"io/ioutil"
"io"
"os" "os"
"path/filepath" "path/filepath"
"testing" "testing"
@ -25,7 +25,7 @@ func TestServerTestdataCases(t *testing.T) {
}() }()
f, err := os.Open(filepath.Join(testdataCasesDir, entry.Name())) f, err := os.Open(filepath.Join(testdataCasesDir, entry.Name()))
require.NoError(t, err) require.NoError(t, err)
input, err := ioutil.ReadAll(f)
input, err := io.ReadAll(f)
require.NoError(t, err) require.NoError(t, err)
server.Fuzz(input) server.Fuzz(input)
}) })


+ 3
- 3
test/fuzz/rpc/jsonrpc/server/handler.go View File

@ -3,13 +3,13 @@ package server
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"io/ioutil"
"io"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/log"
rs "github.com/tendermint/tendermint/rpc/jsonrpc/server" rs "github.com/tendermint/tendermint/rpc/jsonrpc/server"
types "github.com/tendermint/tendermint/rpc/jsonrpc/types"
"github.com/tendermint/tendermint/rpc/jsonrpc/types"
) )
var rpcFuncMap = map[string]*rs.RPCFunc{ var rpcFuncMap = map[string]*rs.RPCFunc{
@ -32,7 +32,7 @@ func Fuzz(data []byte) int {
rec := httptest.NewRecorder() rec := httptest.NewRecorder()
mux.ServeHTTP(rec, req) mux.ServeHTTP(rec, req)
res := rec.Result() res := rec.Result()
blob, err := ioutil.ReadAll(res.Body)
blob, err := io.ReadAll(res.Body)
if err != nil { if err != nil {
panic(err) panic(err)
} }


+ 1
- 2
tools/tm-signer-harness/internal/test_harness_test.go View File

@ -2,7 +2,6 @@ package internal
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"testing" "testing"
"time" "time"
@ -187,7 +186,7 @@ func cleanup(cfg TestHarnessConfig) {
} }
func makeTempFile(name, content string) string { func makeTempFile(name, content string) string {
tempFile, err := ioutil.TempFile("", fmt.Sprintf("%s-*", name))
tempFile, err := os.CreateTemp("", fmt.Sprintf("%s-*", name))
if err != nil { if err != nil {
panic(err) panic(err)
} }


+ 1
- 2
tools/tm-signer-harness/main.go View File

@ -3,7 +3,6 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"time" "time"
@ -149,7 +148,7 @@ func extractKey(tmhome, outputPath string) {
os.Exit(1) os.Exit(1)
} }
pkb := []byte(fpv.Key.PrivKey.(ed25519.PrivKey)) pkb := []byte(fpv.Key.PrivKey.(ed25519.PrivKey))
if err := ioutil.WriteFile(internal.ExpandPath(outputPath), pkb[:32], 0600); err != nil {
if err := os.WriteFile(internal.ExpandPath(outputPath), pkb[:32], 0600); err != nil {
logger.Info("Failed to write private key", "output", outputPath, "err", err) logger.Info("Failed to write private key", "output", outputPath, "err", err)
os.Exit(1) os.Exit(1)
} }


+ 3
- 3
types/genesis.go View File

@ -5,7 +5,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"os"
"time" "time"
"github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto"
@ -51,7 +51,7 @@ func (genDoc *GenesisDoc) SaveAs(file string) error {
return err return err
} }
return ioutil.WriteFile(file, genDocBytes, 0644) // nolint:gosec
return os.WriteFile(file, genDocBytes, 0644) // nolint:gosec
} }
// ValidatorHash returns the hash of the validator set contained in the GenesisDoc // ValidatorHash returns the hash of the validator set contained in the GenesisDoc
@ -125,7 +125,7 @@ func GenesisDocFromJSON(jsonBlob []byte) (*GenesisDoc, error) {
// GenesisDocFromFile reads JSON data from a file and unmarshalls it into a GenesisDoc. // GenesisDocFromFile reads JSON data from a file and unmarshalls it into a GenesisDoc.
func GenesisDocFromFile(genDocFile string) (*GenesisDoc, error) { func GenesisDocFromFile(genDocFile string) (*GenesisDoc, error) {
jsonBlob, err := ioutil.ReadFile(genDocFile)
jsonBlob, err := os.ReadFile(genDocFile)
if err != nil { if err != nil {
return nil, fmt.Errorf("couldn't read GenesisDoc file: %w", err) return nil, fmt.Errorf("couldn't read GenesisDoc file: %w", err)
} }


+ 1
- 2
types/genesis_test.go View File

@ -1,7 +1,6 @@
package types package types
import ( import (
"io/ioutil"
"os" "os"
"testing" "testing"
@ -122,7 +121,7 @@ func TestGenesisGood(t *testing.T) {
} }
func TestGenesisSaveAs(t *testing.T) { func TestGenesisSaveAs(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "genesis")
tmpfile, err := os.CreateTemp("", "genesis")
require.NoError(t, err) require.NoError(t, err)
defer os.Remove(tmpfile.Name()) defer os.Remove(tmpfile.Name())


+ 3
- 3
types/node_key.go View File

@ -1,7 +1,7 @@
package types package types
import ( import (
"io/ioutil"
"os"
"github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519" "github.com/tendermint/tendermint/crypto/ed25519"
@ -33,7 +33,7 @@ func (nodeKey NodeKey) SaveAs(filePath string) error {
if err != nil { if err != nil {
return err return err
} }
return ioutil.WriteFile(filePath, jsonBytes, 0600)
return os.WriteFile(filePath, jsonBytes, 0600)
} }
// LoadOrGenNodeKey attempts to load the NodeKey from the given filePath. If // LoadOrGenNodeKey attempts to load the NodeKey from the given filePath. If
@ -67,7 +67,7 @@ func GenNodeKey() NodeKey {
// LoadNodeKey loads NodeKey located in filePath. // LoadNodeKey loads NodeKey located in filePath.
func LoadNodeKey(filePath string) (NodeKey, error) { func LoadNodeKey(filePath string) (NodeKey, error) {
jsonBytes, err := ioutil.ReadFile(filePath)
jsonBytes, err := os.ReadFile(filePath)
if err != nil { if err != nil {
return NodeKey{}, err return NodeKey{}, err
} }


+ 2
- 2
types/part_set_test.go View File

@ -1,7 +1,7 @@
package types package types
import ( import (
"io/ioutil"
"io"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -57,7 +57,7 @@ func TestBasicPartSet(t *testing.T) {
// Reconstruct data, assert that they are equal. // Reconstruct data, assert that they are equal.
data2Reader := partSet2.GetReader() data2Reader := partSet2.GetReader()
data2, err := ioutil.ReadAll(data2Reader)
data2, err := io.ReadAll(data2Reader)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, data, data2) assert.Equal(t, data, data2)


Loading…
Cancel
Save