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

chore: replace deprecated functions #694

Merged
merged 3 commits into from
Oct 5, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (store) [\#666](https://github.com/line/lbm-sdk/pull/666) change default `iavl-cache-size` and description
* (simapp) [\#679](https://github.com/line/lbm-sdk/pull/679) fix the bug not setting `iavl-cache-size` value of `app.toml`
* (x/foundation) [\#687](https://github.com/line/lbm-sdk/pull/687) fix bugs on aborting x/foundation proposals
* (global) [\#694](https://github.com/line/lbm-sdk/pull/694) replace deprecated functions since go 1.16 or 1.17

### Breaking Changes
* (proto) [\#564](https://github.com/line/lbm-sdk/pull/564) change gRPC path to original cosmos path
Expand Down
3 changes: 1 addition & 2 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/binary"
"encoding/json"
"fmt"
"io/ioutil"
"math/rand"
"os"
"strings"
Expand Down Expand Up @@ -134,7 +133,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)
Expand Down
6 changes: 3 additions & 3 deletions client/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package config_test

import (
"bytes"
//"fmt"
"io/ioutil"
"io"

"os"
"testing"

Expand Down Expand Up @@ -57,7 +57,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")
}
Expand Down
3 changes: 1 addition & 2 deletions client/config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package config

import (
"bytes"
"io/ioutil"
"os"
"text/template"

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions client/keys/add_ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"io"
"testing"

"github.com/line/ostracon/libs/cli"
Expand Down Expand Up @@ -179,7 +179,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 {
Expand Down
4 changes: 2 additions & 2 deletions client/keys/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"io"
"testing"

bip39 "github.com/cosmos/go-bip39"
Expand Down Expand Up @@ -262,7 +262,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 {
Expand Down
4 changes: 2 additions & 2 deletions client/keys/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package keys

import (
"bufio"
"io/ioutil"
"os"

"github.com/spf13/cobra"

Expand All @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions client/keys/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package keys
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -95,7 +94,7 @@ Ax9IQsSq+jOWkPRDJQ69a5/uUm4XliPim/CbYDVoXO6D3fts5IEXcUTmIa60ynC/

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)
Expand Down
4 changes: 2 additions & 2 deletions codec/unknownproto/unknown_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"compress/gzip"
"errors"
"fmt"
"io/ioutil"
"io"
"reflect"
"strings"
"sync"
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 2 additions & 3 deletions cosmovisor/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/url"
"os"
"path/filepath"
Expand Down Expand Up @@ -106,7 +105,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)
}
Expand All @@ -117,7 +116,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)
}
Expand Down
4 changes: 2 additions & 2 deletions crypto/hd/fundraiser_test.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"
"os"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -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)
}
Expand Down
5 changes: 2 additions & 3 deletions crypto/keyring/keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/hex"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"sort"
Expand Down Expand Up @@ -673,7 +672,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)
}
Expand Down Expand Up @@ -737,7 +736,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
}

Expand Down
3 changes: 1 addition & 2 deletions server/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package server

import (
"fmt"
"io/ioutil"
"os"

ostjson "github.com/line/ostracon/libs/json"
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions server/grpc/gogoreflection/serverreflection.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import (
"compress/gzip"
"fmt"
"io"
"io/ioutil"
"log"
"reflect"
"sort"
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions server/grpc/grpc_web_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"encoding/binary"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/textproto"
"strconv"
Expand Down Expand Up @@ -198,7 +197,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
}
Expand Down
3 changes: 1 addition & 2 deletions server/mock/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package mock

import (
"fmt"
"io/ioutil"
"os"

abci "github.com/line/ostracon/abci/types"
Expand All @@ -14,7 +13,7 @@ import (
func SetupApp() (abci.Application, func(), error) {
logger := log.NewOCLogger(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
}
Expand Down
6 changes: 3 additions & 3 deletions simapp/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"math/rand"
"os"
"time"

ostjson "github.com/line/ostracon/libs/json"
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -184,7 +184,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) (octypes.GenesisDoc, []simtypes.Account) {
bytes, err := ioutil.ReadFile(genesisFile)
bytes, err := os.ReadFile(genesisFile)
if err != nil {
panic(err)
}
Expand Down
4 changes: 2 additions & 2 deletions simapp/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"sort"
"strconv"
Expand Down Expand Up @@ -56,7 +56,7 @@ var DefaultConsensusParams = &abci.ConsensusParams{
}

func setup(withGenesis bool, invCheckPeriod uint, opts ...wasm.Option) (*SimApp, GenesisState) {
randDir, _ := ioutil.TempDir(DefaultNodeHome, "")
randDir, _ := os.MkdirTemp(DefaultNodeHome, "")
snapshotDir := filepath.Join(randDir, "data", "snapshots")
snapshotDB := dbm.NewMemDB()

Expand Down
10 changes: 5 additions & 5 deletions simapp/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package simapp
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"

"github.com/line/ostracon/libs/log"
dbm "github.com/tendermint/tm-db"
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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
}
}
Expand Down
Loading