Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[R4R] bump up go version and replace ioutil with io/os #274

Merged
merged 2 commits into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions bsc/rlp/encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"math/big"
"sync"
"testing"
Expand Down Expand Up @@ -349,7 +348,7 @@ func TestEncodeToReader(t *testing.T) {
if err != nil {
return nil, err
}
return ioutil.ReadAll(r)
return io.ReadAll(r)
})
}

Expand Down Expand Up @@ -390,7 +389,7 @@ func TestEncodeToReaderReturnToPool(t *testing.T) {
go func() {
for i := 0; i < 1000; i++ {
_, r, _ := EncodeToReader("foo")
ioutil.ReadAll(r)
io.ReadAll(r)
r.Read(buf)
r.Read(buf)
r.Read(buf)
Expand Down
3 changes: 1 addition & 2 deletions client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/mitchellh/go-homedir"
"github.com/pelletier/go-toml"
"github.com/spf13/cobra"
"io/ioutil"
"os"
"path"
)
Expand Down Expand Up @@ -127,5 +126,5 @@ func createGaiaCLIConfig(cfg *cliConfig) error {
}
}

return ioutil.WriteFile(cfgFile, data, os.ModePerm)
return os.WriteFile(cfgFile, data, os.ModePerm)
}
6 changes: 3 additions & 3 deletions client/keys/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"path"
Expand Down Expand Up @@ -225,7 +225,7 @@ func AddNewKeyRequestHandler(indent bool) http.HandlerFunc {
return
}

body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(err.Error()))
Expand Down Expand Up @@ -323,7 +323,7 @@ func RecoverRequestHandler(indent bool) http.HandlerFunc {
vars := mux.Vars(r)
name := vars["name"]
var m RecoverKeyBody
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(err.Error()))
Expand Down
3 changes: 1 addition & 2 deletions client/keys/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package keys
import (
"github.com/cosmos/cosmos-sdk/crypto/keys"
"github.com/stretchr/testify/require"
"io/ioutil"
"os"
"testing"
)

func TestGetKeyBaseLocks(t *testing.T) {
dir, err := ioutil.TempDir("", "cosmos-sdk-keys")
dir, err := os.MkdirTemp("", "cosmos-sdk-keys")
require.Nil(t, err)
defer os.RemoveAll(dir)

Expand Down
8 changes: 4 additions & 4 deletions client/lcd/certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"encoding/pem"
"errors"
"fmt"
"io/ioutil"
"io"
"math/big"
"net"
"os"
Expand Down Expand Up @@ -76,7 +76,7 @@ func writeCertAndPrivKey(certBytes []byte, priv *ecdsa.PrivateKey) (certFile str
}

func writeCertificateFile(certBytes []byte) (filename string, err error) {
f, err := ioutil.TempFile("", "cert_")
f, err := os.CreateTemp("", "cert_")
if err != nil {
return
}
Expand All @@ -89,7 +89,7 @@ func writeCertificateFile(certBytes []byte) (filename string, err error) {
}

func writeKeyFile(priv *ecdsa.PrivateKey) (filename string, err error) {
f, err := ioutil.TempFile("", "key_")
f, err := os.CreateTemp("", "key_")
if err != nil {
return
}
Expand Down Expand Up @@ -162,7 +162,7 @@ func fingerprintFromFile(certFile string) (string, error) {
return "", err
}
defer f.Close()
data, err := ioutil.ReadAll(f)
data, err := io.ReadAll(f)
if err != nil {
return "", err
}
Expand Down
5 changes: 2 additions & 3 deletions client/lcd/certificates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package lcd
import (
"crypto/ecdsa"
"crypto/x509"
"io/ioutil"
"os"
"testing"

Expand Down Expand Up @@ -71,7 +70,7 @@ zj0EAwIDSQAwRgIhAKnwbhX9FrGG1otCVLwhClQ3RaLxnNpCgIGTqSimb34cAiEA
stMN+IqMCKWlZyGqxGIiyksMLMEU3lRqKNQn2EoAZJY=
-----END CERTIFICATE-----`
wantFingerprint := `SHA256 Fingerprint=0B:ED:9A:AA:A2:D1:7E:B2:53:56:F6:FC:C0:E6:1A:69:70:21:A2:B0:90:FC:AF:BB:EF:AE:2C:78:52:AB:68:40`
certFile, err := ioutil.TempFile("", "test_cert_")
certFile, err := os.CreateTemp("", "test_cert_")
require.Nil(t, err)
_, err = certFile.Write([]byte(cert))
require.Nil(t, err)
Expand All @@ -83,7 +82,7 @@ stMN+IqMCKWlZyGqxGIiyksMLMEU3lRqKNQn2EoAZJY=
require.Equal(t, wantFingerprint, fingerprint)

// test failure
emptyFile, err := ioutil.TempFile("", "test_cert_")
emptyFile, err := os.CreateTemp("", "test_cert_")
require.Nil(t, err)
err = emptyFile.Close()
require.Nil(t, err)
Expand Down
8 changes: 4 additions & 4 deletions client/lcd/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"os"
Expand Down Expand Up @@ -87,7 +87,7 @@ func GetConfig() *tmcfg.Config {
// NOTE: memDB cannot be used because the request is expecting to interact with
// the default location.
func GetKeyBase(t *testing.T) crkeys.Keybase {
dir, err := ioutil.TempDir("", "lcd_test")
dir, err := os.MkdirTemp("", "lcd_test")
require.NoError(t, err)

viper.Set(cli.HomeFlag, dir)
Expand Down Expand Up @@ -265,7 +265,7 @@ func InitializeTestLCD(
viper.Set(client.FlagNode, config.RPC.ListenAddress)
viper.Set(client.FlagChainID, genDoc.ChainID)
viper.Set(client.FlagTrustNode, false)
dir, err := ioutil.TempDir("", "lcd_test")
dir, err := os.MkdirTemp("", "lcd_test")
require.NoError(t, err)
viper.Set(cli.HomeFlag, dir)

Expand Down Expand Up @@ -358,7 +358,7 @@ func Request(t *testing.T, port, method, path string, payload []byte) (*http.Res
res, err = http.DefaultClient.Do(req)
require.Nil(t, err)

output, err := ioutil.ReadAll(res.Body)
output, err := io.ReadAll(res.Body)
res.Body.Close()
require.Nil(t, err)

Expand Down
4 changes: 2 additions & 2 deletions client/tx/broadcast.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package tx

import (
"io"
"net/http"

"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/utils"
"github.com/cosmos/cosmos-sdk/codec"
"io/ioutil"
)

const (
Expand All @@ -29,7 +29,7 @@ type BroadcastBody struct {
func BroadcastTxRequest(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var m BroadcastBody
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
Expand Down
4 changes: 2 additions & 2 deletions client/utils/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package utils

import (
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"strconv"
Expand Down Expand Up @@ -135,7 +135,7 @@ unmarshals to the req interface.
err := ReadRESTReq(w, r, cdc, req)
*/
func ReadRESTReq(w http.ResponseWriter, r *http.Request, cdc *codec.Codec, req interface{}) error {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return err
Expand Down
9 changes: 4 additions & 5 deletions cmd/cosmos-sdk-cli/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import (
"fmt"
"go/build"
"io/ioutil"
"os"
"strings"

Expand Down Expand Up @@ -65,7 +64,7 @@ func copyBasecoinTemplate(projectName string, projectPath string, remoteProjectP
basecoinProjectPath := resolveProjectPath(remoteBasecoinPath)
filepath.Walk(basecoinProjectPath, func(path string, f os.FileInfo, err error) error {
if !f.IsDir() {
data, err := ioutil.ReadFile(path)
data, err := os.ReadFile(path)
if err != nil {
return err
}
Expand All @@ -83,7 +82,7 @@ func copyBasecoinTemplate(projectName string, projectPath string, remoteProjectP
fmt.Println("Creating " + projectFilePath)
// Writing the contents to a file in the project folder
contents = replacer.Replace(contents)
ioutil.WriteFile(projectFilePath, []byte(contents), os.ModePerm)
os.WriteFile(projectFilePath, []byte(contents), os.ModePerm)
}
return nil
})
Expand All @@ -110,7 +109,7 @@ func createGopkg(projectPath string) {
contents += "[[override]]\n\tname = \"" + dependency + "\"\n\tversion = \"=" + version + "\"\n\n"
}
contents += "[prune]\n\tgo-tests = true\n\tunused-packages = true"
ioutil.WriteFile(projectPath+"/Gopkg.toml", []byte(contents), os.ModePerm)
os.WriteFile(projectPath+"/Gopkg.toml", []byte(contents), os.ModePerm)
}

// nolint: errcheck
Expand Down Expand Up @@ -142,7 +141,7 @@ benchmark:
// Replacing instances of base* to project specific names
makefileContents = replacer.Replace(makefileContents)

ioutil.WriteFile(projectPath+"/Makefile", []byte(makefileContents), os.ModePerm)
os.WriteFile(projectPath+"/Makefile", []byte(makefileContents), os.ModePerm)

}

Expand Down
7 changes: 3 additions & 4 deletions cmd/gaia/app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"sort"
Expand Down Expand Up @@ -189,8 +188,8 @@ func GaiaAppGenStateJSON(cdc *codec.Codec, appGenTxs []json.RawMessage) (appStat
// appGenTxs, and persistent peers required to generate genesis.json.
func CollectStdTxs(moniker string, genTxsDir string, cdc *codec.Codec) (
validators []tmtypes.GenesisValidator, appGenTxs []auth.StdTx, persistentPeers string, err error) {
var fos []os.FileInfo
fos, err = ioutil.ReadDir(genTxsDir)
var fos []os.DirEntry
fos, err = os.ReadDir(genTxsDir)
if err != nil {
return
}
Expand All @@ -204,7 +203,7 @@ func CollectStdTxs(moniker string, genTxsDir string, cdc *codec.Codec) (

// get the genStdTx
var jsonRawTx []byte
jsonRawTx, err = ioutil.ReadFile(filename)
jsonRawTx, err = os.ReadFile(filename)
if err != nil {
return
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/gaia/cli_test/cli_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//go:build cli_test
// +build cli_test

package clitest

import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path"
"testing"
Expand Down Expand Up @@ -391,7 +391,7 @@ func TestGaiaCLIConfig(t *testing.T) {
node := fmt.Sprintf("%s:%s", servAddr, port)
chainID := executeInit(t, fmt.Sprintf("gaiad init -o --name=foo --home=%s --home-client=%s", gaiadHome, gaiacliHome))
executeWrite(t, fmt.Sprintf("gaiacli --home=%s config", gaiadHome), gaiacliHome, node, "y")
config, err := ioutil.ReadFile(path.Join(gaiacliHome, "config", "config.toml"))
config, err := os.ReadFile(path.Join(gaiacliHome, "config", "config.toml"))
require.NoError(t, err)
expectedConfig := fmt.Sprintf(`chain_id = "%s"
encoding = "btc"
Expand All @@ -404,7 +404,7 @@ trust_node = true
require.Equal(t, expectedConfig, string(config))
// ensure a backup gets created
executeWrite(t, "gaiacli config", gaiacliHome, node, "y", "y")
configBackup, err := ioutil.ReadFile(path.Join(gaiacliHome, "config", "config.toml-old"))
configBackup, err := os.ReadFile(path.Join(gaiacliHome, "config", "config.toml-old"))
require.NoError(t, err)
require.Equal(t, expectedConfig, string(configBackup))

Expand All @@ -420,7 +420,7 @@ output = "text"
trace = false
trust_node = true
`, gaiacliHome, node)
config, err = ioutil.ReadFile(path.Join(gaiacliHome, "config", "config.toml"))
config, err = os.ReadFile(path.Join(gaiacliHome, "config", "config.toml"))
require.NoError(t, err)
require.Equal(t, expectedConfig, string(config))
}
Expand Down Expand Up @@ -456,7 +456,7 @@ func unmarshalStdTx(t *testing.T, s string) (stdTx auth.StdTx) {
}

func writeToNewTempFile(t *testing.T, s string) *os.File {
fp, err := ioutil.TempFile(os.TempDir(), "cosmos_cli_test_")
fp, err := os.TempFile(os.TempDir(), "cosmos_cli_test_")
require.Nil(t, err)
_, err = fp.WriteString(s)
require.Nil(t, err)
Expand Down
3 changes: 1 addition & 2 deletions cmd/gaia/init/gentx.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/tendermint/tendermint/crypto"
tmcli "github.com/tendermint/tendermint/libs/cli"
"github.com/tendermint/tendermint/libs/common"
"io/ioutil"
"os"
"path/filepath"
)
Expand Down Expand Up @@ -60,7 +59,7 @@ following delegation and commission default parameters:
prepareFlagsForTxCreateValidator(config, nodeID, ip, valPubKey)
createValidatorCmd := cli.GetCmdCreateValidator(cdc)

w, err := ioutil.TempFile("", "gentx")
w, err := os.CreateTemp("", "gentx")
if err != nil {
return err
}
Expand Down
7 changes: 3 additions & 4 deletions cmd/gaia/init/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/cosmos/cosmos-sdk/cmd/gaia/app"
"github.com/tendermint/tendermint/libs/cli"
"io"
"io/ioutil"
"os"
"testing"
"time"
Expand Down Expand Up @@ -39,7 +38,7 @@ func TestInitCmd(t *testing.T) {
}

func setupClientHome(t *testing.T) func() {
clientDir, err := ioutil.TempDir("", "mock-sdk-cmd")
clientDir, err := os.MkdirTemp("", "mock-sdk-cmd")
require.Nil(t, err)
viper.Set(flagClientHome, clientDir)
viper.Set(flagOverwriteKey, true)
Expand Down Expand Up @@ -92,7 +91,7 @@ func TestEmptyState(t *testing.T) {
}

func TestStartStandAlone(t *testing.T) {
home, err := ioutil.TempDir("", "mock-sdk-cmd")
home, err := os.MkdirTemp("", "mock-sdk-cmd")
require.Nil(t, err)
defer func() {
os.RemoveAll(home)
Expand Down Expand Up @@ -130,7 +129,7 @@ func TestStartStandAlone(t *testing.T) {
}

func TestInitNodeValidatorFiles(t *testing.T) {
home, err := ioutil.TempDir("", "mock-sdk-cmd")
home, err := os.MkdirTemp("", "mock-sdk-cmd")
require.Nil(t, err)
defer func() {
os.RemoveAll(home)
Expand Down
Loading