migrate away from deprecated ioutil APIs (#7175)

Co-authored-by: Callum Waters <cmwaters19@gmail.com>
Co-authored-by: M. J. Fromberger <fromberger@interchain.io>
This commit is contained in:
Sharad Chand
2021-10-28 10:34:07 -07:00
committed by GitHub
co-authored by Callum Waters M. J. Fromberger
parent 6108d0a9b5
commit 8441b3715a
58 changed files with 158 additions and 192 deletions
+3 -3
View File
@@ -5,7 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"time"
"github.com/tendermint/tendermint/crypto"
@@ -51,7 +51,7 @@ func (genDoc *GenesisDoc) SaveAs(file string) error {
return err
}
return ioutil.WriteFile(file, genDocBytes, 0644) // nolint:gosec
return os.WriteFile(file, genDocBytes, 0644) // nolint:gosec
}
// ValidatorHash returns the hash of the validator set contained in the GenesisDoc
@@ -125,7 +125,7 @@ func GenesisDocFromJSON(jsonBlob []byte) (*GenesisDoc, error) {
// GenesisDocFromFile reads JSON data from a file and unmarshalls it into a GenesisDoc.
func GenesisDocFromFile(genDocFile string) (*GenesisDoc, error) {
jsonBlob, err := ioutil.ReadFile(genDocFile)
jsonBlob, err := os.ReadFile(genDocFile)
if err != nil {
return nil, fmt.Errorf("couldn't read GenesisDoc file: %w", err)
}
+1 -2
View File
@@ -1,7 +1,6 @@
package types
import (
"io/ioutil"
"os"
"testing"
@@ -122,7 +121,7 @@ func TestGenesisGood(t *testing.T) {
}
func TestGenesisSaveAs(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "genesis")
tmpfile, err := os.CreateTemp("", "genesis")
require.NoError(t, err)
defer os.Remove(tmpfile.Name())
+3 -3
View File
@@ -1,7 +1,7 @@
package types
import (
"io/ioutil"
"os"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
@@ -33,7 +33,7 @@ func (nodeKey NodeKey) SaveAs(filePath string) error {
if err != nil {
return err
}
return ioutil.WriteFile(filePath, jsonBytes, 0600)
return os.WriteFile(filePath, jsonBytes, 0600)
}
// LoadOrGenNodeKey attempts to load the NodeKey from the given filePath. If
@@ -67,7 +67,7 @@ func GenNodeKey() NodeKey {
// LoadNodeKey loads NodeKey located in filePath.
func LoadNodeKey(filePath string) (NodeKey, error) {
jsonBytes, err := ioutil.ReadFile(filePath)
jsonBytes, err := os.ReadFile(filePath)
if err != nil {
return NodeKey{}, err
}
+2 -2
View File
@@ -1,7 +1,7 @@
package types
import (
"io/ioutil"
"io"
"testing"
"github.com/stretchr/testify/assert"
@@ -57,7 +57,7 @@ func TestBasicPartSet(t *testing.T) {
// Reconstruct data, assert that they are equal.
data2Reader := partSet2.GetReader()
data2, err := ioutil.ReadAll(data2Reader)
data2, err := io.ReadAll(data2Reader)
require.NoError(t, err)
assert.Equal(t, data, data2)