refactor: move from io/ioutil to io and os package (#10341)

## Description

The `io/ioutil` package has been deprecated in Go 1.16 (See https://golang.org/doc/go1.16#ioutil). Since cosmos-sdk has upgraded to Go 1.17 (#9987), this PR replaces the existing `io/ioutil` functions with their new definitions in `io` and `os` packages.

---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [x] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [x] reviewed "Files changed" and left comments if necessary
- [x] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed 
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
This commit is contained in:
Eng Zer Jun 2021-10-13 15:38:22 +08:00 committed by GitHub
parent 33f3b69d05
commit 40a92a2aec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
44 changed files with 97 additions and 120 deletions

View File

@ -126,6 +126,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [\#9699](https://github.com/cosmos/cosmos-sdk/pull/9699) Add `:`, `.`, `-`, and `_` as allowed characters in the default denom regular expression.
* (genesis) [\#9697](https://github.com/cosmos/cosmos-sdk/pull/9697) Ensure `InitGenesis` returns with non-empty validator set.
* [\#10262](https://github.com/cosmos/cosmos-sdk/pull/10262) Remove unnecessary logging in `x/feegrant` simulation.
* [\#10341](https://github.com/cosmos/cosmos-sdk/pull/10341) Move from `io/ioutil` to `io` and `os` packages.
### Bug Fixes

View File

@ -5,7 +5,6 @@ import (
"encoding/binary"
"encoding/json"
"fmt"
"io/ioutil"
"math"
"math/rand"
"os"
@ -162,7 +161,7 @@ func setupBaseAppWithSnapshots(t *testing.T, blocks uint, blockTxs int, options
snapshotInterval := uint64(2)
snapshotTimeout := 1 * time.Minute
snapshotDir, err := ioutil.TempDir("", "baseapp")
snapshotDir, err := os.MkdirTemp("", "baseapp")
require.NoError(t, err)
snapshotStore, err := snapshots.NewStore(dbm.NewMemDB(), snapshotDir)
require.NoError(t, err)
@ -934,7 +933,7 @@ func incrementingCounter(t *testing.T, store sdk.KVStore, counterKey []byte, cou
return &sdk.Result{}, nil
}
//---------------------------------------------------------------------
// ---------------------------------------------------------------------
// Tx processing - CheckTx, DeliverTx, SimulateTx.
// These tests use the serialized tx as input, while most others will use the
// Check(), Deliver(), Simulate() methods directly.

View File

@ -3,7 +3,7 @@ package config_test
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"os"
"testing"
@ -58,7 +58,7 @@ func TestConfigCmd(t *testing.T) {
cmd.SetOut(b)
cmd.SetArgs([]string{"node"})
cmd.Execute()
out, err := ioutil.ReadAll(b)
out, err := io.ReadAll(b)
require.NoError(t, err)
require.Equal(t, string(out), testNode1+"\n")
}

View File

@ -2,7 +2,6 @@ package config
import (
"bytes"
"io/ioutil"
"os"
"text/template"
@ -43,7 +42,7 @@ func writeConfigToFile(configFilePath string, config *ClientConfig) error {
return err
}
return ioutil.WriteFile(configFilePath, buffer.Bytes(), 0600)
return os.WriteFile(configFilePath, buffer.Bytes(), 0600)
}
// ensureConfigPath creates a directory configPath if it does not exist

View File

@ -6,7 +6,7 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"io"
"testing"
"github.com/stretchr/testify/require"
@ -188,7 +188,7 @@ func Test_runAddCmdLedgerDryRun(t *testing.T) {
_, err = kb.Key("testkey")
require.NoError(t, err)
out, err := ioutil.ReadAll(b)
out, err := io.ReadAll(b)
require.NoError(t, err)
require.Contains(t, string(out), "name: testkey")
} else {

View File

@ -4,7 +4,7 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"io"
"testing"
"github.com/stretchr/testify/require"
@ -18,7 +18,7 @@ import (
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
bip39 "github.com/cosmos/go-bip39"
"github.com/cosmos/go-bip39"
)
func Test_runAddCmdBasic(t *testing.T) {
@ -220,7 +220,7 @@ func Test_runAddCmdDryRun(t *testing.T) {
_, err := kb.Key("testkey")
require.NoError(t, err)
out, err := ioutil.ReadAll(b)
out, err := io.ReadAll(b)
require.NoError(t, err)
require.Contains(t, string(out), "name: testkey")
} else {

View File

@ -2,7 +2,7 @@ package keys
import (
"bufio"
"io/ioutil"
"os"
"github.com/spf13/cobra"
@ -24,7 +24,7 @@ func ImportKeyCommand() *cobra.Command {
}
buf := bufio.NewReader(clientCtx.Input)
bz, err := ioutil.ReadFile(args[1])
bz, err := os.ReadFile(args[1])
if err != nil {
return err
}

View File

@ -3,7 +3,6 @@ package keys
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -98,7 +97,7 @@ HbP+c6JmeJy9JXe2rbbF1QtCX1gLqGcDQPBXiCtFvP7/8wTZtVOPj8vREzhZ9ElO
keyfile := filepath.Join(kbHome, "key.asc")
require.NoError(t, ioutil.WriteFile(keyfile, []byte(armoredKey), 0644))
require.NoError(t, os.WriteFile(keyfile, []byte(armoredKey), 0644))
defer func() {
_ = os.RemoveAll(kbHome)

View File

@ -5,7 +5,7 @@ import (
"compress/gzip"
"errors"
"fmt"
"io/ioutil"
"io"
"reflect"
"strings"
"sync"
@ -358,7 +358,7 @@ func extractFileDescMessageDesc(desc descriptorIface) (*descriptor.FileDescripto
if err != nil {
return nil, nil, err
}
protoBlob, err := ioutil.ReadAll(gzr)
protoBlob, err := io.ReadAll(gzr)
if err != nil {
return nil, nil, err
}

View File

@ -2,7 +2,6 @@ package container_test
import (
"fmt"
"io/ioutil"
"os"
"reflect"
"testing"
@ -506,14 +505,14 @@ func TestLogging(t *testing.T) {
var logOut string
var dotGraph string
outfile, err := ioutil.TempFile("", "out")
outfile, err := os.CreateTemp("", "out")
require.NoError(t, err)
stdout := os.Stdout
os.Stdout = outfile
defer func() { os.Stdout = stdout }()
defer os.Remove(outfile.Name())
graphfile, err := ioutil.TempFile("", "graph")
graphfile, err := os.CreateTemp("", "graph")
require.NoError(t, err)
defer os.Remove(graphfile.Name())
@ -533,11 +532,11 @@ func TestLogging(t *testing.T) {
require.Contains(t, logOut, "digraph")
require.Contains(t, dotGraph, "digraph")
outfileContents, err := ioutil.ReadFile(outfile.Name())
outfileContents, err := os.ReadFile(outfile.Name())
require.NoError(t, err)
require.Contains(t, string(outfileContents), "digraph")
graphfileContents, err := ioutil.ReadFile(graphfile.Name())
graphfileContents, err := os.ReadFile(graphfile.Name())
require.NoError(t, err)
require.Contains(t, string(graphfileContents), "<svg")
}

View File

@ -4,7 +4,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/url"
"os"
"path/filepath"
@ -246,7 +245,7 @@ func (cfg *Config) UpgradeInfo() UpgradeInfo {
if err != nil { // no current directory
goto returnError
}
if bz, err = ioutil.ReadFile(filename); err != nil {
if bz, err = os.ReadFile(filename); err != nil {
goto returnError
}
if err = json.Unmarshal(bz, &u); err != nil {

View File

@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"os/signal"
@ -113,7 +112,7 @@ func doBackup(cfg *Config) error {
if !cfg.UnsafeSkipBackup {
// check if upgrade-info.json is not empty.
var uInfo UpgradeInfo
upgradeInfoFile, err := ioutil.ReadFile(filepath.Join(cfg.Home, "data", "upgrade-info.json"))
upgradeInfoFile, err := os.ReadFile(filepath.Join(cfg.Home, "data", "upgrade-info.json"))
if err != nil {
return fmt.Errorf("error while reading upgrade-info.json: %w", err)
}

View File

@ -4,7 +4,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/url"
"os"
"path/filepath"
@ -108,7 +107,7 @@ func GetDownloadURL(info UpgradeInfo) (string, error) {
doc := strings.TrimSpace(info.Info)
// if this is a url, then we download that and try to get a new doc with the real info
if _, err := url.Parse(doc); err == nil {
tmpDir, err := ioutil.TempDir("", "upgrade-manager-reference")
tmpDir, err := os.MkdirTemp("", "upgrade-manager-reference")
if err != nil {
return "", fmt.Errorf("create tempdir for reference file: %w", err)
}
@ -119,7 +118,7 @@ func GetDownloadURL(info UpgradeInfo) (string, error) {
return "", fmt.Errorf("downloading reference link %s: %w", doc, err)
}
refBytes, err := ioutil.ReadFile(refPath)
refBytes, err := os.ReadFile(refPath)
if err != nil {
return "", fmt.Errorf("reading downloaded reference: %w", err)
}

View File

@ -4,7 +4,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"testing"
"github.com/stretchr/testify/require"
@ -35,7 +35,7 @@ func initFundraiserTestVectors(t *testing.T) []addrData {
// var hdPath string = "m/44'/118'/0'/0/0"
var hdToAddrTable []addrData
b, err := ioutil.ReadFile("testdata/test.json")
b, err := os.ReadFile("testdata/test.json")
if err != nil {
t.Fatalf("could not read fundraiser test vector file (testdata/test.json): %s", err)
}

View File

@ -5,7 +5,6 @@ import (
"encoding/hex"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"sort"
@ -682,7 +681,7 @@ func newRealPrompt(dir string, buf io.Reader) func(string) (string, error) {
switch {
case err == nil:
keyhash, err = ioutil.ReadFile(keyhashFilePath)
keyhash, err = os.ReadFile(keyhashFilePath)
if err != nil {
return "", fmt.Errorf("failed to read %s: %v", keyhashFilePath, err)
}
@ -746,7 +745,7 @@ func newRealPrompt(dir string, buf io.Reader) func(string) (string, error) {
continue
}
if err := ioutil.WriteFile(dir+"/keyhash", passwordHash, 0555); err != nil {
if err := os.WriteFile(dir+"/keyhash", passwordHash, 0555); err != nil {
return "", err
}

View File

@ -4,7 +4,6 @@ package server
import (
"fmt"
"io/ioutil"
"os"
"github.com/spf13/cobra"
@ -49,7 +48,7 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com
return err
}
genesis, err := ioutil.ReadFile(config.GenesisFile())
genesis, err := os.ReadFile(config.GenesisFile())
if err != nil {
return err
}

View File

@ -41,7 +41,6 @@ import (
"compress/gzip"
"fmt"
"io"
"io/ioutil"
"log"
"reflect"
"sort"
@ -219,7 +218,7 @@ func decompress(b []byte) ([]byte, error) {
if err != nil {
return nil, fmt.Errorf("bad gzipped descriptor: %v", err)
}
out, err := ioutil.ReadAll(r)
out, err := io.ReadAll(r)
if err != nil {
return nil, fmt.Errorf("bad gzipped descriptor: %v", err)
}

View File

@ -7,7 +7,6 @@ import (
"encoding/binary"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/textproto"
"strconv"
@ -197,7 +196,7 @@ func (s *GRPCWebTestSuite) makeGrpcRequest(
return nil, Trailer{}, nil, err
}
defer resp.Body.Close()
contents, err := ioutil.ReadAll(resp.Body)
contents, err := io.ReadAll(resp.Body)
if err != nil {
return nil, Trailer{}, nil, err
}

View File

@ -2,7 +2,6 @@ package mock
import (
"fmt"
"io/ioutil"
"os"
abci "github.com/tendermint/tendermint/abci/types"
@ -14,7 +13,7 @@ import (
func SetupApp() (abci.Application, func(), error) {
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)).
With("module", "mock")
rootDir, err := ioutil.TempDir("", "mock-sdk")
rootDir, err := os.MkdirTemp("", "mock-sdk")
if err != nil {
return nil, nil, err
}

View File

@ -4,8 +4,8 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"math/rand"
"os"
"time"
tmjson "github.com/tendermint/tendermint/libs/json"
@ -55,7 +55,7 @@ func AppStateFn(cdc codec.JSONCodec, simManager *module.SimulationManager) simty
case config.ParamsFile != "":
appParams := make(simtypes.AppParams)
bz, err := ioutil.ReadFile(config.ParamsFile)
bz, err := os.ReadFile(config.ParamsFile)
if err != nil {
panic(err)
}
@ -194,7 +194,7 @@ func AppStateRandomizedFn(
// AppStateFromGenesisFileFn util function to generate the genesis AppState
// from a genesis.json file.
func AppStateFromGenesisFileFn(r io.Reader, cdc codec.JSONCodec, genesisFile string) (tmtypes.GenesisDoc, []simtypes.Account) {
bytes, err := ioutil.ReadFile(genesisFile)
bytes, err := os.ReadFile(genesisFile)
if err != nil {
panic(err)
}

View File

@ -3,7 +3,7 @@ package simapp
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"github.com/tendermint/tendermint/libs/log"
dbm "github.com/tendermint/tm-db"
@ -34,7 +34,7 @@ func SetupSimulation(dirPrefix, dbName string) (simtypes.Config, dbm.DB, string,
logger = log.NewNopLogger()
}
dir, err := ioutil.TempDir("", dirPrefix)
dir, err := os.MkdirTemp("", dirPrefix)
if err != nil {
return simtypes.Config{}, nil, "", nil, false, err
}
@ -56,7 +56,7 @@ func SimulationOperations(app App, cdc codec.JSONCodec, config simtypes.Config)
}
if config.ParamsFile != "" {
bz, err := ioutil.ReadFile(config.ParamsFile)
bz, err := os.ReadFile(config.ParamsFile)
if err != nil {
panic(err)
}
@ -84,7 +84,7 @@ func CheckExportSimulation(
return err
}
if err := ioutil.WriteFile(config.ExportStatePath, []byte(exported.AppState), 0600); err != nil {
if err := os.WriteFile(config.ExportStatePath, []byte(exported.AppState), 0600); err != nil {
return err
}
}
@ -96,7 +96,7 @@ func CheckExportSimulation(
return err
}
if err := ioutil.WriteFile(config.ExportParamsPath, paramsBz, 0600); err != nil {
if err := os.WriteFile(config.ExportParamsPath, paramsBz, 0600); err != nil {
return err
}
}

View File

@ -5,7 +5,6 @@ import (
"crypto/sha256"
"errors"
"io"
"io/ioutil"
"os"
"testing"
"time"
@ -39,7 +38,7 @@ func hash(chunks [][]byte) []byte {
func makeChunks(chunks [][]byte) <-chan io.ReadCloser {
ch := make(chan io.ReadCloser, len(chunks))
for _, chunk := range chunks {
ch <- ioutil.NopCloser(bytes.NewReader(chunk))
ch <- io.NopCloser(bytes.NewReader(chunk))
}
close(ch)
return ch
@ -48,7 +47,7 @@ func makeChunks(chunks [][]byte) <-chan io.ReadCloser {
func readChunks(chunks <-chan io.ReadCloser) [][]byte {
bodies := [][]byte{}
for chunk := range chunks {
body, err := ioutil.ReadAll(chunk)
body, err := io.ReadAll(chunk)
if err != nil {
panic(err)
}
@ -76,7 +75,7 @@ func (m *mockSnapshotter) Restore(
m.chunks = [][]byte{}
for reader := range chunks {
chunk, err := ioutil.ReadAll(reader)
chunk, err := io.ReadAll(reader)
if err != nil {
return err
}
@ -92,7 +91,7 @@ func (m *mockSnapshotter) Snapshot(height uint64, format uint32) (<-chan io.Read
}
ch := make(chan io.ReadCloser, len(m.chunks))
for _, chunk := range m.chunks {
ch <- ioutil.NopCloser(bytes.NewReader(chunk))
ch <- io.NopCloser(bytes.NewReader(chunk))
}
close(ch)
return ch, nil
@ -101,10 +100,10 @@ func (m *mockSnapshotter) Snapshot(height uint64, format uint32) (<-chan io.Read
// setupBusyManager creates a manager with an empty store that is busy creating a snapshot at height 1.
// The snapshot will complete when the returned closer is called.
func setupBusyManager(t *testing.T) *snapshots.Manager {
// ioutil.TempDir() is used instead of testing.T.TempDir()
// os.MkdirTemp() is used instead of testing.T.TempDir()
// see https://github.com/cosmos/cosmos-sdk/pull/8475 for
// this change's rationale.
tempdir, err := ioutil.TempDir("", "")
tempdir, err := os.MkdirTemp("", "")
require.NoError(t, err)
t.Cleanup(func() { _ = os.RemoveAll(tempdir) })
@ -141,7 +140,7 @@ func (m *hungSnapshotter) Close() {
func (m *hungSnapshotter) Snapshot(height uint64, format uint32) (<-chan io.ReadCloser, error) {
<-m.ch
ch := make(chan io.ReadCloser, 1)
ch <- ioutil.NopCloser(bytes.NewReader([]byte{}))
ch <- io.NopCloser(bytes.NewReader([]byte{}))
return ch, nil
}

View File

@ -4,7 +4,6 @@ import (
"bytes"
"crypto/sha256"
"io"
"io/ioutil"
"sync"
"github.com/cosmos/cosmos-sdk/snapshots/types"
@ -144,7 +143,7 @@ func (m *Manager) LoadChunk(height uint64, format uint32, chunk uint32) ([]byte,
}
defer reader.Close()
return ioutil.ReadAll(reader)
return io.ReadAll(reader)
}
// Prune prunes snapshots, if no other operations are in progress.
@ -239,7 +238,7 @@ func (m *Manager) RestoreChunk(chunk []byte) (bool, error) {
}
// Pass the chunk to the restore, and wait for completion if it was the final one.
m.chRestore <- ioutil.NopCloser(bytes.NewReader(chunk))
m.chRestore <- io.NopCloser(bytes.NewReader(chunk))
m.restoreChunkIndex++
if int(m.restoreChunkIndex) >= len(m.restoreChunkHashes) {

View File

@ -4,7 +4,6 @@ import (
"bytes"
"errors"
"io"
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -20,10 +19,10 @@ import (
)
func setupStore(t *testing.T) *snapshots.Store {
// ioutil.TempDir() is used instead of testing.T.TempDir()
// os.MkdirTemp() is used instead of testing.T.TempDir()
// see https://github.com/cosmos/cosmos-sdk/pull/8475 for
// this change's rationale.
tempdir, err := ioutil.TempDir("", "")
tempdir, err := os.MkdirTemp("", "")
require.NoError(t, err)
t.Cleanup(func() { _ = os.RemoveAll(tempdir) })
@ -195,7 +194,7 @@ func TestStore_Load(t *testing.T) {
for i := uint32(0); i < snapshot.Chunks; i++ {
reader, ok := <-chunks
require.True(t, ok)
chunk, err := ioutil.ReadAll(reader)
chunk, err := io.ReadAll(reader)
require.NoError(t, err)
err = reader.Close()
require.NoError(t, err)
@ -220,7 +219,7 @@ func TestStore_LoadChunk(t *testing.T) {
chunk, err = store.LoadChunk(2, 1, 0)
require.NoError(t, err)
require.NotNil(t, chunk)
body, err := ioutil.ReadAll(chunk)
body, err := io.ReadAll(chunk)
require.NoError(t, err)
assert.Equal(t, []byte{2, 1, 0}, body)
err = chunk.Close()
@ -314,7 +313,7 @@ func TestStore_Save(t *testing.T) {
ch := make(chan io.ReadCloser, 2)
ch <- pr
ch <- ioutil.NopCloser(bytes.NewBuffer([]byte{0xff}))
ch <- io.NopCloser(bytes.NewBuffer([]byte{0xff}))
close(ch)
_, err = store.Save(6, 1, ch)

View File

@ -4,7 +4,6 @@ import (
"bytes"
"errors"
"io"
"io/ioutil"
"testing"
"github.com/stretchr/testify/assert"
@ -66,10 +65,10 @@ func TestChunkWriter(t *testing.T) {
require.NoError(t, err)
chunkWriter.CloseWithError(theErr)
}()
chunk, err := ioutil.ReadAll(<-ch)
chunk, err := io.ReadAll(<-ch)
require.NoError(t, err)
assert.Equal(t, []byte{1, 2}, chunk)
_, err = ioutil.ReadAll(<-ch)
_, err = io.ReadAll(<-ch)
require.Error(t, err)
assert.Equal(t, theErr, err)
assert.Empty(t, ch)
@ -144,7 +143,7 @@ func TestChunkReader(t *testing.T) {
// Closing the reader should close the writer
pr, pw = io.Pipe()
pch = make(chan io.ReadCloser, 2)
pch <- ioutil.NopCloser(bytes.NewBuffer([]byte{1, 2, 3}))
pch <- io.NopCloser(bytes.NewBuffer([]byte{1, 2, 3}))
pch <- pr
close(pch)

View File

@ -8,7 +8,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"math/rand"
"testing"
@ -842,7 +841,7 @@ func benchmarkMultistoreSnapshot(b *testing.B, stores uint8, storeKeys uint64) {
chunks, err := source.Snapshot(uint64(version), snapshottypes.CurrentFormat)
require.NoError(b, err)
for reader := range chunks {
_, err := io.Copy(ioutil.Discard, reader)
_, err := io.Copy(io.Discard, reader)
require.NoError(b, err)
err = reader.Close()
require.NoError(b, err)

View File

@ -3,7 +3,6 @@ package testutil
import (
"bytes"
"io"
"io/ioutil"
"os"
"strings"
"testing"
@ -45,8 +44,8 @@ func ApplyMockIODiscardOutErr(c *cobra.Command) BufferReader {
mockIn := strings.NewReader("")
c.SetIn(mockIn)
c.SetOut(ioutil.Discard)
c.SetErr(ioutil.Discard)
c.SetOut(io.Discard)
c.SetErr(io.Discard)
return mockIn
}
@ -68,7 +67,7 @@ func WriteToNewTempFile(t testing.TB, s string) *os.File {
func TempFile(t testing.TB) *os.File {
t.Helper()
fp, err := ioutil.TempFile(t.TempDir(), "")
fp, err := os.CreateTemp(t.TempDir(), "")
require.NoError(t, err)
return fp

View File

@ -1,7 +1,8 @@
package testutil_test
import (
"io/ioutil"
"io"
"os"
"testing"
"github.com/spf13/cobra"
@ -28,7 +29,7 @@ func TestWriteToNewTempFile(t *testing.T) {
tempfile := testutil.WriteToNewTempFile(t, "test string")
tempfile.Close()
bs, err := ioutil.ReadFile(tempfile.Name())
bs, err := os.ReadFile(tempfile.Name())
require.NoError(t, err)
require.Equal(t, "test string", string(bs))
}
@ -39,6 +40,6 @@ func TestApplyMockIODiscardOutErr(t *testing.T) {
testutil.ApplyMockIODiscardOutErr(cmd)
require.NotEqual(t, cmd.InOrStdin(), oldStdin)
require.Equal(t, cmd.OutOrStdout(), ioutil.Discard)
require.Equal(t, cmd.ErrOrStderr(), ioutil.Discard)
require.Equal(t, cmd.OutOrStdout(), io.Discard)
require.Equal(t, cmd.ErrOrStderr(), io.Discard)
}

View File

@ -1,7 +1,7 @@
package testutil
import (
"io/ioutil"
"io"
"net/http"
)
@ -25,7 +25,7 @@ func GetRequestWithHeaders(url string, headers map[string]string) ([]byte, error
return nil, err
}
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
return nil, err
}

View File

@ -5,7 +5,7 @@ package rest
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"net/http"
)
@ -18,7 +18,7 @@ func GetRequest(url string) ([]byte, error) {
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
return nil, err
}
@ -35,7 +35,7 @@ func PostRequest(url string, contentType string, data []byte) ([]byte, error) {
}
defer res.Body.Close()
bz, err := ioutil.ReadAll(res.Body)
bz, err := io.ReadAll(res.Body)
if err != nil {
return nil, fmt.Errorf("error reading response body: %w", err)
}

View File

@ -2,7 +2,6 @@ package cli
import (
"fmt"
"io/ioutil"
"os"
"strings"
@ -393,14 +392,14 @@ func makeBatchMultisignCmd() func(cmd *cobra.Command, args []string) error {
func unmarshalSignatureJSON(clientCtx client.Context, filename string) (sigs []signingtypes.SignatureV2, err error) {
var bytes []byte
if bytes, err = ioutil.ReadFile(filename); err != nil {
if bytes, err = os.ReadFile(filename); err != nil {
return
}
return clientCtx.TxConfig.UnmarshalSignatureJSON(bytes)
}
func readSignaturesFromFile(ctx client.Context, filename string) (sigs []signingtypes.SignatureV2, err error) {
bz, err := ioutil.ReadFile(filename)
bz, err := os.ReadFile(filename)
if err != nil {
return nil, err
}

View File

@ -5,7 +5,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
@ -334,7 +334,7 @@ func (s *IntegrationTestSuite) TestCLISignAminoJSON() {
fileFlag := fmt.Sprintf("--%s=%s", flags.FlagOutputDocument, filenameSigned)
_, err = TxSignExec(val1.ClientCtx, val1.Address, fileUnsigned.Name(), chainFlag, fileFlag, signModeAminoFlag)
require.NoError(err)
fContent, err := ioutil.ReadFile(filenameSigned)
fContent, err := os.ReadFile(filenameSigned)
require.NoError(err)
require.Equal(res.String(), string(fContent))

View File

@ -5,7 +5,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"strings"
@ -95,9 +94,9 @@ func ReadTxFromFile(ctx client.Context, filename string) (tx sdk.Tx, err error)
var bytes []byte
if filename == "-" {
bytes, err = ioutil.ReadAll(os.Stdin)
bytes, err = io.ReadAll(os.Stdin)
} else {
bytes, err = ioutil.ReadFile(filename)
bytes, err = os.ReadFile(filename)
}
if err != nil {

View File

@ -3,7 +3,7 @@ package cli
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"strconv"
"github.com/spf13/cobra"
@ -129,7 +129,7 @@ func NewMsgCreatePeriodicVestingAccountCmd() *cobra.Command {
return err
}
contents, err := ioutil.ReadFile(args[1])
contents, err := os.ReadFile(args[1])
if err != nil {
return err
}

View File

@ -1,7 +1,7 @@
package cli
import (
"io/ioutil"
"os"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
@ -11,7 +11,7 @@ import (
func ParseCommunityPoolSpendProposalWithDeposit(cdc codec.JSONCodec, proposalFile string) (types.CommunityPoolSpendProposalWithDeposit, error) {
proposal := types.CommunityPoolSpendProposalWithDeposit{}
contents, err := ioutil.ReadFile(proposalFile)
contents, err := os.ReadFile(proposalFile)
if err != nil {
return proposal, err
}

View File

@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
@ -225,7 +224,7 @@ func makeOutputFilepath(rootDir, nodeID string) (string, error) {
}
func readUnsignedGenTxFile(clientCtx client.Context, r io.Reader) (sdk.Tx, error) {
bz, err := ioutil.ReadAll(r)
bz, err := io.ReadAll(r)
if err != nil {
return nil, err
}

View File

@ -3,7 +3,7 @@ package testutil
import (
"context"
"fmt"
"io/ioutil"
"io"
"os"
"path/filepath"
@ -78,7 +78,7 @@ func (s *IntegrationTestSuite) TestGenTxCmd() {
open, err := os.Open(genTxFile)
s.Require().NoError(err)
all, err := ioutil.ReadAll(open)
all, err := io.ReadAll(open)
s.Require().NoError(err)
tx, err := val.ClientCtx.TxConfig.TxJSONDecoder()(all)

View File

@ -6,7 +6,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"runtime"
@ -79,8 +78,8 @@ func CollectTxs(cdc codec.JSONCodec, txJSONDecoder sdk.TxDecoder, moniker, genTx
return appGenTxs, persistentPeers, err
}
var fos []os.FileInfo
fos, err = ioutil.ReadDir(genTxsDir)
var fos []os.DirEntry
fos, err = os.ReadDir(genTxsDir)
if err != nil {
return appGenTxs, persistentPeers, err
}
@ -107,7 +106,7 @@ func CollectTxs(cdc codec.JSONCodec, txJSONDecoder sdk.TxDecoder, moniker, genTx
}
// get the genTx
jsonRawTx, err := ioutil.ReadFile(filepath.Join(genTxsDir, fo.Name()))
jsonRawTx, err := os.ReadFile(filepath.Join(genTxsDir, fo.Name()))
if err != nil {
return appGenTxs, persistentPeers, err
}

View File

@ -2,7 +2,6 @@ package genutil_test
import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -38,7 +37,7 @@ func (dni *doNothingIterator) IterateGenesisBalances(_ codec.JSONCodec, _ map[st
// Ensures that CollectTx correctly traverses directories and won't error out on encountering
// a directory during traversal of the first level. See issue https://github.com/cosmos/cosmos-sdk/issues/6788.
func TestCollectTxsHandlesDirectories(t *testing.T) {
testDir, err := ioutil.TempDir(os.TempDir(), "testCollectTxs")
testDir, err := os.MkdirTemp(os.TempDir(), "testCollectTxs")
if err != nil {
t.Fatal(err)
}

View File

@ -3,7 +3,7 @@ package cli
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"github.com/spf13/pflag"
@ -30,7 +30,7 @@ func parseSubmitProposalFlags(fs *pflag.FlagSet) (*proposal, error) {
}
}
contents, err := ioutil.ReadFile(proposalFile)
contents, err := os.ReadFile(proposalFile)
if err != nil {
return nil, err
}

View File

@ -2,7 +2,7 @@ package utils
import (
"encoding/json"
"io/ioutil"
"os"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/params/types/proposal"
@ -55,7 +55,7 @@ func (pcj ParamChangesJSON) ToParamChanges() []proposal.ParamChange {
func ParseParamChangeProposalJSON(cdc *codec.LegacyAmino, proposalFile string) (ParamChangeProposalJSON, error) {
proposal := ParamChangeProposalJSON{}
contents, err := ioutil.ReadFile(proposalFile)
contents, err := os.ReadFile(proposalFile)
if err != nil {
return proposal, err
}

View File

@ -4,7 +4,7 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
)
// EventStats defines an object that keeps a tally of each event that has occurred
@ -48,7 +48,7 @@ func (es EventStats) ExportJSON(path string) {
panic(err)
}
err = ioutil.WriteFile(path, bz, 0600)
err = os.WriteFile(path, bz, 0600)
if err != nil {
panic(err)
}

View File

@ -3,7 +3,6 @@ package keeper
import (
"encoding/binary"
"encoding/json"
"io/ioutil"
"os"
"path"
"path/filepath"
@ -342,7 +341,7 @@ func (k Keeper) DumpUpgradeInfoToDisk(height int64, p types.Plan) error {
return err
}
return ioutil.WriteFile(upgradeInfoFilePath, info, 0600)
return os.WriteFile(upgradeInfoFilePath, info, 0600)
}
// GetUpgradeInfoPath returns the upgrade info file path
@ -373,7 +372,7 @@ func (k Keeper) ReadUpgradeInfoFromDisk() (types.Plan, error) {
return upgradeInfo, err
}
data, err := ioutil.ReadFile(upgradeInfoPath)
data, err := os.ReadFile(upgradeInfoPath)
if err != nil {
// if file does not exist, assume there are no upgrades
if os.IsNotExist(err) {

View File

@ -2,7 +2,6 @@ package types
import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -77,7 +76,7 @@ func TestSetLoader(t *testing.T) {
data, err := json.Marshal(upgradeInfo)
require.NoError(t, err)
err = ioutil.WriteFile(upgradeInfoFilePath, data, 0644)
err = os.WriteFile(upgradeInfoFilePath, data, 0644)
require.NoError(t, err)
// make sure it exists before running everything