diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c32cf5f40a..1cbb65c163f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 5d77a16469c..b542dce0d13 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -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. diff --git a/client/config/config_test.go b/client/config/config_test.go index c058edf8301..a7a7232cb8f 100644 --- a/client/config/config_test.go +++ b/client/config/config_test.go @@ -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") } diff --git a/client/config/toml.go b/client/config/toml.go index 0393a5b6acc..a26cf78e6f1 100644 --- a/client/config/toml.go +++ b/client/config/toml.go @@ -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 diff --git a/client/keys/add_ledger_test.go b/client/keys/add_ledger_test.go index 2b106615bcd..1901a3e3261 100644 --- a/client/keys/add_ledger_test.go +++ b/client/keys/add_ledger_test.go @@ -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 { diff --git a/client/keys/add_test.go b/client/keys/add_test.go index 1db73799111..b47210194cf 100644 --- a/client/keys/add_test.go +++ b/client/keys/add_test.go @@ -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 { diff --git a/client/keys/import.go b/client/keys/import.go index 36662a8dd2e..a9d5c185acb 100644 --- a/client/keys/import.go +++ b/client/keys/import.go @@ -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 } diff --git a/client/keys/import_test.go b/client/keys/import_test.go index 37f4f3ce6bf..b481285200d 100644 --- a/client/keys/import_test.go +++ b/client/keys/import_test.go @@ -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) diff --git a/codec/unknownproto/unknown_fields.go b/codec/unknownproto/unknown_fields.go index b9db6429628..36b745e1e04 100644 --- a/codec/unknownproto/unknown_fields.go +++ b/codec/unknownproto/unknown_fields.go @@ -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 } diff --git a/container/container_test.go b/container/container_test.go index 9bb072c9cd3..42f1ab0accb 100644 --- a/container/container_test.go +++ b/container/container_test.go @@ -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), "= len(m.restoreChunkHashes) { diff --git a/snapshots/store_test.go b/snapshots/store_test.go index 333031bc44c..77ff32a3c46 100644 --- a/snapshots/store_test.go +++ b/snapshots/store_test.go @@ -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) diff --git a/snapshots/util_test.go b/snapshots/util_test.go index 78c870b90a1..6935c082ad7 100644 --- a/snapshots/util_test.go +++ b/snapshots/util_test.go @@ -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) diff --git a/store/rootmulti/store_test.go b/store/rootmulti/store_test.go index 05817d6a841..a187fef762d 100644 --- a/store/rootmulti/store_test.go +++ b/store/rootmulti/store_test.go @@ -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) diff --git a/testutil/ioutil.go b/testutil/ioutil.go index 6a7e4fff9ce..6ff54d24ecb 100644 --- a/testutil/ioutil.go +++ b/testutil/ioutil.go @@ -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 diff --git a/testutil/ioutil_test.go b/testutil/ioutil_test.go index 415e7842c15..03250fbab6a 100644 --- a/testutil/ioutil_test.go +++ b/testutil/ioutil_test.go @@ -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) } diff --git a/testutil/rest.go b/testutil/rest.go index b468b16bedd..58e6c39b197 100644 --- a/testutil/rest.go +++ b/testutil/rest.go @@ -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 } diff --git a/testutil/rest/rest.go b/testutil/rest/rest.go index 17dddaa6a55..e56ef90a201 100644 --- a/testutil/rest/rest.go +++ b/testutil/rest/rest.go @@ -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) } diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index 4f33ac75212..4044f8b3de2 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -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 } diff --git a/x/auth/client/testutil/suite.go b/x/auth/client/testutil/suite.go index e461efd869a..1ee016ef826 100644 --- a/x/auth/client/testutil/suite.go +++ b/x/auth/client/testutil/suite.go @@ -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)) diff --git a/x/auth/client/tx.go b/x/auth/client/tx.go index 05a7c65567b..a57f28d3d95 100644 --- a/x/auth/client/tx.go +++ b/x/auth/client/tx.go @@ -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 { diff --git a/x/auth/vesting/client/cli/tx.go b/x/auth/vesting/client/cli/tx.go index 28c7e67dec9..74eb5633d25 100644 --- a/x/auth/vesting/client/cli/tx.go +++ b/x/auth/vesting/client/cli/tx.go @@ -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 } diff --git a/x/distribution/client/cli/utils.go b/x/distribution/client/cli/utils.go index 45f941f0897..ce7024dd2e3 100644 --- a/x/distribution/client/cli/utils.go +++ b/x/distribution/client/cli/utils.go @@ -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 } diff --git a/x/genutil/client/cli/gentx.go b/x/genutil/client/cli/gentx.go index c9128ae16dd..00ff11ab6f9 100644 --- a/x/genutil/client/cli/gentx.go +++ b/x/genutil/client/cli/gentx.go @@ -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 } diff --git a/x/genutil/client/testutil/suite.go b/x/genutil/client/testutil/suite.go index 99f007de002..f025160da6c 100644 --- a/x/genutil/client/testutil/suite.go +++ b/x/genutil/client/testutil/suite.go @@ -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) diff --git a/x/genutil/collect.go b/x/genutil/collect.go index b93942e0ba0..008dd937d18 100644 --- a/x/genutil/collect.go +++ b/x/genutil/collect.go @@ -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 } diff --git a/x/genutil/collect_test.go b/x/genutil/collect_test.go index 46e20f88f1b..837e16e6fc9 100644 --- a/x/genutil/collect_test.go +++ b/x/genutil/collect_test.go @@ -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) } diff --git a/x/gov/client/cli/parse.go b/x/gov/client/cli/parse.go index 90066b645ab..eeb814eb98e 100644 --- a/x/gov/client/cli/parse.go +++ b/x/gov/client/cli/parse.go @@ -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 } diff --git a/x/params/client/utils/utils.go b/x/params/client/utils/utils.go index 632c323247b..4c106913b01 100644 --- a/x/params/client/utils/utils.go +++ b/x/params/client/utils/utils.go @@ -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 } diff --git a/x/simulation/event_stats.go b/x/simulation/event_stats.go index 0e4289fd243..9618385b8ff 100644 --- a/x/simulation/event_stats.go +++ b/x/simulation/event_stats.go @@ -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) } diff --git a/x/upgrade/keeper/keeper.go b/x/upgrade/keeper/keeper.go index 21ab2b2a517..8b667ad3173 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -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) { diff --git a/x/upgrade/types/storeloader_test.go b/x/upgrade/types/storeloader_test.go index 20e28888ed3..22d8ab45296 100644 --- a/x/upgrade/types/storeloader_test.go +++ b/x/upgrade/types/storeloader_test.go @@ -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