diff --git a/cli/contract_test.go b/cli/contract_test.go index 6ba7be18b..82cd9d8c3 100644 --- a/cli/contract_test.go +++ b/cli/contract_test.go @@ -4,7 +4,6 @@ import ( "bytes" "encoding/hex" "encoding/json" - "io/ioutil" "os" "path/filepath" "strconv" @@ -35,12 +34,12 @@ func TestCalcHash(t *testing.T) { e := newExecutor(t, false) nefPath := "./testdata/verify.nef" - src, err := ioutil.ReadFile(nefPath) + src, err := os.ReadFile(nefPath) require.NoError(t, err) nefF, err := nef.FileFromBytes(src) require.NoError(t, err) manifestPath := "./testdata/verify.manifest.json" - manifestBytes, err := ioutil.ReadFile(manifestPath) + manifestBytes, err := os.ReadFile(manifestPath) require.NoError(t, err) manif := &manifest.Manifest{} err = json.Unmarshal(manifestBytes, manif) @@ -67,12 +66,12 @@ func TestCalcHash(t *testing.T) { }) t.Run("invalid nef file", func(t *testing.T) { p := filepath.Join(tmpDir, "neogo.calchash.verify.nef") - require.NoError(t, ioutil.WriteFile(p, src[:4], os.ModePerm)) + require.NoError(t, os.WriteFile(p, src[:4], os.ModePerm)) e.RunWithError(t, append(cmd, "--sender", sender.StringLE(), "--in", p, "--manifest", manifestPath)...) }) t.Run("invalid manifest file", func(t *testing.T) { p := filepath.Join(tmpDir, "neogo.calchash.verify.manifest.json") - require.NoError(t, ioutil.WriteFile(p, manifestBytes[:4], os.ModePerm)) + require.NoError(t, os.WriteFile(p, manifestBytes[:4], os.ModePerm)) e.RunWithError(t, append(cmd, "--sender", sender.StringLE(), "--in", nefPath, "--manifest", p)...) }) @@ -106,7 +105,7 @@ func TestContractBindings(t *testing.T) { e.Run(t, "neo-go", "contract", "init", "--name", ctrPath) srcPath := filepath.Join(ctrPath, "main.go") - require.NoError(t, ioutil.WriteFile(srcPath, []byte(`package testcontract + require.NoError(t, os.WriteFile(srcPath, []byte(`package testcontract import( alias "github.com/nspcc-dev/neo-go/pkg/interop/native/ledger" ) @@ -140,7 +139,7 @@ func Blocks() []*alias.Block { // Replace `pkg/interop` in go.mod to avoid getting an actual module version. goMod := filepath.Join(ctrPath, "go.mod") - data, err := ioutil.ReadFile(goMod) + data, err := os.ReadFile(goMod) require.NoError(t, err) i := bytes.IndexByte(data, '\n') @@ -150,7 +149,7 @@ func Blocks() []*alias.Block { require.NoError(t, err) data = append(data, "\nreplace github.com/nspcc-dev/neo-go/pkg/interop => "...) data = append(data, filepath.Join(wd, "../pkg/interop")...) - require.NoError(t, ioutil.WriteFile(goMod, data, os.ModePerm)) + require.NoError(t, os.WriteFile(goMod, data, os.ModePerm)) cmd = append(cmd, "--config", cfgPath, "--out", filepath.Join(tmpDir, "out.nef"), @@ -165,7 +164,7 @@ func Blocks() []*alias.Block { "--config", bindingsPath, "--manifest", manifestPath, "--out", outPath, "--hash", "0x0123456789987654321001234567899876543210") - bs, err := ioutil.ReadFile(outPath) + bs, err := os.ReadFile(outPath) require.NoError(t, err) require.Equal(t, `// Package testcontract contains wrappers for testcontract contract. package testcontract @@ -244,23 +243,23 @@ func TestContractInitAndCompile(t *testing.T) { e.RunWithError(t, append(cmd, "--config", cfgName)...) }) t.Run("provided corrupted config", func(t *testing.T) { - data, err := ioutil.ReadFile(cfgPath) + data, err := os.ReadFile(cfgPath) require.NoError(t, err) badCfg := filepath.Join(tmpDir, "bad.yml") - require.NoError(t, ioutil.WriteFile(badCfg, data[:len(data)-5], os.ModePerm)) + require.NoError(t, os.WriteFile(badCfg, data[:len(data)-5], os.ModePerm)) e.RunWithError(t, append(cmd, "--config", badCfg)...) }) // Replace `pkg/interop` in go.mod to avoid getting an actual module version. goMod := filepath.Join(ctrPath, "go.mod") - data, err := ioutil.ReadFile(goMod) + data, err := os.ReadFile(goMod) require.NoError(t, err) wd, err := os.Getwd() require.NoError(t, err) data = append(data, "\nreplace github.com/nspcc-dev/neo-go/pkg/interop => "...) data = append(data, filepath.Join(wd, "../pkg/interop")...) - require.NoError(t, ioutil.WriteFile(goMod, data, os.ModePerm)) + require.NoError(t, os.WriteFile(goMod, data, os.ModePerm)) cmd = append(cmd, "--config", cfgPath) e.Run(t, cmd...) @@ -481,7 +480,7 @@ func TestContractManifestGroups(t *testing.T) { }) t.Run("corrupted NEF file", func(t *testing.T) { f := filepath.Join(tmpDir, "invalid.nef") - require.NoError(t, ioutil.WriteFile(f, []byte{1, 2, 3}, os.ModePerm)) + require.NoError(t, os.WriteFile(f, []byte{1, 2, 3}, os.ModePerm)) e.RunWithError(t, "neo-go", "contract", "manifest", "add-group", "--wallet", testWalletPath, "--account", testWalletAccount, "--sender", testWalletAccount, "--nef", f) @@ -494,7 +493,7 @@ func TestContractManifestGroups(t *testing.T) { }) t.Run("corrupted manifest file", func(t *testing.T) { f := filepath.Join(tmpDir, "invalid.manifest.json") - require.NoError(t, ioutil.WriteFile(f, []byte{1, 2, 3}, os.ModePerm)) + require.NoError(t, os.WriteFile(f, []byte{1, 2, 3}, os.ModePerm)) e.RunWithError(t, "neo-go", "contract", "manifest", "add-group", "--wallet", testWalletPath, "--account", testWalletAccount, "--sender", testWalletAccount, "--nef", nefName, @@ -573,7 +572,7 @@ func TestContract_TestInvokeScript(t *testing.T) { "--in", badNef) }) t.Run("invalid nef", func(t *testing.T) { - require.NoError(t, ioutil.WriteFile(badNef, []byte("qwer"), os.ModePerm)) + require.NoError(t, os.WriteFile(badNef, []byte("qwer"), os.ModePerm)) e.RunWithError(t, "neo-go", "contract", "testinvokescript", "--rpc-endpoint", "http://"+e.RPC.Addr, "--in", badNef) @@ -689,10 +688,9 @@ func TestComlileAndInvokeFunction(t *testing.T) { e.RunWithError(t, cmd...) }) t.Run("corrupted wallet", func(t *testing.T) { - tmp, err := ioutil.TempDir("", "tmp") - require.NoError(t, err) + tmp := t.TempDir() tmpPath := filepath.Join(tmp, "wallet.json") - require.NoError(t, ioutil.WriteFile(tmpPath, []byte("{"), os.ModePerm)) + require.NoError(t, os.WriteFile(tmpPath, []byte("{"), os.ModePerm)) cmd := append(cmd, "--wallet", tmpPath, h.StringLE(), "getValue") @@ -854,9 +852,9 @@ func TestComlileAndInvokeFunction(t *testing.T) { os.Remove(manifestName) }) - rawNef, err := ioutil.ReadFile(nefName) + rawNef, err := os.ReadFile(nefName) require.NoError(t, err) - rawManifest, err := ioutil.ReadFile(manifestName) + rawManifest, err := os.ReadFile(manifestName) require.NoError(t, err) e.In.WriteString("one\r") @@ -918,7 +916,7 @@ func TestContractInspect(t *testing.T) { func TestCompileExamples(t *testing.T) { tmpDir := t.TempDir() const examplePath = "../examples" - infos, err := ioutil.ReadDir(examplePath) + infos, err := os.ReadDir(examplePath) require.NoError(t, err) // For proper nef generation. @@ -933,7 +931,7 @@ func TestCompileExamples(t *testing.T) { continue } t.Run(info.Name(), func(t *testing.T) { - infos, err := ioutil.ReadDir(filepath.Join(examplePath, info.Name())) + infos, err := os.ReadDir(filepath.Join(examplePath, info.Name())) require.NoError(t, err) require.False(t, len(infos) == 0, "detected smart contract folder with no contract in it") @@ -951,7 +949,7 @@ func TestCompileExamples(t *testing.T) { e.Run(t, opts...) if info.Name() == "storage" { - rawM, err := ioutil.ReadFile(manifestF) + rawM, err := os.ReadFile(manifestF) require.NoError(t, err) m := new(manifest.Manifest) @@ -983,7 +981,7 @@ func TestCompileExamples(t *testing.T) { }) } -func filterFilename(infos []os.FileInfo, ext string) string { +func filterFilename(infos []os.DirEntry, ext string) string { for _, info := range infos { if !info.IsDir() { name := info.Name() diff --git a/cli/dump_test.go b/cli/dump_test.go index 1d42283eb..5dd9dde74 100644 --- a/cli/dump_test.go +++ b/cli/dump_test.go @@ -1,7 +1,6 @@ package main import ( - "io/ioutil" "os" "path/filepath" "strconv" @@ -29,7 +28,7 @@ func TestDBRestoreDump(t *testing.T) { require.NoError(t, err) cfgPath := filepath.Join(tmpDir, "protocol.unit_testnet.yml") - require.NoError(t, ioutil.WriteFile(cfgPath, out, os.ModePerm)) + require.NoError(t, os.WriteFile(cfgPath, out, os.ModePerm)) // generated via `go run ./scripts/gendump/main.go --out ./cli/testdata/chain50x2.acc --blocks 50 --txs 2` const inDump = "./testdata/chain50x2.acc" @@ -61,14 +60,14 @@ func TestDBRestoreDump(t *testing.T) { t.Run("bad logger config", func(t *testing.T) { badConfigDir := t.TempDir() logfile := filepath.Join(badConfigDir, "logdir") - require.NoError(t, ioutil.WriteFile(logfile, []byte{1, 2, 3}, os.ModePerm)) + require.NoError(t, os.WriteFile(logfile, []byte{1, 2, 3}, os.ModePerm)) cfg = loadConfig(t) cfg.ApplicationConfiguration.LogPath = filepath.Join(logfile, "file.log") out, err = yaml.Marshal(cfg) require.NoError(t, err) cfgPath = filepath.Join(badConfigDir, "protocol.unit_testnet.yml") - require.NoError(t, ioutil.WriteFile(cfgPath, out, os.ModePerm)) + require.NoError(t, os.WriteFile(cfgPath, out, os.ModePerm)) e.RunWithError(t, "neo-go", "db", "dump", "--unittest", "--config-path", badConfigDir, "--out", dumpPath) @@ -76,14 +75,14 @@ func TestDBRestoreDump(t *testing.T) { t.Run("bad storage config", func(t *testing.T) { badConfigDir := t.TempDir() logfile := filepath.Join(badConfigDir, "logdir") - require.NoError(t, ioutil.WriteFile(logfile, []byte{1, 2, 3}, os.ModePerm)) + require.NoError(t, os.WriteFile(logfile, []byte{1, 2, 3}, os.ModePerm)) cfg = loadConfig(t) cfg.ApplicationConfiguration.DBConfiguration.Type = "" out, err = yaml.Marshal(cfg) require.NoError(t, err) cfgPath = filepath.Join(badConfigDir, "protocol.unit_testnet.yml") - require.NoError(t, ioutil.WriteFile(cfgPath, out, os.ModePerm)) + require.NoError(t, os.WriteFile(cfgPath, out, os.ModePerm)) e.RunWithError(t, "neo-go", "db", "dump", "--unittest", "--config-path", badConfigDir, "--out", dumpPath) @@ -98,9 +97,9 @@ func TestDBRestoreDump(t *testing.T) { e.Run(t, baseCmd...) - d1, err := ioutil.ReadFile(inDump) + d1, err := os.ReadFile(inDump) require.NoError(t, err) - d2, err := ioutil.ReadFile(dumpPath) + d2, err := os.ReadFile(dumpPath) require.NoError(t, err) require.Equal(t, d1, d2, "dumps differ") } diff --git a/cli/executor_test.go b/cli/executor_test.go index 587aba713..f4014844a 100644 --- a/cli/executor_test.go +++ b/cli/executor_test.go @@ -4,7 +4,6 @@ import ( "bytes" "errors" "io" - "io/ioutil" "math" "strings" "sync" @@ -269,7 +268,7 @@ func (e *executor) run(args ...string) error { e.Err.Reset() input.Terminal = term.NewTerminal(input.ReadWriter{ Reader: e.In, - Writer: ioutil.Discard, + Writer: io.Discard, }, "") err := e.CLI.Run(args) input.Terminal = nil diff --git a/cli/flags/address_test.go b/cli/flags/address_test.go index c990f7729..1409720b9 100644 --- a/cli/flags/address_test.go +++ b/cli/flags/address_test.go @@ -2,7 +2,7 @@ package flags import ( "flag" - "io/ioutil" + "io" "testing" "github.com/nspcc-dev/neo-go/internal/random" @@ -119,7 +119,7 @@ func TestAddressFlag_GetName(t *testing.T) { func TestAddress(t *testing.T) { f := flag.NewFlagSet("", flag.ContinueOnError) - f.SetOutput(ioutil.Discard) // don't pollute test output + f.SetOutput(io.Discard) // don't pollute test output addr := AddressFlag{Name: "addr, a"} addr.Apply(f) require.NoError(t, f.Parse([]string{"--addr", "NRHkiY2hLy5ypD32CKZtL6pNwhbFMqDEhR"})) diff --git a/cli/flags/fixed8_test.go b/cli/flags/fixed8_test.go index 3eb344504..1630696ef 100644 --- a/cli/flags/fixed8_test.go +++ b/cli/flags/fixed8_test.go @@ -2,7 +2,7 @@ package flags import ( "flag" - "io/ioutil" + "io" "testing" "github.com/nspcc-dev/neo-go/pkg/encoding/fixedn" @@ -55,7 +55,7 @@ func TestFixed8Flag_GetName(t *testing.T) { func TestFixed8(t *testing.T) { f := flag.NewFlagSet("", flag.ContinueOnError) - f.SetOutput(ioutil.Discard) // don't pollute test output + f.SetOutput(io.Discard) // don't pollute test output gas := Fixed8Flag{Name: "gas, g"} gas.Apply(f) require.NoError(t, f.Parse([]string{"--gas", "0.123"})) diff --git a/cli/nep11_test.go b/cli/nep11_test.go index a3a3125ed..17383af23 100644 --- a/cli/nep11_test.go +++ b/cli/nep11_test.go @@ -7,8 +7,8 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "math/big" + "os" "path/filepath" "strconv" "testing" @@ -104,10 +104,10 @@ func TestNEP11_ND_OwnerOf_BalanceOf_Transfer(t *testing.T) { tmpDir := t.TempDir() // copy wallet to temp dir in order not to overwrite the original file - bytesRead, err := ioutil.ReadFile(nftOwnerWallet) + bytesRead, err := os.ReadFile(nftOwnerWallet) require.NoError(t, err) wall := filepath.Join(tmpDir, "my_wallet.json") - err = ioutil.WriteFile(wall, bytesRead, 0755) + err = os.WriteFile(wall, bytesRead, 0755) require.NoError(t, err) // transfer funds to contract owner @@ -336,10 +336,10 @@ func TestNEP11_D_OwnerOf_BalanceOf_Transfer(t *testing.T) { tmpDir := t.TempDir() // copy wallet to temp dir in order not to overwrite the original file - bytesRead, err := ioutil.ReadFile(validatorWallet) + bytesRead, err := os.ReadFile(validatorWallet) require.NoError(t, err) wall := filepath.Join(tmpDir, "my_wallet.json") - err = ioutil.WriteFile(wall, bytesRead, 0755) + err = os.WriteFile(wall, bytesRead, 0755) require.NoError(t, err) // deploy NeoFS Object contract diff --git a/cli/paramcontext/context.go b/cli/paramcontext/context.go index 0f354427c..1b28951a4 100644 --- a/cli/paramcontext/context.go +++ b/cli/paramcontext/context.go @@ -3,7 +3,7 @@ package paramcontext import ( "encoding/json" "fmt" - "io/ioutil" + "os" "github.com/nspcc-dev/neo-go/pkg/config/netmode" "github.com/nspcc-dev/neo-go/pkg/core/transaction" @@ -36,7 +36,7 @@ func InitAndSave(net netmode.Magic, tx *transaction.Transaction, acc *wallet.Acc // Read reads parameter context from file. func Read(filename string) (*context.ParameterContext, error) { - data, err := ioutil.ReadFile(filename) + data, err := os.ReadFile(filename) if err != nil { return nil, fmt.Errorf("can't read input file: %w", err) } @@ -52,7 +52,7 @@ func Read(filename string) (*context.ParameterContext, error) { func Save(c *context.ParameterContext, filename string) error { if data, err := json.Marshal(c); err != nil { return fmt.Errorf("can't marshal transaction: %w", err) - } else if err := ioutil.WriteFile(filename, data, 0644); err != nil { + } else if err := os.WriteFile(filename, data, 0644); err != nil { return fmt.Errorf("can't write transaction to file: %w", err) } return nil diff --git a/cli/server/dump.go b/cli/server/dump.go index bee34cec8..762b2e636 100644 --- a/cli/server/dump.go +++ b/cli/server/dump.go @@ -3,7 +3,6 @@ package server import ( "encoding/json" "fmt" - "io/ioutil" "os" "path/filepath" @@ -63,7 +62,7 @@ func (d *dump) tryPersist(prefix string, index uint32) error { } func readFile(path string) (*dump, error) { - data, err := ioutil.ReadFile(path) + data, err := os.ReadFile(path) if err != nil { return nil, err } diff --git a/cli/server/server_test.go b/cli/server/server_test.go index 88909d864..4c62ac37c 100644 --- a/cli/server/server_test.go +++ b/cli/server/server_test.go @@ -3,7 +3,6 @@ package server import ( "encoding/binary" "flag" - "io/ioutil" "os" "path/filepath" "testing" @@ -46,7 +45,7 @@ func TestHandleLoggingParams(t *testing.T) { t.Run("logdir is a file", func(t *testing.T) { logfile := filepath.Join(d, "logdir") - require.NoError(t, ioutil.WriteFile(logfile, []byte{1, 2, 3}, os.ModePerm)) + require.NoError(t, os.WriteFile(logfile, []byte{1, 2, 3}, os.ModePerm)) set := flag.NewFlagSet("flagSet", flag.ExitOnError) ctx := cli.NewContext(cli.NewApp(), set, nil) cfg := config.ApplicationConfiguration{ @@ -196,7 +195,7 @@ func TestRestoreDB(t *testing.T) { t.Run("invalid logger path", func(t *testing.T) { badCfgDir := t.TempDir() logfile := filepath.Join(badCfgDir, "logdir") - require.NoError(t, ioutil.WriteFile(logfile, []byte{1, 2, 3}, os.ModePerm)) + require.NoError(t, os.WriteFile(logfile, []byte{1, 2, 3}, os.ModePerm)) cfg, err := config.LoadFile(filepath.Join(goodCfg, "protocol.privnet.yml")) require.NoError(t, err, "could not load config") cfg.ApplicationConfiguration.LogPath = filepath.Join(logfile, "file.log") @@ -204,7 +203,7 @@ func TestRestoreDB(t *testing.T) { require.NoError(t, err) badCfgPath := filepath.Join(badCfgDir, "protocol.privnet.yml") - require.NoError(t, ioutil.WriteFile(badCfgPath, out, os.ModePerm)) + require.NoError(t, os.WriteFile(badCfgPath, out, os.ModePerm)) *cfgPath = badCfgDir require.Error(t, restoreDB(ctx)) @@ -220,7 +219,7 @@ func TestRestoreDB(t *testing.T) { require.NoError(t, err) badCfgPath := filepath.Join(badCfgDir, "protocol.privnet.yml") - require.NoError(t, ioutil.WriteFile(badCfgPath, out, os.ModePerm)) + require.NoError(t, os.WriteFile(badCfgPath, out, os.ModePerm)) *cfgPath = badCfgDir require.Error(t, restoreDB(ctx)) @@ -238,7 +237,7 @@ func TestRestoreDB(t *testing.T) { }) t.Run("corrupted in: invalid block count", func(t *testing.T) { inPath := filepath.Join(t.TempDir(), "file3.acc") - require.NoError(t, ioutil.WriteFile(inPath, []byte{1, 2, 3}, // file is expected to start from uint32 + require.NoError(t, os.WriteFile(inPath, []byte{1, 2, 3}, // file is expected to start from uint32 os.ModePerm)) *in = inPath require.Error(t, restoreDB(ctx)) @@ -247,10 +246,10 @@ func TestRestoreDB(t *testing.T) { }) t.Run("corrupted in: corrupted block", func(t *testing.T) { inPath := filepath.Join(t.TempDir(), "file3.acc") - b, err := ioutil.ReadFile(testDump) + b, err := os.ReadFile(testDump) require.NoError(t, err) b[5] = 0xff // file is expected to start from uint32 (4 bytes) followed by the first block, so corrupt the first block bytes - require.NoError(t, ioutil.WriteFile(inPath, b, os.ModePerm)) + require.NoError(t, os.WriteFile(inPath, b, os.ModePerm)) *in = inPath require.Error(t, restoreDB(ctx)) @@ -258,12 +257,12 @@ func TestRestoreDB(t *testing.T) { }) t.Run("incremental dump", func(t *testing.T) { inPath := filepath.Join(t.TempDir(), "file1_incremental.acc") - b, err := ioutil.ReadFile(testDump) + b, err := os.ReadFile(testDump) require.NoError(t, err) start := make([]byte, 4) t.Run("good", func(t *testing.T) { binary.LittleEndian.PutUint32(start, 1) // start from the first block - require.NoError(t, ioutil.WriteFile(inPath, append(start, b...), + require.NoError(t, os.WriteFile(inPath, append(start, b...), os.ModePerm)) *in = inPath *incremental = true @@ -272,7 +271,7 @@ func TestRestoreDB(t *testing.T) { }) t.Run("dump is too high", func(t *testing.T) { binary.LittleEndian.PutUint32(start, 2) // start from the second block - require.NoError(t, ioutil.WriteFile(inPath, append(start, b...), + require.NoError(t, os.WriteFile(inPath, append(start, b...), os.ModePerm)) *in = inPath *incremental = true diff --git a/cli/server_test.go b/cli/server_test.go index 6b6415e01..5aa28d59a 100644 --- a/cli/server_test.go +++ b/cli/server_test.go @@ -2,7 +2,6 @@ package main import ( "io" - "io/ioutil" "os" "path/filepath" "runtime" @@ -31,7 +30,7 @@ func TestServerStart(t *testing.T) { require.NoError(t, err) cfgPath := filepath.Join(tmpDir, "protocol.unit_testnet.yml") - require.NoError(t, ioutil.WriteFile(cfgPath, out, os.ModePerm)) + require.NoError(t, os.WriteFile(cfgPath, out, os.ModePerm)) t.Cleanup(func() { require.NoError(t, os.Remove(cfgPath)) }) @@ -47,7 +46,7 @@ func TestServerStart(t *testing.T) { t.Run("bad logger config", func(t *testing.T) { badConfigDir := t.TempDir() logfile := filepath.Join(badConfigDir, "logdir") - require.NoError(t, ioutil.WriteFile(logfile, []byte{1, 2, 3}, os.ModePerm)) + require.NoError(t, os.WriteFile(logfile, []byte{1, 2, 3}, os.ModePerm)) saveCfg(t, func(cfg *config.Config) { cfg.ApplicationConfiguration.LogPath = filepath.Join(logfile, "file.log") }) diff --git a/cli/smartcontract/generate.go b/cli/smartcontract/generate.go index 7c9d3e493..2f166b6f1 100644 --- a/cli/smartcontract/generate.go +++ b/cli/smartcontract/generate.go @@ -2,7 +2,6 @@ package smartcontract import ( "fmt" - "io/ioutil" "os" "strings" @@ -47,7 +46,7 @@ func contractGenerateWrapper(ctx *cli.Context) error { cfg := binding.NewConfig() if cfgPath := ctx.String("config"); cfgPath != "" { - bs, err := ioutil.ReadFile(cfgPath) + bs, err := os.ReadFile(cfgPath) if err != nil { return cli.NewExitError(fmt.Errorf("can't read config file: %w", err), 1) } diff --git a/cli/smartcontract/generate_test.go b/cli/smartcontract/generate_test.go index 28e04c624..64629c695 100644 --- a/cli/smartcontract/generate_test.go +++ b/cli/smartcontract/generate_test.go @@ -2,7 +2,6 @@ package smartcontract import ( "encoding/json" - "io/ioutil" "os" "path/filepath" "strings" @@ -115,7 +114,7 @@ func TestGenerate(t *testing.T) { rawManifest, err := json.Marshal(m) require.NoError(t, err) - require.NoError(t, ioutil.WriteFile(manifestFile, rawManifest, os.ModePerm)) + require.NoError(t, os.WriteFile(manifestFile, rawManifest, os.ModePerm)) h := util.Uint160{ 0x04, 0x08, 0x15, 0x16, 0x23, 0x42, 0x43, 0x44, 0x00, 0x01, @@ -139,7 +138,7 @@ callflags: doSomething: ReadStates ` cfgPath := filepath.Join(t.TempDir(), "binding.yml") - require.NoError(t, ioutil.WriteFile(cfgPath, []byte(rawCfg), os.ModePerm)) + require.NoError(t, os.WriteFile(cfgPath, []byte(rawCfg), os.ModePerm)) require.NoError(t, app.Run([]string{"", "generate-wrapper", "--manifest", manifestFile, @@ -225,7 +224,7 @@ func MyFunc(in map[int]mycontract.Input) []mycontract.Output { } ` - data, err := ioutil.ReadFile(outFile) + data, err := os.ReadFile(outFile) require.NoError(t, err) require.Equal(t, expected, string(data)) } @@ -245,7 +244,7 @@ func TestGenerateValidPackageName(t *testing.T) { rawManifest, err := json.Marshal(m) require.NoError(t, err) - require.NoError(t, ioutil.WriteFile(manifestFile, rawManifest, os.ModePerm)) + require.NoError(t, os.WriteFile(manifestFile, rawManifest, os.ModePerm)) h := util.Uint160{ 0x04, 0x08, 0x15, 0x16, 0x23, 0x42, 0x43, 0x44, 0x00, 0x01, @@ -259,7 +258,7 @@ func TestGenerateValidPackageName(t *testing.T) { "--hash", "0x" + h.StringLE(), })) - data, err := ioutil.ReadFile(outFile) + data, err := os.ReadFile(outFile) require.NoError(t, err) require.Equal(t, `// Package myspacecontract contains wrappers for My space contract contract. package myspacecontract @@ -297,7 +296,7 @@ func TestGenerate_Errors(t *testing.T) { }) t.Run("invalid manifest", func(t *testing.T) { manifestFile := filepath.Join(t.TempDir(), "invalid.json") - require.NoError(t, ioutil.WriteFile(manifestFile, []byte("[]"), os.ModePerm)) + require.NoError(t, os.WriteFile(manifestFile, []byte("[]"), os.ModePerm)) checkError(t, "", "--manifest", manifestFile) }) @@ -305,7 +304,7 @@ func TestGenerate_Errors(t *testing.T) { m := manifest.NewManifest("MyContract") rawManifest, err := json.Marshal(m) require.NoError(t, err) - require.NoError(t, ioutil.WriteFile(manifestFile, rawManifest, os.ModePerm)) + require.NoError(t, os.WriteFile(manifestFile, rawManifest, os.ModePerm)) t.Run("invalid hash", func(t *testing.T) { checkError(t, "invalid contract hash", "--manifest", manifestFile, "--hash", "xxx") @@ -321,7 +320,7 @@ callflags: someFunc: ReadSometimes ` cfgPath := filepath.Join(t.TempDir(), "binding.yml") - require.NoError(t, ioutil.WriteFile(cfgPath, []byte(rawCfg), os.ModePerm)) + require.NoError(t, os.WriteFile(cfgPath, []byte(rawCfg), os.ModePerm)) checkError(t, "can't parse config file", "--manifest", manifestFile, "--hash", util.Uint160{}.StringLE(), diff --git a/cli/smartcontract/manifest.go b/cli/smartcontract/manifest.go index db315285a..20fa640b3 100644 --- a/cli/smartcontract/manifest.go +++ b/cli/smartcontract/manifest.go @@ -4,7 +4,6 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" "os" "github.com/nspcc-dev/neo-go/cli/flags" @@ -78,7 +77,7 @@ func manifestAddGroup(ctx *cli.Context) error { return cli.NewExitError(fmt.Errorf("can't marshal manifest: %w", err), 1) } - err = ioutil.WriteFile(mPath, rawM, os.ModePerm) + err = os.WriteFile(mPath, rawM, os.ModePerm) if err != nil { return cli.NewExitError(fmt.Errorf("can't write manifest file: %w", err), 1) } @@ -90,7 +89,7 @@ func readNEFFile(filename string) (*nef.File, []byte, error) { return nil, nil, errors.New("no nef file was provided") } - f, err := ioutil.ReadFile(filename) + f, err := os.ReadFile(filename) if err != nil { return nil, nil, err } @@ -108,7 +107,7 @@ func readManifest(filename string) (*manifest.Manifest, []byte, error) { return nil, nil, errNoManifestFile } - manifestBytes, err := ioutil.ReadFile(filename) + manifestBytes, err := os.ReadFile(filename) if err != nil { return nil, nil, err } diff --git a/cli/smartcontract/smart_contract.go b/cli/smartcontract/smart_contract.go index 6bd34b6df..558fa4ceb 100644 --- a/cli/smartcontract/smart_contract.go +++ b/cli/smartcontract/smart_contract.go @@ -5,7 +5,6 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -455,7 +454,7 @@ func initSmartContract(ctx *cli.Context) error { if err != nil { return cli.NewExitError(err, 1) } - if err := ioutil.WriteFile(filepath.Join(basePath, "neo-go.yml"), b, 0644); err != nil { + if err := os.WriteFile(filepath.Join(basePath, "neo-go.yml"), b, 0644); err != nil { return cli.NewExitError(err, 1) } @@ -468,12 +467,12 @@ func initSmartContract(ctx *cli.Context) error { require ( github.com/nspcc-dev/neo-go/pkg/interop ` + ver + ` )`) - if err := ioutil.WriteFile(filepath.Join(basePath, "go.mod"), gm, 0644); err != nil { + if err := os.WriteFile(filepath.Join(basePath, "go.mod"), gm, 0644); err != nil { return cli.NewExitError(err, 1) } data := []byte(fmt.Sprintf(smartContractTmpl, contractName)) - if err := ioutil.WriteFile(filepath.Join(basePath, fileName), data, 0644); err != nil { + if err := os.WriteFile(filepath.Join(basePath, fileName), data, 0644); err != nil { return cli.NewExitError(err, 1) } @@ -548,7 +547,7 @@ func calcHash(ctx *cli.Context) error { if mpath == "" { return cli.NewExitError(errors.New("no manifest file provided"), 1) } - f, err := ioutil.ReadFile(p) + f, err := os.ReadFile(p) if err != nil { return cli.NewExitError(fmt.Errorf("can't read .nef file: %w", err), 1) } @@ -556,7 +555,7 @@ func calcHash(ctx *cli.Context) error { if err != nil { return cli.NewExitError(fmt.Errorf("can't unmarshal .nef file: %w", err), 1) } - manifestBytes, err := ioutil.ReadFile(mpath) + manifestBytes, err := os.ReadFile(mpath) if err != nil { return cli.NewExitError(fmt.Errorf("failed to read manifest file: %w", err), 1) } @@ -734,7 +733,7 @@ func testInvokeScript(ctx *cli.Context) error { return cli.NewExitError(errNoInput, 1) } - b, err := ioutil.ReadFile(src) + b, err := os.ReadFile(src) if err != nil { return cli.NewExitError(err, 1) } @@ -798,7 +797,7 @@ func inspect(ctx *cli.Context) error { return cli.NewExitError(fmt.Errorf("failed to compile: %w", err), 1) } } else { - f, err := ioutil.ReadFile(in) + f, err := os.ReadFile(in) if err != nil { return cli.NewExitError(fmt.Errorf("failed to read .nef file: %w", err), 1) } @@ -935,7 +934,7 @@ func contractDeploy(ctx *cli.Context) error { // ParseContractConfig reads contract configuration file (.yaml) and returns unmarshalled ProjectConfig. func ParseContractConfig(confFile string) (ProjectConfig, error) { conf := ProjectConfig{} - confBytes, err := ioutil.ReadFile(confFile) + confBytes, err := os.ReadFile(confFile) if err != nil { return conf, cli.NewExitError(err, 1) } diff --git a/cli/smartcontract/smart_contract_test.go b/cli/smartcontract/smart_contract_test.go index 0bd923d92..0c4011174 100644 --- a/cli/smartcontract/smart_contract_test.go +++ b/cli/smartcontract/smart_contract_test.go @@ -3,7 +3,6 @@ package smartcontract import ( "encoding/hex" "flag" - "io/ioutil" "os" "testing" @@ -31,13 +30,13 @@ func TestInitSmartContract(t *testing.T) { dirInfo, err := os.Stat(contractName) require.NoError(t, err) require.True(t, dirInfo.IsDir()) - files, err := ioutil.ReadDir(contractName) + files, err := os.ReadDir(contractName) require.NoError(t, err) require.Equal(t, 3, len(files)) require.Equal(t, "go.mod", files[0].Name()) require.Equal(t, "main.go", files[1].Name()) require.Equal(t, "neo-go.yml", files[2].Name()) - main, err := ioutil.ReadFile(contractName + "/" + files[1].Name()) + main, err := os.ReadFile(contractName + "/" + files[1].Name()) require.NoError(t, err) require.Equal(t, `package `+contractName+` @@ -56,7 +55,7 @@ func RuntimeNotify(args []interface{}) { runtime.Notify(notificationName, args) }`, string(main)) - manifest, err := ioutil.ReadFile(contractName + "/" + files[2].Name()) + manifest, err := os.ReadFile(contractName + "/" + files[2].Name()) require.NoError(t, err) require.Equal(t, `name: testContract diff --git a/pkg/compiler/compiler.go b/pkg/compiler/compiler.go index ff8e664c9..8bdfac375 100644 --- a/pkg/compiler/compiler.go +++ b/pkg/compiler/compiler.go @@ -9,7 +9,6 @@ import ( "go/token" "go/types" "io" - "io/ioutil" "os" "path/filepath" "runtime" @@ -156,7 +155,7 @@ func getBuildInfo(name string, src interface{}) (*buildInfo, error) { case string: buf = []byte(s) case io.Reader: - buf, err = ioutil.ReadAll(s) + buf, err = io.ReadAll(s) if err != nil { return nil, err } @@ -164,10 +163,7 @@ func getBuildInfo(name string, src interface{}) (*buildInfo, error) { panic(fmt.Sprintf("unsupported src type: %T", s)) } if strings.HasPrefix(runtime.Version(), "go1.15") { - dir, err = ioutil.TempDir("", "*") - if err != nil { - return nil, err - } + dir = os.TempDir() name = filepath.Join(dir, filepath.Base(name)) absName = name names = append(names, "file="+name) @@ -259,7 +255,7 @@ func CompileAndSave(src string, o *Options) ([]byte, error) { return nil, fmt.Errorf("error while serializing .nef file: %w", err) } out := fmt.Sprintf("%s.%s", o.Outfile, o.Ext) - err = ioutil.WriteFile(out, bytes, os.ModePerm) + err = os.WriteFile(out, bytes, os.ModePerm) if err != nil { return f.Script, err } @@ -289,7 +285,7 @@ func CompileAndSave(src string, o *Options) ([]byte, error) { if err != nil { return f.Script, err } - if err := ioutil.WriteFile(o.DebugInfo, data, os.ModePerm); err != nil { + if err := os.WriteFile(o.DebugInfo, data, os.ModePerm); err != nil { return f.Script, err } } @@ -311,7 +307,7 @@ func CompileAndSave(src string, o *Options) ([]byte, error) { if err != nil { return nil, fmt.Errorf("can't marshal bindings configuration: %w", err) } - err = ioutil.WriteFile(o.BindingsFile, data, os.ModePerm) + err = os.WriteFile(o.BindingsFile, data, os.ModePerm) if err != nil { return nil, fmt.Errorf("can't write bindings configuration: %w", err) } @@ -326,7 +322,7 @@ func CompileAndSave(src string, o *Options) ([]byte, error) { if err != nil { return f.Script, fmt.Errorf("failed to marshal manifest to JSON: %w", err) } - return f.Script, ioutil.WriteFile(o.ManifestFile, mData, os.ModePerm) + return f.Script, os.WriteFile(o.ManifestFile, mData, os.ModePerm) } return f.Script, nil diff --git a/pkg/compiler/compiler_test.go b/pkg/compiler/compiler_test.go index 32b242adc..2390652b0 100644 --- a/pkg/compiler/compiler_test.go +++ b/pkg/compiler/compiler_test.go @@ -2,7 +2,6 @@ package compiler_test import ( "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -49,7 +48,7 @@ func TestCompiler(t *testing.T) { { name: "TestCompile", function: func(t *testing.T) { - infos, err := ioutil.ReadDir(examplePath) + infos, err := os.ReadDir(examplePath) require.NoError(t, err) for _, info := range infos { if !info.IsDir() { @@ -66,7 +65,7 @@ func TestCompiler(t *testing.T) { { name: "TestCompileAndSave", function: func(t *testing.T) { - infos, err := ioutil.ReadDir(exampleCompilePath) + infos, err := os.ReadDir(exampleCompilePath) require.NoError(t, err) err = os.MkdirAll(exampleSavePath, os.ModePerm) require.NoError(t, err) diff --git a/pkg/config/config.go b/pkg/config/config.go index 0186b4dc4..73d7f9ff8 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -2,7 +2,6 @@ package config import ( "fmt" - "io/ioutil" "os" "github.com/nspcc-dev/neo-go/pkg/config/netmode" @@ -40,7 +39,7 @@ func LoadFile(configPath string) (Config, error) { return Config{}, fmt.Errorf("config '%s' doesn't exist", configPath) } - configData, err := ioutil.ReadFile(configPath) + configData, err := os.ReadFile(configPath) if err != nil { return Config{}, fmt.Errorf("unable to read config: %w", err) } diff --git a/pkg/core/block/helper_test.go b/pkg/core/block/helper_test.go index b73b50de2..85be4903b 100644 --- a/pkg/core/block/helper_test.go +++ b/pkg/core/block/helper_test.go @@ -4,7 +4,7 @@ import ( "encoding/hex" "encoding/json" "fmt" - "io/ioutil" + "os" "testing" "github.com/nspcc-dev/neo-go/internal/testserdes" @@ -25,7 +25,7 @@ func getDecodedBlock(t *testing.T, i int) *Block { } func getBlockData(i int) (map[string]interface{}, error) { - b, err := ioutil.ReadFile(fmt.Sprintf("../test_data/block_%d.json", i)) + b, err := os.ReadFile(fmt.Sprintf("../test_data/block_%d.json", i)) if err != nil { return nil, err } diff --git a/pkg/core/interop_system_test.go b/pkg/core/interop_system_test.go index c2b2089be..07771e534 100644 --- a/pkg/core/interop_system_test.go +++ b/pkg/core/interop_system_test.go @@ -4,7 +4,6 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" "math" "math/big" "os" @@ -988,7 +987,7 @@ func TestGenerateManagementHelperContracts(t *testing.T) { bytes, err := ne.Bytes() require.NoError(t, err) if saveState { - err = ioutil.WriteFile(helper1ContractNEFPath, bytes, os.ModePerm) + err = os.WriteFile(helper1ContractNEFPath, bytes, os.ModePerm) require.NoError(t, err) } @@ -996,7 +995,7 @@ func TestGenerateManagementHelperContracts(t *testing.T) { mData, err := json.Marshal(m) require.NoError(t, err) if saveState { - err = ioutil.WriteFile(helper1ContractManifestPath, mData, os.ModePerm) + err = os.WriteFile(helper1ContractManifestPath, mData, os.ModePerm) require.NoError(t, err) } @@ -1022,7 +1021,7 @@ func TestGenerateManagementHelperContracts(t *testing.T) { bytes, err = ne.Bytes() require.NoError(t, err) if saveState { - err = ioutil.WriteFile(helper2ContractNEFPath, bytes, os.ModePerm) + err = os.WriteFile(helper2ContractNEFPath, bytes, os.ModePerm) require.NoError(t, err) } @@ -1030,7 +1029,7 @@ func TestGenerateManagementHelperContracts(t *testing.T) { mData, err = json.Marshal(m) require.NoError(t, err) if saveState { - err = ioutil.WriteFile(helper2ContractManifestPath, mData, os.ModePerm) + err = os.WriteFile(helper2ContractManifestPath, mData, os.ModePerm) require.NoError(t, err) } @@ -1041,12 +1040,12 @@ func TestGenerateManagementHelperContracts(t *testing.T) { func getTestContractState(t *testing.T, id1, id2 int32, sender2 util.Uint160) (*state.Contract, *state.Contract) { errNotFound := errors.New("auto-generated oracle contract is not found, use TestGenerateOracleContract to regenerate") - neBytes, err := ioutil.ReadFile(helper1ContractNEFPath) + neBytes, err := os.ReadFile(helper1ContractNEFPath) require.NoError(t, err, fmt.Errorf("nef1: %w", errNotFound)) ne, err := nef.FileFromBytes(neBytes) require.NoError(t, err) - mBytes, err := ioutil.ReadFile(helper1ContractManifestPath) + mBytes, err := os.ReadFile(helper1ContractManifestPath) require.NoError(t, err, fmt.Errorf("manifest1: %w", errNotFound)) m := &manifest.Manifest{} err = json.Unmarshal(mBytes, m) @@ -1060,12 +1059,12 @@ func getTestContractState(t *testing.T, id1, id2 int32, sender2 util.Uint160) (* }, } - neBytes, err = ioutil.ReadFile(helper2ContractNEFPath) + neBytes, err = os.ReadFile(helper2ContractNEFPath) require.NoError(t, err, fmt.Errorf("nef2: %w", errNotFound)) ne, err = nef.FileFromBytes(neBytes) require.NoError(t, err) - mBytes, err = ioutil.ReadFile(helper2ContractManifestPath) + mBytes, err = os.ReadFile(helper2ContractManifestPath) require.NoError(t, err, fmt.Errorf("manifest2: %w", errNotFound)) m = &manifest.Manifest{} err = json.Unmarshal(mBytes, m) diff --git a/pkg/core/native/native_test/management_test.go b/pkg/core/native/native_test/management_test.go index 17d0a86fd..eb4fa8872 100644 --- a/pkg/core/native/native_test/management_test.go +++ b/pkg/core/native/native_test/management_test.go @@ -5,7 +5,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "os" "path/filepath" "testing" @@ -49,12 +49,12 @@ func TestManagement_MinimumDeploymentFee(t *testing.T) { func getTestContractState(t *testing.T, id1, id2 int32, sender2 util.Uint160) (*state.Contract, *state.Contract) { errNotFound := errors.New("auto-generated oracle contract is not found, use TestGenerateOracleContract to regenerate") - neBytes, err := ioutil.ReadFile(helper1ContractNEFPath) + neBytes, err := os.ReadFile(helper1ContractNEFPath) require.NoError(t, err, fmt.Errorf("nef1: %w", errNotFound)) ne, err := nef.FileFromBytes(neBytes) require.NoError(t, err) - mBytes, err := ioutil.ReadFile(helper1ContractManifestPath) + mBytes, err := os.ReadFile(helper1ContractManifestPath) require.NoError(t, err, fmt.Errorf("manifest1: %w", errNotFound)) m := &manifest.Manifest{} err = json.Unmarshal(mBytes, m) @@ -68,12 +68,12 @@ func getTestContractState(t *testing.T, id1, id2 int32, sender2 util.Uint160) (* }, } - neBytes, err = ioutil.ReadFile(helper2ContractNEFPath) + neBytes, err = os.ReadFile(helper2ContractNEFPath) require.NoError(t, err, fmt.Errorf("nef2: %w", errNotFound)) ne, err = nef.FileFromBytes(neBytes) require.NoError(t, err) - mBytes, err = ioutil.ReadFile(helper2ContractManifestPath) + mBytes, err = os.ReadFile(helper2ContractManifestPath) require.NoError(t, err, fmt.Errorf("manifest2: %w", errNotFound)) m = &manifest.Manifest{} err = json.Unmarshal(mBytes, m) diff --git a/pkg/core/native/native_test/oracle_test.go b/pkg/core/native/native_test/oracle_test.go index 17cc8df75..8b7ae6a4a 100644 --- a/pkg/core/native/native_test/oracle_test.go +++ b/pkg/core/native/native_test/oracle_test.go @@ -4,9 +4,9 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" "math" "math/big" + "os" "path/filepath" "strings" "testing" @@ -45,12 +45,12 @@ func getOracleContractState(t *testing.T, sender util.Uint160, id int32) *state. ) errNotFound := errors.New("auto-generated oracle contract is not found, use TestGenerateOracleContract to regenerate") - neBytes, err := ioutil.ReadFile(oracleContractNEFPath) + neBytes, err := os.ReadFile(oracleContractNEFPath) require.NoError(t, err, fmt.Errorf("nef: %w", errNotFound)) ne, err := nef.FileFromBytes(neBytes) require.NoError(t, err) - mBytes, err := ioutil.ReadFile(oracleContractManifestPath) + mBytes, err := os.ReadFile(oracleContractManifestPath) require.NoError(t, err, fmt.Errorf("manifest: %w", errNotFound)) m := &manifest.Manifest{} err = json.Unmarshal(mBytes, m) diff --git a/pkg/core/oracle_test.go b/pkg/core/oracle_test.go index 68e63d85c..b33bf78dd 100644 --- a/pkg/core/oracle_test.go +++ b/pkg/core/oracle_test.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" gio "io" - "io/ioutil" "net/http" "os" "path" @@ -124,7 +123,7 @@ func TestGenerateOracleContract(t *testing.T) { bytes, err := ne.Bytes() require.NoError(t, err) if saveState { - err = ioutil.WriteFile(oracleContractNEFPath, bytes, os.ModePerm) + err = os.WriteFile(oracleContractNEFPath, bytes, os.ModePerm) require.NoError(t, err) } @@ -132,7 +131,7 @@ func TestGenerateOracleContract(t *testing.T) { mData, err := json.Marshal(m) require.NoError(t, err) if saveState { - err = ioutil.WriteFile(oracleContractManifestPath, mData, os.ModePerm) + err = os.WriteFile(oracleContractManifestPath, mData, os.ModePerm) require.NoError(t, err) } @@ -144,12 +143,12 @@ func TestGenerateOracleContract(t *testing.T) { func getOracleContractState(t *testing.T, sender util.Uint160, id int32) *state.Contract { errNotFound := errors.New("auto-generated oracle contract is not found, use TestGenerateOracleContract to regenerate") - neBytes, err := ioutil.ReadFile(oracleContractNEFPath) + neBytes, err := os.ReadFile(oracleContractNEFPath) require.NoError(t, err, fmt.Errorf("nef: %w", errNotFound)) ne, err := nef.FileFromBytes(neBytes) require.NoError(t, err) - mBytes, err := ioutil.ReadFile(oracleContractManifestPath) + mBytes, err := os.ReadFile(oracleContractManifestPath) require.NoError(t, err, fmt.Errorf("manifest: %w", errNotFound)) m := &manifest.Manifest{} err = json.Unmarshal(mBytes, m) @@ -639,5 +638,5 @@ func newDefaultHTTPClient(returnOracleRedirectionErrOn func(address string) bool } func newResponseBody(resp []byte) gio.ReadCloser { - return ioutil.NopCloser(bytes.NewReader(resp)) + return gio.NopCloser(bytes.NewReader(resp)) } diff --git a/pkg/rpc/server/server_test.go b/pkg/rpc/server/server_test.go index 6bc84ee8b..f9a6b02b9 100644 --- a/pkg/rpc/server/server_test.go +++ b/pkg/rpc/server/server_test.go @@ -5,7 +5,7 @@ import ( "encoding/base64" "encoding/json" "fmt" - "io/ioutil" + gio "io" "math/big" "net/http" "net/http/httptest" @@ -2029,7 +2029,7 @@ func doRPCCallOverHTTP(rpcCall string, url string, t *testing.T) []byte { cl := http.Client{Timeout: time.Second} resp, err := cl.Post(url, "application/json", strings.NewReader(rpcCall)) require.NoErrorf(t, err, "could not make a POST request") - body, err := ioutil.ReadAll(resp.Body) + body, err := gio.ReadAll(resp.Body) assert.NoErrorf(t, err, "could not read response from the request: %s", rpcCall) return bytes.TrimSpace(body) } diff --git a/pkg/smartcontract/parameter.go b/pkg/smartcontract/parameter.go index ebf2e237e..91f773fed 100644 --- a/pkg/smartcontract/parameter.go +++ b/pkg/smartcontract/parameter.go @@ -8,9 +8,9 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" "math" "math/bits" + "os" "strconv" "strings" "unicode/utf8" @@ -436,7 +436,7 @@ func NewParameterFromString(in string) (*Parameter, error) { res.Type = inferParamType(val) } if res.Type == ByteArrayType && typStr == fileBytesParamType { - res.Value, err = ioutil.ReadFile(val) + res.Value, err = os.ReadFile(val) if err != nil { return nil, fmt.Errorf("failed to read '%s' parameter from file '%s': %w", fileBytesParamType, val, err) } diff --git a/pkg/vm/cli/cli.go b/pkg/vm/cli/cli.go index d37da180a..c538d8937 100644 --- a/pkg/vm/cli/cli.go +++ b/pkg/vm/cli/cli.go @@ -9,7 +9,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "math/big" "os" "strconv" @@ -503,7 +502,7 @@ func handleReset(c *cli.Context) error { } func getManifestFromFile(name string) (*manifest.Manifest, error) { - bs, err := ioutil.ReadFile(name) + bs, err := os.ReadFile(name) if err != nil { return nil, fmt.Errorf("%w: can't read manifest", ErrInvalidParameter) } diff --git a/pkg/vm/cli/cli_test.go b/pkg/vm/cli/cli_test.go index 584e46859..708ae06f3 100644 --- a/pkg/vm/cli/cli_test.go +++ b/pkg/vm/cli/cli_test.go @@ -7,7 +7,6 @@ import ( "encoding/json" "fmt" gio "io" - "io/ioutil" "os" "path/filepath" "strings" @@ -209,14 +208,14 @@ func TestLoad(t *testing.T) { checkLoadgo := func(t *testing.T, tName, cName, cErrName string) { t.Run("loadgo "+tName, func(t *testing.T) { filename := filepath.Join(tmpDir, cName) - require.NoError(t, ioutil.WriteFile(filename, []byte(src), os.ModePerm)) + require.NoError(t, os.WriteFile(filename, []byte(src), os.ModePerm)) filename = "'" + filename + "'" filenameErr := filepath.Join(tmpDir, cErrName) - require.NoError(t, ioutil.WriteFile(filenameErr, []byte(src+"invalid_token"), os.ModePerm)) + require.NoError(t, os.WriteFile(filenameErr, []byte(src+"invalid_token"), os.ModePerm)) filenameErr = "'" + filenameErr + "'" goMod := []byte(`module test.example/vmcli go 1.16`) - require.NoError(t, ioutil.WriteFile(filepath.Join(tmpDir, "go.mod"), goMod, os.ModePerm)) + require.NoError(t, os.WriteFile(filepath.Join(tmpDir, "go.mod"), goMod, os.ModePerm)) e := newTestVMCLI(t) e.runProgWithTimeout(t, 10*time.Second, @@ -244,7 +243,7 @@ go 1.16`) } ` filename := filepath.Join(tmpDir, "vmtestcontract.go") - require.NoError(t, ioutil.WriteFile(filename, []byte(srcAllowNotify), os.ModePerm)) + require.NoError(t, os.WriteFile(filename, []byte(srcAllowNotify), os.ModePerm)) filename = "'" + filename + "'" wd, err := os.Getwd() require.NoError(t, err) @@ -254,7 +253,7 @@ require ( ) replace github.com/nspcc-dev/neo-go/pkg/interop => ` + filepath.Join(wd, "../../interop") + ` go 1.16`) - require.NoError(t, ioutil.WriteFile(filepath.Join(tmpDir, "go.mod"), goMod, os.ModePerm)) + require.NoError(t, os.WriteFile(filepath.Join(tmpDir, "go.mod"), goMod, os.ModePerm)) e := newTestVMCLI(t) e.runProg(t, @@ -271,15 +270,15 @@ go 1.16`) filename := filepath.Join(tmpDir, "vmtestcontract.nef") rawNef, err := nefFile.Bytes() require.NoError(t, err) - require.NoError(t, ioutil.WriteFile(filename, rawNef, os.ModePerm)) + require.NoError(t, os.WriteFile(filename, rawNef, os.ModePerm)) m, err := di.ConvertToManifest(&compiler.Options{}) require.NoError(t, err) manifestFile := filepath.Join(tmpDir, "vmtestcontract.manifest.json") rawManifest, err := json.Marshal(m) require.NoError(t, err) - require.NoError(t, ioutil.WriteFile(manifestFile, rawManifest, os.ModePerm)) + require.NoError(t, os.WriteFile(manifestFile, rawManifest, os.ModePerm)) filenameErr := filepath.Join(tmpDir, "vmtestcontract_err.nef") - require.NoError(t, ioutil.WriteFile(filenameErr, append([]byte{1, 2, 3, 4}, rawNef...), os.ModePerm)) + require.NoError(t, os.WriteFile(filenameErr, append([]byte{1, 2, 3, 4}, rawNef...), os.ModePerm)) notExists := filepath.Join(tmpDir, "notexists.json") manifestFile = "'" + manifestFile + "'" @@ -325,7 +324,7 @@ func TestRunWithDifferentArguments(t *testing.T) { tmpDir := t.TempDir() filename := filepath.Join(tmpDir, "run_vmtestcontract.go") - require.NoError(t, ioutil.WriteFile(filename, []byte(src), os.ModePerm)) + require.NoError(t, os.WriteFile(filename, []byte(src), os.ModePerm)) filename = "'" + filename + "'" e := newTestVMCLI(t) diff --git a/pkg/vm/json_test.go b/pkg/vm/json_test.go index bd15eba66..5d7050dbb 100644 --- a/pkg/vm/json_test.go +++ b/pkg/vm/json_test.go @@ -7,7 +7,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "io" "math/big" "os" "path/filepath" @@ -129,7 +129,7 @@ func testSyscallHandler(v *VM, id uint32) error { } func testFile(t *testing.T, filename string) { - data, err := ioutil.ReadFile(filename) + data, err := os.ReadFile(filename) require.NoError(t, err) // get rid of possible BOM @@ -472,7 +472,7 @@ func decodeBytes(data []byte) ([]byte, error) { } r := base64.NewDecoder(base64.StdEncoding, bytes.NewReader(data)) - return ioutil.ReadAll(r) + return io.ReadAll(r) } func decodeHex(s string) ([]byte, error) { diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index 666e2f30b..a7e29fffc 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -7,7 +7,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "math" "math/big" "os" @@ -234,7 +233,7 @@ func (v *VM) AddBreakPointRel(n int) { // LoadFileWithFlags loads a program in NEF format from the given path, ready to execute it. func (v *VM) LoadFileWithFlags(path string, f callflag.CallFlag) error { - b, err := ioutil.ReadFile(path) + b, err := os.ReadFile(path) if err != nil { return err } diff --git a/pkg/wallet/regenerate_test.go b/pkg/wallet/regenerate_test.go index 168fcff34..dfed86462 100644 --- a/pkg/wallet/regenerate_test.go +++ b/pkg/wallet/regenerate_test.go @@ -3,7 +3,7 @@ package wallet import ( "encoding/json" "fmt" - "io/ioutil" + "os" "path/filepath" "testing" @@ -227,11 +227,11 @@ func TestRegenerateCLIWallet1_solo(t *testing.T) { require.NoError(t, acc3.ConvertMultisig(1, keys.PublicKeys{getKeys(t)[0]})) acc4 := getAccountWithScrypt(t, verifyWIF, "pass", scrypt) // deployed verify.go contract - f, err := ioutil.ReadFile(verifyNEFPath) + f, err := os.ReadFile(verifyNEFPath) require.NoError(t, err) nefFile, err := nef.FileFromBytes(f) require.NoError(t, err) - manifestBytes, err := ioutil.ReadFile(verifyManifestPath) + manifestBytes, err := os.ReadFile(verifyManifestPath) require.NoError(t, err) m := &manifest.Manifest{} require.NoError(t, json.Unmarshal(manifestBytes, m)) diff --git a/pkg/wallet/wallet.go b/pkg/wallet/wallet.go index 63d74fcca..bf89300e9 100644 --- a/pkg/wallet/wallet.go +++ b/pkg/wallet/wallet.go @@ -4,7 +4,6 @@ import ( "encoding/json" "errors" "io" - "io/ioutil" "os" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" @@ -161,7 +160,7 @@ func (w *Wallet) savePretty() error { } func (w *Wallet) writeRaw(data []byte) error { - return ioutil.WriteFile(w.path, data, 0644) + return os.WriteFile(w.path, data, 0644) } // JSON outputs a pretty JSON representation of the wallet. diff --git a/scripts/compare-dumps/compare-dumps.go b/scripts/compare-dumps/compare-dumps.go index 73458c3c0..627a5b145 100644 --- a/scripts/compare-dumps/compare-dumps.go +++ b/scripts/compare-dumps/compare-dumps.go @@ -7,7 +7,6 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" "os" "path/filepath" "sort" @@ -32,7 +31,7 @@ type storageOp struct { } func readFile(path string) (dump, error) { - data, err := ioutil.ReadFile(path) + data, err := os.ReadFile(path) if err != nil { return nil, err }