Skip to content

Commit b3c022d

Browse files
authored
refactor: move from io/ioutil to io and os package (cosmos#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 (cosmos#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)
1 parent 6d0f4f0 commit b3c022d

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

state.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"encoding/json"
55
"fmt"
66
"io"
7-
"io/ioutil"
87
"math/rand"
8+
"os"
99
"time"
1010

1111
tmjson "github.com/tendermint/tendermint/libs/json"
@@ -55,7 +55,7 @@ func AppStateFn(cdc codec.JSONCodec, simManager *module.SimulationManager) simty
5555

5656
case config.ParamsFile != "":
5757
appParams := make(simtypes.AppParams)
58-
bz, err := ioutil.ReadFile(config.ParamsFile)
58+
bz, err := os.ReadFile(config.ParamsFile)
5959
if err != nil {
6060
panic(err)
6161
}
@@ -194,7 +194,7 @@ func AppStateRandomizedFn(
194194
// AppStateFromGenesisFileFn util function to generate the genesis AppState
195195
// from a genesis.json file.
196196
func AppStateFromGenesisFileFn(r io.Reader, cdc codec.JSONCodec, genesisFile string) (tmtypes.GenesisDoc, []simtypes.Account) {
197-
bytes, err := ioutil.ReadFile(genesisFile)
197+
bytes, err := os.ReadFile(genesisFile)
198198
if err != nil {
199199
panic(err)
200200
}

utils.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package simapp
33
import (
44
"encoding/json"
55
"fmt"
6-
"io/ioutil"
6+
"os"
77

88
"github.com/tendermint/tendermint/libs/log"
99
dbm "github.com/tendermint/tm-db"
@@ -34,7 +34,7 @@ func SetupSimulation(dirPrefix, dbName string) (simtypes.Config, dbm.DB, string,
3434
logger = log.NewNopLogger()
3535
}
3636

37-
dir, err := ioutil.TempDir("", dirPrefix)
37+
dir, err := os.MkdirTemp("", dirPrefix)
3838
if err != nil {
3939
return simtypes.Config{}, nil, "", nil, false, err
4040
}
@@ -56,7 +56,7 @@ func SimulationOperations(app App, cdc codec.JSONCodec, config simtypes.Config)
5656
}
5757

5858
if config.ParamsFile != "" {
59-
bz, err := ioutil.ReadFile(config.ParamsFile)
59+
bz, err := os.ReadFile(config.ParamsFile)
6060
if err != nil {
6161
panic(err)
6262
}
@@ -84,7 +84,7 @@ func CheckExportSimulation(
8484
return err
8585
}
8686

87-
if err := ioutil.WriteFile(config.ExportStatePath, []byte(exported.AppState), 0600); err != nil {
87+
if err := os.WriteFile(config.ExportStatePath, []byte(exported.AppState), 0600); err != nil {
8888
return err
8989
}
9090
}
@@ -96,7 +96,7 @@ func CheckExportSimulation(
9696
return err
9797
}
9898

99-
if err := ioutil.WriteFile(config.ExportParamsPath, paramsBz, 0600); err != nil {
99+
if err := os.WriteFile(config.ExportParamsPath, paramsBz, 0600); err != nil {
100100
return err
101101
}
102102
}

0 commit comments

Comments
 (0)